forked from tornado-packages/tornado-core
Add block num params for relayers event
This commit is contained in:
parent
bdcf48db73
commit
be0e2419aa
5
dist/events/base.d.ts
vendored
5
dist/events/base.d.ts
vendored
@ -184,10 +184,11 @@ export interface CachedRelayerInfo extends RelayerParams {
|
|||||||
owner?: string;
|
owner?: string;
|
||||||
stakeBalance?: string;
|
stakeBalance?: string;
|
||||||
hostnames: SubdomainMap;
|
hostnames: SubdomainMap;
|
||||||
tovarishUrl?: string;
|
tovarishHost?: string;
|
||||||
tovarishNetworks?: number[];
|
tovarishNetworks?: number[];
|
||||||
}
|
}
|
||||||
export interface CachedRelayers {
|
export interface CachedRelayers {
|
||||||
|
lastBlock: number;
|
||||||
timestamp: number;
|
timestamp: number;
|
||||||
relayers: CachedRelayerInfo[];
|
relayers: CachedRelayerInfo[];
|
||||||
fromCache?: boolean;
|
fromCache?: boolean;
|
||||||
@ -232,7 +233,7 @@ export declare class BaseRegistryService extends BaseEventsService<RegistersEven
|
|||||||
/**
|
/**
|
||||||
* Handle saving relayers
|
* 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
|
* Get cached or latest relayer and save to local
|
||||||
*/
|
*/
|
||||||
|
29
dist/index.js
vendored
29
dist/index.js
vendored
@ -3290,10 +3290,10 @@ class BaseGovernanceService extends BaseEventsService {
|
|||||||
function getTovarishNetworks(registryService, relayers) {
|
function getTovarishNetworks(registryService, relayers) {
|
||||||
return __async$8(this, null, function* () {
|
return __async$8(this, null, function* () {
|
||||||
yield Promise.all(
|
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;
|
var _a, _b;
|
||||||
try {
|
try {
|
||||||
relayer.tovarishNetworks = yield fetchData(relayer.tovarishUrl, __spreadProps(__spreadValues({}, registryService.fetchDataOptions), {
|
relayer.tovarishNetworks = yield fetchData(relayer.tovarishHost, __spreadProps(__spreadValues({}, registryService.fetchDataOptions), {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
@ -3359,6 +3359,7 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
getRelayersFromDB() {
|
getRelayersFromDB() {
|
||||||
return __async$8(this, null, function* () {
|
return __async$8(this, null, function* () {
|
||||||
return {
|
return {
|
||||||
|
lastBlock: 0,
|
||||||
timestamp: 0,
|
timestamp: 0,
|
||||||
relayers: []
|
relayers: []
|
||||||
};
|
};
|
||||||
@ -3370,6 +3371,7 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
getRelayersFromCache() {
|
getRelayersFromCache() {
|
||||||
return __async$8(this, null, function* () {
|
return __async$8(this, null, function* () {
|
||||||
return {
|
return {
|
||||||
|
lastBlock: 0,
|
||||||
timestamp: 0,
|
timestamp: 0,
|
||||||
relayers: [],
|
relayers: [],
|
||||||
fromCache: true
|
fromCache: true
|
||||||
@ -3387,10 +3389,10 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
}
|
}
|
||||||
getLatestRelayers() {
|
getLatestRelayers() {
|
||||||
return __async$8(this, null, function* () {
|
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 subdomains = Object.values(this.relayerEnsSubdomains);
|
||||||
const registerSet = /* @__PURE__ */ new Set();
|
const registerSet = /* @__PURE__ */ new Set();
|
||||||
const uniqueRegisters = registerEvents.filter(({ ensName }) => {
|
const uniqueRegisters = events.filter(({ ensName }) => {
|
||||||
if (!registerSet.has(ensName)) {
|
if (!registerSet.has(ensName)) {
|
||||||
registerSet.add(ensName);
|
registerSet.add(ensName);
|
||||||
return true;
|
return true;
|
||||||
@ -3400,15 +3402,15 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
const relayerNameHashes = uniqueRegisters.map((r) => ethers.namehash(r.ensName));
|
const relayerNameHashes = uniqueRegisters.map((r) => ethers.namehash(r.ensName));
|
||||||
const [relayersData, timestamp] = yield Promise.all([
|
const [relayersData, timestamp] = yield Promise.all([
|
||||||
this.Aggregator.relayersData.staticCall(relayerNameHashes, subdomains.concat("tovarish-relayer")),
|
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 relayers = relayersData.map(({ owner, balance: stakeBalance, records, isRegistered }, index) => {
|
||||||
const { ensName, relayerAddress } = uniqueRegisters[index];
|
const { ensName, relayerAddress } = uniqueRegisters[index];
|
||||||
let tovarishUrl = void 0;
|
let tovarishHost = void 0;
|
||||||
const hostnames = records.reduce((acc, record, recordIndex) => {
|
const hostnames = records.reduce((acc, record, recordIndex) => {
|
||||||
if (record) {
|
if (record) {
|
||||||
if (recordIndex === records.length - 1) {
|
if (recordIndex === records.length - 1) {
|
||||||
tovarishUrl = record;
|
tovarishHost = record;
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
acc[Number(Object.keys(this.relayerEnsSubdomains)[recordIndex])] = record;
|
acc[Number(Object.keys(this.relayerEnsSubdomains)[recordIndex])] = record;
|
||||||
@ -3426,12 +3428,13 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
owner,
|
owner,
|
||||||
stakeBalance: ethers.formatEther(stakeBalance),
|
stakeBalance: ethers.formatEther(stakeBalance),
|
||||||
hostnames,
|
hostnames,
|
||||||
tovarishUrl
|
tovarishHost
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}).filter((r) => r);
|
}).filter((r) => r);
|
||||||
yield getTovarishNetworks(this, relayers);
|
yield getTovarishNetworks(this, relayers);
|
||||||
return {
|
return {
|
||||||
|
lastBlock,
|
||||||
timestamp,
|
timestamp,
|
||||||
relayers
|
relayers
|
||||||
};
|
};
|
||||||
@ -3442,7 +3445,7 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
saveRelayers(_0) {
|
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() {
|
updateRelayers() {
|
||||||
return __async$8(this, null, function* () {
|
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;
|
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());
|
({ lastBlock, timestamp, relayers } = yield this.getLatestRelayers());
|
||||||
shouldSave = true;
|
shouldSave = true;
|
||||||
}
|
}
|
||||||
if (shouldSave) {
|
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
29
dist/index.mjs
vendored
@ -3269,10 +3269,10 @@ class BaseGovernanceService extends BaseEventsService {
|
|||||||
function getTovarishNetworks(registryService, relayers) {
|
function getTovarishNetworks(registryService, relayers) {
|
||||||
return __async$8(this, null, function* () {
|
return __async$8(this, null, function* () {
|
||||||
yield Promise.all(
|
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;
|
var _a, _b;
|
||||||
try {
|
try {
|
||||||
relayer.tovarishNetworks = yield fetchData(relayer.tovarishUrl, __spreadProps(__spreadValues({}, registryService.fetchDataOptions), {
|
relayer.tovarishNetworks = yield fetchData(relayer.tovarishHost, __spreadProps(__spreadValues({}, registryService.fetchDataOptions), {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
@ -3338,6 +3338,7 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
getRelayersFromDB() {
|
getRelayersFromDB() {
|
||||||
return __async$8(this, null, function* () {
|
return __async$8(this, null, function* () {
|
||||||
return {
|
return {
|
||||||
|
lastBlock: 0,
|
||||||
timestamp: 0,
|
timestamp: 0,
|
||||||
relayers: []
|
relayers: []
|
||||||
};
|
};
|
||||||
@ -3349,6 +3350,7 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
getRelayersFromCache() {
|
getRelayersFromCache() {
|
||||||
return __async$8(this, null, function* () {
|
return __async$8(this, null, function* () {
|
||||||
return {
|
return {
|
||||||
|
lastBlock: 0,
|
||||||
timestamp: 0,
|
timestamp: 0,
|
||||||
relayers: [],
|
relayers: [],
|
||||||
fromCache: true
|
fromCache: true
|
||||||
@ -3366,10 +3368,10 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
}
|
}
|
||||||
getLatestRelayers() {
|
getLatestRelayers() {
|
||||||
return __async$8(this, null, function* () {
|
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 subdomains = Object.values(this.relayerEnsSubdomains);
|
||||||
const registerSet = /* @__PURE__ */ new Set();
|
const registerSet = /* @__PURE__ */ new Set();
|
||||||
const uniqueRegisters = registerEvents.filter(({ ensName }) => {
|
const uniqueRegisters = events.filter(({ ensName }) => {
|
||||||
if (!registerSet.has(ensName)) {
|
if (!registerSet.has(ensName)) {
|
||||||
registerSet.add(ensName);
|
registerSet.add(ensName);
|
||||||
return true;
|
return true;
|
||||||
@ -3379,15 +3381,15 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
const relayerNameHashes = uniqueRegisters.map((r) => namehash(r.ensName));
|
const relayerNameHashes = uniqueRegisters.map((r) => namehash(r.ensName));
|
||||||
const [relayersData, timestamp] = yield Promise.all([
|
const [relayersData, timestamp] = yield Promise.all([
|
||||||
this.Aggregator.relayersData.staticCall(relayerNameHashes, subdomains.concat("tovarish-relayer")),
|
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 relayers = relayersData.map(({ owner, balance: stakeBalance, records, isRegistered }, index) => {
|
||||||
const { ensName, relayerAddress } = uniqueRegisters[index];
|
const { ensName, relayerAddress } = uniqueRegisters[index];
|
||||||
let tovarishUrl = void 0;
|
let tovarishHost = void 0;
|
||||||
const hostnames = records.reduce((acc, record, recordIndex) => {
|
const hostnames = records.reduce((acc, record, recordIndex) => {
|
||||||
if (record) {
|
if (record) {
|
||||||
if (recordIndex === records.length - 1) {
|
if (recordIndex === records.length - 1) {
|
||||||
tovarishUrl = record;
|
tovarishHost = record;
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
acc[Number(Object.keys(this.relayerEnsSubdomains)[recordIndex])] = record;
|
acc[Number(Object.keys(this.relayerEnsSubdomains)[recordIndex])] = record;
|
||||||
@ -3405,12 +3407,13 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
owner,
|
owner,
|
||||||
stakeBalance: formatEther(stakeBalance),
|
stakeBalance: formatEther(stakeBalance),
|
||||||
hostnames,
|
hostnames,
|
||||||
tovarishUrl
|
tovarishHost
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}).filter((r) => r);
|
}).filter((r) => r);
|
||||||
yield getTovarishNetworks(this, relayers);
|
yield getTovarishNetworks(this, relayers);
|
||||||
return {
|
return {
|
||||||
|
lastBlock,
|
||||||
timestamp,
|
timestamp,
|
||||||
relayers
|
relayers
|
||||||
};
|
};
|
||||||
@ -3421,7 +3424,7 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
saveRelayers(_0) {
|
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() {
|
updateRelayers() {
|
||||||
return __async$8(this, null, function* () {
|
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;
|
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());
|
({ lastBlock, timestamp, relayers } = yield this.getLatestRelayers());
|
||||||
shouldSave = true;
|
shouldSave = true;
|
||||||
}
|
}
|
||||||
if (shouldSave) {
|
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
29
dist/tornado.umd.js
vendored
@ -59634,10 +59634,10 @@ class BaseGovernanceService extends BaseEventsService {
|
|||||||
function getTovarishNetworks(registryService, relayers) {
|
function getTovarishNetworks(registryService, relayers) {
|
||||||
return __async(this, null, function* () {
|
return __async(this, null, function* () {
|
||||||
yield Promise.all(
|
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;
|
var _a, _b;
|
||||||
try {
|
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: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
@ -59703,6 +59703,7 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
getRelayersFromDB() {
|
getRelayersFromDB() {
|
||||||
return __async(this, null, function* () {
|
return __async(this, null, function* () {
|
||||||
return {
|
return {
|
||||||
|
lastBlock: 0,
|
||||||
timestamp: 0,
|
timestamp: 0,
|
||||||
relayers: []
|
relayers: []
|
||||||
};
|
};
|
||||||
@ -59714,6 +59715,7 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
getRelayersFromCache() {
|
getRelayersFromCache() {
|
||||||
return __async(this, null, function* () {
|
return __async(this, null, function* () {
|
||||||
return {
|
return {
|
||||||
|
lastBlock: 0,
|
||||||
timestamp: 0,
|
timestamp: 0,
|
||||||
relayers: [],
|
relayers: [],
|
||||||
fromCache: true
|
fromCache: true
|
||||||
@ -59731,10 +59733,10 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
}
|
}
|
||||||
getLatestRelayers() {
|
getLatestRelayers() {
|
||||||
return __async(this, null, function* () {
|
return __async(this, null, function* () {
|
||||||
const registerEvents = (yield this.updateEvents()).events;
|
const { events, lastBlock } = yield this.updateEvents();
|
||||||
const subdomains = Object.values(this.relayerEnsSubdomains);
|
const subdomains = Object.values(this.relayerEnsSubdomains);
|
||||||
const registerSet = /* @__PURE__ */ new Set();
|
const registerSet = /* @__PURE__ */ new Set();
|
||||||
const uniqueRegisters = registerEvents.filter(({ ensName }) => {
|
const uniqueRegisters = events.filter(({ ensName }) => {
|
||||||
if (!registerSet.has(ensName)) {
|
if (!registerSet.has(ensName)) {
|
||||||
registerSet.add(ensName);
|
registerSet.add(ensName);
|
||||||
return true;
|
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 relayerNameHashes = uniqueRegisters.map((r) => (0,ethers__WEBPACK_IMPORTED_MODULE_5__/* .namehash */ .kM)(r.ensName));
|
||||||
const [relayersData, timestamp] = yield Promise.all([
|
const [relayersData, timestamp] = yield Promise.all([
|
||||||
this.Aggregator.relayersData.staticCall(relayerNameHashes, subdomains.concat("tovarish-relayer")),
|
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 relayers = relayersData.map(({ owner, balance: stakeBalance, records, isRegistered }, index) => {
|
||||||
const { ensName, relayerAddress } = uniqueRegisters[index];
|
const { ensName, relayerAddress } = uniqueRegisters[index];
|
||||||
let tovarishUrl = void 0;
|
let tovarishHost = void 0;
|
||||||
const hostnames = records.reduce((acc, record, recordIndex) => {
|
const hostnames = records.reduce((acc, record, recordIndex) => {
|
||||||
if (record) {
|
if (record) {
|
||||||
if (recordIndex === records.length - 1) {
|
if (recordIndex === records.length - 1) {
|
||||||
tovarishUrl = record;
|
tovarishHost = record;
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
acc[Number(Object.keys(this.relayerEnsSubdomains)[recordIndex])] = record;
|
acc[Number(Object.keys(this.relayerEnsSubdomains)[recordIndex])] = record;
|
||||||
@ -59770,12 +59772,13 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
owner,
|
owner,
|
||||||
stakeBalance: (0,ethers__WEBPACK_IMPORTED_MODULE_6__/* .formatEther */ .ck)(stakeBalance),
|
stakeBalance: (0,ethers__WEBPACK_IMPORTED_MODULE_6__/* .formatEther */ .ck)(stakeBalance),
|
||||||
hostnames,
|
hostnames,
|
||||||
tovarishUrl
|
tovarishHost
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}).filter((r) => r);
|
}).filter((r) => r);
|
||||||
yield getTovarishNetworks(this, relayers);
|
yield getTovarishNetworks(this, relayers);
|
||||||
return {
|
return {
|
||||||
|
lastBlock,
|
||||||
timestamp,
|
timestamp,
|
||||||
relayers
|
relayers
|
||||||
};
|
};
|
||||||
@ -59786,7 +59789,7 @@ class BaseRegistryService extends BaseEventsService {
|
|||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
saveRelayers(_0) {
|
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() {
|
updateRelayers() {
|
||||||
return __async(this, null, function* () {
|
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;
|
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());
|
({ lastBlock, timestamp, relayers } = yield this.getLatestRelayers());
|
||||||
shouldSave = true;
|
shouldSave = true;
|
||||||
}
|
}
|
||||||
if (shouldSave) {
|
if (shouldSave) {
|
||||||
yield this.saveRelayers({ timestamp, relayers });
|
yield this.saveRelayers({ lastBlock, timestamp, relayers });
|
||||||
}
|
}
|
||||||
return { timestamp, relayers };
|
return { lastBlock, timestamp, relayers };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
dist/tornado.umd.min.js
vendored
2
dist/tornado.umd.min.js
vendored
File diff suppressed because one or more lines are too long
@ -749,10 +749,10 @@ export class BaseGovernanceService extends BaseEventsService<AllGovernanceEvents
|
|||||||
export async function getTovarishNetworks(registryService: BaseRegistryService, relayers: CachedRelayerInfo[]) {
|
export async function getTovarishNetworks(registryService: BaseRegistryService, relayers: CachedRelayerInfo[]) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
relayers
|
relayers
|
||||||
.filter((r) => r.tovarishUrl)
|
.filter((r) => r.tovarishHost)
|
||||||
.map(async (relayer) => {
|
.map(async (relayer) => {
|
||||||
try {
|
try {
|
||||||
relayer.tovarishNetworks = await fetchData(relayer.tovarishUrl as string, {
|
relayer.tovarishNetworks = await fetchData(relayer.tovarishHost as string, {
|
||||||
...registryService.fetchDataOptions,
|
...registryService.fetchDataOptions,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -778,11 +778,12 @@ export interface CachedRelayerInfo extends RelayerParams {
|
|||||||
owner?: string;
|
owner?: string;
|
||||||
stakeBalance?: string;
|
stakeBalance?: string;
|
||||||
hostnames: SubdomainMap;
|
hostnames: SubdomainMap;
|
||||||
tovarishUrl?: string;
|
tovarishHost?: string;
|
||||||
tovarishNetworks?: number[];
|
tovarishNetworks?: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CachedRelayers {
|
export interface CachedRelayers {
|
||||||
|
lastBlock: number;
|
||||||
timestamp: number;
|
timestamp: number;
|
||||||
relayers: CachedRelayerInfo[];
|
relayers: CachedRelayerInfo[];
|
||||||
fromCache?: boolean;
|
fromCache?: boolean;
|
||||||
@ -863,6 +864,7 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
|
|||||||
*/
|
*/
|
||||||
async getRelayersFromDB(): Promise<CachedRelayers> {
|
async getRelayersFromDB(): Promise<CachedRelayers> {
|
||||||
return {
|
return {
|
||||||
|
lastBlock: 0,
|
||||||
timestamp: 0,
|
timestamp: 0,
|
||||||
relayers: [],
|
relayers: [],
|
||||||
};
|
};
|
||||||
@ -873,6 +875,7 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
|
|||||||
*/
|
*/
|
||||||
async getRelayersFromCache(): Promise<CachedRelayers> {
|
async getRelayersFromCache(): Promise<CachedRelayers> {
|
||||||
return {
|
return {
|
||||||
|
lastBlock: 0,
|
||||||
timestamp: 0,
|
timestamp: 0,
|
||||||
relayers: [],
|
relayers: [],
|
||||||
fromCache: true,
|
fromCache: true,
|
||||||
@ -890,13 +893,13 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getLatestRelayers(): Promise<CachedRelayers> {
|
async getLatestRelayers(): Promise<CachedRelayers> {
|
||||||
const registerEvents = (await this.updateEvents()).events;
|
const { events, lastBlock } = await this.updateEvents();
|
||||||
|
|
||||||
const subdomains = Object.values(this.relayerEnsSubdomains);
|
const subdomains = Object.values(this.relayerEnsSubdomains);
|
||||||
|
|
||||||
const registerSet = new Set();
|
const registerSet = new Set();
|
||||||
|
|
||||||
const uniqueRegisters = registerEvents.filter(({ ensName }) => {
|
const uniqueRegisters = events.filter(({ ensName }) => {
|
||||||
if (!registerSet.has(ensName)) {
|
if (!registerSet.has(ensName)) {
|
||||||
registerSet.add(ensName);
|
registerSet.add(ensName);
|
||||||
return true;
|
return true;
|
||||||
@ -908,20 +911,20 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
|
|||||||
|
|
||||||
const [relayersData, timestamp] = await Promise.all([
|
const [relayersData, timestamp] = await Promise.all([
|
||||||
this.Aggregator.relayersData.staticCall(relayerNameHashes, subdomains.concat('tovarish-relayer')),
|
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
|
const relayers = relayersData
|
||||||
.map(({ owner, balance: stakeBalance, records, isRegistered }, index) => {
|
.map(({ owner, balance: stakeBalance, records, isRegistered }, index) => {
|
||||||
const { ensName, relayerAddress } = uniqueRegisters[index];
|
const { ensName, relayerAddress } = uniqueRegisters[index];
|
||||||
|
|
||||||
let tovarishUrl = undefined;
|
let tovarishHost = undefined;
|
||||||
|
|
||||||
const hostnames = records.reduce((acc, record, recordIndex) => {
|
const hostnames = records.reduce((acc, record, recordIndex) => {
|
||||||
if (record) {
|
if (record) {
|
||||||
// tovarish-relayer.relayer.eth
|
// tovarish-relayer.relayer.eth
|
||||||
if (recordIndex === records.length - 1) {
|
if (recordIndex === records.length - 1) {
|
||||||
tovarishUrl = record;
|
tovarishHost = record;
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -943,7 +946,7 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
|
|||||||
owner,
|
owner,
|
||||||
stakeBalance: formatEther(stakeBalance),
|
stakeBalance: formatEther(stakeBalance),
|
||||||
hostnames,
|
hostnames,
|
||||||
tovarishUrl,
|
tovarishHost,
|
||||||
} as CachedRelayerInfo;
|
} as CachedRelayerInfo;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -952,6 +955,7 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
|
|||||||
await getTovarishNetworks(this, relayers);
|
await getTovarishNetworks(this, relayers);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
lastBlock,
|
||||||
timestamp,
|
timestamp,
|
||||||
relayers,
|
relayers,
|
||||||
};
|
};
|
||||||
@ -961,29 +965,29 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
|
|||||||
* Handle saving relayers
|
* Handle saving relayers
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// 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
|
* Get cached or latest relayer and save to local
|
||||||
*/
|
*/
|
||||||
async updateRelayers(): Promise<CachedRelayers> {
|
async updateRelayers(): Promise<CachedRelayers> {
|
||||||
// eslint-disable-next-line prefer-const
|
// 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;
|
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());
|
({ lastBlock, timestamp, relayers } = await this.getLatestRelayers());
|
||||||
|
|
||||||
shouldSave = true;
|
shouldSave = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldSave) {
|
if (shouldSave) {
|
||||||
await this.saveRelayers({ timestamp, relayers });
|
await this.saveRelayers({ lastBlock, timestamp, relayers });
|
||||||
}
|
}
|
||||||
|
|
||||||
return { timestamp, relayers };
|
return { lastBlock, timestamp, relayers };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user