multi: use prev output fetcher where possible
This commit is contained in:
13 files changed
+255
-44
No files matched your search
+24
-7
@@ -42,6 +42,7 @@ type Input interface {
|
||||
// also nested p2sh outputs.
|
||||
CraftInputScript(signer Signer, txn *wire.MsgTx,
|
||||
hashCache *txscript.TxSigHashes,
|
||||
prevOutputFetcher txscript.PrevOutputFetcher,
|
||||
txinIdx int) (*Script, error)
|
||||
|
||||
// BlocksToMaturity returns the relative timelock, as a number of
|
||||
@@ -221,9 +222,13 @@ func NewCsvInputWithCltv(outpoint *wire.OutPoint, witnessType WitnessType,
|
||||
// txIndex within the passed transaction. The input scripts generated by this
|
||||
// method support spending p2wkh, p2wsh, and also nested p2sh outputs.
|
||||
func (bi *BaseInput) CraftInputScript(signer Signer, txn *wire.MsgTx,
|
||||
hashCache *txscript.TxSigHashes, txinIdx int) (*Script, error) {
|
||||
hashCache *txscript.TxSigHashes,
|
||||
prevOutputFetcher txscript.PrevOutputFetcher, txinIdx int) (*Script,
|
||||
error) {
|
||||
|
||||
witnessFunc := bi.witnessType.WitnessGenerator(signer, bi.SignDesc())
|
||||
signDesc := bi.SignDesc()
|
||||
signDesc.PrevOutputFetcher = prevOutputFetcher
|
||||
witnessFunc := bi.witnessType.WitnessGenerator(signer, signDesc)
|
||||
|
||||
return witnessFunc(txn, hashCache, txinIdx)
|
||||
}
|
||||
@@ -260,11 +265,14 @@ func MakeHtlcSucceedInput(outpoint *wire.OutPoint,
|
||||
// txIndex within the passed transaction. The input scripts generated by this
|
||||
// method support spending p2wkh, p2wsh, and also nested p2sh outputs.
|
||||
func (h *HtlcSucceedInput) CraftInputScript(signer Signer, txn *wire.MsgTx,
|
||||
hashCache *txscript.TxSigHashes, txinIdx int) (*Script, error) {
|
||||
hashCache *txscript.TxSigHashes,
|
||||
prevOutputFetcher txscript.PrevOutputFetcher, txinIdx int) (*Script,
|
||||
error) {
|
||||
|
||||
desc := h.signDesc
|
||||
desc.SigHashes = hashCache
|
||||
desc.InputIndex = txinIdx
|
||||
desc.PrevOutputFetcher = prevOutputFetcher
|
||||
|
||||
witness, err := SenderHtlcSpendRedeem(
|
||||
signer, &desc, txn, h.preimage,
|
||||
@@ -291,7 +299,9 @@ type HtlcSecondLevelAnchorInput struct {
|
||||
// createWitness creates a witness allowing the passed transaction to
|
||||
// spend the input.
|
||||
createWitness func(signer Signer, txn *wire.MsgTx,
|
||||
hashCache *txscript.TxSigHashes, txinIdx int) (wire.TxWitness, error)
|
||||
hashCache *txscript.TxSigHashes,
|
||||
prevOutputFetcher txscript.PrevOutputFetcher,
|
||||
txinIdx int) (wire.TxWitness, error)
|
||||
}
|
||||
|
||||
// RequiredTxOut returns the tx out needed to be present on the sweep tx for
|
||||
@@ -313,9 +323,12 @@ func (i *HtlcSecondLevelAnchorInput) RequiredLockTime() (uint32, bool) {
|
||||
// method support spending p2wkh, p2wsh, and also nested p2sh outputs.
|
||||
func (i *HtlcSecondLevelAnchorInput) CraftInputScript(signer Signer,
|
||||
txn *wire.MsgTx, hashCache *txscript.TxSigHashes,
|
||||
txinIdx int) (*Script, error) {
|
||||
prevOutputFetcher txscript.PrevOutputFetcher, txinIdx int) (*Script,
|
||||
error) {
|
||||
|
||||
witness, err := i.createWitness(signer, txn, hashCache, txinIdx)
|
||||
witness, err := i.createWitness(
|
||||
signer, txn, hashCache, prevOutputFetcher, txinIdx,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -335,11 +348,13 @@ func MakeHtlcSecondLevelTimeoutAnchorInput(signedTx *wire.MsgTx,
|
||||
// 2nd timeout transaction.
|
||||
createWitness := func(signer Signer, txn *wire.MsgTx,
|
||||
hashCache *txscript.TxSigHashes,
|
||||
prevOutputFetcher txscript.PrevOutputFetcher,
|
||||
txinIdx int) (wire.TxWitness, error) {
|
||||
|
||||
desc := signDetails.SignDesc
|
||||
desc.SigHashes = NewTxSigHashesV0Only(txn)
|
||||
desc.SigHashes = txscript.NewTxSigHashes(txn, prevOutputFetcher)
|
||||
desc.InputIndex = txinIdx
|
||||
desc.PrevOutputFetcher = prevOutputFetcher
|
||||
|
||||
return SenderHtlcSpendTimeout(
|
||||
signDetails.PeerSig, signDetails.SigHashType, signer,
|
||||
@@ -373,11 +388,13 @@ func MakeHtlcSecondLevelSuccessAnchorInput(signedTx *wire.MsgTx,
|
||||
// success transaction.
|
||||
createWitness := func(signer Signer, txn *wire.MsgTx,
|
||||
hashCache *txscript.TxSigHashes,
|
||||
prevOutputFetcher txscript.PrevOutputFetcher,
|
||||
txinIdx int) (wire.TxWitness, error) {
|
||||
|
||||
desc := signDetails.SignDesc
|
||||
desc.SigHashes = hashCache
|
||||
desc.InputIndex = txinIdx
|
||||
desc.PrevOutputFetcher = prevOutputFetcher
|
||||
|
||||
return ReceiverHtlcSpendRedeem(
|
||||
signDetails.PeerSig, signDetails.SigHashType,
|
||||
|
||||
Reference in new issue
Block a user