From ef56beb29b3dc8808167acefe2bd23c2680643b2 Mon Sep 17 00:00:00 2001 From: tornadocontrib Date: Sat, 21 Sep 2024 03:56:48 +0000 Subject: [PATCH] tornado-core 1.0.6 * fixed save condition --- dist/events/base.d.ts | 1 + dist/index.js | 9 +++++++-- dist/index.mjs | 9 +++++++-- dist/index.umd.js | 9 +++++++-- package.json | 2 +- src/events/base.ts | 13 +++++++++++-- 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/dist/events/base.d.ts b/dist/events/base.d.ts index e5fb683..45fc565 100644 --- a/dist/events/base.d.ts +++ b/dist/events/base.d.ts @@ -184,6 +184,7 @@ export interface CachedRelayerInfo extends RelayerParams { export interface CachedRelayers { timestamp: number; relayers: CachedRelayerInfo[]; + fromCache?: boolean; } export type BaseRegistryServiceConstructor = { netId: NetIdType; diff --git a/dist/index.js b/dist/index.js index e70e754..32bb90d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3344,7 +3344,8 @@ class BaseRegistryService extends BaseEventsService { return __async$8(this, null, function* () { return { timestamp: 0, - relayers: [] + relayers: [], + fromCache: true }; }); } @@ -3415,10 +3416,14 @@ class BaseRegistryService extends BaseEventsService { */ updateRelayers() { return __async$8(this, null, function* () { - let { timestamp, relayers } = yield this.getSavedRelayers(); + let { timestamp, relayers, fromCache } = yield this.getSavedRelayers(); + let shouldSave = fromCache != null ? fromCache : false; if (!relayers.length || timestamp + this.updateInterval < Math.floor(Date.now() / 1e3)) { console.log("\nUpdating relayers from registry\n"); ({ timestamp, relayers } = yield this.getLatestRelayers()); + shouldSave = true; + } + if (shouldSave) { yield this.saveRelayers({ timestamp, relayers }); } return { timestamp, relayers }; diff --git a/dist/index.mjs b/dist/index.mjs index 79ef4f2..71c1bf9 100644 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -3323,7 +3323,8 @@ class BaseRegistryService extends BaseEventsService { return __async$8(this, null, function* () { return { timestamp: 0, - relayers: [] + relayers: [], + fromCache: true }; }); } @@ -3394,10 +3395,14 @@ class BaseRegistryService extends BaseEventsService { */ updateRelayers() { return __async$8(this, null, function* () { - let { timestamp, relayers } = yield this.getSavedRelayers(); + let { timestamp, relayers, fromCache } = yield this.getSavedRelayers(); + let shouldSave = fromCache != null ? fromCache : false; if (!relayers.length || timestamp + this.updateInterval < Math.floor(Date.now() / 1e3)) { console.log("\nUpdating relayers from registry\n"); ({ timestamp, relayers } = yield this.getLatestRelayers()); + shouldSave = true; + } + if (shouldSave) { yield this.saveRelayers({ timestamp, relayers }); } return { timestamp, relayers }; diff --git a/dist/index.umd.js b/dist/index.umd.js index a3a20d8..3af025a 100644 --- a/dist/index.umd.js +++ b/dist/index.umd.js @@ -59692,7 +59692,8 @@ class BaseRegistryService extends BaseEventsService { return __async(this, null, function* () { return { timestamp: 0, - relayers: [] + relayers: [], + fromCache: true }; }); } @@ -59763,10 +59764,14 @@ class BaseRegistryService extends BaseEventsService { */ updateRelayers() { return __async(this, null, function* () { - let { timestamp, relayers } = yield this.getSavedRelayers(); + let { timestamp, relayers, fromCache } = yield this.getSavedRelayers(); + let shouldSave = fromCache != null ? fromCache : false; if (!relayers.length || timestamp + this.updateInterval < Math.floor(Date.now() / 1e3)) { console.log("\nUpdating relayers from registry\n"); ({ timestamp, relayers } = yield this.getLatestRelayers()); + shouldSave = true; + } + if (shouldSave) { yield this.saveRelayers({ timestamp, relayers }); } return { timestamp, relayers }; diff --git a/package.json b/package.json index 5ced6df..84f4a09 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tornado/core", - "version": "1.0.5", + "version": "1.0.6", "description": "An SDK for building applications on top of Privacy Pools", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/src/events/base.ts b/src/events/base.ts index ff6aa78..1f84440 100644 --- a/src/events/base.ts +++ b/src/events/base.ts @@ -31,7 +31,7 @@ import { } from '../batch'; import type { fetchDataOptions } from '../providers'; -import type { NetIdType, Config, SubdomainMap } from '../networkConfig'; +import type { NetIdType, SubdomainMap } from '../networkConfig'; import { RelayerParams, MIN_STAKE_BALANCE } from '../relayerClient'; import type { @@ -773,6 +773,7 @@ export interface CachedRelayerInfo extends RelayerParams { export interface CachedRelayers { timestamp: number; relayers: CachedRelayerInfo[]; + fromCache?: boolean; } export type BaseRegistryServiceConstructor = { @@ -858,6 +859,7 @@ export class BaseRegistryService extends BaseEventsService { return { timestamp: 0, relayers: [], + fromCache: true, }; } @@ -939,13 +941,20 @@ export class BaseRegistryService extends BaseEventsService { * Get cached or latest relayer and save to local */ async updateRelayers(): Promise { - let { timestamp, relayers } = await this.getSavedRelayers(); + // eslint-disable-next-line prefer-const + let { timestamp, relayers, fromCache } = await this.getSavedRelayers(); + + let shouldSave = fromCache ?? false; if (!relayers.length || timestamp + this.updateInterval < Math.floor(Date.now() / 1000)) { console.log('\nUpdating relayers from registry\n'); ({ timestamp, relayers } = await this.getLatestRelayers()); + shouldSave = true; + } + + if (shouldSave) { await this.saveRelayers({ timestamp, relayers }); }