Skip to content

Commit c9695b3

Browse files
authored
Update get-logs.ts (#880)
1 parent bc6a6d9 commit c9695b3

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

src/server/routes/transaction/blockchain/get-logs.ts

+29-9
Original file line numberDiff line numberDiff line change
@@ -198,28 +198,48 @@ export async function getTransactionLogs(fastify: FastifyInstance) {
198198
);
199199
}
200200

201-
const contract = getContract({
202-
address: transactionReceipt.to,
203-
chain,
204-
client: thirdwebClient,
205-
});
201+
const contracts = new Set<string>();
202+
contracts.add(transactionReceipt.to);
203+
for (const log of transactionReceipt.logs) {
204+
if (log.address) {
205+
contracts.add(log.address);
206+
}
207+
}
206208

207-
const abi: AbiEvent.AbiEvent[] = await resolveContractAbi(contract);
208-
const eventSignatures = abi.filter((item) => item.type === "event");
209-
if (eventSignatures.length === 0) {
209+
const eventSignaturePromises = Array.from(contracts).map(
210+
async (address) => {
211+
const contract = getContract({
212+
address,
213+
chain,
214+
client: thirdwebClient,
215+
});
216+
217+
const abi: AbiEvent.AbiEvent[] = await resolveContractAbi(contract);
218+
const eventSignatures = abi.filter((item) => item.type === "event");
219+
return eventSignatures;
220+
},
221+
);
222+
223+
const combinedEventSignatures: AbiEvent.AbiEvent[] = (
224+
await Promise.all(eventSignaturePromises)
225+
).flat();
226+
227+
if (combinedEventSignatures.length === 0) {
210228
throw createCustomError(
211229
"No events found in contract or could not resolve contract ABI",
212230
StatusCodes.BAD_REQUEST,
213231
"NO_EVENTS_FOUND",
214232
);
215233
}
216234

217-
const preparedEvents = eventSignatures.map((signature) =>
235+
const preparedEvents = combinedEventSignatures.map((signature) =>
218236
prepareEvent({ signature }),
219237
);
238+
220239
const parsedLogs = parseEventLogs({
221240
events: preparedEvents,
222241
logs: transactionReceipt.logs,
242+
strict: false,
223243
});
224244

225245
reply.status(StatusCodes.OK).send({

0 commit comments

Comments
 (0)