import { initializeEthersJS } from './initializeEthersJS' ; import { ethers } from 'ethers' ; import { Logger } from '@nestjs/common' ; export async function getEvents ( firstBlock , lastMinedBlock , logger ) { const BLOCKS_TO_PROCESS_AT_TIME = 1000 ; let currentBlock = firstBlock ; const allEvents = [ ] ; const { provider , pixelMap , pixelMapWrapper } = initializeEthersJS ( ) ; const tileUpdatedFilter = pixelMap . filters . TileUpdated ( ) ; const transferFilter = pixelMapWrapper . filters . Transfer ( ) ; const unwrappedFilter = pixelMapWrapper . filters . Unwrapped ( ) ; const wrappedFilter = pixelMapWrapper . filters . Wrapped ( ) ; while ( currentBlock < lastMinedBlock ) { let toBlock = currentBlock + BLOCKS_TO_PROCESS_AT_TIME ; if ( toBlock > lastMinedBlock ) { toBlock = lastMinedBlock ; } const tileUpdatedEvents = await pixelMap . queryFilter ( tileUpdatedFilter , currentBlock , toBlock ) ; const transferEvents = await pixelMapWrapper . queryFilter ( transferFilter , currentBlock , toBlock ) ; const unwrappedEvents = await pixelMapWrapper . queryFilter ( unwrappedFilter , currentBlock , toBlock ) ; const wrappedEvents = await pixelMapWrapper . queryFilter ( wrappedFilter , currentBlock , toBlock ) ; allEvents . push ( ... tileUpdatedEvents ) ; allEvents . push ( ... transferEvents ) ; allEvents . push ( ... unwrappedEvents ) ; allEvents . push ( ... wrappedEvents ) ; logger . log ( 'Scanning (inclusive) from: ' + currentBlock + ' to ' + toBlock + '.  Total events so far: ' + allEvents . length ) ; currentBlock = toBlock + 1 ; } const sorted = allEvents . sort ( ( a , b ) => a . blockNumber > b . blockNumber ? 1 : a . blockNumber === b . blockNumber ? a . transactionIndex > b . transactionIndex ? 1 : - 1 : - 1 ) ; return sorted ; }