Skip to content

Commit

Permalink
handle addresses limit
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbronco committed Dec 20, 2023
1 parent a8c838b commit 6825b46
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion modules/web3/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const getEvents = async (
rpcUrl: string,
rpcMaxBlockRange: number,
abi?: any,
maxAddresses = 500,
): Promise<Event[]> => {
let iEvents: Interface;
if (abi && abi.length > 0) {
Expand All @@ -28,7 +29,7 @@ export const getEvents = async (
const from = fromBlock + (i > 0 ? 1 : 0) + i * rpcMaxBlockRange;
const to = Math.min(fromBlock + (i + 1) * rpcMaxBlockRange, toBlock);

const addressChunks = chunk(addresses, 500);
const addressChunks = chunk(addresses, maxAddresses);

for (const addressChunk of addressChunks) {
const promise = fetchLogs(from, to, addressChunk, topics, rpcUrl).catch((e: any) => {
Expand Down Expand Up @@ -62,6 +63,26 @@ export const getEvents = async (
});
}

// Allnodes addresses size limit
if (e.includes && e.includes('specify less number of addresses')) {
return new Promise<Event[]>((resolve) => {
setTimeout(() => {
resolve(
getEvents(
from,
to,
addressChunk,
topics,
rpcUrl,
rpcMaxBlockRange,
undefined,
maxAddresses / 2,
),
);
}, 1000);
});
}

console.error('Error fetching logs:', e);
return Promise.reject(e);
});
Expand Down

0 comments on commit 6825b46

Please sign in to comment.