mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-07 16:34:06 +00:00
Invoke subgraph handler in watcher event processing (#34)
* Invoke subgraph handler in watcher event processing * Fix error when invoking subgraph handler * Parse events using event signature specified in subgraph yaml * Use contract abi to parse event params * Invoke event handler based on event signature * Fill event with block and transaction data * Comment missing fields in block and transaction data
This commit is contained in:
@@ -10,14 +10,27 @@
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"internalType": "uint256",
|
||||
"internalType": "uint8",
|
||||
"name": "param2",
|
||||
"type": "uint256"
|
||||
"type": "uint8"
|
||||
}
|
||||
],
|
||||
"name": "Test",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "emitEvent",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "getMethod",
|
||||
|
||||
@@ -27,8 +27,8 @@ export class Test__Params {
|
||||
return this._event.parameters[0].value.toString();
|
||||
}
|
||||
|
||||
get param2(): BigInt {
|
||||
return this._event.parameters[1].value.toBigInt();
|
||||
get param2(): i32 {
|
||||
return this._event.parameters[1].value.toI32();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,21 @@ export class Example1 extends ethereum.SmartContract {
|
||||
return new Example1("Example1", address);
|
||||
}
|
||||
|
||||
emitEvent(): boolean {
|
||||
let result = super.call("emitEvent", "emitEvent():(bool)", []);
|
||||
|
||||
return result[0].toBoolean();
|
||||
}
|
||||
|
||||
try_emitEvent(): ethereum.CallResult<boolean> {
|
||||
let result = super.tryCall("emitEvent", "emitEvent():(bool)", []);
|
||||
if (result.reverted) {
|
||||
return new ethereum.CallResult();
|
||||
}
|
||||
let value = result.value;
|
||||
return ethereum.CallResult.fromValue(value[0].toBoolean());
|
||||
}
|
||||
|
||||
getMethod(): string {
|
||||
let result = super.call("getMethod", "getMethod():(string)", []);
|
||||
|
||||
@@ -52,3 +67,33 @@ export class Example1 extends ethereum.SmartContract {
|
||||
return ethereum.CallResult.fromValue(value[0].toString());
|
||||
}
|
||||
}
|
||||
|
||||
export class EmitEventCall extends ethereum.Call {
|
||||
get inputs(): EmitEventCall__Inputs {
|
||||
return new EmitEventCall__Inputs(this);
|
||||
}
|
||||
|
||||
get outputs(): EmitEventCall__Outputs {
|
||||
return new EmitEventCall__Outputs(this);
|
||||
}
|
||||
}
|
||||
|
||||
export class EmitEventCall__Inputs {
|
||||
_call: EmitEventCall;
|
||||
|
||||
constructor(call: EmitEventCall) {
|
||||
this._call = call;
|
||||
}
|
||||
}
|
||||
|
||||
export class EmitEventCall__Outputs {
|
||||
_call: EmitEventCall;
|
||||
|
||||
constructor(call: EmitEventCall) {
|
||||
this._call = call;
|
||||
}
|
||||
|
||||
get value0(): boolean {
|
||||
return this._call.outputValues[0].value.toBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,21 +6,19 @@ import {
|
||||
BigInt,
|
||||
ethereum,
|
||||
Address,
|
||||
Bytes
|
||||
ByteArray,
|
||||
Bytes,
|
||||
Entity
|
||||
} from '@graphprotocol/graph-ts';
|
||||
|
||||
import {
|
||||
Test
|
||||
} from './Example1/Example1';
|
||||
|
||||
export {
|
||||
BigDecimal,
|
||||
BigInt,
|
||||
|
||||
ethereum,
|
||||
Entity,
|
||||
|
||||
Address,
|
||||
Bytes,
|
||||
|
||||
Test
|
||||
ByteArray,
|
||||
Bytes
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export class ExampleEntity extends Entity {
|
||||
|
||||
this.set("count", Value.fromBigInt(BigInt.zero()));
|
||||
this.set("param1", Value.fromString(""));
|
||||
this.set("param2", Value.fromBigInt(BigInt.zero()));
|
||||
this.set("param2", Value.fromI32(0));
|
||||
}
|
||||
|
||||
save(): void {
|
||||
@@ -66,12 +66,12 @@ export class ExampleEntity extends Entity {
|
||||
this.set("param1", Value.fromString(value));
|
||||
}
|
||||
|
||||
get param2(): BigInt {
|
||||
get param2(): i32 {
|
||||
let value = this.get("param2");
|
||||
return value!.toBigInt();
|
||||
return value!.toI32();
|
||||
}
|
||||
|
||||
set param2(value: BigInt) {
|
||||
this.set("param2", Value.fromBigInt(value));
|
||||
set param2(value: i32) {
|
||||
this.set("param2", Value.fromI32(value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 example1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@graphprotocol/graph-cli": "ssh://git@github.com:vulcanize/graph-cli.git#graph-watcher-v0.22.1",
|
||||
"@graphprotocol/graph-ts": "0.22.0"
|
||||
"@graphprotocol/graph-cli": "ssh://git@github.com:vulcanize/graph-cli.git#ng-add-exports",
|
||||
"@graphprotocol/graph-ts": "^0.22.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ type ExampleEntity @entity {
|
||||
id: ID!
|
||||
count: BigInt!
|
||||
param1: String! # string
|
||||
param2: BigInt! # uint256
|
||||
param2: Int! # uint8
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ export function handleTest (event: Test): void {
|
||||
log.debug('event.address: {}', [event.address.toHexString()]);
|
||||
log.debug('event.params.param1: {}', [event.params.param1]);
|
||||
log.debug('event.params.param2: {}', [event.params.param2.toString()]);
|
||||
log.debug('event.block.hash: {}', [event.block.hash.toHexString()]);
|
||||
|
||||
// Entities can be loaded from the store using a string ID; this ID
|
||||
// needs to be unique across all entities of the same type
|
||||
|
||||
@@ -6,7 +6,7 @@ dataSources:
|
||||
name: Example1
|
||||
network: mainnet
|
||||
source:
|
||||
address: "0x3ebd8bb51fF52aDAc490117B31F5F137BB125A9D"
|
||||
address: "0x4Ab7aE18973491Df21d6103dfA55170fdB2CCC98"
|
||||
abi: Example1
|
||||
mapping:
|
||||
kind: ethereum/events
|
||||
@@ -18,6 +18,6 @@ dataSources:
|
||||
- name: Example1
|
||||
file: ./abis/Example1.json
|
||||
eventHandlers:
|
||||
- event: Test(string,uint256)
|
||||
- event: Test(string,uint8)
|
||||
handler: handleTest
|
||||
file: ./src/mapping.ts
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
chalk "^2.0.0"
|
||||
js-tokens "^4.0.0"
|
||||
|
||||
"@graphprotocol/graph-cli@ssh://git@github.com:vulcanize/graph-cli.git#graph-watcher-v0.22.1":
|
||||
"@graphprotocol/graph-cli@ssh://git@github.com:vulcanize/graph-cli.git#ng-add-exports":
|
||||
version "0.22.1"
|
||||
resolved "ssh://git@github.com:vulcanize/graph-cli.git#4241570e91578a0128deccc518d52eca00bd587c"
|
||||
resolved "ssh://git@github.com:vulcanize/graph-cli.git#d70ae40a7517a666f550b25a0fa4ae0d3758e7d0"
|
||||
dependencies:
|
||||
assemblyscript "0.19.10"
|
||||
binary-install-raw "0.0.13"
|
||||
@@ -51,10 +51,10 @@
|
||||
which "2.0.2"
|
||||
yaml "^1.5.1"
|
||||
|
||||
"@graphprotocol/graph-ts@0.22.0":
|
||||
version "0.22.0"
|
||||
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.22.0.tgz#5280513d1c8a162077f82ce7f9a492bb5783d6f4"
|
||||
integrity sha512-kJIBL73xBxj0+NJdRABukAtcrc3Mb8jt31s0tCLPe6c57rQXEf7KR9oYrFdzE1ZsJCP6j+MX+A2+sj1Pj3aJtQ==
|
||||
"@graphprotocol/graph-ts@^0.22.1":
|
||||
version "0.22.1"
|
||||
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.22.1.tgz#3189b2495b33497280f617316cce68074d48e236"
|
||||
integrity sha512-T5xrHN0tHJwd7ZnSTLhk5hAL3rCIp6rJ40kBCrETnv1mfK9hVyoojJK6VtBQXTbLsYtKe4SYjjD0cdOsAR9QiA==
|
||||
dependencies:
|
||||
assemblyscript "0.19.10"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user