mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-05-05 17:30:21 +02: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
|
return i.unconfParent
|
||||||
}
|
}
|
||||||
|
|
||||||
// BaseInput contains all the information needed to sweep a basic output
|
// BaseInput contains all the information needed to sweep a basic
|
||||||
// (CSV/CLTV/no time lock)
|
// output (CSV/CLTV/no time lock).
|
||||||
type BaseInput struct {
|
type BaseInput struct {
|
||||||
inputKit
|
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
|
// CraftInputScript returns a valid set of input scripts allowing this output
|
||||||
// to be spent. The returns input scripts should target the input at location
|
// to be spent. The returns input scripts should target the input at location
|
||||||
// txIndex within the passed transaction. The input scripts generated by this
|
// 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.InputIndex = txinIdx
|
||||||
desc.PrevOutputFetcher = prevOutputFetcher
|
desc.PrevOutputFetcher = prevOutputFetcher
|
||||||
|
|
||||||
witness, err := SenderHtlcSpendRedeem(
|
isTaproot := txscript.IsPayToTaproot(desc.Output.PkScript)
|
||||||
signer, &desc, txn, h.preimage,
|
|
||||||
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user