tornado-core 1.0.6

* fixed save condition
This commit is contained in:
Tornado Contrib 2024-09-21 03:56:48 +00:00
parent e506c373de
commit ef56beb29b
Signed by: tornadocontrib
GPG Key ID: 60B4DF1A076C64B1
6 changed files with 34 additions and 9 deletions

@ -184,6 +184,7 @@ export interface CachedRelayerInfo extends RelayerParams {
export interface CachedRelayers { export interface CachedRelayers {
timestamp: number; timestamp: number;
relayers: CachedRelayerInfo[]; relayers: CachedRelayerInfo[];
fromCache?: boolean;
} }
export type BaseRegistryServiceConstructor = { export type BaseRegistryServiceConstructor = {
netId: NetIdType; netId: NetIdType;

9
dist/index.js vendored

@ -3344,7 +3344,8 @@ class BaseRegistryService extends BaseEventsService {
return __async$8(this, null, function* () { return __async$8(this, null, function* () {
return { return {
timestamp: 0, timestamp: 0,
relayers: [] relayers: [],
fromCache: true
}; };
}); });
} }
@ -3415,10 +3416,14 @@ class BaseRegistryService extends BaseEventsService {
*/ */
updateRelayers() { updateRelayers() {
return __async$8(this, null, function* () { 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)) { if (!relayers.length || timestamp + this.updateInterval < Math.floor(Date.now() / 1e3)) {
console.log("\nUpdating relayers from registry\n"); console.log("\nUpdating relayers from registry\n");
({ timestamp, relayers } = yield this.getLatestRelayers()); ({ timestamp, relayers } = yield this.getLatestRelayers());
shouldSave = true;
}
if (shouldSave) {
yield this.saveRelayers({ timestamp, relayers }); yield this.saveRelayers({ timestamp, relayers });
} }
return { timestamp, relayers }; return { timestamp, relayers };

9
dist/index.mjs vendored

@ -3323,7 +3323,8 @@ class BaseRegistryService extends BaseEventsService {
return __async$8(this, null, function* () { return __async$8(this, null, function* () {
return { return {
timestamp: 0, timestamp: 0,
relayers: [] relayers: [],
fromCache: true
}; };
}); });
} }
@ -3394,10 +3395,14 @@ class BaseRegistryService extends BaseEventsService {
*/ */
updateRelayers() { updateRelayers() {
return __async$8(this, null, function* () { 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)) { if (!relayers.length || timestamp + this.updateInterval < Math.floor(Date.now() / 1e3)) {
console.log("\nUpdating relayers from registry\n"); console.log("\nUpdating relayers from registry\n");
({ timestamp, relayers } = yield this.getLatestRelayers()); ({ timestamp, relayers } = yield this.getLatestRelayers());
shouldSave = true;
}
if (shouldSave) {
yield this.saveRelayers({ timestamp, relayers }); yield this.saveRelayers({ timestamp, relayers });
} }
return { timestamp, relayers }; return { timestamp, relayers };

9
dist/index.umd.js vendored

@ -59692,7 +59692,8 @@ class BaseRegistryService extends BaseEventsService {
return __async(this, null, function* () { return __async(this, null, function* () {
return { return {
timestamp: 0, timestamp: 0,
relayers: [] relayers: [],
fromCache: true
}; };
}); });
} }
@ -59763,10 +59764,14 @@ class BaseRegistryService extends BaseEventsService {
*/ */
updateRelayers() { updateRelayers() {
return __async(this, null, function* () { 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)) { if (!relayers.length || timestamp + this.updateInterval < Math.floor(Date.now() / 1e3)) {
console.log("\nUpdating relayers from registry\n"); console.log("\nUpdating relayers from registry\n");
({ timestamp, relayers } = yield this.getLatestRelayers()); ({ timestamp, relayers } = yield this.getLatestRelayers());
shouldSave = true;
}
if (shouldSave) {
yield this.saveRelayers({ timestamp, relayers }); yield this.saveRelayers({ timestamp, relayers });
} }
return { timestamp, relayers }; return { timestamp, relayers };

@ -1,6 +1,6 @@
{ {
"name": "@tornado/core", "name": "@tornado/core",
"version": "1.0.5", "version": "1.0.6",
"description": "An SDK for building applications on top of Privacy Pools", "description": "An SDK for building applications on top of Privacy Pools",
"main": "./dist/index.js", "main": "./dist/index.js",
"module": "./dist/index.mjs", "module": "./dist/index.mjs",

@ -31,7 +31,7 @@ import {
} from '../batch'; } from '../batch';
import type { fetchDataOptions } from '../providers'; 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 { RelayerParams, MIN_STAKE_BALANCE } from '../relayerClient';
import type { import type {
@ -773,6 +773,7 @@ export interface CachedRelayerInfo extends RelayerParams {
export interface CachedRelayers { export interface CachedRelayers {
timestamp: number; timestamp: number;
relayers: CachedRelayerInfo[]; relayers: CachedRelayerInfo[];
fromCache?: boolean;
} }
export type BaseRegistryServiceConstructor = { export type BaseRegistryServiceConstructor = {
@ -858,6 +859,7 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
return { return {
timestamp: 0, timestamp: 0,
relayers: [], relayers: [],
fromCache: true,
}; };
} }
@ -939,13 +941,20 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
* Get cached or latest relayer and save to local * Get cached or latest relayer and save to local
*/ */
async updateRelayers(): Promise<CachedRelayers> { async updateRelayers(): Promise<CachedRelayers> {
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)) { if (!relayers.length || timestamp + this.updateInterval < Math.floor(Date.now() / 1000)) {
console.log('\nUpdating relayers from registry\n'); console.log('\nUpdating relayers from registry\n');
({ timestamp, relayers } = await this.getLatestRelayers()); ({ timestamp, relayers } = await this.getLatestRelayers());
shouldSave = true;
}
if (shouldSave) {
await this.saveRelayers({ timestamp, relayers }); await this.saveRelayers({ timestamp, relayers });
} }