From 04623a23e6e49e44443a6c48e1a2d3c50255a649 Mon Sep 17 00:00:00 2001 From: Ayanami Date: Sat, 5 Feb 2022 10:33:25 +0900 Subject: [PATCH] Fixed web3 overflow bug for non-geth rpc nodes --- cli.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cli.js b/cli.js index 9313a86..39722b2 100755 --- a/cli.js +++ b/cli.js @@ -700,7 +700,7 @@ function initJson(file) { return new Promise((resolve, reject) => { fs.readFile(file, 'utf8', (error, data) => { if (error) { - reject(error); + resolve([]); } try { resolve(JSON.parse(data)); @@ -750,10 +750,16 @@ async function fetchEvents({ type, currency, amount}) { for (let i=startBlock; i < targetBlock; i+=chunks) { let fetchedEvents = []; async function fetchLatestEvents(i) { + let j; + if (i+chunks-1 > targetBlock) { + j = targetBlock; + } else { + j = i+chunks-1; + } await tornadoContract.getPastEvents(capitalizeFirstLetter(type), { fromBlock: i, - toBlock: i+chunks-1, - }).then(r => { fetchedEvents = fetchedEvents.concat(r); console.log("Fetched",amount,currency.toUpperCase(),type,"events to block:", i+chunks-1) }, err => { console.error(i + " failed fetching",type,"events from node", err); process.exit(1); }).catch(console.log); + toBlock: j, + }).then(r => { fetchedEvents = fetchedEvents.concat(r); console.log("Fetched",amount,currency.toUpperCase(),type,"events to block:", j) }, err => { console.error(i + " failed fetching",type,"events from node", err); process.exit(1); }).catch(console.log); } async function mapDepositEvents() {