@pioneer-platform/utxo-network 8.1.62 → 8.1.63

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.
Files changed (2) hide show
  1. package/lib/index.js +134 -109
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -385,112 +385,137 @@ var get_fee = function (coin) {
385
385
  });
386
386
  });
387
387
  };
388
+ /*
389
+ TODO - this is a mess
390
+
391
+ - need to figure out how to handle unchained vs node
392
+
393
+ We should broadcast many nodes
394
+
395
+ - unchained
396
+ - daemon
397
+ - blockbook
398
+
399
+ shotgun approach
400
+ push too all
401
+ first txid returns success
402
+ */
388
403
  var broadcast_transaction = function (coin, tx) {
389
404
  return __awaiter(this, void 0, void 0, function () {
390
- var tag, output, responseBroadcast, url, body, output_1, e_6, e_7, e_8;
405
+ var tag, output, result, e_6;
391
406
  return __generator(this, function (_a) {
392
407
  switch (_a.label) {
393
408
  case 0:
394
409
  tag = TAG + " | broadcast_transaction | ";
395
410
  _a.label = 1;
396
411
  case 1:
397
- _a.trys.push([1, 12, , 13]);
412
+ _a.trys.push([1, 5, , 6]);
398
413
  output = {
399
414
  success: false
400
415
  };
401
416
  log.info(tag, "coin: ", coin);
402
- _a.label = 2;
417
+ if (!unchained[SYMBOL_TO_CAIP[coin]]) return [3 /*break*/, 3];
418
+ return [4 /*yield*/, unchained[SYMBOL_TO_CAIP[coin]].SendTx({ hex: tx })];
403
419
  case 2:
404
- _a.trys.push([2, 10, , 11]);
405
- responseBroadcast = void 0;
406
- if (!(coin === 'BTC')) return [3 /*break*/, 7];
407
- log.info(tag, "BTC detected!");
408
- url = "https://api.bitcoin.shapeshift.com/api/v1/send";
409
- body = {
410
- url: url,
411
- method: 'POST',
412
- json: false,
413
- data: { hex: tx },
414
- };
415
- output_1 = {
416
- success: false
417
- };
418
- _a.label = 3;
420
+ result = _a.sent();
421
+ log.info(tag, "result.data: ", result.data);
422
+ output.txid = result.data;
423
+ output.success = true;
424
+ return [3 /*break*/, 4];
419
425
  case 3:
420
- _a.trys.push([3, 5, , 6]);
421
- return [4 /*yield*/, axios(body)];
422
- case 4:
423
- responseBroadcast = _a.sent();
424
- responseBroadcast = responseBroadcast.data;
425
- log.info(tag, 'responseBroadcast: ', responseBroadcast);
426
- output_1.txid = responseBroadcast;
427
- if (output_1.txid)
428
- output_1.success = true;
429
- return [3 /*break*/, 6];
426
+ console.log("no unchained for coin: ", coin);
427
+ //@TODO fall back to node
428
+ output.success = false;
429
+ output.error = "no unchained for coin: " + coin;
430
+ _a.label = 4;
431
+ case 4:
432
+ //Jesus fuck
433
+ // try{
434
+ // //TODO use for non-bitcoin? wtf why bitcoin blockbook broke?
435
+ // let responseBroadcast
436
+ // if(coin === 'BTC'){
437
+ // log.info(tag,"BTC detected!")
438
+ // let url = "https://api.bitcoin.shapeshift.com/api/v1/send"
439
+ // let body = {
440
+ // url,
441
+ // method: 'POST',
442
+ // json:false,
443
+ // data:{hex:tx},
444
+ // }
445
+ // let output:any = {
446
+ // success:false
447
+ // }
448
+ // try{
449
+ // responseBroadcast = await axios(body)
450
+ // responseBroadcast = responseBroadcast.data
451
+ // log.info(tag,'responseBroadcast: ',responseBroadcast)
452
+ // output.txid = responseBroadcast
453
+ // if(output.txid)output.success = true
454
+ //
455
+ // }catch(e:any){
456
+ // // log.info(tag,"error: ",e)
457
+ // // log.info(tag,"data0: ",e)
458
+ // // log.info(tag,"resp: ",resp)
459
+ // // log.info(tag,"data0: ",Object.keys(e))
460
+ // // log.info(tag,"data1: ",e.response.req)
461
+ // log.info(tag,"data2: ",e.response.data)
462
+ // log.info(tag,"data2: ",e.response.data.message)
463
+ // // log.info(tag,"error3: ",e.toJSON().request)
464
+ // // log.info(tag,"erro4: ",e.toJSON().data)
465
+ // // log.info(tag,"error5: ",e.toJSON().code)
466
+ // if(e.response.data.message){
467
+ // log.info(tag,"saving message! ")
468
+ // output.error = e.response.data.message
469
+ // }else{
470
+ // output.error = e
471
+ // }
472
+ // }
473
+ // log.info(tag,"output: ",output)
474
+ // return output
475
+ // } else {
476
+ // responseBroadcast = await blockbook.broadcast(coin,tx)
477
+ // log.info(tag,'responseBroadcast: ',responseBroadcast)
478
+ // if(responseBroadcast.success && responseBroadcast.success !== false){
479
+ // output.success = true
480
+ // if(responseBroadcast.txid){
481
+ // output.txid = responseBroadcast.resp.data.result
482
+ // }
483
+ // if(responseBroadcast.resp.data.result){
484
+ // output.txid = responseBroadcast.resp.data.result
485
+ // }
486
+ // } else if(responseBroadcast.error) {
487
+ // output.error = responseBroadcast.error
488
+ // } else {
489
+ // output.error = "unknown error"
490
+ // output.debug = responseBroadcast
491
+ // }
492
+ // return output
493
+ // }
494
+ //
495
+ // //use nodes
496
+ // // log.info(tag,'nodeMap: ',nodeMap)
497
+ // // let responseBroadcast = await nodeMap[coin].sendRawTransaction(tx)
498
+ // // log.info(tag,'responseBroadcast: ',responseBroadcast)
499
+ //
500
+ //
501
+ // }catch(e){
502
+ // //TODO handle errors
503
+ // if(!output.error)output.error = e
504
+ // return output
505
+ // }
506
+ return [2 /*return*/, output];
430
507
  case 5:
431
508
  e_6 = _a.sent();
432
- // log.info(tag,"error: ",e)
433
- // log.info(tag,"data0: ",e)
434
- // log.info(tag,"resp: ",resp)
435
- // log.info(tag,"data0: ",Object.keys(e))
436
- // log.info(tag,"data1: ",e.response.req)
437
- log.info(tag, "data2: ", e_6.response.data);
438
- log.info(tag, "data2: ", e_6.response.data.message);
439
- // log.info(tag,"error3: ",e.toJSON().request)
440
- // log.info(tag,"erro4: ",e.toJSON().data)
441
- // log.info(tag,"error5: ",e.toJSON().code)
442
- if (e_6.response.data.message) {
443
- log.info(tag, "saving message! ");
444
- output_1.error = e_6.response.data.message;
445
- }
446
- else {
447
- output_1.error = e_6;
448
- }
449
- return [3 /*break*/, 6];
450
- case 6:
451
- log.info(tag, "output: ", output_1);
452
- return [2 /*return*/, output_1];
453
- case 7: return [4 /*yield*/, blockbook.broadcast(coin, tx)];
454
- case 8:
455
- responseBroadcast = _a.sent();
456
- log.info(tag, 'responseBroadcast: ', responseBroadcast);
457
- if (responseBroadcast.success && responseBroadcast.success !== false) {
458
- output.success = true;
459
- if (responseBroadcast.txid) {
460
- output.txid = responseBroadcast.resp.data.result;
461
- }
462
- if (responseBroadcast.resp.data.result) {
463
- output.txid = responseBroadcast.resp.data.result;
464
- }
465
- }
466
- else if (responseBroadcast.error) {
467
- output.error = responseBroadcast.error;
468
- }
469
- else {
470
- output.error = "unknown error";
471
- output.debug = responseBroadcast;
472
- }
473
- return [2 /*return*/, output];
474
- case 9: return [3 /*break*/, 11];
475
- case 10:
476
- e_7 = _a.sent();
477
- //TODO handle errors
478
- if (!output.error)
479
- output.error = e_7;
480
- return [2 /*return*/, output];
481
- case 11: return [3 /*break*/, 13];
482
- case 12:
483
- e_8 = _a.sent();
484
- console.error(tag, e_8);
485
- throw e_8;
486
- case 13: return [2 /*return*/];
509
+ console.error(tag, e_6);
510
+ throw e_6;
511
+ case 6: return [2 /*return*/];
487
512
  }
488
513
  });
489
514
  });
490
515
  };
