mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-08 12:28:05 +00:00
Filter logs by events specified in subgraph config (#473)
* Use topic hash of events from config file * Add eventSignaturesMap field in IndexerInterface * Add eventSignaturesMap property in Indexer class --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
parent
8e9d5092fc
commit
5b95335fde
@ -102,7 +102,7 @@ export class Indexer implements IndexerInterface {
|
|||||||
_abiMap: Map<string, JsonFragment[]>;
|
_abiMap: Map<string, JsonFragment[]>;
|
||||||
_storageLayoutMap: Map<string, StorageLayout>;
|
_storageLayoutMap: Map<string, StorageLayout>;
|
||||||
_contractMap: Map<string, ethers.utils.Interface>;
|
_contractMap: Map<string, ethers.utils.Interface>;
|
||||||
_eventSignaturesMap: Map<string, string[]>;
|
eventSignaturesMap: Map<string, string[]>;
|
||||||
|
|
||||||
{{#if (subgraphPath)}}
|
{{#if (subgraphPath)}}
|
||||||
_entityTypesMap: Map<string, { [key: string]: string }>;
|
_entityTypesMap: Map<string, { [key: string]: string }>;
|
||||||
@ -141,7 +141,7 @@ export class Indexer implements IndexerInterface {
|
|||||||
this._abiMap = new Map();
|
this._abiMap = new Map();
|
||||||
this._storageLayoutMap = new Map();
|
this._storageLayoutMap = new Map();
|
||||||
this._contractMap = new Map();
|
this._contractMap = new Map();
|
||||||
this._eventSignaturesMap = new Map();
|
this.eventSignaturesMap = new Map();
|
||||||
let contractInterface: ethers.utils.Interface;
|
let contractInterface: ethers.utils.Interface;
|
||||||
let eventSignatures: string[];
|
let eventSignatures: string[];
|
||||||
{{#each contracts as | contract |}}
|
{{#each contracts as | contract |}}
|
||||||
@ -159,7 +159,7 @@ export class Indexer implements IndexerInterface {
|
|||||||
eventSignatures = Object.values(contractInterface.events).map(value => {
|
eventSignatures = Object.values(contractInterface.events).map(value => {
|
||||||
return contractInterface.getEventTopic(value);
|
return contractInterface.getEventTopic(value);
|
||||||
});
|
});
|
||||||
this._eventSignaturesMap.set(KIND_{{capitalize contract.contractName}}, eventSignatures);
|
this.eventSignaturesMap.set(KIND_{{capitalize contract.contractName}}, eventSignatures);
|
||||||
{{#if contract.contractStorageLayout}}
|
{{#if contract.contractStorageLayout}}
|
||||||
|
|
||||||
assert({{contract.contractName}}StorageLayout);
|
assert({{contract.contractName}}StorageLayout);
|
||||||
@ -689,7 +689,7 @@ export class Indexer implements IndexerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fetchEventsAndSaveBlocks (blocks: DeepPartial<BlockProgress>[]): Promise<{ blockProgress: BlockProgress, events: DeepPartial<Event>[] }[]> {
|
async fetchEventsAndSaveBlocks (blocks: DeepPartial<BlockProgress>[]): Promise<{ blockProgress: BlockProgress, events: DeepPartial<Event>[] }[]> {
|
||||||
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<{
|
async fetchAndSaveFilteredEventsAndBlocks (startBlock: number, endBlock: number): Promise<{
|
||||||
@ -698,11 +698,11 @@ export class Indexer implements IndexerInterface {
|
|||||||
ethFullBlock: EthFullBlock;
|
ethFullBlock: EthFullBlock;
|
||||||
ethFullTransactions: EthFullTransaction[];
|
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<DeepPartial<Event>[]> {
|
async fetchEventsForContracts (blockHash: string, blockNumber: number, addresses: string[]): Promise<DeepPartial<Event>[]> {
|
||||||
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<BlockProgress>): Promise<[
|
async saveBlockAndFetchEvents (block: DeepPartial<BlockProgress>): Promise<[
|
||||||
@ -843,7 +843,7 @@ export class Indexer implements IndexerInterface {
|
|||||||
assert(blockHash);
|
assert(blockHash);
|
||||||
assert(blockNumber);
|
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();
|
const dbTx = await this._db.createTransactionRunner();
|
||||||
try {
|
try {
|
||||||
|
@ -125,6 +125,21 @@ export class GraphWatcher {
|
|||||||
|
|
||||||
return acc;
|
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[] {
|
get dataSources (): any[] {
|
||||||
|
@ -27,6 +27,7 @@ import { GetStorageAt, getStorageValue, MappingKey, StorageLayout } from '@cerc-
|
|||||||
export class Indexer implements IndexerInterface {
|
export class Indexer implements IndexerInterface {
|
||||||
_getStorageAt: GetStorageAt;
|
_getStorageAt: GetStorageAt;
|
||||||
_storageLayoutMap: Map<string, StorageLayout> = new Map();
|
_storageLayoutMap: Map<string, StorageLayout> = new Map();
|
||||||
|
eventSignaturesMap: Map<string, string[]> = new Map();
|
||||||
|
|
||||||
constructor (ethClient: EthClient, storageLayoutMap?: Map<string, StorageLayout>) {
|
constructor (ethClient: EthClient, storageLayoutMap?: Map<string, StorageLayout>) {
|
||||||
this._getStorageAt = ethClient.getStorageAt.bind(ethClient);
|
this._getStorageAt = ethClient.getStorageAt.bind(ethClient);
|
||||||
|
@ -156,6 +156,7 @@ export interface EthClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IndexerInterface {
|
export interface IndexerInterface {
|
||||||
|
eventSignaturesMap: Map<string, string[]>
|
||||||
readonly serverConfig: ServerConfig
|
readonly serverConfig: ServerConfig
|
||||||
readonly upstreamConfig: UpstreamConfig
|
readonly upstreamConfig: UpstreamConfig
|
||||||
readonly storageLayoutMap: Map<string, StorageLayout>
|
readonly storageLayoutMap: Map<string, StorageLayout>
|
||||||
|
Loading…
Reference in New Issue
Block a user