Skip to content

Commit

Permalink
Fix: Count previous input satoshis (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tíghearnán Carroll committed Apr 5, 2022
1 parent 463d2d2 commit dd08c7f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions spv/ancestors_binary.go
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dd08c7f

Please sign in to comment.