Skip to content

Commit

Permalink
Add update for custom properties in state diff
Browse files Browse the repository at this point in the history
  • Loading branch information
nikugogoi committed Jun 13, 2022
1 parent f2d299f commit 83a1b03
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 32 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/publish.yaml

This file was deleted.

86 changes: 78 additions & 8 deletions packages/erc721-watcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,82 @@
export RECIPIENT_ADDRESS="<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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion packages/erc721-watcher/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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': {
Expand Down

0 comments on commit 83a1b03

Please sign in to comment.