Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use stack-orchestrator for erc721-watcher demo #132

Merged
merged 3 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 108 additions & 10 deletions packages/erc721-watcher/demo.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,94 @@
# Demo

* For setup follow the [steps in Readme](./README.md#setup).
* Clone the [stack-orchestrator](https://github.com/vulcanize/stack-orchestrator) repo.

* Create a `config.sh` file.

```bash
cd stack-orchestrator/helper-scripts
./create-config.sh
```

* Setup the required repositories.

```bash
./setup-repositories.sh -p ssh
```

* Checkout [v4 release](https://github.com/vulcanize/go-ethereum/releases/tag/v1.10.19-statediff-4.0.2-alpha) in go-ethereum repo. The path for go-ethereum is specified by `vulcanize_go_ethereum` variable in `config.sh` file created in stack-orchestrator repo.

```bash
# In go-ethereum repo.
git checkout v1.10.19-statediff-4.0.2-alpha
```

* To run the stack-orchestrator, the docker-compose version used is:

```bash
docker-compose version

# docker-compose version 1.29.2, build 5becea4c
```

* Run the stack-orchestrator

```bash
cd stack-orchestrator/helper-scripts
```

```bash
./wrapper.sh -f true \
-m true \
-s v4 \
-l latest \
-v remove \
-p ../config.sh
```

* Run the IPFS (go-ipfs version 0.12.2) daemon:

```bash
ipfs daemon

# API server listening on /ip4/127.0.0.1/tcp/5001
```
The IPFS API address can be seen in the output.

* In the [config file](./environments/local.toml) update the `server.ipfsApiAddr` config with the IPFS API address.

* Create a postgres12 database for the watcher:

```bash
sudo su - postgres

# If database already exists
# dropdb erc721-watcher

createdb erc721-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):

```bash
# If database already exists
# dropdb erc721-watcher-job-queue

createdb erc721-watcher-job-queue
```

```
postgres@tesla:~$ psql -U postgres -h localhost erc721-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.

erc721-watcher-job-queue=# CREATE EXTENSION pgcrypto;
CREATE EXTENSION
erc721-watcher-job-queue=# exit
```

* In the [config file](./environments/local.toml) update the `database` connection settings.

* Run the watcher:

Expand Down Expand Up @@ -39,7 +127,17 @@
}
```

* Connect MetaMask to `http://localhost:8545` (with chain ID `41337`)
* Get the signer account address and export to a shell variable:

```bash
yarn account
```

```bash
export SIGNER_ADDRESS="<SIGNER_ADDRESS>"
```

* Connect MetaMask to `http://localhost:8545` (with chain ID `99`)

* Add a second account to Metamask and export the account address to a shell variable for later use:

Expand Down Expand Up @@ -78,7 +176,7 @@
balanceOf(
blockHash: "LATEST_BLOCK_HASH"
contractAddress: "NFT_ADDRESS"
owner: "0xDC7d7A8920C8Eecc098da5B7522a5F31509b5Bfc"
owner: "SIGNER_ADDRESS"
) {
value
proof {
Expand Down Expand Up @@ -113,7 +211,7 @@
_balances(
blockHash: "LATEST_BLOCK_HASH"
contractAddress: "NFT_ADDRESS"
key0: "0xDC7d7A8920C8Eecc098da5B7522a5F31509b5Bfc"
key0: "SIGNER_ADDRESS"
) {
value
proof {
Expand Down Expand Up @@ -152,10 +250,10 @@
* Mint token

```bash
yarn nft:mint --nft $NFT_ADDRESS --to 0xDC7d7A8920C8Eecc098da5B7522a5F31509b5Bfc --token-id 1
yarn nft:mint --nft $NFT_ADDRESS --to $SIGNER_ADDRESS --token-id 1
```

* A Transfer event to 0xDC7d7A8920C8Eecc098da5B7522a5F31509b5Bfc shall be visible in the subscription at endpoint.
* A Transfer event to SIGNER_ADDRESS shall be visible in the subscription at endpoint.

* An auto-generated `diff_staged` IPLDBlock should be added with parent CID pointing to the initial checkpoint IPLDBlock.

Expand Down Expand Up @@ -215,7 +313,7 @@
fromBalanceOf: balanceOf(
blockHash: "LATEST_BLOCK_HASH"
contractAddress: "NFT_ADDRESS"
owner: "0xDC7d7A8920C8Eecc098da5B7522a5F31509b5Bfc"
owner: "SIGNER_ADDRESS"
) {
value
proof {
Expand Down Expand Up @@ -248,10 +346,10 @@
* Transfer token

```bash
yarn nft:transfer --nft $NFT_ADDRESS --from 0xDC7d7A8920C8Eecc098da5B7522a5F31509b5Bfc --to $RECIPIENT_ADDRESS --token-id 1
yarn nft:transfer --nft $NFT_ADDRESS --from $SIGNER_ADDRESS --to $RECIPIENT_ADDRESS --token-id 1
```

* An Approval event for ZERO_ADDRESS (0xDC7d7A8920C8Eecc098da5B7522a5F31509b5Bfc) shall be visible in the subscription at endpoint.
* An Approval event for SIGNER_ADDRESS shall be visible in the subscription at endpoint.

* A Transfer event to $RECIPIENT_ADDRESS shall be visible in the subscription at endpoint.

Expand All @@ -271,7 +369,7 @@
yarn checkpoint --address $NFT_ADDRESS
```

* Run the `getState` query again with the output blockHash and kind checkpoint at the endpoint.
* Run the `getState` query again with the output blockHash and kind `checkpoint` at the endpoint.

* The latest checkpoint should have the aggregate of state diffs since the last checkpoint.

Expand Down
1 change: 1 addition & 0 deletions packages/erc721-watcher/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import './test/tasks/nft-deploy';
import './test/tasks/nft-mint';
import './test/tasks/nft-transfer';
import './test/tasks/block-latest';
import './test/tasks/account';

// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
Expand Down
3 changes: 2 additions & 1 deletion packages/erc721-watcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"nft:deploy": "hardhat --network localhost nft-deploy",
"nft:mint": "hardhat --network localhost nft-mint",
"nft:transfer": "hardhat --network localhost nft-transfer",
"block:latest": "hardhat --network localhost block-latest"
"block:latest": "hardhat --network localhost block-latest",
"account": "hardhat --network localhost account"
},
"repository": {
"type": "git",
Expand Down
12 changes: 12 additions & 0 deletions packages/erc721-watcher/test/tasks/account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Copyright 2022 Vulcanize, Inc.
//

import { task } from 'hardhat/config';
import '@nomiclabs/hardhat-ethers';

task('account', 'Prints the account', async (taskArgs, hre) => {
const [account] = await hre.ethers.getSigners();

console.log(account.address);
});