Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
khaidarkairbek committed Dec 31, 2024
1 parent dfc0564 commit 14611db
Showing 1 changed file with 27 additions and 33 deletions.
60 changes: 27 additions & 33 deletions packages/core/src/build/configAndIndexingFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,40 +361,34 @@ export async function buildConfigAndIndexingFunctions({
// is an invariant of the current filter design.
// Note: This can throw.

const filteredTopicsArray = buildTopics(
source.abi,
source.filter,
).reduce(
(acc, cur) => {
if (acc.includes(cur) === false) {
acc.push(cur);
}

return acc;
},
[] as {
topic0: Hex;
topic1: Hex | Hex[] | null;
topic2: Hex | Hex[] | null;
topic3: Hex | Hex[] | null;
}[],
);

const filteredEventSelectors = filteredTopicsArray.reduce(
(acc, cur) => {
const eventSelector = cur.topic0;

if (
eventSelector !== null &&
acc.includes(eventSelector) === false
) {
acc.push(eventSelector);
}
const filteredTopicsArray = buildTopics(source.abi, source.filter);

const filteredEventSelectors: Hex[] = [];
const resolvedTopicsArray: {
topic0: Hex;
topic1: LogTopic;
topic2: LogTopic;
topic3: LogTopic;
}[] = [];

for (const topics of filteredTopicsArray) {
const eventSelector = topics.topic0;
if (
resolvedTopicsArray.some(
(t) =>
t.topic0 === eventSelector &&
t.topic1 === topics.topic1 &&
t.topic2 === topics.topic2 &&
t.topic3 === topics.topic3,
) === false
) {
resolvedTopicsArray.push(topics);
}

return acc;
},
[] as Hex[],
);
if (filteredEventSelectors.includes(eventSelector) === false) {
filteredEventSelectors.push(eventSelector);
}
}

// Merge filtered topics and registered event selectors
const excludedRegisteredEventSelectors =
Expand Down

0 comments on commit 14611db

Please sign in to comment.