src/blockchain/watcher.js
/**
   * Fetch all events between now and the latest block
   *
   * @param  {Number} [fromBlockNum=lastForeignBlock] The block from which onwards should the events be checked
   * @param  {Number} [toBlockNum=lastForeignBlock+1] No events after this block should be returned
   *
   * @return {Promise} Resolves to an array of events between speciefied block and latest known block.
   */
Fetch all events between now and the latest block
@param  {Number} [fromBlockNum=lastForeignBlock] The block from which onwards should the events be checked
@param  {Number} [toBlockNum=lastForeignBlock+1] No events after this block should be returned

@return {Promise} Resolves to an array of events between speciefied block and latest known block.
Fetch all events between now and the latest block @param { Number } [ fromBlockNum = lastForeignBlock ] The block from which onwards should the events be checked @param { Number } [ toBlockNum = lastForeignBlock + 1 ] No events after this block should be returned @return { Promise } Resolves to an array of events between speciefied block and latest known block .
async function fetchPastForeignEvents(
    fromBlockNum = lastForeignBlock,
    toBlockNum = lastForeignBlock + 1,
  ) {
    const fromBlock = toHex(fromBlockNum) || toHex(1); 
    const toBlock = toHex(toBlockNum) || toHex(1); 
    const events = [].concat(
      await liquidPledging.$contract.getPastEvents({ fromBlock, toBlock }),
      await kernel.$contract.getPastEvents({
        fromBlock,
        toBlock,
        filter: {
          namespace: keccak256('base'),
          name: [
            keccak256('lpp-capped-milestone'),
            keccak256('lpp-lp-milestone'),
            keccak256('lpp-bridged-milestone'),
            keccak256('lpp-campaign'),
          ],
        },
      }),
      await web3.eth
        .getPastLogs({
          fromBlock,
          toBlock,
          topics: getMilestoneTopics(),
        })
        .then(evnts => evnts.map(e => milestoneEventDecoder(e))),
      await lpVault.$contract.getPastEvents({ fromBlock, toBlock }),
    );
    return events.map(e => {
      return { ...e, isHomeEvent: false };
    });
  }
async function fetchPastForeignEvents ( fromBlockNum = lastForeignBlock , toBlockNum = lastForeignBlock + 1 , ) { const fromBlock = toHex ( fromBlockNum ) || toHex ( 1 ) ; const toBlock = toHex ( toBlockNum ) || toHex ( 1 ) ; const events = [ ] . concat ( await liquidPledging . $contract . getPastEvents ( { fromBlock , toBlock } ) , await kernel . $contract . getPastEvents ( { fromBlock , toBlock , filter : { namespace : keccak256 ( 'base' ) , name : [ keccak256 ( 'lpp-capped-milestone' ) , keccak256 ( 'lpp-lp-milestone' ) , keccak256 ( 'lpp-bridged-milestone' ) , keccak256 ( 'lpp-campaign' ) , ] , } , } ) , await web3 . eth . getPastLogs ( { fromBlock , toBlock , topics : getMilestoneTopics ( ) , } ) . then ( evnts => evnts . map ( e => milestoneEventDecoder ( e ) ) ) , await lpVault . $contract . getPastEvents ( { fromBlock , toBlock } ) , ) ; return events . map ( e => { return { ... e , isHomeEvent : false } ; } ) ; }
Fetch all events between now and the latest block
 @param  {Number} [fromBlockNum=lastForeignBlock] The block from which onwards should the events be checked
 @param  {Number} [toBlockNum=lastForeignBlock+1] No events after this block should be returned
Fetch all events between now and the latest block @param { Number } [ fromBlockNum = lastForeignBlock ] The block from which onwards should the events be checked @param { Number } [ toBlockNum = lastForeignBlock + 1 ] No events after this block should be returned
// convert to hex due to web3 bug https://github.com/ethereum/web3.js/issues/1097 // convert to hex due to web3 bug https://github.com/ethereum/web3.js/issues/1097 // Get the events from contracts