nikugogoi
43d64f9e4b
* 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 |
||
---|---|---|
.. | ||
environments | ||
src | ||
.eslintignore | ||
.eslintrc.json | ||
.gitignore | ||
package.json | ||
README.md | ||
tsconfig.json |
Example Watcher
Setup
-
Run the following command to install required packages:
yarn
-
Create a postgres12 database for the watcher:
sudo su - postgres createdb graph-test-watcher
-
If the watcher is an
active
watcher:Create database for the job queue and enable the
pgcrypto
extension on them (https://github.com/timgit/pg-boss/blob/master/docs/usage.md#intro):createdb graph-test-watcher-job-queue
postgres@tesla:~$ psql -U postgres -h localhost graph-test-watcher-job-queue Password for user postgres: psql (12.7 (Ubuntu 12.7-1.pgdg18.04+1)) SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off) Type "help" for help. graph-test-watcher-job-queue=# CREATE EXTENSION pgcrypto; CREATE EXTENSION graph-test-watcher-job-queue=# exit
-
Update the config with database connection settings.
-
Update the
upstream
config in the config file and provide theipld-eth-server
GQL API and theindexer-db
postgraphile endpoints.
Customize
-
Indexing on an event:
-
Edit the custom hook function
handleEvent
(triggered on an event) in hooks.ts to perform corresponding indexing using theIndexer
object. -
Refer to hooks.example.ts for an example hook function for events in an ERC20 contract.
-
Run
-
Run the watcher:
yarn server
GQL console: http://localhost:3008/graphql
-
If the watcher is an
active
watcher:-
Run the job-runner:
yarn job-runner
-
To watch a contract:
yarn watch:contract --address <contract-address> --kind Example --starting-block [block-number]
-
To fill a block range:
yarn fill --startBlock <from-block> --endBlock <to-block>
-