static cache should be prefixed by network

Signed-off-by: AlienTornadosaurusHex <>
This commit is contained in:
AlienTornadosaurusHex 2023-05-12 22:19:58 +00:00
parent e49e3e0c0d
commit ad0d1391dc
120 changed files with 81 additions and 43 deletions

View file

@ -4,7 +4,7 @@ import Web3 from 'web3'
import networkConfig from '../../networkConfig'
export async function download({ name, directory, contentType }) {
export function download({ name, directory }) {
const path = `${directory}${name}.gz`.toLowerCase()
const data = fs.readFileSync(path)
@ -13,16 +13,16 @@ export async function download({ name, directory, contentType }) {
return content
}
export async function loadCachedEvents({ name, directory, deployedBlock }) {
export function loadCachedEvents({ name, directory, deployedBlock }) {
try {
const module = await download({ contentType: 'string', directory, name })
const module = download({ contentType: 'string', directory, name })
if (module) {
const events = JSON.parse(module)
return {
events,
lastBlock: events[events.length - 1].blockNumber
lastBlock: events[events.length - 1].blockNumber
}
}
} catch (err) {
@ -67,6 +67,7 @@ export async function getPastEvents({ type, fromBlock, netId, events, contractAt
}
console.log(`Fetching ${type}, chainId - ${netId}`, `chunksCount - ${chunksCount}`)
for (let i = 0; i < chunksCount; i++)
try {
await new Promise((resolve) => setTimeout(resolve, 200))

View file

@ -1,14 +1,11 @@
import fs from 'fs'
import zlib from 'zlib'
export async function save(filePath) {
const directories = filePath.split('/')
const fileName = directories[directories.length - 1]
export function save(filePath) {
try {
const data = fs.readFileSync(`${filePath}`)
const payload = await zlib.deflateSync(data, {
const payload = zlib.deflateSync(data, {
level: zlib.constants.Z_BEST_COMPRESSION,
strategy: zlib.constants.Z_FILTERED
})