@ercworldio/blockchain-shared 1.0.1-dev.12 → 1.0.1-dev.14

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.
@@ -14,8 +14,7 @@ declare class QnWebhookAddressManager {
14
14
  /** Returns the { name, network } pairs for the notification configs of a given chain. */
15
15
  private get_webhook_keys_for_chain;
16
16
  private get_notif_configs;
17
- private is_stale;
18
- private load;
17
+ private load_entries;
19
18
  private ensure_loaded;
20
19
  private matches_key;
21
20
  add_address(blockchain: BlockchainType, address: string): Promise<boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"QnWebhookAddressManager.d.ts","sourceRoot":"","sources":["../../../src/services/quicknode-notifications/QnWebhookAddressManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,OAAO,EAAiB,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AA8BlE,cAAM,uBAAuB;IACzB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA0B;IACjD,OAAO,CAAC,GAAG,CAAqB;IAChC,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,KAAK,CAAmD;IAEhE,OAAO,CAAC,EAAE,CAAgB;IAC1B,OAAO;IAMP,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,GAAG,CAAC,EAAE,kBAAkB,GAAG,uBAAuB;IAOzG,OAAO,CAAC,wBAAwB;IAKhC,yFAAyF;IACzF,OAAO,CAAC,0BAA0B;IAQlC,OAAO,CAAC,iBAAiB;IAkBzB,OAAO,CAAC,QAAQ;YAMF,IAAI;YAyCJ,aAAa;IAQ3B,OAAO,CAAC,WAAW;IAIN,WAAW,CAAC,UAAU,EAAE,c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,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,GAAG,CAAC,EAAE,kBAAkB,GAAG,uBAAuB;IAOzG,OAAO,CAAC,wBAAwB;IAKhC,yFAAyF;IACzF,OAAO,CAAC,0BAA0B;IAQlC,OAAO,CAAC,iBAAiB;YAkBX,YAAY;YA+BZ,aAAa;IAQ3B,OAAO,CAAC,WAAW;IAIN,WAAW,CAAC,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAoB1E,cAAc,CAAC,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAmB1F;;;;OAIG;IACU,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAwBvF;;;;OAIG;IACU,yBAAyB,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAyB5F;;;;OAIG;IACU,qBAAqB,CAAC,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBzH;;;;OAIG;IACU,0BAA0B,CAAC,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;YAsBhH,sBAAsB;CAuBvC;AAED,eAAe,uBAAuB,CAAC"}
@@ -12,6 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ const AsyncTTLCache_1 = __importDefault(require("../../utils/AsyncTTLCache"));
15
16
  const ChainManager_1 = __importDefault(require("../ChainManager"));
16
17
  const DepositAddressService_1 = __importDefault(require("../DepositAddressService"));
17
18
  const QnNotificationsApi_1 = __importDefault(require("./QnNotificationsApi"));
@@ -20,7 +21,7 @@ const ADDRESS_SYNC_BATCH_SIZE = 500;
20
21
  const ADDRESS_LOG_THRESHOLD = 1000;
21
22
  class QnWebhookAddressManager {
22
23
  constructor(config, db, rlc) {
23
- this.cache = new Map();
24
+ this.cache = AsyncTTLCache_1.default.create(CACHE_TTL_MS);
24
25
  this.config = config;
25
26
  this.api = QnNotificationsApi_1.default.getInstance(config, rlc);
26
27
  this.db = db;
@@ -58,29 +59,15 @@ class QnWebhookAddressManager {
58
59
  .flatMap(([_, cfg]) => cfg.quicknodeNotificationConfig.map(n => (Object.assign(Object.assign({}, n), { blockchain: cfg.blockchainType }))))
59
60
  .filter((n, i, arr) => arr.findIndex(x => x.name === n.name) === i);
60
61
  }
61
- is_stale(blockchain) {
62
- const cached = this.cache.get(blockchain);
63
- if (!cached)
64
- return true;
65
- return Date.now() - cached.loaded_at > CACHE_TTL_MS;
66
- }
67
- load(blockchain) {
62
+ load_entries(blockchain) {
68
63
  return __awaiter(this, void 0, void 0, function* () {
69
64
  const notif_configs = this.get_notif_configs(blockchain);
70
65
  if (notif_configs.length === 0)
71
- return;
72
- let all_webhooks = [];
73
- try {
74
- const res = yield this.api.get_all_webhooks();
75
- all_webhooks = res.data || [];
76
- }
77
- catch (error) {
78
- console.error(`QnWebhookAddressManager: Failed to fetch webhooks for blockchain=${blockchain}`, error);
79
- return;
80
- }
81
- // Get all addresses to add to webhook
66
+ return [];
67
+ const res = yield this.api.get_all_webhooks();
68
+ const all_webhooks = res.data || [];
82
69
  const addresses = yield this.fetch_all_db_addresses(blockchain);
83
- console.log(`Loading ${addresses.length} addresses from db`);
70
+ console.log(`Loaded ${addresses.length} addresses from db`);
84
71
  const entries = [];
85
72
  for (const notif_config of notif_configs) {
86
73
  const existing = all_webhooks.find(w => {
@@ -88,7 +75,6 @@ class QnWebhookAddressManager {
88
75
  return ((_a = w.name) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === notif_config.name.toLowerCase() &&
89
76
  ((_b = w.network) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === notif_config.network.toLowerCase();
90
77
  });
91
- console.log(`Existing webhooks matching update: `, existing);
92
78
  if (!existing) {
93
79
  console.warn(`QnWebhookAddressManager: No webhook found for config=${notif_config.name} network=${notif_config.network}`);
94
80
  continue;
@@ -101,17 +87,12 @@ class QnWebhookAddressManager {
101
87
  address_set: new Set(addresses),
102
88
  });
103
89
  }
104
- this.cache.set(blockchain, { entries, loaded_at: Date.now() });
90
+ return entries;
105
91
  });
106
92
  }
107
93
  ensure_loaded(blockchain) {
108
94
  return __awaiter(this, void 0, void 0, function* () {
109
- var _a;
110
- if (this.is_stale(blockchain)) {
111
- console.log(`Stale: loading...`);
112
- yield this.load(blockchain);
113
- }
114
- return ((_a = this.cache.get(blockchain)) === null || _a === void 0 ? void 0 : _a.entries) || [];
95
+ return this.cache.get_value(blockchain, blockchain, (bc) => this.load_entries(bc));
115
96
  });
116
97
  }
117
98
  matches_key(entry, key) {
@@ -127,7 +108,7 @@ class QnWebhookAddressManager {
127
108
  continue;
128
109
  entry.address_set.add(address);
129
110
  try {
130
- console.log(`Adding addresses: `, entry.address_set);
111
+ console.log(`add_address : Adding addresses: `, entry.address_set);
131
112
  yield this.api.update_webhook_addresses(entry.webhook_id, entry.template, Array.from(entry.address_set));
132
113
  console.log(`QnWebhookAddressManager: Added ${address} to ${entry.name} webhook`);
133
114
  }
@@ -149,7 +130,7 @@ class QnWebhookAddressManager {
149
130
  continue;
150
131
  entry.address_set.delete(address);
151
132
  try {
152
- console.log(`Updating webhook addresses to :`, Array.from(entry.address_set));
133
+ console.log(`remove_address: Updating webhook addresses to :`, Array.from(entry.address_set));
153
134
  yield this.api.update_webhook_addresses(entry.webhook_id, entry.template, Array.from(entry.address_set));
154
135
  console.log(`QnWebhookAddressManager: Removed ${address} from ${entry.name} webhook`);
155
136
  }
@@ -176,10 +157,11 @@ class QnWebhookAddressManager {
176
157
  const entries = (yield this.ensure_loaded(blockchain))
177
158
  .filter(e => keys.some(k => this.matches_key(e, k)));
178
159
  for (const entry of entries) {
179
- if (entry.address_set.has(address))
180
- continue;
181
- entry.address_set.add(address);
160
+ // if (entry.address_set.has(address)) continue;
161
+ if (!entry.address_set.has(address) && !entry.address_set.has(address.toLowerCase()))
162
+ entry.address_set.add(address);
182
163
  try {
164
+ console.log(`add_address_to_chain: Updating webhook addresses. new set ${entry.address_set.size} addresses`);
183
165
  yield this.api.update_webhook_addresses(entry.webhook_id, entry.template, Array.from(entry.address_set));
184
166
  console.log(`QnWebhookAddressManager: Added ${address} to ${entry.name} webhook (chain ${chain_id})`);
185
167
  }
@@ -206,10 +188,11 @@ class QnWebhookAddressManager {
206
188
  const entries = (yield this.ensure_loaded(blockchain))
207
189
  .filter(e => keys.some(k => this.matches_key(e, k)));
208
190
  for (const entry of entries) {
209
- if (!entry.address_set.has(address))
210
- continue;
211
- entry.address_set.delete(address);
191
+ // if (!entry.address_set.has(address)) continue;
192
+ if (entry.address_set.has(address) || entry.address_set.has(address.toLowerCase()))
193
+ entry.address_set.delete(address);
212
194
  try {
195
+ console.log(`remove_address_from_chain: Updating webhook addresses. new set ${entry.address_set.size} addresses`);
213
196
  yield this.api.update_webhook_addresses(entry.webhook_id, entry.template, Array.from(entry.address_set));
214
197
  console.log(`QnWebhookAddressManager: Removed ${address} from ${entry.name} webhook (chain ${chain_id})`);
215
198
  }
@@ -237,6 +220,7 @@ class QnWebhookAddressManager {
237
220
  continue;
238
221
  entry.address_set.add(address);
239
222
  try {
223
+ console.log(`sync_add_to_remaining: Updating webhook addresses. new set ${entry.address_set.size} addresses`);
240
224
  yield this.api.update_webhook_addresses(entry.webhook_id, entry.template, Array.from(entry.address_set));
241
225
  console.log(`QnWebhookAddressManager: Synced add ${address} to ${entry.name} webhook`);
242
226
  }
@@ -262,6 +246,7 @@ class QnWebhookAddressManager {
262
246
  continue;
263
247
  entry.address_set.delete(address);
264
248
  try {
249
+ console.log(`sync_remove_from_remaining: Updating webhook addresses. new set ${entry.address_set.size} addresses`);
265
250
  yield this.api.update_webhook_addresses(entry.webhook_id, entry.template, Array.from(entry.address_set));
266
251
  console.log(`QnWebhookAddressManager: Synced remove ${address} from ${entry.name} webhook`);
267
252
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ercworldio/blockchain-shared",
3
- "version": "1.0.1-dev.12",
3
+ "version": "1.0.1-dev.14",
4
4
  "description": "Shared library for blockchain projects",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",