From 1e3ea347d8b3f674c9fa2e3807ef2c49bb392f8e Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Wed, 6 Jun 2018 11:30:48 +0200 Subject: [PATCH 1/7] Persist AuthData to resubmit after "pending" response --- readme_bridge.md | 2 +- readme_compliance.md | 1 + .../handlers/request_handler_payment.go | 66 ++++--- .../handlers/request_handler_send.go | 57 +++++- .../handlers/request_handler_send_test.go | 177 +++++++++++++++++- .../gateway/db/drivers/mysql/bindata.go | 25 ++- .../migrations_compliance/02_auth_data.sql | 10 + .../gateway/db/drivers/postgres/bindata.go | 25 ++- .../migrations_compliance/02_auth_data.sql | 11 ++ .../stellar/gateway/db/entities/auth_data.go | 29 +++ .../stellar/gateway/db/repository.go | 23 +++ src/github.com/stellar/gateway/mocks/main.go | 9 + .../gateway/protocols/bridge/payment.go | 3 +- .../gateway/protocols/compliance/send.go | 2 + 14 files changed, 402 insertions(+), 38 deletions(-) create mode 100644 src/github.com/stellar/gateway/db/drivers/mysql/migrations_compliance/02_auth_data.sql create mode 100644 src/github.com/stellar/gateway/db/drivers/postgres/migrations_compliance/02_auth_data.sql create mode 100644 src/github.com/stellar/gateway/db/entities/auth_data.go diff --git a/readme_bridge.md b/readme_bridge.md index fc6d5d6..94b1147 100644 --- a/readme_bridge.md +++ b/readme_bridge.md @@ -279,7 +279,7 @@ Every request must contain required parameters from the following list. Addition name | | description --- | --- | --- -`id` | optional | Unique ID of the payment. If you send another request with the same `id` previously sent transaction will be resubmitted to the network. +`id` | optional | Unique ID of the payment. If you send another request with the same `id` previously sent transaction will be resubmitted to the network. This parameter is required when sending a payment using Compliance protocol. `source` | optional | Secret seed of transaction source account. If ommitted it will use the `base_seed` specified in the config file. `sender` | optional | Payment address (ex. `bob*stellar.org`) of payment sender account. Required for when sending using Compliance protocol. `destination` | required | Account ID or payment address (ex. `bob*stellar.org`) of payment destination account diff --git a/readme_compliance.md b/readme_compliance.md index 41f83ad..c2da4db 100644 --- a/readme_compliance.md +++ b/readme_compliance.md @@ -86,6 +86,7 @@ Typically called by the bridge server when a user initiates a payment. This endp name | | description --- | --- | --- +`id` | required | ID of the payment/transaction. In case of `pending` response or errors, you should resubmit the request with the same `id` value. `source` | required | Account ID of transaction source account. `sender` | required | Stellar address (ex. `bob*stellar.org`) of payment sender account. `destination` | required | Account ID or Stellar address (ex. `bob*stellar.org`) of payment destination account diff --git a/src/github.com/stellar/gateway/bridge/handlers/request_handler_payment.go b/src/github.com/stellar/gateway/bridge/handlers/request_handler_payment.go index 1c3a193..36f8601 100644 --- a/src/github.com/stellar/gateway/bridge/handlers/request_handler_payment.go +++ b/src/github.com/stellar/gateway/bridge/handlers/request_handler_payment.go @@ -41,32 +41,6 @@ func (rh *RequestHandler) Payment(w http.ResponseWriter, r *http.Request) { return } - var paymentID *string - - if request.ID != "" { - sentTransaction, err := rh.Repository.GetSentTransactionByPaymentID(request.ID) - if err != nil { - log.WithFields(log.Fields{"err": err}).Error("Error getting sent transaction") - server.Write(w, protocols.InternalServerError) - return - } - - if sentTransaction == nil { - paymentID = &request.ID - } else { - log.WithFields(log.Fields{"paymentID": request.ID, "tx": sentTransaction.EnvelopeXdr}).Info("Transaction with given ID already exists, resubmitting...") - submitResponse, err := rh.Horizon.SubmitTransaction(sentTransaction.EnvelopeXdr) - if err != nil { - log.WithFields(log.Fields{"error": err}).Error("Error submitting transaction") - server.Write(w, protocols.InternalServerError) - return - } - - rh.handleSubmitterResponse(w, submitResponse) - return - } - } - if request.Source == "" { request.Source = rh.Config.Accounts.BaseSeed } @@ -76,13 +50,19 @@ func (rh *RequestHandler) Payment(w http.ResponseWriter, r *http.Request) { // * User explicitly wants to use compliance protocol if rh.Config.Compliance != "" && (request.ExtraMemo != "" || (request.ExtraMemo == "" && request.UseCompliance)) { - rh.complianceProtocolPayment(w, request, paymentID) + rh.complianceProtocolPayment(w, request) } else { - rh.standardPayment(w, request, paymentID) + rh.standardPayment(w, request) } } -func (rh *RequestHandler) complianceProtocolPayment(w http.ResponseWriter, request *bridge.PaymentRequest, paymentID *string) { +func (rh *RequestHandler) complianceProtocolPayment(w http.ResponseWriter, request *bridge.PaymentRequest) { + var paymentID *string + + if request.ID != "" { + paymentID = &request.ID + } + // Compliance server part sendRequest := request.ToComplianceSendRequest() @@ -153,7 +133,33 @@ func (rh *RequestHandler) complianceProtocolPayment(w http.ResponseWriter, reque rh.handleSubmitterResponse(w, submitResponse) } -func (rh *RequestHandler) standardPayment(w http.ResponseWriter, request *bridge.PaymentRequest, paymentID *string) { +func (rh *RequestHandler) standardPayment(w http.ResponseWriter, request *bridge.PaymentRequest) { + var paymentID *string + + if request.ID != "" { + sentTransaction, err := rh.Repository.GetSentTransactionByPaymentID(request.ID) + if err != nil { + log.WithFields(log.Fields{"err": err}).Error("Error getting sent transaction") + server.Write(w, protocols.InternalServerError) + return + } + + if sentTransaction == nil { + paymentID = &request.ID + } else { + log.WithFields(log.Fields{"paymentID": request.ID, "tx": sentTransaction.EnvelopeXdr}).Info("Transaction with given ID already exists, resubmitting...") + submitResponse, err := rh.Horizon.SubmitTransaction(sentTransaction.EnvelopeXdr) + if err != nil { + log.WithFields(log.Fields{"error": err}).Error("Error submitting transaction") + server.Write(w, protocols.InternalServerError) + return + } + + rh.handleSubmitterResponse(w, submitResponse) + return + } + } + destinationObject := &federation.NameResponse{} var err error diff --git a/src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go b/src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go index 4f2ef9f..25416ba 100644 --- a/src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go +++ b/src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go @@ -6,6 +6,7 @@ import ( "net/http" log "github.com/sirupsen/logrus" + "github.com/stellar/gateway/db/entities" "github.com/stellar/gateway/protocols" callback "github.com/stellar/gateway/protocols/compliance" "github.com/stellar/gateway/server" @@ -36,6 +37,34 @@ func (rh *RequestHandler) HandlerSend(c web.C, w http.ResponseWriter, r *http.Re return } + authDataEntity, err := rh.Repository.GetAuthData(request.ID) + if err != nil { + log.Error(err.Error()) + server.Write(w, protocols.InternalServerError) + return + } + + if authDataEntity != nil { + stellarToml, err := rh.StellarTomlResolver.GetStellarToml(authDataEntity.Domain) + if err != nil { + log.WithFields(log.Fields{ + "destination": request.Destination, + "err": err, + }).Print("Cannot resolve address") + server.Write(w, callback.CannotResolveDestination) + return + } + + if stellarToml.AuthServer == "" { + log.Print("No AUTH_SERVER in stellar.toml") + server.Write(w, callback.AuthServerNotDefined) + return + } + + rh.sendAuthData(w, stellarToml.AuthServer, []byte(authDataEntity.AuthData)) + return + } + var domain string var destinationObject *federation.NameResponse @@ -247,6 +276,28 @@ func (rh *RequestHandler) HandlerSend(c web.C, w http.ResponseWriter, r *http.Re server.Write(w, protocols.InternalServerError) return } + + authDataEntity = &entities.AuthData{ + Domain: domain, + AuthData: string(data), + } + err = rh.EntityManager.Persist(authDataEntity) + if err != nil { + return + } + + rh.sendAuthData(w, stellarToml.AuthServer, data) +} + +func (rh *RequestHandler) sendAuthData(w http.ResponseWriter, authServer string, data []byte) { + var authData compliance.AuthData + err := json.Unmarshal(data, &authData) + if err != nil { + log.Error(err) + server.Write(w, protocols.InternalServerError) + return + } + sig, err := rh.SignatureSignerVerifier.Sign(rh.Config.Keys.SigningSeed, data) if err != nil { log.Error("Error signing authData") @@ -259,12 +310,12 @@ func (rh *RequestHandler) HandlerSend(c web.C, w http.ResponseWriter, r *http.Re Signature: sig, } resp, err := rh.Client.PostForm( - stellarToml.AuthServer, + authServer, authRequest.ToURLValues(), ) if err != nil { log.WithFields(log.Fields{ - "auth_server": stellarToml.AuthServer, + "auth_server": authServer, "err": err, }).Error("Error sending request to auth server") server.Write(w, protocols.InternalServerError) @@ -301,7 +352,7 @@ func (rh *RequestHandler) HandlerSend(c web.C, w http.ResponseWriter, r *http.Re response := callback.SendResponse{ AuthResponse: authResponse, - TransactionXdr: txBase64, + TransactionXdr: authData.Tx, } server.Write(w, &response) } diff --git a/src/github.com/stellar/gateway/compliance/handlers/request_handler_send_test.go b/src/github.com/stellar/gateway/compliance/handlers/request_handler_send_test.go index 02bff78..ac12515 100644 --- a/src/github.com/stellar/gateway/compliance/handlers/request_handler_send_test.go +++ b/src/github.com/stellar/gateway/compliance/handlers/request_handler_send_test.go @@ -10,6 +10,7 @@ import ( "github.com/facebookgo/inject" . "github.com/smartystreets/goconvey/convey" "github.com/stellar/gateway/compliance/config" + "github.com/stellar/gateway/db/entities" "github.com/stellar/gateway/mocks" "github.com/stellar/gateway/net" "github.com/stellar/gateway/test" @@ -19,6 +20,7 @@ import ( "github.com/stellar/go/protocols/federation" "github.com/stellar/go/xdr" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/zenazn/goji/web" ) @@ -73,10 +75,24 @@ func TestRequestHandlerSend(t *testing.T) { defer testServer.Close() Convey("Given send request", t, func() { - Convey("When source param is missing", func() { + Convey("When id param is missing", func() { statusCode, response := net.GetResponse(testServer, url.Values{}) responseString := strings.TrimSpace(string(response)) assert.Equal(t, 400, statusCode) + expected := test.StringToJSONMap(`{ + "code": "missing_parameter", + "message": "Required parameter is missing.", + "data": { + "name": "id" + } + }`) + assert.Equal(t, expected, test.StringToJSONMap(responseString)) + }) + + Convey("When source param is missing", func() { + statusCode, response := net.GetResponse(testServer, url.Values{"id": {"id"}}) + responseString := strings.TrimSpace(string(response)) + assert.Equal(t, 400, statusCode) expected := test.StringToJSONMap(`{ "code": "missing_parameter", "message": "Required parameter is missing.", @@ -89,6 +105,7 @@ func TestRequestHandlerSend(t *testing.T) { Convey("When source param is invalid", func() { params := url.Values{ + "id": {"id"}, "source": {"bad"}, "sender": {"alice*stellar.org"}, // GAW77Z6GPWXSODJOMF5L5BMX6VMYGEJRKUNBC2CZ725JTQZORK74HQQD "destination": {"bob*stellar.org"}, // GAMVF7G4GJC4A7JMFJWLUAEIBFQD5RT3DCB5DC5TJDEKQBBACQ4JZVEE @@ -113,6 +130,7 @@ func TestRequestHandlerSend(t *testing.T) { Convey("When params are valid", func() { params := url.Values{ + "id": {"id"}, "source": {"GAW77Z6GPWXSODJOMF5L5BMX6VMYGEJRKUNBC2CZ725JTQZORK74HQQD"}, "sender": {"alice*stellar.org"}, // GAW77Z6GPWXSODJOMF5L5BMX6VMYGEJRKUNBC2CZ725JTQZORK74HQQD "destination": {"bob*stellar.org"}, // GAMVF7G4GJC4A7JMFJWLUAEIBFQD5RT3DCB5DC5TJDEKQBBACQ4JZVEE @@ -122,6 +140,9 @@ func TestRequestHandlerSend(t *testing.T) { "extra_memo": {"hello world"}, } + mockRepository.Mock.On("GetAuthData", "id").Return(nil, nil).Once() + mockEntityManager.On("Persist", mock.AnythingOfType("*entities.AuthData")).Return(nil).Once() + senderInfo := compliance.SenderInfo{FirstName: "John", LastName: "Doe"} senderInfoMap, err := senderInfo.Map() require.NoError(t, err) @@ -472,6 +493,160 @@ func TestRequestHandlerSend(t *testing.T) { }`) assert.Equal(t, expected, test.StringToJSONMap(responseString)) }) + + Convey("it returns SendResponse when pending, then success (payment)", func() { + authServer := "https://acme.com/auth" + + mockFederationResolver.On( + "LookupByAddress", + "bob*stellar.org", + ).Return(&federation.NameResponse{ + AccountID: "GAMVF7G4GJC4A7JMFJWLUAEIBFQD5RT3DCB5DC5TJDEKQBBACQ4JZVEE", + MemoType: "text", + Memo: federation.Memo{"bob"}, + }, nil).Once() + + mockStellartomlResolver.On( + "GetStellarToml", + "stellar.org", + ).Return(&stellartoml.Response{AuthServer: authServer}, nil).Once() + + attachment := compliance.Attachment{ + Nonce: "nonce", + Transaction: compliance.Transaction{ + Route: "bob", + Note: "", + SenderInfo: senderInfoMap, + Extra: "hello world", + }, + } + + attachmentJSON, err := attachment.Marshal() + require.NoError(t, err) + attachHash, err := attachment.Hash() + require.NoError(t, err) + + txBuilder, err := build.Transaction( + build.SourceAccount{"GAW77Z6GPWXSODJOMF5L5BMX6VMYGEJRKUNBC2CZ725JTQZORK74HQQD"}, + build.Sequence{0}, + build.TestNetwork, + build.MemoHash{attachHash}, + build.Payment( + build.Destination{"GAMVF7G4GJC4A7JMFJWLUAEIBFQD5RT3DCB5DC5TJDEKQBBACQ4JZVEE"}, + build.CreditAmount{"USD", "GAMVF7G4GJC4A7JMFJWLUAEIBFQD5RT3DCB5DC5TJDEKQBBACQ4JZVEE", "20"}, + ), + ) + require.NoError(t, err) + txB64, err := xdr.MarshalBase64(txBuilder.TX) + require.NoError(t, err) + + authData := compliance.AuthData{ + Sender: "alice*stellar.org", + NeedInfo: false, + Tx: txB64, + AttachmentJSON: string(attachmentJSON), + } + + authDataJSON, err := authData.Marshal() + require.NoError(t, err) + + authRequest := compliance.AuthRequest{ + DataJSON: string(authDataJSON), + Signature: "YeMlOYWNysyGBfsAe40z9dGgpRsKSQrqFIGAEsyJQ8osnXlLPynvJ2WQDGcBq2n5AA96YZdABhQz5ymqvxfQDw==", + } + + authResponse := compliance.AuthResponse{ + InfoStatus: compliance.AuthStatusPending, + TxStatus: compliance.AuthStatusPending, + Pending: 60, + } + + authResponseJSON, err := authResponse.Marshal() + require.NoError(t, err) + + mockHTTPClient.On( + "PostForm", + c.Callbacks.FetchInfo, + url.Values{"address": {"alice*stellar.org"}}, + ).Return( + net.BuildHTTPResponse(200, "{\"first_name\": \"John\", \"last_name\": \"Doe\"}"), + nil, + ).Once() + + mockHTTPClient.On( + "PostForm", + authServer, + authRequest.ToURLValues(), + ).Return( + net.BuildHTTPResponse(200, string(authResponseJSON)), + nil, + ).Once() + + mockSignerVerifier.On( + "Sign", + c.Keys.SigningSeed, + []byte(authRequest.DataJSON), + ).Return(authRequest.Signature, nil).Once() + + statusCode, response := net.GetResponse(testServer, params) + responseString := strings.TrimSpace(string(response)) + assert.Equal(t, 200, statusCode) + expected := test.StringToJSONMap(`{ + "auth_response": { + "info_status": "pending", + "tx_status": "pending", + "pending": 60 + }, + "transaction_xdr": "` + txB64 + `" + }`) + assert.Equal(t, expected, test.StringToJSONMap(responseString)) + + // Sending the request again + mockRepository.Mock.On("GetAuthData", "id").Return(&entities.AuthData{ + Domain: "stellar.org", + AuthData: string(authDataJSON), + }, nil).Once() + + authResponse = compliance.AuthResponse{ + InfoStatus: compliance.AuthStatusOk, + TxStatus: compliance.AuthStatusOk, + } + + authResponseJSON, err = authResponse.Marshal() + require.NoError(t, err) + + mockStellartomlResolver.On( + "GetStellarToml", + "stellar.org", + ).Return(&stellartoml.Response{AuthServer: authServer}, nil).Once() + + mockHTTPClient.On( + "PostForm", + authServer, + authRequest.ToURLValues(), + ).Return( + net.BuildHTTPResponse(200, string(authResponseJSON)), + nil, + ).Once() + + mockSignerVerifier.On( + "Sign", + c.Keys.SigningSeed, + []byte(authRequest.DataJSON), + ).Return(authRequest.Signature, nil).Once() + + statusCode, response = net.GetResponse(testServer, params) + responseString = strings.TrimSpace(string(response)) + assert.Equal(t, 200, statusCode) + expected = test.StringToJSONMap(`{ + "auth_response": { + "info_status": "ok", + "tx_status": "ok" + }, + "transaction_xdr": "` + txB64 + `" + }`) + assert.Equal(t, expected, test.StringToJSONMap(responseString)) + }) }) }) } diff --git a/src/github.com/stellar/gateway/db/drivers/mysql/bindata.go b/src/github.com/stellar/gateway/db/drivers/mysql/bindata.go index fe283b7..a38b3d4 100644 --- a/src/github.com/stellar/gateway/db/drivers/mysql/bindata.go +++ b/src/github.com/stellar/gateway/db/drivers/mysql/bindata.go @@ -4,6 +4,7 @@ // migrations_gateway/02_payment_id.sql // migrations_gateway/03_transaction_id.sql // migrations_compliance/01_init.sql +// migrations_compliance/02_auth_data.sql // DO NOT EDIT! package mysql @@ -126,7 +127,7 @@ func migrations_gateway03_transaction_idSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations_gateway/03_transaction_id.sql", size: 164, mode: os.FileMode(420), modTime: time.Unix(1516147358, 0)} + info := bindataFileInfo{name: "migrations_gateway/03_transaction_id.sql", size: 164, mode: os.FileMode(420), modTime: time.Unix(1516212470, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -151,6 +152,26 @@ func migrations_compliance01_initSql() (*asset, error) { return a, nil } +var _migrations_compliance02_auth_dataSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x64\x8f\xb1\x4e\xc3\x30\x18\x84\x77\x3f\xc5\x8d\x89\xa0\x43\x91\x2a\x21\x55\x1d\xdc\xf8\x07\x2c\x5c\xa7\x32\xf6\xd0\xa9\xb6\x48\x21\x1e\xea\xa0\xe8\x0f\xf0\xf8\xa8\x59\x00\x75\xbe\xef\xee\xf4\x2d\x16\xb8\x39\xe7\xf7\x31\xf1\x09\xe1\x43\x34\x8e\xa4\x27\x78\xb9\x35\x84\x28\x27\xee\x55\xe2\x14\x51\x09\x20\xe6\x2e\x22\x17\xae\x96\xcb\x1a\xb6\xf5\xb0\xc1\x18\xc8\xe0\xdb\xa3\xb6\x8d\xa3\x1d\x59\x7f\x7b\xe1\xba\xe1\x9c\x72\x89\xf8\x4c\xe3\x6b\x9f\xc6\xea\x6e\xb5\xfa\x2d\xcc\x44\x9a\xb8\x3f\x76\xf3\x32\x9f\xbe\xf9\x5f\xb8\x77\x7a\x27\xdd\x01\xcf\x74\x40\x75\xf9\xac\x45\x0d\xb2\x8f\xda\xd2\x46\x97\x32\xa8\x2d\x14\x3d\xc8\x60\x3c\x9a\x27\xe9\x5e\xc8\x6f\x26\x7e\xbb\x5f\x0b\xf1\xd7\x45\x0d\x5f\x45\x28\xd7\xee\xaf\x5c\xd6\xe2\x27\x00\x00\xff\xff\x52\xbf\x57\x07\xf4\x00\x00\x00") + +func migrations_compliance02_auth_dataSqlBytes() ([]byte, error) { + return bindataRead( + _migrations_compliance02_auth_dataSql, + "migrations_compliance/02_auth_data.sql", + ) +} + +func migrations_compliance02_auth_dataSql() (*asset, error) { + bytes, err := migrations_compliance02_auth_dataSqlBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "migrations_compliance/02_auth_data.sql", size: 244, mode: os.FileMode(420), modTime: time.Unix(1528276740, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + // Asset loads and returns the asset for the given name. // It returns an error if the asset could not be found or // could not be loaded. @@ -207,6 +228,7 @@ var _bindata = map[string]func() (*asset, error){ "migrations_gateway/02_payment_id.sql": migrations_gateway02_payment_idSql, "migrations_gateway/03_transaction_id.sql": migrations_gateway03_transaction_idSql, "migrations_compliance/01_init.sql": migrations_compliance01_initSql, + "migrations_compliance/02_auth_data.sql": migrations_compliance02_auth_dataSql, } // AssetDir returns the file names below a certain @@ -251,6 +273,7 @@ type bintree struct { var _bintree = &bintree{nil, map[string]*bintree{ "migrations_compliance": &bintree{nil, map[string]*bintree{ "01_init.sql": &bintree{migrations_compliance01_initSql, map[string]*bintree{}}, + "02_auth_data.sql": &bintree{migrations_compliance02_auth_dataSql, map[string]*bintree{}}, }}, "migrations_gateway": &bintree{nil, map[string]*bintree{ "01_init.sql": &bintree{migrations_gateway01_initSql, map[string]*bintree{}}, diff --git a/src/github.com/stellar/gateway/db/drivers/mysql/migrations_compliance/02_auth_data.sql b/src/github.com/stellar/gateway/db/drivers/mysql/migrations_compliance/02_auth_data.sql new file mode 100644 index 0000000..3cc82c8 --- /dev/null +++ b/src/github.com/stellar/gateway/db/drivers/mysql/migrations_compliance/02_auth_data.sql @@ -0,0 +1,10 @@ +-- +migrate Up +CREATE TABLE `AuthData` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `domain` varchar(255) NOT NULL, + `auth_data` text NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +migrate Down +DROP TABLE `AuthData`; diff --git a/src/github.com/stellar/gateway/db/drivers/postgres/bindata.go b/src/github.com/stellar/gateway/db/drivers/postgres/bindata.go index 1804fd0..b0f12a2 100644 --- a/src/github.com/stellar/gateway/db/drivers/postgres/bindata.go +++ b/src/github.com/stellar/gateway/db/drivers/postgres/bindata.go @@ -4,6 +4,7 @@ // migrations_gateway/02_payment_id.sql // migrations_gateway/03_transaction_id.sql // migrations_compliance/01_init.sql +// migrations_compliance/02_auth_data.sql // DO NOT EDIT! package postgres @@ -126,7 +127,7 @@ func migrations_gateway03_transaction_idSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations_gateway/03_transaction_id.sql", size: 156, mode: os.FileMode(420), modTime: time.Unix(1516147543, 0)} + info := bindataFileInfo{name: "migrations_gateway/03_transaction_id.sql", size: 156, mode: os.FileMode(420), modTime: time.Unix(1516212470, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -151,6 +152,26 @@ func migrations_compliance01_initSql() (*asset, error) { return a, nil } +var _migrations_compliance02_auth_dataSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x5c\xce\xb1\xae\x82\x30\x14\x87\xf1\xfd\x3c\xc5\x7f\x84\xdc\xcb\x62\xc2\xc4\x54\xa5\x83\x11\x81\x34\x30\x30\x99\xa3\x25\xb4\x89\x80\xa9\x07\xf5\xf1\x0d\x9b\x3a\x7f\xf9\x92\x5f\x92\xe0\x6f\xf4\x43\x60\xe9\xd1\xde\x68\x67\xb4\x6a\x34\x1a\xb5\x2d\x34\xd4\x22\x2e\x67\x61\x44\x04\x78\x8b\xb3\x1f\xee\x7d\xf0\x7c\xfd\x27\xc0\xce\x23\xfb\x09\x0f\x0e\x17\xc7\x21\xda\xa4\x69\x8c\xb2\x6a\x50\xb6\x45\xb1\x76\x5e\xc4\x9d\xec\x7a\x4b\xff\x92\xaf\x44\x40\x6d\xf6\x47\x65\x3a\x1c\x74\x87\xc8\xdb\x98\xe2\x8c\xe8\xd3\x92\xcf\xcf\x89\x72\x53\xd5\x3f\x96\x8c\xde\x01\x00\x00\xff\xff\x9b\xa6\x46\xc6\xb2\x00\x00\x00") + +func migrations_compliance02_auth_dataSqlBytes() ([]byte, error) { + return bindataRead( + _migrations_compliance02_auth_dataSql, + "migrations_compliance/02_auth_data.sql", + ) +} + +func migrations_compliance02_auth_dataSql() (*asset, error) { + bytes, err := migrations_compliance02_auth_dataSqlBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "migrations_compliance/02_auth_data.sql", size: 178, mode: os.FileMode(420), modTime: time.Unix(1528276732, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + // Asset loads and returns the asset for the given name. // It returns an error if the asset could not be found or // could not be loaded. @@ -207,6 +228,7 @@ var _bindata = map[string]func() (*asset, error){ "migrations_gateway/02_payment_id.sql": migrations_gateway02_payment_idSql, "migrations_gateway/03_transaction_id.sql": migrations_gateway03_transaction_idSql, "migrations_compliance/01_init.sql": migrations_compliance01_initSql, + "migrations_compliance/02_auth_data.sql": migrations_compliance02_auth_dataSql, } // AssetDir returns the file names below a certain @@ -251,6 +273,7 @@ type bintree struct { var _bintree = &bintree{nil, map[string]*bintree{ "migrations_compliance": &bintree{nil, map[string]*bintree{ "01_init.sql": &bintree{migrations_compliance01_initSql, map[string]*bintree{}}, + "02_auth_data.sql": &bintree{migrations_compliance02_auth_dataSql, map[string]*bintree{}}, }}, "migrations_gateway": &bintree{nil, map[string]*bintree{ "01_init.sql": &bintree{migrations_gateway01_initSql, map[string]*bintree{}}, diff --git a/src/github.com/stellar/gateway/db/drivers/postgres/migrations_compliance/02_auth_data.sql b/src/github.com/stellar/gateway/db/drivers/postgres/migrations_compliance/02_auth_data.sql new file mode 100644 index 0000000..53b98f9 --- /dev/null +++ b/src/github.com/stellar/gateway/db/drivers/postgres/migrations_compliance/02_auth_data.sql @@ -0,0 +1,11 @@ +-- +migrate Up +CREATE TABLE AuthData ( + id bigserial, + domain varchar(255) NOT NULL, + auth_data text NOT NULL, + + PRIMARY KEY (id) +); + +-- +migrate Down +DROP TABLE AuthData; diff --git a/src/github.com/stellar/gateway/db/entities/auth_data.go b/src/github.com/stellar/gateway/db/entities/auth_data.go new file mode 100644 index 0000000..efb05be --- /dev/null +++ b/src/github.com/stellar/gateway/db/entities/auth_data.go @@ -0,0 +1,29 @@ +package entities + +// AuthData represents auth data +type AuthData struct { + exists bool + ID *int64 `db:"id"` + Domain string `db:"domain"` + AuthData string `db:"auth_data"` +} + +// GetID returns ID of the entity +func (e *AuthData) GetID() *int64 { + return e.ID +} + +// SetID sets ID of the entity +func (e *AuthData) SetID(id int64) { + e.ID = &id +} + +// IsNew returns true if the entity has not been persisted yet +func (e *AuthData) IsNew() bool { + return !e.exists +} + +// SetExists sets entity as persisted +func (e *AuthData) SetExists() { + e.exists = true +} diff --git a/src/github.com/stellar/gateway/db/repository.go b/src/github.com/stellar/gateway/db/repository.go index 3298be7..daf7dbf 100644 --- a/src/github.com/stellar/gateway/db/repository.go +++ b/src/github.com/stellar/gateway/db/repository.go @@ -15,6 +15,7 @@ type RepositoryInterface interface { GetSentTransactionByPaymentID(paymentID string) (*entities.SentTransaction, error) GetAllowedFiByDomain(domain string) (*entities.AllowedFi, error) GetAllowedUserByDomainAndUserID(domain, userID string) (*entities.AllowedUser, error) + GetAuthData(id string) (*entities.AuthData, error) GetReceivedPaymentByOperationID(operationID int64) (*entities.ReceivedPayment, error) GetReceivedPayments(page, limit int) ([]*entities.ReceivedPayment, error) GetSentTransactions(page, limit int) ([]*entities.SentTransaction, error) @@ -165,6 +166,28 @@ func (r Repository) GetReceivedPaymentByOperationID(operationID int64) (*entitie return &found, nil } +// GetAuthData returns received auth data by id +func (r Repository) GetAuthData(id string) (*entities.AuthData, error) { + var found entities.AuthData + + err := r.repo.GetRaw( + &found, + "SELECT * FROM AuthData WHERE id = ?", + id, + ) + + if r.repo.NoRows(err) { + return nil, nil + } + + if err != nil { + return nil, err + } + + found.SetExists() + return &found, nil +} + // GetReceivedPayments returns received payments func (r Repository) GetReceivedPayments(page, limit int) ([]*entities.ReceivedPayment, error) { payments := []*entities.ReceivedPayment{} diff --git a/src/github.com/stellar/gateway/mocks/main.go b/src/github.com/stellar/gateway/mocks/main.go index a11ec71..3e10baa 100644 --- a/src/github.com/stellar/gateway/mocks/main.go +++ b/src/github.com/stellar/gateway/mocks/main.go @@ -167,6 +167,15 @@ func (m *MockRepository) GetReceivedPaymentByOperationID(operationID int64) (*en return a.Get(0).(*entities.ReceivedPayment), a.Error(1) } +// GetAuthData is a mocking a method +func (m *MockRepository) GetAuthData(id string) (*entities.AuthData, error) { + a := m.Called(id) + if a.Get(0) == nil { + return nil, a.Error(1) + } + return a.Get(0).(*entities.AuthData), a.Error(1) +} + func (m *MockRepository) GetReceivedPayments(page, limit int) ([]*entities.ReceivedPayment, error) { a := m.Called(page, limit) if a.Get(0) == nil { diff --git a/src/github.com/stellar/gateway/protocols/bridge/payment.go b/src/github.com/stellar/gateway/protocols/bridge/payment.go index c1fe67a..4a3b63d 100644 --- a/src/github.com/stellar/gateway/protocols/bridge/payment.go +++ b/src/github.com/stellar/gateway/protocols/bridge/payment.go @@ -109,7 +109,8 @@ func (request *PaymentRequest) ToValues() url.Values { func (request *PaymentRequest) ToComplianceSendRequest() callback.SendRequest { sourceKeypair, _ := keypair.Parse(request.Source) return callback.SendRequest{ - // Compliance does not sign transaction, it just needs public key + ID: request.ID, + // Compliance does not sign the transaction, it just needs a public key Source: sourceKeypair.Address(), Sender: request.Sender, Destination: request.Destination, diff --git a/src/github.com/stellar/gateway/protocols/compliance/send.go b/src/github.com/stellar/gateway/protocols/compliance/send.go index f2316dc..2cbaca3 100644 --- a/src/github.com/stellar/gateway/protocols/compliance/send.go +++ b/src/github.com/stellar/gateway/protocols/compliance/send.go @@ -12,6 +12,8 @@ import ( // SendRequest represents request sent to /send endpoint of compliance server type SendRequest struct { + // Payment ID - used to resubmit auth request in case of `pending` response. + ID string `name:"id" required:""` // Source account ID Source string `name:"source" required:""` // Sender address (like alice*stellar.org) From 49c869c706afd9f5f9d592d02353657fb4beeca7 Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Thu, 7 Jun 2018 11:47:15 +0200 Subject: [PATCH 2/7] Update drivers --- src/github.com/stellar/gateway/db/drivers/mysql/main.go | 7 +++++++ src/github.com/stellar/gateway/db/drivers/postgres/main.go | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/github.com/stellar/gateway/db/drivers/mysql/main.go b/src/github.com/stellar/gateway/db/drivers/mysql/main.go index 205e8c3..33febe2 100644 --- a/src/github.com/stellar/gateway/db/drivers/mysql/main.go +++ b/src/github.com/stellar/gateway/db/drivers/mysql/main.go @@ -70,6 +70,8 @@ func (d *Driver) Insert(object entities.Entity) (id int64, err error) { result, err = d.database.NamedExec(query, object) case *entities.AllowedUser: result, err = d.database.NamedExec(query, object) + case *entities.AuthData: + result, err = d.database.NamedExec(query, object) case *entities.SentTransaction: result, err = d.database.NamedExec(query, object) case *entities.ReceivedPayment: @@ -128,6 +130,8 @@ func (d *Driver) Update(object entities.Entity) (err error) { _, err = d.database.NamedExec(query, object) case *entities.AllowedUser: _, err = d.database.NamedExec(query, object) + case *entities.AuthData: + _, err = d.database.NamedExec(query, object) case *entities.SentTransaction: _, err = d.database.NamedExec(query, object) case *entities.ReceivedPayment: @@ -231,6 +235,9 @@ func getTypeData(object interface{}) (typeValue reflect.Type, tableName string, case *entities.AllowedUser: typeValue = reflect.TypeOf(*object) tableName = "AllowedUser" + case *entities.AuthData: + typeValue = reflect.TypeOf(*object) + tableName = "AuthData" case *entities.SentTransaction: typeValue = reflect.TypeOf(*object) tableName = "SentTransaction" diff --git a/src/github.com/stellar/gateway/db/drivers/postgres/main.go b/src/github.com/stellar/gateway/db/drivers/postgres/main.go index 41d1b18..0bffc50 100644 --- a/src/github.com/stellar/gateway/db/drivers/postgres/main.go +++ b/src/github.com/stellar/gateway/db/drivers/postgres/main.go @@ -81,6 +81,8 @@ func (d *Driver) Insert(object entities.Entity) (id int64, err error) { err = stmt.Get(&id, object) case *entities.AllowedUser: err = stmt.Get(&id, object) + case *entities.AuthData: + err = stmt.Get(&id, object) case *entities.SentTransaction: err = stmt.Get(&id, object) case *entities.ReceivedPayment: @@ -137,6 +139,8 @@ func (d *Driver) Update(object entities.Entity) (err error) { _, err = d.database.NamedExec(query, object) case *entities.AllowedUser: _, err = d.database.NamedExec(query, object) + case *entities.AuthData: + _, err = d.database.NamedExec(query, object) case *entities.SentTransaction: _, err = d.database.NamedExec(query, object) case *entities.ReceivedPayment: @@ -245,6 +249,9 @@ func getTypeData(object interface{}) (typeValue reflect.Type, tableName string, case *entities.AllowedUser: typeValue = reflect.TypeOf(*object) tableName = "AllowedUser" + case *entities.AuthData: + typeValue = reflect.TypeOf(*object) + tableName = "AuthData" case *entities.SentTransaction: typeValue = reflect.TypeOf(*object) tableName = "SentTransaction" From ea0cafc920d866ed95d61aafe03d191d1dd8f0f8 Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Thu, 7 Jun 2018 13:09:14 +0200 Subject: [PATCH 3/7] Update ID field --- .../gateway/compliance/handlers/request_handler_send.go | 1 + .../compliance/handlers/request_handler_send_test.go | 8 +++++++- .../stellar/gateway/db/drivers/mysql/bindata.go | 4 ++-- .../drivers/mysql/migrations_compliance/02_auth_data.sql | 2 +- .../stellar/gateway/db/drivers/postgres/bindata.go | 4 ++-- .../postgres/migrations_compliance/02_auth_data.sql | 2 +- src/github.com/stellar/gateway/db/entities/auth_data.go | 6 +++--- 7 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go b/src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go index 25416ba..b87c5a4 100644 --- a/src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go +++ b/src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go @@ -278,6 +278,7 @@ func (rh *RequestHandler) HandlerSend(c web.C, w http.ResponseWriter, r *http.Re } authDataEntity = &entities.AuthData{ + ID: request.ID, Domain: domain, AuthData: string(data), } diff --git a/src/github.com/stellar/gateway/compliance/handlers/request_handler_send_test.go b/src/github.com/stellar/gateway/compliance/handlers/request_handler_send_test.go index ac12515..510d8bc 100644 --- a/src/github.com/stellar/gateway/compliance/handlers/request_handler_send_test.go +++ b/src/github.com/stellar/gateway/compliance/handlers/request_handler_send_test.go @@ -141,7 +141,12 @@ func TestRequestHandlerSend(t *testing.T) { } mockRepository.Mock.On("GetAuthData", "id").Return(nil, nil).Once() - mockEntityManager.On("Persist", mock.AnythingOfType("*entities.AuthData")).Return(nil).Once() + mockEntityManager.On("Persist", mock.AnythingOfType("*entities.AuthData")).Run(func(args mock.Arguments) { + entity, ok := args.Get(0).(*entities.AuthData) + assert.True(t, ok, "Invalid conversion") + assert.Equal(t, "id", entity.ID) + assert.Equal(t, "stellar.org", entity.Domain) + }).Return(nil).Once() senderInfo := compliance.SenderInfo{FirstName: "John", LastName: "Doe"} senderInfoMap, err := senderInfo.Map() @@ -603,6 +608,7 @@ func TestRequestHandlerSend(t *testing.T) { // Sending the request again mockRepository.Mock.On("GetAuthData", "id").Return(&entities.AuthData{ + ID: "id", Domain: "stellar.org", AuthData: string(authDataJSON), }, nil).Once() diff --git a/src/github.com/stellar/gateway/db/drivers/mysql/bindata.go b/src/github.com/stellar/gateway/db/drivers/mysql/bindata.go index a38b3d4..717d600 100644 --- a/src/github.com/stellar/gateway/db/drivers/mysql/bindata.go +++ b/src/github.com/stellar/gateway/db/drivers/mysql/bindata.go @@ -152,7 +152,7 @@ func migrations_compliance01_initSql() (*asset, error) { return a, nil } -var _migrations_compliance02_auth_dataSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x64\x8f\xb1\x4e\xc3\x30\x18\x84\x77\x3f\xc5\x8d\x89\xa0\x43\x91\x2a\x21\x55\x1d\xdc\xf8\x07\x2c\x5c\xa7\x32\xf6\xd0\xa9\xb6\x48\x21\x1e\xea\xa0\xe8\x0f\xf0\xf8\xa8\x59\x00\x75\xbe\xef\xee\xf4\x2d\x16\xb8\x39\xe7\xf7\x31\xf1\x09\xe1\x43\x34\x8e\xa4\x27\x78\xb9\x35\x84\x28\x27\xee\x55\xe2\x14\x51\x09\x20\xe6\x2e\x22\x17\xae\x96\xcb\x1a\xb6\xf5\xb0\xc1\x18\xc8\xe0\xdb\xa3\xb6\x8d\xa3\x1d\x59\x7f\x7b\xe1\xba\xe1\x9c\x72\x89\xf8\x4c\xe3\x6b\x9f\xc6\xea\x6e\xb5\xfa\x2d\xcc\x44\x9a\xb8\x3f\x76\xf3\x32\x9f\xbe\xf9\x5f\xb8\x77\x7a\x27\xdd\x01\xcf\x74\x40\x75\xf9\xac\x45\x0d\xb2\x8f\xda\xd2\x46\x97\x32\xa8\x2d\x14\x3d\xc8\x60\x3c\x9a\x27\xe9\x5e\xc8\x6f\x26\x7e\xbb\x5f\x0b\xf1\xd7\x45\x0d\x5f\x45\x28\xd7\xee\xaf\x5c\xd6\xe2\x27\x00\x00\xff\xff\x52\xbf\x57\x07\xf4\x00\x00\x00") +var _migrations_compliance02_auth_dataSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x8f\x41\x0b\x82\x30\x18\x86\xef\xfb\x15\xdf\x51\x29\x2f\x81\x10\x88\x87\xe9\xbe\x4a\x5a\x53\xd6\x3c\x78\x6a\x23\x2d\x3d\x38\x43\x66\xf5\xf3\xc3\x4e\x45\xd0\xf9\x79\x79\x1f\x9e\x20\x80\x45\xdf\x5d\x47\xe3\x1a\x28\x6f\x24\x95\x48\x15\x82\xa2\x09\x47\xd0\x74\x72\x2d\x33\xce\x68\xf0\x08\x80\xee\x6a\x0d\x77\x33\x9e\x5b\x33\x7a\xab\x30\xf4\x41\xe4\x0a\x44\xc9\xf9\x72\xa6\xf5\xd0\x9b\xce\xfe\x5b\x98\xc9\xb5\xa7\xfa\xfd\xe7\x9a\xa7\xfb\x82\x85\xcc\x0e\x54\x56\xb0\xc7\x0a\xbc\xd9\xe4\x13\x1f\x50\x6c\x33\x81\x71\x66\xed\xc0\x12\x60\xb8\xa1\x25\x57\x90\xee\xa8\x3c\xa2\x8a\x27\x77\x59\x47\x84\x7c\x16\xb0\xe1\x61\x09\x93\x79\xf1\x53\x10\x91\x57\x00\x00\x00\xff\xff\x33\x14\xe8\xe4\xea\x00\x00\x00") func migrations_compliance02_auth_dataSqlBytes() ([]byte, error) { return bindataRead( @@ -167,7 +167,7 @@ func migrations_compliance02_auth_dataSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations_compliance/02_auth_data.sql", size: 244, mode: os.FileMode(420), modTime: time.Unix(1528276740, 0)} + info := bindataFileInfo{name: "migrations_compliance/02_auth_data.sql", size: 234, mode: os.FileMode(420), modTime: time.Unix(1528369167, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/src/github.com/stellar/gateway/db/drivers/mysql/migrations_compliance/02_auth_data.sql b/src/github.com/stellar/gateway/db/drivers/mysql/migrations_compliance/02_auth_data.sql index 3cc82c8..2e47d41 100644 --- a/src/github.com/stellar/gateway/db/drivers/mysql/migrations_compliance/02_auth_data.sql +++ b/src/github.com/stellar/gateway/db/drivers/mysql/migrations_compliance/02_auth_data.sql @@ -1,6 +1,6 @@ -- +migrate Up CREATE TABLE `AuthData` ( - `id` int(11) NOT NULL AUTO_INCREMENT, + `id` varchar(255) NOT NULL, `domain` varchar(255) NOT NULL, `auth_data` text NOT NULL, PRIMARY KEY (`id`) diff --git a/src/github.com/stellar/gateway/db/drivers/postgres/bindata.go b/src/github.com/stellar/gateway/db/drivers/postgres/bindata.go index b0f12a2..f6ba0c5 100644 --- a/src/github.com/stellar/gateway/db/drivers/postgres/bindata.go +++ b/src/github.com/stellar/gateway/db/drivers/postgres/bindata.go @@ -152,7 +152,7 @@ func migrations_compliance01_initSql() (*asset, error) { return a, nil } -var _migrations_compliance02_auth_dataSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x5c\xce\xb1\xae\x82\x30\x14\x87\xf1\xfd\x3c\xc5\x7f\x84\xdc\xcb\x62\xc2\xc4\x54\xa5\x83\x11\x81\x34\x30\x30\x99\xa3\x25\xb4\x89\x80\xa9\x07\xf5\xf1\x0d\x9b\x3a\x7f\xf9\x92\x5f\x92\xe0\x6f\xf4\x43\x60\xe9\xd1\xde\x68\x67\xb4\x6a\x34\x1a\xb5\x2d\x34\xd4\x22\x2e\x67\x61\x44\x04\x78\x8b\xb3\x1f\xee\x7d\xf0\x7c\xfd\x27\xc0\xce\x23\xfb\x09\x0f\x0e\x17\xc7\x21\xda\xa4\x69\x8c\xb2\x6a\x50\xb6\x45\xb1\x76\x5e\xc4\x9d\xec\x7a\x4b\xff\x92\xaf\x44\x40\x6d\xf6\x47\x65\x3a\x1c\x74\x87\xc8\xdb\x98\xe2\x8c\xe8\xd3\x92\xcf\xcf\x89\x72\x53\xd5\x3f\x96\x8c\xde\x01\x00\x00\xff\xff\x9b\xa6\x46\xc6\xb2\x00\x00\x00") +var _migrations_compliance02_auth_dataSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x74\xce\xb1\xaa\xc2\x30\x14\x87\xf1\xfd\x3c\xc5\x7f\x6c\xb9\xb7\x8b\xd0\xa9\x53\xb4\x19\xc4\xd8\x96\x90\x0e\x9d\xe4\x60\x8a\xc9\xd0\x56\xc2\xa9\xfa\xf8\xe2\xa6\x82\xf3\x07\x1f\xbf\xa2\xc0\xdf\x14\x2f\x89\x65\x44\x7f\xa5\x9d\xd5\xca\x69\x38\xb5\x35\x1a\x6a\x95\x50\xb3\x30\x32\x02\xa2\xc7\x8d\xd3\x39\x70\xca\x36\x65\x99\xa3\x69\x1d\x9a\xde\x98\x7f\x02\xfc\x32\x71\x9c\x7f\x77\x5e\x25\x9c\xfc\xeb\x24\xe3\x43\x3e\x12\x01\x9d\xdd\x1f\x95\x1d\x70\xd0\x03\xb2\xe8\x73\xca\x2b\xa2\x77\x57\xbd\xdc\x67\xaa\x6d\xdb\x7d\xb9\x2a\x7a\x06\x00\x00\xff\xff\x47\x8b\x6d\x94\xbe\x00\x00\x00") func migrations_compliance02_auth_dataSqlBytes() ([]byte, error) { return bindataRead( @@ -167,7 +167,7 @@ func migrations_compliance02_auth_dataSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations_compliance/02_auth_data.sql", size: 178, mode: os.FileMode(420), modTime: time.Unix(1528276732, 0)} + info := bindataFileInfo{name: "migrations_compliance/02_auth_data.sql", size: 190, mode: os.FileMode(420), modTime: time.Unix(1528369177, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/src/github.com/stellar/gateway/db/drivers/postgres/migrations_compliance/02_auth_data.sql b/src/github.com/stellar/gateway/db/drivers/postgres/migrations_compliance/02_auth_data.sql index 53b98f9..abc569a 100644 --- a/src/github.com/stellar/gateway/db/drivers/postgres/migrations_compliance/02_auth_data.sql +++ b/src/github.com/stellar/gateway/db/drivers/postgres/migrations_compliance/02_auth_data.sql @@ -1,6 +1,6 @@ -- +migrate Up CREATE TABLE AuthData ( - id bigserial, + id varchar(255) NOT NULL, domain varchar(255) NOT NULL, auth_data text NOT NULL, diff --git a/src/github.com/stellar/gateway/db/entities/auth_data.go b/src/github.com/stellar/gateway/db/entities/auth_data.go index efb05be..cdc9b91 100644 --- a/src/github.com/stellar/gateway/db/entities/auth_data.go +++ b/src/github.com/stellar/gateway/db/entities/auth_data.go @@ -3,19 +3,19 @@ package entities // AuthData represents auth data type AuthData struct { exists bool - ID *int64 `db:"id"` + ID string `db:"id"` Domain string `db:"domain"` AuthData string `db:"auth_data"` } // GetID returns ID of the entity func (e *AuthData) GetID() *int64 { - return e.ID + return nil } // SetID sets ID of the entity func (e *AuthData) SetID(id int64) { - e.ID = &id + // } // IsNew returns true if the entity has not been persisted yet From 84dd94ea6b20df8d26985a119578518c859369e7 Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Fri, 8 Jun 2018 11:57:35 +0200 Subject: [PATCH 4/7] Fix AuthData --- .../compliance/handlers/request_handler_send.go | 6 +++--- .../handlers/request_handler_send_test.go | 8 ++++---- .../stellar/gateway/db/drivers/mysql/bindata.go | 4 ++-- .../mysql/migrations_compliance/02_auth_data.sql | 6 ++++-- .../stellar/gateway/db/drivers/postgres/bindata.go | 4 ++-- .../postgres/migrations_compliance/02_auth_data.sql | 5 ++++- .../stellar/gateway/db/entities/auth_data.go | 13 +++++++------ 7 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go b/src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go index b87c5a4..2fc3e9f 100644 --- a/src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go +++ b/src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go @@ -278,9 +278,9 @@ func (rh *RequestHandler) HandlerSend(c web.C, w http.ResponseWriter, r *http.Re } authDataEntity = &entities.AuthData{ - ID: request.ID, - Domain: domain, - AuthData: string(data), + RequestID: request.ID, + Domain: domain, + AuthData: string(data), } err = rh.EntityManager.Persist(authDataEntity) if err != nil { diff --git a/src/github.com/stellar/gateway/compliance/handlers/request_handler_send_test.go b/src/github.com/stellar/gateway/compliance/handlers/request_handler_send_test.go index 510d8bc..84d5d7b 100644 --- a/src/github.com/stellar/gateway/compliance/handlers/request_handler_send_test.go +++ b/src/github.com/stellar/gateway/compliance/handlers/request_handler_send_test.go @@ -144,7 +144,7 @@ func TestRequestHandlerSend(t *testing.T) { mockEntityManager.On("Persist", mock.AnythingOfType("*entities.AuthData")).Run(func(args mock.Arguments) { entity, ok := args.Get(0).(*entities.AuthData) assert.True(t, ok, "Invalid conversion") - assert.Equal(t, "id", entity.ID) + assert.Equal(t, "id", entity.RequestID) assert.Equal(t, "stellar.org", entity.Domain) }).Return(nil).Once() @@ -608,9 +608,9 @@ func TestRequestHandlerSend(t *testing.T) { // Sending the request again mockRepository.Mock.On("GetAuthData", "id").Return(&entities.AuthData{ - ID: "id", - Domain: "stellar.org", - AuthData: string(authDataJSON), + RequestID: "id", + Domain: "stellar.org", + AuthData: string(authDataJSON), }, nil).Once() authResponse = compliance.AuthResponse{ diff --git a/src/github.com/stellar/gateway/db/drivers/mysql/bindata.go b/src/github.com/stellar/gateway/db/drivers/mysql/bindata.go index 717d600..a8cde67 100644 --- a/src/github.com/stellar/gateway/db/drivers/mysql/bindata.go +++ b/src/github.com/stellar/gateway/db/drivers/mysql/bindata.go @@ -152,7 +152,7 @@ func migrations_compliance01_initSql() (*asset, error) { return a, nil } -var _migrations_compliance02_auth_dataSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x8f\x41\x0b\x82\x30\x18\x86\xef\xfb\x15\xdf\x51\x29\x2f\x81\x10\x88\x87\xe9\xbe\x4a\x5a\x53\xd6\x3c\x78\x6a\x23\x2d\x3d\x38\x43\x66\xf5\xf3\xc3\x4e\x45\xd0\xf9\x79\x79\x1f\x9e\x20\x80\x45\xdf\x5d\x47\xe3\x1a\x28\x6f\x24\x95\x48\x15\x82\xa2\x09\x47\xd0\x74\x72\x2d\x33\xce\x68\xf0\x08\x80\xee\x6a\x0d\x77\x33\x9e\x5b\x33\x7a\xab\x30\xf4\x41\xe4\x0a\x44\xc9\xf9\x72\xa6\xf5\xd0\x9b\xce\xfe\x5b\x98\xc9\xb5\xa7\xfa\xfd\xe7\x9a\xa7\xfb\x82\x85\xcc\x0e\x54\x56\xb0\xc7\x0a\xbc\xd9\xe4\x13\x1f\x50\x6c\x33\x81\x71\x66\xed\xc0\x12\x60\xb8\xa1\x25\x57\x90\xee\xa8\x3c\xa2\x8a\x27\x77\x59\x47\x84\x7c\x16\xb0\xe1\x61\x09\x93\x79\xf1\x53\x10\x91\x57\x00\x00\x00\xff\xff\x33\x14\xe8\xe4\xea\x00\x00\x00") +var _migrations_compliance02_auth_dataSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x90\xb1\x4e\xc3\x30\x10\x86\x77\x3f\xc5\x8d\x8e\x68\x87\x22\x55\x42\xaa\x3a\xb8\xf1\x01\x16\xa9\x53\x8c\x3d\x74\x4a\x2c\x12\x48\x86\x3a\x60\xce\xc0\xe3\x23\x67\xa1\x15\x12\xe3\xfd\xf7\x9d\xee\xd7\xb7\x5c\xc2\xd5\x69\x7c\x8d\x9e\x7a\x70\x6f\xac\x34\x28\x2c\x82\x15\xbb\x0a\xa1\x15\x89\x06\xe9\xc9\xb7\xc0\x19\x40\x3b\x76\x2d\x8c\x81\xf8\x6a\x55\x80\xae\x2d\x68\x57\x55\x20\x9c\xad\x1b\xa5\x4b\x83\x7b\xd4\x76\x91\xb9\xd8\xbf\xa7\xfe\x83\x9a\xcc\x7f\xfa\xf8\x3c\xf8\xc8\xaf\xd7\xeb\xdf\xa3\x99\xea\xa6\x93\x1f\xc3\x7f\x84\x4f\x34\x34\xdd\xfc\x9f\xfa\x6f\xba\x58\x1e\x8c\xda\x0b\x73\x84\x07\x3c\x02\xcf\xcd\x8a\x9c\x3a\xad\x1e\x1d\xce\xe1\x45\x0b\x7e\x3e\x15\x0b\x56\x00\xea\x3b\xa5\x71\xab\x42\x98\xe4\x0e\x24\xde\x0a\x57\x59\x28\xef\x85\x79\x42\xbb\x4d\xf4\x72\xb3\x61\xec\x5c\x8e\x9c\xbe\x02\x93\xa6\x3e\xfc\x91\xb3\x61\x3f\x01\x00\x00\xff\xff\x87\x4c\xc4\xc0\x45\x01\x00\x00") func migrations_compliance02_auth_dataSqlBytes() ([]byte, error) { return bindataRead( @@ -167,7 +167,7 @@ func migrations_compliance02_auth_dataSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations_compliance/02_auth_data.sql", size: 234, mode: os.FileMode(420), modTime: time.Unix(1528369167, 0)} + info := bindataFileInfo{name: "migrations_compliance/02_auth_data.sql", size: 325, mode: os.FileMode(420), modTime: time.Unix(1528451670, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/src/github.com/stellar/gateway/db/drivers/mysql/migrations_compliance/02_auth_data.sql b/src/github.com/stellar/gateway/db/drivers/mysql/migrations_compliance/02_auth_data.sql index 2e47d41..313d4aa 100644 --- a/src/github.com/stellar/gateway/db/drivers/mysql/migrations_compliance/02_auth_data.sql +++ b/src/github.com/stellar/gateway/db/drivers/mysql/migrations_compliance/02_auth_data.sql @@ -1,9 +1,11 @@ -- +migrate Up CREATE TABLE `AuthData` ( - `id` varchar(255) NOT NULL, + `id` int(11) NOT NULL AUTO_INCREMENT, + `request_id` varchar(255) NOT NULL, `domain` varchar(255) NOT NULL, `auth_data` text NOT NULL, - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), + UNIQUE KEY `request_id` (`request_id`), ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- +migrate Down diff --git a/src/github.com/stellar/gateway/db/drivers/postgres/bindata.go b/src/github.com/stellar/gateway/db/drivers/postgres/bindata.go index f6ba0c5..e369269 100644 --- a/src/github.com/stellar/gateway/db/drivers/postgres/bindata.go +++ b/src/github.com/stellar/gateway/db/drivers/postgres/bindata.go @@ -152,7 +152,7 @@ func migrations_compliance01_initSql() (*asset, error) { return a, nil } -var _migrations_compliance02_auth_dataSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x74\xce\xb1\xaa\xc2\x30\x14\x87\xf1\xfd\x3c\xc5\x7f\x6c\xb9\xb7\x8b\xd0\xa9\x53\xb4\x19\xc4\xd8\x96\x90\x0e\x9d\xe4\x60\x8a\xc9\xd0\x56\xc2\xa9\xfa\xf8\xe2\xa6\x82\xf3\x07\x1f\xbf\xa2\xc0\xdf\x14\x2f\x89\x65\x44\x7f\xa5\x9d\xd5\xca\x69\x38\xb5\x35\x1a\x6a\x95\x50\xb3\x30\x32\x02\xa2\xc7\x8d\xd3\x39\x70\xca\x36\x65\x99\xa3\x69\x1d\x9a\xde\x98\x7f\x02\xfc\x32\x71\x9c\x7f\x77\x5e\x25\x9c\xfc\xeb\x24\xe3\x43\x3e\x12\x01\x9d\xdd\x1f\x95\x1d\x70\xd0\x03\xb2\xe8\x73\xca\x2b\xa2\x77\x57\xbd\xdc\x67\xaa\x6d\xdb\x7d\xb9\x2a\x7a\x06\x00\x00\xff\xff\x47\x8b\x6d\x94\xbe\x00\x00\x00") +var _migrations_compliance02_auth_dataSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x74\x8f\xb1\x4f\x85\x30\x10\x87\xf7\xfb\x2b\x7e\x23\x44\xdf\x62\xf2\x26\xa6\x6a\x3b\x10\xb1\x60\x43\x13\x99\xc8\x69\x1b\x68\x22\xa0\xa5\xa8\x7f\xbe\x61\x30\xa2\xc9\x5b\xef\xbb\xcb\x7d\xdf\xe9\x84\xab\x29\x0c\x91\x93\x87\x7d\xa3\x3b\xa3\x44\xab\xd0\x8a\xdb\x4a\x41\x6c\x69\x94\x9c\x18\x19\x01\xc1\xe1\x39\x0c\xab\x8f\x81\x5f\xaf\x09\x88\xfe\x7d\xf3\x6b\xea\x83\xc3\x07\xc7\x97\x91\x63\x76\x73\x3e\xe7\xd0\x75\x0b\x6d\xab\x6a\xdf\x71\xcb\xc4\x61\xbe\xcc\x79\x4b\x63\xef\xf6\x0f\xc9\x7f\xa5\x3f\x88\x80\xc6\x94\x0f\xc2\x74\xb8\x57\x1d\xb2\xe0\x72\xca\x0b\xfa\x11\xb4\xba\x7c\xb4\x0a\xa5\x96\xea\xe9\xa8\x52\xeb\x83\xf5\xef\x7c\xbf\x3c\x96\xca\xe5\x73\x26\x69\xea\xe6\x5f\x69\x41\xdf\x01\x00\x00\xff\xff\x0e\x07\x5f\x45\x10\x01\x00\x00") func migrations_compliance02_auth_dataSqlBytes() ([]byte, error) { return bindataRead( @@ -167,7 +167,7 @@ func migrations_compliance02_auth_dataSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations_compliance/02_auth_data.sql", size: 190, mode: os.FileMode(420), modTime: time.Unix(1528369177, 0)} + info := bindataFileInfo{name: "migrations_compliance/02_auth_data.sql", size: 272, mode: os.FileMode(420), modTime: time.Unix(1528451691, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/src/github.com/stellar/gateway/db/drivers/postgres/migrations_compliance/02_auth_data.sql b/src/github.com/stellar/gateway/db/drivers/postgres/migrations_compliance/02_auth_data.sql index abc569a..dbffdae 100644 --- a/src/github.com/stellar/gateway/db/drivers/postgres/migrations_compliance/02_auth_data.sql +++ b/src/github.com/stellar/gateway/db/drivers/postgres/migrations_compliance/02_auth_data.sql @@ -1,11 +1,14 @@ -- +migrate Up CREATE TABLE AuthData ( - id varchar(255) NOT NULL, + id bigserial, + request_id varchar(255) NOT NULL, domain varchar(255) NOT NULL, auth_data text NOT NULL, PRIMARY KEY (id) ); +CREATE UNIQUE INDEX request_id ON AuthData (request_id); + -- +migrate Down DROP TABLE AuthData; diff --git a/src/github.com/stellar/gateway/db/entities/auth_data.go b/src/github.com/stellar/gateway/db/entities/auth_data.go index cdc9b91..3521563 100644 --- a/src/github.com/stellar/gateway/db/entities/auth_data.go +++ b/src/github.com/stellar/gateway/db/entities/auth_data.go @@ -2,20 +2,21 @@ package entities // AuthData represents auth data type AuthData struct { - exists bool - ID string `db:"id"` - Domain string `db:"domain"` - AuthData string `db:"auth_data"` + exists bool + ID *int64 `db:"id"` + RequestID string `db:"request_id"` + Domain string `db:"domain"` + AuthData string `db:"auth_data"` } // GetID returns ID of the entity func (e *AuthData) GetID() *int64 { - return nil + return e.ID } // SetID sets ID of the entity func (e *AuthData) SetID(id int64) { - // + e.ID = &id } // IsNew returns true if the entity has not been persisted yet From bad9f6b496648af32e8a56530c0737227d9d468c Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Fri, 8 Jun 2018 12:03:39 +0200 Subject: [PATCH 5/7] Fix migrations --- src/github.com/stellar/gateway/db/drivers/mysql/bindata.go | 4 ++-- .../db/drivers/mysql/migrations_compliance/02_auth_data.sql | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/github.com/stellar/gateway/db/drivers/mysql/bindata.go b/src/github.com/stellar/gateway/db/drivers/mysql/bindata.go index a8cde67..0dd7613 100644 --- a/src/github.com/stellar/gateway/db/drivers/mysql/bindata.go +++ b/src/github.com/stellar/gateway/db/drivers/mysql/bindata.go @@ -152,7 +152,7 @@ func migrations_compliance01_initSql() (*asset, error) { return a, nil } -var _migrations_compliance02_auth_dataSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x90\xb1\x4e\xc3\x30\x10\x86\x77\x3f\xc5\x8d\x8e\x68\x87\x22\x55\x42\xaa\x3a\xb8\xf1\x01\x16\xa9\x53\x8c\x3d\x74\x4a\x2c\x12\x48\x86\x3a\x60\xce\xc0\xe3\x23\x67\xa1\x15\x12\xe3\xfd\xf7\x9d\xee\xd7\xb7\x5c\xc2\xd5\x69\x7c\x8d\x9e\x7a\x70\x6f\xac\x34\x28\x2c\x82\x15\xbb\x0a\xa1\x15\x89\x06\xe9\xc9\xb7\xc0\x19\x40\x3b\x76\x2d\x8c\x81\xf8\x6a\x55\x80\xae\x2d\x68\x57\x55\x20\x9c\xad\x1b\xa5\x4b\x83\x7b\xd4\x76\x91\xb9\xd8\xbf\xa7\xfe\x83\x9a\xcc\x7f\xfa\xf8\x3c\xf8\xc8\xaf\xd7\xeb\xdf\xa3\x99\xea\xa6\x93\x1f\xc3\x7f\x84\x4f\x34\x34\xdd\xfc\x9f\xfa\x6f\xba\x58\x1e\x8c\xda\x0b\x73\x84\x07\x3c\x02\xcf\xcd\x8a\x9c\x3a\xad\x1e\x1d\xce\xe1\x45\x0b\x7e\x3e\x15\x0b\x56\x00\xea\x3b\xa5\x71\xab\x42\x98\xe4\x0e\x24\xde\x0a\x57\x59\x28\xef\x85\x79\x42\xbb\x4d\xf4\x72\xb3\x61\xec\x5c\x8e\x9c\xbe\x02\x93\xa6\x3e\xfc\x91\xb3\x61\x3f\x01\x00\x00\xff\xff\x87\x4c\xc4\xc0\x45\x01\x00\x00") +var _migrations_compliance02_auth_dataSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x90\xb1\x4e\xc3\x30\x10\x86\x77\x3f\xc5\x8d\x8e\xa0\x43\x91\x2a\x21\x55\x1d\xdc\xf8\x00\x8b\xd4\x29\xc6\x1e\x3a\x25\x16\x09\x24\x43\x1d\x30\x67\xe0\xf1\x91\xb3\xd0\x0a\xa9\xe3\xfd\xf7\x9d\xee\xd7\xb7\x58\xc0\xd5\x71\x7c\x8b\x9e\x7a\x70\xef\xac\x34\x28\x2c\x82\x15\xdb\x0a\xa1\x15\x89\x06\xe9\xc9\xb7\xc0\x19\x40\x3b\x76\x2d\x8c\x81\xf8\x72\x59\x80\xae\x2d\x68\x57\x55\x20\x9c\xad\x1b\xa5\x4b\x83\x3b\xd4\xf6\x3a\x73\xb1\xff\x48\xfd\x27\x35\x99\xff\xf2\xf1\x65\xf0\x91\xdf\xac\x56\x7f\x47\x33\xd5\x4d\x47\x3f\x86\x4b\x84\x4f\x34\x34\xdd\xfc\x9f\xfa\x1f\x3a\x5b\xee\x8d\xda\x09\x73\x80\x47\x3c\x00\xcf\xcd\x8a\x9c\x3a\xad\x9e\x1c\xce\xe1\x59\x0b\x7e\x3a\x15\xac\x00\xd4\xf7\x4a\xe3\x46\x85\x30\xc9\x2d\x48\xbc\x13\xae\xb2\x50\x3e\x08\xf3\x8c\x76\x93\xe8\xf5\x76\xcd\xd8\xa9\x1b\x39\x7d\x07\x26\x4d\xbd\xff\xe7\x66\xcd\x7e\x03\x00\x00\xff\xff\xdd\xf4\xfc\xaa\x44\x01\x00\x00") func migrations_compliance02_auth_dataSqlBytes() ([]byte, error) { return bindataRead( @@ -167,7 +167,7 @@ func migrations_compliance02_auth_dataSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations_compliance/02_auth_data.sql", size: 325, mode: os.FileMode(420), modTime: time.Unix(1528451670, 0)} + info := bindataFileInfo{name: "migrations_compliance/02_auth_data.sql", size: 324, mode: os.FileMode(420), modTime: time.Unix(1528452152, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/src/github.com/stellar/gateway/db/drivers/mysql/migrations_compliance/02_auth_data.sql b/src/github.com/stellar/gateway/db/drivers/mysql/migrations_compliance/02_auth_data.sql index 313d4aa..be46194 100644 --- a/src/github.com/stellar/gateway/db/drivers/mysql/migrations_compliance/02_auth_data.sql +++ b/src/github.com/stellar/gateway/db/drivers/mysql/migrations_compliance/02_auth_data.sql @@ -5,7 +5,7 @@ CREATE TABLE `AuthData` ( `domain` varchar(255) NOT NULL, `auth_data` text NOT NULL, PRIMARY KEY (`id`), - UNIQUE KEY `request_id` (`request_id`), + UNIQUE KEY `request_id` (`request_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- +migrate Down From 1421e276027e6188d12b8e2166e478580005dccb Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Fri, 8 Jun 2018 12:12:55 +0200 Subject: [PATCH 6/7] Fix query --- src/github.com/stellar/gateway/db/repository.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/github.com/stellar/gateway/db/repository.go b/src/github.com/stellar/gateway/db/repository.go index daf7dbf..91addb7 100644 --- a/src/github.com/stellar/gateway/db/repository.go +++ b/src/github.com/stellar/gateway/db/repository.go @@ -15,7 +15,7 @@ type RepositoryInterface interface { GetSentTransactionByPaymentID(paymentID string) (*entities.SentTransaction, error) GetAllowedFiByDomain(domain string) (*entities.AllowedFi, error) GetAllowedUserByDomainAndUserID(domain, userID string) (*entities.AllowedUser, error) - GetAuthData(id string) (*entities.AuthData, error) + GetAuthData(requestID string) (*entities.AuthData, error) GetReceivedPaymentByOperationID(operationID int64) (*entities.ReceivedPayment, error) GetReceivedPayments(page, limit int) ([]*entities.ReceivedPayment, error) GetSentTransactions(page, limit int) ([]*entities.SentTransaction, error) @@ -166,14 +166,14 @@ func (r Repository) GetReceivedPaymentByOperationID(operationID int64) (*entitie return &found, nil } -// GetAuthData returns received auth data by id -func (r Repository) GetAuthData(id string) (*entities.AuthData, error) { +// GetAuthData returns received auth data by request_id +func (r Repository) GetAuthData(requestID string) (*entities.AuthData, error) { var found entities.AuthData err := r.repo.GetRaw( &found, - "SELECT * FROM AuthData WHERE id = ?", - id, + "SELECT * FROM AuthData WHERE request_id = ?", + requestID, ) if r.repo.NoRows(err) { From 168e002f1fcf0aa97ef332b1f4030c89bda4b38a Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Wed, 13 Jun 2018 13:45:37 +0200 Subject: [PATCH 7/7] Send error response --- .../stellar/gateway/compliance/handlers/request_handler_send.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go b/src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go index 2fc3e9f..0ca142a 100644 --- a/src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go +++ b/src/github.com/stellar/gateway/compliance/handlers/request_handler_send.go @@ -284,6 +284,8 @@ func (rh *RequestHandler) HandlerSend(c web.C, w http.ResponseWriter, r *http.Re } err = rh.EntityManager.Persist(authDataEntity) if err != nil { + log.WithFields(log.Fields{"err": err}).Warn("Error persisting authDataEntity") + server.Write(w, protocols.InternalServerError) return }