Skip to content

Commit

Permalink
update: events handling
Browse files Browse the repository at this point in the history
  • Loading branch information
radzionc committed Oct 6, 2023
1 parent 50d06cc commit 8939c0f
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions indexers/shared/collectors/events/EventCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,39 @@ export class EventCollector implements Runnable {
};

private map = (block: Block): Event[] => {
const events = block.txs.flatMap((tx) => {
return tx.logs.filter(this.findWasmEvent).flatMap((log) => {
const wasmEvent = this.findWasmEvent(log);
return groupAttributes(wasmEvent.attributes).map((group, index) => {
const payload = serialize(group);
const event = {
contract: this.monikers(payload['_contract_address'], payload),
action: payload.action,
height: block.height,
txHash: tx.txHash,
msgIndex: log.msgIndex,
eventIndex: index,
timestamp: tx.timestamp,
payload: payload,
};
if (this.onEvent) {
this.onEvent(event);
}
return event;
const events: Event[] = [];
block.txs.forEach((tx) => {
tx.logs.forEach((log) => {
log.events.forEach((event) => {
if (event.type !== 'wasm') return;

groupAttributes(event.attributes).forEach((group, index) => {
const payload = serialize(group);
const contract = this.monikers(payload['_contract_address'], payload);
if (!contract) return;

const event = {
contract: this.monikers(payload['_contract_address'], payload),
action: payload.action,
height: block.height,
txHash: tx.txHash,
msgIndex: log.msgIndex,
eventIndex: index,
timestamp: tx.timestamp,
payload: payload,
};

events.push(event);
});
});
});
});
return events.filter((event) => event.contract !== undefined);

if (this.onEvent) {
events.forEach((event) => this.onEvent(event));
}

return events;
};

run = async (): Promise<void> => {
Expand Down

0 comments on commit 8939c0f

Please sign in to comment.