-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.php
529 lines (504 loc) · 24 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
<?php
// Copyright (c) 2018-2022 The CYBAVO developers
// All Rights Reserved.
// NOTICE: All information contained herein is, and remains
// the property of CYBAVO and its suppliers,
// if any. The intellectual and technical concepts contained
// herein are proprietary to CYBAVO
// Dissemination of this information or reproduction of this materia
// is strictly forbidden unless prior written permission is obtained
// from CYBAVO.
include_once 'helper/apicaller.php';
include_once 'models/apicode.php';
include_once 'mockserver.conf.php';
date_default_timezone_set('UTC');
init_db();
function log_access($uri, $resp) {
file_put_contents('php://stdout', sprintf('[%s] %s %s %d', date('D M j H:i:s Y'),
$uri, json_encode(json_decode($resp['result'])), $resp['status'])."\n");
}
function log_text($uri, $text) {
file_put_contents('php://stdout', sprintf('[%s] %s %s', date('D M j H:i:s Y'), $uri, $text)."\n");
}
function get_query_params() {
$params = parse_url($_SERVER["REQUEST_URI"], PHP_URL_QUERY);
return explode('&', $params);
}
function response($resp)
{
header_remove();
http_response_code($resp['status']);
header('Content-Type: application/json');
return json_encode(json_decode($resp['result']));
}
function response_plaintext($status_code, $text)
{
header_remove();
http_response_code($status_code);
return $text;
}
function base64url_encode($data) {
return strtr(base64_encode($data), '+/', '-_');
}
$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
$method = $_SERVER['REQUEST_METHOD'];
$post_data = file_get_contents('php://input');
$query = get_query_params();
if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/apitoken$/i', $path, $m)) {
$payload = json_decode($post_data, true);
set_api_code($m['wallet_id'], $payload['api_code'], $payload['api_secret']);
$resp['status'] = 200;
$resp['result'] = '{"result": 1}';
log_access($m['0'], $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/addresses$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/addresses';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/pooladdress$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/pooladdress';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/pooladdress\/balance$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/pooladdress/balance';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/collection\/notifications\/manual$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/collection/notifications/manual';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/sender\/transactions$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/sender/transactions';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/sender\/transactions\/(?<order_id>[\w\-_]+)\/cancel$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/sender/transactions/'.$m['order_id'].'/cancel';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/sender\/transactions\/(?<order_id>[\w\-_]+)$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/sender/transactions/'.$m['order_id'];
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/sender\/transactions\/(?<order_id>[\w\-_]+)\/all$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/sender/transactions/'.$m['order_id'].'/all';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/sender\/balance$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/sender/balance';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/apisecret$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/apisecret';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/apisecret\/activate$/i', $path, $m)) {
if ($m['wallet_id'] == 0) {
$uri = '/v1/sofa/wallets/readonly/apisecret/activate';
} else {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/apisecret/activate';
}
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/notifications$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/notifications';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/notifications\/get_by_id$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/notifications/get_by_id';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/receiver\/notifications\/txid\/(?<txid>[\w\-_]+)\/(?<vout_index>\d+)$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/receiver/notifications/txid/'.$m['txid'].'/'.$m['vout_index'];
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/sender\/notifications\/order_id\/(?<order_id>[\w\-_]+)$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/sender/notifications/order_id/'.$m['order_id'].'/'.$m['vout_index'];
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/transactions$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/transactions';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/blocks$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/blocks';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/addresses\/invalid-deposit$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/addresses/invalid-deposit';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/info$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/info';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/addresses\/verify$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/addresses/verify';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/autofee$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/autofee';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/receiver\/balance$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/receiver/balance';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/vault\/balance$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/vault/balance';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (!strcmp($path, '/v1/mock/wallets/callback')) {
$callback = json_decode($post_data, true);
$ac = get_api_code($callback['wallet_id']);
$header_checksum = $_SERVER['HTTP_X_CHECKSUM'];
$payload = $post_data.$ac['api_secret'];
$checksum = base64url_encode(hash('sha256', $payload, true));
log_text('/v1/mock/callback',
"header_checksum: ".$header_checksum." <-> checksum: ".$checksum."\npayload: ".$post_data);
if (!strcmp($header_checksum, $checksum)) {
// Callback Type
// DepositCallback = 1
// WithdrawCallback = 2
// CollectCallback = 3
// AirdropCallback = 4
// Processing State
// ProcessingStateInPool = 0
// ProcessingStateInChain = 1
// ProcessingStateDone = 2
// Callback State
// CallbackStateHolding = 1
// CallbackStateInPool = 2
// CallbackStateInChain = 3
// CallbackStateFailed = 5
// CallbackStateCancelled = 8
// CallbackStateDropped = 10
// CallbackStateInChainFailed = 11
$callback = json_decode($post_data, true);
if ($callback['type'] == 1) { // DepositCallback
//
// deposit unique ID
$uniqueID = $callback['txid'].'_'.$callback['vout_index'];
//
if ($callback['processing_state'] == 2) { // ProcessingStateDone
// deposit succeeded, use the deposit unique ID to update your business logic
}
} else if ($callback['type'] == 2) { // WithdrawCallback
//
// withdrawal unique ID
$uniqueID = $callback['order_id'];
//
if ($callback['state'] == 3 && $callback['processing_state'] == 2) { // CallbackStateInChain && ProcessingStateDone
// withdrawal succeeded, use the withdrawal uniqueID to update your business logic
} else if ($callback['state'] == 5 || $callback['state'] == 11) { // CallbackStateFailed || CallbackStateInChainFailed
// withdrawal failed, use the withdrawal unique ID to update your business logic
}
} else if ($callback['type'] == 4) { // AirdropCallback
//
// airdrop unique ID
$uniqueID = $callback['txid'].'_'.$callback['vout_index'];
//
if ($callback['processing_state'] == 2) { // ProcessingStateDone
// airdrop succeeded, use the airdrop unique ID to update your business logic
}
}
// reply 200 OK to confirm the callback has been processed
echo response_plaintext(200, 'OK');
} else {
echo response_plaintext(400, 'Bad checksum');
}
return;
} else if (!strcmp($path, '/v1/mock/wallets/withdrawal/callback')) {
$callback = json_decode($post_data, true);
// How to verify:
// 1. Try to find corresponding API secret by $callback['order_id']
// 2. Calculate checksum then compare to X-CHECKSUM header (refer to sample code bellow)
// 3. If these two checksums match and the request is valid in your system,
// reply 200, OK otherwise reply 400 to decline the withdrawal
// sample code to calculate checksum and verify
// $header_checksum = $_SERVER['HTTP_X_CHECKSUM'];
// $payload = $post_data.$ac['api_secret'];
// $checksum = base64url_encode(hash('sha256', $payload, true));
// if (strcmp($header_checksum, $checksum) != 0) {
// echo response_plaintext(400, 'Bad checksum');
// return;
// }
// reply 200 OK to confirm the callback has been processed
echo response_plaintext(200, 'OK');
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/addresses\/contract_txid$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/addresses/contract_txid';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/sender\/transactions\/acl$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/sender/transactions/acl';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/sender\/notifications\/manual$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/sender/notifications/manual';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/refreshsecret$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/refreshsecret';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/sender\/whitelist$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/sender/whitelist';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/sender\/whitelist\/config$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/sender/whitelist/config';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/sender\/whitelist\/check$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/sender/whitelist/check';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/addresses\/label$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/addresses/label';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/addresses\/get_labels$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/addresses/get_labels';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/readonly\/walletlist$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/readonly/walletlist';
$resp = make_request(0, $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/merchant\/(?<merchant_id>\d+)\/apitoken$/i', $path, $m)) {
$payload = json_decode($post_data, true);
set_api_code($m['merchant_id'], $payload['api_code'], $payload['api_secret']);
$resp['status'] = 200;
$resp['result'] = '{"result": 1}';
log_access($m['0'], $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/merchant\/(?<merchant_id>\d+)\/order$/i', $path, $m)) {
if ($method == 'POST') {
$data = json_decode($post_data, true);
if (!empty($data) && !empty($data['redirect_url'])) {
$data['redirect_url'] = urlencode($data['redirect_url']);
$post_data = json_encode($data);
}
}
$uri = '/v1/merchant/'.$m['merchant_id'].'/order';
$resp = make_request($m['merchant_id'], $method, $uri, $query, $post_data);
if ($method == 'GET') {
$data = json_decode($resp['result'], true);
if (!empty($data['redirect_url'])) {
$data['redirect_url'] = urldecode($data['redirect_url']);
$resp['result'] = json_encode($data);
}
}
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/merchant\/(?<merchant_id>\d+)\/order\/duration$/i', $path, $m)) {
$uri = '/v1/merchant/'.$m['merchant_id'].'/order/duration';
$resp = make_request($m['merchant_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/merchant\/(?<merchant_id>\d+)\/apisecret$/i', $path, $m)) {
$uri = '/v1/merchant/'.$m['merchant_id'].'/apisecret';
$resp = make_request($m['merchant_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/merchant\/(?<merchant_id>\d+)\/apisecret\/activate$/i', $path, $m)) {
$uri = '/v1/merchant/'.$m['merchant_id'].'/apisecret/activate';
$resp = make_request($m['merchant_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/merchant\/(?<merchant_id>\d+)\/apisecret\/refreshsecret$/i', $path, $m)) {
$uri = '/v1/merchant/'.$m['merchant_id'].'/apisecret/refreshsecret';
$resp = make_request($m['merchant_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/merchant\/(?<merchant_id>\d+)\/notifications\/manual$/i', $path, $m)) {
$uri = '/v1/merchant/'.$m['merchant_id'].'/notifications/manual';
$resp = make_request($m['merchant_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (!strcmp($path, '/v1/mock/merchant/callback')) {
$callback = json_decode($post_data, true);
$ac = get_api_code($callback['merchant_id']);
$header_checksum = $_SERVER['HTTP_X_CHECKSUM'];
$payload = $post_data.$ac['api_secret'];
$checksum = base64url_encode(hash('sha256', $payload, true));
log_text('/v1/mock//merchant/callback',
"header_checksum: ".$header_checksum." <-> checksum: ".$checksum."\npayload: ".$post_data);
if (!strcmp($header_checksum, $checksum)) {
// Merchant Order State
// Success = 0
// Expired = 1
// Insufficient = 2
// Excess = 3
// Cancel = 4
$callback = json_decode($post_data, true);
if ($callback['state'] == 0) {
} else if ($callback['state'] == 1) {
} else if ($callback['state'] == 2) {
} else if ($callback['state'] == 3) {
} else if ($callback['state'] == 4) {
}
// reply 200 OK to confirm the callback has been processed
echo response_plaintext(200, 'OK');
} else {
echo response_plaintext(400, 'Bad checksum');
}
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/notifications\/inspect$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/notifications/inspect';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/sender\/transactions$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/sender/transactions';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/autofees$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/autofees';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/signmessage$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/signmessage';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/contract\/read$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/contract/read';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/sender\/transactions\/eventlog$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/sender/transactions/eventlog';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/readonly\/walletlist\/balances$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/readonly/walletlist/balances';
$resp = make_request(0, $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/receiver\/addresses\/verify$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/receiver/addresses/verify';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/currency\/prices$/i', $path)) {
$uri = '/v1/sofa/currency/prices';
$resp = make_request(0, $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/receiver\/get-balances$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/receiver/get-balances';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/currency\/(?<currency>\d+)\/contract\/get-multiple-tokenuri$/i', $path, $m)) {
$uri = '/v1/sofa/currency/'.$m['currency'].'/contract/get-multiple-tokenuri';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/wallets\/(?<wallet_id>\d+)\/signtransaction$/i', $path, $m)) {
$uri = '/v1/sofa/wallets/'.$m['wallet_id'].'/signtransaction';
$resp = make_request($m['wallet_id'], $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
} else if (preg_match('/\/v1\/mock\/healthcheck$/i', $path, $m)) {
$uri = '/v1/sofa/healthcheck';
$resp = make_request(null, $method, $uri, $query, $post_data);
log_access($uri, $resp);
echo response($resp);
return;
}
$resp['status'] = 404;
$resp['result'] = '{"result": "invalid path"}';
log_access($path, $resp);
echo response($resp);
?>