mirror of
https://github.com/aljazceru/breez-lnd.git
synced 2025-12-17 14:14:21 +01:00
lnwallet: convert CommitSpendTimeout to user the Signer interface
This commit is contained in:
@@ -83,7 +83,7 @@ func GenFundingPkScript(aPub, bPub []byte, amt int64) ([]byte, *wire.TxOut, erro
|
||||
return redeemScript, wire.NewTxOut(amt, pkScript), nil
|
||||
}
|
||||
|
||||
// spendMultiSig generates the witness stack required to redeem the 2-of-2 p2wsh
|
||||
// SpendMultiSig generates the witness stack required to redeem the 2-of-2 p2wsh
|
||||
// multi-sig output.
|
||||
func SpendMultiSig(redeemScript, pubA, sigA, pubB, sigB []byte) [][]byte {
|
||||
witness := make([][]byte, 4)
|
||||
@@ -592,18 +592,19 @@ func commitScriptUnencumbered(key *btcec.PublicKey) ([]byte, error) {
|
||||
return builder.Script()
|
||||
}
|
||||
|
||||
// commitSpendTimeout constructs a valid witness allowing the owner of a
|
||||
// CommitSpendTimeout constructs a valid witness allowing the owner of a
|
||||
// particular commitment transaction to spend the output returning settled
|
||||
// funds back to themselves after an absolute block timeout.
|
||||
func commitSpendTimeout(commitScript []byte, outputAmt btcutil.Amount,
|
||||
blockTimeout uint32, selfKey *btcec.PrivateKey,
|
||||
sweepTx *wire.MsgTx) (wire.TxWitness, error) {
|
||||
func CommitSpendTimeout(signer Signer, signDesc *SignDescriptor,
|
||||
blockTimeout uint32, sweepTx *wire.MsgTx) (wire.TxWitness, error) {
|
||||
|
||||
inputIndex := signDesc.InputIndex
|
||||
|
||||
// In order to properly spend the transaction, we need to set the
|
||||
// sequence number. We do this by convering the relative block delay
|
||||
// into a sequence number value able to be interpeted by
|
||||
// OP_CHECKSEQUENCEVERIFY.
|
||||
sweepTx.TxIn[0].Sequence = lockTimeToSequence(false, blockTimeout)
|
||||
sweepTx.TxIn[inputIndex].Sequence = lockTimeToSequence(false, blockTimeout)
|
||||
|
||||
// Additionally, OP_CSV requires that the version of the transaction
|
||||
// spending a pkscript with OP_CSV within it *must* be >= 2.
|
||||
@@ -611,10 +612,7 @@ func commitSpendTimeout(commitScript []byte, outputAmt btcutil.Amount,
|
||||
|
||||
// With the sequence number in place, we're now able to properly sign
|
||||
// off on the sweep transaction.
|
||||
hashCache := txscript.NewTxSigHashes(sweepTx)
|
||||
sweepSig, err := txscript.RawTxInWitnessSignature(
|
||||
sweepTx, hashCache, 0, int64(outputAmt), commitScript,
|
||||
txscript.SigHashAll, selfKey)
|
||||
sweepSig, err := signer.SignOutputRaw(sweepTx, signDesc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -622,9 +620,9 @@ func commitSpendTimeout(commitScript []byte, outputAmt btcutil.Amount,
|
||||
// Place a zero as the first item in the evaluated witness stack to
|
||||
// force script execution to the timeout spend clause.
|
||||
witnessStack := wire.TxWitness(make([][]byte, 3))
|
||||
witnessStack[0] = sweepSig
|
||||
witnessStack[0] = append(sweepSig, byte(txscript.SigHashAll))
|
||||
witnessStack[1] = []byte{0}
|
||||
witnessStack[2] = commitScript
|
||||
witnessStack[2] = signDesc.RedeemScript
|
||||
|
||||
return witnessStack, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user