Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stwiname committed Nov 25, 2024
1 parent d5374dd commit b639369
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 7 additions & 6 deletions packages/node/src/indexer/indexer.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,12 @@ export class IndexerManager extends BaseIndexerManager<
const groupedEvents = events.reduce(
(acc, evt, idx) => {
if (evt.phase.isInitialization) {
acc.init ??= [];
acc.init.push(evt);
} else if (evt.phase.isFinalization) {
acc.finalize ??= [];
acc.finalize.push(evt);
} else if (evt.extrinsic?.idx) {
const idx = evt.extrinsic.idx;
acc[idx] = acc[idx] || [];
acc[idx] ??= [];
acc[idx].push(evt);
} else {
logger.warn(
Expand All @@ -128,11 +126,14 @@ export class IndexerManager extends BaseIndexerManager<
}
return acc;
},
{} as Record<number | 'init' | 'finalize', SubstrateEvent[]>,
{ init: [], finalize: [] } as Record<
number | 'init' | 'finalize',
SubstrateEvent[]
>,
);

// Run initialization events
for (const event of groupedEvents.init ?? []) {
for (const event of groupedEvents.init) {
await this.indexEvent(event, dataSources, getVM);
}

Expand All @@ -150,7 +151,7 @@ export class IndexerManager extends BaseIndexerManager<
}

// Run finalization events
for (const event of groupedEvents.finalize ?? []) {
for (const event of groupedEvents.finalize) {
await this.indexEvent(event, dataSources, getVM);
}
} else {
Expand Down
4 changes: 1 addition & 3 deletions packages/node/src/utils/substrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ function groupEventsByExtrinsic(
if (extrinsicIdx === undefined) {
return acc;
}
if (!acc[extrinsicIdx]) {
acc[extrinsicIdx] = [];
}
acc[extrinsicIdx] ??= [];
acc[extrinsicIdx].push(event);
return acc;
},
Expand Down

0 comments on commit b639369

Please sign in to comment.