Use subgraph to fetch deposit events and registry events #31
@ -412,10 +412,11 @@ class EventService {
|
||||
async getEventsFromBlock({ fromBlock, graphMethod, type }) {
|
||||
try {
|
||||
// ToDo think about undefined
|
||||
const rpcEvents = await this.getEventsFromRpc({ fromBlock, type })
|
||||
|
||||
const allEvents = [].concat(rpcEvents || [])
|
||||
const graphEvents = await this.getEventsFromGraph({ fromBlock, methodName: graphMethod })
|
||||
const lastSyncBlock = fromBlock > graphEvents?.lastBlock ? fromBlock : graphEvents?.lastBlock
|
||||
const rpcEvents = await this.getEventsFromRpc({ fromBlock: lastSyncBlock, type })
|
||||
|
||||
const allEvents = [].concat(graphEvents?.events || [], rpcEvents || [])
|
||||
if (allEvents.length) {
|
||||
return {
|
||||
events: allEvents,
|
||||
|
@ -3,6 +3,7 @@ import namehash from 'eth-ens-namehash'
|
||||
import { BigNumber as BN } from 'bignumber.js'
|
||||
import { toChecksumAddress, isAddress } from 'web3-utils'
|
||||
|
||||
import { graph } from '@/services'
|
||||
import networkConfig from '@/networkConfig'
|
||||
import { REGISTRY_DEPLOYED_BLOCK } from '@/constants'
|
||||
import { sleep, flattenNArray } from '@/utils'
|
||||
@ -169,9 +170,21 @@ class RelayerRegister {
|
||||
fetchRelayers = async () => {
|
||||
const blockRange = 10000
|
||||
// eslint-disable-next-line prefer-const
|
||||
let { blockTo, cachedEvents } = await this.getCachedData()
|
||||
let { blockFrom, blockTo, cachedEvents } = await this.getCachedData()
|
||||
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 fromBlock = cachedEvents.length === 0 ? REGISTRY_DEPLOYED_BLOCK[1] : blockTo
|
||||
const blockDifference = currentBlockNumber - fromBlock
|
||||
@ -181,7 +194,7 @@ class RelayerRegister {
|
||||
let registerRelayerEvents
|
||||
let lastSyncBlock = blockTo
|
||||
|
||||
if (cachedEvents.length > 0 || blockDifference === 0) {
|
||||
if (blockDifference <= 0) {
|
||||
return cachedEvents
|
||||
} else if (blockDifference >= blockRange) {
|
||||
toBlock = currentBlockNumber
|
||||
|
Loading…
x
Reference in New Issue
Block a user