Feature request: Extension point to check if contract should be indexed
Problem
I need to dynamically choose which contracts to index. Currently there is a extension point shouldIndex in ContractIndexer uses contract data which requires indexer to fetch contract data before this call. It will fetch it for every contract new to indexer which dramatically reduce indexing performance.
Currently i use following dirty patch:
async shouldIndex?(contract: Contract): Promise<boolean> {
// patch ContractResolver to avoid fetching contract schema and other stuff if address should not be indexed
if (!this.patched) {
const registry = (this.ctx.diContainer as any)._registry._registryMap as Map<any, any>;
const self = this;
registry.forEach((v, k) => {
if ((k.toString() as string).indexOf('class ContractResolver') >= 0) {
const resolvedV = this.ctx.diContainer.resolve(k);
(resolvedV as any).resolve = async function (address) {
const shouldIndex = await self.shouldIndexAddress(address);
return shouldIndex ? this.cache.get(address) : null;
}
}
})
this.patched = true;
}
return this.shouldIndexAddress(contract.address);
}
Proposal
Add following extension point to ContractIndexer interface which will be executed BEFORE fetching contract data.
async shouldIndexAddress(address: string): Promise<boolean>;
Or maybe there is some another way to do this? I'm using version 0.7.0