From dd08c7f0f1a52176ebdeac9448c5d87c437e50a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=ADghearn=C3=A1n=20Carroll?= Date: Tue, 5 Apr 2022 10:41:26 +0100 Subject: [PATCH] Fix: Count previous input satoshis (#43) --- spv/ancestors_binary.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spv/ancestors_binary.go b/spv/ancestors_binary.go index c86da3a..8497851 100644 --- a/spv/ancestors_binary.go +++ b/spv/ancestors_binary.go @@ -6,6 +6,7 @@ import ( "github.com/libsv/go-bk/crypto" "github.com/libsv/go-bt/v2" "github.com/libsv/go-bt/v2/bscript" + "github.com/pkg/errors" "github.com/libsv/go-bc" ) @@ -153,6 +154,21 @@ func VerifyAncestors(ctx context.Context, ancestry *Ancestry, mpv MerkleProofVer if opts.feeQuote == nil { return ErrNoFeeQuoteSupplied } + for i, input := range ancestry.PaymentTx.Inputs { + var inputID [32]byte + copy(inputID[:], input.PreviousTxID()) + parent, ok := ancestry.Ancestors[inputID] + if !ok { + return errors.Wrapf(ErrNoFeeQuoteSupplied, "missing tx for input %d", i) + } + + out := parent.Tx.OutputIdx(int(input.PreviousTxOutIndex)) + if out == nil { + return ErrMissingOutput + } + + input.PreviousTxSatoshis = out.Satoshis + } ok, err := ancestry.PaymentTx.IsFeePaidEnough(opts.feeQuote) if err != nil { return err