@pioneer-platform/pioneer 8.2.15 → 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 CHANGED
@@ -34,7 +34,7 @@ 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
- pubkeys: any;
37
+ nfts: any;
38
38
  balances: any;
39
39
  }>;
40
40
  declare let register_address: (username: string, pubkey: any, context: string) => Promise<any>;
package/lib/index.js CHANGED
@@ -737,7 +737,7 @@ var register_zpub = function (username, pubkey, context) {
737
737
  };
738
738
  var register_xpub = function (username, pubkey, context) {
739
739
  return __awaiter(this, void 0, void 0, function () {
740
- var tag, queueId, account, index, address, work, _a, pubkeys, balances, e_6;
740
+ var tag, queueId, account, index, address, work, _a, balances, nfts, e_6;
741
741
  return __generator(this, function (_b) {
742
742
  switch (_b.label) {
743
743
  case 0:
@@ -781,10 +781,9 @@ var register_xpub = function (username, pubkey, context) {
781
781
  queue.createWork("pioneer:pubkey:ingest", work);
782
782
  return [4 /*yield*/, get_pubkey_balances(work)];
783
783
  case 3:
784
- _a = _b.sent(), pubkeys = _a.pubkeys, balances = _a.balances;
785
- log.debug(tag, "pubkeys: ", pubkeys.length);
786
- log.debug(tag, "balances: ", balances.length);
787
- 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 }];
788
787
  case 4:
789
788
  e_6 = _b.sent();
790
789
  console.error(tag, "e: ", e_6);
@@ -839,14 +838,13 @@ var register_address = function (username, pubkey, context) {
839
838
  var update_pubkeys = function (username, pubkeys, context) {
840
839
  return __awaiter(this, void 0, void 0, function () {
841
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;
842
- var _a, _b, _c;
843
- return __generator(this, function (_d) {
844
- switch (_d.label) {
841
+ return __generator(this, function (_a) {
842
+ switch (_a.label) {
845
843
  case 0:
846
844
  tag = TAG + " | update_pubkeys | ";
847
- _d.label = 1;
845
+ _a.label = 1;
848
846
  case 1:
849
- _d.trys.push([1, 20, , 21]);
847
+ _a.trys.push([1, 20, , 21]);
850
848
  log.debug(tag, "input: ", { username: username, pubkeys: pubkeys, context: context });
851
849
  saveActions = [];
852
850
  output = {};
@@ -865,7 +863,7 @@ var update_pubkeys = function (username, pubkeys, context) {
865
863
  log.debug(tag, "allPubkeys: ", allPubkeys);
866
864
  return [4 /*yield*/, pubkeysDB.find({ "pubkey": { "$in": allPubkeys } })];
867
865
  case 2:
868
- allKnownPubkeys = _d.sent();
866
+ allKnownPubkeys = _a.sent();
869
867
  log.debug(tag, "allKnownPubkeys: ", allKnownPubkeys.length);
870
868
  knownPubkeys_1 = [];
871
869
  for (i = 0; i < allKnownPubkeys.length; i++) {
@@ -878,7 +876,7 @@ var update_pubkeys = function (username, pubkeys, context) {
878
876
  log.debug(tag, "unknown: ", unknown);
879
877
  log.debug(tag, "Registering pubkeys : ", unknown.length);
880
878
  i = 0;
881
- _d.label = 3;
879
+ _a.label = 3;
882
880
  case 3:
883
881
  if (!(i < unknown.length)) return [3 /*break*/, 17];
884
882
  pubkey = unknown[i];
@@ -928,10 +926,9 @@ var update_pubkeys = function (username, pubkeys, context) {
928
926
  saveActions.push({ insertOne: entryMongo });
929
927
  return [4 /*yield*/, register_xpub(username, pubkeyInfo, context)];
930
928
  case 4:
931
- result = _d.sent();
929
+ result = _a.sent();
932
930
  entryMongo.balances = result.balances;
933
931
  allBalances.push.apply(allBalances, result.balances);
934
- (_a = output.pubkeys).push.apply(_a, result.pubkeys);
935
932
  return [3 /*break*/, 10];
936
933
  case 5:
937
934
  if (!(pubkeyInfo.type === "zpub" || pubkeyInfo.zpub)) return [3 /*break*/, 7];
@@ -945,35 +942,33 @@ var update_pubkeys = function (username, pubkeys, context) {
945
942
  saveActions.push({ insertOne: entryMongo });
946
943
  return [4 /*yield*/, register_zpub(username, pubkeyInfo, context)];
947
944
  case 6:
948
- result = _d.sent();
945
+ result = _a.sent();
949
946
  entryMongo.balances = result.balances;
950
947
  allBalances.push.apply(allBalances, result.balances);
951
- (_b = output.pubkeys).push.apply(_b, result.pubkeys);
952
948
  return [3 /*break*/, 10];
953
949
  case 7:
954
950
  if (!(pubkeyInfo.type === "address")) return [3 /*break*/, 9];
955
951
  entryMongo.pubkey = pubkeyInfo.pubkey;
956
952
  return [4 /*yield*/, register_address(username, pubkeyInfo, context)];
957
953
  case 8:
958
- result = _d.sent();
954
+ result = _a.sent();
959
955
  entryMongo.balances = result.balances;
960
956
  allBalances.push.apply(allBalances, result.balances);
961
- (_c = output.pubkeys).push.apply(_c, result.pubkeys);
962
957
  return [3 /*break*/, 10];
963
958
  case 9:
964
959
  log.error("Unhandled type: ", pubkeyInfo.type);
965
- _d.label = 10;
960
+ _a.label = 10;
966
961
  case 10:
967
962
  //verify write
968
963
  log.debug(tag, "entryMongo: ", entryMongo);
969
964
  return [4 /*yield*/, pubkeysDB.findOne({ pubkey: entryMongo.pubkey })];
970
965
  case 11:
971
- keyExists = _d.sent();
966
+ keyExists = _a.sent();
972
967
  if (!keyExists) return [3 /*break*/, 13];
973
968
  log.debug(tag, "Key already registered! key: ", entryMongo);
974
969
  return [4 /*yield*/, pubkeysDB.update({ pubkey: entryMongo.pubkey }, { $addToSet: { tags: { $each: [context, username] } } })];
975
970
  case 12:
976
- pushTagMongo = _d.sent();
971
+ pushTagMongo = _a.sent();
977
972
  log.debug(tag, "pushTagMongo: ", pushTagMongo);
978
973
  return [3 /*break*/, 16];
979
974
  case 13:
@@ -983,16 +978,16 @@ var update_pubkeys = function (username, pubkeys, context) {
983
978
  throw Error("105: unable to save invalid pubkey!");
984
979
  case 14: return [4 /*yield*/, pubkeysDB.insert(entryMongo)];
985
980
  case 15:
986
- resultSave = _d.sent();
981
+ resultSave = _a.sent();
987
982
  log.debug(tag, "resultSave: ", resultSave);
988
- _d.label = 16;
983
+ _a.label = 16;
989
984
  case 16:
990
985
  i++;
991
986
  return [3 /*break*/, 3];
992
987
  case 17: return [3 /*break*/, 19];
993
988
  case 18:
994
989
  log.debug(tag, " No new pubkeys! ");
995
- _d.label = 19;
990
+ _a.label = 19;
996
991
  case 19:
997
992
  log.debug(tag, "output: ", output);
998
993
  if (allBalances.length === 0) {
@@ -1003,7 +998,7 @@ var update_pubkeys = function (username, pubkeys, context) {
1003
998
  log.debug(tag, " return object: ", output);
1004
999
  return [2 /*return*/, output];
1005
1000
  case 20:
1006
- e_8 = _d.sent();
1001
+ e_8 = _a.sent();
1007
1002
  console.error(tag, "e: ", e_8);
1008
1003
  throw e_8;
1009
1004
  case 21: return [2 /*return*/];
@@ -1021,15 +1016,15 @@ var update_pubkeys = function (username, pubkeys, context) {
1021
1016
  */
1022
1017
  var register_pubkeys = function (username, pubkeys) {
1023
1018
  return __awaiter(this, void 0, void 0, function () {
1024
- var tag, saveActions, allBalances, output, i, pubkeyInfo, nativeAsset, pubkeyExists, entryMongo, xpub, result, zpub, result, result, action, saveMongoBulk, allPubkeys, i, pubkeyInfo, e_9;
1025
- var _a, _b, _c, _d, _e;
1026
- return __generator(this, function (_f) {
1027
- switch (_f.label) {
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) {
1028
1023
  case 0:
1029
1024
  tag = TAG + " | register_pubkeys | ";
1030
- _f.label = 1;
1025
+ _c.label = 1;
1031
1026
  case 1:
1032
- _f.trys.push([1, 16, , 17]);
1027
+ _c.trys.push([1, 18, , 19]);
1033
1028
  log.debug(tag, "input: ", { username: username, pubkeys: pubkeys });
1034
1029
  saveActions = [];
1035
1030
  allBalances = [];
@@ -1038,9 +1033,9 @@ var register_pubkeys = function (username, pubkeys) {
1038
1033
  output.balances = [];
1039
1034
  output.nfts = [];
1040
1035
  i = 0;
1041
- _f.label = 2;
1036
+ _c.label = 2;
1042
1037
  case 2:
1043
- if (!(i < pubkeys.length)) return [3 /*break*/, 12];
1038
+ if (!(i < pubkeys.length)) return [3 /*break*/, 14];
1044
1039
  pubkeyInfo = pubkeys[i];
1045
1040
  log.debug(tag, "pubkeyInfo: ", pubkeyInfo);
1046
1041
  if (!pubkeyInfo.blockchain)
@@ -1066,7 +1061,8 @@ var register_pubkeys = function (username, pubkeys) {
1066
1061
  throw Error("Invalid pubkey required field: context:" + pubkeyInfo.blockchain);
1067
1062
  return [4 /*yield*/, pubkeysDB.findOne({ pubkey: pubkeyInfo.pubkey })];
1068
1063
  case 3:
1069
- pubkeyExists = _f.sent();
1064
+ pubkeyExists = _c.sent();
1065
+ log.info(tag, "pubkeyExists: ", pubkeyExists);
1070
1066
  if (!!pubkeyExists) return [3 /*break*/, 11];
1071
1067
  entryMongo = {
1072
1068
  pubkey: pubkeyInfo.pubkey,
@@ -1092,10 +1088,9 @@ var register_pubkeys = function (username, pubkeys) {
1092
1088
  entryMongo.address = pubkeyInfo.address;
1093
1089
  return [4 /*yield*/, register_xpub(username, pubkeyInfo, pubkeyInfo.context)];
1094
1090
  case 4:
1095
- result = _f.sent();
1091
+ result = _c.sent();
1096
1092
  entryMongo.balances = result.balances;
1097
1093
  allBalances.push.apply(allBalances, result.balances);
1098
- (_a = output.pubkeys).push.apply(_a, result.pubkeys);
1099
1094
  return [3 /*break*/, 10];
1100
1095
  case 5:
1101
1096
  if (!(pubkeyInfo.type === "zpub")) return [3 /*break*/, 7];
@@ -1107,10 +1102,9 @@ var register_pubkeys = function (username, pubkeys) {
1107
1102
  entryMongo.address = pubkeyInfo.address;
1108
1103
  return [4 /*yield*/, register_xpub(username, pubkeyInfo, pubkeyInfo.context)];
1109
1104
  case 6:
1110
- result = _f.sent();
1105
+ result = _c.sent();
1111
1106
  entryMongo.balances = result.balances;
1112
1107
  allBalances.push.apply(allBalances, result.balances);
1113
- (_b = output.pubkeys).push.apply(_b, result.pubkeys);
1114
1108
  return [3 /*break*/, 10];
1115
1109
  case 7:
1116
1110
  if (!(pubkeyInfo.type === "address")) return [3 /*break*/, 9];
@@ -1120,14 +1114,13 @@ var register_pubkeys = function (username, pubkeys) {
1120
1114
  entryMongo.address = pubkeyInfo.address;
1121
1115
  return [4 /*yield*/, register_address(username, pubkeyInfo, pubkeyInfo.context)];
1122
1116
  case 8:
1123
- result = _f.sent();
1117
+ result = _c.sent();
1124
1118
  entryMongo.balances = result.balances;
1125
1119
  allBalances.push.apply(allBalances, result.balances);
1126
- (_c = output.pubkeys).push.apply(_c, result.pubkeys);
1127
1120
  return [3 /*break*/, 10];
1128
1121
  case 9:
1129
1122
  log.error(tag, "Unhandled type: ", pubkeyInfo.type);
1130
- _f.label = 10;
1123
+ _c.label = 10;
1131
1124
  case 10:
1132
1125
  //verify write
1133
1126
  log.info(tag, "entryMongo: ", entryMongo);
@@ -1138,36 +1131,46 @@ var register_pubkeys = function (username, pubkeys) {
1138
1131
  action = {
1139
1132
  insertOne: entryMongo
1140
1133
  };
1134
+ log.info(tag, "action: ", action);
1141
1135
  saveActions.push(action);
1142
- _f.label = 11;
1136
+ return [3 /*break*/, 13];
1143
1137
  case 11:
1138
+ if (!(pubkeyExists.indexOf(username) === -1)) return [3 /*break*/, 13];
1139
+ return [4 /*yield*/, pubkeysDB.update({ pubkey: pubkeyInfo.pubkey }, { $addToSet: { tags: { $each: [username] } } })];
1140
+ case 12:
1141
+ pushTagMongo = _c.sent();
1142
+ log.info(tag, "pushTagMongo: ", pushTagMongo);
1143
+ _c.label = 13;
1144
+ case 13:
1144
1145
  i++;
1145
1146
  return [3 /*break*/, 2];
1146
- case 12:
1147
- if (!(saveActions.length > 0)) return [3 /*break*/, 14];
1147
+ case 14:
1148
+ //bulk write to mongo
1149
+ log.info(tag, "saveActions: ", saveActions);
1150
+ if (!(saveActions.length > 0)) return [3 /*break*/, 16];
1148
1151
  return [4 /*yield*/, pubkeysDB.bulkWrite(saveActions, { ordered: false })];
1149
- case 13:
1150
- saveMongoBulk = _f.sent();
1151
- log.info(tag, "saveMongoBulk: ", saveMongoBulk);
1152
- _f.label = 14;
1153
- case 14: return [4 /*yield*/, pubkeysDB.find({ tags: { $in: [username] } })];
1154
1152
  case 15:
1155
- allPubkeys = _f.sent();
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] } })];
1157
+ case 17:
1158
+ allPubkeys = _c.sent();
1156
1159
  log.info(tag, "allPubkeys: ", allPubkeys.length);
1157
1160
  //get all balances for username
1158
1161
  for (i = 0; i < allPubkeys.length; i++) {
1159
1162
  pubkeyInfo = allPubkeys[i];
1160
1163
  if (pubkeyInfo.balances)
1161
- (_d = output.balances).push.apply(_d, pubkeyInfo.balances);
1164
+ (_a = output.balances).push.apply(_a, pubkeyInfo.balances);
1162
1165
  if (pubkeyInfo.nfts)
1163
- (_e = output.nfts).push.apply(_e, pubkeyInfo.nfts);
1166
+ (_b = output.nfts).push.apply(_b, pubkeyInfo.nfts);
1164
1167
  }
1165
1168
  return [2 /*return*/, output];
1166
- case 16:
1167
- e_9 = _f.sent();
1169
+ case 18:
1170
+ e_9 = _c.sent();
1168
1171
  console.error(tag, "e: ", e_9);
1169
1172
  throw e_9;
1170
- case 17: return [2 /*return*/];
1173
+ case 19: return [2 /*return*/];
1171
1174
  }
1172
1175
  });
1173
1176
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/pioneer",
3
- "version": "8.2.15",
3
+ "version": "8.2.16",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {