* Implement store get api without blockHash and blockNumber * Pass database instance to GraphWatcher * Implement store set without block data * Store blockHash and blockNumber in database entity table * Implement getting entity in subgraph from store.get * Add block data present in postgraphile * Pass db and context to instantiate method in tests * GQL API in graph-test-watcher to test store.set * Remove contract address from subgraph file * Fix block in dummy event data * Pass just blockHash to get an entity from the database * Review changes and add TODOs Co-authored-by: prathamesh <prathamesh.musale0@gmail.com> |
||
|---|---|---|
| .. | ||
| 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
activewatcher:Create database for the job queue and enable the
pgcryptoextension on them (https://github.com/timgit/pg-boss/blob/master/docs/usage.md#intro):createdb graph-test-watcher-job-queuepostgres@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
upstreamconfig in the config file and provide theipld-eth-serverGQL API and theindexer-dbpostgraphile endpoints.
Customize
-
Indexing on an event:
-
Edit the custom hook function
handleEvent(triggered on an event) in hooks.ts to perform corresponding indexing using theIndexerobject. -
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
activewatcher:-
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>
-