Support toBlock condition for commitments to prevent balance being double counted
This commit is contained in:
parent
6447563ea0
commit
d86d3ff125
@ -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
Loading…
Reference in New Issue
Block a user