From bbdf0fbea3c7fc2043b8180abc9872974d5bb5fe Mon Sep 17 00:00:00 2001 From: Theodike <44587268+Theodikes@users.noreply.github.com> Date: Fri, 14 Apr 2023 20:06:39 +0300 Subject: [PATCH] Remove duplicate function updateCache --- cli.js | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/cli.js b/cli.js index e1930e0..9b2cfc8 100755 --- a/cli.js +++ b/cli.js @@ -931,6 +931,17 @@ async function fetchEvents({ type, currency, amount }) { console.log('Loaded cached', amount, currency.toUpperCase(), type, 'events for', startBlock, 'block'); console.log('Fetching', amount, currency.toUpperCase(), type, 'events for', netName, 'network'); + async function updateCache(fetchedEvents) { + try { + const fileName = `./cache/${netName.toLowerCase()}/${type}s_${currency}_${amount}.json`; + const localEvents = await initJson(fileName); + const events = localEvents.concat(fetchedEvents); + await fs.writeFileSync(fileName, JSON.stringify(events, null, 2), 'utf8'); + } catch (error) { + throw new Error('Writing cache file failed:', error); + } + } + async function syncEvents() { try { let targetBlock = await web3.eth.getBlockNumber(); @@ -1005,18 +1016,8 @@ async function fetchEvents({ type, currency, amount }) { } } - async function updateCache() { - try { - const fileName = `./cache/${netName.toLowerCase()}/${type}s_${currency}_${amount}.json`; - const localEvents = await initJson(fileName); - const events = localEvents.concat(fetchedEvents); - await fs.writeFileSync(fileName, JSON.stringify(events, null, 2), 'utf8'); - } catch (error) { - throw new Error('Writing cache file failed:', error); - } - } await fetchWeb3Events(i); - await updateCache(); + await updateCache(fetchedEvents); } } catch (error) { console.log(error); @@ -1143,17 +1144,6 @@ async function fetchEvents({ type, currency, amount }) { } } - async function updateCache(fetchedEvents) { - try { - const fileName = `./cache/${netName.toLowerCase()}/${type}s_${currency}_${amount}.json`; - const localEvents = await initJson(fileName); - const events = localEvents.concat(fetchedEvents); - await fs.writeFileSync(fileName, JSON.stringify(events, null, 2), 'utf8'); - } catch (error) { - throw new Error('Writing cache file failed:', error); - } - } - async function fetchGraphEvents() { console.log('Querying latest events from TheGraph'); const latestTimestamp = await queryLatestTimestamp();