Skip to content

Commit

Permalink
Merge pull request #40 from libsv/fix/ancestry
Browse files Browse the repository at this point in the history
Fix: Transaction Ancestry
  • Loading branch information
roppa authored Apr 5, 2022
2 parents 73c768b + 3af2c73 commit b2c012a
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 92 deletions.
6 changes: 3 additions & 3 deletions data/noop/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func (n noop) PaymentRequest(ctx context.Context, args dpp.PaymentRequestArgs) (
fq.UpdateExpiry(time.Now().Add(10 * time.Hour))
return fq
}(),
Memo: "noop",
PaymentURL: "noop",
SPVRequired: true,
Memo: "noop",
PaymentURL: "noop",
AncestryRequired: true,
MerchantData: &dpp.Merchant{
AvatarURL: "noop",
Name: "noop",
Expand Down
17 changes: 8 additions & 9 deletions data/payd/models/payd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package models
import (
"time"

"github.com/libsv/go-bc/spv"
"github.com/libsv/go-bt/v2"

"github.com/libsv/go-dpp"
)

// PayDPaymentRequest is used to send a payment to PayD for valdiation and storage.
type PayDPaymentRequest struct {
SPVEnvelope *spv.Envelope `json:"spvEnvelope"`
RawTX *string `json:"rawTx"`
Ancestry *string `json:"ancestry"`
RawTx *string `json:"rawTx"`
ProofCallbacks map[string]dpp.ProofCallback `json:"proofCallbacks"`
}

Expand All @@ -24,10 +23,10 @@ type Destination struct {

// DestinationResponse is the response for the destinations api.
type DestinationResponse struct {
SPVRequired bool `json:"spvRequired"`
Network string `json:"network"`
Outputs []Destination `json:"outputs"`
Fees *bt.FeeQuote `json:"fees"`
CreatedAt time.Time `json:"createdAt"`
ExpiresAt time.Time `json:"expiresAt"`
AncestryRequired bool `json:"ancestryRequired"`
Network string `json:"network"`
Outputs []Destination `json:"outputs"`
Fees *bt.FeeQuote `json:"fees"`
CreatedAt time.Time `json:"createdAt"`
ExpiresAt time.Time `json:"expiresAt"`
}
4 changes: 2 additions & 2 deletions data/payd/payd.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func (p *payd) PaymentRequest(ctx context.Context, args dpp.PaymentRequestArgs)
// If invalid a non 204 status code is returned.
func (p *payd) PaymentCreate(ctx context.Context, args dpp.PaymentCreateArgs, req dpp.Payment) (*dpp.PaymentACK, error) {
paymentReq := models.PayDPaymentRequest{
RawTX: req.RawTX,
SPVEnvelope: req.SPVEnvelope,
RawTx: req.RawTx,
Ancestry: req.Ancestry,
ProofCallbacks: req.ProofCallbacks,
}
var ack dpp.PaymentACK
Expand Down
39 changes: 16 additions & 23 deletions data/payd/payd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/libsv/dpp-proxy/data/payd"
"github.com/libsv/dpp-proxy/data/payd/models"
"github.com/libsv/dpp-proxy/mocks"
"github.com/libsv/go-bc/spv"
"github.com/libsv/go-bt/v2"
"github.com/libsv/go-bt/v2/bscript"
"github.com/libsv/go-dpp"
Expand All @@ -36,15 +35,13 @@ func TestPayd_PaymentCreate(t *testing.T) {
PaymentID: "qwe123",
},
req: dpp.Payment{
RawTX: func() *string { s := "rawrawraw"; return &s }(),
SPVEnvelope: &spv.Envelope{},
RawTx: func() *string { s := "rawrawraw"; return &s }(),
ProofCallbacks: map[string]dpp.ProofCallback{
"abc.com": {Token: "mYtOkEn"},
},
},
expReq: models.PayDPaymentRequest{
RawTX: func() *string { s := "rawrawraw"; return &s }(),
SPVEnvelope: &spv.Envelope{},
RawTx: func() *string { s := "rawrawraw"; return &s }(),
ProofCallbacks: map[string]dpp.ProofCallback{
"abc.com": {Token: "mYtOkEn"},
},
Expand All @@ -63,15 +60,13 @@ func TestPayd_PaymentCreate(t *testing.T) {
PaymentID: "qwe123",
},
req: dpp.Payment{
RawTX: func() *string { s := "rawrawraw"; return &s }(),
SPVEnvelope: &spv.Envelope{},
RawTx: func() *string { s := "rawrawraw"; return &s }(),
ProofCallbacks: map[string]dpp.ProofCallback{
"abc.com": {Token: "mYtOkEn"},
},
},
expReq: models.PayDPaymentRequest{
RawTX: func() *string { s := "rawrawraw"; return &s }(),
SPVEnvelope: &spv.Envelope{},
RawTx: func() *string { s := "rawrawraw"; return &s }(),
ProofCallbacks: map[string]dpp.ProofCallback{
"abc.com": {Token: "mYtOkEn"},
},
Expand All @@ -91,15 +86,13 @@ func TestPayd_PaymentCreate(t *testing.T) {
PaymentID: "qwe123",
},
req: dpp.Payment{
RawTX: func() *string { s := "rawrawraw"; return &s }(),
SPVEnvelope: &spv.Envelope{},
RawTx: func() *string { s := "rawrawraw"; return &s }(),
ProofCallbacks: map[string]dpp.ProofCallback{
"abc.com": {Token: "mYtOkEn"},
},
},
expReq: models.PayDPaymentRequest{
RawTX: func() *string { s := "rawrawraw"; return &s }(),
SPVEnvelope: &spv.Envelope{},
RawTx: func() *string { s := "rawrawraw"; return &s }(),
ProofCallbacks: map[string]dpp.ProofCallback{
"abc.com": {Token: "mYtOkEn"},
},
Expand Down Expand Up @@ -148,7 +141,7 @@ func TestPayd_PaymentRequest(t *testing.T) {
return json.Unmarshal([]byte(`
{
"network": "mainnet",
"spvRequired": true,
"ancestryRequired": true,
"destinations": {
"outputs": [
{
Expand Down Expand Up @@ -210,10 +203,10 @@ func TestPayd_PaymentRequest(t *testing.T) {
},
expURL: "http://payddest:445/api/v1/payments/qwe123",
expPaymentReq: &dpp.PaymentRequest{
SPVRequired: true,
Network: "mainnet",
Memo: "invoice 6K9oZq9",
PaymentURL: "http://dpp:8445/api/v1/payment/6K9oZq9",
AncestryRequired: true,
Network: "mainnet",
Memo: "invoice 6K9oZq9",
PaymentURL: "http://dpp:8445/api/v1/payment/6K9oZq9",
Destinations: dpp.PaymentDestinations{
Outputs: []dpp.Output{{
LockingScript: func() *bscript.Script {
Expand Down Expand Up @@ -252,7 +245,7 @@ func TestPayd_PaymentRequest(t *testing.T) {
return json.Unmarshal([]byte(`
{
"network": "mainnet",
"spvRequired": true,
"ancestryRequired": true,
"destinations": {
"outputs": [
{
Expand Down Expand Up @@ -315,10 +308,10 @@ func TestPayd_PaymentRequest(t *testing.T) {
},
expURL: "https://securepayddest:4445/api/v1/payments/bwe123",
expPaymentReq: &dpp.PaymentRequest{
SPVRequired: true,
Network: "mainnet",
Memo: "invoice 6K9oZq9",
PaymentURL: "https://dpp:8445/api/v1/payment/6K9oZq9",
AncestryRequired: true,
Network: "mainnet",
Memo: "invoice 6K9oZq9",
PaymentURL: "https://dpp:8445/api/v1/payment/6K9oZq9",
Destinations: dpp.PaymentDestinations{
Outputs: []dpp.Output{{
LockingScript: func() *bscript.Script {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/libsv/go-bc v0.1.9
github.com/libsv/go-bk v0.1.6
github.com/libsv/go-bt/v2 v2.1.0-beta.2
github.com/libsv/go-dpp v0.0.9
github.com/libsv/go-dpp v0.1.11
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.1
github.com/rs/zerolog v1.26.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ github.com/libsv/go-bt/v2 v2.1.0-beta.2 h1:oq6BQQtNeZiG/esfoY/7RyYF+dDj996xqNfvo
github.com/libsv/go-bt/v2 v2.1.0-beta.2/go.mod h1:u5g3GmVLffBV8sWvMqHR3JekC51OR9XYvmQp1h/XoiQ=
github.com/libsv/go-dpp v0.0.9 h1:Sm9udJ4n9x7/3WSGjdB0+R7SZKJBIltI6Qnji/VgISY=
github.com/libsv/go-dpp v0.0.9/go.mod h1:VZ4BSG12xv5KHeqdz4tPDYcwVkAFmfDXO4zJ2t9bsyI=
github.com/libsv/go-dpp v0.0.10-0.20220404121630-0c117ccbe02a h1:wRtlK0r2681PYRQJOCwb9YGmJXwmsAOU0pYLaVnX3HE=
github.com/libsv/go-dpp v0.0.10-0.20220404121630-0c117ccbe02a/go.mod h1:VZ4BSG12xv5KHeqdz4tPDYcwVkAFmfDXO4zJ2t9bsyI=
github.com/libsv/go-dpp v0.1.11 h1:K3fpykSin7L5s8SghkLSivACuimagdbCdHXHb5ZrrRQ=
github.com/libsv/go-dpp v0.1.11/go.mod h1:nc9Lh987LXHc8+pE3k3ThMWvQQft9JSboFQF1elfRFs=
github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w=
github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
Expand Down
24 changes: 11 additions & 13 deletions service/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service_test

import (
"context"
"encoding/hex"
"errors"
"testing"

Expand All @@ -25,10 +26,13 @@ func TestPayment_Create(t *testing.T) {
return &dpp.PaymentACK{}, nil
},
req: dpp.Payment{
SPVEnvelope: &spv.Envelope{
RawTx: "01000000000000000000",
TxID: "d21633ba23f70118185227be58a63527675641ad37967e2aa461559f577aec43",
},
Ancestry: func() *string {
s := &spv.Envelope{}
bb, _ := s.Bytes()
ss := hex.EncodeToString(bb)
return &ss
}(),
RawTx: func() *string { s := "01000000000000000000"; return &s }(),
MerchantData: dpp.Merchant{
ExtendedData: map[string]interface{}{"paymentReference": "omgwow"},
},
Expand All @@ -43,10 +47,7 @@ func TestPayment_Create(t *testing.T) {
},
args: dpp.PaymentCreateArgs{},
req: dpp.Payment{
SPVEnvelope: &spv.Envelope{
RawTx: "01000000000000000000",
TxID: "d21633ba23f70118185227be58a63527675641ad37967e2aa461559f577aec43",
},
RawTx: func() *string { s := "01000000000000000000"; return &s }(),
MerchantData: dpp.Merchant{
ExtendedData: map[string]interface{}{"paymentReference": "omgwow"},
},
Expand All @@ -65,7 +66,7 @@ func TestPayment_Create(t *testing.T) {
ExtendedData: map[string]interface{}{"paymentReference": "omgwow"},
},
},
expErr: errors.New("[spvEnvelope/rawTx: either an SPVEnvelope or a rawTX are required]"),
expErr: errors.New("[ancestry/rawTx: either ancestry or a rawTX are required]"),
},
"error on payment create is handled": {
paymentCreateFn: func(context.Context, dpp.PaymentCreateArgs, dpp.Payment) (*dpp.PaymentACK, error) {
Expand All @@ -75,10 +76,7 @@ func TestPayment_Create(t *testing.T) {
PaymentID: "abc123",
},
req: dpp.Payment{
SPVEnvelope: &spv.Envelope{
RawTx: "01000000000000000000",
TxID: "d21633ba23f70118185227be58a63527675641ad37967e2aa461559f577aec43",
},
RawTx: func() *string { s := "01000000000000000000"; return &s }(),
MerchantData: dpp.Merchant{
ExtendedData: map[string]interface{}{"paymentReference": "omgwow"},
},
Expand Down
8 changes: 4 additions & 4 deletions service/paymentrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestPaymentRequest_PaymentRequest(t *testing.T) {
},
paymentRequestFunc: func(context.Context, dpp.PaymentRequestArgs) (*dpp.PaymentRequest, error) {
return &dpp.PaymentRequest{
SPVRequired: false,
AncestryRequired: false,
CreationTimestamp: created,
ExpirationTimestamp: expired,
Destinations: dpp.PaymentDestinations{
Expand All @@ -49,7 +49,7 @@ func TestPaymentRequest_PaymentRequest(t *testing.T) {
}, nil
},
expResp: &dpp.PaymentRequest{
SPVRequired: false,
AncestryRequired: false,
CreationTimestamp: created,
ExpirationTimestamp: expired,
Destinations: dpp.PaymentDestinations{
Expand All @@ -75,7 +75,7 @@ func TestPaymentRequest_PaymentRequest(t *testing.T) {
},
paymentRequestFunc: func(context.Context, dpp.PaymentRequestArgs) (*dpp.PaymentRequest, error) {
return &dpp.PaymentRequest{
SPVRequired: false,
AncestryRequired: false,
CreationTimestamp: created,
ExpirationTimestamp: expired,
Destinations: dpp.PaymentDestinations{
Expand All @@ -94,7 +94,7 @@ func TestPaymentRequest_PaymentRequest(t *testing.T) {
}, nil
},
expResp: &dpp.PaymentRequest{
SPVRequired: false,
AncestryRequired: false,
CreationTimestamp: created,
ExpirationTimestamp: expired,
Destinations: dpp.PaymentDestinations{
Expand Down
12 changes: 6 additions & 6 deletions vendor/github.com/libsv/go-dpp/destinations.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 11 additions & 28 deletions vendor/github.com/libsv/go-dpp/payment.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/github.com/libsv/go-dpp/payment_request.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ github.com/libsv/go-bk/envelope
github.com/libsv/go-bt/v2
github.com/libsv/go-bt/v2/bscript
github.com/libsv/go-bt/v2/sighash
# github.com/libsv/go-dpp v0.0.9
# github.com/libsv/go-dpp v0.1.11
## explicit; go 1.17
github.com/libsv/go-dpp
github.com/libsv/go-dpp/mocks
Expand Down

0 comments on commit b2c012a

Please sign in to comment.