diff --git a/packages/codegen/src/templates/indexer-template.handlebars b/packages/codegen/src/templates/indexer-template.handlebars index 589e6178..2eae5ad5 100644 --- a/packages/codegen/src/templates/indexer-template.handlebars +++ b/packages/codegen/src/templates/indexer-template.handlebars @@ -102,7 +102,7 @@ export class Indexer implements IndexerInterface { _abiMap: Map; _storageLayoutMap: Map; _contractMap: Map; - _eventSignaturesMap: Map; + eventSignaturesMap: Map; {{#if (subgraphPath)}} _entityTypesMap: Map; @@ -141,7 +141,7 @@ export class Indexer implements IndexerInterface { this._abiMap = new Map(); this._storageLayoutMap = new Map(); this._contractMap = new Map(); - this._eventSignaturesMap = new Map(); + this.eventSignaturesMap = new Map(); let contractInterface: ethers.utils.Interface; let eventSignatures: string[]; {{#each contracts as | contract |}} @@ -159,7 +159,7 @@ export class Indexer implements IndexerInterface { eventSignatures = Object.values(contractInterface.events).map(value => { return contractInterface.getEventTopic(value); }); - this._eventSignaturesMap.set(KIND_{{capitalize contract.contractName}}, eventSignatures); + this.eventSignaturesMap.set(KIND_{{capitalize contract.contractName}}, eventSignatures); {{#if contract.contractStorageLayout}} assert({{contract.contractName}}StorageLayout); @@ -689,7 +689,7 @@ export class Indexer implements IndexerInterface { } async fetchEventsAndSaveBlocks (blocks: DeepPartial[]): Promise<{ blockProgress: BlockProgress, events: DeepPartial[] }[]> { - return this._baseIndexer.fetchEventsAndSaveBlocks(blocks, this._eventSignaturesMap, this.parseEventNameAndArgs.bind(this)); + return this._baseIndexer.fetchEventsAndSaveBlocks(blocks, this.eventSignaturesMap, this.parseEventNameAndArgs.bind(this)); } async fetchAndSaveFilteredEventsAndBlocks (startBlock: number, endBlock: number): Promise<{ @@ -698,11 +698,11 @@ export class Indexer implements IndexerInterface { ethFullBlock: EthFullBlock; ethFullTransactions: EthFullTransaction[]; }[]> { - return this._baseIndexer.fetchAndSaveFilteredEventsAndBlocks(startBlock, endBlock, this._eventSignaturesMap, this.parseEventNameAndArgs.bind(this)); + return this._baseIndexer.fetchAndSaveFilteredEventsAndBlocks(startBlock, endBlock, this.eventSignaturesMap, this.parseEventNameAndArgs.bind(this)); } async fetchEventsForContracts (blockHash: string, blockNumber: number, addresses: string[]): Promise[]> { - return this._baseIndexer.fetchEventsForContracts(blockHash, blockNumber, addresses, this._eventSignaturesMap, this.parseEventNameAndArgs.bind(this)); + return this._baseIndexer.fetchEventsForContracts(blockHash, blockNumber, addresses, this.eventSignaturesMap, this.parseEventNameAndArgs.bind(this)); } async saveBlockAndFetchEvents (block: DeepPartial): Promise<[ @@ -843,7 +843,7 @@ export class Indexer implements IndexerInterface { assert(blockHash); assert(blockNumber); - const { events: dbEvents, transactions } = await this._baseIndexer.fetchEvents(blockHash, blockNumber, this._eventSignaturesMap, this.parseEventNameAndArgs.bind(this)); + const { events: dbEvents, transactions } = await this._baseIndexer.fetchEvents(blockHash, blockNumber, this.eventSignaturesMap, this.parseEventNameAndArgs.bind(this)); const dbTx = await this._db.createTransactionRunner(); try { diff --git a/packages/graph-node/src/watcher.ts b/packages/graph-node/src/watcher.ts index 672473c8..7f1786c7 100644 --- a/packages/graph-node/src/watcher.ts +++ b/packages/graph-node/src/watcher.ts @@ -125,6 +125,21 @@ export class GraphWatcher { return acc; }, {}); + + this.fillEventSignatureMap(); + } + + fillEventSignatureMap () { + this._dataSources.forEach(contract => { + if (contract.kind === 'ethereum/contract' && contract.mapping.kind === 'ethereum/events') { + const contractName = contract.name; + const topicHashes = contract.mapping.eventHandlers.map((handler: any) => { + return this._dataSourceMap[contractName].contractInterface.getEventTopic(utils.EventFragment.from(handler.event).name); + }); + assert(this._indexer); + this._indexer.eventSignaturesMap.set(contractName, topicHashes); + } + }); } get dataSources (): any[] { diff --git a/packages/graph-node/test/utils/indexer.ts b/packages/graph-node/test/utils/indexer.ts index 110dc661..0987eeb5 100644 --- a/packages/graph-node/test/utils/indexer.ts +++ b/packages/graph-node/test/utils/indexer.ts @@ -27,6 +27,7 @@ import { GetStorageAt, getStorageValue, MappingKey, StorageLayout } from '@cerc- export class Indexer implements IndexerInterface { _getStorageAt: GetStorageAt; _storageLayoutMap: Map = new Map(); + eventSignaturesMap: Map = new Map(); constructor (ethClient: EthClient, storageLayoutMap?: Map) { this._getStorageAt = ethClient.getStorageAt.bind(ethClient); diff --git a/packages/util/src/types.ts b/packages/util/src/types.ts index 13f76dfb..1e899cc4 100644 --- a/packages/util/src/types.ts +++ b/packages/util/src/types.ts @@ -156,6 +156,7 @@ export interface EthClient { } export interface IndexerInterface { + eventSignaturesMap: Map readonly serverConfig: ServerConfig readonly upstreamConfig: UpstreamConfig readonly storageLayoutMap: Map