Use Subgraph & Batched Events #2
@ -73,16 +73,30 @@ const setTornadoPool = (chainId, provider) => {
|
|||||||
const getCommitmentBatch = async ({ blockFrom, blockTo, cachedEvents, withCache }) => {
|
const getCommitmentBatch = async ({ blockFrom, blockTo, cachedEvents, withCache }) => {
|
||||||
const events = []
|
const events = []
|
||||||
|
|
||||||
let { events: graphEvents, lastSyncBlock } = await getAllCommitments({ fromBlock: blockFrom, chainId })
|
let { events: graphEvents, lastSyncBlock } = await getAllCommitments({
|
||||||
|
fromBlock: blockFrom,
|
||||||
|
toBlock: blockTo,
|
||||||
|
chainId
|
||||||
|
})
|
||||||
|
|
||||||
if (lastSyncBlock) {
|
if (lastSyncBlock) {
|
||||||
graphEvents = graphEvents.map(({ blockNumber, transactionHash, index, commitment, encryptedOutput }) => ({
|
graphEvents = graphEvents
|
||||||
blockNumber,
|
.filter(({ blockNumber }) => {
|
||||||
transactionHash,
|
if (blockFrom && blockTo) {
|
||||||
index: Number(index),
|
return Number(blockFrom) <= Number(blockNumber) && Number(blockNumber) <= Number(blockTo)
|
||||||
commitment,
|
} else if (blockTo) {
|
||||||
encryptedOutput,
|
return Number(blockNumber) <= Number(blockTo)
|
||||||
}))
|
}
|
||||||
|
// does not filter by default
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
.map(({ blockNumber, transactionHash, index, commitment, encryptedOutput }) => ({
|
||||||
|
blockNumber,
|
||||||
|
transactionHash,
|
||||||
|
index: Number(index),
|
||||||
|
commitment,
|
||||||
|
encryptedOutput,
|
||||||
|
}))
|
||||||
|
|
||||||
console.log({
|
console.log({
|
||||||
graphEvents
|
graphEvents
|
||||||
|
@ -45,7 +45,7 @@ async function getCommitments({ fromBlock, chainId }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAllCommitments({ fromBlock, chainId }) {
|
async function getAllCommitments({ fromBlock, toBlock, chainId }) {
|
||||||
try {
|
try {
|
||||||
let commitments = []
|
let commitments = []
|
||||||
let lastSyncBlock
|
let lastSyncBlock
|
||||||
@ -70,6 +70,10 @@ async function getAllCommitments({ fromBlock, chainId }) {
|
|||||||
fromBlock = Number(lastEvent.blockNumber)
|
fromBlock = Number(lastEvent.blockNumber)
|
||||||
|
|
||||||
commitments = commitments.concat(results)
|
commitments = commitments.concat(results)
|
||||||
|
|
||||||
|
if (toBlock && fromBlock >= Number(toBlock)) {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!commitments) {
|
if (!commitments) {
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user