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

Commit 7737fd7

Browse files
authored
Merge pull request #49 from stellar/attachment
New Attachment convention
2 parents 04a5ece + b1bc7fa commit 7737fd7

File tree

277 files changed

+5178
-17347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

277 files changed

+5178
-17347
lines changed

src/github.com/stellar/gateway/bridge/app.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import (
1717
"github.com/stellar/gateway/db/drivers/postgres"
1818
"github.com/stellar/gateway/horizon"
1919
"github.com/stellar/gateway/listener"
20-
"github.com/stellar/gateway/protocols/federation"
21-
"github.com/stellar/gateway/protocols/stellartoml"
2220
"github.com/stellar/gateway/server"
2321
"github.com/stellar/gateway/submitter"
22+
"github.com/stellar/go/clients/federation"
23+
"github.com/stellar/go/clients/stellartoml"
2424
"github.com/zenazn/goji"
2525
"github.com/zenazn/goji/web/middleware"
2626
)
@@ -138,11 +138,16 @@ func NewApp(config config.Config, migrateFlag bool) (app *App, err error) {
138138

139139
requestHandler := handlers.RequestHandler{}
140140

141+
federationClient := &federation.Client{
142+
HTTP: http.DefaultClient,
143+
StellarTOML: stellartoml.DefaultClient,
144+
}
145+
141146
err = g.Provide(
142147
&inject.Object{Value: &requestHandler},
143148
&inject.Object{Value: &config},
144-
&inject.Object{Value: &stellartoml.Resolver{}},
145-
&inject.Object{Value: &federation.Resolver{}},
149+
&inject.Object{Value: stellartoml.DefaultClient},
150+
&inject.Object{Value: federationClient},
146151
&inject.Object{Value: &h},
147152
&inject.Object{Value: &ts},
148153
&inject.Object{Value: &paymentListener},

src/github.com/stellar/gateway/bridge/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"errors"
55
"net/url"
66

7-
"github.com/stellar/go-stellar-base/keypair"
7+
"github.com/stellar/go/keypair"
88
)
99

1010
// Config contains config params of the bridge server

src/github.com/stellar/gateway/bridge/handlers/main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ package handlers
22

33
import (
44
"github.com/stellar/gateway/bridge/config"
5+
"github.com/stellar/gateway/external"
56
"github.com/stellar/gateway/horizon"
67
"github.com/stellar/gateway/net"
7-
"github.com/stellar/gateway/protocols/federation"
8-
"github.com/stellar/gateway/protocols/stellartoml"
98
"github.com/stellar/gateway/submitter"
109
)
1110

@@ -14,8 +13,8 @@ type RequestHandler struct {
1413
Config *config.Config `inject:""`
1514
Client net.HTTPClientInterface `inject:""`
1615
Horizon horizon.HorizonInterface `inject:""`
17-
StellarTomlResolver stellartoml.ResolverInterface `inject:""`
18-
FederationResolver federation.ResolverInterface `inject:""`
16+
StellarTomlResolver external.StellarTomlClientInterface `inject:""`
17+
FederationResolver external.FederationClientInterface `inject:""`
1918
TransactionSubmitter submitter.TransactionSubmitterInterface `inject:""`
2019
}
2120

src/github.com/stellar/gateway/bridge/handlers/request_handler_authorize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/stellar/gateway/protocols"
88
"github.com/stellar/gateway/protocols/bridge"
99
"github.com/stellar/gateway/server"
10-
b "github.com/stellar/go-stellar-base/build"
10+
b "github.com/stellar/go/build"
1111
)
1212

1313
// Authorize implements /authorize endpoint

src/github.com/stellar/gateway/bridge/handlers/request_handler_authorize_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/stellar/gateway/mocks"
1616
"github.com/stellar/gateway/net"
1717
"github.com/stellar/gateway/test"
18-
b "github.com/stellar/go-stellar-base/build"
18+
b "github.com/stellar/go/build"
1919
"github.com/stretchr/testify/assert"
2020
)
2121

src/github.com/stellar/gateway/bridge/handlers/request_handler_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/stellar/gateway/protocols"
1010
"github.com/stellar/gateway/protocols/bridge"
1111
"github.com/stellar/gateway/server"
12-
b "github.com/stellar/go-stellar-base/build"
12+
b "github.com/stellar/go/build"
1313
)
1414

1515
// Builder implements /builder endpoint

src/github.com/stellar/gateway/bridge/handlers/request_handler_create_keypair.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
"github.com/stellar/gateway/protocols"
99
"github.com/stellar/gateway/server"
10-
"github.com/stellar/go-stellar-base/keypair"
10+
"github.com/stellar/go/keypair"
1111
)
1212

