forked from tornadocash/nova-ui
Compare commits
No commits in common. "d31a957fb42ce71c5cc26473a5b6712e72a7925e" and "11ee25dbce8c0fe24beffb828ad8a4a425accafc" have entirely different histories.
d31a957fb4
...
11ee25dbce
@ -2,12 +2,6 @@
|
|||||||
|
|
||||||
## Build Setup
|
## Build Setup
|
||||||
|
|
||||||
If you use the latest Node.js version, you should modify your NODE_OPTIONS env
|
|
||||||
|
|
||||||
```bash
|
|
||||||
export NODE_OPTIONS="--openssl-legacy-provider"
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# install dependencies
|
# install dependencies
|
||||||
$ yarn install
|
$ yarn install
|
||||||
|
|||||||
@ -11,7 +11,6 @@ import { ExtendedProvider } from './services/provider'
|
|||||||
import { POOL_CONTRACT, RPC_LIST, FALLBACK_RPC_LIST, workerEvents, numbers } from './services/constants'
|
import { POOL_CONTRACT, RPC_LIST, FALLBACK_RPC_LIST, workerEvents, numbers } from './services/constants'
|
||||||
import { sleep } from './services/utilities'
|
import { sleep } from './services/utilities'
|
||||||
import { poolAbi } from './services/pool'
|
import { poolAbi } from './services/pool'
|
||||||
import { downloadEvents } from './services/downloadEvents'
|
|
||||||
|
|
||||||
const getProviderWithSigner = (chainId) => {
|
const getProviderWithSigner = (chainId) => {
|
||||||
return new ExtendedProvider(RPC_LIST[chainId], chainId, FALLBACK_RPC_LIST[chainId])
|
return new ExtendedProvider(RPC_LIST[chainId], chainId, FALLBACK_RPC_LIST[chainId])
|
||||||
@ -166,14 +165,6 @@ const getCommitments = async ({ withCache, lastSyncBlock }) => {
|
|||||||
return { commitmentEvents: cachedEvents }
|
return { commitmentEvents: cachedEvents }
|
||||||
}
|
}
|
||||||
blockFrom = newBlockFrom > currentBlock ? currentBlock : newBlockFrom
|
blockFrom = newBlockFrom > currentBlock ? currentBlock : newBlockFrom
|
||||||
} else {
|
|
||||||
const downloadedEvents = await downloadEvents(`commitments_${self.chainId}.json`, blockFrom)
|
|
||||||
|
|
||||||
if (downloadedEvents.events.length) {
|
|
||||||
cachedEvents.push(...downloadedEvents.events)
|
|
||||||
|
|
||||||
blockFrom = downloadedEvents.lastBlock
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const commitmentEvents = await getCommitmentBatch({ blockFrom, blockTo: currentBlock, cachedEvents, withCache })
|
const commitmentEvents = await getCommitmentBatch({ blockFrom, blockTo: currentBlock, cachedEvents, withCache })
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import { ExtendedProvider } from './services/provider'
|
|||||||
import { POOL_CONTRACT, RPC_LIST, FALLBACK_RPC_LIST, workerEvents, numbers } from './services/constants'
|
import { POOL_CONTRACT, RPC_LIST, FALLBACK_RPC_LIST, workerEvents, numbers } from './services/constants'
|
||||||
import { sleep } from './services/utilities'
|
import { sleep } from './services/utilities'
|
||||||
import { poolAbi } from './services/pool'
|
import { poolAbi } from './services/pool'
|
||||||
import { downloadEvents } from './services/downloadEvents'
|
|
||||||
|
|
||||||
const getProviderWithSigner = (chainId) => {
|
const getProviderWithSigner = (chainId) => {
|
||||||
return new ExtendedProvider(RPC_LIST[chainId], chainId, FALLBACK_RPC_LIST[chainId])
|
return new ExtendedProvider(RPC_LIST[chainId], chainId, FALLBACK_RPC_LIST[chainId])
|
||||||
@ -121,14 +120,6 @@ const getCachedEvents = async () => {
|
|||||||
return { blockFrom, cachedEvents }
|
return { blockFrom, cachedEvents }
|
||||||
}
|
}
|
||||||
blockFrom = newBlockFrom > currentBlock ? currentBlock : newBlockFrom
|
blockFrom = newBlockFrom > currentBlock ? currentBlock : newBlockFrom
|
||||||
} else {
|
|
||||||
const downloadedEvents = await downloadEvents(`nullifiers_${self.chainId}.json`, blockFrom)
|
|
||||||
|
|
||||||
if (downloadedEvents.events.length) {
|
|
||||||
cachedEvents.push(...downloadedEvents.events)
|
|
||||||
|
|
||||||
blockFrom = downloadedEvents.lastBlock
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { blockFrom, cachedEvents }
|
return { blockFrom, cachedEvents }
|
||||||
|
|||||||
@ -1,37 +0,0 @@
|
|||||||
import { unzipAsync } from "./zip"
|
|
||||||
|
|
||||||
export async function downloadEvents(fileName, deployedBlock) {
|
|
||||||
fileName = fileName.toLowerCase()
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
const prefix = __webpack_public_path__.slice(0, -7)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const resp = await fetch(`${prefix}/${fileName}.zip`, {
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const arrayBuffer = await resp.arrayBuffer()
|
|
||||||
|
|
||||||
const { [fileName]: content } = await unzipAsync(new Uint8Array(arrayBuffer))
|
|
||||||
|
|
||||||
const events = JSON.parse(new TextDecoder().decode(content))
|
|
||||||
|
|
||||||
const lastBlock = events && Array.isArray(events) && events[events.length - 1]
|
|
||||||
? events[events.length - 1].blockNumber
|
|
||||||
: deployedBlock
|
|
||||||
|
|
||||||
return {
|
|
||||||
events,
|
|
||||||
lastBlock
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
return {
|
|
||||||
events: [],
|
|
||||||
lastBlock: deployedBlock
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -55,6 +55,7 @@ export default {
|
|||||||
'setProvider',
|
'setProvider',
|
||||||
'changeChain',
|
'changeChain',
|
||||||
'checkNetwork',
|
'checkNetwork',
|
||||||
|
'checkSanction',
|
||||||
'setWalletParams',
|
'setWalletParams',
|
||||||
'getWalletBalance',
|
'getWalletBalance',
|
||||||
]),
|
]),
|
||||||
@ -92,6 +93,9 @@ export default {
|
|||||||
const address = await provider.setupProvider()
|
const address = await provider.setupProvider()
|
||||||
const network = await provider.checkNetworkVersion()
|
const network = await provider.checkNetworkVersion()
|
||||||
|
|
||||||
|
if (address) {
|
||||||
|
await this.checkSanction(address)
|
||||||
|
}
|
||||||
await this.setProvider({ network, name: key })
|
await this.setProvider({ network, name: key })
|
||||||
await this.setAccountData(address)
|
await this.setAccountData(address)
|
||||||
|
|
||||||
@ -122,6 +126,8 @@ export default {
|
|||||||
if (address) {
|
if (address) {
|
||||||
const checksumAddress = toChecksumAddress(address)
|
const checksumAddress = toChecksumAddress(address)
|
||||||
|
|
||||||
|
await this.checkSanction(checksumAddress)
|
||||||
|
|
||||||
if (!this.isConnected) {
|
if (!this.isConnected) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import { isEmpty, sleep, toChecksumAddress } from '@/utilities'
|
|||||||
import { getBridgeHelper, getBridgeProxy, getAmbBridge } from '@/contracts'
|
import { getBridgeHelper, getBridgeProxy, getAmbBridge } from '@/contracts'
|
||||||
|
|
||||||
import { EventsClass, GetAffirmationParams, GetRelayedMessageParams, SaveEventsParams } from './@types'
|
import { EventsClass, GetAffirmationParams, GetRelayedMessageParams, SaveEventsParams } from './@types'
|
||||||
import { downloadEvents } from './load'
|
|
||||||
|
|
||||||
export * from './batch'
|
export * from './batch'
|
||||||
|
|
||||||
@ -34,31 +33,19 @@ class EventAggregator implements EventsClass {
|
|||||||
storeName: `${IndexDBStores.ACCOUNT_EVENTS}_${chainId}`,
|
storeName: `${IndexDBStores.ACCOUNT_EVENTS}_${chainId}`,
|
||||||
})
|
})
|
||||||
|
|
||||||
const newEvents = []
|
|
||||||
|
|
||||||
if (cachedEvents?.length) {
|
if (cachedEvents?.length) {
|
||||||
const [latestEvent] = cachedEvents.slice(-numbers.ONE)
|
const [latestEvent] = cachedEvents.slice(-numbers.ONE)
|
||||||
blockFrom = Number(latestEvent.blockNumber) + numbers.ONE
|
blockFrom = Number(latestEvent.blockNumber) + numbers.ONE
|
||||||
} else {
|
|
||||||
const downloadedEvents = await downloadEvents(`accounts_${chainId}.json`, blockFrom)
|
|
||||||
|
|
||||||
if (downloadedEvents.events.length) {
|
|
||||||
newEvents.push(...downloadedEvents.events)
|
|
||||||
|
|
||||||
blockFrom = downloadedEvents.lastBlock
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { events: graphEvents, lastSyncBlock } = await getAllAccounts({ fromBlock: blockFrom, chainId })
|
const { events: graphEvents, lastSyncBlock } = await getAllAccounts({ fromBlock: blockFrom, chainId })
|
||||||
|
|
||||||
newEvents.push(...graphEvents)
|
const [account] = graphEvents.filter((e: { key: string }) => e.key === publicKey)
|
||||||
|
|
||||||
const [account] = newEvents.filter((e: { key: string }) => e.key === publicKey)
|
|
||||||
|
|
||||||
if (account) {
|
if (account) {
|
||||||
this.saveEvents({
|
this.saveEvents({
|
||||||
chainId,
|
chainId,
|
||||||
events: newEvents,
|
events: graphEvents,
|
||||||
storeName: IndexDBStores.ACCOUNT_EVENTS,
|
storeName: IndexDBStores.ACCOUNT_EVENTS,
|
||||||
})
|
})
|
||||||
return account.owner
|
return account.owner
|
||||||
@ -81,7 +68,7 @@ class EventAggregator implements EventsClass {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
newEvents.push(...accountEvents)
|
const newEvents = graphEvents.concat(accountEvents)
|
||||||
|
|
||||||
this.saveEvents({
|
this.saveEvents({
|
||||||
chainId,
|
chainId,
|
||||||
@ -89,7 +76,7 @@ class EventAggregator implements EventsClass {
|
|||||||
storeName: IndexDBStores.ACCOUNT_EVENTS,
|
storeName: IndexDBStores.ACCOUNT_EVENTS,
|
||||||
})
|
})
|
||||||
|
|
||||||
const events = newEvents.filter((e: { key: string }) => e.key === publicKey)
|
const events = cachedEvents.concat(newEvents).filter((e: { key: string }) => e.key === publicKey)
|
||||||
|
|
||||||
if (isEmpty(events)) {
|
if (isEmpty(events)) {
|
||||||
return undefined
|
return undefined
|
||||||
@ -100,7 +87,6 @@ class EventAggregator implements EventsClass {
|
|||||||
|
|
||||||
return event.owner
|
return event.owner
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err)
|
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,30 +113,19 @@ class EventAggregator implements EventsClass {
|
|||||||
storeName: `${IndexDBStores.ACCOUNT_EVENTS}_${chainId}`,
|
storeName: `${IndexDBStores.ACCOUNT_EVENTS}_${chainId}`,
|
||||||
})
|
})
|
||||||
|
|
||||||
const newEvents = []
|
|
||||||
|
|
||||||
if (cachedEvents?.length) {
|
if (cachedEvents?.length) {
|
||||||
const [latestEvent] = cachedEvents.slice(-numbers.ONE)
|
const [latestEvent] = cachedEvents.slice(-numbers.ONE)
|
||||||
blockFrom = Number(latestEvent.blockNumber) + numbers.ONE
|
blockFrom = Number(latestEvent.blockNumber) + numbers.ONE
|
||||||
} else {
|
|
||||||
const downloadedEvents = await downloadEvents(`accounts_${chainId}.json`, blockFrom)
|
|
||||||
|
|
||||||
if (downloadedEvents.events.length) {
|
|
||||||
newEvents.push(...downloadedEvents.events)
|
|
||||||
|
|
||||||
blockFrom = downloadedEvents.lastBlock
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { events: graphEvents, lastSyncBlock } = await getAllAccounts({ fromBlock: blockFrom, chainId })
|
const { events: graphEvents, lastSyncBlock } = await getAllAccounts({ fromBlock: blockFrom, chainId })
|
||||||
newEvents.push(...graphEvents)
|
|
||||||
|
|
||||||
const [account] = newEvents.filter((e: { owner: string }) => toChecksumAddress(e.owner) === toChecksumAddress(address))
|
const [account] = graphEvents.filter((e: { owner: string }) => toChecksumAddress(e.owner) === toChecksumAddress(address))
|
||||||
|
|
||||||
if (account) {
|
if (account) {
|
||||||
this.saveEvents({
|
this.saveEvents({
|
||||||
chainId,
|
chainId,
|
||||||
events: newEvents,
|
events: graphEvents,
|
||||||
storeName: IndexDBStores.ACCOUNT_EVENTS,
|
storeName: IndexDBStores.ACCOUNT_EVENTS,
|
||||||
})
|
})
|
||||||
return account.key
|
return account.key
|
||||||
@ -173,7 +148,7 @@ class EventAggregator implements EventsClass {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
newEvents.push(...accountEvents)
|
const newEvents = graphEvents.concat(accountEvents)
|
||||||
|
|
||||||
this.saveEvents({
|
this.saveEvents({
|
||||||
chainId,
|
chainId,
|
||||||
@ -194,7 +169,6 @@ class EventAggregator implements EventsClass {
|
|||||||
|
|
||||||
return event.key
|
return event.key
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err)
|
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,49 +0,0 @@
|
|||||||
import { unzip } from 'fflate'
|
|
||||||
|
|
||||||
export function unzipAsync(data: Uint8Array) {
|
|
||||||
return new Promise((res, rej) => {
|
|
||||||
unzip(data, {}, (err, data) => {
|
|
||||||
if (err) {
|
|
||||||
rej(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
res(data);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function downloadEvents(fileName: string, deployedBlock: number) {
|
|
||||||
fileName = fileName.toLowerCase()
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
const prefix = __webpack_public_path__.slice(0, -7)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const resp = await fetch(`${prefix}/${fileName}.zip`, {
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const arrayBuffer = await resp.arrayBuffer()
|
|
||||||
|
|
||||||
const { [fileName]: content } = (await unzipAsync(new Uint8Array(arrayBuffer))) as any
|
|
||||||
|
|
||||||
const events = JSON.parse(new TextDecoder().decode(content))
|
|
||||||
|
|
||||||
const lastBlock = events && Array.isArray(events) && events[events.length - 1]
|
|
||||||
? events[events.length - 1].blockNumber
|
|
||||||
: deployedBlock
|
|
||||||
|
|
||||||
return {
|
|
||||||
events,
|
|
||||||
lastBlock
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
return {
|
|
||||||
events: [],
|
|
||||||
lastBlock: deployedBlock
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -19,6 +19,17 @@ export const actions: ActionTree<WalletState, RootState> = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async checkSanction({ getters }, address) {
|
||||||
|
const contract = getSanctionList(getters.dependencies.l1ChainId)
|
||||||
|
|
||||||
|
const isSanctioned = await contract.callStatic.isSanctioned(address)
|
||||||
|
if (isSanctioned) {
|
||||||
|
window.onbeforeunload = null
|
||||||
|
// ToDo add type
|
||||||
|
// @ts-expect-error
|
||||||
|
window.location = 'https://twitter.com/TornadoCash/status/1514904975037669386'
|
||||||
|
}
|
||||||
|
},
|
||||||
checkAppNetwork({ commit }, network) {
|
checkAppNetwork({ commit }, network) {
|
||||||
try {
|
try {
|
||||||
// TODO create a selector for active network
|
// TODO create a selector for active network
|
||||||
|
|||||||
@ -60018,15 +60018,13 @@ async function getAllCommitments({ fromBlock, toBlock, chainId }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = commitments
|
const data = commitments.map((e) => ({
|
||||||
.map((e) => ({
|
|
||||||
blockNumber: Number(e.blockNumber),
|
blockNumber: Number(e.blockNumber),
|
||||||
transactionHash: e.transactionHash,
|
transactionHash: e.transactionHash,
|
||||||
index: Number(e.index),
|
index: Number(e.index),
|
||||||
commitment: e.commitment,
|
commitment: e.commitment,
|
||||||
encryptedOutput: e.encryptedOutput
|
encryptedOutput: e.encryptedOutput
|
||||||
}))
|
}))
|
||||||
.sort((a, b) => a.index - b.index)
|
|
||||||
|
|
||||||
const [lastEvent] = data.slice(-numbers.ONE)
|
const [lastEvent] = data.slice(-numbers.ONE)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user