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

Commit 6abde83

Browse files
committed
Hooks -> Callbacks
Close #16
1 parent 405c9d9 commit 6abde83

File tree

7 files changed

+40
-40
lines changed

7 files changed

+40
-40
lines changed

config-example.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ url = "root:@/gateway_test?parseTime=true"
2121
authorizing_seed = "SDMRITVCFY6IIK6H5DXIVUOL342YFVE3VFOGVF3D7XXHGITPX4ABMYXR" # GCAW3TYUYGCNODKO4QKMD6PSH5GP3KES4GWGVFCKZ6DD6EJUDUQ77BO
2222
receiving_account_id = "GAJBUSUTGTS3MAU2KP6MWJFJACDN4ZJ5YCET23U6XYZZ7WUD2OYQQUR2"
2323

24-
[hooks]
24+
[callbacks]
2525
receive = "http://localhost:8002/receive"
2626
error = "http://localhost:8002/error"

readme_bridge.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ The `config_bridge.toml` file must be present in a working directory. Config fil
4040
* `base_seed` - The secret seed of the account used to send payments. If left blank you will need to pass it in calls to `/payment`.
4141
* `authorizing_seed` - The secret seed of the public key that is able to submit `allow_trust` operations on the issuing account.
4242
* `issuing_account_id` - The account ID of the issuing account.
43-
* `receiving_account_id` - The account ID that receives incoming payments. The `receive hook` will be called when a payment is received by this account.
44-
* `hooks`
45-
* `receive` - URL of the webhook where requests will be sent when a new payment is sent to the receiving account. The bridge server will keep calling the receive hook indefinitely until 200 OK status is returned by it. **WARNING** The bridge server can send multiple requests to this webhook for a single payment! You need to be prepared for it. See: [Security](#security).
43+
* `receiving_account_id` - The account ID that receives incoming payments. The `callbacks.receive` will be called when a payment is received by this account.
44+
* `callbacks`
45+
* `receive` - URL of the webhook where requests will be sent when a new payment is sent to the receiving account. The bridge server will keep calling the receive callback indefinitely until 200 OK status is returned by it. **WARNING** The bridge server can send multiple requests to this webhook for a single payment! You need to be prepared for it. See: [Security](#security).
4646
* `error` - URL of the webhook where requests will be sent when there is an error with an incoming payment
4747
* `log_format` - set to `json` for JSON logs
4848

@@ -347,18 +347,18 @@ It will return [`SubmitTransactionResponse`](./blob/master/src/github.com/stella
347347
* [`AllowTrustTrustNotRequired`](./blob/master/src/github.com/stellar/gateway/protocols/bridge/authorize.go)
348348
* [`AllowTrustCantRevoke`](./blob/master/src/github.com/stellar/gateway/protocols/bridge/authorize.go)
349349

350-
## Hooks
350+
## Callbacks
351351

352352
The Bridge server listens for payment operations to the account specified by `accounts.receiving_account_id`. Every time
353-
a payment arrives it will send a HTTP POST request to `hooks.receive`.
353+
a payment arrives it will send a HTTP POST request to `callbacks.receive`.
354354

355355
`Content-Type` of requests data will be `application/x-www-form-urlencoded`.
356356

357-
### `hooks.receive`
357+
### `callbacks.receive`
358358

359-
The POST request with following parameters will be sent to this hook when a payment arrives.
359+
The POST request with following parameters will be sent to this callback when a payment arrives.
360360

361-
> **Warning!** This hook can be called multiple times. Please check `id` parameter and respond with `200 OK` in case of duplicate payment.
361+
> **Warning!** This callback can be called multiple times. Please check `id` parameter and respond with `200 OK` in case of duplicate payment.
362362
363363
#### Request
364364

@@ -381,8 +381,8 @@ Respond with `200 OK` when processing succeeded. Any other status code will be c
381381
* This server must be set up in an isolated environment (ex. AWS VPC). Please make sure your firewall is properly configured
382382
and accepts connections from a trusted IPs only. You can also set the `api_key` config parameter but it's not recommended.
383383
If you don't set this properly, an unauthorized person will be able to submit transactions from your accounts!
384-
* Make sure the `hooks` you provide only accept connections from the bridge server IP.
385-
* Remember that `hooks.receive` may be called multiple times with the same payment. Check `id` parameter and ignore
384+
* Make sure the `callbacks` you provide only accept connections from the bridge server IP.
385+
* Remember that `callbacks.receive` may be called multiple times with the same payment. Check `id` parameter and ignore
386386
requests with the same value (just send `200 OK` response).
387387

388388
## Building

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ func NewApp(config config.Config, migrateFlag bool) (app *App, err error) {
115115

116116
if config.Accounts.ReceivingAccountID == "" {
117117
log.Warning("No accounts.receiving_account_id param. Skipping...")
118-
} else if config.Hooks.Receive == "" {
119-
log.Warning("No hooks.receive param. Skipping...")
118+
} else if config.Callbacks.Receive == "" {
119+
log.Warning("No callbacks.receive param. Skipping...")
120120
} else {
121121
paymentListener, err = listener.NewPaymentListener(&config, entityManager, &h, repository, time.Now)
122122
if err != nil {

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Config struct {
2121
URL string
2222
}
2323
Accounts
24-
Hooks
24+
Callbacks
2525
}
2626

2727
// Asset represents credit asset
@@ -38,8 +38,8 @@ type Accounts struct {
3838
ReceivingAccountID string `mapstructure:"receiving_account_id"`
3939
}
4040

41-
// Hooks contains values of `hooks` config group
42-
type Hooks struct {
41+
// Callbacks contains values of `callbacks` config group
42+
type Callbacks struct {
4343
Receive string
4444
Error string
4545
}
@@ -123,18 +123,18 @@ func (c *Config) Validate() (err error) {
123123
}
124124
}
125125

126-
if c.Hooks.Receive != "" {
127-
_, err = url.Parse(c.Hooks.Receive)
126+
if c.Callbacks.Receive != "" {
127+
_, err = url.Parse(c.Callbacks.Receive)
128128
if err != nil {
129-
err = errors.New("Cannot parse hooks.receive param")
129+
err = errors.New("Cannot parse callbacks.receive param")
130130
return
131131
}
132132
}
133133

134-
if c.Hooks.Error != "" {
135-
_, err = url.Parse(c.Hooks.Error)
134+
if c.Callbacks.Error != "" {
135+
_, err = url.Parse(c.Callbacks.Error)
136136
if err != nil {
137-
err = errors.New("Cannot parse hooks.error param")
137+
err = errors.New("Cannot parse callbacks.error param")
138138
return
139139
}
140140
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type PaymentListener struct {
2929
now func() time.Time
3030
}
3131

32-
const hookTimeout = 10 * time.Second
32+
const callbackTimeout = 10 * time.Second
3333

3434
// NewPaymentListener creates a new PaymentListener
3535
func NewPaymentListener(
@@ -40,7 +40,7 @@ func NewPaymentListener(
4040
now func() time.Time,
4141
) (pl PaymentListener, err error) {
4242
pl.client = &http.Client{
43-
Timeout: hookTimeout,
43+
Timeout: callbackTimeout,
4444
}
4545
pl.config = config
4646
pl.entityManager = entityManager
@@ -192,7 +192,7 @@ func (pl PaymentListener) onPayment(payment horizon.PaymentResponse) (err error)
192192
}
193193

194194
resp, err := pl.client.PostForm(
195-
pl.config.Hooks.Receive,
195+
pl.config.Callbacks.Receive,
196196
url.Values{
197197
"id": {payment.ID},
198198
"from": {payment.From},
@@ -204,23 +204,23 @@ func (pl PaymentListener) onPayment(payment horizon.PaymentResponse) (err error)
204204
},
205205
)
206206
if err != nil {
207-
pl.log.Error("Error sending request to receive hook")
207+
pl.log.Error("Error sending request to receive callback")
208208
return err
209209
}
210210

211211
if resp.StatusCode != 200 {
212212
defer resp.Body.Close()
213213
body, err := ioutil.ReadAll(resp.Body)
214214
if err != nil {
215-
pl.log.Error("Error reading receive hook response")
215+
pl.log.Error("Error reading receive callback response")
216216
return err
217217
}
218218

219219
pl.log.WithFields(logrus.Fields{
220220
"status": resp.StatusCode,
221221
"body": string(body),
222-
}).Error("Error response from receive hook")
223-
return errors.New("Error response from receive hook")
222+
}).Error("Error response from receive callback")
223+
return errors.New("Error response from receive callback")
224224
}
225225

226226
dbPayment.Status = "Success"

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ func TestPaymentListener(t *testing.T) {
3030
IssuingAccountID: "GATKP6ZQM5CSLECPMTAC5226PE367QALCPM6AFHTSULPPZMT62OOPMQB",
3131
ReceivingAccountID: "GATKP6ZQM5CSLECPMTAC5226PE367QALCPM6AFHTSULPPZMT62OOPMQB",
3232
},
33-
Hooks: config.Hooks{
34-
Receive: "http://receive_hook",
33+
Callbacks: config.Callbacks{
34+
Receive: "http://receive_callback",
3535
},
3636
}
3737

@@ -148,7 +148,7 @@ func TestPaymentListener(t *testing.T) {
148148
})
149149
})
150150

151-
Convey("When receive hook returns error", func() {
151+
Convey("When receive callback returns error", func() {
152152
operation.Type = "payment"
153153
operation.To = "GATKP6ZQM5CSLECPMTAC5226PE367QALCPM6AFHTSULPPZMT62OOPMQB"
154154
operation.AssetCode = "USD"
@@ -161,7 +161,7 @@ func TestPaymentListener(t *testing.T) {
161161

162162
mockHTTPClient.On(
163163
"PostForm",
164-
"http://receive_hook",
164+
"http://receive_callback",
165165
url.Values{
166166
"id": {"1"},
167167
"from": {"GBIHSMPXC2KJ3NJVHEYTG3KCHYEUQRT45X6AWYWXMAXZOAX4F5LFZYYQ"},
@@ -184,7 +184,7 @@ func TestPaymentListener(t *testing.T) {
184184
})
185185
})
186186

187-
Convey("When receive hook returns success", func() {
187+
Convey("When receive callback returns success", func() {
188188
operation.Type = "payment"
189189
operation.To = "GATKP6ZQM5CSLECPMTAC5226PE367QALCPM6AFHTSULPPZMT62OOPMQB"
190190
operation.AssetCode = "USD"
@@ -200,7 +200,7 @@ func TestPaymentListener(t *testing.T) {
200200

201201
mockHTTPClient.On(
202202
"PostForm",
203-
"http://receive_hook",
203+
"http://receive_callback",
204204
url.Values{
205205
"id": {"1"},
206206
"from": {"GBIHSMPXC2KJ3NJVHEYTG3KCHYEUQRT45X6AWYWXMAXZOAX4F5LFZYYQ"},
@@ -223,7 +223,7 @@ func TestPaymentListener(t *testing.T) {
223223
})
224224
})
225225

226-
Convey("When receive hook returns success (no memo)", func() {
226+
Convey("When receive callback returns success (no memo)", func() {
227227
operation.Type = "payment"
228228
operation.To = "GATKP6ZQM5CSLECPMTAC5226PE367QALCPM6AFHTSULPPZMT62OOPMQB"
229229
operation.AssetCode = "USD"
@@ -237,7 +237,7 @@ func TestPaymentListener(t *testing.T) {
237237

238238
mockHTTPClient.On(
239239
"PostForm",
240-
"http://receive_hook",
240+
"http://receive_callback",
241241
url.Values{
242242
"id": {"1"},
243243
"from": {"GBIHSMPXC2KJ3NJVHEYTG3KCHYEUQRT45X6AWYWXMAXZOAX4F5LFZYYQ"},
@@ -260,7 +260,7 @@ func TestPaymentListener(t *testing.T) {
260260
})
261261
})
262262

263-
Convey("When receive hook returns success and compliance server is connected", func() {
263+
Convey("When receive callback returns success and compliance server is connected", func() {
264264
paymentListener.config.Compliance = "http://compliance"
265265

266266
operation.Type = "payment"
@@ -287,7 +287,7 @@ func TestPaymentListener(t *testing.T) {
287287

288288
mockHTTPClient.On(
289289
"PostForm",
290-
"http://receive_hook",
290+
"http://receive_callback",
291291
url.Values{
292292
"id": {"1"},
293293
"from": {"GBIHSMPXC2KJ3NJVHEYTG3KCHYEUQRT45X6AWYWXMAXZOAX4F5LFZYYQ"},

src/github.com/stellar/gateway/protocols/compliance/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ When you want to use compliance protocol when receiving payments...
6464
| □<-----------------------------------□ |
6565
| □ | |
6666
| □~~~ - Bridge server will send | |
67-
| □ a receive hook with | |
67+
| □ a receive callback with | |
6868
| □ `extra_memo` preimage | |
6969
| □ | |
7070
| | | |

0 commit comments

Comments
 (0)