Support filtering by topics when fetching logs in rpc-eth-client (#441)

* Support filtering by topics when fetching logs

* Include event signatures from all contracts in topics list

* Refactor common code

* Update package versions
This commit is contained in:
prathamesh0
2023-10-26 17:25:56 +05:30
committed by GitHub
parent 43463af1f2
commit a8e59eb6b9
21 changed files with 179 additions and 148 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/codegen",
"version": "0.2.66",
"version": "0.2.67",
"description": "Code generator",
"private": true,
"main": "index.js",
@@ -20,7 +20,7 @@
},
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
"dependencies": {
"@cerc-io/util": "^0.2.66",
"@cerc-io/util": "^0.2.67",
"@graphql-tools/load-files": "^6.5.2",
"@poanet/solidity-flattener": "https://github.com/vulcanize/solidity-flattener.git",
"@solidity-parser/parser": "^0.13.2",
@@ -23,8 +23,11 @@
clearEntitiesCacheInterval = 1000
{{/if}}
# Boolean to filter logs by contract.
filterLogs = false
# Boolean to filter logs by contracts.
filterLogsByAddresses = false
# Boolean to filter logs by topics.
filterLogsByTopics = false
# Max block range for which to return events in eventsInRange GQL query.
# Use -1 for skipping check on block range.
@@ -96,6 +96,7 @@ export class Indexer implements IndexerInterface {
_abiMap: Map<string, JsonFragment[]>;
_storageLayoutMap: Map<string, StorageLayout>;
_contractMap: Map<string, ethers.utils.Interface>;
_eventSignaturesMap: Map<string, string[]>;
{{#if (subgraphPath)}}
_entityTypesMap: Map<string, { [key: string]: string }>;
@@ -121,6 +122,9 @@ export class Indexer implements IndexerInterface {
this._abiMap = new Map();
this._storageLayoutMap = new Map();
this._contractMap = new Map();
this._eventSignaturesMap = new Map();
let contractInterface: ethers.utils.Interface;
let eventSignatures: string[];
{{#each contracts as | contract |}}
const { abi: {{contract.contractName}}ABI{{#if contract.contractStorageLayout}}, storageLayout: {{contract.contractName}}StorageLayout{{/if}} } = {{contract.contractName}}Artifacts;
@@ -129,11 +133,19 @@ export class Indexer implements IndexerInterface {
assert({{contract.contractName}}ABI);
this._abiMap.set(KIND_{{capitalize contract.contractName}}, {{contract.contractName}}ABI);
contractInterface = new ethers.utils.Interface({{contract.contractName}}ABI);
this._contractMap.set(KIND_{{capitalize contract.contractName}}, contractInterface);
eventSignatures = Object.values(contractInterface.events).map(value => {
return contractInterface.getEventTopic(value);
});
this._eventSignaturesMap.set(KIND_{{capitalize contract.contractName}}, eventSignatures);
{{#if contract.contractStorageLayout}}
assert({{contract.contractName}}StorageLayout);
this._storageLayoutMap.set(KIND_{{capitalize contract.contractName}}, {{contract.contractName}}StorageLayout);
{{/if}}
this._contractMap.set(KIND_{{capitalize contract.contractName}}, new ethers.utils.Interface({{contract.contractName}}ABI));
{{/each}}
{{#if (subgraphPath)}}
@@ -642,7 +654,7 @@ export class Indexer implements IndexerInterface {
}
async fetchEventsAndSaveBlocks (blocks: DeepPartial<BlockProgress>[]): Promise<{ blockProgress: BlockProgress, events: DeepPartial<Event>[] }[]> {
return this._baseIndexer.fetchEventsAndSaveBlocks(blocks, this.parseEventNameAndArgs.bind(this));
return this._baseIndexer.fetchEventsAndSaveBlocks(blocks, this._eventSignaturesMap, this.parseEventNameAndArgs.bind(this));
}
async saveBlockAndFetchEvents (block: DeepPartial<BlockProgress>): Promise<[BlockProgress, DeepPartial<Event>[]]> {
@@ -762,7 +774,7 @@ export class Indexer implements IndexerInterface {
assert(blockHash);
assert(blockNumber);
const dbEvents = await this._baseIndexer.fetchEvents(blockHash, blockNumber, this.parseEventNameAndArgs.bind(this));
const dbEvents = await this._baseIndexer.fetchEvents(blockHash, blockNumber, this._eventSignaturesMap, this.parseEventNameAndArgs.bind(this));
const dbTx = await this._db.createTransactionRunner();
try {
@@ -41,12 +41,12 @@
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
"dependencies": {
"@apollo/client": "^3.3.19",
"@cerc-io/cli": "^0.2.65",
"@cerc-io/ipld-eth-client": "^0.2.65",
"@cerc-io/solidity-mapper": "^0.2.65",
"@cerc-io/util": "^0.2.65",
"@cerc-io/cli": "^0.2.67",
"@cerc-io/ipld-eth-client": "^0.2.67",
"@cerc-io/solidity-mapper": "^0.2.67",
"@cerc-io/util": "^0.2.67",
{{#if (subgraphPath)}}
"@cerc-io/graph-node": "^0.2.65",
"@cerc-io/graph-node": "^0.2.67",
{{/if}}
"@ethersproject/providers": "^5.4.4",
"apollo-type-bigint": "^0.1.3",