Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

Commit 9289aa1

Browse files
committed
Send routing information in receive hook params - close #22
1 parent d27c44a commit 9289aa1

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

readme_bridge.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ name | description
382382
--- | ---
383383
`id` | Operation ID
384384
`from` | Account ID of the sender
385-
`route` | The recipient ID at the receiving FI. This will be the routing information containd in the memo.
385+
`route` | The recipient ID at the receiving FI. This will be the routing information contained in the memo or memo value if no compliance server is connected or memo type is not `hash`.
386386
`amount` | Amount that was sent
387387
`asset_code` | Code of the asset sent (ex. `USD`)
388388
`memo_type` | Type of the memo attached to the transaction. This field will be empty when no memo was attached.

src/github.com/stellar/gateway/listener/payment_listener.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/stellar/gateway/horizon"
1717
"github.com/stellar/gateway/net"
1818
"github.com/stellar/gateway/protocols/compliance"
19+
"github.com/stellar/gateway/protocols/memo"
1920
)
2021

2122
// PaymentListener is listening for a new payments received by ReceivingAccount
@@ -190,11 +191,24 @@ func (pl PaymentListener) onPayment(payment horizon.PaymentResponse) (err error)
190191
pl.log.WithFields(logrus.Fields{"err": err}).Error("Cannot unmarshal receiveResponse")
191192
return err
192193
}
193-
}else
194-
{
195-
if payment.Memo.Type != "hash" {
196-
route=string(payment.Memo.Value)
194+
195+
var authData compliance.AuthData
196+
err = json.Unmarshal([]byte(receiveResponse.Data), &authData)
197+
if err != nil {
198+
pl.log.WithFields(logrus.Fields{"err": err}).Error("Cannot unmarshal authData")
199+
return err
200+
}
201+
202+
var memo memo.Memo
203+
err = json.Unmarshal([]byte(authData.Memo), &memo)
204+
if err != nil {
205+
pl.log.WithFields(logrus.Fields{"err": err}).Error("Cannot unmarshal memo")
206+
return err
197207
}
208+
209+
route = memo.Transaction.Route
210+
} else if payment.Memo.Type != "hash" {
211+
route = payment.Memo.Value
198212
}
199213

200214
resp, err := pl.client.PostForm(

src/github.com/stellar/gateway/listener/payment_listener_test.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package listener
22

33
import (
4+
"encoding/json"
45
"errors"
56
"net/url"
67
"testing"
@@ -12,6 +13,8 @@ import (
1213
"github.com/stellar/gateway/horizon"
1314
"github.com/stellar/gateway/mocks"
1415
"github.com/stellar/gateway/net"
16+
"github.com/stellar/gateway/protocols/compliance"
17+
"github.com/stellar/gateway/protocols/memo"
1518
"github.com/stretchr/testify/assert"
1619
)
1720

@@ -165,6 +168,7 @@ func TestPaymentListener(t *testing.T) {
165168
url.Values{
166169
"id": {"1"},
167170
"from": {"GBIHSMPXC2KJ3NJVHEYTG3KCHYEUQRT45X6AWYWXMAXZOAX4F5LFZYYQ"},
171+
"route": {"testing"},
168172
"amount": {"200"},
169173
"asset_code": {"USD"},
170174
"memo_type": {"text"},
@@ -204,6 +208,7 @@ func TestPaymentListener(t *testing.T) {
204208
url.Values{
205209
"id": {"1"},
206210
"from": {"GBIHSMPXC2KJ3NJVHEYTG3KCHYEUQRT45X6AWYWXMAXZOAX4F5LFZYYQ"},
211+
"route": {"testing"},
207212
"amount": {"200"},
208213
"asset_code": {"USD"},
209214
"memo_type": {"text"},
@@ -241,6 +246,7 @@ func TestPaymentListener(t *testing.T) {
241246
url.Values{
242247
"id": {"1"},
243248
"from": {"GBIHSMPXC2KJ3NJVHEYTG3KCHYEUQRT45X6AWYWXMAXZOAX4F5LFZYYQ"},
249+
"route": {""},
244250
"amount": {"200"},
245251
"asset_code": {"USD"},
246252
"memo_type": {""},
@@ -276,12 +282,32 @@ func TestPaymentListener(t *testing.T) {
276282
mockHorizon.On("LoadMemo", &operation).Return(nil).Once()
277283
mockEntityManager.On("Persist", &dbPayment).Return(nil).Once()
278284

285+
memo := memo.Memo{
286+
Transaction: memo.Transaction{
287+
Route: "jed*stellar.org",
288+
},
289+
}
290+
291+
memoString, _ := json.Marshal(memo)
292+
293+
auth := compliance.AuthData{
294+
Memo: string(memoString),
295+
}
296+
297+
authString, _ := json.Marshal(auth)
298+
299+
response := compliance.ReceiveResponse{
300+
Data: string(authString),
301+
}
302+
303+
responseString, _ := json.Marshal(response)
304+
279305
mockHTTPClient.On(
280306
"PostForm",
281307
"http://compliance/receive",
282308
url.Values{"memo": {"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"}},
283309
).Return(
284-
net.BuildHTTPResponse(200, "{\"data\": \"hello world\"}"),
310+
net.BuildHTTPResponse(200, string(responseString)),
285311
nil,
286312
).Once()
287313

@@ -291,11 +317,12 @@ func TestPaymentListener(t *testing.T) {
291317
url.Values{
292318
"id": {"1"},
293319
"from": {"GBIHSMPXC2KJ3NJVHEYTG3KCHYEUQRT45X6AWYWXMAXZOAX4F5LFZYYQ"},
320+
"route": {"jed*stellar.org"},
294321
"amount": {"200"},
295322
"asset_code": {"USD"},
296323
"memo_type": {"hash"},
297324
"memo": {"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"},
298-
"data": {"hello world"},
325+
"data": {string(authString)},
299326
},
300327
).Return(
301328
net.BuildHTTPResponse(200, "ok"),

0 commit comments

Comments
 (0)