4.6 KiB
Demo
-
The following core services need to be running for the demo:
- ipld-eth-db
- Version: v4.2.3-alpha
- geth
- State diffing service should use
ipld-eth-dbfor database. - Version: v1.10.26-statediff-4.2.2-alpha
- Endpoint: http://127.0.0.1:8545
- State diffing service should use
- ipld-eth-server
- Should use
ipld-eth-dbfor database. - Version: v4.2.3-alpha
- Endpoints:
- Should use
- ipld-eth-db
-
Create a postgres12 database for the watcher:
sudo su - postgres # If database already exists # dropdb graph-test-watcher createdb graph-test-watcher -
Create database for the job queue and enable the
pgcryptoextension on them (https://github.com/timgit/pg-boss/blob/master/docs/usage.md#intro):# If database already exists # dropdb graph-test-watcher-job-queue 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 -
In the config file update the
databaseconnection settings. -
In
watcher-tsrepo, follow the instructions in Setup for installing and building packages.# After setup yarn && yarn build -
In packages/graph-node, deploy an
Examplecontract:yarn example:deploy -
Set the returned address to the variable
$EXAMPLE_ADDRESS:EXAMPLE_ADDRESS=<EXAMPLE_ADDRESS> -
In packages/graph-node/test/subgraph/example1/subgraph.yaml:
- Set the source address for
Example1datasource to theEXAMPLE_ADDRESS. - Set the
startBlockless than or equal to the latest mined block.
- Set the source address for
-
Build the example subgraph:
yarn build:example -
Run the job-runner:
yarn job-runner -
Run the watcher:
yarn server -
The output from the block handler in the mapping code should be visible in the
job-runnerfor each block. -
Run the following GQL subscription at the graphql endpoint http://127.0.0.1:3008/graphql
subscription { onEvent { event { __typename ... on TestEvent { param1 param2 }, }, block { number hash } } } -
In packages/graph-node, trigger the
Testevent by calling a example contract method:yarn example:test --address $EXAMPLE_ADDRESS-
A
Testevent shall be visible in the subscription at endpoint. -
The subgraph entity
Categoryshould be updated in the database. -
An auto-generated
diff-stagedentryStateshould be added.
-
-
Run the query for entity in at the endpoint:
query { category( block: { hash: "EVENT_BLOCK_HASH" }, id: "1" ) { __typename id count name } } -
Run the
getStatequery at the endpoint to get the latestStateforEXAMPLE_ADDRESS:query { getState ( blockHash: "EVENT_BLOCK_HASH" contractAddress: "EXAMPLE_ADDRESS" # kind: "checkpoint" # kind: "diff" kind: "diff_staged" ) { cid block { cid hash number timestamp parentHash } contractAddress data } } -
diffstates get created corresponding to thediff_stagedstates when their respective blocks reach the pruned region. -
In packages/graph-test-watcher:
-
After the
diffstate has been created, create acheckpoint:yarn checkpoint create --address $EXAMPLE_ADDRESS-
A
checkpointstate should be created at the latest canonical block hash. -
Run the
getStatequery again at the endpoint with the outputblockHashand kindcheckpoint.
-
-
-
All the
Stateentries can be seen inpg-adminin tablestate.