mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-13 07:37:22 +01:00
lnwallet: add new HtlcSecondLevelRevoke witness type
In this commit, we add a new witness type to the set of known types. This new type will be used when we need to sweep an HTLC that the remote party has taken to the second level.
This commit is contained in:
@@ -817,6 +817,31 @@ func htlcSpendSuccess(signer Signer, signDesc *SignDescriptor,
|
||||
return witnessStack, nil
|
||||
}
|
||||
|
||||
// htlcSpendRevoke spends a second-level HTLC output. This function is to be
|
||||
// used by the sender or receiver of an HTLC to claim the HTLC after a revoked
|
||||
// commitment transaction was broadcast.
|
||||
func htlcSpendRevoke(signer Signer, signDesc *SignDescriptor,
|
||||
revokeTx *wire.MsgTx) (wire.TxWitness, error) {
|
||||
|
||||
// We don't need any spacial modifications to the transaction as this
|
||||
// is just sweeping a revoked HTLC output. So we'll generate a regular
|
||||
// witness signature.
|
||||
sweepSig, err := signer.SignOutputRaw(revokeTx, signDesc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// We set a one as the first element the witness stack (ignoring the
|
||||
// witness script), in order to force execution to the revocation
|
||||
// clause in the second level HTLC script.
|
||||
witnessStack := wire.TxWitness(make([][]byte, 3))
|
||||
witnessStack[0] = append(sweepSig, byte(signDesc.HashType))
|
||||
witnessStack[1] = []byte{1}
|
||||
witnessStack[2] = signDesc.WitnessScript
|
||||
|
||||
return witnessStack, nil
|
||||
}
|
||||
|
||||
// HtlcSecondLevelSpend exposes the public witness generation function for
|
||||
// spending an HTLC success transaction, either due to an expiring time lock or
|
||||
// having had the payment preimage. This method is able to spend any
|
||||
@@ -848,31 +873,6 @@ func HtlcSecondLevelSpend(signer Signer, signDesc *SignDescriptor,
|
||||
return witnessStack, nil
|
||||
}
|
||||
|
||||
// htlcTimeoutRevoke spends a second-level HTLC output. This function is to be
|
||||
// used by the sender or receiver of an HTLC to claim the HTLC after a revoked
|
||||
// commitment transaction was broadcast.
|
||||
func htlcSpendRevoke(signer Signer, signDesc *SignDescriptor,
|
||||
revokeTx *wire.MsgTx) (wire.TxWitness, error) {
|
||||
|
||||
// We don't need any spacial modifications to the transaction as this
|
||||
// is just sweeping a revoked HTLC output. So we'll generate a regular
|
||||
// witness signature.
|
||||
sweepSig, err := signer.SignOutputRaw(revokeTx, signDesc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// We set a one as the first element the witness stack (ignoring the
|
||||
// witness script), in order to force execution to the revocation
|
||||
// clause in the second level HTLC script.
|
||||
witnessStack := wire.TxWitness(make([][]byte, 3))
|
||||
witnessStack[0] = append(sweepSig, byte(signDesc.HashType))
|
||||
witnessStack[1] = []byte{1}
|
||||
witnessStack[2] = signDesc.WitnessScript
|
||||
|
||||
return witnessStack, nil
|
||||
}
|
||||
|
||||
// lockTimeToSequence converts the passed relative locktime to a sequence
|
||||
// number in accordance to BIP-68.
|
||||
// See: https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki
|
||||
|
||||
Reference in New Issue
Block a user