mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-07 20:08:06 +00:00
Update codegen to store hash for indexed reference type event args
This commit is contained in:
parent
14a32a7d47
commit
26d998d3a7
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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}}
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user