watcher-ts/packages/graph-test-watcher
2023-01-16 07:40:39 -05:00
..
environments Accommodate GQL optimizations in graph-test-watcher (#249) 2022-11-22 15:20:44 +05:30
src Implement peer package to send messages between peers (#279) 2023-01-10 20:10:27 +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
demo.md Add demo for graph-test-watcher (#267) 2022-11-28 16:35:19 +05:30
package.json Add a method to send messages on the network using pubsub (#293) 2023-01-11 17:19:21 +05:30
README.md deduplicate into a docs/README 2023-01-16 07:40:39 -05:00
tsconfig.json Add a table for entites in frothy region for subgraph watchers (#231) 2022-11-16 17:12:54 +05:30

Example Watcher

Setup

  • Run the following command to install required packages:

    yarn
    

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.

    • While using the indexer storage methods for indexing, pass diff as true if default state is desired to be generated using the state variables being indexed.

  • Generating state:

    • Edit the custom hook function createInitialState (triggered if the watcher passes the start block, checkpoint: true) in hooks.ts to save an initial State using the Indexer object.

    • Edit the custom hook function createStateDiff (triggered on a block) in hooks.ts to save the state in a diff State using the Indexer object. The default state (if exists) is updated.

    • Edit the custom hook function createStateCheckpoint (triggered just before default and CLI checkpoint) in hooks.ts to save the state in a checkpoint State using the Indexer object.

  • The existing example hooks in hooks.ts are for an ERC20 contract.

Run

Follow the steps below or follow the Demo

  • Run the server:

    yarn server
    

    GQL console: http://localhost:3008/graphql

  • If the watcher is an active watcher:

    • Run the job-runner:

      yarn job-runner
      
    • Run the server:

      yarn server
      

      GQL console: http://localhost:3008/graphql

    • To watch a contract:

      yarn watch:contract --address <contract-address> --kind <contract-kind> --checkpoint <true | false> --starting-block [block-number]
      
      • address: Address or identifier of the contract to be watched.
      • kind: Kind of the contract.
      • checkpoint: Turn checkpointing on (true | false).
      • starting-block: Starting block for the contract (default: 1).

      Examples:

      Watch a contract with its address and checkpointing on:

      yarn watch:contract --address 0x1F78641644feB8b64642e833cE4AFE93DD6e7833 --kind ERC20 --checkpoint true
      

      Watch a contract with its identifier and checkpointing on:

      yarn watch:contract --address MyProtocol --kind protocol --checkpoint true
      
    • To fill a block range:

      yarn fill --start-block <from-block> --end-block <to-block>
      
      • start-block: Block number to start filling from.
      • end-block: Block number till which to fill.
    • To create a checkpoint for a contract:

      yarn checkpoint create --address <contract-address> --block-hash [block-hash]
      
      • address: Address or identifier of the contract for which to create a checkpoint.
      • block-hash: Hash of a block (in the pruned region) at which to create the checkpoint (default: latest canonical block hash).
    • To verify a checkpoint:

      yarn checkpoint verify --cid <checkpoint-cid>
      

      cid: CID of the checkpoint for which to verify.

    • To reset the watcher to a previous block number:

      • Reset watcher:

        yarn reset watcher --block-number <previous-block-number>
        
      • Reset job-queue:

        yarn reset job-queue
        
      • Reset state:

        yarn reset state --block-number <previous-block-number>
        
      • block-number: Block number to which to reset the watcher.

    • To export and import the watcher state:

      • In source watcher, export watcher state:

        yarn export-state --export-file [export-file-path] --block-number [snapshot-block-height]
        
        • export-file: Path of file to which to export the watcher data.
        • block-number: Block height at which to take snapshot for export.
      • In target watcher, run job-runner:

        yarn job-runner
        
      • Import watcher state:

        yarn import-state --import-file <import-file-path>
        
        • import-file: Path of file from which to import the watcher data.
      • Run server:

        yarn server
        
    • To inspect a CID:

      yarn inspect-cid --cid <cid>
      
      • cid: CID to be inspected.