Skip to content

Commit

Permalink
Fix: Forward payd PaymentACK response (bitcoin-sv#24)
Browse files Browse the repository at this point in the history
* forward payd response for payment send

* build
  • Loading branch information
Tíghearnán Carroll authored Feb 7, 2022
1 parent 6e8a1fc commit 7325ae2
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 202 deletions.
7 changes: 4 additions & 3 deletions data/noop/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/libsv/go-bt/v2"
"github.com/libsv/go-bt/v2/bscript"
"github.com/libsv/p4-server/log"

"github.com/libsv/go-p4"
Expand Down Expand Up @@ -52,9 +53,9 @@ func (n noop) PaymentRequest(ctx context.Context, args p4.PaymentRequestArgs) (*
},
Destinations: p4.PaymentDestinations{
Outputs: []p4.Output{{
Amount: 0,
Script: "noop",
Description: "noop",
Amount: 0,
LockingScript: &bscript.Script{},
Description: "noop",
}},
},
}, nil
Expand Down
8 changes: 3 additions & 5 deletions data/payd/payd.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ func (p *payd) PaymentCreate(ctx context.Context, args p4.PaymentCreateArgs, req
SPVEnvelope: req.SPVEnvelope,
ProofCallbacks: req.ProofCallbacks,
}
if err := p.client.Do(ctx, http.MethodPost, fmt.Sprintf(urlPayments, p.baseURL(), args.PaymentID), http.StatusNoContent, paymentReq, nil); err != nil {
var ack p4.PaymentACK
if err := p.client.Do(ctx, http.MethodPost, fmt.Sprintf(urlPayments, p.baseURL(), args.PaymentID), http.StatusNoContent, paymentReq, &ack); err != nil {
return nil, err
}
return &p4.PaymentACK{
Memo: req.Memo,
Payment: &req,
}, nil
return &ack, nil
}

