Get event handler using cleaned subgraph event signature (#73)

This commit is contained in:
prathamesh0 2021-12-08 16:22:20 +05:30 committed by nabarun
parent d4e79ceee4
commit 3d3ebb0e43
2 changed files with 15 additions and 6 deletions

View File

@ -51,8 +51,8 @@ import { Slash } from './entity/Slash';
const log = debug('vulcanize:indexer');
const KIND_EDENNETWORK = 'EdenNetwork';
const KIND_MERKLEDISTRIBUTOR = 'MerkleDistributor';
const KIND_DISTRIBUTORGOVERNANCE = 'DistributorGovernance';
const KIND_MERKLEDISTRIBUTOR = 'EdenNetworkDistribution';
const KIND_DISTRIBUTORGOVERNANCE = 'EdenNetworkGovernance';
const TRANSFER_EVENT = 'Transfer';
const APPROVAL_EVENT = 'Approval';

View File

@ -123,16 +123,25 @@ export class GraphWatcher {
return;
}
// Get event handler based on event signature.
const eventHandler = dataSource.mapping.eventHandlers.find((eventHandler: any) => eventHandler.event === eventSignature);
const { instance: { exports: instanceExports }, contractInterface } = this._dataSourceMap[contract];
// Get event handler based on event topic (from event signature).
const eventTopic = contractInterface.getEventTopic(eventSignature);
const eventHandler = dataSource.mapping.eventHandlers.find((eventHandler: any) => {
// The event signature we get from logDescription is different than that given in the subgraph yaml file.
// For eg. event in subgraph.yaml: Stake(indexed address,uint256); from logDescription: Stake(address,uint256)
// ethers.js doesn't recognize the subgraph event signature with indexed keyword before param type.
// Match event topics from cleaned subgraph event signature (Stake(indexed address,uint256) -> Stake(address,uint256)).
const subgraphEventTopic = contractInterface.getEventTopic(eventHandler.event.replace(/indexed /g, ''));
return subgraphEventTopic === eventTopic;
});
if (!eventHandler) {
log(`No handler configured in subgraph for event ${eventSignature}`);
return;
}
const { instance: { exports: instanceExports }, contractInterface } = this._dataSourceMap[contract];
const eventFragment = contractInterface.getEvent(eventSignature);
const data = {