Skip to content

Commit 59830d7

Browse files
committed
fix(decoder): log sequence + execution
1 parent 8a29382 commit 59830d7

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

services/decoder/decoder.ts

+27-21
Original file line numberDiff line numberDiff line change
@@ -167,30 +167,36 @@ export class GoldRushDecoder {
167167
) => {
168168
const covalent_client = new CovalentClient(covalent_api_key);
169169
const events: EventType[] = [];
170-
const logs = (tx.log_events ?? []).reverse();
171170
if (tx.value) {
172171
const nativeEvent = this.native_decoder(tx);
173172
events.push(nativeEvent);
174173
}
175-
for (const log of logs) {
176-
const {
177-
raw_log_topics: [topic0_hash],
178-
sender_address: contract_address,
179-
// !ERROR: add factory_contract_address in the log_event(s)
180-
// factory_contract_address,
181-
} = log;
182-
const decoding_index =
183-
// !ERROR: add factory_contract_address in the log_event(s)
184-
// factory_contract_address ||
185-
this.decoders[chain_name]?.[contract_address]?.[topic0_hash];
186-
const fallback_index = this.fallbacks[topic0_hash];
187-
if (decoding_index !== undefined || fallback_index !== undefined) {
188-
const logEvent = await this.decoding_functions[
189-
decoding_index ?? fallback_index
190-
](log, tx, chain_name, covalent_client);
191-
events.push(logEvent);
192-
}
193-
}
194-
return events;
174+
const decodedEvents = await Promise.all(
175+
(tx.log_events ?? []).map((log) => {
176+
const {
177+
raw_log_topics: [topic0_hash],
178+
sender_address: contract_address,
179+
// !ERROR: add factory_contract_address in the log_event(s)
180+
// factory_contract_address,
181+
} = log;
182+
const decoding_index =
183+
// !ERROR: add factory_contract_address in the log_event(s)
184+
// factory_contract_address ||
185+
this.decoders[chain_name]?.[contract_address]?.[
186+
topic0_hash
187+
];
188+
const fallback_index = this.fallbacks[topic0_hash];
189+
if (
190+
decoding_index !== undefined ||
191+
fallback_index !== undefined
192+
) {
193+
return this.decoding_functions[
194+
decoding_index ?? fallback_index
195+
](log, tx, chain_name, covalent_client);
196+
}
197+
return null;
198+
})
199+
);
200+
return events.concat(decodedEvents.filter(Boolean) as EventType[]);
195201
};
196202
}

0 commit comments

Comments
 (0)