// ProofCreate will pass on the proof to a payd instance for storage.
Expand Down
25 changes: 21 additions & 4 deletions data/payd/payd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/libsv/go-bc/spv"
"github.com/libsv/go-bt/v2"
"github.com/libsv/go-bt/v2/bscript"
"github.com/libsv/go-p4"
"github.com/libsv/p4-server/config"
"github.com/libsv/p4-server/data/payd"
Expand Down Expand Up @@ -215,10 +216,18 @@ func TestPayd_PaymentRequest(t *testing.T) {
PaymentURL: "http://p4:8445/api/v1/payment/6K9oZq9",
Destinations: p4.PaymentDestinations{
Outputs: []p4.Output{{
Script: "525252",
LockingScript: func() *bscript.Script {
ls, err := bscript.NewFromHexString("525252")
assert.NoError(t, err)
return ls
}(),
Amount: 100,
}, {
Script: "535353",
LockingScript: func() *bscript.Script {
ls, err := bscript.NewFromHexString("535353")
assert.NoError(t, err)
return ls
}(),
Amount: 400,
}},
},
Expand Down Expand Up @@ -312,10 +321,18 @@ func TestPayd_PaymentRequest(t *testing.T) {
PaymentURL: "https://p4:8445/api/v1/payment/6K9oZq9",
Destinations: p4.PaymentDestinations{
Outputs: []p4.Output{{
Script: "525252",
LockingScript: func() *bscript.Script {
ls, err := bscript.NewFromHexString("525252")
assert.NoError(t, err)
return ls
}(),
Amount: 100,
}, {
Script: "535353",
LockingScript: func() *bscript.Script {
ls, err := bscript.NewFromHexString("535353")
assert.NoError(t, err)
return ls
}(),
Amount: 400,
}},
},
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.8
github.com/libsv/go-bk v0.1.6
github.com/libsv/go-bt/v2 v2.1.0-beta.2
github.com/libsv/go-p4 v0.0.7
github.com/libsv/go-p4 v0.0.8
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.1
github.com/rs/zerolog v1.26.0
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,15 @@ github.com/labstack/echo/v4 v4.6.3/go.mod h1:Hk5OiHj0kDqmFq7aHe7eDqI7CUhuCrfpupQ
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o=
github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/libsv/go-bc v0.1.7/go.mod h1:IZuBIf65nlLY1OR/oXGOW/AgVvO5hGhIhRZPiHAiVHU=
github.com/libsv/go-bc v0.1.8 h1:sn0zz9nyaC0oRNYfRiNgt0ceCAjN4QeJXherfo1o7QI=
github.com/libsv/go-bc v0.1.8/go.mod h1:4YMpWv9xxg/tt+y1jP9HxIh+2fiZno4+UIh78wi1Vwk=
github.com/libsv/go-bk v0.1.4/go.mod h1:xbDkeFFpP0uyFaPLnP6TwaLpAsHaslZ0LftTdWlB6HI=
github.com/libsv/go-bk v0.1.5/go.mod h1:xbDkeFFpP0uyFaPLnP6TwaLpAsHaslZ0LftTdWlB6HI=
github.com/libsv/go-bk v0.1.6 h1:c9CiT5+64HRDbzxPl1v/oiFmbvWZTuUYqywCf+MBs/c=
github.com/libsv/go-bk v0.1.6/go.mod h1:khJboDoH18FPUaZlzRFKzlVN84d4YfdmlDtdX4LAjQA=
github.com/libsv/go-bt/v2 v2.0.0-beta.7/go.mod h1:6Vk1qMlMoFJFNm7rR7NmFx4VwHNMCi4+V9WBqTd37rQ=
github.com/libsv/go-bt/v2 v2.0.0-beta.13/go.mod h1:u5g3GmVLffBV8sWvMqHR3JekC51OR9XYvmQp1h/XoiQ=
github.com/libsv/go-bt/v2 v2.1.0-beta.2 h1:oq6BQQtNeZiG/esfoY/7RyYF+dDj996xqNfvoQfH6n4=
github.com/libsv/go-bt/v2 v2.1.0-beta.2/go.mod h1:u5g3GmVLffBV8sWvMqHR3JekC51OR9XYvmQp1h/XoiQ=
github.com/libsv/go-p4 v0.0.7 h1:zKrNUNQ1zL6T5prxWu7LkxXQ5ysBHDL1RH8Ziu6f9kQ=
github.com/libsv/go-p4 v0.0.7/go.mod h1:neXEtCQkbdYbB35sMZ8BBA1NK4/uENZ+MhfiM1qzeBM=
github.com/libsv/go-p4 v0.0.8 h1:JHybpU6+cbOz0M+6v2S85BzzTedE1CNuzNbut3bB8ds=
github.com/libsv/go-p4 v0.0.8/go.mod h1:1AzWDmB9aYsPRtlY8APVCtLnwaCedoPELrgG8a5FSZQ=
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
25 changes: 21 additions & 4 deletions service/paymentrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
"time"

"github.com/libsv/go-bt/v2/bscript"
"github.com/libsv/go-p4"
p4mocks "github.com/libsv/go-p4/mocks"
"github.com/libsv/p4-server/service"
Expand Down Expand Up @@ -33,7 +34,11 @@ func TestPaymentRequest_PaymentRequest(t *testing.T) {
Destinations: p4.PaymentDestinations{
Outputs: []p4.Output{{
Amount: 500,
Script: "abc123",
LockingScript: func() *bscript.Script {
ls, err := bscript.NewFromHexString("abc123")
assert.NoError(t, err)
return ls
}(),
}},
},
PaymentURL: "http://iamsotest/api/v1/payment/abc123",
Expand All @@ -50,7 +55,11 @@ func TestPaymentRequest_PaymentRequest(t *testing.T) {
Destinations: p4.PaymentDestinations{
Outputs: []p4.Output{{
Amount: 500,
Script: "abc123",
LockingScript: func() *bscript.Script {
ls, err := bscript.NewFromHexString("abc123")
assert.NoError(t, err)
return ls
}(),
}},
},
PaymentURL: "http://iamsotest/api/v1/payment/abc123",
Expand All @@ -72,7 +81,11 @@ func TestPaymentRequest_PaymentRequest(t *testing.T) {
Destinations: p4.PaymentDestinations{
Outputs: []p4.Output{{
Amount: 500,
Script: "abc123",
LockingScript: func() *bscript.Script {
ls, err := bscript.NewFromHexString("abc123")
assert.NoError(t, err)
return ls
}(),
}},
},
MerchantData: &p4.Merchant{},
Expand All @@ -87,7 +100,11 @@ func TestPaymentRequest_PaymentRequest(t *testing.T) {
Destinations: p4.PaymentDestinations{
Outputs: []p4.Output{{
Amount: 500,
Script: "abc123",
LockingScript: func() *bscript.Script {
ls, err := bscript.NewFromHexString("abc123")
assert.NoError(t, err)
return ls
}(),
}},
},
PaymentURL: "http://iamsotest/api/v1/payment/abc123",
Expand Down
9 changes: 2 additions & 7 deletions vendor/github.com/libsv/go-p4/destinations.go

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

10 changes: 0 additions & 10 deletions vendor/github.com/libsv/go-p4/merchant.go

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

81 changes: 0 additions & 81 deletions vendor/github.com/libsv/go-p4/mocks/destination_reader.go

This file was deleted.

75 changes: 0 additions & 75 deletions vendor/github.com/libsv/go-p4/mocks/merchant_reader.go

This file was deleted.

2 changes: 0 additions & 2 deletions vendor/github.com/libsv/go-p4/mocks/mocks.go

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

Loading

0 comments on commit 7325ae2

Please sign in to comment.