@pioneer-platform/pioneer 8.2.13 → 8.2.16
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.d.ts +2 -2
- package/lib/index.js +125 -174
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -34,9 +34,9 @@ declare let get_and_verify_pubkeys: (username: string, context?: string) => Prom
|
|
|
34
34
|
}>;
|
|
35
35
|
declare let register_zpub: (username: string, pubkey: any, context: string) => Promise<any>;
|
|
36
36
|
declare let register_xpub: (username: string, pubkey: any, context: string) => Promise<{
|
|
37
|
-
|
|
37
|
+
nfts: any;
|
|
38
38
|
balances: any;
|
|
39
39
|
}>;
|
|
40
40
|
declare let register_address: (username: string, pubkey: any, context: string) => Promise<any>;
|
|
41
41
|
declare let update_pubkeys: (username: string, pubkeys: any, context: string) => Promise<any>;
|
|
42
|
-
declare const register_pubkeys: (username: string, pubkeys: any
|
|
42
|
+
declare const register_pubkeys: (username: string, pubkeys: any) => Promise<any>;
|
package/lib/index.js
CHANGED
|
@@ -165,10 +165,10 @@ module.exports = {
|
|
|
165
165
|
});
|
|
166
166
|
});
|
|
167
167
|
},
|
|
168
|
-
register: function (username, pubkeys
|
|
168
|
+
register: function (username, pubkeys) {
|
|
169
169
|
return __awaiter(this, void 0, void 0, function () {
|
|
170
170
|
return __generator(this, function (_a) {
|
|
171
|
-
return [2 /*return*/, register_pubkeys(username, pubkeys
|
|
171
|
+
return [2 /*return*/, register_pubkeys(username, pubkeys)];
|
|
172
172
|
});
|
|
173
173
|
});
|
|
174
174
|
},
|
|
@@ -235,14 +235,14 @@ function setInCache(key, data, expiration) {
|
|
|
235
235
|
var get_pubkey_balances = function (pubkey) {
|
|
236
236
|
var _a, _b;
|
|
237
237
|
return __awaiter(this, void 0, void 0, function () {
|
|
238
|
-
var tag, output, balances_1, nfts, positions, cacheKey, cachedData, balance, _c, cacheKeyZapper, cachedDataZapper, zapperInfo, cacheKeyAllPioneers, cachedAllPioneers, allPioneers, isPioneer, updatedUsername, pioneerImage, updatedUsername2, cacheKeyBlockbookInfo, cachedBlockbookInfo, blockbookInfo, cacheKeyNetwork, cachedDataNetwork, balanceNetwork, pubkeyInfo,
|
|
238
|
+
var tag, output, balances_1, nfts, positions, cacheKey, cachedData, balance, _c, cacheKeyZapper, cachedDataZapper, zapperInfo, cacheKeyAllPioneers, cachedAllPioneers, allPioneers, isPioneer, updatedUsername, pioneerImage, updatedUsername2, cacheKeyBlockbookInfo, cachedBlockbookInfo, blockbookInfo, cacheKeyNetwork, cachedDataNetwork, balanceNetwork, pubkeyInfo, _loop_1, i, e_2;
|
|
239
239
|
return __generator(this, function (_d) {
|
|
240
240
|
switch (_d.label) {
|
|
241
241
|
case 0:
|
|
242
242
|
tag = TAG + " | get_pubkey_balances | ";
|
|
243
243
|
_d.label = 1;
|
|
244
244
|
case 1:
|
|
245
|
-
_d.trys.push([1,
|
|
245
|
+
_d.trys.push([1, 35, , 36]);
|
|
246
246
|
output = {};
|
|
247
247
|
if (!pubkey.symbol && pubkey.asset)
|
|
248
248
|
pubkey.symbol = pubkey.asset;
|
|
@@ -497,102 +497,30 @@ var get_pubkey_balances = function (pubkey) {
|
|
|
497
497
|
log.debug(tag, "nfts: ", pubkeyInfo.nfts.length);
|
|
498
498
|
log.debug(tag, "balances: ", balances_1);
|
|
499
499
|
log.debug(tag, "balances: ", balances_1.length);
|
|
500
|
-
saveActions = [];
|
|
501
500
|
_loop_1 = function (i) {
|
|
502
|
-
var balance, balanceIndex, assetInfo;
|
|
503
|
-
var _e;
|
|
504
|
-
return __generator(this, function (_f) {
|
|
505
|
-
switch (_f.label) {
|
|
506
|
-
case 0:
|
|
507
|
-
balance = balances_1[i];
|
|
508
|
-
balanceIndex = pubkeyInfo.balances.findIndex(function (e) { return e.symbol === balance.symbol; });
|
|
509
|
-
return [4 /*yield*/, assetsDB.findOne({ symbol: balance.symbol })];
|
|
510
|
-
case 1:
|
|
511
|
-
assetInfo = _f.sent();
|
|
512
|
-
log.debug(tag, "assetInfo: ", assetInfo);
|
|
513
|
-
if (assetInfo) {
|
|
514
|
-
balance.caip = assetInfo.caip;
|
|
515
|
-
balance.image = assetInfo.image;
|
|
516
|
-
balance.assetCaip = assetInfo.caip;
|
|
517
|
-
balance.description = assetInfo.description;
|
|
518
|
-
balance.website = assetInfo.website;
|
|
519
|
-
balance.explorer = assetInfo.explorer;
|
|
520
|
-
balance.context = pubkey.context;
|
|
521
|
-
}
|
|
522
|
-
if (balanceIndex !== -1 && pubkeyInfo.balances[balanceIndex].balance !== balance.balance) {
|
|
523
|
-
saveActions.push({
|
|
524
|
-
updateOne: {
|
|
525
|
-
filter: { pubkey: pubkey.pubkey },
|
|
526
|
-
update: {
|
|
527
|
-
$set: (_e = {}, _e["balances.".concat(balanceIndex)] = balance, _e),
|
|
528
|
-
},
|
|
529
|
-
},
|
|
530
|
-
});
|
|
531
|
-
}
|
|
532
|
-
else {
|
|
533
|
-
log.debug(tag, pubkey.context + ": balance not changed! ", balance.symbol);
|
|
534
|
-
}
|
|
535
|
-
return [2 /*return*/];
|
|
536
|
-
}
|
|
537
|
-
});
|
|
538
|
-
};
|
|
539
|
-
i = 0;
|
|
540
|
-
_d.label = 35;
|
|
541
|
-
case 35:
|
|
542
|
-
if (!(i < balances_1.length)) return [3 /*break*/, 38];
|
|
543
|
-
return [5 /*yield**/, _loop_1(i)];
|
|
544
|
-
case 36:
|
|
545
|
-
_d.sent();
|
|
546
|
-
_d.label = 37;
|
|
547
|
-
case 37:
|
|
548
|
-
i++;
|
|
549
|
-
return [3 /*break*/, 35];
|
|
550
|
-
case 38:
|
|
551
|
-
_loop_2 = function (i) {
|
|
552
501
|
var nft = nfts[i];
|
|
553
502
|
log.debug(tag, "pubkeyInfo.nfts: ", pubkeyInfo.nfts.length);
|
|
554
503
|
var existingNft = pubkeyInfo.nfts.find(function (e) { return e.name === nft.name; });
|
|
555
|
-
if (!existingNft) {
|
|
556
|
-
saveActions.push({
|
|
557
|
-
updateOne: {
|
|
558
|
-
filter: { pubkey: pubkey.pubkey },
|
|
559
|
-
update: {
|
|
560
|
-
$addToSet: { nfts: nft }
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
504
|
};
|
|
566
505
|
for (i = 0; i < nfts.length; i++) {
|
|
567
|
-
|
|
506
|
+
_loop_1(i);
|
|
568
507
|
}
|
|
569
|
-
if (!(saveActions.length > 0)) return [3 /*break*/, 40];
|
|
570
|
-
return [4 /*yield*/, pubkeysDB.bulkWrite(saveActions, { ordered: false })];
|
|
571
|
-
case 39:
|
|
572
|
-
updateSuccess = _d.sent();
|
|
573
|
-
log.debug(tag, "updateSuccess: ", updateSuccess);
|
|
574
|
-
output.dbUpdate = updateSuccess;
|
|
575
|
-
_d.label = 40;
|
|
576
|
-
case 40:
|
|
577
|
-
//@TODO save transactions
|
|
578
|
-
// Build output
|
|
579
|
-
output.pubkeys = [pubkeyInfo];
|
|
580
508
|
output.balances = balances_1;
|
|
581
509
|
output.nfts = nfts;
|
|
582
510
|
output.success = true;
|
|
583
511
|
return [2 /*return*/, output];
|
|
584
|
-
case
|
|
512
|
+
case 35:
|
|
585
513
|
e_2 = _d.sent();
|
|
586
514
|
console.error(tag, "e: ", e_2);
|
|
587
515
|
throw e_2;
|
|
588
|
-
case
|
|
516
|
+
case 36: return [2 /*return*/];
|
|
589
517
|
}
|
|
590
518
|
});
|
|
591
519
|
});
|
|
592
520
|
};
|
|
593
521
|
var get_and_rescan_pubkeys = function (username) {
|
|
594
522
|
return __awaiter(this, void 0, void 0, function () {
|
|
595
|
-
var tag, pubkeysMongo, userInfo, blockchains, pubkeys, masters, i, pubkeyInfo,
|
|
523
|
+
var tag, pubkeysMongo, userInfo, blockchains, pubkeys, masters, i, pubkeyInfo, _loop_2, j, e_3;
|
|
596
524
|
return __generator(this, function (_a) {
|
|
597
525
|
switch (_a.label) {
|
|
598
526
|
case 0:
|
|
@@ -618,7 +546,7 @@ var get_and_rescan_pubkeys = function (username) {
|
|
|
618
546
|
for (i = 0; i < pubkeysMongo.length; i++) {
|
|
619
547
|
pubkeyInfo = pubkeysMongo[i];
|
|
620
548
|
delete pubkeyInfo._id;
|
|
621
|
-
|
|
549
|
+
_loop_2 = function (j) {
|
|
622
550
|
var context = userInfo.wallets[i];
|
|
623
551
|
if (pubkeyInfo.type === 'zpub') {
|
|
624
552
|
//if context found in tags
|
|
@@ -642,7 +570,7 @@ var get_and_rescan_pubkeys = function (username) {
|
|
|
642
570
|
};
|
|
643
571
|
//for each wallet by user
|
|
644
572
|
for (j = 0; j < userInfo.wallets.length; j++) {
|
|
645
|
-
|
|
573
|
+
_loop_2(j);
|
|
646
574
|
}
|
|
647
575
|
}
|
|
648
576
|
return [2 /*return*/, { pubkeys: pubkeys, masters: masters }];
|
|
@@ -797,7 +725,7 @@ var register_zpub = function (username, pubkey, context) {
|
|
|
797
725
|
case 3:
|
|
798
726
|
result = _a.sent();
|
|
799
727
|
log.debug(result);
|
|
800
|
-
return [2 /*return*/,
|
|
728
|
+
return [2 /*return*/, result];
|
|
801
729
|
case 4:
|
|
802
730
|
e_5 = _a.sent();
|
|
803
731
|
console.error(tag, "e: ", e_5);
|
|
@@ -809,7 +737,7 @@ var register_zpub = function (username, pubkey, context) {
|
|
|
809
737
|
};
|
|
810
738
|
var register_xpub = function (username, pubkey, context) {
|
|
811
739
|
return __awaiter(this, void 0, void 0, function () {
|
|
812
|
-
var tag, queueId, account, index, address, work, _a,
|
|
740
|
+
var tag, queueId, account, index, address, work, _a, balances, nfts, e_6;
|
|
813
741
|
return __generator(this, function (_b) {
|
|
814
742
|
switch (_b.label) {
|
|
815
743
|
case 0:
|
|
@@ -853,10 +781,9 @@ var register_xpub = function (username, pubkey, context) {
|
|
|
853
781
|
queue.createWork("pioneer:pubkey:ingest", work);
|
|
854
782
|
return [4 /*yield*/, get_pubkey_balances(work)];
|
|
855
783
|
case 3:
|
|
856
|
-
_a = _b.sent(),
|
|
857
|
-
log.
|
|
858
|
-
|
|
859
|
-
return [2 /*return*/, { pubkeys: pubkeys, balances: balances }];
|
|
784
|
+
_a = _b.sent(), balances = _a.balances, nfts = _a.nfts;
|
|
785
|
+
log.info(tag, "balances: ", balances.length);
|
|
786
|
+
return [2 /*return*/, { nfts: nfts, balances: balances }];
|
|
860
787
|
case 4:
|
|
861
788
|
e_6 = _b.sent();
|
|
862
789
|
console.error(tag, "e: ", e_6);
|
|
@@ -898,7 +825,7 @@ var register_address = function (username, pubkey, context) {
|
|
|
898
825
|
case 2:
|
|
899
826
|
result = _a.sent();
|
|
900
827
|
log.debug(tag, "result: ", result);
|
|
901
|
-
return [2 /*return*/,
|
|
828
|
+
return [2 /*return*/, result];
|
|
902
829
|
case 3:
|
|
903
830
|
e_7 = _a.sent();
|
|
904
831
|
console.error(tag, "e: ", e_7);
|
|
@@ -911,14 +838,13 @@ var register_address = function (username, pubkey, context) {
|
|
|
911
838
|
var update_pubkeys = function (username, pubkeys, context) {
|
|
912
839
|
return __awaiter(this, void 0, void 0, function () {
|
|
913
840
|
var tag, saveActions, output, allPubkeys, PubkeyMap, i, pubkeyInfo, allBalances, allKnownPubkeys, knownPubkeys_1, i, unknown, i, pubkey, pubkeyInfo, nativeAsset, entryMongo, result, result, result, keyExists, pushTagMongo, resultSave, e_8;
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
switch (_d.label) {
|
|
841
|
+
return __generator(this, function (_a) {
|
|
842
|
+
switch (_a.label) {
|
|
917
843
|
case 0:
|
|
918
844
|
tag = TAG + " | update_pubkeys | ";
|
|
919
|
-
|
|
845
|
+
_a.label = 1;
|
|
920
846
|
case 1:
|
|
921
|
-
|
|
847
|
+
_a.trys.push([1, 20, , 21]);
|
|
922
848
|
log.debug(tag, "input: ", { username: username, pubkeys: pubkeys, context: context });
|
|
923
849
|
saveActions = [];
|
|
924
850
|
output = {};
|
|
@@ -937,7 +863,7 @@ var update_pubkeys = function (username, pubkeys, context) {
|
|
|
937
863
|
log.debug(tag, "allPubkeys: ", allPubkeys);
|
|
938
864
|
return [4 /*yield*/, pubkeysDB.find({ "pubkey": { "$in": allPubkeys } })];
|
|
939
865
|
case 2:
|
|
940
|
-
allKnownPubkeys =
|
|
866
|
+
allKnownPubkeys = _a.sent();
|
|
941
867
|
log.debug(tag, "allKnownPubkeys: ", allKnownPubkeys.length);
|
|
942
868
|
knownPubkeys_1 = [];
|
|
943
869
|
for (i = 0; i < allKnownPubkeys.length; i++) {
|
|
@@ -950,7 +876,7 @@ var update_pubkeys = function (username, pubkeys, context) {
|
|
|
950
876
|
log.debug(tag, "unknown: ", unknown);
|
|
951
877
|
log.debug(tag, "Registering pubkeys : ", unknown.length);
|
|
952
878
|
i = 0;
|
|
953
|
-
|
|
879
|
+
_a.label = 3;
|
|
954
880
|
case 3:
|
|
955
881
|
if (!(i < unknown.length)) return [3 /*break*/, 17];
|
|
956
882
|
pubkey = unknown[i];
|
|
@@ -1000,10 +926,9 @@ var update_pubkeys = function (username, pubkeys, context) {
|
|
|
1000
926
|
saveActions.push({ insertOne: entryMongo });
|
|
1001
927
|
return [4 /*yield*/, register_xpub(username, pubkeyInfo, context)];
|
|
1002
928
|
case 4:
|
|
1003
|
-
result =
|
|
929
|
+
result = _a.sent();
|
|
1004
930
|
entryMongo.balances = result.balances;
|
|
1005
931
|
allBalances.push.apply(allBalances, result.balances);
|
|
1006
|
-
(_a = output.pubkeys).push.apply(_a, result.pubkeys);
|
|
1007
932
|
return [3 /*break*/, 10];
|
|
1008
933
|
case 5:
|
|
1009
934
|
if (!(pubkeyInfo.type === "zpub" || pubkeyInfo.zpub)) return [3 /*break*/, 7];
|
|
@@ -1017,35 +942,33 @@ var update_pubkeys = function (username, pubkeys, context) {
|
|
|
1017
942
|
saveActions.push({ insertOne: entryMongo });
|
|
1018
943
|
return [4 /*yield*/, register_zpub(username, pubkeyInfo, context)];
|
|
1019
944
|
case 6:
|
|
1020
|
-
result =
|
|
945
|
+
result = _a.sent();
|
|
1021
946
|
entryMongo.balances = result.balances;
|
|
1022
947
|
allBalances.push.apply(allBalances, result.balances);
|
|
1023
|
-
(_b = output.pubkeys).push.apply(_b, result.pubkeys);
|
|
1024
948
|
return [3 /*break*/, 10];
|
|
1025
949
|
case 7:
|
|
1026
950
|
if (!(pubkeyInfo.type === "address")) return [3 /*break*/, 9];
|
|
1027
951
|
entryMongo.pubkey = pubkeyInfo.pubkey;
|
|
1028
952
|
return [4 /*yield*/, register_address(username, pubkeyInfo, context)];
|
|
1029
953
|
case 8:
|
|
1030
|
-
result =
|
|
954
|
+
result = _a.sent();
|
|
1031
955
|
entryMongo.balances = result.balances;
|
|
1032
956
|
allBalances.push.apply(allBalances, result.balances);
|
|
1033
|
-
(_c = output.pubkeys).push.apply(_c, result.pubkeys);
|
|
1034
957
|
return [3 /*break*/, 10];
|
|
1035
958
|
case 9:
|
|
1036
959
|
log.error("Unhandled type: ", pubkeyInfo.type);
|
|
1037
|
-
|
|
960
|
+
_a.label = 10;
|
|
1038
961
|
case 10:
|
|
1039
962
|
//verify write
|
|
1040
963
|
log.debug(tag, "entryMongo: ", entryMongo);
|
|
1041
964
|
return [4 /*yield*/, pubkeysDB.findOne({ pubkey: entryMongo.pubkey })];
|
|
1042
965
|
case 11:
|
|
1043
|
-
keyExists =
|
|
966
|
+
keyExists = _a.sent();
|
|
1044
967
|
if (!keyExists) return [3 /*break*/, 13];
|
|
1045
968
|
log.debug(tag, "Key already registered! key: ", entryMongo);
|
|
1046
969
|
return [4 /*yield*/, pubkeysDB.update({ pubkey: entryMongo.pubkey }, { $addToSet: { tags: { $each: [context, username] } } })];
|
|
1047
970
|
case 12:
|
|
1048
|
-
pushTagMongo =
|
|
971
|
+
pushTagMongo = _a.sent();
|
|
1049
972
|
log.debug(tag, "pushTagMongo: ", pushTagMongo);
|
|
1050
973
|
return [3 /*break*/, 16];
|
|
1051
974
|
case 13:
|
|
@@ -1055,16 +978,16 @@ var update_pubkeys = function (username, pubkeys, context) {
|
|
|
1055
978
|
throw Error("105: unable to save invalid pubkey!");
|
|
1056
979
|
case 14: return [4 /*yield*/, pubkeysDB.insert(entryMongo)];
|
|
1057
980
|
case 15:
|
|
1058
|
-
resultSave =
|
|
981
|
+
resultSave = _a.sent();
|
|
1059
982
|
log.debug(tag, "resultSave: ", resultSave);
|
|
1060
|
-
|
|
983
|
+
_a.label = 16;
|
|
1061
984
|
case 16:
|
|
1062
985
|
i++;
|
|
1063
986
|
return [3 /*break*/, 3];
|
|
1064
987
|
case 17: return [3 /*break*/, 19];
|
|
1065
988
|
case 18:
|
|
1066
989
|
log.debug(tag, " No new pubkeys! ");
|
|
1067
|
-
|
|
990
|
+
_a.label = 19;
|
|
1068
991
|
case 19:
|
|
1069
992
|
log.debug(tag, "output: ", output);
|
|
1070
993
|
if (allBalances.length === 0) {
|
|
@@ -1075,7 +998,7 @@ var update_pubkeys = function (username, pubkeys, context) {
|
|
|
1075
998
|
log.debug(tag, " return object: ", output);
|
|
1076
999
|
return [2 /*return*/, output];
|
|
1077
1000
|
case 20:
|
|
1078
|
-
e_8 =
|
|
1001
|
+
e_8 = _a.sent();
|
|
1079
1002
|
console.error(tag, "e: ", e_8);
|
|
1080
1003
|
throw e_8;
|
|
1081
1004
|
case 21: return [2 /*return*/];
|
|
@@ -1083,29 +1006,40 @@ var update_pubkeys = function (username, pubkeys, context) {
|
|
|
1083
1006
|
});
|
|
1084
1007
|
});
|
|
1085
1008
|
};
|
|
1086
|
-
|
|
1009
|
+
/*
|
|
1010
|
+
Rules:
|
|
1011
|
+
|
|
1012
|
+
only go to network if no pubkey exists
|
|
1013
|
+
|
|
1014
|
+
do not sync balances here (we only sync balances on context change)
|
|
1015
|
+
|
|
1016
|
+
*/
|
|
1017
|
+
var register_pubkeys = function (username, pubkeys) {
|
|
1087
1018
|
return __awaiter(this, void 0, void 0, function () {
|
|
1088
|
-
var tag, saveActions, allBalances, output, i, pubkeyInfo, nativeAsset, entryMongo, xpub, result, zpub, result, result,
|
|
1089
|
-
var _a, _b
|
|
1090
|
-
return __generator(this, function (
|
|
1091
|
-
switch (
|
|
1019
|
+
var tag, saveActions, allBalances, output, i, pubkeyInfo, nativeAsset, pubkeyExists, entryMongo, xpub, result, zpub, result, result, action, pushTagMongo, saveMongoBulk, allPubkeys, i, pubkeyInfo, e_9;
|
|
1020
|
+
var _a, _b;
|
|
1021
|
+
return __generator(this, function (_c) {
|
|
1022
|
+
switch (_c.label) {
|
|
1092
1023
|
case 0:
|
|
1093
1024
|
tag = TAG + " | register_pubkeys | ";
|
|
1094
|
-
|
|
1025
|
+
_c.label = 1;
|
|
1095
1026
|
case 1:
|
|
1096
|
-
|
|
1097
|
-
log.debug(tag, "input: ", { username: username, pubkeys: pubkeys
|
|
1027
|
+
_c.trys.push([1, 18, , 19]);
|
|
1028
|
+
log.debug(tag, "input: ", { username: username, pubkeys: pubkeys });
|
|
1098
1029
|
saveActions = [];
|
|
1099
1030
|
allBalances = [];
|
|
1100
1031
|
output = {};
|
|
1101
1032
|
output.pubkeys = [];
|
|
1102
1033
|
output.balances = [];
|
|
1034
|
+
output.nfts = [];
|
|
1103
1035
|
i = 0;
|
|
1104
|
-
|
|
1036
|
+
_c.label = 2;
|
|
1105
1037
|
case 2:
|
|
1106
|
-
if (!(i < pubkeys.length)) return [3 /*break*/,
|
|
1038
|
+
if (!(i < pubkeys.length)) return [3 /*break*/, 14];
|
|
1107
1039
|
pubkeyInfo = pubkeys[i];
|
|
1108
1040
|
log.debug(tag, "pubkeyInfo: ", pubkeyInfo);
|
|
1041
|
+
if (!pubkeyInfo.blockchain)
|
|
1042
|
+
throw Error("Invalid pubkey required field: blockchain");
|
|
1109
1043
|
nativeAsset = getNativeAssetForBlockchain(pubkeyInfo.blockchain);
|
|
1110
1044
|
if (!nativeAsset)
|
|
1111
1045
|
throw Error("104: invalid pubkey! unsupported by coins module!");
|
|
@@ -1113,19 +1047,23 @@ var register_pubkeys = function (username, pubkeys, context) {
|
|
|
1113
1047
|
throw Error("104: invalid pubkey! missing pubkey!");
|
|
1114
1048
|
if (!pubkeyInfo.type)
|
|
1115
1049
|
throw Error("104: invalid pubkey! missing type!");
|
|
1116
|
-
//TODO verify type is in enums
|
|
1117
|
-
//hack
|
|
1118
1050
|
if (!pubkeyInfo.symbol)
|
|
1119
1051
|
pubkeyInfo.symbol = nativeAsset;
|
|
1120
|
-
log.debug(tag, "pubkeyInfo: ", pubkeyInfo);
|
|
1121
|
-
if (!pubkeyInfo.blockchain)
|
|
1122
|
-
throw Error("Invalid pubkey required field: blockchain");
|
|
1123
1052
|
if (!pubkeyInfo.script_type)
|
|
1124
1053
|
throw Error("Invalid pubkey required field: script_type coin:" + pubkeyInfo.blockchain);
|
|
1125
1054
|
if (!pubkeyInfo.network)
|
|
1126
1055
|
throw Error("Invalid pubkey required field: network coin:" + pubkeyInfo.blockchain);
|
|
1127
1056
|
if (!pubkeyInfo.master)
|
|
1128
1057
|
throw Error("Invalid pubkey required field: master coin:" + pubkeyInfo.blockchain);
|
|
1058
|
+
if (!pubkeyInfo.path)
|
|
1059
|
+
throw Error("Invalid pubkey required field: path coin:" + pubkeyInfo.blockchain);
|
|
1060
|
+
if (!pubkeyInfo.context)
|
|
1061
|
+
throw Error("Invalid pubkey required field: context:" + pubkeyInfo.blockchain);
|
|
1062
|
+
return [4 /*yield*/, pubkeysDB.findOne({ pubkey: pubkeyInfo.pubkey })];
|
|
1063
|
+
case 3:
|
|
1064
|
+
pubkeyExists = _c.sent();
|
|
1065
|
+
log.info(tag, "pubkeyExists: ", pubkeyExists);
|
|
1066
|
+
if (!!pubkeyExists) return [3 /*break*/, 11];
|
|
1129
1067
|
entryMongo = {
|
|
1130
1068
|
pubkey: pubkeyInfo.pubkey,
|
|
1131
1069
|
type: pubkeyInfo.type,
|
|
@@ -1137,9 +1075,9 @@ var register_pubkeys = function (username, pubkeys, context) {
|
|
|
1137
1075
|
script_type: pubkeyInfo.script_type,
|
|
1138
1076
|
network: pubkeyInfo.blockchain,
|
|
1139
1077
|
created: new Date().getTime(),
|
|
1140
|
-
tags: [username, pubkeyInfo.blockchain, pubkeyInfo.symbol, pubkeyInfo.network, context],
|
|
1078
|
+
tags: [username, pubkeyInfo.blockchain, pubkeyInfo.symbol, pubkeyInfo.network, pubkeyInfo.context],
|
|
1141
1079
|
};
|
|
1142
|
-
if (!(pubkeyInfo.type === "xpub")) return [3 /*break*/,
|
|
1080
|
+
if (!(pubkeyInfo.type === "xpub")) return [3 /*break*/, 5];
|
|
1143
1081
|
log.debug(tag, "pubkeyInfo: ", pubkeyInfo);
|
|
1144
1082
|
xpub = pubkeyInfo.pubkey;
|
|
1145
1083
|
log.debug(tag, "xpub: ", xpub);
|
|
@@ -1148,78 +1086,91 @@ var register_pubkeys = function (username, pubkeys, context) {
|
|
|
1148
1086
|
entryMongo.type = 'xpub';
|
|
1149
1087
|
entryMongo.master = pubkeyInfo.address;
|
|
1150
1088
|
entryMongo.address = pubkeyInfo.address;
|
|
1151
|
-
return [4 /*yield*/, register_xpub(username, pubkeyInfo, context)];
|
|
1152
|
-
case 3:
|
|
1153
|
-
result = _d.sent();
|
|
1154
|
-
allBalances.push.apply(allBalances, result.balances);
|
|
1155
|
-
(_a = output.pubkeys).push.apply(_a, result.pubkeys);
|
|
1156
|
-
return [3 /*break*/, 9];
|
|
1089
|
+
return [4 /*yield*/, register_xpub(username, pubkeyInfo, pubkeyInfo.context)];
|
|
1157
1090
|
case 4:
|
|
1158
|
-
|
|
1091
|
+
result = _c.sent();
|
|
1092
|
+
entryMongo.balances = result.balances;
|
|
1093
|
+
allBalances.push.apply(allBalances, result.balances);
|
|
1094
|
+
return [3 /*break*/, 10];
|
|
1095
|
+
case 5:
|
|
1096
|
+
if (!(pubkeyInfo.type === "zpub")) return [3 /*break*/, 7];
|
|
1159
1097
|
zpub = pubkeyInfo.pubkey;
|
|
1160
1098
|
entryMongo.pubkey = zpub;
|
|
1161
1099
|
entryMongo.zpub = zpub;
|
|
1162
1100
|
entryMongo.type = 'zpub';
|
|
1163
1101
|
entryMongo.master = pubkeyInfo.address;
|
|
1164
1102
|
entryMongo.address = pubkeyInfo.address;
|
|
1165
|
-
return [4 /*yield*/, register_xpub(username, pubkeyInfo, context)];
|
|
1166
|
-
case 5:
|
|
1167
|
-
result = _d.sent();
|
|
1168
|
-
allBalances.push.apply(allBalances, result.balances);
|
|
1169
|
-
(_b = output.pubkeys).push.apply(_b, result.pubkeys);
|
|
1170
|
-
return [3 /*break*/, 9];
|
|
1103
|
+
return [4 /*yield*/, register_xpub(username, pubkeyInfo, pubkeyInfo.context)];
|
|
1171
1104
|
case 6:
|
|
1172
|
-
|
|
1105
|
+
result = _c.sent();
|
|
1106
|
+
entryMongo.balances = result.balances;
|
|
1107
|
+
allBalances.push.apply(allBalances, result.balances);
|
|
1108
|
+
return [3 /*break*/, 10];
|
|
1109
|
+
case 7:
|
|
1110
|
+
if (!(pubkeyInfo.type === "address")) return [3 /*break*/, 9];
|
|
1173
1111
|
entryMongo.pubkey = pubkeyInfo.pubkey;
|
|
1174
1112
|
entryMongo.master = pubkeyInfo.pubkey;
|
|
1175
1113
|
entryMongo.type = pubkeyInfo.type;
|
|
1176
1114
|
entryMongo.address = pubkeyInfo.address;
|
|
1177
|
-
return [4 /*yield*/, register_address(username, pubkeyInfo, context)];
|
|
1178
|
-
case 7:
|
|
1179
|
-
result = _d.sent();
|
|
1180
|
-
allBalances.push.apply(allBalances, result.balances);
|
|
1181
|
-
(_c = output.pubkeys).push.apply(_c, result.pubkeys);
|
|
1182
|
-
return [3 /*break*/, 9];
|
|
1115
|
+
return [4 /*yield*/, register_address(username, pubkeyInfo, pubkeyInfo.context)];
|
|
1183
1116
|
case 8:
|
|
1184
|
-
|
|
1185
|
-
|
|
1117
|
+
result = _c.sent();
|
|
1118
|
+
entryMongo.balances = result.balances;
|
|
1119
|
+
allBalances.push.apply(allBalances, result.balances);
|
|
1120
|
+
return [3 /*break*/, 10];
|
|
1186
1121
|
case 9:
|
|
1122
|
+
log.error(tag, "Unhandled type: ", pubkeyInfo.type);
|
|
1123
|
+
_c.label = 10;
|
|
1124
|
+
case 10:
|
|
1187
1125
|
//verify write
|
|
1188
|
-
log.
|
|
1126
|
+
log.info(tag, "entryMongo: ", entryMongo);
|
|
1189
1127
|
if (!entryMongo.pubkey)
|
|
1190
1128
|
throw Error("103: Invalid pubkey! can not save!");
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1129
|
+
if (!entryMongo.balances)
|
|
1130
|
+
throw Error("103: Invalid pubkey! no balances set!");
|
|
1131
|
+
action = {
|
|
1132
|
+
insertOne: entryMongo
|
|
1133
|
+
};
|
|
1134
|
+
log.info(tag, "action: ", action);
|
|
1135
|
+
saveActions.push(action);
|
|
1136
|
+
return [3 /*break*/, 13];
|
|
1197
1137
|
case 11:
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
return [3 /*break*/, 15];
|
|
1138
|
+
if (!(pubkeyExists.indexOf(username) === -1)) return [3 /*break*/, 13];
|
|
1139
|
+
return [4 /*yield*/, pubkeysDB.update({ pubkey: pubkeyInfo.pubkey }, { $addToSet: { tags: { $each: [username] } } })];
|
|
1201
1140
|
case 12:
|
|
1202
|
-
|
|
1203
|
-
log.
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
case 13: return [4 /*yield*/, pubkeysDB.insert(entryMongo)];
|
|
1207
|
-
case 14:
|
|
1208
|
-
saveMongo = _d.sent();
|
|
1209
|
-
log.debug(tag, "saveMongo: ", saveMongo);
|
|
1210
|
-
_d.label = 15;
|
|
1211
|
-
case 15:
|
|
1141
|
+
pushTagMongo = _c.sent();
|
|
1142
|
+
log.info(tag, "pushTagMongo: ", pushTagMongo);
|
|
1143
|
+
_c.label = 13;
|
|
1144
|
+
case 13:
|
|
1212
1145
|
i++;
|
|
1213
1146
|
return [3 /*break*/, 2];
|
|
1214
|
-
case
|
|
1215
|
-
|
|
1216
|
-
log.
|
|
1217
|
-
return [
|
|
1147
|
+
case 14:
|
|
1148
|
+
//bulk write to mongo
|
|
1149
|
+
log.info(tag, "saveActions: ", saveActions);
|
|
1150
|
+
if (!(saveActions.length > 0)) return [3 /*break*/, 16];
|
|
1151
|
+
return [4 /*yield*/, pubkeysDB.bulkWrite(saveActions, { ordered: false })];
|
|
1152
|
+
case 15:
|
|
1153
|
+
saveMongoBulk = _c.sent();
|
|
1154
|
+
log.info(tag, "saveMongoBulk: ", saveMongoBulk);
|
|
1155
|
+
_c.label = 16;
|
|
1156
|
+
case 16: return [4 /*yield*/, pubkeysDB.find({ tags: { $in: [username] } })];
|
|
1218
1157
|
case 17:
|
|
1219
|
-
|
|
1158
|
+
allPubkeys = _c.sent();
|
|
1159
|
+
log.info(tag, "allPubkeys: ", allPubkeys.length);
|
|
1160
|
+
//get all balances for username
|
|
1161
|
+
for (i = 0; i < allPubkeys.length; i++) {
|
|
1162
|
+
pubkeyInfo = allPubkeys[i];
|
|
1163
|
+
if (pubkeyInfo.balances)
|
|
1164
|
+
(_a = output.balances).push.apply(_a, pubkeyInfo.balances);
|
|
1165
|
+
if (pubkeyInfo.nfts)
|
|
1166
|
+
(_b = output.nfts).push.apply(_b, pubkeyInfo.nfts);
|
|
1167
|
+
}
|
|
1168
|
+
return [2 /*return*/, output];
|
|
1169
|
+
case 18:
|
|
1170
|
+
e_9 = _c.sent();
|
|
1220
1171
|
console.error(tag, "e: ", e_9);
|
|
1221
1172
|
throw e_9;
|
|
1222
|
-
case
|
|
1173
|
+
case 19: return [2 /*return*/];
|
|
1223
1174
|
}
|
|
1224
1175
|
});
|
|
1225
1176
|
});
|