@pioneer-platform/binance-network 8.5.0 → 8.6.0

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.
@@ -0,0 +1,2 @@
1
+
2
+ $ tsc -p .
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @pioneer-platform/binance-network
2
2
 
3
+ ## 8.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Automated minor version bump for all packages
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @pioneer-platform/loggerdog@8.6.0
13
+ - @pioneer-platform/nodes@8.6.0
14
+
3
15
  ## 8.5.0
4
16
 
5
17
  ### Minor Changes
package/build.sh ADDED
@@ -0,0 +1,22 @@
1
+ #!/bin/bash
2
+ # Fast Bun build (replaces slow tsc)
3
+
4
+ OUTDIR="${1:-lib}"
5
+ ENTRY="${2:-src/index.ts}"
6
+
7
+ # Clean output
8
+ rm -rf "$OUTDIR"
9
+ mkdir -p "$OUTDIR"
10
+
11
+ # Build with Bun (10x faster than tsc)
12
+ bun build "$ENTRY" \
13
+ --outdir "$OUTDIR" \
14
+ --target node \
15
+ --format cjs \
16
+ --sourcemap \
17
+ --minify
18
+
19
+ # Generate TypeScript declarations
20
+ bunx tsc --emitDeclarationOnly --outDir "$OUTDIR" --project .
21
+
22
+ echo "✅ Built $OUTDIR"
package/lib/index.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ declare const TAG = " | bnb-network | ";
2
+ declare const moment: any;
3
+ declare const axiosLib: any;
4
+ declare const Axios: any;
5
+ declare const https: any;
6
+ declare const axios: any;
7
+ declare const log: any;
8
+ declare let URL_BNBchaind: string;
9
+ declare let URL_BNBcli: string;
10
+ declare let URL_REMOTE: string;
11
+ declare let URL_DEX: string;
12
+ declare let URL_DEX_0: string;
13
+ declare let URL_DEX_1: string;
14
+ declare let URL_DEX_2: string;
15
+ declare let URL_DEX_3: string;
16
+ declare var crypto: any;
17
+ declare const ASSET = "BNB";
18
+ declare let ROUND_ROBIN_STATE: any;
19
+ declare let REMOTE_OVERRIDE_BNB: string | undefined;
20
+ declare let get_block_height: () => Promise<any>;
21
+ declare let get_balance: (address: string, token: string) => Promise<any>;
22
+ declare let get_txs_by_address: (address: string) => Promise<any>;
23
+ declare let get_txs_by_height: (height: string, address: string) => Promise<any>;
24
+ declare let get_block: (height: string) => Promise<any>;
25
+ declare let get_block_remote: (height: string) => Promise<any>;
26
+ declare let get_account: (address: string) => Promise<any>;
27
+ declare let broadcast_transaction: (rawTx: string) => Promise<any>;
28
+ declare let get_node_info: () => Promise<any>;
29
+ declare let get_node_syncing: () => Promise<any>;
30
+ declare let get_node_version: () => Promise<any>;
31
+ declare let normalize_tx: (tx: any, type: string) => any;
32
+ declare let getTransaction: (txid: string) => Promise<any>;
package/lib/index.js ADDED
@@ -0,0 +1,797 @@
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
73
+ return g.next = verb(0), g["throw"] = verb(1), g["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 axiosLib = require('axios');
101
+ var Axios = axiosLib.default || axiosLib;
102
+ var https = require('https');
103
+ var axios = Axios.create({
104
+ httpsAgent: new https.Agent({
105
+ rejectUnauthorized: false
106
+ })
107
+ });
108
+ var log = require('@pioneer-platform/loggerdog')();
109
+ // let URL_BNBchaind = process.env["URL_BNB"] || 'http://127.0.0.1:27147'
110
+ // let URL_BNBcli = process.env["URL_BNBCLI"] || 'http://127.0.0.1:8333'
111
+ //Debug
112
+ var URL_BNBchaind = process.env["URL_BNB"] || 'https://dex.binance.org';
113
+ var URL_BNBcli = process.env["URL_BNBCLI"] || 'https://dex.binance.org';
114
+ var URL_REMOTE = process.env["URL_BNB_REMOTE"] || 'https://dataseed1.binance.org:443';
115
+ var URL_DEX = process.env["BNB_FULL_REMOTE"] || 'https://dex.binance.org';
116
+ var URL_DEX_0 = process.env["BNB_FULL_REMOTE_1"] || 'https://dex.binance.org';
117
+ var URL_DEX_1 = process.env["BNB_FULL_REMOTE_2"] || 'https://dex-atlantic.binance.org';
118
+ var URL_DEX_2 = process.env["BNB_FULL_REMOTE_3"] || 'https://dex-asiapacific.binance.org';
119
+ var URL_DEX_3 = process.env["BNB_FULL_REMOTE_4"] || 'https://dex-european.binance.org';
120
+ // @ts-ignore
121
+ var crypto = require('crypto');
122
+ //console.log(sdk)
123
+ //network.getTransactions()
124
+ // let client = sdk.BncClient(URL)
125
+ // console.log(client)
126
+ var ASSET = "BNB";
127
+ var ROUND_ROBIN_STATE = [];
128
+ var REMOTE_OVERRIDE_BNB = process.env['REMOTE_OVERRIDE_BNB'];
129
+ module.exports = {
130
+ init: function (mode, config) {
131
+ if (mode) {
132
+ //TODO override nodes
133
+ }
134
+ else {
135
+ }
136
+ },
137
+ nodeInfo: function () {
138
+ return get_node_info();
139
+ },
140
+ nodeInfoSyncing: function () {
141
+ return get_node_syncing();
142
+ },
143
+ nodeInfoVersion: function () {
144
+ return get_node_version();
145
+ },
146
+ txs: function (address) {
147
+ return get_txs_by_address(address);
148
+ },
149
+ txsByHeight: function (height, address) {
150
+ return get_txs_by_height(height, address);
151
+ },
152
+ getBlockHeight: function () {
153
+ return get_block_height();
154
+ },
155
+ getTransaction: function (txid) {
156
+ return getTransaction(txid);
157
+ },
158
+ getBalance: function (address, token) {
159
+ return get_balance(address, token);
160
+ },
161
+ getBlock: function (height) {
162
+ return get_block(height);
163
+ },
164
+ getBlockRemote: function (height) {
165
+ return get_block_remote(height);
166
+ },
167
+ broadcast: function (tx) {
168
+ return broadcast_transaction(tx);
169
+ },
170
+ getAccount: function (address) {
171
+ return get_account(address);
172
+ },
173
+ // getSequence:function (address:string) {
174
+ // return get_account_sequence(address);
175
+ // },
176
+ // getValidators:function () {
177
+ // return get_validators();
178
+ // }
179
+ };
180
+ var get_block_height = function () {
181
+ return __awaiter(this, void 0, void 0, function () {
182
+ var tag, output, height, bnbncliRemote, e_1, bnbncliRemote, e_2;
183
+ return __generator(this, function (_a) {
184
+ switch (_a.label) {
185
+ case 0:
186
+ tag = TAG + " | get_block_height | ";
187
+ output = {};
188
+ _a.label = 1;
189
+ case 1:
190
+ _a.trys.push([1, 7, , 8]);
191
+ height = void 0;
192
+ _a.label = 2;
193
+ case 2:
194
+ _a.trys.push([2, 4, , 6]);
195
+ return [4 /*yield*/, axios({ method: 'GET', url: URL_BNBchaind + '/abci_info' })];
196
+ case 3:
197
+ bnbncliRemote = _a.sent();
198
+ log.debug(tag, "bnbncliRemote: ", bnbncliRemote.data);
199
+ height = bnbncliRemote.data.result.response.last_block_height;
200
+ return [3 /*break*/, 6];
201
+ case 4:
202
+ e_1 = _a.sent();
203
+ return [4 /*yield*/, axios({ method: 'GET', url: URL_REMOTE + '/abci_info' })];
204
+ case 5:
205
+ bnbncliRemote = _a.sent();
206
+ log.debug(tag, "bnbncliRemote: ", bnbncliRemote.data);
207
+ height = bnbncliRemote.data.result.response.last_block_height;
208
+ return [3 /*break*/, 6];
209
+ case 6: return [2 /*return*/, height];
210
+ case 7:
211
+ e_2 = _a.sent();
212
+ //log.error(tag,"e: ",{e})
213
+ output.success = false;
214
+ output.error = e_2;
215
+ return [2 /*return*/, output];
216
+ case 8: return [2 /*return*/];
217
+ }
218
+ });
219
+ });
220
+ };
221
+ var get_balance = function (address, token) {
222
+ return __awaiter(this, void 0, void 0, function () {
223
+ var tag, output, url, result, balanceInfo, i, assetInfo, e_3;
224
+ return __generator(this, function (_a) {
225
+ switch (_a.label) {
226
+ case 0:
227
+ tag = TAG + " | get_account | ";
228
+ output = {};
229
+ _a.label = 1;
230
+ case 1:
231
+ _a.trys.push([1, 3, , 4]);
232
+ if (!token)
233
+ token = ASSET;
234
+ log.debug(tag, "get_account: ", address);
235
+ url = URL_DEX + '/api/v1/account/' + address;
236
+ log.debug(tag, "url: ", url);
237
+ return [4 /*yield*/, axios({
238
+ url: url,
239
+ method: 'GET'
240
+ })];
241
+ case 2:
242
+ result = _a.sent();
243
+ balanceInfo = result.data;
244
+ log.debug('balanceInfo: ', balanceInfo);
245
+ if (!balanceInfo || !balanceInfo.balances || balanceInfo.balances.length === 0) {
246
+ output = 0;
247
+ }
248
+ for (i = 0; i < balanceInfo.balances.length; i++) {
249
+ assetInfo = balanceInfo.balances[i];
250
+ log.debug(tag, "assetInfo: ", assetInfo);
251
+ if (assetInfo.symbol === token) {
252
+ output = parseFloat(assetInfo.free);
253
+ }
254
+ }
255
+ return [2 /*return*/, output];
256
+ case 3:
257
+ e_3 = _a.sent();
258
+ //node 404's on fresh addresses like an asshole
259
+ return [2 /*return*/, 0];
260
+ case 4: return [2 /*return*/];
261
+ }
262
+ });
263
+ });
264
+ };
265
+ /*
266
+
267
+ https://docs.binance.org/api-reference/dex-api/paths.html#apiv1transactions
268
+
269
+ */
270
+ var get_txs_by_address = function (address) {
271
+ return __awaiter(this, void 0, void 0, function () {
272
+ var tag, output, output_1, startTime, url, resultSends, sends, e_4;
273
+ return __generator(this, function (_a) {
274
+ switch (_a.label) {
275
+ case 0:
276
+ tag = ' | get_txs_by_address | ';
277
+ output = {};
278
+ _a.label = 1;
279
+ case 1:
280
+ _a.trys.push([1, 3, , 4]);
281
+ output_1 = [];
282
+ startTime = moment().subtract('months', 6).unix();
283
+ startTime = startTime * 1000;
284
+ log.debug("startTime: ", startTime);
285
+ url = URL_DEX + '/api/v1/transactions?address=' + address + '&startTime=' + startTime;
286
+ log.debug(tag, "url: ", url);
287
+ return [4 /*yield*/, axios({
288
+ url: url,
289
+ method: 'GET'
290
+ })];
291
+ case 2:
292
+ resultSends = _a.sent();
293
+ sends = resultSends.data;
294
+ log.debug('sends: ', sends);
295
+ return [2 /*return*/, sends.tx];
296
+ case 3:
297
+ e_4 = _a.sent();
298
+ //log.error(tag,"e: ",{e})
299
+ output.success = false;
300
+ output.error = e_4;
301
+ return [2 /*return*/, output];
302
+ case 4: return [2 /*return*/];
303
+ }
304
+ });
305
+ });
306
+ };
307
+ // let get_txs_by_address = async function(address){
308
+ // let tag = TAG + " | get_txs_by_height | "
309
+ // try{
310
+ //
311
+ //
312
+ // //log.debug(network)
313
+ // let txs = network.getTransactions(address,0)
314
+ //
315
+ // // let txInfo = await axios({method:'GET',url:URL_BNBcli+'/tx_search?address='+address})
316
+ // // log.debug(tag,"txInfo: ",txInfo.data)
317
+ //
318
+ //
319
+ // return txs
320
+ // }catch(e){
321
+ // //log.error(tag,"e: ",{e})
322
+ // let output:any = {}
323
+ // output.success = false
324
+ // output.error = e
325
+ // return output
326
+ // }
327
+ // }
328
+ var get_txs_by_height = function (height, address) {
329
+ return __awaiter(this, void 0, void 0, function () {
330
+ var tag, output;
331
+ return __generator(this, function (_a) {
332
+ tag = TAG + " | get_txs_by_height | ";
333
+ output = {};
334
+ try {
335
+ //TODO
336
+ //let txs = await network.getTransactions(address)
337
+ // let txInfo = await axios({method:'GET',url:URL+'/api/v1/transactions?blockHeight='+height})
338
+ // log.debug(tag,"txInfo: ",txInfo.data)
339
+ return [2 /*return*/, "TODO"];
340
+ }
341
+ catch (e) {
342
+ //log.error(tag,"e: ",{e})
343
+ output.success = false;
344
+ output.error = e;
345
+ return [2 /*return*/, output];
346
+ }
347
+ return [2 /*return*/];
348
+ });
349
+ });
350
+ };
351
+ var get_block = function (height) {
352
+ return __awaiter(this, void 0, void 0, function () {
353
+ var tag, output, txInfo, i, rawTx, txSummary, buffer, hash, rawTxHex, e_5, txs, i, entry, e_6;
354
+ return __generator(this, function (_a) {
355
+ switch (_a.label) {
356
+ case 0:
357
+ tag = TAG + " | get_block | ";
358
+ output = {};
359
+ _a.label = 1;
360
+ case 1:
361
+ _a.trys.push([1, 7, , 8]);
362
+ if (typeof (height) === 'string')
363
+ parseInt(height);
364
+ log.debug("checkpoint! ", height);
365
+ //txs
366
+ output.txs = [];
367
+ txInfo = void 0;
368
+ _a.label = 2;
369
+ case 2:
370
+ _a.trys.push([2, 4, , 6]);
371
+ if (REMOTE_OVERRIDE_BNB)
372
+ throw Error("102: forced remote override");
373
+ return [4 /*yield*/, axios({ method: 'GET', url: URL_BNBcli + '/blocks/' + height })];
374
+ case 3:
375
+ txInfo = _a.sent();
376
+ log.debug(tag, "txInfo: ", txInfo);
377
+ if (txInfo.data.block.data.txs) {
378
+ //convert raw tx's
379
+ for (i = 0; i < txInfo.data.block.data.txs.length; i++) {
380
+ rawTx = txInfo.data.block.data.txs[i];
381
+ log.debug(tag, "rawTx: ", rawTx);
382
+ txSummary = {};
383
+ buffer = Buffer.from(rawTx, 'base64');
384
+ hash = crypto.createHash('sha256').update(buffer).digest('hex').toUpperCase();
385
+ log.debug(tag, "hash: ", hash);
386
+ rawTxHex = buffer.toString('hex');
387
+ //let decodedTx = bnbDecoder.decodeTransfer(rawTxHex);
388
+ //log.debug(tag,"decodedTx: ",JSON.stringify(decodedTx))
389
+ txSummary.txid = hash;
390
+ txSummary.blockHeight = height;
391
+ //txSummary.tx = decodedTx
392
+ output.txs.push(txSummary);
393
+ }
394
+ }
395
+ return [3 /*break*/, 6];
396
+ case 4:
397
+ e_5 = _a.sent();
398
+ return [4 /*yield*/, get_block_remote(height)];
399
+ case 5:
400
+ //throw e
401
+ txInfo = _a.sent();
402
+ log.debug(tag, "txInfo: ", txInfo);
403
+ txs = [];
404
+ for (i = 0; i < txInfo.tx.length; i++) {
405
+ entry = txInfo.tx[i];
406
+ entry.txid = entry.txHash;
407
+ txs.push(entry);
408
+ }
409
+ output.txs = txs;
410
+ return [3 /*break*/, 6];
411
+ case 6: return [2 /*return*/, output];
412
+ case 7:
413
+ e_6 = _a.sent();
414
+ //log.error(tag,"e: ",{e})
415
+ output.success = false;
416
+ output.error = e_6;
417
+ return [2 /*return*/, output];
418
+ case 8: return [2 /*return*/];
419
+ }
420
+ });
421
+ });
422
+ };
423
+ var get_block_remote = function (height) {
424
+ return __awaiter(this, void 0, void 0, function () {
425
+ var tag, output, selected, txInfo, e_7;
426
+ return __generator(this, function (_a) {
427
+ switch (_a.label) {
428
+ case 0:
429
+ tag = TAG + " | get_block | ";
430
+ output = {};
431
+ _a.label = 1;
432
+ case 1:
433
+ _a.trys.push([1, 3, , 4]);
434
+ log.debug("checkpoint! ", height);
435
+ selected = void 0;
436
+ //rand 1-4
437
+ if (ROUND_ROBIN_STATE.length == 0) {
438
+ //add all 5
439
+ ROUND_ROBIN_STATE.push(URL_DEX_0);
440
+ ROUND_ROBIN_STATE.push(URL_DEX_1);
441
+ ROUND_ROBIN_STATE.push(URL_DEX_2);
442
+ ROUND_ROBIN_STATE.push(URL_DEX_3);
443
+ selected = URL_DEX_0;
444
+ }
445
+ else {
446
+ //pop at random
447
+ selected = ROUND_ROBIN_STATE.pop();
448
+ }
449
+ //
450
+ log.debug(tag, "selected: ", selected);
451
+ return [4 /*yield*/, axios({ method: 'GET', url: selected + '/api/v1/transactions-in-block/' + height })];
452
+ case 2:
453
+ txInfo = _a.sent();
454
+ log.debug(tag, "txInfo: ", txInfo.data);
455
+ return [2 /*return*/, txInfo.data];
456
+ case 3:
457
+ e_7 = _a.sent();
458
+ //log.error(tag,"e: ",{e})
459
+ output.success = false;
460
+ output.error = e_7;
461
+ return [2 /*return*/, output];
462
+ case 4: return [2 /*return*/];
463
+ }
464
+ });
465
+ });
466
+ };
467
+ var get_account = function (address) {
468
+ return __awaiter(this, void 0, void 0, function () {
469
+ var tag, output, url, result, balanceInfo, e_8, output_2;
470
+ return __generator(this, function (_a) {
471
+ switch (_a.label) {
472
+ case 0:
473
+ tag = TAG + " | get_account | ";
474
+ output = {};
475
+ _a.label = 1;
476
+ case 1:
477
+ _a.trys.push([1, 3, , 4]);
478
+ log.debug(tag, "get_account: ", address);
479
+ url = URL_DEX + '/api/v1/account/' + address;
480
+ log.debug(tag, "url: ", url);
481
+ return [4 /*yield*/, axios({
482
+ url: url,
483
+ method: 'GET'
484
+ })];
485
+ case 2:
486
+ result = _a.sent();
487
+ balanceInfo = result.data;
488
+ log.debug('balanceInfo: ', balanceInfo);
489
+ return [2 /*return*/, balanceInfo];
490
+ case 3:
491
+ e_8 = _a.sent();
492
+ output_2 = {
493
+ account_number: 0,
494
+ address: address,
495
+ balances: [],
496
+ flags: 0,
497
+ public_key: [],
498
+ sequence: 0
499
+ };
500
+ return [2 /*return*/, output_2];
501
+ case 4: return [2 /*return*/];
502
+ }
503
+ });
504
+ });
505
+ };
506
+ /*
507
+
508
+ 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).
509
+
510
+
511
+
512
+ Input tx example:
513
+
514
+ {
515
+ "tx": {
516
+ "msg": [
517
+ "string"
518
+ ],
519
+ "fee": {
520
+ "gas": "string",
521
+ "amount": [
522
+ {
523
+ "denom": "stake",
524
+ "amount": "50"
525
+ }
526
+ ]
527
+ },
528
+ "memo": "string",
529
+ "signature": {
530
+ "signature": "MEUCIQD02fsDPra8MtbRsyB1w7bqTM55Wu138zQbFcWx4+CFyAIge5WNPfKIuvzBZ69MyqHsqD8S1IwiEp+iUb6VSdtlpgY=",
531
+ "pub_key": {
532
+ "type": "tendermint/PubKeySecp256k1",
533
+ "value": "Avz04VhtKJh8ACCVzlI8aTosGy0ikFXKIVHQ3jKMrosH"
534
+ },
535
+ "account_number": "0",
536
+ "sequence": "0"
537
+ }
538
+ },
539
+ "mode": "block"
540
+ }
541
+
542
+
543
+ responce:
544
+
545
+ {
546
+ "check_tx": {
547
+ "code": 0,
548
+ "data": "data",
549
+ "log": "log",
550
+ "gas_used": 5000,
551
+ "gas_wanted": 10000,
552
+ "info": "info",
553
+ "tags": [
554
+ "",
555
+ ""
556
+ ]
557
+ },
558
+ "deliver_tx": {
559
+ "code": 5,
560
+ "data": "data",
561
+ "log": "log",
562
+ "gas_used": 5000,
563
+ "gas_wanted": 10000,
564
+ "info": "info",
565
+ "tags": [
566
+ "",
567
+ ""
568
+ ]
569
+ },
570
+ "hash": "EE5F3404034C524501629B56E0DDC38FAD651F04",
571
+ "height": 0
572
+ }
573
+
574
+ */
575
+ var broadcast_transaction = function (rawTx) {
576
+ return __awaiter(this, void 0, void 0, function () {
577
+ var tag, output, url, config, response, txid, error_1, e_9;
578
+ return __generator(this, function (_a) {
579
+ switch (_a.label) {
580
+ case 0:
581
+ tag = TAG + " | broadcast_transaction | ";
582
+ output = {};
583
+ _a.label = 1;
584
+ case 1:
585
+ _a.trys.push([1, 6, , 7]);
586
+ log.debug(tag, "tx: ", rawTx);
587
+ log.debug(tag, "tx: ", typeof (rawTx));
588
+ url = 'https://dex.binance.org/api/v1/broadcast?sync=true';
589
+ config = {
590
+ headers: {
591
+ 'Content-Type': 'text/plain',
592
+ },
593
+ };
594
+ _a.label = 2;
595
+ case 2:
596
+ _a.trys.push([2, 4, , 5]);
597
+ return [4 /*yield*/, axios.post(url, rawTx, config)];
598
+ case 3:
599
+ response = _a.sent();
600
+ console.log(response.data);
601
+ txid = response.data[0].hash;
602
+ return [3 /*break*/, 5];
603
+ case 4:
604
+ error_1 = _a.sent();
605
+ console.error(error_1);
606
+ return [3 /*break*/, 5];
607
+ case 5: return [3 /*break*/, 7];
608
+ case 6:
609
+ e_9 = _a.sent();
610
+ //log.error(tag,"e: ",{e})
611
+ log.error(tag, e_9);
612
+ log.error(tag, e_9.response);
613
+ log.error(tag, e_9.response.data);
614
+ log.error(tag, e_9.response.data.error);
615
+ output.success = false;
616
+ output.error = e_9;
617
+ return [2 /*return*/, output];
618
+ case 7: return [2 /*return*/];
619
+ }
620
+ });
621
+ });
622
+ };
623
+ var get_node_info = function () {
624
+ return __awaiter(this, void 0, void 0, function () {
625
+ var tag, output, chaind, bnbncli, bnbncliRemote, e_10;
626
+ return __generator(this, function (_a) {
627
+ switch (_a.label) {
628
+ case 0:
629
+ tag = TAG + " | get_node_info | ";
630
+ output = {};
631
+ _a.label = 1;
632
+ case 1:
633
+ _a.trys.push([1, 5, , 6]);
634
+ return [4 /*yield*/, axios({ method: 'GET', url: URL_BNBchaind + '/abci_info' })];
635
+ case 2:
636
+ chaind = _a.sent();
637
+ log.debug(tag, "chaind: ", chaind.data);
638
+ output.bnbchaind = chaind.data;
639
+ return [4 /*yield*/, axios({ method: 'GET', url: URL_BNBcli + '/version' })];
640
+ case 3:
641
+ bnbncli = _a.sent();
642
+ log.debug(tag, "bnbncli: ", bnbncli.data);
643
+ output.bnbncli = bnbncli.data;
644
+ return [4 /*yield*/, axios({ method: 'GET', url: URL_REMOTE + '/abci_info' })];
645
+ case 4:
646
+ bnbncliRemote = _a.sent();
647
+ log.debug(tag, "bnbncliRemote: ", bnbncliRemote.data.result);
648
+ output.bnbncliRemote = bnbncliRemote.data;
649
+ return [2 /*return*/, output];
650
+ case 5:
651
+ e_10 = _a.sent();
652
+ //log.error(tag,"e: ",{e})
653
+ output.success = false;
654
+ output.error = e_10;
655
+ return [2 /*return*/, output];
656
+ case 6: return [2 /*return*/];
657
+ }
658
+ });
659
+ });
660
+ };
661
+ var get_node_syncing = function () {
662
+ return __awaiter(this, void 0, void 0, function () {
663
+ var tag, output, txInfo, e_11;
664
+ return __generator(this, function (_a) {
665
+ switch (_a.label) {
666
+ case 0:
667
+ tag = TAG + " | get_node_info | ";
668
+ output = {};
669
+ _a.label = 1;
670
+ case 1:
671
+ _a.trys.push([1, 3, , 4]);
672
+ return [4 /*yield*/, axios({ method: 'GET', url: URL + '/syncing' })];
673
+ case 2:
674
+ txInfo = _a.sent();
675
+ log.debug(tag, "txInfo: ", txInfo.data);
676
+ return [2 /*return*/, txInfo.data];
677
+ case 3:
678
+ e_11 = _a.sent();
679
+ //log.error(tag,"e: ",{e})
680
+ output.success = false;
681
+ output.error = e_11;
682
+ return [2 /*return*/, output];
683
+ case 4: return [2 /*return*/];
684
+ }
685
+ });
686
+ });
687
+ };
688
+ var get_node_version = function () {
689
+ return __awaiter(this, void 0, void 0, function () {
690
+ var tag, output, txInfo, e_12;
691
+ return __generator(this, function (_a) {
692
+ switch (_a.label) {
693
+ case 0:
694
+ tag = TAG + " | get_node_info | ";
695
+ output = {};
696
+ _a.label = 1;
697
+ case 1:
698
+ _a.trys.push([1, 3, , 4]);
699
+ return [4 /*yield*/, axios({ method: 'GET', url: URL_BNBcli + '/version' })];
700
+ case 2:
701
+ txInfo = _a.sent();
702
+ log.debug(tag, "txInfo: ", txInfo.data);
703
+ return [2 /*return*/, txInfo.data];
704
+ case 3:
705
+ e_12 = _a.sent();
706
+ //log.error(tag,"e: ",{e})
707
+ output.success = false;
708
+ output.error = e_12;
709
+ return [2 /*return*/, output];
710
+ case 4: return [2 /*return*/];
711
+ }
712
+ });
713
+ });
714
+ };
715
+ /*
716
+
717
+
718
+ txid:'66b0b99ee373064cdf8ce24b86b45c087ae50f5eaa32d2ee24dd26e39a5e3455',
719
+ status: 'confirmed',
720
+ type: 'send',
721
+ amount: -78602,
722
+ date: '2019-05-10T21:01:23Z',
723
+ confirmations: 1055,
724
+ network: 'BTC',
725
+ xpub:'xpub6CKkkDxRtCu6RWh9VCs3p9N8SzgFspo9qDcXbUkSXfHstFGgAd3XwsYbgQK82m7wnEp1byQGFenCHNk5ndJ8nx9dch7miL44FZV1pVQe6K4'
726
+
727
+
728
+ */
729
+ var normalize_tx = function (tx, type) {
730
+ var output = {};
731
+ //
732
+ output.txid = tx.txhash;
733
+ output.height = tx.height;
734
+ if (tx.height)
735
+ output.status = "confirmed";
736
+ output.type = "transfer";
737
+ var event = {};
738
+ //TODO my god this is ugly? and does it always work?
739
+ if (type === 'send') {
740
+ event.amount = tx.tx.value.msg[0].value.amount[0].amount * -1;
741
+ }
742
+ else {
743
+ event.amount = tx.tx.value.msg[0].value.amount[0].amount;
744
+ }
745
+ output.date = tx.timestamp;
746
+ output.network = ASSET;
747
+ output.symbol = 'ATOM';
748
+ output.coin = 'ATOM';
749
+ output.height = tx.height;
750
+ output.gas_used = tx.gas_used;
751
+ output.gas_wanted = tx.gas_wanted;
752
+ return output;
753
+ };
754
+ var getTransaction = function (txid) {
755
+ return __awaiter(this, void 0, void 0, function () {
756
+ var tag, output, selected, txInfo, e_13;
757
+ return __generator(this, function (_a) {
758
+ switch (_a.label) {
759
+ case 0:
760
+ tag = TAG + " | getTransaction | ";
761
+ output = {};
762
+ _a.label = 1;
763
+ case 1:
764
+ _a.trys.push([1, 3, , 4]);
765
+ selected = void 0;
766
+ //rand 1-4
767
+ if (ROUND_ROBIN_STATE.length == 0) {
768
+ //add all 5
769
+ ROUND_ROBIN_STATE.push(URL_DEX_0);
770
+ ROUND_ROBIN_STATE.push(URL_DEX_1);
771
+ ROUND_ROBIN_STATE.push(URL_DEX_2);
772
+ ROUND_ROBIN_STATE.push(URL_DEX_3);
773
+ selected = URL_DEX_0;
774
+ }
775
+ else {
776
+ //pop at random
777
+ selected = ROUND_ROBIN_STATE.pop();
778
+ }
779
+ return [4 /*yield*/, axios({ method: 'GET', url: selected + '/api/v1/tx/' + txid + "?format=json" })];
780
+ case 2:
781
+ txInfo = _a.sent();
782
+ log.debug(tag, "txInfo: ", txInfo.data);
783
+ //
784
+ // let txInfo = await axios({method:'GET',url:URL_DEX+'/api/v1/tx/'+txid+"?format=json"})
785
+ // log.debug(tag,"txInfo: ",txInfo.data)
786
+ return [2 /*return*/, txInfo.data];
787
+ case 3:
788
+ e_13 = _a.sent();
789
+ //log.error(tag,"e: ",{e})
790
+ output.success = false;
791
+ output.error = e_13;
792
+ return [2 /*return*/, output];
793
+ case 4: return [2 /*return*/];
794
+ }
795
+ });
796
+ });
797
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/binance-network",
3
- "version": "8.5.0",
3
+ "version": "8.6.0",
4
4
  "scripts": {
5
5
  "create": "pnpm run build && pnpm run test",
6
6
  "build": "tsc -p .",
@@ -10,8 +10,8 @@
10
10
  },
11
11
  "dependencies": {
12
12
  "@crypto-hex-decoder/bnb": "^2.1.0",
13
- "@pioneer-platform/loggerdog": "^8.5.0",
14
- "@pioneer-platform/nodes": "^8.5.0",
13
+ "@pioneer-platform/loggerdog": "^8.6.0",
14
+ "@pioneer-platform/nodes": "^8.6.0",
15
15
  "axios": "^1.6.0",
16
16
  "dotenv": "^8.2.0",
17
17
  "https": "^1.0.0",