1313
// KeyPair struct contains key pair public and private key

src/github.com/stellar/gateway/bridge/handlers/request_handler_payment.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import (
1414
"github.com/stellar/gateway/horizon"
1515
"github.com/stellar/gateway/protocols"
1616
"github.com/stellar/gateway/protocols/bridge"
17-
"github.com/stellar/gateway/protocols/compliance"
17+
callback "github.com/stellar/gateway/protocols/compliance"
1818
"github.com/stellar/gateway/server"
19-
"github.com/stellar/go-stellar-base/amount"
20-
b "github.com/stellar/go-stellar-base/build"
21-
"github.com/stellar/go-stellar-base/keypair"
22-
"github.com/stellar/go-stellar-base/xdr"
19+
"github.com/stellar/go/amount"
20+
b "github.com/stellar/go/build"
21+
"github.com/stellar/go/keypair"
22+
"github.com/stellar/go/protocols/compliance"
23+
"github.com/stellar/go/xdr"
2324
)
2425

2526
// Payment implements /payment endpoint
@@ -75,30 +76,30 @@ func (rh *RequestHandler) Payment(w http.ResponseWriter, r *http.Request) {
7576
return
7677
}
7778

78-
var complianceSendResponse compliance.SendResponse
79-
err = json.Unmarshal(body, &complianceSendResponse)
79+
var callbackSendResponse callback.SendResponse
80+
err = json.Unmarshal(body, &callbackSendResponse)
8081
if err != nil {
8182
log.Error("Error unmarshalling from compliance server")
8283
server.Write(w, protocols.InternalServerError)
8384
return
8485
}
8586

