mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-23 11:39:05 +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 Handlebars from 'handlebars';
|
||||||
import { Writable } from 'stream';
|
import { Writable } from 'stream';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import { utils } from 'ethers';
|
||||||
|
|
||||||
import { getTsForSol } from './utils/type-mappings';
|
import { getTsForSol } from './utils/type-mappings';
|
||||||
import { Param } from './utils/types';
|
import { Param } from './utils/types';
|
||||||
@ -82,7 +83,7 @@ export class Indexer {
|
|||||||
this._queries.push(queryObject);
|
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.
|
// Check if the event is already added.
|
||||||
if (this._events.some(event => event.name === name && event.kind === contractKind)) {
|
if (this._events.some(event => event.name === name && event.kind === contractKind)) {
|
||||||
return;
|
return;
|
||||||
@ -90,17 +91,20 @@ export class Indexer {
|
|||||||
|
|
||||||
const eventObject = {
|
const eventObject = {
|
||||||
name,
|
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
|
kind: contractKind
|
||||||
};
|
};
|
||||||
|
|
||||||
eventObject.params = eventObject.params.map((param) => {
|
|
||||||
const tsParamType = getTsForSol(param.type);
|
|
||||||
assert(tsParamType);
|
|
||||||
param.type = tsParamType;
|
|
||||||
return param;
|
|
||||||
});
|
|
||||||
|
|
||||||
this._events.push(eventObject);
|
this._events.push(eventObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import assert from 'assert';
|
|||||||
import { GraphQLSchema, parse, printSchema, print } from 'graphql';
|
import { GraphQLSchema, parse, printSchema, print } from 'graphql';
|
||||||
import { SchemaComposer } from 'graphql-compose';
|
import { SchemaComposer } from 'graphql-compose';
|
||||||
import { Writable } from 'stream';
|
import { Writable } from 'stream';
|
||||||
|
import { utils } from 'ethers';
|
||||||
|
|
||||||
import { getTsForSol, getGqlForTs } from './utils/type-mappings';
|
import { getTsForSol, getGqlForTs } from './utils/type-mappings';
|
||||||
import { Param } from './utils/types';
|
import { Param } from './utils/types';
|
||||||
@ -65,7 +66,7 @@ export class Schema {
|
|||||||
* @param name Event name.
|
* @param name Event name.
|
||||||
* @param params Event parameters.
|
* @param params Event parameters.
|
||||||
*/
|
*/
|
||||||
addEventType (name: string, params: Array<Param>): void {
|
addEventType (name: string, params: Array<utils.ParamType>): void {
|
||||||
name = `${name}Event`;
|
name = `${name}Event`;
|
||||||
|
|
||||||
// Check if the type is already added.
|
// Check if the type is already added.
|
||||||
|
@ -465,12 +465,14 @@ export class Indexer implements IPLDIndexerInterface {
|
|||||||
case {{capitalize event.name}}_EVENT: {
|
case {{capitalize event.name}}_EVENT: {
|
||||||
eventName = logDescription.name;
|
eventName = logDescription.name;
|
||||||
{{#if event.params}}
|
{{#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}}
|
{{/if}}
|
||||||
eventInfo = {
|
eventInfo = {
|
||||||
{{#each event.params}}
|
{{#each event.params}}
|
||||||
{{#if (compare this.type 'bigint')}}
|
{{#if (compare this.type 'bigint')}}
|
||||||
{{this.name}}: BigInt({{this.name}}.toString())
|
{{this.name}}: BigInt({{this.name}}.toString())
|
||||||
|
{{~else if this.isIndexedReferenceType}}
|
||||||
|
{{this.name}}: {{this.name}}.hash
|
||||||
{{~else}}
|
{{~else}}
|
||||||
{{this.name}}
|
{{this.name}}
|
||||||
{{~/if}}
|
{{~/if}}
|
||||||
|
@ -133,14 +133,10 @@ export class Visitor {
|
|||||||
const contractInterface = new utils.Interface(abi);
|
const contractInterface = new utils.Interface(abi);
|
||||||
|
|
||||||
Object.values(contractInterface.events).forEach(event => {
|
Object.values(contractInterface.events).forEach(event => {
|
||||||
const params = event.inputs.map(input => {
|
this._schema.addEventType(event.name, event.inputs);
|
||||||
return { name: input.name, type: input.type };
|
|
||||||
});
|
|
||||||
|
|
||||||
this._schema.addEventType(event.name, params);
|
|
||||||
|
|
||||||
assert(this._contract);
|
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
|
```bash
|
||||||
# In MobyMask repo.
|
# In MobyMask repo.
|
||||||
git checkout ng-use-watcher
|
git checkout use-laconic-watcher-as-hosted-index
|
||||||
```
|
```
|
||||||
|
|
||||||
* Run yarn to install the packages
|
* Run yarn to install the packages
|
||||||
@ -204,7 +204,7 @@
|
|||||||
isPhisher(
|
isPhisher(
|
||||||
blockHash: "LATEST_BLOCK_HASH"
|
blockHash: "LATEST_BLOCK_HASH"
|
||||||
contractAddress: "MOBY_ADDRESS",
|
contractAddress: "MOBY_ADDRESS",
|
||||||
key0: "phisherName"
|
key0: "TWT:phishername"
|
||||||
) {
|
) {
|
||||||
value
|
value
|
||||||
proof {
|
proof {
|
||||||
@ -215,7 +215,7 @@
|
|||||||
isMember(
|
isMember(
|
||||||
blockHash: "LATEST_BLOCK_HASH"
|
blockHash: "LATEST_BLOCK_HASH"
|
||||||
contractAddress: "MOBY_ADDRESS",
|
contractAddress: "MOBY_ADDRESS",
|
||||||
key0: "memberName"
|
key0: "TWT:membername"
|
||||||
) {
|
) {
|
||||||
value
|
value
|
||||||
proof {
|
proof {
|
||||||
|
@ -589,7 +589,6 @@ export class Indexer implements IPLDIndexerInterface {
|
|||||||
eventName = logDescription.name;
|
eventName = logDescription.name;
|
||||||
const [entity, isMember] = logDescription.args;
|
const [entity, isMember] = logDescription.args;
|
||||||
eventInfo = {
|
eventInfo = {
|
||||||
// Indexed reference type arg
|
|
||||||
entity: entity.hash,
|
entity: entity.hash,
|
||||||
isMember
|
isMember
|
||||||
};
|
};
|
||||||
@ -610,7 +609,6 @@ export class Indexer implements IPLDIndexerInterface {
|
|||||||
eventName = logDescription.name;
|
eventName = logDescription.name;
|
||||||
const [entity, isPhisher] = logDescription.args;
|
const [entity, isPhisher] = logDescription.args;
|
||||||
eventInfo = {
|
eventInfo = {
|
||||||
// Indexed reference type arg
|
|
||||||
entity: entity.hash,
|
entity: entity.hash,
|
||||||
isPhisher
|
isPhisher
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user