Use Subgraph & Batched Events #2

Closed
tornadocontrib wants to merge 8 commits from tornadocontrib/nova-ui:events into master
4 changed files with 30 additions and 12 deletions
Showing only changes of commit d86d3ff125 - Show all commits

@ -73,10 +73,24 @@ const setTornadoPool = (chainId, provider) => {
const getCommitmentBatch = async ({ blockFrom, blockTo, cachedEvents, withCache }) => {
const events = []
let { events: graphEvents, lastSyncBlock } = await getAllCommitments({ fromBlock: blockFrom, chainId })
let { events: graphEvents, lastSyncBlock } = await getAllCommitments({
fromBlock: blockFrom,
toBlock: blockTo,
chainId
})
if (lastSyncBlock) {
graphEvents = graphEvents.map(({ blockNumber, transactionHash, index, commitment, encryptedOutput }) => ({
graphEvents = graphEvents
.filter(({ blockNumber }) => {
if (blockFrom && blockTo) {
return Number(blockFrom) <= Number(blockNumber) && Number(blockNumber) <= Number(blockTo)
} else if (blockTo) {
return Number(blockNumber) <= Number(blockTo)
}
// does not filter by default
return true
})
.map(({ blockNumber, transactionHash, index, commitment, encryptedOutput }) => ({
blockNumber,
transactionHash,
index: Number(index),

@ -45,7 +45,7 @@ async function getCommitments({ fromBlock, chainId }) {
}
}
async function getAllCommitments({ fromBlock, chainId }) {
async function getAllCommitments({ fromBlock, toBlock, chainId }) {
try {
let commitments = []
let lastSyncBlock
@ -70,6 +70,10 @@ async function getAllCommitments({ fromBlock, chainId }) {
fromBlock = Number(lastEvent.blockNumber)
commitments = commitments.concat(results)
if (toBlock && fromBlock >= Number(toBlock)) {
break
}
}
if (!commitments) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long