mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
input: HtlcSucceedInput to support sweeping for taproot chans
This commit is contained in:
parent
b00cf25590
commit
fa07a2d248
@ -153,8 +153,8 @@ func (i *inputKit) UnconfParent() *TxInfo {
|
||||
return i.unconfParent
|
||||
}
|
||||
|
||||
// BaseInput contains all the information needed to sweep a basic output
|
||||
// (CSV/CLTV/no time lock)
|
||||
// BaseInput contains all the information needed to sweep a basic
|
||||
// output (CSV/CLTV/no time lock).
|
||||
type BaseInput struct {
|
||||
inputKit
|
||||
}
|
||||
@ -267,6 +267,24 @@ func MakeHtlcSucceedInput(outpoint *wire.OutPoint,
|
||||
}
|
||||
}
|
||||
|
||||
// MakeTaprootHtlcSucceedInput creates a new HtlcSucceedInput that can be used
|
||||
// to spend an HTLC output for a taproot channel on the remote party's
|
||||
// commitment transaction.
|
||||
func MakeTaprootHtlcSucceedInput(op *wire.OutPoint, signDesc *SignDescriptor,
|
||||
preimage []byte, heightHint, blocksToMaturity uint32) HtlcSucceedInput {
|
||||
|
||||
return HtlcSucceedInput{
|
||||
inputKit: inputKit{
|
||||
outpoint: *op,
|
||||
witnessType: TaprootHtlcAcceptedRemoteSuccess,
|
||||
signDesc: *signDesc,
|
||||
heightHint: heightHint,
|
||||
blockToMaturity: blocksToMaturity,
|
||||
},
|
||||
preimage: preimage,
|
||||
}
|
||||
}
|
||||
|
||||
// CraftInputScript returns a valid set of input scripts allowing this output
|
||||
// to be spent. The returns input scripts should target the input at location
|
||||
// txIndex within the passed transaction. The input scripts generated by this
|
||||
@ -281,9 +299,27 @@ func (h *HtlcSucceedInput) CraftInputScript(signer Signer, txn *wire.MsgTx,
|
||||
desc.InputIndex = txinIdx
|
||||
desc.PrevOutputFetcher = prevOutputFetcher
|
||||
|
||||
witness, err := SenderHtlcSpendRedeem(
|
||||
signer, &desc, txn, h.preimage,
|
||||
isTaproot := txscript.IsPayToTaproot(desc.Output.PkScript)
|
||||
|
||||
var (
|
||||
witness wire.TxWitness
|
||||
err error
|
||||
)
|
||||
if isTaproot {
|
||||
if desc.ControlBlock == nil {
|
||||
return nil, fmt.Errorf("ctrl block must be set")
|
||||
}
|
||||
|
||||
desc.SignMethod = TaprootScriptSpendSignMethod
|
||||
|
||||
witness, err = SenderHTLCScriptTaprootRedeem(
|
||||
signer, &desc, txn, h.preimage, nil, nil,
|
||||
)
|
||||
} else {
|
||||
witness, err = SenderHtlcSpendRedeem(
|
||||
signer, &desc, txn, h.preimage,
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user