@pioneer-platform/utxo-network 8.1.53 → 8.1.59
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/lib/index.js +115 -76
- package/lib/sochain-api.js +18 -13
- package/lib/types/client-types.d.ts +6 -6
- package/lib/types/common.d.ts +4 -4
- package/lib/types/index.js +6 -2
- package/lib/types/ledger.d.ts +2 -2
- package/lib/types/sochain-api-types.d.ts +10 -10
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +55 -37
- package/package.json +8 -7
package/lib/index.js
CHANGED
|
@@ -105,7 +105,11 @@
|
|
|
105
105
|
*/
|
|
106
106
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
107
107
|
if (k2 === undefined) k2 = k;
|
|
108
|
-
Object.
|
|
108
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
109
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
110
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
111
|
+
}
|
|
112
|
+
Object.defineProperty(o, k2, desc);
|
|
109
113
|
}) : (function(o, m, k, k2) {
|
|
110
114
|
if (k2 === undefined) k2 = k;
|
|
111
115
|
o[k2] = m[k];
|
|
@@ -118,7 +122,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
118
122
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
119
123
|
if (mod && mod.__esModule) return mod;
|
|
120
124
|
var result = {};
|
|
121
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
125
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
122
126
|
__setModuleDefault(result, mod);
|
|
123
127
|
return result;
|
|
124
128
|
};
|
|
@@ -137,7 +141,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
137
141
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
138
142
|
function step(op) {
|
|
139
143
|
if (f) throw new TypeError("Generator is already executing.");
|
|
140
|
-
while (_) try {
|
|
144
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
141
145
|
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;
|
|
142
146
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
143
147
|
switch (op[0]) {
|
|
@@ -170,6 +174,7 @@ var axios = Axios.create({
|
|
|
170
174
|
var log = require('@pioneer-platform/loggerdog')();
|
|
171
175
|
var BitcoinRpc = require('bitcoin-rpc-promise');
|
|
172
176
|
// import { Blockbook } from 'blockbook-client'
|
|
177
|
+
var Unchained = require("@pioneer-platform/unchained");
|
|
173
178
|
var blockbook = require('@pioneer-platform/blockbook');
|
|
174
179
|
var sochain = __importStar(require("./sochain-api"));
|
|
175
180
|
var Utils = __importStar(require("./utils"));
|
|
@@ -187,9 +192,18 @@ for (var i = 0; i < coins.length; i++) {
|
|
|
187
192
|
}
|
|
188
193
|
var URL_BLOCKCHAIN_INFO = "http://blockchain.info";
|
|
189
194
|
var URL_BLOCKBOOK_BTC = "";
|
|
195
|
+
var SYMBOL_TO_CAIP = {
|
|
196
|
+
"BCH": "bip122:000000000000000000651ef99cb9fcbe/slip44:145",
|
|
197
|
+
// "ETH":"eip155:1/slip44:60",
|
|
198
|
+
"BTC": "bip122:000000000019d6689c085ae165831e93/slip44:0",
|
|
199
|
+
"DASH": "bip122:dash-hash/slip44:5",
|
|
200
|
+
"DOGE": "bip122:00000000001a91e3dace36e2be3bf030/slip44:3",
|
|
201
|
+
"LTC": "bip122:12a765e31ffd4059bada1e25190f6e98/slip44:2",
|
|
202
|
+
};
|
|
190
203
|
var RUNTIME = 'pioneer';
|
|
191
204
|
var ONLINE = [];
|
|
192
205
|
var OFFLINE = [];
|
|
206
|
+
var unchained;
|
|
193
207
|
module.exports = {
|
|
194
208
|
init: function (runtime, servers) {
|
|
195
209
|
return init_network(runtime, servers);
|
|
@@ -273,10 +287,52 @@ module.exports = {
|
|
|
273
287
|
broadcast: function (coin, tx) {
|
|
274
288
|
return broadcast_transaction(coin, tx);
|
|
275
289
|
},
|
|
290
|
+
// getAccount:function (address) {
|
|
291
|
+
// return get_account(address);
|
|
292
|
+
// },
|
|
293
|
+
// getSequence:function (address) {
|
|
294
|
+
// return get_account_sequence(address);
|
|
295
|
+
// },
|
|
296
|
+
// getValidators:function () {
|
|
297
|
+
// return get_validators();
|
|
298
|
+
// }
|
|
276
299
|
};
|
|
277
|
-
var
|
|
300
|
+
var init_network = function (runtime, servers) {
|
|
278
301
|
return __awaiter(this, void 0, void 0, function () {
|
|
279
302
|
var tag, output, e_1;
|
|
303
|
+
return __generator(this, function (_a) {
|
|
304
|
+
switch (_a.label) {
|
|
305
|
+
case 0:
|
|
306
|
+
tag = ' | get_txs_by_address | ';
|
|
307
|
+
_a.label = 1;
|
|
308
|
+
case 1:
|
|
309
|
+
_a.trys.push([1, 4, , 5]);
|
|
310
|
+
log.debug(tag, "checkpoint: ");
|
|
311
|
+
output = [];
|
|
312
|
+
RUNTIME = runtime;
|
|
313
|
+
return [4 /*yield*/, blockbook.init()];
|
|
314
|
+
case 2:
|
|
315
|
+
_a.sent();
|
|
316
|
+
return [4 /*yield*/, Unchained.init()];
|
|
317
|
+
case 3:
|
|
318
|
+
unchained = _a.sent();
|
|
319
|
+
log.info("unchained: ", unchained);
|
|
320
|
+
//get unchainedservers
|
|
321
|
+
//figure out what is online
|
|
322
|
+
//return online servers
|
|
323
|
+
return [2 /*return*/, true];
|
|
324
|
+
case 4:
|
|
325
|
+
e_1 = _a.sent();
|
|
326
|
+
console.error(tag, 'Error: ', e_1);
|
|
327
|
+
throw e_1;
|
|
328
|
+
case 5: return [2 /*return*/];
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
var get_pubkey_info = function (coin, xpub) {
|
|
334
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
335
|
+
var tag, output, e_2;
|
|
280
336
|
return __generator(this, function (_a) {
|
|
281
337
|
switch (_a.label) {
|
|
282
338
|
case 0:
|
|
@@ -290,8 +346,8 @@ var get_pubkey_info = function (coin, xpub) {
|
|
|
290
346
|
log.debug(tag, "output: ", output);
|
|
291
347
|
return [2 /*return*/, output];
|
|
292
348
|
case 3:
|
|
293
|
-
|
|
294
|
-
console.error(tag,
|
|
349
|
+
e_2 = _a.sent();
|
|
350
|
+
console.error(tag, e_2);
|
|
295
351
|
return [3 /*break*/, 4];
|
|
296
352
|
case 4: return [2 /*return*/];
|
|
297
353
|
}
|
|
@@ -300,7 +356,7 @@ var get_pubkey_info = function (coin, xpub) {
|
|
|
300
356
|
};
|
|
301
357
|
var get_fees_with_memo = function (coin, memo) {
|
|
302
358
|
return __awaiter(this, void 0, void 0, function () {
|
|
303
|
-
var tag, fees,
|
|
359
|
+
var tag, fees, e_3;
|
|
304
360
|
return __generator(this, function (_a) {
|
|
305
361
|
switch (_a.label) {
|
|
306
362
|
case 0:
|
|
@@ -313,8 +369,8 @@ var get_fees_with_memo = function (coin, memo) {
|
|
|
313
369
|
fees = (_a.sent()).fees;
|
|
314
370
|
return [2 /*return*/, fees];
|
|
315
371
|
case 3:
|
|
316
|
-
|
|
317
|
-
console.error(tag,
|
|
372
|
+
e_3 = _a.sent();
|
|
373
|
+
console.error(tag, e_3);
|
|
318
374
|
return [3 /*break*/, 4];
|
|
319
375
|
case 4: return [2 /*return*/];
|
|
320
376
|
}
|
|
@@ -323,7 +379,7 @@ var get_fees_with_memo = function (coin, memo) {
|
|
|
323
379
|
};
|
|
324
380
|
var get_fees_with_rates = function (coin, memo) {
|
|
325
381
|
return __awaiter(this, void 0, void 0, function () {
|
|
326
|
-
var tag, output, txFee, rates, fees,
|
|
382
|
+
var tag, output, txFee, rates, fees, e_4;
|
|
327
383
|
return __generator(this, function (_a) {
|
|
328
384
|
switch (_a.label) {
|
|
329
385
|
case 0:
|
|
@@ -349,8 +405,8 @@ var get_fees_with_rates = function (coin, memo) {
|
|
|
349
405
|
};
|
|
350
406
|
return [2 /*return*/, { fees: fees, rates: rates }];
|
|
351
407
|
case 3:
|
|
352
|
-
|
|
353
|
-
console.error(tag,
|
|
408
|
+
e_4 = _a.sent();
|
|
409
|
+
console.error(tag, e_4);
|
|
354
410
|
return [3 /*break*/, 4];
|
|
355
411
|
case 4: return [2 /*return*/];
|
|
356
412
|
}
|
|
@@ -359,15 +415,16 @@ var get_fees_with_rates = function (coin, memo) {
|
|
|
359
415
|
};
|
|
360
416
|
var get_fee = function (coin) {
|
|
361
417
|
return __awaiter(this, void 0, void 0, function () {
|
|
362
|
-
var tag, output, query,
|
|
418
|
+
var tag, output, query, result, e_5;
|
|
363
419
|
return __generator(this, function (_a) {
|
|
364
420
|
switch (_a.label) {
|
|
365
421
|
case 0:
|
|
366
422
|
tag = TAG + " | get_fee | ";
|
|
367
423
|
_a.label = 1;
|
|
368
424
|
case 1:
|
|
369
|
-
_a.trys.push([1,
|
|
425
|
+
_a.trys.push([1, 7, , 8]);
|
|
370
426
|
output = {};
|
|
427
|
+
log.info(tag, "coin: ", coin);
|
|
371
428
|
if (!(coin === 'BTC')) return [3 /*break*/, 3];
|
|
372
429
|
query = "https://bitcoinfees.earn.com/api/v1/fees/recommended";
|
|
373
430
|
return [4 /*yield*/, axios({ method: 'GET', url: query })];
|
|
@@ -375,23 +432,31 @@ var get_fee = function (coin) {
|
|
|
375
432
|
output = _a.sent();
|
|
376
433
|
log.debug(tag, "output: ", output.data);
|
|
377
434
|
output = output.data.fastestFee;
|
|
378
|
-
return [3 /*break*/, 4];
|
|
379
|
-
case 3:
|
|
380
|
-
//eh just send whatever, probally be fine
|
|
381
|
-
throw Error("unknown coin! " + coin);
|
|
382
|
-
case 4: return [2 /*return*/, output];
|
|
383
|
-
case 5:
|
|
384
|
-
e_4 = _a.sent();
|
|
385
|
-
console.error(tag, e_4);
|
|
386
435
|
return [3 /*break*/, 6];
|
|
387
|
-
case
|
|
436
|
+
case 3:
|
|
437
|
+
log.info(tag, "caip: ", SYMBOL_TO_CAIP[coin]);
|
|
438
|
+
if (!unchained[SYMBOL_TO_CAIP[coin]]) return [3 /*break*/, 5];
|
|
439
|
+
return [4 /*yield*/, unchained[SYMBOL_TO_CAIP[coin]].GetNetworkFees()];
|
|
440
|
+
case 4:
|
|
441
|
+
result = _a.sent();
|
|
442
|
+
console.log("result: ", result.data);
|
|
443
|
+
return [3 /*break*/, 6];
|
|
444
|
+
case 5:
|
|
445
|
+
console.log("no unchained for coin: ", coin);
|
|
446
|
+
_a.label = 6;
|
|
447
|
+
case 6: return [2 /*return*/, output];
|
|
448
|
+
case 7:
|
|
449
|
+
e_5 = _a.sent();
|
|
450
|
+
console.error(tag, e_5);
|
|
451
|
+
return [3 /*break*/, 8];
|
|
452
|
+
case 8: return [2 /*return*/];
|
|
388
453
|
}
|
|
389
454
|
});
|
|
390
455
|
});
|
|
391
456
|
};
|
|
392
457
|
var broadcast_transaction = function (coin, tx) {
|
|
393
458
|
return __awaiter(this, void 0, void 0, function () {
|
|
394
|
-
var tag, output, responseBroadcast, url, body, output_1,
|
|
459
|
+
var tag, output, responseBroadcast, url, body, output_1, e_6, e_7, e_8;
|
|
395
460
|
return __generator(this, function (_a) {
|
|
396
461
|
switch (_a.label) {
|
|
397
462
|
case 0:
|
|
@@ -432,23 +497,23 @@ var broadcast_transaction = function (coin, tx) {
|
|
|
432
497
|
output_1.success = true;
|
|
433
498
|
return [3 /*break*/, 6];
|
|
434
499
|
case 5:
|
|
435
|
-
|
|
500
|
+
e_6 = _a.sent();
|
|
436
501
|
// log.info(tag,"error: ",e)
|
|
437
502
|
// log.info(tag,"data0: ",e)
|
|
438
503
|
// log.info(tag,"resp: ",resp)
|
|
439
504
|
// log.info(tag,"data0: ",Object.keys(e))
|
|
440
505
|
// log.info(tag,"data1: ",e.response.req)
|
|
441
|
-
log.info(tag, "data2: ",
|
|
442
|
-
log.info(tag, "data2: ",
|
|
506
|
+
log.info(tag, "data2: ", e_6.response.data);
|
|
507
|
+
log.info(tag, "data2: ", e_6.response.data.message);
|
|
443
508
|
// log.info(tag,"error3: ",e.toJSON().request)
|
|
444
509
|
// log.info(tag,"erro4: ",e.toJSON().data)
|
|
445
510
|
// log.info(tag,"error5: ",e.toJSON().code)
|
|
446
|
-
if (
|
|
511
|
+
if (e_6.response.data.message) {
|
|
447
512
|
log.info(tag, "saving message! ");
|
|
448
|
-
output_1.error =
|
|
513
|
+
output_1.error = e_6.response.data.message;
|
|
449
514
|
}
|
|
450
515
|
else {
|
|
451
|
-
output_1.error =
|
|
516
|
+
output_1.error = e_6;
|
|
452
517
|
}
|
|
453
518
|
return [3 /*break*/, 6];
|
|
454
519
|
case 6:
|
|
@@ -477,16 +542,16 @@ var broadcast_transaction = function (coin, tx) {
|
|
|
477
542
|
return [2 /*return*/, output];
|
|
478
543
|
case 9: return [3 /*break*/, 11];
|
|
479
544
|
case 10:
|
|
480
|
-
|
|
545
|
+
e_7 = _a.sent();
|
|
481
546
|
//TODO handle errors
|
|
482
547
|
if (!output.error)
|
|
483
|
-
output.error =
|
|
548
|
+
output.error = e_7;
|
|
484
549
|
return [2 /*return*/, output];
|
|
485
550
|
case 11: return [3 /*break*/, 13];
|
|
486
551
|
case 12:
|
|
487
|
-
|
|
488
|
-
console.error(tag,
|
|
489
|
-
throw
|
|
552
|
+
e_8 = _a.sent();
|
|
553
|
+
console.error(tag, e_8);
|
|
554
|
+
throw e_8;
|
|
490
555
|
case 13: return [2 /*return*/];
|
|
491
556
|
}
|
|
492
557
|
});
|
|
@@ -494,7 +559,7 @@ var broadcast_transaction = function (coin, tx) {
|
|
|
494
559
|
};
|
|
495
560
|
var get_balance_by_addresses = function (coin, addresses) {
|
|
496
561
|
return __awaiter(this, void 0, void 0, function () {
|
|
497
|
-
var tag, query, i, address, balanceInfo,
|
|
562
|
+
var tag, query, i, address, balanceInfo, e_9;
|
|
498
563
|
return __generator(this, function (_a) {
|
|
499
564
|
switch (_a.label) {
|
|
500
565
|
case 0:
|
|
@@ -516,8 +581,8 @@ var get_balance_by_addresses = function (coin, addresses) {
|
|
|
516
581
|
//https://blockchain.info/multiaddr?active=$address|$address
|
|
517
582
|
return [2 /*return*/, balanceInfo.data];
|
|
518
583
|
case 3:
|
|
519
|
-
|
|
520
|
-
console.error(tag,
|
|
584
|
+
e_9 = _a.sent();
|
|
585
|
+
console.error(tag, e_9);
|
|
521
586
|
return [3 /*break*/, 4];
|
|
522
587
|
case 4: return [2 /*return*/];
|
|
523
588
|
}
|
|
@@ -526,7 +591,7 @@ var get_balance_by_addresses = function (coin, addresses) {
|
|
|
526
591
|
};
|
|
527
592
|
var get_balance_by_address = function (coin, address) {
|
|
528
593
|
return __awaiter(this, void 0, void 0, function () {
|
|
529
|
-
var tag, balanceInfo,
|
|
594
|
+
var tag, balanceInfo, e_10;
|
|
530
595
|
return __generator(this, function (_a) {
|
|
531
596
|
switch (_a.label) {
|
|
532
597
|
case 0:
|
|
@@ -539,8 +604,8 @@ var get_balance_by_address = function (coin, address) {
|
|
|
539
604
|
balanceInfo = _a.sent();
|
|
540
605
|
return [2 /*return*/, balanceInfo.data.balance];
|
|
541
606
|
case 3:
|
|
542
|
-
|
|
543
|
-
console.error(tag,
|
|
607
|
+
e_10 = _a.sent();
|
|
608
|
+
console.error(tag, e_10);
|
|
544
609
|
return [3 /*break*/, 4];
|
|
545
610
|
case 4: return [2 /*return*/];
|
|
546
611
|
}
|
|
@@ -549,7 +614,7 @@ var get_balance_by_address = function (coin, address) {
|
|
|
549
614
|
};
|
|
550
615
|
var get_utxos_by_xpub = function (coin, xpub) {
|
|
551
616
|
return __awaiter(this, void 0, void 0, function () {
|
|
552
|
-
var tag, output,
|
|
617
|
+
var tag, output, e_11;
|
|
553
618
|
return __generator(this, function (_a) {
|
|
554
619
|
switch (_a.label) {
|
|
555
620
|
case 0:
|
|
@@ -563,8 +628,8 @@ var get_utxos_by_xpub = function (coin, xpub) {
|
|
|
563
628
|
log.debug(tag, "output: ", output);
|
|
564
629
|
return [2 /*return*/, output];
|
|
565
630
|
case 3:
|
|
566
|
-
|
|
567
|
-
console.error(tag,
|
|
631
|
+
e_11 = _a.sent();
|
|
632
|
+
console.error(tag, e_11);
|
|
568
633
|
return [3 /*break*/, 4];
|
|
569
634
|
case 4: return [2 /*return*/];
|
|
570
635
|
}
|
|
@@ -573,7 +638,7 @@ var get_utxos_by_xpub = function (coin, xpub) {
|
|
|
573
638
|
};
|
|
574
639
|
var get_balance_by_xpub = function (coin, xpub) {
|
|
575
640
|
return __awaiter(this, void 0, void 0, function () {
|
|
576
|
-
var tag, output, balance, i, uxto,
|
|
641
|
+
var tag, output, balance, i, uxto, e_12;
|
|
577
642
|
return __generator(this, function (_a) {
|
|
578
643
|
switch (_a.label) {
|
|
579
644
|
case 0:
|
|
@@ -593,8 +658,8 @@ var get_balance_by_xpub = function (coin, xpub) {
|
|
|
593
658
|
}
|
|
594
659
|
return [2 /*return*/, balance / 100000000];
|
|
595
660
|
case 3:
|
|
596
|
-
|
|
597
|
-
console.error(tag,
|
|
661
|
+
e_12 = _a.sent();
|
|
662
|
+
console.error(tag, e_12);
|
|
598
663
|
return [3 /*break*/, 4];
|
|
599
664
|
case 4: return [2 /*return*/];
|
|
600
665
|
}
|
|
@@ -603,7 +668,7 @@ var get_balance_by_xpub = function (coin, xpub) {
|
|
|
603
668
|
};
|
|
604
669
|
var get_block_hash = function (coin, height) {
|
|
605
670
|
return __awaiter(this, void 0, void 0, function () {
|
|
606
|
-
var tag, blockHash,
|
|
671
|
+
var tag, blockHash, e_13;
|
|
607
672
|
return __generator(this, function (_a) {
|
|
608
673
|
switch (_a.label) {
|
|
609
674
|
case 0:
|
|
@@ -616,36 +681,10 @@ var get_block_hash = function (coin, height) {
|
|
|
616
681
|
blockHash = _a.sent();
|
|
617
682
|
log.debug(tag, "blockHash: ", blockHash);
|
|
618
683
|
return [2 /*return*/, blockHash];
|
|
619
|
-
case 3:
|
|
620
|
-
e_12 = _a.sent();
|
|
621
|
-
console.error(tag, e_12);
|
|
622
|
-
return [3 /*break*/, 4];
|
|
623
|
-
case 4: return [2 /*return*/];
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
});
|
|
627
|
-
};
|
|
628
|
-
var init_network = function (runtime, servers) {
|
|
629
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
630
|
-
var tag, output, e_13;
|
|
631
|
-
return __generator(this, function (_a) {
|
|
632
|
-
switch (_a.label) {
|
|
633
|
-
case 0:
|
|
634
|
-
tag = ' | get_txs_by_address | ';
|
|
635
|
-
_a.label = 1;
|
|
636
|
-
case 1:
|
|
637
|
-
_a.trys.push([1, 3, , 4]);
|
|
638
|
-
log.debug(tag, "checkpoint: ");
|
|
639
|
-
output = [];
|
|
640
|
-
RUNTIME = runtime;
|
|
641
|
-
return [4 /*yield*/, blockbook.init()];
|
|
642
|
-
case 2:
|
|
643
|
-
_a.sent();
|
|
644
|
-
return [2 /*return*/, true];
|
|
645
684
|
case 3:
|
|
646
685
|
e_13 = _a.sent();
|
|
647
|
-
console.error(tag,
|
|
648
|
-
|
|
686
|
+
console.error(tag, e_13);
|
|
687
|
+
return [3 /*break*/, 4];
|
|
649
688
|
case 4: return [2 /*return*/];
|
|
650
689
|
}
|
|
651
690
|
});
|
package/lib/sochain-api.js
CHANGED
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
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;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -57,7 +57,7 @@ var toSochainNetwork = function (net) {
|
|
|
57
57
|
* @param {string} address
|
|
58
58
|
* @returns {BtcAddressDTO}
|
|
59
59
|
*/
|
|
60
|
-
|
|
60
|
+
var getAddress = function (_a) {
|
|
61
61
|
var sochainUrl = _a.sochainUrl, network = _a.network, address = _a.address;
|
|
62
62
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
63
63
|
var url, response, addressResponse, error_1;
|
|
@@ -65,7 +65,7 @@ exports.getAddress = function (_a) {
|
|
|
65
65
|
switch (_b.label) {
|
|
66
66
|
case 0:
|
|
67
67
|
_b.trys.push([0, 2, , 3]);
|
|
68
|
-
url = sochainUrl
|
|
68
|
+
url = "".concat(sochainUrl, "/address/").concat(toSochainNetwork(network), "/").concat(address);
|
|
69
69
|
return [4 /*yield*/, axios_1.default.get(url)];
|
|
70
70
|
case 1:
|
|
71
71
|
response = _b.sent();
|
|
@@ -79,6 +79,7 @@ exports.getAddress = function (_a) {
|
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
81
|
};
|
|
82
|
+
exports.getAddress = getAddress;
|
|
82
83
|
/**
|
|
83
84
|
* Get transaction by hash.
|
|
84
85
|
*
|
|
@@ -89,7 +90,7 @@ exports.getAddress = function (_a) {
|
|
|
89
90
|
* @param {string} hash The transaction hash.
|
|
90
91
|
* @returns {Transactions}
|
|
91
92
|
*/
|
|
92
|
-
|
|
93
|
+
var getTx = function (_a) {
|
|
93
94
|
var sochainUrl = _a.sochainUrl, network = _a.network, hash = _a.hash;
|
|
94
95
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
95
96
|
var url, response, tx, error_2;
|
|
@@ -97,7 +98,7 @@ exports.getTx = function (_a) {
|
|
|
97
98
|
switch (_b.label) {
|
|
98
99
|
case 0:
|
|
99
100
|
_b.trys.push([0, 2, , 3]);
|
|
100
|
-
url = sochainUrl
|
|
101
|
+
url = "".concat(sochainUrl, "/get_tx/").concat(toSochainNetwork(network), "/").concat(hash);
|
|
101
102
|
return [4 /*yield*/, axios_1.default.get(url)];
|
|
102
103
|
case 1:
|
|
103
104
|
response = _b.sent();
|
|
@@ -111,6 +112,7 @@ exports.getTx = function (_a) {
|
|
|
111
112
|
});
|
|
112
113
|
});
|
|
113
114
|
};
|
|
115
|
+
exports.getTx = getTx;
|
|
114
116
|
/**
|
|
115
117
|
* Get address balance.
|
|
116
118
|
*
|
|
@@ -121,7 +123,7 @@ exports.getTx = function (_a) {
|
|
|
121
123
|
* @param {string} address
|
|
122
124
|
* @returns {number}
|
|
123
125
|
*/
|
|
124
|
-
|
|
126
|
+
var getBalance = function (_a) {
|
|
125
127
|
var sochainUrl = _a.sochainUrl, network = _a.network, address = _a.address;
|
|
126
128
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
127
129
|
var url, response, balanceResponse, confirmed, unconfirmed, netAmt, result, error_3;
|
|
@@ -129,15 +131,15 @@ exports.getBalance = function (_a) {
|
|
|
129
131
|
switch (_b.label) {
|
|
130
132
|
case 0:
|
|
131
133
|
_b.trys.push([0, 2, , 3]);
|
|
132
|
-
url = sochainUrl
|
|
134
|
+
url = "".concat(sochainUrl, "/get_address_balance/").concat(toSochainNetwork(network), "/").concat(address);
|
|
133
135
|
return [4 /*yield*/, axios_1.default.get(url)];
|
|
134
136
|
case 1:
|
|
135
137
|
response = _b.sent();
|
|
136
138
|
balanceResponse = response.data;
|
|
137
|
-
confirmed = xchain_util_1.assetAmount(balanceResponse.data.confirmed_balance, utils_1.BTC_DECIMAL);
|
|
138
|
-
unconfirmed = xchain_util_1.assetAmount(balanceResponse.data.unconfirmed_balance, utils_1.BTC_DECIMAL);
|
|
139
|
+
confirmed = (0, xchain_util_1.assetAmount)(balanceResponse.data.confirmed_balance, utils_1.BTC_DECIMAL);
|
|
140
|
+
unconfirmed = (0, xchain_util_1.assetAmount)(balanceResponse.data.unconfirmed_balance, utils_1.BTC_DECIMAL);
|
|
139
141
|
netAmt = confirmed.amount().plus(unconfirmed.amount());
|
|
140
|
-
result = xchain_util_1.assetToBase(xchain_util_1.assetAmount(netAmt, utils_1.BTC_DECIMAL));
|
|
142
|
+
result = (0, xchain_util_1.assetToBase)((0, xchain_util_1.assetAmount)(netAmt, utils_1.BTC_DECIMAL));
|
|
141
143
|
return [2 /*return*/, result];
|
|
142
144
|
case 2:
|
|
143
145
|
error_3 = _b.sent();
|
|
@@ -147,6 +149,7 @@ exports.getBalance = function (_a) {
|
|
|
147
149
|
});
|
|
148
150
|
});
|
|
149
151
|
};
|
|
152
|
+
exports.getBalance = getBalance;
|
|
150
153
|
/**
|
|
151
154
|
* Get unspent txs
|
|
152
155
|
*
|
|
@@ -157,7 +160,7 @@ exports.getBalance = function (_a) {
|
|
|
157
160
|
* @param {string} address
|
|
158
161
|
* @returns {BtcAddressUTXOs}
|
|
159
162
|
*/
|
|
160
|
-
|
|
163
|
+
var getUnspentTxs = function (_a) {
|
|
161
164
|
var sochainUrl = _a.sochainUrl, network = _a.network, address = _a.address;
|
|
162
165
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
163
166
|
var resp, response, error_4;
|
|
@@ -165,7 +168,7 @@ exports.getUnspentTxs = function (_a) {
|
|
|
165
168
|
switch (_b.label) {
|
|
166
169
|
case 0:
|
|
167
170
|
_b.trys.push([0, 2, , 3]);
|
|
168
|
-
return [4 /*yield*/, axios_1.default.get(sochainUrl
|
|
171
|
+
return [4 /*yield*/, axios_1.default.get("".concat(sochainUrl, "/get_tx_unspent/").concat(toSochainNetwork(network), "/").concat(address))];
|
|
169
172
|
case 1:
|
|
170
173
|
resp = _b.sent();
|
|
171
174
|
response = resp.data;
|
|
@@ -178,12 +181,13 @@ exports.getUnspentTxs = function (_a) {
|
|
|
178
181
|
});
|
|
179
182
|
});
|
|
180
183
|
};
|
|
184
|
+
exports.getUnspentTxs = getUnspentTxs;
|
|
181
185
|
/**
|
|
182
186
|
* Get Bitcoin suggested transaction fee.
|
|
183
187
|
*
|
|
184
188
|
* @returns {number} The Bitcoin suggested transaction fee per bytes in sat.
|
|
185
189
|
*/
|
|
186
|
-
|
|
190
|
+
var getSuggestedTxFee = function (coin) { return __awaiter(void 0, void 0, void 0, function () {
|
|
187
191
|
var response, error_5;
|
|
188
192
|
return __generator(this, function (_a) {
|
|
189
193
|
switch (_a.label) {
|
|
@@ -200,3 +204,4 @@ exports.getSuggestedTxFee = function (coin) { return __awaiter(void 0, void 0, v
|
|
|
200
204
|
}
|
|
201
205
|
});
|
|
202
206
|
}); };
|
|
207
|
+
exports.getSuggestedTxFee = getSuggestedTxFee;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Address, FeeOptionKey, Fees, Network } from '@xchainjs/xchain-client';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
2
|
+
export type FeeRate = number;
|
|
3
|
+
export type FeeRates = Record<FeeOptionKey, FeeRate>;
|
|
4
|
+
export type FeesWithRates = {
|
|
5
5
|
rates: FeeRates;
|
|
6
6
|
fees: Fees;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type NormalTxParams = {
|
|
9
9
|
addressTo: string;
|
|
10
10
|
amount: number;
|
|
11
11
|
feeRate: number;
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export type VaultTxParams = NormalTxParams & {
|
|
14
14
|
memo: string;
|
|
15
15
|
};
|
|
16
|
-
export
|
|
16
|
+
export type GetChangeParams = {
|
|
17
17
|
valueOut: number;
|
|
18
18
|
sochainUrl: string;
|
|
19
19
|
network: Network;
|
package/lib/types/common.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
export
|
|
2
|
+
export type Witness = {
|
|
3
3
|
value: number;
|
|
4
4
|
script: Buffer;
|
|
5
5
|
};
|
|
6
|
-
export
|
|
6
|
+
export type UTXO = {
|
|
7
7
|
hash: string;
|
|
8
8
|
index: number;
|
|
9
9
|
witnessUtxo: Witness;
|
|
10
10
|
txHex: string;
|
|
11
11
|
};
|
|
12
|
-
export
|
|
13
|
-
export
|
|
12
|
+
export type UTXOs = UTXO[];
|
|
13
|
+
export type DerivePath = {
|
|
14
14
|
mainnet: string;
|
|
15
15
|
testnet: string;
|
|
16
16
|
};
|
package/lib/types/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
8
12
|
}));
|
|
9
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
17
|
__exportStar(require("./client-types"), exports);
|
package/lib/types/ledger.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Address, Network, TxParams } from '@xchainjs/xchain-client';
|
|
2
2
|
import { FeeRate } from './client-types';
|
|
3
3
|
import { UTXOs } from './common';
|
|
4
|
-
export
|
|
4
|
+
export type LedgerTxInfo = {
|
|
5
5
|
utxos: UTXOs;
|
|
6
6
|
newTxHex: string;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type LedgerTxInfoParams = Pick<TxParams, 'amount' | 'recipient'> & {
|
|
9
9
|
feeRate: FeeRate;
|
|
10
10
|
sender: Address;
|
|
11
11
|
network: Network;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Network, TxHash } from '@xchainjs/xchain-client';
|
|
2
|
-
export
|
|
2
|
+
export type AddressParams = {
|
|
3
3
|
sochainUrl: string;
|
|
4
4
|
network: Network;
|
|
5
5
|
address: string;
|
|
6
6
|
};
|
|
7
|
-
export
|
|
7
|
+
export type TxHashParams = {
|
|
8
8
|
sochainUrl: string;
|
|
9
9
|
network: Network;
|
|
10
10
|
hash: TxHash;
|
|
11
11
|
};
|
|
12
|
-
export
|
|
12
|
+
export type TxBroadcastParams = {
|
|
13
13
|
sochainUrl: string;
|
|
14
14
|
network: Network;
|
|
15
15
|
txHex: string;
|
|
@@ -34,7 +34,7 @@ export interface Transaction {
|
|
|
34
34
|
inputs: TxIO[];
|
|
35
35
|
outputs: TxIO[];
|
|
36
36
|
}
|
|
37
|
-
export
|
|
37
|
+
export type BtcAddressUTXO = {
|
|
38
38
|
txid: string;
|
|
39
39
|
output_no: number;
|
|
40
40
|
script_asm: string;
|
|
@@ -43,7 +43,7 @@ export declare type BtcAddressUTXO = {
|
|
|
43
43
|
confirmations: number;
|
|
44
44
|
time: number;
|
|
45
45
|
};
|
|
46
|
-
export
|
|
46
|
+
export type BtcAddressTxDTO = {
|
|
47
47
|
txid: string;
|
|
48
48
|
block_no: number;
|
|
49
49
|
confirmations: number;
|
|
@@ -52,7 +52,7 @@ export declare type BtcAddressTxDTO = {
|
|
|
52
52
|
script_asm: string;
|
|
53
53
|
script_hex: string;
|
|
54
54
|
};
|
|
55
|
-
export
|
|
55
|
+
export type BtcAddressDTO = {
|
|
56
56
|
network: string;
|
|
57
57
|
address: string;
|
|
58
58
|
balance: string;
|
|
@@ -61,19 +61,19 @@ export declare type BtcAddressDTO = {
|
|
|
61
61
|
total_txs: number;
|
|
62
62
|
txs: BtcAddressTxDTO[];
|
|
63
63
|
};
|
|
64
|
-
export
|
|
64
|
+
export type BtcGetBalanceDTO = {
|
|
65
65
|
network: string;
|
|
66
66
|
address: string;
|
|
67
67
|
confirmed_balance: string;
|
|
68
68
|
unconfirmed_balance: string;
|
|
69
69
|
};
|
|
70
|
-
export
|
|
70
|
+
export type BtcUnspentTxsDTO = {
|
|
71
71
|
network: string;
|
|
72
72
|
address: string;
|
|
73
73
|
txs: BtcAddressUTXO[];
|
|
74
74
|
};
|
|
75
|
-
export
|
|
76
|
-
export
|
|
75
|
+
export type BtcAddressUTXOs = BtcAddressUTXO[];
|
|
76
|
+
export type BtcBroadcastTransfer = {
|
|
77
77
|
network: string;
|
|
78
78
|
txid: string;
|
|
79
79
|
};
|
package/lib/utils.d.ts
CHANGED
|
@@ -104,7 +104,7 @@ export declare const getDerivePath: (index?: number) => DerivePath;
|
|
|
104
104
|
* @param {string} memo
|
|
105
105
|
* @returns {BaseAmount} The calculated fees based on fee rate and the memo.
|
|
106
106
|
*/
|
|
107
|
-
export declare const calcFee: (feeRate: FeeRate, memo?: string
|
|
107
|
+
export declare const calcFee: (feeRate: FeeRate, memo?: string) => BaseAmount;
|
|
108
108
|
/**
|
|
109
109
|
* Get the default fees with rates.
|
|
110
110
|
*
|
package/lib/utils.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -14,7 +18,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
14
18
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
19
|
if (mod && mod.__esModule) return mod;
|
|
16
20
|
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
22
|
__setModuleDefault(result, mod);
|
|
19
23
|
return result;
|
|
20
24
|
};
|
|
@@ -33,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
33
37
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
34
38
|
function step(op) {
|
|
35
39
|
if (f) throw new TypeError("Generator is already executing.");
|
|
36
|
-
while (_) try {
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
37
41
|
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;
|
|
38
42
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
39
43
|
switch (op[0]) {
|
|
@@ -76,10 +80,11 @@ var inputBytes = function (input) {
|
|
|
76
80
|
* @param {string} memo The memo to be compiled.
|
|
77
81
|
* @returns {Buffer} The compiled memo.
|
|
78
82
|
*/
|
|
79
|
-
|
|
83
|
+
var compileMemo = function (memo) {
|
|
80
84
|
var data = Buffer.from(memo, 'utf8'); // converts MEMO to buffer
|
|
81
85
|
return Bitcoin.script.compile([Bitcoin.opcodes.OP_RETURN, data]); // Compile OP_RETURN script
|
|
82
86
|
};
|
|
87
|
+
exports.compileMemo = compileMemo;
|
|
83
88
|
/**
|
|
84
89
|
* Get the transaction fee.
|
|
85
90
|
*
|
|
@@ -88,7 +93,7 @@ exports.compileMemo = function (memo) {
|
|
|
88
93
|
* @param {Buffer} data The compiled memo (Optional).
|
|
89
94
|
* @returns {number} The fee amount.
|
|
90
95
|
*/
|
|
91
|
-
|
|
96
|
+
var getFee = function (inputs, feeRate, data) {
|
|
92
97
|
if (data === void 0) { data = null; }
|
|
93
98
|
var sum = TX_EMPTY_SIZE +
|
|
94
99
|
inputs.reduce(function (a, x) { return a + inputBytes(x); }, 0) +
|
|
@@ -103,35 +108,39 @@ exports.getFee = function (inputs, feeRate, data) {
|
|
|
103
108
|
var fee = sum * feeRate;
|
|
104
109
|
return fee > const_1.MIN_TX_FEE ? fee : const_1.MIN_TX_FEE;
|
|
105
110
|
};
|
|
111
|
+
exports.getFee = getFee;
|
|
106
112
|
/**
|
|
107
113
|
* Get the average value of an array.
|
|
108
114
|
*
|
|
109
115
|
* @param {Array<number>} array
|
|
110
116
|
* @returns {number} The average value.
|
|
111
117
|
*/
|
|
112
|
-
|
|
118
|
+
var arrayAverage = function (array) {
|
|
113
119
|
var sum = 0;
|
|
114
120
|
array.forEach(function (value) { return (sum += value); });
|
|
115
121
|
return sum / array.length;
|
|
116
122
|
};
|
|
123
|
+
exports.arrayAverage = arrayAverage;
|
|
117
124
|
/**
|
|
118
125
|
* Check if give network is a testnet.
|
|
119
126
|
*
|
|
120
127
|
* @param {Network} network
|
|
121
128
|
* @returns {boolean} `true` or `false`
|
|
122
129
|
*/
|
|
123
|
-
|
|
130
|
+
var isTestnet = function (network) {
|
|
124
131
|
return network === 'testnet';
|
|
125
132
|
};
|
|
133
|
+
exports.isTestnet = isTestnet;
|
|
126
134
|
/**
|
|
127
135
|
* Get Bitcoin network to be used with bitcoinjs.
|
|
128
136
|
*
|
|
129
137
|
* @param {Network} network
|
|
130
138
|
* @returns {Bitcoin.Network} The BTC network.
|
|
131
139
|
*/
|
|
132
|
-
|
|
133
|
-
return exports.isTestnet(network) ? Bitcoin.networks.testnet : Bitcoin.networks.bitcoin;
|
|
140
|
+
var btcNetwork = function (network) {
|
|
141
|
+
return (0, exports.isTestnet)(network) ? Bitcoin.networks.testnet : Bitcoin.networks.bitcoin;
|
|
134
142
|
};
|
|
143
|
+
exports.btcNetwork = btcNetwork;
|
|
135
144
|
/**
|
|
136
145
|
* Get the balances of an address.
|
|
137
146
|
*
|
|
@@ -140,7 +149,7 @@ exports.btcNetwork = function (network) {
|
|
|
140
149
|
* @param {Address} address
|
|
141
150
|
* @returns {Array<Balance>} The balances of the given address.
|
|
142
151
|
*/
|
|
143
|
-
|
|
152
|
+
var getBalance = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
144
153
|
var balance, error_1;
|
|
145
154
|
return __generator(this, function (_a) {
|
|
146
155
|
switch (_a.label) {
|
|
@@ -162,6 +171,7 @@ exports.getBalance = function (params) { return __awaiter(void 0, void 0, void 0
|
|
|
162
171
|
}
|
|
163
172
|
});
|
|
164
173
|
}); };
|
|
174
|
+
exports.getBalance = getBalance;
|
|
165
175
|
/**
|
|
166
176
|
* Get the balance changes amount.
|
|
167
177
|
*
|
|
@@ -178,10 +188,10 @@ var getChange = function (_a) {
|
|
|
178
188
|
switch (_b.label) {
|
|
179
189
|
case 0:
|
|
180
190
|
_b.trys.push([0, 2, , 3]);
|
|
181
|
-
return [4 /*yield*/, exports.getBalance({ sochainUrl: sochainUrl, network: network, address: address })];
|
|
191
|
+
return [4 /*yield*/, (0, exports.getBalance)({ sochainUrl: sochainUrl, network: network, address: address })];
|
|
182
192
|
case 1:
|
|
183
193
|
balances = _b.sent();
|
|
184
|
-
btcBalance = balances.filter(function (balance) { return xchain_util_1.assetToString(balance.asset) === xchain_util_1.assetToString(xchain_util_1.AssetBTC); })[0];
|
|
194
|
+
btcBalance = balances.filter(function (balance) { return (0, xchain_util_1.assetToString)(balance.asset) === (0, xchain_util_1.assetToString)(xchain_util_1.AssetBTC); })[0];
|
|
185
195
|
change = 0;
|
|
186
196
|
if (btcBalance && btcBalance.amount.amount().minus(valueOut).isGreaterThan(DUST_THRESHOLD)) {
|
|
187
197
|
change = btcBalance.amount.amount().minus(valueOut).toNumber();
|
|
@@ -202,15 +212,16 @@ var getChange = function (_a) {
|
|
|
202
212
|
* @param {Network} network
|
|
203
213
|
* @returns {boolean} `true` or `false`.
|
|
204
214
|
*/
|
|
205
|
-
|
|
215
|
+
var validateAddress = function (address, network) {
|
|
206
216
|
try {
|
|
207
|
-
Bitcoin.address.toOutputScript(address, exports.btcNetwork(network));
|
|
217
|
+
Bitcoin.address.toOutputScript(address, (0, exports.btcNetwork)(network));
|
|
208
218
|
return true;
|
|
209
219
|
}
|
|
210
220
|
catch (error) {
|
|
211
221
|
return false;
|
|
212
222
|
}
|
|
213
223
|
};
|
|
224
|
+
exports.validateAddress = validateAddress;
|
|
214
225
|
/**
|
|
215
226
|
* Scan UTXOs from sochain.
|
|
216
227
|
*
|
|
@@ -219,7 +230,7 @@ exports.validateAddress = function (address, network) {
|
|
|
219
230
|
* @param {Address} address
|
|
220
231
|
* @returns {Array<UTXO>} The UTXOs of the given address.
|
|
221
232
|
*/
|
|
222
|
-
|
|
233
|
+
var scanUTXOs = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
223
234
|
var utxos;
|
|
224
235
|
return __generator(this, function (_a) {
|
|
225
236
|
switch (_a.label) {
|
|
@@ -231,7 +242,7 @@ exports.scanUTXOs = function (params) { return __awaiter(void 0, void 0, void 0,
|
|
|
231
242
|
hash: utxo.txid,
|
|
232
243
|
index: utxo.output_no,
|
|
233
244
|
witnessUtxo: {
|
|
234
|
-
value: xchain_util_1.assetToBase(xchain_util_1.assetAmount(utxo.value, exports.BTC_DECIMAL)).amount().toNumber(),
|
|
245
|
+
value: (0, xchain_util_1.assetToBase)((0, xchain_util_1.assetAmount)(utxo.value, exports.BTC_DECIMAL)).amount().toNumber(),
|
|
235
246
|
script: Buffer.from(utxo.script_hex, 'hex'),
|
|
236
247
|
},
|
|
237
248
|
});
|
|
@@ -239,13 +250,14 @@ exports.scanUTXOs = function (params) { return __awaiter(void 0, void 0, void 0,
|
|
|
239
250
|
}
|
|
240
251
|
});
|
|
241
252
|
}); };
|
|
253
|
+
exports.scanUTXOs = scanUTXOs;
|
|
242
254
|
/**
|
|
243
255
|
* Build transcation.
|
|
244
256
|
*
|
|
245
257
|
* @param {BuildParams} params The transaction build options.
|
|
246
258
|
* @returns {Transaction}
|
|
247
259
|
*/
|
|
248
|
-
|
|
260
|
+
var buildTx = function (_a) {
|
|
249
261
|
var amount = _a.amount, recipient = _a.recipient, memo = _a.memo, feeRate = _a.feeRate, sender = _a.sender, network = _a.network, sochainUrl = _a.sochainUrl;
|
|
250
262
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
251
263
|
var utxos, balance, btcBalance, feeRateWhole, compiledMemo, fee, psbt_1, change, e_2;
|
|
@@ -253,29 +265,29 @@ exports.buildTx = function (_a) {
|
|
|
253
265
|
switch (_b.label) {
|
|
254
266
|
case 0:
|
|
255
267
|
_b.trys.push([0, 4, , 5]);
|
|
256
|
-
return [4 /*yield*/, exports.scanUTXOs({ sochainUrl: sochainUrl, network: network, address: sender })];
|
|
268
|
+
return [4 /*yield*/, (0, exports.scanUTXOs)({ sochainUrl: sochainUrl, network: network, address: sender })];
|
|
257
269
|
case 1:
|
|
258
270
|
utxos = _b.sent();
|
|
259
271
|
if (utxos.length === 0) {
|
|
260
272
|
return [2 /*return*/, Promise.reject(Error('No utxos to send'))];
|
|
261
273
|
}
|
|
262
|
-
return [4 /*yield*/, exports.getBalance({ sochainUrl: sochainUrl, network: network, address: sender })];
|
|
274
|
+
return [4 /*yield*/, (0, exports.getBalance)({ sochainUrl: sochainUrl, network: network, address: sender })];
|
|
263
275
|
case 2:
|
|
264
276
|
balance = _b.sent();
|
|
265
277
|
btcBalance = balance.filter(function (balance) { return balance.asset.symbol === xchain_util_1.AssetBTC.symbol; })[0];
|
|
266
278
|
if (!btcBalance) {
|
|
267
279
|
return [2 /*return*/, Promise.reject(new Error('No btcBalance found'))];
|
|
268
280
|
}
|
|
269
|
-
if (!exports.validateAddress(recipient, network)) {
|
|
281
|
+
if (!(0, exports.validateAddress)(recipient, network)) {
|
|
270
282
|
return [2 /*return*/, Promise.reject(new Error('Invalid address'))];
|
|
271
283
|
}
|
|
272
284
|
feeRateWhole = Number(feeRate.toFixed(0));
|
|
273
|
-
compiledMemo = memo ? exports.compileMemo(memo) : null;
|
|
274
|
-
fee = exports.getFee(utxos, feeRateWhole, compiledMemo);
|
|
285
|
+
compiledMemo = memo ? (0, exports.compileMemo)(memo) : null;
|
|
286
|
+
fee = (0, exports.getFee)(utxos, feeRateWhole, compiledMemo);
|
|
275
287
|
if (amount.amount().plus(fee).isGreaterThan(btcBalance.amount.amount())) {
|
|
276
288
|
return [2 /*return*/, Promise.reject(Error('Balance insufficient for transaction'))];
|
|
277
289
|
}
|
|
278
|
-
psbt_1 = new Bitcoin.Psbt({ network: exports.btcNetwork(network) }) // Network-specific
|
|
290
|
+
psbt_1 = new Bitcoin.Psbt({ network: (0, exports.btcNetwork)(network) }) // Network-specific
|
|
279
291
|
;
|
|
280
292
|
//Inputs
|
|
281
293
|
utxos.forEach(function (utxo) {
|
|
@@ -306,6 +318,7 @@ exports.buildTx = function (_a) {
|
|
|
306
318
|
});
|
|
307
319
|
});
|
|
308
320
|
};
|
|
321
|
+
exports.buildTx = buildTx;
|
|
309
322
|
/**
|
|
310
323
|
* Broadcast the transaction.
|
|
311
324
|
*
|
|
@@ -321,13 +334,14 @@ exports.buildTx = function (_a) {
|
|
|
321
334
|
* @param {number} index (optional)
|
|
322
335
|
* @returns {DerivePath} The bitcoin derivation path by the index. (both mainnet and testnet)
|
|
323
336
|
*/
|
|
324
|
-
|
|
337
|
+
var getDerivePath = function (index) {
|
|
325
338
|
if (index === void 0) { index = 0; }
|
|
326
339
|
return ({
|
|
327
|
-
mainnet: "84'/0'/0'/0/"
|
|
328
|
-
testnet: "84'/1'/0'/0/"
|
|
340
|
+
mainnet: "84'/0'/0'/0/".concat(index),
|
|
341
|
+
testnet: "84'/1'/0'/0/".concat(index),
|
|
329
342
|
});
|
|
330
343
|
};
|
|
344
|
+
exports.getDerivePath = getDerivePath;
|
|
331
345
|
/**
|
|
332
346
|
* Calculate fees based on fee rate and memo.
|
|
333
347
|
*
|
|
@@ -335,17 +349,18 @@ exports.getDerivePath = function (index) {
|
|
|
335
349
|
* @param {string} memo
|
|
336
350
|
* @returns {BaseAmount} The calculated fees based on fee rate and the memo.
|
|
337
351
|
*/
|
|
338
|
-
|
|
339
|
-
var compiledMemo = memo ? exports.compileMemo(memo) : null;
|
|
340
|
-
var fee = exports.getFee([], feeRate, compiledMemo);
|
|
341
|
-
return xchain_util_1.baseAmount(fee);
|
|
352
|
+
var calcFee = function (feeRate, memo) {
|
|
353
|
+
var compiledMemo = memo ? (0, exports.compileMemo)(memo) : null;
|
|
354
|
+
var fee = (0, exports.getFee)([], feeRate, compiledMemo);
|
|
355
|
+
return (0, xchain_util_1.baseAmount)(fee);
|
|
342
356
|
};
|
|
357
|
+
exports.calcFee = calcFee;
|
|
343
358
|
/**
|
|
344
359
|
* Get the default fees with rates.
|
|
345
360
|
*
|
|
346
361
|
* @returns {FeesWithRates} The default fees and rates.
|
|
347
362
|
*/
|
|
348
|
-
|
|
363
|
+
var getDefaultFeesWithRates = function () {
|
|
349
364
|
var rates = {
|
|
350
365
|
fastest: 50,
|
|
351
366
|
fast: 20,
|
|
@@ -353,24 +368,26 @@ exports.getDefaultFeesWithRates = function () {
|
|
|
353
368
|
};
|
|
354
369
|
var fees = {
|
|
355
370
|
type: 'byte',
|
|
356
|
-
fast: exports.calcFee(rates.fast),
|
|
357
|
-
average: exports.calcFee(rates.average),
|
|
358
|
-
fastest: exports.calcFee(rates.fastest),
|
|
371
|
+
fast: (0, exports.calcFee)(rates.fast),
|
|
372
|
+
average: (0, exports.calcFee)(rates.average),
|
|
373
|
+
fastest: (0, exports.calcFee)(rates.fastest),
|
|
359
374
|
};
|
|
360
375
|
return {
|
|
361
376
|
fees: fees,
|
|
362
377
|
rates: rates,
|
|
363
378
|
};
|
|
364
379
|
};
|
|
380
|
+
exports.getDefaultFeesWithRates = getDefaultFeesWithRates;
|
|
365
381
|
/**
|
|
366
382
|
* Get the default fees.
|
|
367
383
|
*
|
|
368
384
|
* @returns {Fees} The default fees.
|
|
369
385
|
*/
|
|
370
|
-
|
|
371
|
-
var fees = exports.getDefaultFeesWithRates().fees;
|
|
386
|
+
var getDefaultFees = function () {
|
|
387
|
+
var fees = (0, exports.getDefaultFeesWithRates)().fees;
|
|
372
388
|
return fees;
|
|
373
389
|
};
|
|
390
|
+
exports.getDefaultFees = getDefaultFees;
|
|
374
391
|
/**
|
|
375
392
|
* Get address prefix based on the network.
|
|
376
393
|
*
|
|
@@ -378,4 +395,5 @@ exports.getDefaultFees = function () {
|
|
|
378
395
|
* @returns {string} The address prefix based on the network.
|
|
379
396
|
*
|
|
380
397
|
**/
|
|
381
|
-
|
|
398
|
+
var getPrefix = function (network) { return (network === 'testnet' ? 'tb1' : 'bc1'); };
|
|
399
|
+
exports.getPrefix = getPrefix;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/utxo-network",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.1.59",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -11,13 +11,14 @@
|
|
|
11
11
|
"build:live": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@pioneer-platform/blockbook": "8.1.
|
|
15
|
-
"@pioneer-platform/loggerdog": "^8.1.
|
|
14
|
+
"@pioneer-platform/blockbook": "^8.1.49",
|
|
15
|
+
"@pioneer-platform/loggerdog": "^8.1.29",
|
|
16
|
+
"@pioneer-platform/unchained": "8.1.56",
|
|
16
17
|
"@types/request-promise-native": "^1.0.17",
|
|
17
18
|
"@xchainjs/xchain-client": "^0.7.0",
|
|
18
19
|
"@xchainjs/xchain-util": "^0.2.6",
|
|
19
20
|
"axiom": "^0.1.6",
|
|
20
|
-
"axios": "^
|
|
21
|
+
"axios": "^1.3.4",
|
|
21
22
|
"bitcoin-promise": "^1.3.1",
|
|
22
23
|
"bitcoin-rpc-promise": "^2.1.6",
|
|
23
24
|
"bitcoinjs-lib": "^5.2.0",
|
|
@@ -28,8 +29,8 @@
|
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@types/node": "^13.13.50",
|
|
31
|
-
"ts-node": "^
|
|
32
|
-
"typescript": "^
|
|
32
|
+
"ts-node": "^10.9.1",
|
|
33
|
+
"typescript": "^5.0.2"
|
|
33
34
|
},
|
|
34
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "8c626a669f7045d1eb9c00252d9a81845a57fa50"
|
|
35
36
|
}
|