watcher-ts/packages/graph-test-watcher
prathamesh0 16bb955213 Invoke subgraph block handlers (#43)
* Add a test case to eden test to call the block handler

* Add a block handler in example subgraph and call it in a watcher

* Use an array map to call all the block handlers for a contract

* Await on all the promises returned by block handlers map
2021-12-28 16:08:05 +05:30
..
environments Invoke subgraph handler in watcher event processing (#34) 2021-12-28 16:08:05 +05:30
src Invoke subgraph block handlers (#43) 2021-12-28 16:08:05 +05:30
.eslintignore Integrate generated watcher to invoke handlers in graph-node (#33) 2021-12-28 16:08:05 +05:30
.eslintrc.json Integrate generated watcher to invoke handlers in graph-node (#33) 2021-12-28 16:08:05 +05:30
.gitignore Integrate generated watcher to invoke handlers in graph-node (#33) 2021-12-28 16:08:05 +05:30
package.json Integrate generated watcher to invoke handlers in graph-node (#33) 2021-12-28 16:08:05 +05:30
README.md Integrate generated watcher to invoke handlers in graph-node (#33) 2021-12-28 16:08:05 +05:30
tsconfig.json Integrate generated watcher to invoke handlers in graph-node (#33) 2021-12-28 16:08:05 +05:30

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 the ipld-eth-server GQL API and the indexer-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 the Indexer 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>