watcher-ts/packages/mobymask-watcher/demo.md
nikugogoi c299737aab
Add demo for graph-test-watcher (#267)
* Add demo for graph-test-watcher

* Remove stack-orchestrator from demos
2022-11-28 16:35:19 +05:30

5.1 KiB

Demo

  • The following core services need to be running for the demo:

  • Create a postgres12 database for the watcher:

    sudo su - postgres
    
    # If database already exists
    # dropdb mobymask-watcher
    
    createdb mobymask-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):

    # If database already exists
    # dropdb mobymask-watcher-job-queue
    
    createdb mobymask-watcher-job-queue
    
    postgres@tesla:~$ psql -U postgres -h localhost mobymask-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.
    
    mobymask-watcher-job-queue=# CREATE EXTENSION pgcrypto;
    CREATE EXTENSION
    mobymask-watcher-job-queue=# exit
    
  • In the config file update the database connection settings.

  • In watcher-ts repo, follow the instructions in Setup for installing and building packages.

    # After setup
    yarn && yarn build
    
  • Run the job-runner:

    yarn job-runner
    
  • Change directory to packages/mobymask-watcher/ and run the watcher:

    yarn server
    
  • Clone the MobyMask repo.

  • Checkout to the branch with changes for using this watcher:

    # In MobyMask repo.
    git checkout use-laconic-watcher-as-hosted-index
    
  • Run yarn to install the packages

    yarn
    
  • Deploy the contract:

    cd packages/hardhat
    
    yarn deploy
    # deploying "PhisherRegistry" (tx: 0xaebeb2e883ece1f679304ec46f5dc61ca74f9e168427268a7dfa8802195b8de0)...: deployed at <MOBY_ADDRESS> with 2306221 gas
    # $ hardhat run scripts/publish.js
    # ✅  Published contracts to the subgraph package.
    # Done in 14.28s.
    

    Export the address of the deployed contract to a shell variable for later use:

    export MOBY_ADDRESS="<MOBY_ADDRESS>"
    
  • Run the following GQL mutation in watcher GraphQL endpoint http://127.0.0.1:3010/graphql

    mutation {
      watchContract(
        address: "MOBY_ADDRESS"
        kind: "PhisherRegistry"
        checkpoint: true
      )
    }
    
  • Get the latest block

    query {
      latestBlock {
        hash
        number
      }
    }
    
  • Run the following GQL query in GraphQL endpoint

    query {
      isPhisher(
        blockHash: "LATEST_BLOCK_HASH"
        contractAddress: "MOBY_ADDRESS"
        key0: "TWT:phishername"
      ) {
        value
        proof {
          data
        }
      }
      isMember(
        blockHash: "LATEST_BLOCK_HASH"
        contractAddress: "MOBY_ADDRESS"
        key0: "TWT:membername"
      ) {
        value
        proof {
          data
        }
      }
    }
    
  • Run the following GQL subscription in generated watcher GraphQL endpoint:

    subscription {
      onEvent {
        event {
          __typename
          ... on PhisherStatusUpdatedEvent {
            entity
            isPhisher
          },
          ... on MemberStatusUpdatedEvent {
            entity
            isMember
          }
        },
        block {
          number
          hash
        }
      }
    }
    
  • Update isPhiser and isMember lists with names

    yarn claimPhisher --contract $MOBY_ADDRESS --name phisherName 
    
    yarn claimMember --contract $MOBY_ADDRESS --name memberName
    
  • The events should be visible in the subscription at GQL endpoint. Note down the event blockHash from result.

  • The isMember and isPhisher lists should be indexed. Check the database (mobymask-watcher) tables is_phisher and is_member, there should be entries at the event blockHash and the value should be true. The data is indexed in handleEvent method in the hooks file.

  • Update the the previous query with event blockHash and check isPhisher and isMember in GraphQL playground

    query {
      isPhisher(
        blockHash: "EVENT_BLOCK_HASH"
        contractAddress: "MOBY_ADDRESS",
        key0: "TWT:phishername"
      ) {
        value
        proof {
          data
        }
      }
    
      isMember(
        blockHash: "EVENT_BLOCK_HASH"
        contractAddress: "MOBY_ADDRESS",
        key0: "TWT:membername"
      ) {
        value
        proof {
          data
        }
      }
    }
    

    The data is fetched from watcher database as it is already indexed.