Minor updates #1

Closed
tornadocontrib wants to merge 67 commits from tornadocontrib/tornado-core:main into main
6 changed files with 70 additions and 56 deletions
Showing only changes of commit be0e2419aa - Show all commits

View File

@ -184,10 +184,11 @@ export interface CachedRelayerInfo extends RelayerParams {
owner?: string;
stakeBalance?: string;
hostnames: SubdomainMap;
tovarishUrl?: string;
tovarishHost?: string;
tovarishNetworks?: number[];
}
export interface CachedRelayers {
lastBlock: number;
timestamp: number;
relayers: CachedRelayerInfo[];
fromCache?: boolean;
@ -232,7 +233,7 @@ export declare class BaseRegistryService extends BaseEventsService<RegistersEven
/**
* Handle saving relayers
*/
saveRelayers({ timestamp, relayers }: CachedRelayers): Promise<void>;
saveRelayers({ lastBlock, timestamp, relayers }: CachedRelayers): Promise<void>;
/**
* Get cached or latest relayer and save to local
*/

29
dist/index.js vendored
View File

@ -3290,10 +3290,10 @@ class BaseGovernanceService extends BaseEventsService {
function getTovarishNetworks(registryService, relayers) {
return __async$8(this, null, function* () {
yield Promise.all(
relayers.filter((r) => r.tovarishUrl).map((relayer) => __async$8(this, null, function* () {
relayers.filter((r) => r.tovarishHost).map((relayer) => __async$8(this, null, function* () {
var _a, _b;
try {
relayer.tovarishNetworks = yield fetchData(relayer.tovarishUrl, __spreadProps(__spreadValues({}, registryService.fetchDataOptions), {
relayer.tovarishNetworks = yield fetchData(relayer.tovarishHost, __spreadProps(__spreadValues({}, registryService.fetchDataOptions), {
headers: {
"Content-Type": "application/json"
},
@ -3359,6 +3359,7 @@ class BaseRegistryService extends BaseEventsService {
getRelayersFromDB() {
return __async$8(this, null, function* () {
return {
lastBlock: 0,
timestamp: 0,
relayers: []
};
@ -3370,6 +3371,7 @@ class BaseRegistryService extends BaseEventsService {
getRelayersFromCache() {
return __async$8(this, null, function* () {
return {
lastBlock: 0,
timestamp: 0,
relayers: [],
fromCache: true
@ -3387,10 +3389,10 @@ class BaseRegistryService extends BaseEventsService {
}
getLatestRelayers() {
return __async$8(this, null, function* () {
const registerEvents = (yield this.updateEvents()).events;
const { events, lastBlock } = yield this.updateEvents();
const subdomains = Object.values(this.relayerEnsSubdomains);
const registerSet = /* @__PURE__ */ new Set();
const uniqueRegisters = registerEvents.filter(({ ensName }) => {
const uniqueRegisters = events.filter(({ ensName }) => {
if (!registerSet.has(ensName)) {
registerSet.add(ensName);
return true;
@ -3400,15 +3402,15 @@ class BaseRegistryService extends BaseEventsService {
const relayerNameHashes = uniqueRegisters.map((r) => ethers.namehash(r.ensName));
const [relayersData, timestamp] = yield Promise.all([
this.Aggregator.relayersData.staticCall(relayerNameHashes, subdomains.concat("tovarish-relayer")),
this.provider.getBlock("latest").then((b) => Number(b == null ? void 0 : b.timestamp))
this.provider.getBlock(lastBlock).then((b) => Number(b == null ? void 0 : b.timestamp))
]);
const relayers = relayersData.map(({ owner, balance: stakeBalance, records, isRegistered }, index) => {
const { ensName, relayerAddress } = uniqueRegisters[index];
let tovarishUrl = void 0;
let tovarishHost = void 0;
const hostnames = records.reduce((acc, record, recordIndex) => {
if (record) {
if (recordIndex === records.length - 1) {
tovarishUrl = record;
tovarishHost = record;
return acc;
}
acc[Number(Object.keys(this.relayerEnsSubdomains)[recordIndex])] = record;
@ -3426,12 +3428,13 @@ class BaseRegistryService extends BaseEventsService {
owner,
stakeBalance: ethers.formatEther(stakeBalance),
hostnames,
tovarishUrl
tovarishHost
};
}
}).filter((r) => r);
yield getTovarishNetworks(this, relayers);
return {
lastBlock,
timestamp,
relayers
};
@ -3442,7 +3445,7 @@ class BaseRegistryService extends BaseEventsService {
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
saveRelayers(_0) {
return __async$8(this, arguments, function* ({ timestamp, relayers }) {
return __async$8(this, arguments, function* ({ lastBlock, timestamp, relayers }) {
});
}
/**
@ -3450,17 +3453,17 @@ class BaseRegistryService extends BaseEventsService {
*/
updateRelayers() {
return __async$8(this, null, function* () {
let { timestamp, relayers, fromCache } = yield this.getSavedRelayers();
let { lastBlock, 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());
({ lastBlock, timestamp, relayers } = yield this.getLatestRelayers());
shouldSave = true;
}
if (shouldSave) {
yield this.saveRelayers({ timestamp, relayers });
yield this.saveRelayers({ lastBlock, timestamp, relayers });
}
return { timestamp, relayers };
return { lastBlock, timestamp, relayers };
});
}
}

29
dist/index.mjs vendored
View File

@ -3269,10 +3269,10 @@ class BaseGovernanceService extends BaseEventsService {
function getTovarishNetworks(registryService, relayers) {
return __async$8(this, null, function* () {
yield Promise.all(
relayers.filter((r) => r.tovarishUrl).map((relayer) => __async$8(this, null, function* () {
relayers.filter((r) => r.tovarishHost).map((relayer) => __async$8(this, null, function* () {
var _a, _b;
try {
relayer.tovarishNetworks = yield fetchData(relayer.tovarishUrl, __spreadProps(__spreadValues({}, registryService.fetchDataOptions), {
relayer.tovarishNetworks = yield fetchData(relayer.tovarishHost, __spreadProps(__spreadValues({}, registryService.fetchDataOptions), {
headers: {
"Content-Type": "application/json"
},
@ -3338,6 +3338,7 @@ class BaseRegistryService extends BaseEventsService {
getRelayersFromDB() {
return __async$8(this, null, function* () {
return {
lastBlock: 0,
timestamp: 0,
relayers: []
};
@ -3349,6 +3350,7 @@ class BaseRegistryService extends BaseEventsService {
getRelayersFromCache() {
return __async$8(this, null, function* () {
return {
lastBlock: 0,
timestamp: 0,
relayers: [],
fromCache: true
@ -3366,10 +3368,10 @@ class BaseRegistryService extends BaseEventsService {
}
getLatestRelayers() {
return __async$8(this, null, function* () {
const registerEvents = (yield this.updateEvents()).events;
const { events, lastBlock } = yield this.updateEvents();
const subdomains = Object.values(this.relayerEnsSubdomains);
const registerSet = /* @__PURE__ */ new Set();
const uniqueRegisters = registerEvents.filter(({ ensName }) => {
const uniqueRegisters = events.filter(({ ensName }) => {
if (!registerSet.has(ensName)) {
registerSet.add(ensName);
return true;
@ -3379,15 +3381,15 @@ class BaseRegistryService extends BaseEventsService {
const relayerNameHashes = uniqueRegisters.map((r) => namehash(r.ensName));
const [relayersData, timestamp] = yield Promise.all([
this.Aggregator.relayersData.staticCall(relayerNameHashes, subdomains.concat("tovarish-relayer")),
this.provider.getBlock("latest").then((b) => Number(b == null ? void 0 : b.timestamp))
this.provider.getBlock(lastBlock).then((b) => Number(b == null ? void 0 : b.timestamp))
]);
const relayers = relayersData.map(({ owner, balance: stakeBalance, records, isRegistered }, index) => {
const { ensName, relayerAddress } = uniqueRegisters[index];
let tovarishUrl = void 0;
let tovarishHost = void 0;
const hostnames = records.reduce((acc, record, recordIndex) => {
if (record) {
if (recordIndex === records.length - 1) {
tovarishUrl = record;
tovarishHost = record;
return acc;
}
acc[Number(Object.keys(this.relayerEnsSubdomains)[recordIndex])] = record;
@ -3405,12 +3407,13 @@ class BaseRegistryService extends BaseEventsService {
owner,
stakeBalance: formatEther(stakeBalance),
hostnames,
tovarishUrl
tovarishHost
};
}
}).filter((r) => r);
yield getTovarishNetworks(this, relayers);
return {
lastBlock,
timestamp,
relayers
};
@ -3421,7 +3424,7 @@ class BaseRegistryService extends BaseEventsService {
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
saveRelayers(_0) {
return __async$8(this, arguments, function* ({ timestamp, relayers }) {
return __async$8(this, arguments, function* ({ lastBlock, timestamp, relayers }) {
});
}
/**
@ -3429,17 +3432,17 @@ class BaseRegistryService extends BaseEventsService {
*/
updateRelayers() {
return __async$8(this, null, function* () {
let { timestamp, relayers, fromCache } = yield this.getSavedRelayers();
let { lastBlock, 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());
({ lastBlock, timestamp, relayers } = yield this.getLatestRelayers());
shouldSave = true;
}
if (shouldSave) {
yield this.saveRelayers({ timestamp, relayers });
yield this.saveRelayers({ lastBlock, timestamp, relayers });
}
return { timestamp, relayers };
return { lastBlock, timestamp, relayers };
});
}
}

29
dist/tornado.umd.js vendored
View File

@ -59634,10 +59634,10 @@ class BaseGovernanceService extends BaseEventsService {
function getTovarishNetworks(registryService, relayers) {
return __async(this, null, function* () {
yield Promise.all(
relayers.filter((r) => r.tovarishUrl).map((relayer) => __async(this, null, function* () {
relayers.filter((r) => r.tovarishHost).map((relayer) => __async(this, null, function* () {
var _a, _b;
try {
relayer.tovarishNetworks = yield (0,_providers__WEBPACK_IMPORTED_MODULE_2__/* .fetchData */ .Fd)(relayer.tovarishUrl, __spreadProps(__spreadValues({}, registryService.fetchDataOptions), {
relayer.tovarishNetworks = yield (0,_providers__WEBPACK_IMPORTED_MODULE_2__/* .fetchData */ .Fd)(relayer.tovarishHost, __spreadProps(__spreadValues({}, registryService.fetchDataOptions), {
headers: {
"Content-Type": "application/json"
},
@ -59703,6 +59703,7 @@ class BaseRegistryService extends BaseEventsService {
getRelayersFromDB() {
return __async(this, null, function* () {
return {
lastBlock: 0,
timestamp: 0,
relayers: []
};
@ -59714,6 +59715,7 @@ class BaseRegistryService extends BaseEventsService {
getRelayersFromCache() {
return __async(this, null, function* () {
return {
lastBlock: 0,
timestamp: 0,
relayers: [],
fromCache: true
@ -59731,10 +59733,10 @@ class BaseRegistryService extends BaseEventsService {
}
getLatestRelayers() {
return __async(this, null, function* () {
const registerEvents = (yield this.updateEvents()).events;
const { events, lastBlock } = yield this.updateEvents();
const subdomains = Object.values(this.relayerEnsSubdomains);
const registerSet = /* @__PURE__ */ new Set();
const uniqueRegisters = registerEvents.filter(({ ensName }) => {
const uniqueRegisters = events.filter(({ ensName }) => {
if (!registerSet.has(ensName)) {
registerSet.add(ensName);
return true;
@ -59744,15 +59746,15 @@ class BaseRegistryService extends BaseEventsService {
const relayerNameHashes = uniqueRegisters.map((r) => (0,ethers__WEBPACK_IMPORTED_MODULE_5__/* .namehash */ .kM)(r.ensName));
const [relayersData, timestamp] = yield Promise.all([
this.Aggregator.relayersData.staticCall(relayerNameHashes, subdomains.concat("tovarish-relayer")),
this.provider.getBlock("latest").then((b) => Number(b == null ? void 0 : b.timestamp))
this.provider.getBlock(lastBlock).then((b) => Number(b == null ? void 0 : b.timestamp))
]);
const relayers = relayersData.map(({ owner, balance: stakeBalance, records, isRegistered }, index) => {
const { ensName, relayerAddress } = uniqueRegisters[index];
let tovarishUrl = void 0;
let tovarishHost = void 0;
const hostnames = records.reduce((acc, record, recordIndex) => {
if (record) {
if (recordIndex === records.length - 1) {
tovarishUrl = record;
tovarishHost = record;
return acc;
}
acc[Number(Object.keys(this.relayerEnsSubdomains)[recordIndex])] = record;
@ -59770,12 +59772,13 @@ class BaseRegistryService extends BaseEventsService {
owner,
stakeBalance: (0,ethers__WEBPACK_IMPORTED_MODULE_6__/* .formatEther */ .ck)(stakeBalance),
hostnames,
tovarishUrl
tovarishHost
};
}
}).filter((r) => r);
yield getTovarishNetworks(this, relayers);
return {
lastBlock,
timestamp,
relayers
};
@ -59786,7 +59789,7 @@ class BaseRegistryService extends BaseEventsService {
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
saveRelayers(_0) {
return __async(this, arguments, function* ({ timestamp, relayers }) {
return __async(this, arguments, function* ({ lastBlock, timestamp, relayers }) {
});
}
/**
@ -59794,17 +59797,17 @@ class BaseRegistryService extends BaseEventsService {
*/
updateRelayers() {
return __async(this, null, function* () {
let { timestamp, relayers, fromCache } = yield this.getSavedRelayers();
let { lastBlock, 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());
({ lastBlock, timestamp, relayers } = yield this.getLatestRelayers());
shouldSave = true;
}
if (shouldSave) {
yield this.saveRelayers({ timestamp, relayers });
yield this.saveRelayers({ lastBlock, timestamp, relayers });
}
return { timestamp, relayers };
return { lastBlock, timestamp, relayers };
});
}
}

File diff suppressed because one or more lines are too long

View File

@ -749,10 +749,10 @@ export class BaseGovernanceService extends BaseEventsService<AllGovernanceEvents
export async function getTovarishNetworks(registryService: BaseRegistryService, relayers: CachedRelayerInfo[]) {
await Promise.all(
relayers
.filter((r) => r.tovarishUrl)
.filter((r) => r.tovarishHost)
.map(async (relayer) => {
try {
relayer.tovarishNetworks = await fetchData(relayer.tovarishUrl as string, {
relayer.tovarishNetworks = await fetchData(relayer.tovarishHost as string, {
...registryService.fetchDataOptions,
headers: {
'Content-Type': 'application/json',
@ -778,11 +778,12 @@ export interface CachedRelayerInfo extends RelayerParams {
owner?: string;
stakeBalance?: string;
hostnames: SubdomainMap;
tovarishUrl?: string;
tovarishHost?: string;
tovarishNetworks?: number[];
}
export interface CachedRelayers {
lastBlock: number;
timestamp: number;
relayers: CachedRelayerInfo[];
fromCache?: boolean;
@ -863,6 +864,7 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
*/
async getRelayersFromDB(): Promise<CachedRelayers> {
return {
lastBlock: 0,
timestamp: 0,
relayers: [],
};
@ -873,6 +875,7 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
*/
async getRelayersFromCache(): Promise<CachedRelayers> {
return {
lastBlock: 0,
timestamp: 0,
relayers: [],
fromCache: true,
@ -890,13 +893,13 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
}
async getLatestRelayers(): Promise<CachedRelayers> {
const registerEvents = (await this.updateEvents()).events;
const { events, lastBlock } = await this.updateEvents();
const subdomains = Object.values(this.relayerEnsSubdomains);
const registerSet = new Set();
const uniqueRegisters = registerEvents.filter(({ ensName }) => {
const uniqueRegisters = events.filter(({ ensName }) => {
if (!registerSet.has(ensName)) {
registerSet.add(ensName);
return true;
@ -908,20 +911,20 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
const [relayersData, timestamp] = await Promise.all([
this.Aggregator.relayersData.staticCall(relayerNameHashes, subdomains.concat('tovarish-relayer')),
this.provider.getBlock('latest').then((b) => Number(b?.timestamp)),
this.provider.getBlock(lastBlock).then((b) => Number(b?.timestamp)),
]);
const relayers = relayersData
.map(({ owner, balance: stakeBalance, records, isRegistered }, index) => {
const { ensName, relayerAddress } = uniqueRegisters[index];
let tovarishUrl = undefined;
let tovarishHost = undefined;
const hostnames = records.reduce((acc, record, recordIndex) => {
if (record) {
// tovarish-relayer.relayer.eth
if (recordIndex === records.length - 1) {
tovarishUrl = record;
tovarishHost = record;
return acc;
}
@ -943,7 +946,7 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
owner,
stakeBalance: formatEther(stakeBalance),
hostnames,
tovarishUrl,
tovarishHost,
} as CachedRelayerInfo;
}
})
@ -952,6 +955,7 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
await getTovarishNetworks(this, relayers);
return {
lastBlock,
timestamp,
relayers,
};
@ -961,29 +965,29 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
* Handle saving relayers
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async saveRelayers({ timestamp, relayers }: CachedRelayers) {}
async saveRelayers({ lastBlock, timestamp, relayers }: CachedRelayers) {}
/**
* Get cached or latest relayer and save to local
*/
async updateRelayers(): Promise<CachedRelayers> {
// eslint-disable-next-line prefer-const
let { timestamp, relayers, fromCache } = await this.getSavedRelayers();
let { lastBlock, 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());
({ lastBlock, timestamp, relayers } = await this.getLatestRelayers());
shouldSave = true;
}
if (shouldSave) {
await this.saveRelayers({ timestamp, relayers });
await this.saveRelayers({ lastBlock, timestamp, relayers });
}
return { timestamp, relayers };
return { lastBlock, timestamp, relayers };
}
}