input: HtlcSucceedInput to support sweeping for taproot chans

This commit is contained in:
Olaoluwa Osuntokun 2023-03-01 21:50:55 -08:00
parent b00cf25590
commit fa07a2d248
No known key found for this signature in database
GPG Key ID: 3BBD59E99B280306

View File

@ -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
}