From ad3870af0e2fbdce197a7aebb4e0697e6ab1f77a Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 10 Mar 2022 09:27:38 +0100 Subject: [PATCH] fix decoding events --- libs/remix-lib/src/execution/eventsDecoder.ts | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/libs/remix-lib/src/execution/eventsDecoder.ts b/libs/remix-lib/src/execution/eventsDecoder.ts index 4622b245fd..cdb794fd71 100644 --- a/libs/remix-lib/src/execution/eventsDecoder.ts +++ b/libs/remix-lib/src/execution/eventsDecoder.ts @@ -56,21 +56,22 @@ export class EventsDecoder { return eventsABI } - _event (hash: string, eventsABI: Record, contractName: string) { - const events = eventsABI[contractName] - if (!events) return null - - if (events[hash]) { - const event = events[hash] - for (const input of event.inputs) { - if (input.type === 'function') { - input.type = 'bytes24' - input.baseType = 'bytes24' + _event (hash, eventsABI) { + // get all the events responding to that hash. + const contracts = [] + for (const k in eventsABI) { + if (eventsABI[k][hash]) { + const event = eventsABI[k][hash] + for (const input of event.inputs) { + if (input.type === 'function') { + input.type = 'bytes24' + input.baseType = 'bytes24' + } } + contracts.push(event) } - return event } - return null + return contracts } _stringifyBigNumber (value): string { @@ -95,16 +96,23 @@ export class EventsDecoder { // [address, topics, mem] const log = logs[i] const topicId = log.topics[0] - const eventAbi = this._event(topicId.replace('0x', ''), eventsABI, contractName) - if (eventAbi) { - const decodedlog = eventAbi.abi.parseLog(log) - const decoded = {} - for (const v in decodedlog.args) { - decoded[v] = this._stringifyEvent(decodedlog.args[v]) + const eventAbis = this._event(topicId.replace('0x', ''), eventsABI) + for (const eventAbi of eventAbis) { + try { + if (eventAbi) { + const decodedlog = eventAbi.abi.parseLog(log) + const decoded = {} + for (const v in decodedlog.args) { + decoded[v] = this._stringifyEvent(decodedlog.args[v]) + } + events.push({ from: log.address, topic: topicId, event: eventAbi.event, args: decoded }) + } else { + events.push({ from: log.address, data: log.data, topics: log.topics }) + } + break // if one of the iteration is successful + } catch (e) { + continue } - events.push({ from: log.address, topic: topicId, event: eventAbi.event, args: decoded }) - } else { - events.push({ from: log.address, data: log.data, topics: log.topics }) } } cb(null, { decoded: events, raw: logs })