@pioneer-platform/binance-network 8.3.3 → 8.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/package.json +11 -11
- package/LICENSE +0 -674
- package/lib/index.d.ts +0 -31
- package/lib/index.js +0 -796
package/lib/index.js
DELETED
|
@@ -1,796 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
BNB network tools
|
|
4
|
-
|
|
5
|
-
basic fee
|
|
6
|
-
0.000375 BNB
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
BNB explorer
|
|
10
|
-
https://explorer.binance.org/address/bnb1nsxpvdupgn87td6jnekc8fhs0fkyschgk26yng
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//nodes
|
|
14
|
-
https://github.com/binance-chain/node-binary
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
//API
|
|
18
|
-
https://docs.binance.org/api-reference/node-rpc.html
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
//sdk
|
|
22
|
-
https://github.com/binance-chain/javascript-sdk
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
//examples
|
|
26
|
-
https://github.com/binance-chain/javascript-sdk/wiki/API-Examples
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
Available endpoints:
|
|
32
|
-
|
|
33
|
-
Endpoints that require arguments:
|
|
34
|
-
//dataseed1.binance.org/abci_info?
|
|
35
|
-
//dataseed1.binance.org/abci_query?path=_&data=_&height=_&prove=_
|
|
36
|
-
//dataseed1.binance.org/block?height=_
|
|
37
|
-
//dataseed1.binance.org/block_by_hash?hash=_
|
|
38
|
-
//dataseed1.binance.org/block_results?height=_
|
|
39
|
-
//dataseed1.binance.org/blockchain?minHeight=_&maxHeight=_
|
|
40
|
-
//dataseed1.binance.org/broadcast_evidence?evidence=_
|
|
41
|
-
//dataseed1.binance.org/broadcast_tx_async?tx=_
|
|
42
|
-
//dataseed1.binance.org/broadcast_tx_commit?tx=_
|
|
43
|
-
//dataseed1.binance.org/broadcast_tx_sync?tx=_
|
|
44
|
-
//dataseed1.binance.org/commit?height=_
|
|
45
|
-
//dataseed1.binance.org/consensus_params?height=_
|
|
46
|
-
//dataseed1.binance.org/consensus_state?
|
|
47
|
-
//dataseed1.binance.org/dump_consensus_state?
|
|
48
|
-
//dataseed1.binance.org/genesis?
|
|
49
|
-
//dataseed1.binance.org/health?
|
|
50
|
-
//dataseed1.binance.org/net_info?
|
|
51
|
-
//dataseed1.binance.org/num_unconfirmed_txs?
|
|
52
|
-
//dataseed1.binance.org/status?
|
|
53
|
-
//dataseed1.binance.org/subscribe?query=_
|
|
54
|
-
//dataseed1.binance.org/tx?hash=_&prove=_
|
|
55
|
-
//dataseed1.binance.org/tx_search?query=_&prove=_&page=_&per_page=_
|
|
56
|
-
//dataseed1.binance.org/unconfirmed_txs?limit=_
|
|
57
|
-
//dataseed1.binance.org/unsubscribe?query=_
|
|
58
|
-
//dataseed1.binance.org/unsubscribe_all?
|
|
59
|
-
//dataseed1.binance.org/validators?height=_
|
|
60
|
-
|
|
61
|
-
*/
|
|
62
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
63
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
64
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
65
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
66
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
67
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
68
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
72
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
73
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
74
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
75
|
-
function step(op) {
|
|
76
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
77
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
78
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
79
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
80
|
-
switch (op[0]) {
|
|
81
|
-
case 0: case 1: t = op; break;
|
|
82
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
83
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
84
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
85
|
-
default:
|
|
86
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
87
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
88
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
89
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
90
|
-
if (t[2]) _.ops.pop();
|
|
91
|
-
_.trys.pop(); continue;
|
|
92
|
-
}
|
|
93
|
-
op = body.call(thisArg, _);
|
|
94
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
95
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
var TAG = " | bnb-network | ";
|
|
99
|
-
var moment = require('moment');
|
|
100
|
-
var Axios = require('axios');
|
|
101
|
-
var https = require('https');
|
|
102
|
-
var axios = Axios.create({
|
|
103
|
-
httpsAgent: new https.Agent({
|
|
104
|
-
rejectUnauthorized: false
|
|
105
|
-
})
|
|
106
|
-
});
|
|
107
|
-
var log = require('@pioneer-platform/loggerdog')();
|
|
108
|
-
// let URL_BNBchaind = process.env["URL_BNB"] || 'http://127.0.0.1:27147'
|
|
109
|
-
// let URL_BNBcli = process.env["URL_BNBCLI"] || 'http://127.0.0.1:8333'
|
|
110
|
-
//Debug
|
|
111
|
-
var URL_BNBchaind = process.env["URL_BNB"] || 'https://dex.binance.org';
|
|
112
|
-
var URL_BNBcli = process.env["URL_BNBCLI"] || 'https://dex.binance.org';
|
|
113
|
-
var URL_REMOTE = process.env["URL_BNB_REMOTE"] || 'https://dataseed1.binance.org:443';
|
|
114
|
-
var URL_DEX = process.env["BNB_FULL_REMOTE"] || 'https://dex.binance.org';
|
|
115
|
-
var URL_DEX_0 = process.env["BNB_FULL_REMOTE_1"] || 'https://dex.binance.org';
|
|
116
|
-
var URL_DEX_1 = process.env["BNB_FULL_REMOTE_2"] || 'https://dex-atlantic.binance.org';
|
|
117
|
-
var URL_DEX_2 = process.env["BNB_FULL_REMOTE_3"] || 'https://dex-asiapacific.binance.org';
|
|
118
|
-
var URL_DEX_3 = process.env["BNB_FULL_REMOTE_4"] || 'https://dex-european.binance.org';
|
|
119
|
-
// @ts-ignore
|
|
120
|
-
var crypto = require('crypto');
|
|
121
|
-
//console.log(sdk)
|
|
122
|
-
//network.getTransactions()
|
|
123
|
-
// let client = sdk.BncClient(URL)
|
|
124
|
-
// console.log(client)
|
|
125
|
-
var ASSET = "BNB";
|
|
126
|
-
var ROUND_ROBIN_STATE = [];
|
|
127
|
-
var REMOTE_OVERRIDE_BNB = process.env['REMOTE_OVERRIDE_BNB'];
|
|
128
|
-
module.exports = {
|
|
129
|
-
init: function (mode, config) {
|
|
130
|
-
if (mode) {
|
|
131
|
-
//TODO override nodes
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
nodeInfo: function () {
|
|
137
|
-
return get_node_info();
|
|
138
|
-
},
|
|
139
|
-
nodeInfoSyncing: function () {
|
|
140
|
-
return get_node_syncing();
|
|
141
|
-
},
|
|
142
|
-
nodeInfoVersion: function () {
|
|
143
|
-
return get_node_version();
|
|
144
|
-
},
|
|
145
|
-
txs: function (address) {
|
|
146
|
-
return get_txs_by_address(address);
|
|
147
|
-
},
|
|
148
|
-
txsByHeight: function (height, address) {
|
|
149
|
-
return get_txs_by_height(height, address);
|
|
150
|
-
},
|
|
151
|
-
getBlockHeight: function () {
|
|
152
|
-
return get_block_height();
|
|
153
|
-
},
|
|
154
|
-
getTransaction: function (txid) {
|
|
155
|
-
return getTransaction(txid);
|
|
156
|
-
},
|
|
157
|
-
getBalance: function (address, token) {
|
|
158
|
-
return get_balance(address, token);
|
|
159
|
-
},
|
|
160
|
-
getBlock: function (height) {
|
|
161
|
-
return get_block(height);
|
|
162
|
-
},
|
|
163
|
-
getBlockRemote: function (height) {
|
|
164
|
-
return get_block_remote(height);
|
|
165
|
-
},
|
|
166
|
-
broadcast: function (tx) {
|
|
167
|
-
return broadcast_transaction(tx);
|
|
168
|
-
},
|
|
169
|
-
getAccount: function (address) {
|
|
170
|
-
return get_account(address);
|
|
171
|
-
},
|
|
172
|
-
// getSequence:function (address:string) {
|
|
173
|
-
// return get_account_sequence(address);
|
|
174
|
-
// },
|
|
175
|
-
// getValidators:function () {
|
|
176
|
-
// return get_validators();
|
|
177
|
-
// }
|
|
178
|
-
};
|
|
179
|
-
var get_block_height = function () {
|
|
180
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
181
|
-
var tag, output, height, bnbncliRemote, e_1, bnbncliRemote, e_2;
|
|
182
|
-
return __generator(this, function (_a) {
|
|
183
|
-
switch (_a.label) {
|
|
184
|
-
case 0:
|
|
185
|
-
tag = TAG + " | get_block_height | ";
|
|
186
|
-
output = {};
|
|
187
|
-
_a.label = 1;
|
|
188
|
-
case 1:
|
|
189
|
-
_a.trys.push([1, 7, , 8]);
|
|
190
|
-
height = void 0;
|
|
191
|
-
_a.label = 2;
|
|
192
|
-
case 2:
|
|
193
|
-
_a.trys.push([2, 4, , 6]);
|
|
194
|
-
return [4 /*yield*/, axios({ method: 'GET', url: URL_BNBchaind + '/abci_info' })];
|
|
195
|
-
case 3:
|
|
196
|
-
bnbncliRemote = _a.sent();
|
|
197
|
-
log.debug(tag, "bnbncliRemote: ", bnbncliRemote.data);
|
|
198
|
-
height = bnbncliRemote.data.result.response.last_block_height;
|
|
199
|
-
return [3 /*break*/, 6];
|
|
200
|
-
case 4:
|
|
201
|
-
e_1 = _a.sent();
|
|
202
|
-
return [4 /*yield*/, axios({ method: 'GET', url: URL_REMOTE + '/abci_info' })];
|
|
203
|
-
case 5:
|
|
204
|
-
bnbncliRemote = _a.sent();
|
|
205
|
-
log.debug(tag, "bnbncliRemote: ", bnbncliRemote.data);
|
|
206
|
-
height = bnbncliRemote.data.result.response.last_block_height;
|
|
207
|
-
return [3 /*break*/, 6];
|
|
208
|
-
case 6: return [2 /*return*/, height];
|
|
209
|
-
case 7:
|
|
210
|
-
e_2 = _a.sent();
|
|
211
|
-
//log.error(tag,"e: ",{e})
|
|
212
|
-
output.success = false;
|
|
213
|
-
output.error = e_2;
|
|
214
|
-
return [2 /*return*/, output];
|
|
215
|
-
case 8: return [2 /*return*/];
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
};
|
|
220
|
-
var get_balance = function (address, token) {
|
|
221
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
222
|
-
var tag, output, url, result, balanceInfo, i, assetInfo, e_3;
|
|
223
|
-
return __generator(this, function (_a) {
|
|
224
|
-
switch (_a.label) {
|
|
225
|
-
case 0:
|
|
226
|
-
tag = TAG + " | get_account | ";
|
|
227
|
-
output = {};
|
|
228
|
-
_a.label = 1;
|
|
229
|
-
case 1:
|
|
230
|
-
_a.trys.push([1, 3, , 4]);
|
|
231
|
-
if (!token)
|
|
232
|
-
token = ASSET;
|
|
233
|
-
log.debug(tag, "get_account: ", address);
|
|
234
|
-
url = URL_DEX + '/api/v1/account/' + address;
|
|
235
|
-
log.debug(tag, "url: ", url);
|
|
236
|
-
return [4 /*yield*/, axios({
|
|
237
|
-
url: url,
|
|
238
|
-
method: 'GET'
|
|
239
|
-
})];
|
|
240
|
-
case 2:
|
|
241
|
-
result = _a.sent();
|
|
242
|
-
balanceInfo = result.data;
|
|
243
|
-
log.debug('balanceInfo: ', balanceInfo);
|
|
244
|
-
if (!balanceInfo || !balanceInfo.balances || balanceInfo.balances.length === 0) {
|
|
245
|
-
output = 0;
|
|
246
|
-
}
|
|
247
|
-
for (i = 0; i < balanceInfo.balances.length; i++) {
|
|
248
|
-
assetInfo = balanceInfo.balances[i];
|
|
249
|
-
log.debug(tag, "assetInfo: ", assetInfo);
|
|
250
|
-
if (assetInfo.symbol === token) {
|
|
251
|
-
output = parseFloat(assetInfo.free);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return [2 /*return*/, output];
|
|
255
|
-
case 3:
|
|
256
|
-
e_3 = _a.sent();
|
|
257
|
-
//node 404's on fresh addresses like an asshole
|
|
258
|
-
return [2 /*return*/, 0];
|
|
259
|
-
case 4: return [2 /*return*/];
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
};
|
|
264
|
-
/*
|
|
265
|
-
|
|
266
|
-
https://docs.binance.org/api-reference/dex-api/paths.html#apiv1transactions
|
|
267
|
-
|
|
268
|
-
*/
|
|
269
|
-
var get_txs_by_address = function (address) {
|
|
270
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
271
|
-
var tag, output, output_1, startTime, url, resultSends, sends, e_4;
|
|
272
|
-
return __generator(this, function (_a) {
|
|
273
|
-
switch (_a.label) {
|
|
274
|
-
case 0:
|
|
275
|
-
tag = ' | get_txs_by_address | ';
|
|
276
|
-
output = {};
|
|
277
|
-
_a.label = 1;
|
|
278
|
-
case 1:
|
|
279
|
-
_a.trys.push([1, 3, , 4]);
|
|
280
|
-
output_1 = [];
|
|
281
|
-
startTime = moment().subtract('months', 6).unix();
|
|
282
|
-
startTime = startTime * 1000;
|
|
283
|
-
log.debug("startTime: ", startTime);
|
|
284
|
-
url = URL_DEX + '/api/v1/transactions?address=' + address + '&startTime=' + startTime;
|
|
285
|
-
log.debug(tag, "url: ", url);
|
|
286
|
-
return [4 /*yield*/, axios({
|
|
287
|
-
url: url,
|
|
288
|
-
method: 'GET'
|
|
289
|
-
})];
|
|
290
|
-
case 2:
|
|
291
|
-
resultSends = _a.sent();
|
|
292
|
-
sends = resultSends.data;
|
|
293
|
-
log.debug('sends: ', sends);
|
|
294
|
-
return [2 /*return*/, sends.tx];
|
|
295
|
-
case 3:
|
|
296
|
-
e_4 = _a.sent();
|
|
297
|
-
//log.error(tag,"e: ",{e})
|
|
298
|
-
output.success = false;
|
|
299
|
-
output.error = e_4;
|
|
300
|
-
return [2 /*return*/, output];
|
|
301
|
-
case 4: return [2 /*return*/];
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
};
|
|
306
|
-
// let get_txs_by_address = async function(address){
|
|
307
|
-
// let tag = TAG + " | get_txs_by_height | "
|
|
308
|
-
// try{
|
|
309
|
-
//
|
|
310
|
-
//
|
|
311
|
-
// //log.debug(network)
|
|
312
|
-
// let txs = network.getTransactions(address,0)
|
|
313
|
-
//
|
|
314
|
-
// // let txInfo = await axios({method:'GET',url:URL_BNBcli+'/tx_search?address='+address})
|
|
315
|
-
// // log.debug(tag,"txInfo: ",txInfo.data)
|
|
316
|
-
//
|
|
317
|
-
//
|
|
318
|
-
// return txs
|
|
319
|
-
// }catch(e){
|
|
320
|
-
// //log.error(tag,"e: ",{e})
|
|
321
|
-
// let output:any = {}
|
|
322
|
-
// output.success = false
|
|
323
|
-
// output.error = e
|
|
324
|
-
// return output
|
|
325
|
-
// }
|
|
326
|
-
// }
|
|
327
|
-
var get_txs_by_height = function (height, address) {
|
|
328
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
329
|
-
var tag, output;
|
|
330
|
-
return __generator(this, function (_a) {
|
|
331
|
-
tag = TAG + " | get_txs_by_height | ";
|
|
332
|
-
output = {};
|
|
333
|
-
try {
|
|
334
|
-
//TODO
|
|
335
|
-
//let txs = await network.getTransactions(address)
|
|
336
|
-
// let txInfo = await axios({method:'GET',url:URL+'/api/v1/transactions?blockHeight='+height})
|
|
337
|
-
// log.debug(tag,"txInfo: ",txInfo.data)
|
|
338
|
-
return [2 /*return*/, "TODO"];
|
|
339
|
-
}
|
|
340
|
-
catch (e) {
|
|
341
|
-
//log.error(tag,"e: ",{e})
|
|
342
|
-
output.success = false;
|
|
343
|
-
output.error = e;
|
|
344
|
-
return [2 /*return*/, output];
|
|
345
|
-
}
|
|
346
|
-
return [2 /*return*/];
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
};
|
|
350
|
-
var get_block = function (height) {
|
|
351
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
352
|
-
var tag, output, txInfo, i, rawTx, txSummary, buffer, hash, rawTxHex, e_5, txs, i, entry, e_6;
|
|
353
|
-
return __generator(this, function (_a) {
|
|
354
|
-
switch (_a.label) {
|
|
355
|
-
case 0:
|
|
356
|
-
tag = TAG + " | get_block | ";
|
|
357
|
-
output = {};
|
|
358
|
-
_a.label = 1;
|
|
359
|
-
case 1:
|
|
360
|
-
_a.trys.push([1, 7, , 8]);
|
|
361
|
-
if (typeof (height) === 'string')
|
|
362
|
-
parseInt(height);
|
|
363
|
-
log.debug("checkpoint! ", height);
|
|
364
|
-
//txs
|
|
365
|
-
output.txs = [];
|
|
366
|
-
txInfo = void 0;
|
|
367
|
-
_a.label = 2;
|
|
368
|
-
case 2:
|
|
369
|
-
_a.trys.push([2, 4, , 6]);
|
|
370
|
-
if (REMOTE_OVERRIDE_BNB)
|
|
371
|
-
throw Error("102: forced remote override");
|
|
372
|
-
return [4 /*yield*/, axios({ method: 'GET', url: URL_BNBcli + '/blocks/' + height })];
|
|
373
|
-
case 3:
|
|
374
|
-
txInfo = _a.sent();
|
|
375
|
-
log.debug(tag, "txInfo: ", txInfo);
|
|
376
|
-
if (txInfo.data.block.data.txs) {
|
|
377
|
-
//convert raw tx's
|
|
378
|
-
for (i = 0; i < txInfo.data.block.data.txs.length; i++) {
|
|
379
|
-
rawTx = txInfo.data.block.data.txs[i];
|
|
380
|
-
log.debug(tag, "rawTx: ", rawTx);
|
|
381
|
-
txSummary = {};
|
|
382
|
-
buffer = Buffer.from(rawTx, 'base64');
|
|
383
|
-
hash = crypto.createHash('sha256').update(buffer).digest('hex').toUpperCase();
|
|
384
|
-
log.debug(tag, "hash: ", hash);
|
|
385
|
-
rawTxHex = buffer.toString('hex');
|
|
386
|
-
//let decodedTx = bnbDecoder.decodeTransfer(rawTxHex);
|
|
387
|
-
//log.debug(tag,"decodedTx: ",JSON.stringify(decodedTx))
|
|
388
|
-
txSummary.txid = hash;
|
|
389
|
-
txSummary.blockHeight = height;
|
|
390
|
-
//txSummary.tx = decodedTx
|
|
391
|
-
output.txs.push(txSummary);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
return [3 /*break*/, 6];
|
|
395
|
-
case 4:
|
|
396
|
-
e_5 = _a.sent();
|
|
397
|
-
return [4 /*yield*/, get_block_remote(height)];
|
|
398
|
-
case 5:
|
|
399
|
-
//throw e
|
|
400
|
-
txInfo = _a.sent();
|
|
401
|
-
log.debug(tag, "txInfo: ", txInfo);
|
|
402
|
-
txs = [];
|
|
403
|
-
for (i = 0; i < txInfo.tx.length; i++) {
|
|
404
|
-
entry = txInfo.tx[i];
|
|
405
|
-
entry.txid = entry.txHash;
|
|
406
|
-
txs.push(entry);
|
|
407
|
-
}
|
|
408
|
-
output.txs = txs;
|
|
409
|
-
return [3 /*break*/, 6];
|
|
410
|
-
case 6: return [2 /*return*/, output];
|
|
411
|
-
case 7:
|
|
412
|
-
e_6 = _a.sent();
|
|
413
|
-
//log.error(tag,"e: ",{e})
|
|
414
|
-
output.success = false;
|
|
415
|
-
output.error = e_6;
|
|
416
|
-
return [2 /*return*/, output];
|
|
417
|
-
case 8: return [2 /*return*/];
|
|
418
|
-
}
|
|
419
|
-
});
|
|
420
|
-
});
|
|
421
|
-
};
|
|
422
|
-
var get_block_remote = function (height) {
|
|
423
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
424
|
-
var tag, output, selected, txInfo, e_7;
|
|
425
|
-
return __generator(this, function (_a) {
|
|
426
|
-
switch (_a.label) {
|
|
427
|
-
case 0:
|
|
428
|
-
tag = TAG + " | get_block | ";
|
|
429
|
-
output = {};
|
|
430
|
-
_a.label = 1;
|
|
431
|
-
case 1:
|
|
432
|
-
_a.trys.push([1, 3, , 4]);
|
|
433
|
-
log.debug("checkpoint! ", height);
|
|
434
|
-
selected = void 0;
|
|
435
|
-
//rand 1-4
|
|
436
|
-
if (ROUND_ROBIN_STATE.length == 0) {
|
|
437
|
-
//add all 5
|
|
438
|
-
ROUND_ROBIN_STATE.push(URL_DEX_0);
|
|
439
|
-
ROUND_ROBIN_STATE.push(URL_DEX_1);
|
|
440
|
-
ROUND_ROBIN_STATE.push(URL_DEX_2);
|
|
441
|
-
ROUND_ROBIN_STATE.push(URL_DEX_3);
|
|
442
|
-
selected = URL_DEX_0;
|
|
443
|
-
}
|
|
444
|
-
else {
|
|
445
|
-
//pop at random
|
|
446
|
-
selected = ROUND_ROBIN_STATE.pop();
|
|
447
|
-
}
|
|
448
|
-
//
|
|
449
|
-
log.debug(tag, "selected: ", selected);
|
|
450
|
-
return [4 /*yield*/, axios({ method: 'GET', url: selected + '/api/v1/transactions-in-block/' + height })];
|
|
451
|
-
case 2:
|
|
452
|
-
txInfo = _a.sent();
|
|
453
|
-
log.debug(tag, "txInfo: ", txInfo.data);
|
|
454
|
-
return [2 /*return*/, txInfo.data];
|
|
455
|
-
case 3:
|
|
456
|
-
e_7 = _a.sent();
|
|
457
|
-
//log.error(tag,"e: ",{e})
|
|
458
|
-
output.success = false;
|
|
459
|
-
output.error = e_7;
|
|
460
|
-
return [2 /*return*/, output];
|
|
461
|
-
case 4: return [2 /*return*/];
|
|
462
|
-
}
|
|
463
|
-
});
|
|
464
|
-
});
|
|
465
|
-
};
|
|
466
|
-
var get_account = function (address) {
|
|
467
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
468
|
-
var tag, output, url, result, balanceInfo, e_8, output_2;
|
|
469
|
-
return __generator(this, function (_a) {
|
|
470
|
-
switch (_a.label) {
|
|
471
|
-
case 0:
|
|
472
|
-
tag = TAG + " | get_account | ";
|
|
473
|
-
output = {};
|
|
474
|
-
_a.label = 1;
|
|
475
|
-
case 1:
|
|
476
|
-
_a.trys.push([1, 3, , 4]);
|
|
477
|
-
log.debug(tag, "get_account: ", address);
|
|
478
|
-
url = URL_DEX + '/api/v1/account/' + address;
|
|
479
|
-
log.debug(tag, "url: ", url);
|
|
480
|
-
return [4 /*yield*/, axios({
|
|
481
|
-
url: url,
|
|
482
|
-
method: 'GET'
|
|
483
|
-
})];
|
|
484
|
-
case 2:
|
|
485
|
-
result = _a.sent();
|
|
486
|
-
balanceInfo = result.data;
|
|
487
|
-
log.debug('balanceInfo: ', balanceInfo);
|
|
488
|
-
return [2 /*return*/, balanceInfo];
|
|
489
|
-
case 3:
|
|
490
|
-
e_8 = _a.sent();
|
|
491
|
-
output_2 = {
|
|
492
|
-
account_number: 0,
|
|
493
|
-
address: address,
|
|
494
|
-
balances: [],
|
|
495
|
-
flags: 0,
|
|
496
|
-
public_key: [],
|
|
497
|
-
sequence: 0
|
|
498
|
-
};
|
|
499
|
-
return [2 /*return*/, output_2];
|
|
500
|
-
case 4: return [2 /*return*/];
|
|
501
|
-
}
|
|
502
|
-
});
|
|
503
|
-
});
|
|
504
|
-
};
|
|
505
|
-
/*
|
|
506
|
-
|
|
507
|
-
The tx must be a signed StdTx. The supported broadcast modes include "block"(return after tx commit), "sync"(return afer CheckTx) and "async"(return right away).
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
Input tx example:
|
|
512
|
-
|
|
513
|
-
{
|
|
514
|
-
"tx": {
|
|
515
|
-
"msg": [
|
|
516
|
-
"string"
|
|
517
|
-
],
|
|
518
|
-
"fee": {
|
|
519
|
-
"gas": "string",
|
|
520
|
-
"amount": [
|
|
521
|
-
{
|
|
522
|
-
"denom": "stake",
|
|
523
|
-
"amount": "50"
|
|
524
|
-
}
|
|
525
|
-
]
|
|
526
|
-
},
|
|
527
|
-
"memo": "string",
|
|
528
|
-
"signature": {
|
|
529
|
-
"signature": "MEUCIQD02fsDPra8MtbRsyB1w7bqTM55Wu138zQbFcWx4+CFyAIge5WNPfKIuvzBZ69MyqHsqD8S1IwiEp+iUb6VSdtlpgY=",
|
|
530
|
-
"pub_key": {
|
|
531
|
-
"type": "tendermint/PubKeySecp256k1",
|
|
532
|
-
"value": "Avz04VhtKJh8ACCVzlI8aTosGy0ikFXKIVHQ3jKMrosH"
|
|
533
|
-
},
|
|
534
|
-
"account_number": "0",
|
|
535
|
-
"sequence": "0"
|
|
536
|
-
}
|
|
537
|
-
},
|
|
538
|
-
"mode": "block"
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
responce:
|
|
543
|
-
|
|
544
|
-
{
|
|
545
|
-
"check_tx": {
|
|
546
|
-
"code": 0,
|
|
547
|
-
"data": "data",
|
|
548
|
-
"log": "log",
|
|
549
|
-
"gas_used": 5000,
|
|
550
|
-
"gas_wanted": 10000,
|
|
551
|
-
"info": "info",
|
|
552
|
-
"tags": [
|
|
553
|
-
"",
|
|
554
|
-
""
|
|
555
|
-
]
|
|
556
|
-
},
|
|
557
|
-
"deliver_tx": {
|
|
558
|
-
"code": 5,
|
|
559
|
-
"data": "data",
|
|
560
|
-
"log": "log",
|
|
561
|
-
"gas_used": 5000,
|
|
562
|
-
"gas_wanted": 10000,
|
|
563
|
-
"info": "info",
|
|
564
|
-
"tags": [
|
|
565
|
-
"",
|
|
566
|
-
""
|
|
567
|
-
]
|
|
568
|
-
},
|
|
569
|
-
"hash": "EE5F3404034C524501629B56E0DDC38FAD651F04",
|
|
570
|
-
"height": 0
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
*/
|
|
574
|
-
var broadcast_transaction = function (rawTx) {
|
|
575
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
576
|
-
var tag, output, url, config, response, txid, error_1, e_9;
|
|
577
|
-
return __generator(this, function (_a) {
|
|
578
|
-
switch (_a.label) {
|
|
579
|
-
case 0:
|
|
580
|
-
tag = TAG + " | broadcast_transaction | ";
|
|
581
|
-
output = {};
|
|
582
|
-
_a.label = 1;
|
|
583
|
-
case 1:
|
|
584
|
-
_a.trys.push([1, 6, , 7]);
|
|
585
|
-
log.debug(tag, "tx: ", rawTx);
|
|
586
|
-
log.debug(tag, "tx: ", typeof (rawTx));
|
|
587
|
-
url = 'https://dex.binance.org/api/v1/broadcast?sync=true';
|
|
588
|
-
config = {
|
|
589
|
-
headers: {
|
|
590
|
-
'Content-Type': 'text/plain',
|
|
591
|
-
},
|
|
592
|
-
};
|
|
593
|
-
_a.label = 2;
|
|
594
|
-
case 2:
|
|
595
|
-
_a.trys.push([2, 4, , 5]);
|
|
596
|
-
return [4 /*yield*/, axios.post(url, rawTx, config)];
|
|
597
|
-
case 3:
|
|
598
|
-
response = _a.sent();
|
|
599
|
-
console.log(response.data);
|
|
600
|
-
txid = response.data[0].hash;
|
|
601
|
-
return [3 /*break*/, 5];
|
|
602
|
-
case 4:
|
|
603
|
-
error_1 = _a.sent();
|
|
604
|
-
console.error(error_1);
|
|
605
|
-
return [3 /*break*/, 5];
|
|
606
|
-
case 5: return [3 /*break*/, 7];
|
|
607
|
-
case 6:
|
|
608
|
-
e_9 = _a.sent();
|
|
609
|
-
//log.error(tag,"e: ",{e})
|
|
610
|
-
log.error(tag, e_9);
|
|
611
|
-
log.error(tag, e_9.response);
|
|
612
|
-
log.error(tag, e_9.response.data);
|
|
613
|
-
log.error(tag, e_9.response.data.error);
|
|
614
|
-
output.success = false;
|
|
615
|
-
output.error = e_9;
|
|
616
|
-
return [2 /*return*/, output];
|
|
617
|
-
case 7: return [2 /*return*/];
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
});
|
|
621
|
-
};
|
|
622
|
-
var get_node_info = function () {
|
|
623
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
624
|
-
var tag, output, chaind, bnbncli, bnbncliRemote, e_10;
|
|
625
|
-
return __generator(this, function (_a) {
|
|
626
|
-
switch (_a.label) {
|
|
627
|
-
case 0:
|
|
628
|
-
tag = TAG + " | get_node_info | ";
|
|
629
|
-
output = {};
|
|
630
|
-
_a.label = 1;
|
|
631
|
-
case 1:
|
|
632
|
-
_a.trys.push([1, 5, , 6]);
|
|
633
|
-
return [4 /*yield*/, axios({ method: 'GET', url: URL_BNBchaind + '/abci_info' })];
|
|
634
|
-
case 2:
|
|
635
|
-
chaind = _a.sent();
|
|
636
|
-
log.debug(tag, "chaind: ", chaind.data);
|
|
637
|
-
output.bnbchaind = chaind.data;
|
|
638
|
-
return [4 /*yield*/, axios({ method: 'GET', url: URL_BNBcli + '/version' })];
|
|
639
|
-
case 3:
|
|
640
|
-
bnbncli = _a.sent();
|
|
641
|
-
log.debug(tag, "bnbncli: ", bnbncli.data);
|
|
642
|
-
output.bnbncli = bnbncli.data;
|
|
643
|
-
return [4 /*yield*/, axios({ method: 'GET', url: URL_REMOTE + '/abci_info' })];
|
|
644
|
-
case 4:
|
|
645
|
-
bnbncliRemote = _a.sent();
|
|
646
|
-
log.debug(tag, "bnbncliRemote: ", bnbncliRemote.data.result);
|
|
647
|
-
output.bnbncliRemote = bnbncliRemote.data;
|
|
648
|
-
return [2 /*return*/, output];
|
|
649
|
-
case 5:
|
|
650
|
-
e_10 = _a.sent();
|
|
651
|
-
//log.error(tag,"e: ",{e})
|
|
652
|
-
output.success = false;
|
|
653
|
-
output.error = e_10;
|
|
654
|
-
return [2 /*return*/, output];
|
|
655
|
-
case 6: return [2 /*return*/];
|
|
656
|
-
}
|
|
657
|
-
});
|
|
658
|
-
});
|
|
659
|
-
};
|
|
660
|
-
var get_node_syncing = function () {
|
|
661
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
662
|
-
var tag, output, txInfo, e_11;
|
|
663
|
-
return __generator(this, function (_a) {
|
|
664
|
-
switch (_a.label) {
|
|
665
|
-
case 0:
|
|
666
|
-
tag = TAG + " | get_node_info | ";
|
|
667
|
-
output = {};
|
|
668
|
-
_a.label = 1;
|
|
669
|
-
case 1:
|
|
670
|
-
_a.trys.push([1, 3, , 4]);
|
|
671
|
-
return [4 /*yield*/, axios({ method: 'GET', url: URL + '/syncing' })];
|
|
672
|
-
case 2:
|
|
673
|
-
txInfo = _a.sent();
|
|
674
|
-
log.debug(tag, "txInfo: ", txInfo.data);
|
|
675
|
-
return [2 /*return*/, txInfo.data];
|
|
676
|
-
case 3:
|
|
677
|
-
e_11 = _a.sent();
|
|
678
|
-
//log.error(tag,"e: ",{e})
|
|
679
|
-
output.success = false;
|
|
680
|
-
output.error = e_11;
|
|
681
|
-
return [2 /*return*/, output];
|
|
682
|
-
case 4: return [2 /*return*/];
|
|
683
|
-
}
|
|
684
|
-
});
|
|
685
|
-
});
|
|
686
|
-
};
|
|
687
|
-
var get_node_version = function () {
|
|
688
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
689
|
-
var tag, output, txInfo, e_12;
|
|
690
|
-
return __generator(this, function (_a) {
|
|
691
|
-
switch (_a.label) {
|
|
692
|
-
case 0:
|
|
693
|
-
tag = TAG + " | get_node_info | ";
|
|
694
|
-
output = {};
|
|
695
|
-
_a.label = 1;
|
|
696
|
-
case 1:
|
|
697
|
-
_a.trys.push([1, 3, , 4]);
|
|
698
|
-
return [4 /*yield*/, axios({ method: 'GET', url: URL_BNBcli + '/version' })];
|
|
699
|
-
case 2:
|
|
700
|
-
txInfo = _a.sent();
|
|
701
|
-
log.debug(tag, "txInfo: ", txInfo.data);
|
|
702
|
-
return [2 /*return*/, txInfo.data];
|
|
703
|
-
case 3:
|
|
704
|
-
e_12 = _a.sent();
|
|
705
|
-
//log.error(tag,"e: ",{e})
|
|
706
|
-
output.success = false;
|
|
707
|
-
output.error = e_12;
|
|
708
|
-
return [2 /*return*/, output];
|
|
709
|
-
case 4: return [2 /*return*/];
|
|
710
|
-
}
|
|
711
|
-
});
|
|
712
|
-
});
|
|
713
|
-
};
|
|
714
|
-
/*
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
txid:'66b0b99ee373064cdf8ce24b86b45c087ae50f5eaa32d2ee24dd26e39a5e3455',
|
|
718
|
-
status: 'confirmed',
|
|
719
|
-
type: 'send',
|
|
720
|
-
amount: -78602,
|
|
721
|
-
date: '2019-05-10T21:01:23Z',
|
|
722
|
-
confirmations: 1055,
|
|
723
|
-
network: 'BTC',
|
|
724
|
-
xpub:'xpub6CKkkDxRtCu6RWh9VCs3p9N8SzgFspo9qDcXbUkSXfHstFGgAd3XwsYbgQK82m7wnEp1byQGFenCHNk5ndJ8nx9dch7miL44FZV1pVQe6K4'
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
*/
|
|
728
|
-
var normalize_tx = function (tx, type) {
|
|
729
|
-
var output = {};
|
|
730
|
-
//
|
|
731
|
-
output.txid = tx.txhash;
|
|
732
|
-
output.height = tx.height;
|
|
733
|
-
if (tx.height)
|
|
734
|
-
output.status = "confirmed";
|
|
735
|
-
output.type = "transfer";
|
|
736
|
-
var event = {};
|
|
737
|
-
//TODO my god this is ugly? and does it always work?
|
|
738
|
-
if (type === 'send') {
|
|
739
|
-
event.amount = tx.tx.value.msg[0].value.amount[0].amount * -1;
|
|
740
|
-
}
|
|
741
|
-
else {
|
|
742
|
-
event.amount = tx.tx.value.msg[0].value.amount[0].amount;
|
|
743
|
-
}
|
|
744
|
-
output.date = tx.timestamp;
|
|
745
|
-
output.network = ASSET;
|
|
746
|
-
output.symbol = 'ATOM';
|
|
747
|
-
output.coin = 'ATOM';
|
|
748
|
-
output.height = tx.height;
|
|
749
|
-
output.gas_used = tx.gas_used;
|
|
750
|
-
output.gas_wanted = tx.gas_wanted;
|
|
751
|
-
return output;
|
|
752
|
-
};
|
|
753
|
-
var getTransaction = function (txid) {
|
|
754
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
755
|
-
var tag, output, selected, txInfo, e_13;
|
|
756
|
-
return __generator(this, function (_a) {
|
|
757
|
-
switch (_a.label) {
|
|
758
|
-
case 0:
|
|
759
|
-
tag = TAG + " | getTransaction | ";
|
|
760
|
-
output = {};
|
|
761
|
-
_a.label = 1;
|
|
762
|
-
case 1:
|
|
763
|
-
_a.trys.push([1, 3, , 4]);
|
|
764
|
-
selected = void 0;
|
|
765
|
-
//rand 1-4
|
|
766
|
-
if (ROUND_ROBIN_STATE.length == 0) {
|
|
767
|
-
//add all 5
|
|
768
|
-
ROUND_ROBIN_STATE.push(URL_DEX_0);
|
|
769
|
-
ROUND_ROBIN_STATE.push(URL_DEX_1);
|
|
770
|
-
ROUND_ROBIN_STATE.push(URL_DEX_2);
|
|
771
|
-
ROUND_ROBIN_STATE.push(URL_DEX_3);
|
|
772
|
-
selected = URL_DEX_0;
|
|
773
|
-
}
|
|
774
|
-
else {
|
|
775
|
-
//pop at random
|
|
776
|
-
selected = ROUND_ROBIN_STATE.pop();
|
|
777
|
-
}
|
|
778
|
-
return [4 /*yield*/, axios({ method: 'GET', url: selected + '/api/v1/tx/' + txid + "?format=json" })];
|
|
779
|
-
case 2:
|
|
780
|
-
txInfo = _a.sent();
|
|
781
|
-
log.debug(tag, "txInfo: ", txInfo.data);
|
|
782
|
-
//
|
|
783
|
-
// let txInfo = await axios({method:'GET',url:URL_DEX+'/api/v1/tx/'+txid+"?format=json"})
|
|
784
|
-
// log.debug(tag,"txInfo: ",txInfo.data)
|
|
785
|
-
return [2 /*return*/, txInfo.data];
|
|
786
|
-
case 3:
|
|
787
|
-
e_13 = _a.sent();
|
|
788
|
-
//log.error(tag,"e: ",{e})
|
|
789
|
-
output.success = false;
|
|
790
|
-
output.error = e_13;
|
|
791
|
-
return [2 /*return*/, output];
|
|
792
|
-
case 4: return [2 /*return*/];
|
|
793
|
-
}
|
|
794
|
-
});
|
|
795
|
-
});
|
|
796
|
-
};
|