491
516
  var get_balance_by_addresses = function (coin, addresses) {
492
517
  return __awaiter(this, void 0, void 0, function () {
493
- var tag, query, i, address, balanceInfo, e_9;
518
+ var tag, query, i, address, balanceInfo, e_7;
494
519
  return __generator(this, function (_a) {
495
520
  switch (_a.label) {
496
521
  case 0:
@@ -512,8 +537,8 @@ var get_balance_by_addresses = function (coin, addresses) {
512
537
  //https://blockchain.info/multiaddr?active=$address|$address
513
538
  return [2 /*return*/, balanceInfo.data];
514
539
  case 3:
515
- e_9 = _a.sent();
516
- console.error(tag, e_9);
540
+ e_7 = _a.sent();
541
+ console.error(tag, e_7);
517
542
  return [3 /*break*/, 4];
518
543
  case 4: return [2 /*return*/];
519
544
  }
@@ -522,7 +547,7 @@ var get_balance_by_addresses = function (coin, addresses) {
522
547
  };
523
548
  var get_balance_by_address = function (coin, address) {
524
549
  return __awaiter(this, void 0, void 0, function () {
525
- var tag, balanceInfo, e_10;
550
+ var tag, balanceInfo, e_8;
526
551
  return __generator(this, function (_a) {
527
552
  switch (_a.label) {
528
553
  case 0:
@@ -535,8 +560,8 @@ var get_balance_by_address = function (coin, address) {
535
560
  balanceInfo = _a.sent();
536
561
  return [2 /*return*/, balanceInfo.data.balance];
537
562
  case 3:
538
- e_10 = _a.sent();
539
- console.error(tag, e_10);
563
+ e_8 = _a.sent();
564
+ console.error(tag, e_8);
540
565
  return [3 /*break*/, 4];
541
566
  case 4: return [2 /*return*/];
542
567
  }
@@ -545,7 +570,7 @@ var get_balance_by_address = function (coin, address) {
545
570
  };
546
571
  var get_utxos_by_xpub = function (coin, xpub) {
547
572
  return __awaiter(this, void 0, void 0, function () {
548
- var tag, output, result, e_11;
573
+ var tag, output, result, e_9;
549
574
  return __generator(this, function (_a) {
550
575
  switch (_a.label) {
551
576
  case 0:
@@ -571,9 +596,9 @@ var get_utxos_by_xpub = function (coin, xpub) {
571
596
  _a.label = 4;
572
597
  case 4: return [2 /*return*/, output];
573
598
  case 5:
574
- e_11 = _a.sent();
575
- console.error(tag, e_11);
576
- throw e_11;
599
+ e_9 = _a.sent();
600
+ console.error(tag, e_9);
601
+ throw e_9;
577
602
  case 6: return [2 /*return*/];
578
603
  }
579
604
  });
@@ -581,7 +606,7 @@ var get_utxos_by_xpub = function (coin, xpub) {
581
606
  };
582
607
  var get_balance_by_xpub = function (coin, xpub) {
583
608
  return __awaiter(this, void 0, void 0, function () {
584
- var tag, output, balance, i, uxto, e_12;
609
+ var tag, output, balance, i, uxto, e_10;
585
610
  return __generator(this, function (_a) {
586
611
  switch (_a.label) {
587
612
  case 0:
@@ -601,8 +626,8 @@ var get_balance_by_xpub = function (coin, xpub) {
601
626
  }
602
627
  return [2 /*return*/, balance / 100000000];
603
628
  case 3:
604
- e_12 = _a.sent();
605
- console.error(tag, e_12);
629
+ e_10 = _a.sent();
630
+ console.error(tag, e_10);
606
631
  return [3 /*break*/, 4];
607
632
  case 4: return [2 /*return*/];
608
633
  }
@@ -611,7 +636,7 @@ var get_balance_by_xpub = function (coin, xpub) {
611
636
  };
612
637
  var get_block_hash = function (coin, height) {
613
638
  return __awaiter(this, void 0, void 0, function () {
614
- var tag, blockHash, e_13;
639
+ var tag, blockHash, e_11;
615
640
  return __generator(this, function (_a) {
616
641
  switch (_a.label) {
617
642
  case 0:
@@ -625,8 +650,8 @@ var get_block_hash = function (coin, height) {
625
650
  log.debug(tag, "blockHash: ", blockHash);
626
651
  return [2 /*return*/, blockHash];
627
652
  case 3:
628
- e_13 = _a.sent();
629
- console.error(tag, e_13);
653
+ e_11 = _a.sent();
654
+ console.error(tag, e_11);
630
655
  return [3 /*break*/, 4];
631
656
  case 4: return [2 /*return*/];
632
657
  }
@@ -635,7 +660,7 @@ var get_block_hash = function (coin, height) {
635
660
  };
636
661
  var get_transaction = function (coin, txid, format) {
637
662
  return __awaiter(this, void 0, void 0, function () {
638
- var tag, txInfo, output, e_14;
663
+ var tag, txInfo, output, e_12;
639
664
  return __generator(this, function (_a) {
640
665
  switch (_a.label) {
641
666
  case 0:
@@ -651,9 +676,9 @@ var get_transaction = function (coin, txid, format) {
651
676
  log.debug(tag, "output: ", output);
652
677
  return [2 /*return*/, output];
653
678
  case 3:
654
- e_14 = _a.sent();
655
- console.error(tag, 'Error: ', e_14);
656
- throw e_14;
679
+ e_12 = _a.sent();
680
+ console.error(tag, 'Error: ', e_12);
681
+ throw e_12;
657
682
  case 4: return [2 /*return*/];
658
683
  }
659
684
  });
@@ -787,7 +812,7 @@ var get_txs_by_xpubs = function (coin, xpub) {
787
812
  // }
788
813
  var get_block = function (coin, height) {
789
814
  return __awaiter(this, void 0, void 0, function () {
790
- var tag, blockHash, blockInfo, e_15;
815
+ var tag, blockHash, blockInfo, e_13;
791
816
  return __generator(this, function (_a) {
792
817
  switch (_a.label) {
793
818
  case 0:
@@ -806,8 +831,8 @@ var get_block = function (coin, height) {
806
831
  log.debug(tag, "blockInfo: ", blockInfo);
807
832
  return [2 /*return*/, blockInfo];
808
833
  case 4:
809
- e_15 = _a.sent();
810
- console.error(tag, e_15);
834
+ e_13 = _a.sent();
835
+ console.error(tag, e_13);
811
836
  return [3 /*break*/, 5];
812
837
  case 5: return [2 /*return*/];
813
838
  }
@@ -840,7 +865,7 @@ var get_block = function (coin, height) {
840
865
  // }
841
866
  var get_node_info = function (coin) {
842
867
  return __awaiter(this, void 0, void 0, function () {
843
- var tag, results, e_16;
868
+ var tag, results, e_14;
844
869
  return __generator(this, function (_a) {
845
870
  switch (_a.label) {
846
871
  case 0:
@@ -855,8 +880,8 @@ var get_node_info = function (coin) {
855
880
  results.coin = coin;
856
881
  return [2 /*return*/, results];
857
882
  case 3:
858
- e_16 = _a.sent();
859
- console.error(tag, e_16);
883
+ e_14 = _a.sent();
884
+ console.error(tag, e_14);
860
885
  return [3 /*break*/, 4];
861
886
  case 4: return [2 /*return*/];
862
887
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/utxo-network",
3
- "version": "8.1.62",
3
+ "version": "8.1.63",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {
@@ -32,5 +32,5 @@
32
32
  "ts-node": "^10.9.1",
33
33
  "typescript": "^5.0.2"
34
34
  },
35
- "gitHead": "8c626a669f7045d1eb9c00252d9a81845a57fa50"
35
+ "gitHead": "974ddd872e4595ebc78a4f983811303b9623cf82"
36
36
  }