daemon/indexing/listener/listener.js
async function runBatch(opts, context) {
  const fromBlock = opts.fromBlock
  const toBlock = opts.toBlock
  let lastLogBlock = undefined

  console.log(
    'Looking for logs from block ' + fromBlock + ' to ' + (toBlock || 'Latest')
  )

  const eventTopics = Object.keys(context.signatureToRules)
  const logs = await web3.eth.getPastLogs({
    fromBlock: web3.utils.toHex(fromBlock), // Hex required for infura
    toBlock: toBlock ? web3.utils.toHex(toBlock) : "latest",  // Hex required for infura
    topics: [eventTopics]
  })

  if (logs.length > 0) {
    console.log('' + logs.length + ' logs found')
  }

  for (const log of logs) {
    const contractVersion = context.addressToVersion[log.address]
    if (contractVersion == undefined) {
      continue // Skip - Not a trusted contract
    }
    const contractName = contractVersion.contractName
    const rule = context.signatureToRules[log.topics[0]][contractName]
    if (rule == undefined) {
      continue // Skip - No handler defined
    }
    lastLogBlock = log.blockNumber
    // Process it
    await handleLog(log, rule, contractVersion, context)
  }
  return lastLogBlock
}
async function runBatch(opts, context) {
  const fromBlock = opts.fromBlock
  const toBlock = opts.toBlock
  let lastLogBlock = undefined

  console.log(
    'Looking for logs from block ' + fromBlock + ' to ' + (toBlock || 'Latest')
  )

  const eventTopics = Object.keys(context.signatureToRules)
  const logs = await web3.eth.getPastLogs({
    fromBlock: web3.utils.toHex(fromBlock), // Hex required for infura
    toBlock: toBlock ? web3.utils.toHex(toBlock) : "latest",  // Hex required for infura
    topics: [eventTopics]
  })

  if (logs.length > 0) {
    console.log('' + logs.length + ' logs found')
  }

  for (const log of logs) {
    const contractVersion = context.addressToVersion[log.address]
    if (contractVersion == undefined) {
      continue // Skip - Not a trusted contract
    }
    const contractName = contractVersion.contractName
    const rule = context.signatureToRules[log.topics[0]][contractName]
    if (rule == undefined) {
      continue // Skip - No handler defined
    }
    lastLogBlock = log.blockNumber
    // Process it
    await handleLog(log, rule, contractVersion, context)
  }
  return lastLogBlock
}
async function runBatch ( opts , context ) { const fromBlock = opts . fromBlock const toBlock = opts . toBlock let lastLogBlock = undefined console . log ( 'Looking for logs from block ' + fromBlock + ' to ' + ( toBlock || 'Latest' ) ) const eventTopics = Object . keys ( context . signatureToRules ) const logs = await web3 . eth . getPastLogs ( { fromBlock : web3 . utils . toHex ( fromBlock ) , // Hex required for infura toBlock : toBlock ? web3 . utils . toHex ( toBlock ) : "latest" , // Hex required for infura topics : [ eventTopics ] } ) if ( logs . length > 0 ) { console . log ( '' + logs . length + ' logs found' ) } for ( const log of logs ) { const contractVersion = context . addressToVersion [ log . address ] if ( contractVersion == undefined ) { continue // Skip - Not a trusted contract } const contractName = contractVersion . contractName const rule = context . signatureToRules [ log . topics [ 0 ] ] [ contractName ] if ( rule == undefined ) { continue // Skip - No handler defined } lastLogBlock = log . blockNumber // Process it await handleLog ( log , rule , contractVersion , context ) } return lastLogBlock }
runBatch - gets and processes logs for a range of blocks
runBatch - gets and processes logs for a range of blocks