Skip to content

Commit 5ae1f7a

Browse files
Optimize encodeEventTopics by precomputing event topics (#16)
* Initial plan * Optimize encodeEventTopics by precomputing event topics Co-authored-by: NicoSerranoP <38594836+NicoSerranoP@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: NicoSerranoP <38594836+NicoSerranoP@users.noreply.github.com>
1 parent 4044f30 commit 5ae1f7a

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

  • gas-benchmarks/src/utils

gas-benchmarks/src/utils/rpc.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ export const getUniqueLogs = (logs: Log[]): Log[] => {
7979
export const getTransactionsWithEvents = async (
8080
logs: Log[],
8181
events: readonly AbiEvent[],
82-
): Promise<TransactionReceipt[]> =>
83-
logs.reduce<Promise<TransactionReceipt[]>>(async (accumulatorPromise, log) => {
82+
): Promise<TransactionReceipt[]> => {
83+
const eventTopics = events.map((event) => encodeEventTopics({ abi: [event] })[0]);
84+
85+
return logs.reduce<Promise<TransactionReceipt[]>>(async (accumulatorPromise, log) => {
8486
const accumulator = await accumulatorPromise;
8587

8688
if (accumulator.length >= NUMBER_OF_TRANSACTIONS) {
@@ -93,9 +95,8 @@ export const getTransactionsWithEvents = async (
9395
return accumulator;
9496
}
9597

96-
const hasAllEvents = events.every((event, index) => {
98+
const hasAllEvents = eventTopics.every((eventTopic, index) => {
9799
const logTopic = receipt.logs[index]!.topics[0];
98-
const eventTopic = encodeEventTopics({ abi: [event] })[0];
99100

100101
return logTopic === eventTopic;
101102
});
@@ -108,3 +109,4 @@ export const getTransactionsWithEvents = async (
108109

109110
return accumulator;
110111
}, Promise.resolve([]));
112+
};

0 commit comments

Comments
 (0)