Skip to content

Commit 17b3442

Browse files
authored
Merge pull request #143 from libsv/fix/ancestry
Feature: Transaction Ancestory
2 parents 73f8dee + 12df91b commit 17b3442

20 files changed

+273
-410
lines changed

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ require (
3131
require (
3232
github.com/google/uuid v1.3.0
3333
github.com/gorilla/websocket v1.5.0
34-
github.com/libsv/go-bc v0.1.8
34+
github.com/libsv/go-bc v0.1.10
3535
github.com/rs/zerolog v1.26.1
3636
github.com/theflyingcodr/sockets v0.0.11-beta.0.20220225103542-c6eecb16f586
3737
)
@@ -92,7 +92,7 @@ require (
9292

9393
require (
9494
github.com/InVisionApp/go-health/v2 v2.1.2
95-
github.com/libsv/go-dpp v0.0.9
95+
github.com/libsv/go-dpp v0.1.11
9696
github.com/libsv/go-spvchannels v0.0.2
9797
)
9898

go.sum

+12
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,12 @@ github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E=
514514
github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
515515
github.com/libsv/go-bc v0.1.8 h1:sn0zz9nyaC0oRNYfRiNgt0ceCAjN4QeJXherfo1o7QI=
516516
github.com/libsv/go-bc v0.1.8/go.mod h1:4YMpWv9xxg/tt+y1jP9HxIh+2fiZno4+UIh78wi1Vwk=
517+
github.com/libsv/go-bc v0.1.9 h1:dTCGLUs3SiolKN5LpNPBTGCEl/HHaGB+hwZRkNfhDJE=
518+
github.com/libsv/go-bc v0.1.9/go.mod h1:55OsjWtvaIEXy4w02icUi2lIdThuwqkAiSeF4GPU5tw=
519+
github.com/libsv/go-bc v0.1.10-0.20220405091049-8313f23e03aa h1:pjp+AkTohM3CBrB0aL3xf09TliJu86EblV5AEum8maE=
520+
github.com/libsv/go-bc v0.1.10-0.20220405091049-8313f23e03aa/go.mod h1:55OsjWtvaIEXy4w02icUi2lIdThuwqkAiSeF4GPU5tw=
521+
github.com/libsv/go-bc v0.1.10 h1:pe3CriFVcHauoQSk8rJeC3/7BOgTqfp33LBb0M4SSi8=
522+
github.com/libsv/go-bc v0.1.10/go.mod h1:55OsjWtvaIEXy4w02icUi2lIdThuwqkAiSeF4GPU5tw=
517523
github.com/libsv/go-bk v0.1.5/go.mod h1:xbDkeFFpP0uyFaPLnP6TwaLpAsHaslZ0LftTdWlB6HI=
518524
github.com/libsv/go-bk v0.1.6 h1:c9CiT5+64HRDbzxPl1v/oiFmbvWZTuUYqywCf+MBs/c=
519525
github.com/libsv/go-bk v0.1.6/go.mod h1:khJboDoH18FPUaZlzRFKzlVN84d4YfdmlDtdX4LAjQA=
@@ -523,6 +529,12 @@ github.com/libsv/go-bt/v2 v2.1.0-beta.2 h1:oq6BQQtNeZiG/esfoY/7RyYF+dDj996xqNfvo
523529
github.com/libsv/go-bt/v2 v2.1.0-beta.2/go.mod h1:u5g3GmVLffBV8sWvMqHR3JekC51OR9XYvmQp1h/XoiQ=
524530
github.com/libsv/go-dpp v0.0.9 h1:Sm9udJ4n9x7/3WSGjdB0+R7SZKJBIltI6Qnji/VgISY=
525531
github.com/libsv/go-dpp v0.0.9/go.mod h1:VZ4BSG12xv5KHeqdz4tPDYcwVkAFmfDXO4zJ2t9bsyI=
532+
github.com/libsv/go-dpp v0.0.10-0.20220404121630-0c117ccbe02a h1:wRtlK0r2681PYRQJOCwb9YGmJXwmsAOU0pYLaVnX3HE=
533+
github.com/libsv/go-dpp v0.0.10-0.20220404121630-0c117ccbe02a/go.mod h1:VZ4BSG12xv5KHeqdz4tPDYcwVkAFmfDXO4zJ2t9bsyI=
534+
github.com/libsv/go-dpp v0.0.10 h1:rQcWKkVlWl8ud4s0uqOJ/hEyDG+oPxP/jbJZmISYdKw=
535+
github.com/libsv/go-dpp v0.0.10/go.mod h1:nc9Lh987LXHc8+pE3k3ThMWvQQft9JSboFQF1elfRFs=
536+
github.com/libsv/go-dpp v0.1.11 h1:K3fpykSin7L5s8SghkLSivACuimagdbCdHXHb5ZrrRQ=
537+
github.com/libsv/go-dpp v0.1.11/go.mod h1:nc9Lh987LXHc8+pE3k3ThMWvQQft9JSboFQF1elfRFs=
526538
github.com/libsv/go-spvchannels v0.0.2 h1:WkhJZmVQftNVSYFJjkXTf+78IC0jX6jBYKnWrVm57+E=
527539
github.com/libsv/go-spvchannels v0.0.2/go.mod h1:J2uSn4X/Eq3BIEfmGtuhAHZUxyUIQydpxSZFyEIb8D0=
528540
github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w=

mocks/p4.go mocks/dpp.go

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/payment_verifier.go

+28-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

payment_request.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type PaymentRequestResponse struct {
3030
Memo string `json:"memo"`
3131
MerchantData User `json:"merchantData"`
3232
Fee *bt.FeeQuote `json:"fees"`
33-
SPVRequired bool `json:"spvRequired" example:"true"`
33+
AncestryRequired bool `json:"ancestryRequired" example:"true"`
3434
}
3535

3636
// PaymentRequestService will create and return a paymentRequest using the args provided.

service/envelopes.go

+4-12
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,10 @@ func (e *envelopes) Envelope(ctx context.Context, args payd.EnvelopeArgs, req dp
115115
return nil, errors.Wrapf(err, "failed to sign tx %s", tx.String())
116116
}
117117

118-
spvEnvelope := &spv.Envelope{
119-
RawTx: tx.String(),
120-
TxID: tx.TxID(),
121-
}
122-
123-
if req.SPVRequired {
124-
// Create the spv envelope for the tx.
125-
s, err := e.spvc.CreateEnvelope(ctx, tx)
126-
if err != nil {
127-
return nil, errors.Wrapf(err, "failed to create spv envelope for tx %s", tx.String())
128-
}
129-
spvEnvelope = s
118+
// Create the spv envelope for the tx.
119+
spvEnvelope, err := e.spvc.CreateEnvelope(ctx, tx)
120+
if err != nil {
121+
return nil, errors.Wrapf(err, "failed to create spv envelope for tx %s", tx.String())
130122
}
131123

132124
txCreate := payd.TransactionCreate{

service/pay.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package service
22

33
import (
44
"context"
5+
"encoding/hex"
56
"fmt"
67

78
"github.com/libsv/go-bk/bip32"
@@ -91,9 +92,15 @@ func (p *pay) Pay(ctx context.Context, req payd.PayRequest) (*dpp.PaymentACK, er
9192
if err != nil {
9293
return nil, errors.Wrapf(err, "envelope creation failed for '%s'", req.PayToURL)
9394
}
95+
bb, err := env.Bytes()
96+
if err != nil {
97+
return nil, errors.Wrapf(err, "failed to convert ancestry into bytes for payment '%s'", payReq.PaymentURL)
98+
}
99+
ancestry := hex.EncodeToString(bb)
94100
// Send the payment to the dpp proxy server.
95101
ack, err := p.dpp.PaymentSend(ctx, req, dpp.Payment{
96-
SPVEnvelope: env,
102+
Ancestry: &ancestry,
103+
RawTx: &env.RawTx,
97104
ProofCallbacks: map[string]dpp.ProofCallback{
98105
"https://" + p.svrCfg.Hostname + "/api/v1/proofs/" + env.TxID: {},
99106
},

service/payment_request.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (p *paymentRequest) PaymentRequest(ctx context.Context, args payd.PaymentRe
9797
}
9898
return &payd.PaymentRequestResponse{
9999
Network: string(p.cfg.Network),
100-
SPVRequired: dd.SPVRequired,
100+
AncestryRequired: dd.SPVRequired,
101101
Destinations: payd.DPPDestination{Outputs: oo},
102102
Fee: fees,
103103
CreationTimestamp: dd.CreatedAt,

service/payments.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package service
22

33
import (
44
"context"
5+
"encoding/hex"
56
"fmt"
67
"path"
78
"time"
@@ -80,7 +81,19 @@ func (p *payments) PaymentCreate(ctx context.Context, args payd.PaymentCreateArg
8081
return nil, errs.NewErrUnprocessable("E001", "fee quote has expired, please make a new payment request")
8182
}
8283

83-
tx, err := p.paymentVerify.VerifyPayment(ctx, req.SPVEnvelope, p.paymentVerifyOpts(inv.SPVRequired, fq)...)
84+
tx, err := bt.NewTxFromString(*req.RawTx)
85+
if err != nil {
86+
return nil, errors.Wrap(err, "failed to parse tx")
87+
}
88+
89+
ancestors := []byte{1}
90+
if req.Ancestry != nil {
91+
ancestors, err = hex.DecodeString(*req.Ancestry)
92+
if err != nil {
93+
return nil, errors.Wrap(err, "failed to decode ancestry")
94+
}
95+
}
96+
tx, err = p.paymentVerify.VerifyPayment(ctx, tx, ancestors, p.paymentVerifyOpts(inv.SPVRequired, fq)...)
8497
if err != nil {
8598
if errors.Is(err, spv.ErrFeePaidNotEnough) {
8699
return nil, validator.ErrValidation{
@@ -91,12 +104,11 @@ func (p *payments) PaymentCreate(ctx context.Context, args payd.PaymentCreateArg
91104
}
92105
// map error to a validation error
93106
return nil, validator.ErrValidation{
94-
"spvEnvelope": {
107+
"ancestry": {
95108
err.Error(),
96109
},
97110
}
98111
}
99-
100112
// get destinations
101113
oo, err := p.destRdr.Destinations(ctx, payd.DestinationsArgs{InvoiceID: args.InvoiceID})
102114
if err != nil {
@@ -156,7 +168,7 @@ func (p *payments) PaymentCreate(ctx context.Context, args payd.PaymentCreateArg
156168
InvoiceID: args.InvoiceID,
157169
TxID: txID,
158170
RefundTo: null.StringFromPtr(req.RefundTo),
159-
TxHex: req.SPVEnvelope.RawTx,
171+
TxHex: *req.RawTx,
160172
Outputs: txos,
161173
}); err != nil {
162174
return nil, errors.Wrapf(err, "failed to store transaction for invoiceID '%s'", args.InvoiceID)

0 commit comments

Comments
 (0)