Use subgraph to fetch deposit events and registry events #31

Merged
Theo merged 1 commits from tornadocontrib/classic-ui:light into development 2024-05-05 20:24:25 +03:00
2 changed files with 19 additions and 5 deletions
Showing only changes of commit 2cf3b33b62 - Show all commits

View File

@ -412,10 +412,11 @@ class EventService {
async getEventsFromBlock({ fromBlock, graphMethod, type }) { async getEventsFromBlock({ fromBlock, graphMethod, type }) {
try { try {
// ToDo think about undefined // ToDo think about undefined
const rpcEvents = await this.getEventsFromRpc({ fromBlock, type }) const graphEvents = await this.getEventsFromGraph({ fromBlock, methodName: graphMethod })
const lastSyncBlock = fromBlock > graphEvents?.lastBlock ? fromBlock : graphEvents?.lastBlock
const allEvents = [].concat(rpcEvents || []) const rpcEvents = await this.getEventsFromRpc({ fromBlock: lastSyncBlock, type })
const allEvents = [].concat(graphEvents?.events || [], rpcEvents || [])
if (allEvents.length) { if (allEvents.length) {
return { return {
events: allEvents, events: allEvents,

View File

@ -3,6 +3,7 @@ import namehash from 'eth-ens-namehash'
import { BigNumber as BN } from 'bignumber.js' import { BigNumber as BN } from 'bignumber.js'
import { toChecksumAddress, isAddress } from 'web3-utils' import { toChecksumAddress, isAddress } from 'web3-utils'
import { graph } from '@/services'
import networkConfig from '@/networkConfig' import networkConfig from '@/networkConfig'
import { REGISTRY_DEPLOYED_BLOCK } from '@/constants' import { REGISTRY_DEPLOYED_BLOCK } from '@/constants'
import { sleep, flattenNArray } from '@/utils' import { sleep, flattenNArray } from '@/utils'
@ -169,9 +170,21 @@ class RelayerRegister {
fetchRelayers = async () => { fetchRelayers = async () => {
const blockRange = 10000 const blockRange = 10000
// eslint-disable-next-line prefer-const // eslint-disable-next-line prefer-const
let { blockTo, cachedEvents } = await this.getCachedData() let { blockFrom, blockTo, cachedEvents } = await this.getCachedData()
let allRelayers = cachedEvents let allRelayers = cachedEvents
if (!cachedEvents || !cachedEvents.length) {
const { lastSyncBlock, events } = await graph.getAllRegisters(blockFrom)
if (events.length) {
blockTo = lastSyncBlock + 1
cachedEvents = events.map((el) => ({
ensName: el.ensName,
relayerAddress: toChecksumAddress(el.address)
}))
}
}
const currentBlockNumber = await this.provider.getBlockNumber() const currentBlockNumber = await this.provider.getBlockNumber()
const fromBlock = cachedEvents.length === 0 ? REGISTRY_DEPLOYED_BLOCK[1] : blockTo const fromBlock = cachedEvents.length === 0 ? REGISTRY_DEPLOYED_BLOCK[1] : blockTo
const blockDifference = currentBlockNumber - fromBlock const blockDifference = currentBlockNumber - fromBlock
@ -181,7 +194,7 @@ class RelayerRegister {
let registerRelayerEvents let registerRelayerEvents
let lastSyncBlock = blockTo let lastSyncBlock = blockTo
if (cachedEvents.length > 0 || blockDifference === 0) { if (blockDifference <= 0) {
return cachedEvents return cachedEvents
} else if (blockDifference >= blockRange) { } else if (blockDifference >= blockRange) {
toBlock = currentBlockNumber toBlock = currentBlockNumber