Remove duplicate function updateCache

This commit is contained in:
Theodike 2023-04-14 20:06:39 +03:00
parent 85c5bdc13f
commit bbdf0fbea3

34
cli.js
View File

@ -931,6 +931,17 @@ async function fetchEvents({ type, currency, amount }) {
console.log('Loaded cached', amount, currency.toUpperCase(), type, 'events for', startBlock, 'block'); console.log('Loaded cached', amount, currency.toUpperCase(), type, 'events for', startBlock, 'block');
console.log('Fetching', amount, currency.toUpperCase(), type, 'events for', netName, 'network'); 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() { async function syncEvents() {
try { try {
let targetBlock = await web3.eth.getBlockNumber(); 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 fetchWeb3Events(i);
await updateCache(); await updateCache(fetchedEvents);
} }
} catch (error) { } catch (error) {
console.log(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() { async function fetchGraphEvents() {
console.log('Querying latest events from TheGraph'); console.log('Querying latest events from TheGraph');
const latestTimestamp = await queryLatestTimestamp(); const latestTimestamp = await queryLatestTimestamp();