daemon/indexing/listener/listener.js
async function liveTracking(config) {
  setupOriginJS(config)
  const context = await new Context(config).init()

  let lastLogBlock = getLastBlock(config)
  let lastCheckedBlock = 0
  const checkIntervalSeconds = 5
  let start

  const check = async () => {
    await withRetrys(async () => {
      start = new Date()
      const currentBlockNumber = await web3.eth.getBlockNumber()
      if (currentBlockNumber == lastCheckedBlock) {
        console.log('No new block.')
        return scheduleNextCheck()
      }
      console.log('New block: ' + currentBlockNumber)
      const toBlock = Math.min(lastLogBlock+MAX_BATCH_BLOCKS, currentBlockNumber)
      const opts = { fromBlock: lastLogBlock + 1, toBlock: toBlock }
      await runBatch(opts, context)
      lastLogBlock = toBlock
      setLastBlock(config, toBlock)
      lastCheckedBlock = currentBlockNumber
      return scheduleNextCheck()
    })
  }
  const scheduleNextCheck = async () => {
    const elapsed = new Date() - start
    const delay = Math.max(checkIntervalSeconds * 1000 - elapsed, 1)
    setTimeout(check, delay)
  }

  check()
}
async function liveTracking(config) {
  setupOriginJS(config)
  const context = await new Context(config).init()

  let lastLogBlock = getLastBlock(config)
  let lastCheckedBlock = 0
  const checkIntervalSeconds = 5
  let start

  const check = async () => {
    await withRetrys(async () => {
      start = new Date()
      const currentBlockNumber = await web3.eth.getBlockNumber()
      if (currentBlockNumber == lastCheckedBlock) {
        console.log('No new block.')
        return scheduleNextCheck()
      }
      console.log('New block: ' + currentBlockNumber)
      const toBlock = Math.min(lastLogBlock+MAX_BATCH_BLOCKS, currentBlockNumber)
      const opts = { fromBlock: lastLogBlock + 1, toBlock: toBlock }
      await runBatch(opts, context)
      lastLogBlock = toBlock
      setLastBlock(config, toBlock)
      lastCheckedBlock = currentBlockNumber
      return scheduleNextCheck()
    })
  }
  const scheduleNextCheck = async () => {
    const elapsed = new Date() - start
    const delay = Math.max(checkIntervalSeconds * 1000 - elapsed, 1)
    setTimeout(check, delay)
  }

  check()
}
async function liveTracking ( config ) { setupOriginJS ( config ) const context = await new Context ( config ) . init ( ) let lastLogBlock = getLastBlock ( config ) let lastCheckedBlock = 0 const checkIntervalSeconds = 5 let start const check = async ( ) => { await withRetrys ( async ( ) => { start = new Date ( ) const currentBlockNumber = await web3 . eth . getBlockNumber ( ) if ( currentBlockNumber == lastCheckedBlock ) { console . log ( 'No new block.' ) return scheduleNextCheck ( ) } console . log ( 'New block: ' + currentBlockNumber ) const toBlock = Math . min ( lastLogBlock + MAX_BATCH_BLOCKS , currentBlockNumber ) const opts = { fromBlock : lastLogBlock + 1 , toBlock : toBlock } await runBatch ( opts , context ) lastLogBlock = toBlock setLastBlock ( config , toBlock ) lastCheckedBlock = currentBlockNumber return scheduleNextCheck ( ) } ) } const scheduleNextCheck = async ( ) => { const elapsed = new Date ( ) - start const delay = Math . max ( checkIntervalSeconds * 1000 - elapsed , 1 ) setTimeout ( check , delay ) } check ( ) }
liveTracking - checks for a new block every checkIntervalSeconds - if new block appeared, look for all events after the last found event
liveTracking - checks for a new block every checkIntervalSeconds - if new block appeared look for all events after the last found event