Skip to content

Commit

Permalink
fixed has parents functionality (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
tigh-latte authored Oct 4, 2021
1 parent 240be81 commit 68c2d2e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion spv/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (e *Envelope) IsAnchored() bool {

// HasParents returns true if this envelope has immediate parents.
func (e *Envelope) HasParents() bool {
return e.Parents == nil || len(e.Parents) == 0
return e.Parents != nil && len(e.Parents) > 0
}

// ParentTX will return a parent if found and convert the rawTx to a bt.TX, otherwise a ErrNotAllInputsSupplied error is returned.
Expand Down
6 changes: 3 additions & 3 deletions spv/verifypayment.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (v *verifier) VerifyPayment(ctx context.Context, initialPayment *Envelope,
//
// If there are no parents the method will fail, also, if there are no fees the method will fail.
func (v *verifier) verifyFees(initialPayment *Envelope, tx *bt.Tx, opts *verifyOptions) error {
if initialPayment.HasParents() {
if !initialPayment.HasParents() {
return ErrCannotCalculateFeePaid
}
if opts.feeQuote == nil {
Expand Down Expand Up @@ -90,7 +90,7 @@ func (v *verifier) verifyFees(initialPayment *Envelope, tx *bt.Tx, opts *verifyO

func (v *verifier) verifyTxs(ctx context.Context, payment *Envelope, opts *verifyOptions) error {
// If at the beginning or middle of the tx chain and tx is unconfirmed, fail and error.
if opts.proofs && !payment.IsAnchored() && payment.HasParents() {
if opts.proofs && !payment.IsAnchored() && !payment.HasParents() {
return errors.Wrapf(ErrNoConfirmedTransaction, "tx %s has no confirmed/anchored tx", payment.TxID)
}

Expand All @@ -108,7 +108,7 @@ func (v *verifier) verifyTxs(ctx context.Context, payment *Envelope, opts *verif

// If a Merkle Proof is provided, assume we are at the anchor/beginning of the tx chain.
// Verify and return the result.
if payment.IsAnchored() || payment.HasParents() {
if payment.IsAnchored() || !payment.HasParents() {
if opts.proofs {
return v.verifyTxAnchor(ctx, payment)
}
Expand Down

0 comments on commit 68c2d2e

Please sign in to comment.