I have this function where I disabled eslint warning but I would like to improve the code. I understand that I should use promise.All(), but I am unsure how to proceed since I have two await in the for loop.
const getBatchLogsByHash = async (
chainId: number,
rpc: string,
batch: BlockRange,
) => {
const firstBlock = batch.startBlock;
const lastBlock = batch.endBlock;
const logs: Array<Log> = [];
/* eslint-disable no-await-in-loop */
for (let i = firstBlock; i <= lastBlock; i += 1) {
const block = await ethers.fetchBlock(chainId, rpc, i);
const blockLogs = await ethers.fetchLogsByBlockHash(
chainId,
rpc,
block.hash,
);
logs.push(...blockLogs);
}
return logs;
};
Thanks for the help
Promise.allinstead of your for-loop, you have no guarantee whatsoever, in what order the requests are executed. Ie yourlogsmay appear in arbitrary order ...