@ercworldio/blockchain-shared 1.0.1-dev.13 → 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
|
|
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;
|
|
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;AAyBlE,cAAM,uBAAuB;IACzB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA0B;IACjD,OAAO,CAAC,GAAG,CAAqB;IAChC,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,KAAK,CAAqD;IAElE,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;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 =
|
|
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
|
-
|
|
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
|
-
|
|
73
|
-
|
|
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(`
|
|
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
|
-
|
|
90
|
+
return entries;
|
|
105
91
|
});
|
|
106
92
|
}
|
|
107
93
|
ensure_loaded(blockchain) {
|
|
108
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
-
|
|
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) {
|
|
@@ -176,9 +157,9 @@ 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
|
-
|
|
181
|
-
|
|
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 {
|
|
183
164
|
console.log(`add_address_to_chain: Updating webhook addresses. new set ${entry.address_set.size} addresses`);
|
|
184
165
|
yield this.api.update_webhook_addresses(entry.webhook_id, entry.template, Array.from(entry.address_set));
|
|
@@ -207,9 +188,9 @@ class QnWebhookAddressManager {
|
|
|
207
188
|
const entries = (yield this.ensure_loaded(blockchain))
|
|
208
189
|
.filter(e => keys.some(k => this.matches_key(e, k)));
|
|
209
190
|
for (const entry of entries) {
|
|
210
|
-
if (!entry.address_set.has(address))
|
|
211
|
-
|
|
212
|
-
|
|
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);
|
|
213
194
|
try {
|
|
214
195
|
console.log(`remove_address_from_chain: Updating webhook addresses. new set ${entry.address_set.size} addresses`);
|
|
215
196
|
yield this.api.update_webhook_addresses(entry.webhook_id, entry.template, Array.from(entry.address_set));
|