Skip to content

Commit 24adf7d

Browse files
committed
fix(decoder): log sequence + execution
1 parent f3b5af5 commit 24adf7d

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

services/decoder/decoder.ts

+37-34
Original file line numberDiff line numberDiff line change
@@ -158,43 +158,46 @@ export class GoldRushDecoder {
158158
) => {
159159
const covalent_client = new CovalentClient(covalent_api_key);
160160
const events: EventType[] = [];
161-
const logs = (tx.log_events ?? []).reverse();
162161
if (tx.value) {
163162
const nativeEvent = this.native_decoder(tx);
164163
events.push(nativeEvent);
165164
}
166-
for (const log of logs) {
167-
const {
168-
raw_log_topics: [topic0_hash],
169-
sender_address,
170-
sender_factory_address,
171-
} = log;
172-
const decoding_index =
173-
this.decoders[chain_name]?.[sender_address]?.[topic0_hash] ??
174-
this.decoders[chain_name]?.[sender_factory_address]?.[
175-
topic0_hash
176-
];
177-
const fallback_index = this.fallbacks[topic0_hash];
178-
let logEvent: EventType | null = null;
179-
if (decoding_index !== undefined) {
180-
logEvent = await this.decoding_functions[decoding_index](
181-
log,
182-
tx,
183-
chain_name,
184-
covalent_client
185-
);
186-
} else if (fallback_index !== undefined) {
187-
logEvent = await this.fallback_functions[fallback_index](
188-
log,
189-
tx,
190-
chain_name,
191-
covalent_client
192-
);
193-
}
194-
if (logEvent) {
195-
events.push(logEvent);
196-
}
197-
}
198-
return events;
165+
166+
const decodedEvents = await Promise.all(
167+
(tx.log_events ?? []).map((log) => {
168+
const {
169+
raw_log_topics: [topic0_hash],
170+
sender_address,
171+
sender_factory_address,
172+
} = log;
173+
const decoding_index =
174+
this.decoders[chain_name]?.[sender_address]?.[
175+
topic0_hash
176+
] ??
177+
this.decoders[chain_name]?.[sender_factory_address]?.[
178+
topic0_hash
179+
];
180+
const fallback_index = this.fallbacks[topic0_hash];
181+
182+
if (decoding_index !== undefined) {
183+
return this.decoding_functions[decoding_index](
184+
log,
185+
tx,
186+
chain_name,
187+
covalent_client
188+
);
189+
} else if (fallback_index !== undefined) {
190+
return this.fallback_functions[fallback_index](
191+
log,
192+
tx,
193+
chain_name,
194+
covalent_client
195+
);
196+
}
197+
return null;
198+
})
199+
);
200+
201+
return events.concat(decodedEvents.filter(Boolean) as EventType[]);
199202
};
200203
}

0 commit comments

Comments
 (0)