86-
if complianceSendResponse.AuthResponse.InfoStatus == compliance.AuthStatusPending ||
87-
complianceSendResponse.AuthResponse.TxStatus == compliance.AuthStatusPending {
88-
log.WithFields(log.Fields{"response": complianceSendResponse}).Info("Compliance response pending")
89-
server.Write(w, bridge.NewPaymentPendingError(complianceSendResponse.AuthResponse.Pending))
87+
if callbackSendResponse.AuthResponse.InfoStatus == compliance.AuthStatusPending ||
88+
callbackSendResponse.AuthResponse.TxStatus == compliance.AuthStatusPending {
89+
log.WithFields(log.Fields{"response": callbackSendResponse}).Info("Compliance response pending")
90+
server.Write(w, bridge.NewPaymentPendingError(callbackSendResponse.AuthResponse.Pending))
9091
return
9192
}
9293

93-
if complianceSendResponse.AuthResponse.InfoStatus == compliance.AuthStatusDenied ||
94-
complianceSendResponse.AuthResponse.TxStatus == compliance.AuthStatusDenied {
95-
log.WithFields(log.Fields{"response": complianceSendResponse}).Info("Compliance response denied")
94+
if callbackSendResponse.AuthResponse.InfoStatus == compliance.AuthStatusDenied ||
95+
callbackSendResponse.AuthResponse.TxStatus == compliance.AuthStatusDenied {
96+
log.WithFields(log.Fields{"response": callbackSendResponse}).Info("Compliance response denied")
9697
server.Write(w, bridge.PaymentDenied)
9798
return
9899
}
99100

100101
var tx xdr.Transaction
101-
err = xdr.SafeUnmarshalBase64(complianceSendResponse.TransactionXdr, &tx)
102+
err = xdr.SafeUnmarshalBase64(callbackSendResponse.TransactionXdr, &tx)
102103
if err != nil {
103104
log.Error("Error unmarshalling transaction returned by compliance server")
104105
server.Write(w, protocols.InternalServerError)
@@ -108,7 +109,7 @@ func (rh *RequestHandler) Payment(w http.ResponseWriter, r *http.Request) {
108109
submitResponse, submitError = rh.TransactionSubmitter.SignAndSubmitRawTransaction(request.Source, &tx)
109110
} else {
110111
// Payment without compliance server
111-
destinationObject, _, err := rh.FederationResolver.Resolve(request.Destination)
112+
destinationObject, err := rh.FederationResolver.LookupByAddress(request.Destination)
112113
if err != nil {
113114
log.WithFields(log.Fields{"destination": request.Destination, "err": err}).Print("Cannot resolve address")
114115
server.Write(w, bridge.PaymentCannotResolveDestination)

src/github.com/stellar/gateway/bridge/handlers/request_handler_payment_test.go

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ import (
1515
"github.com/stellar/gateway/horizon"
1616
"github.com/stellar/gateway/mocks"
1717
"github.com/stellar/gateway/net"
18-
"github.com/stellar/gateway/protocols/compliance"
19-
"github.com/stellar/gateway/protocols/federation"
20-
"github.com/stellar/gateway/protocols/stellartoml"
18+
callback "github.com/stellar/gateway/protocols/compliance"
2119
"github.com/stellar/gateway/test"
22-
"github.com/stellar/go-stellar-base/xdr"
20+
"github.com/stellar/go/protocols/federation"
21+
"github.com/stellar/go/xdr"
2322
"github.com/stretchr/testify/assert"
2423
"github.com/stretchr/testify/mock"
2524
)
@@ -94,11 +93,10 @@ func TestRequestHandlerPayment(t *testing.T) {
9493
}
9594

9695
mockFederationResolver.On(
97-
"Resolve",
96+
"LookupByAddress",
9897
"GD3YBOYIUVLU",
9998
).Return(
100-
federation.Response{AccountID: "GD3YBOYIUVLU"},
101-
stellartoml.StellarToml{},
99+
&federation.NameResponse{AccountID: "GD3YBOYIUVLU"},
102100
nil,
103101
).Once()
104102

@@ -126,11 +124,10 @@ func TestRequestHandlerPayment(t *testing.T) {
126124

127125
Convey("When FederationResolver returns error", func() {
128126
mockFederationResolver.On(
129-
"Resolve",
127+
"LookupByAddress",
130128
"bob*stellar.org",
131129
).Return(
132-
federation.Response{},
133-
stellartoml.StellarToml{},
130+
&federation.NameResponse{},
134131
errors.New("stellar.toml response status code indicates error"),
135132
).Once()
136133

@@ -155,11 +152,10 @@ func TestRequestHandlerPayment(t *testing.T) {
155152
}
156153

157154
mockFederationResolver.On(
158-
"Resolve",
155+
"LookupByAddress",
159156
"bob*stellar.org",
160157
).Return(
161-
federation.Response{AccountID: "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632"},
162-
stellartoml.StellarToml{},
158+
&federation.NameResponse{AccountID: "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632"},
163159
nil,
164160
).Once()
165161

@@ -215,15 +211,14 @@ func TestRequestHandlerPayment(t *testing.T) {
215211
}
216212

217213
mockFederationResolver.On(
218-
"Resolve",
214+
"LookupByAddress",
219215
"bob*stellar.org",
220216
).Return(
221-
federation.Response{
217+
&federation.NameResponse{
222218
AccountID: "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632",
223219
MemoType: "text",
224220
Memo: "125",
225221
},
226-
stellartoml.StellarToml{},
227222
nil,
228223
).Once()
229224

@@ -281,11 +276,10 @@ func TestRequestHandlerPayment(t *testing.T) {
281276
}
282277

283278
mockFederationResolver.On(
284-
"Resolve",
279+
"LookupByAddress",
285280
"GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632",
286281
).Return(
287-
federation.Response{AccountID: "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632"},
288-
stellartoml.StellarToml{},
282+
&federation.NameResponse{AccountID: "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632"},
289283
nil,
290284
).Once()
291285

@@ -313,11 +307,10 @@ func TestRequestHandlerPayment(t *testing.T) {
313307
assetIssuer := "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632"
314308

315309
mockFederationResolver.On(
316-
"Resolve",
310+
"LookupByAddress",
317311
"GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632",
318312
).Return(
319-
federation.Response{AccountID: "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632"},
320-
stellartoml.StellarToml{},
313+
&federation.NameResponse{AccountID: "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632"},
321314
nil,
322315
).Once()
323316

@@ -364,11 +357,10 @@ func TestRequestHandlerPayment(t *testing.T) {
364357
assetIssuer := "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632"
365358

366359
mockFederationResolver.On(
367-
"Resolve",
360+
"LookupByAddress",
368361
"GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632",
369362
).Return(
370-
federation.Response{AccountID: "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632"},
371-
stellartoml.StellarToml{},
363+
&federation.NameResponse{AccountID: "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632"},
372364
nil,
373365
).Once()
374366

@@ -416,11 +408,10 @@ func TestRequestHandlerPayment(t *testing.T) {
416408

417409
// Federation response
418410
mockFederationResolver.On(
419-
"Resolve",
411+
"LookupByAddress",
420412
"GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632",
421413
).Return(
422-
federation.Response{AccountID: "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632"},
423-
stellartoml.StellarToml{},
414+
&federation.NameResponse{AccountID: "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632"},
424415
nil,
425416
).Once()
426417

@@ -472,11 +463,10 @@ func TestRequestHandlerPayment(t *testing.T) {
472463
}
473464

474465
mockFederationResolver.On(
475-
"Resolve",
466+
"LookupByAddress",
476467
"GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632",
477468
).Return(
478-
federation.Response{AccountID: "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632"},
479-
stellartoml.StellarToml{},
469+
&federation.NameResponse{AccountID: "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632"},
480470
nil,
481471
).Once()
482472

@@ -786,11 +776,10 @@ func TestRequestHandlerPayment(t *testing.T) {
786776

787777
// Destination
788778
mockFederationResolver.On(
789-
"Resolve",
779+
"LookupByAddress",
790780
"GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632",
791781
).Return(
792-
federation.Response{AccountID: "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632"},
793-
stellartoml.StellarToml{},
782+
&federation.NameResponse{AccountID: "GDSIKW43UA6JTOA47WVEBCZ4MYC74M3GNKNXTVDXFHXYYTNO5GGVN632"},
794783
nil,
795784
).Once()
796785

@@ -1021,7 +1010,7 @@ func TestRequestHandlerPayment(t *testing.T) {
10211010

10221011
expectedTx := &xdr.Transaction{
10231012
SourceAccount: xdr.AccountId{
1024-
Type: xdr.CryptoKeyTypeKeyTypeEd25519,
1013+
Type: xdr.PublicKeyTypePublicKeyTypeEd25519,
10251014
Ed25519: &sourceXdr,
10261015
},
10271016
Fee: 100,
@@ -1033,7 +1022,7 @@ func TestRequestHandlerPayment(t *testing.T) {
10331022
Type: xdr.OperationTypePayment,
10341023
PaymentOp: &xdr.PaymentOp{
10351024
Destination: xdr.AccountId{
1036-
Type: xdr.CryptoKeyTypeKeyTypeEd25519,
1025+
Type: xdr.PublicKeyTypePublicKeyTypeEd25519,
10371026
Ed25519: &destinationXdr,
10381027
},
10391028
Amount: 200000000,
@@ -1042,7 +1031,7 @@ func TestRequestHandlerPayment(t *testing.T) {
10421031
AlphaNum4: &xdr.AssetAlphaNum4{
10431032
AssetCode: [4]byte{'U', 'S', 'D', 0},
10441033
Issuer: xdr.AccountId{
1045-
Type: xdr.CryptoKeyTypeKeyTypeEd25519,
1034+
Type: xdr.PublicKeyTypePublicKeyTypeEd25519,
10461035
Ed25519: &issuerXdr,
10471036
},
10481037
},
@@ -1053,7 +1042,7 @@ func TestRequestHandlerPayment(t *testing.T) {
10531042
},
10541043
}
10551044

1056-
complianceResponse := compliance.SendResponse{
1045+
complianceResponse := callback.SendResponse{
10571046
TransactionXdr: "AAAAAC3/58Z9rycNLmF6voWX9VmDETFVGhFoWf66mcMuir/DAAAAZAAAAAAAAAAAAAAAAAAAAAO5TSe5k00+CKUuUtfafav6xITv43pTgO6QiPes4u/N6QAAAAEAAAAAAAAAAQAAAAAZUvzcMkXAfSwqbLoAiAlgPsZ7GIPRi7NIyKgEIBQ4nAAAAAFVU0QAAAAAABlS/NwyRcB9LCpsugCICWA+xnsYg9GLs0jIqAQgFDicAAAAAAvrwgAAAAAA",
10581047
}
10591048

@@ -1100,7 +1089,7 @@ func TestRequestHandlerPayment(t *testing.T) {
11001089
})
11011090

11021091
Convey("it should return error when transaction submitter fails", func() {
1103-
complianceResponse := compliance.SendResponse{
1092+
complianceResponse := callback.SendResponse{
11041093
TransactionXdr: "AAAAAC3/58Z9rycNLmF6voWX9VmDETFVGhFoWf66mcMuir/DAAAAZAAAAAAAAAAAAAAAAAAAAAO5TSe5k00+CKUuUtfafav6xITv43pTgO6QiPes4u/N6QAAAAEAAAAAAAAAAQAAAAAZUvzcMkXAfSwqbLoAiAlgPsZ7GIPRi7NIyKgEIBQ4nAAAAAFVU0QAAAAAABlS/NwyRcB9LCpsugCICWA+xnsYg9GLs0jIqAQgFDicAAAAAAvrwgAAAAAA",
11051094
}
11061095

0 commit comments

Comments
 (0)