From 83a1b0314a5fdcf5962847f00f42888e388ab7b4 Mon Sep 17 00:00:00 2001 From: nabarun Date: Mon, 13 Jun 2022 15:44:04 +0530 Subject: [PATCH] Add update for custom properties in state diff --- .github/workflows/publish.yaml | 23 -------- packages/erc721-watcher/README.md | 86 +++++++++++++++++++++++++--- packages/erc721-watcher/src/hooks.ts | 15 ++++- 3 files changed, 92 insertions(+), 32 deletions(-) delete mode 100644 .github/workflows/publish.yaml diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml deleted file mode 100644 index 797eee8b2..000000000 --- a/.github/workflows/publish.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: Publish Docker image -on: - release: - types: [published] -jobs: - docker_publish: - name: Push Docker image to Github Hub - runs-on: ubuntu-latest - steps: - - name: Get the version - id: vars - run: | - echo ::set-output name=sha::$(echo ${GITHUB_SHA:0:7}) - echo ::set-output name=tag::$(echo ${GITHUB_REF#refs/tags/}) - - name: Docker Login to Registry - run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u vulcanize --password-stdin - - name: Docker Pull - run: docker pull ghcr.io/vulcanize/graph-watcher-ts:${{steps.vars.outputs.sha}} - - name: Tag docker image - run: docker tag ghcr.io/vulcanize/graph-watcher-ts:${{steps.vars.outputs.sha}} ghcr.io/vulcanize/graph-watcher-ts:${{steps.vars.outputs.tag}} - - name: Docker Push to Github Hub - run: docker push ghcr.io/vulcanize/graph-watcher-ts:${{steps.vars.outputs.tag}} - diff --git a/packages/erc721-watcher/README.md b/packages/erc721-watcher/README.md index 2f14a9277..e841d918d 100644 --- a/packages/erc721-watcher/README.md +++ b/packages/erc721-watcher/README.md @@ -102,6 +102,82 @@ export RECIPIENT_ADDRESS="" ``` +* To get the current block hash at any time, run: + + ```bash + yarn block:latest + ``` + +* Run the following GQL query (`eth_call`) in generated watcher GraphQL endpoint http://127.0.0.1:3006/graphql + + ```graphql + query { + name( + blockHash: "LATEST_BLOCK_HASH" + contractAddress: "NFT_ADDRESS" + ) { + value + proof { + data + } + } + symbol( + blockHash: "LATEST_BLOCK_HASH" + contractAddress: "NFT_ADDRESS" + ) { + value + proof { + data + } + } + balanceOf( + blockHash: "LATEST_BLOCK_HASH" + contractAddress: "NFT_ADDRESS" + owner: "0xDC7d7A8920C8Eecc098da5B7522a5F31509b5Bfc" + ) { + value + proof { + data + } + } + } + ``` + +* Run the following GQL query (`storage`) in generated watcher graphql endpoint http://127.0.0.1:3006/graphql + + ```graphql + query { + _name( + blockHash: "LATEST_BLOCK_HASH" + contractAddress: "NFT_ADDRESS" + ) { + value + proof { + data + } + } + _symbol( + blockHash: "LATEST_BLOCK_HASH" + contractAddress: "NFT_ADDRESS" + ) { + value + proof { + data + } + } + _balances( + blockHash: "LATEST_BLOCK_HASH" + contractAddress: "NFT_ADDRESS" + key0: "0xDC7d7A8920C8Eecc098da5B7522a5F31509b5Bfc" + ) { + value + proof { + data + } + } + } + ``` + * Run the following GQL subscription in generated watcher GraphQL endpoint: ```graphql @@ -165,13 +241,7 @@ `diff` IPLDBlocks get created corresponding to the `diff_staged` blocks when their respective eth_blocks reach the pruned region. -* To get the current block hash at any time, run: - - ```bash - yarn block:latest - ``` - -* Run the following query for `balanceOf` and `ownerOf` (`eth_call`): +* Get the latest blockHash and run the following query for `balanceOf` and `ownerOf` (`eth_call`): ```graphql query { @@ -224,7 +294,7 @@ * Run the getState query again at the endpoint with the event blockHash. - * After the `diff` block has been created, create a checkpoint using CLI in `packages/erc721-watcher`: + * After the `diff` block has been created (can check if event block number pruned in yarn server log), create a checkpoint using CLI in `packages/erc721-watcher`: ```bash yarn checkpoint --address $NFT_ADDRESS diff --git a/packages/erc721-watcher/src/hooks.ts b/packages/erc721-watcher/src/hooks.ts index cdf2be3c7..771715f8c 100644 --- a/packages/erc721-watcher/src/hooks.ts +++ b/packages/erc721-watcher/src/hooks.ts @@ -4,7 +4,7 @@ import assert from 'assert'; -// import { updateStateForMappingType, updateStateForElementaryType } from '@vulcanize/util'; +import { updateStateForMappingType, updateStateForElementaryType } from '@vulcanize/util'; import { Indexer, ResultEvent } from './indexer'; @@ -94,6 +94,19 @@ export async function handleEvent (indexer: Indexer, eventData: ResultEvent): Pr // Update owner for the tokenId in database. await indexer._owners(eventData.block.hash, eventData.contract, tokenId, true); + // Update custom state diffs with properties name and symbol. + // { + // "name": "TestNFT", + // "symbol": "TNFT" + // } + const { value: name } = await indexer.name(eventData.block.hash, eventData.contract); + const nameUpdate = updateStateForElementaryType({}, 'name', name); + await indexer.createDiffStaged(eventData.contract, eventData.block.hash, nameUpdate); + + const { value: symbol } = await indexer.symbol(eventData.block.hash, eventData.contract); + const symbolUpdate = updateStateForElementaryType({}, 'symbol', symbol); + await indexer.createDiffStaged(eventData.contract, eventData.block.hash, symbolUpdate); + break; } case 'ApprovalEvent': {