Update codegen to store hash for indexed reference type event args

This commit is contained in:
nabarun 2022-06-29 12:03:24 +05:30 committed by Ashwin Phatak
parent 14a32a7d47
commit 26d998d3a7
6 changed files with 23 additions and 22 deletions

View File

@ -8,6 +8,7 @@ import assert from 'assert';
import Handlebars from 'handlebars';
import { Writable } from 'stream';
import _ from 'lodash';
import { utils } from 'ethers';
import { getTsForSol } from './utils/type-mappings';
import { Param } from './utils/types';
@ -82,7 +83,7 @@ export class Indexer {
this._queries.push(queryObject);
}
addEvent (name: string, params: Array<Param>, contractKind: string): void {
addEvent (name: string, params: Array<utils.ParamType>, contractKind: string): void {
// Check if the event is already added.
if (this._events.some(event => event.name === name && event.kind === contractKind)) {
return;
@ -90,17 +91,20 @@ export class Indexer {
const eventObject = {
name,
params: _.cloneDeep(params),
params: params.map((param) => {
const tsParamType = getTsForSol(param.type);
assert(tsParamType);
const isReferenceType = param.type === 'string' || param.type === 'bytes' || param.baseType === 'tuple' || param.baseType === 'array';
return {
...param,
type: tsParamType,
isIndexedReferenceType: param.indexed && isReferenceType
};
}),
kind: contractKind
};
eventObject.params = eventObject.params.map((param) => {
const tsParamType = getTsForSol(param.type);
assert(tsParamType);
param.type = tsParamType;
return param;
});
this._events.push(eventObject);
}

View File

@ -6,6 +6,7 @@ import assert from 'assert';
import { GraphQLSchema, parse, printSchema, print } from 'graphql';
import { SchemaComposer } from 'graphql-compose';
import { Writable } from 'stream';
import { utils } from 'ethers';
import { getTsForSol, getGqlForTs } from './utils/type-mappings';
import { Param } from './utils/types';
@ -65,7 +66,7 @@ export class Schema {
* @param name Event name.
* @param params Event parameters.
*/
addEventType (name: string, params: Array<Param>): void {
addEventType (name: string, params: Array<utils.ParamType>): void {
name = `${name}Event`;
// Check if the type is already added.

View File

@ -465,12 +465,14 @@ export class Indexer implements IPLDIndexerInterface {
case {{capitalize event.name}}_EVENT: {
eventName = logDescription.name;
{{#if event.params}}
const [ {{#each event.params~}} {{this.name}} {{~#unless @last}}, {{/unless}} {{~/each}} ] = logDescription.args;
const [{{#each event.params~}} {{this.name}} {{~#unless @last}}, {{/unless}} {{~/each}}] = logDescription.args;
{{/if}}
eventInfo = {
{{#each event.params}}
{{#if (compare this.type 'bigint')}}
{{this.name}}: BigInt({{this.name}}.toString())
{{~else if this.isIndexedReferenceType}}
{{this.name}}: {{this.name}}.hash
{{~else}}
{{this.name}}
{{~/if}}

View File

@ -133,14 +133,10 @@ export class Visitor {
const contractInterface = new utils.Interface(abi);
Object.values(contractInterface.events).forEach(event => {
const params = event.inputs.map(input => {
return { name: input.name, type: input.type };
});
this._schema.addEventType(event.name, params);
this._schema.addEventType(event.name, event.inputs);
assert(this._contract);
this._indexer.addEvent(event.name, params, this._contract.kind);
this._indexer.addEvent(event.name, event.inputs, this._contract.kind);
});
}

View File

@ -109,7 +109,7 @@
```bash
# In MobyMask repo.
git checkout ng-use-watcher
git checkout use-laconic-watcher-as-hosted-index
```
* Run yarn to install the packages
@ -204,7 +204,7 @@
isPhisher(
blockHash: "LATEST_BLOCK_HASH"
contractAddress: "MOBY_ADDRESS",
key0: "phisherName"
key0: "TWT:phishername"
) {
value
proof {
@ -215,7 +215,7 @@
isMember(
blockHash: "LATEST_BLOCK_HASH"
contractAddress: "MOBY_ADDRESS",
key0: "memberName"
key0: "TWT:membername"
) {
value
proof {

View File

@ -589,7 +589,6 @@ export class Indexer implements IPLDIndexerInterface {
eventName = logDescription.name;
const [entity, isMember] = logDescription.args;
eventInfo = {
// Indexed reference type arg
entity: entity.hash,
isMember
};
@ -610,7 +609,6 @@ export class Indexer implements IPLDIndexerInterface {
eventName = logDescription.name;
const [entity, isPhisher] = logDescription.args;
eventInfo = {
// Indexed reference type arg
entity: entity.hash,
isPhisher
};