update: events

This commit is contained in:
Pasha8914 2022-06-13 17:13:54 +10:00 committed by Danil Kovtonyuk
parent f0e38035e7
commit 72b87db11f
48 changed files with 25 additions and 29 deletions

@ -53,6 +53,7 @@ yarn update:zip
```
yarn update:events 56
yarn update:encrypted 56
yarn update:zip
```

@ -50,10 +50,13 @@ export const addressType = { type: 'string', pattern: '^0x[a-fA-F0-9]{40}$' }
// TODO auto update in yarn updateCache
export const cachedEventsLength = {
mainnet: {
ENCRYPTED_NOTES: 16890
ENCRYPTED_NOTES: 16898
},
goerli: {
ENCRYPTED_NOTES: 1366
ENCRYPTED_NOTES: 1662
},
bsc: {
ENCRYPTED_NOTES: 11333
}
}

@ -39,7 +39,7 @@ class IndexedDB {
return
}
this.db = await openDB(this.dbName, 32, this.options) // version (optional): Schema version, or undefined to open the current version.
this.db = await openDB(this.dbName, 33, this.options) // version (optional): Schema version, or undefined to open the current version.
this.onEventHandler()
this.dbExists = true

@ -1,6 +1,7 @@
import fs from 'fs'
import Jszip from 'jszip'
import Web3 from 'web3'
import networkConfig from '../../networkConfig'
const jszip = new Jszip()
@ -48,9 +49,15 @@ export async function loadCachedEvents({ name, directory, deployedBlock }) {
}
}
export async function getPastEvents({ type, fromBlock, netId, events, rpcUrl, contractAttrs }) {
export async function getPastEvents({ type, fromBlock, netId, events, contractAttrs }) {
let downloadedEvents = events
let [{ url: rpcUrl }] = Object.values(networkConfig[`netId${netId}`].rpcUrls)
if (netId === '5') {
rpcUrl = `https://goerli.infura.io/v3/${process.env.INFURA_KEY}`
}
const provider = new Web3.providers.HttpProvider(rpcUrl)
const web3 = new Web3(provider)
const contract = new web3.eth.Contract(...contractAttrs)

@ -18,12 +18,6 @@ async function saveEncryptedNote(netId) {
'tornado-proxy-light.contract.tornadocash.eth': lightProxy
} = networkConfig[`netId${netId}`]
let [{ url: rpcUrl }] = Object.values(networkConfig[`netId${netId}`].rpcUrls)
if (netId === '5') {
rpcUrl = `https://goerli.infura.io/v3/${process.env.INFURA_KEY}`
}
const contractAddress = tornadoRouter || tornadoProxy || lightProxy
let encryptedEvents = []
@ -39,7 +33,6 @@ async function saveEncryptedNote(netId) {
encryptedEvents = await getPastEvents({
netId,
rpcUrl,
type: 'EncryptedNote',
events: encryptedEvents,
fromBlock: cachedEvents.lastBlock + 1,

@ -9,7 +9,7 @@ import { loadCachedEvents, getPastEvents } from './helpers'
const EVENTS_PATH = './static/events/'
const EVENTS = ['Deposit', 'Withdrawal']
const enabledChains = ['1', '56']
const enabledChains = ['1', '56', '5']
async function main(type, netId) {
const { tokens, nativeCurrency, deployedBlock } = networkConfig[`netId${netId}`]
@ -25,18 +25,11 @@ async function main(type, netId) {
console.log('cachedEvents count - ', cachedEvents.events.length)
console.log('lastBlock - ', cachedEvents.lastBlock)
let [{ url: rpcUrl }] = Object.values(networkConfig[`netId${netId}`].rpcUrls)
if (netId === '5') {
rpcUrl = `https://goerli.infura.io/v3/${process.env.INFURA_KEY}`
}
let events = []
events = await getPastEvents({
type,
netId,
rpcUrl,
events,
contractAttrs: [ABI, _contract],
fromBlock: cachedEvents.lastBlock + 1

@ -11,9 +11,7 @@ function updateEncrypted(netId) {
const file = `${EVENTS_PATH}encrypted_notes_${netId}.json`
save(file)
} catch {
console.warn('Not detected any events files for chainId - ', netId)
}
} catch {}
}
async function updateCommon(netId) {
const { nativeCurrency, tokens } = networkConfig[`netId${netId}`]

Binary file not shown.

@ -451,16 +451,17 @@ const actions = {
let cachedEvents = await dispatch('getEncryptedEventsFromDb', { netId })
const networksWithCache = [1, 5, 56]
const networksWithCache = {
1: cachedEventsLength.mainnet.ENCRYPTED_NOTES,
5: cachedEventsLength.goerli.ENCRYPTED_NOTES,
56: cachedEventsLength.bsc.ENCRYPTED_NOTES
}
const LENGTH_CACHE =
Number(netId) === 1
? cachedEventsLength.mainnet.ENCRYPTED_NOTES
: cachedEventsLength.goerli.ENCRYPTED_NOTES
const LENGTH_CACHE = networksWithCache[Number(netId)]
if (
((isEmptyArray(cachedEvents) || !cachedEvents) && networksWithCache.includes(netId)) ||
(cachedEvents.length < LENGTH_CACHE && networksWithCache.includes(netId))
((isEmptyArray(cachedEvents) || !cachedEvents) && networksWithCache[Number(netId)]) ||
(cachedEvents.length < LENGTH_CACHE && networksWithCache[Number(netId)])
) {
;({ events: cachedEvents } = await dispatch('loadEncryptedEvents', { netId }))
}