diff --git a/packages/codegen/src/data/entities/Contract.yaml b/packages/codegen/src/data/entities/Contract.yaml index 60a7ac4da..8eceed687 100644 --- a/packages/codegen/src/data/entities/Contract.yaml +++ b/packages/codegen/src/data/entities/Contract.yaml @@ -2,6 +2,7 @@ className: Contract indexOn: - columns: - address + - kind unique: true columns: - name: id diff --git a/packages/codegen/src/templates/indexer-template.handlebars b/packages/codegen/src/templates/indexer-template.handlebars index 0036e331e..b8a308a57 100644 --- a/packages/codegen/src/templates/indexer-template.handlebars +++ b/packages/codegen/src/templates/indexer-template.handlebars @@ -525,23 +525,27 @@ export class Indexer implements IndexerInterface { } {{/if}} - parseEventNameAndArgs (kind: string, logObj: any): { eventParsed: boolean, eventDetails: any } { + parseEventNameAndArgs (watchedContracts: Contract[], logObj: any): { eventParsed: boolean, eventDetails: any } { const { topics, data } = logObj; - - const contract = this._contractMap.get(kind); - assert(contract); - - let logDescription: ethers.utils.LogDescription; - try { - logDescription = contract.parseLog({ data, topics }); - } catch (err) { - // Return if no matching event found - if ((err as Error).message.includes('no matching event')) { - log(`WARNING: Skipping event for contract ${kind} as no matching event found in the ABI`); - return { eventParsed: false, eventDetails: {} }; + let logDescription: ethers.utils.LogDescription | undefined; + + for (const watchedContract of watchedContracts) { + const contract = this._contractMap.get(watchedContract.kind); + assert(contract); + + try { + logDescription = contract.parseLog({ data, topics }); + break; + } catch (err) { + // Continue loop only if no matching event found + if (!((err as Error).message.includes('no matching event'))) { + throw err; + } } + } - throw err; + if (!logDescription) { + return { eventParsed: false, eventDetails: {} }; } const { eventName, eventInfo, eventSignature } = this._baseIndexer.parseEvent(logDescription); @@ -647,8 +651,8 @@ export class Indexer implements IndexerInterface { return this._baseIndexer.getEventsByFilter(blockHash, contract, name); } - isWatchedContract (address : string): Contract | undefined { - return this._baseIndexer.isWatchedContract(address); + isContractAddressWatched (address : string): Contract[] | undefined { + return this._baseIndexer.isContractAddressWatched(address); } getWatchedContracts (): Contract[] {