From 5d824b55ff0737e577dd85a678abfb0d76d14bff Mon Sep 17 00:00:00 2001 From: nabarun Date: Tue, 21 Jun 2022 16:08:26 +0530 Subject: [PATCH 1/3] Use stack-orchestrator for erc721-watcher demo --- packages/erc721-watcher/demo.md | 98 +++++++++++++++++-- packages/erc721-watcher/hardhat.config.ts | 1 + packages/erc721-watcher/package.json | 3 +- packages/erc721-watcher/test/tasks/account.ts | 12 +++ 4 files changed, 104 insertions(+), 10 deletions(-) create mode 100644 packages/erc721-watcher/test/tasks/account.ts diff --git a/packages/erc721-watcher/demo.md b/packages/erc721-watcher/demo.md index 709343462..d5d160256 100644 --- a/packages/erc721-watcher/demo.md +++ b/packages/erc721-watcher/demo.md @@ -1,6 +1,76 @@ # Demo -* For setup follow the [steps in Readme](./README.md#setup). +* Clone the [stack-orchestrator](https://github.com/vulcanize/stack-orchestrator) and [go-ethereum](https://github.com/vulcanize/stack-orchestrator) repos. + +* Checkout [v4 release](https://github.com/vulcanize/go-ethereum/releases/tag/v1.10.19-statediff-4.0.2-alpha) in go-ethereum repo. + + ```bash + # In go-ethereum repo. + git checkout v1.10.19-statediff-4.0.2-alpha + ``` + +* Create a `config.sh` file in `stack-orchestrator` repo. + + ```sh + # Path to go-ethereum repo. + vulcanize_go_ethereum=~/vulcanize/go-ethereum + + genesis_file_path='start-up-files/go-ethereum/auto-genesis.json' + extra_args='--metrics --metrics.expensive --metrics.addr 0.0.0.0 --metrics.port 6060' + db_write=true + eth_forward_eth_calls=false + eth_proxy_on_error=true + eth_http_path='go-ethereum:8545' + ``` + +* Run the stack-orchestrator for watcher + + ```bash + cd stack-orchestrator/helper-scripts + ``` + + ```bash + ./wrapper.sh -b watcher \ + -s v4 \ + -l latest \ + -v remove \ + -p ../config.sh + ``` + +* Run the IPFS (go-ipfs version 0.12.2) daemon: + + ```bash + ipfs daemon + ``` + +* 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 + 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): + + ``` + 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: @@ -39,7 +109,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="" + ``` + +* 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: @@ -78,7 +158,7 @@ balanceOf( blockHash: "LATEST_BLOCK_HASH" contractAddress: "NFT_ADDRESS" - owner: "0xDC7d7A8920C8Eecc098da5B7522a5F31509b5Bfc" + owner: "SIGNER_ADDRESS" ) { value proof { @@ -113,7 +193,7 @@ _balances( blockHash: "LATEST_BLOCK_HASH" contractAddress: "NFT_ADDRESS" - key0: "0xDC7d7A8920C8Eecc098da5B7522a5F31509b5Bfc" + key0: "SIGNER_ADDRESS" ) { value proof { @@ -152,10 +232,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. @@ -215,7 +295,7 @@ fromBalanceOf: balanceOf( blockHash: "LATEST_BLOCK_HASH" contractAddress: "NFT_ADDRESS" - owner: "0xDC7d7A8920C8Eecc098da5B7522a5F31509b5Bfc" + owner: "SIGNER_ADDRESS" ) { value proof { @@ -248,10 +328,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. diff --git a/packages/erc721-watcher/hardhat.config.ts b/packages/erc721-watcher/hardhat.config.ts index 5d885b127..1dd86450c 100644 --- a/packages/erc721-watcher/hardhat.config.ts +++ b/packages/erc721-watcher/hardhat.config.ts @@ -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 diff --git a/packages/erc721-watcher/package.json b/packages/erc721-watcher/package.json index 9192d8454..461c3721b 100644 --- a/packages/erc721-watcher/package.json +++ b/packages/erc721-watcher/package.json @@ -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", diff --git a/packages/erc721-watcher/test/tasks/account.ts b/packages/erc721-watcher/test/tasks/account.ts new file mode 100644 index 000000000..78a15e35a --- /dev/null +++ b/packages/erc721-watcher/test/tasks/account.ts @@ -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); +}); From af355f67032a64db903d714cb1888e16f9de89e7 Mon Sep 17 00:00:00 2001 From: nabarun Date: Tue, 21 Jun 2022 18:27:25 +0530 Subject: [PATCH 2/3] Run all services in stack-orchestrator with auto mining of blocks --- packages/erc721-watcher/demo.md | 43 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/packages/erc721-watcher/demo.md b/packages/erc721-watcher/demo.md index d5d160256..ceb87facf 100644 --- a/packages/erc721-watcher/demo.md +++ b/packages/erc721-watcher/demo.md @@ -1,40 +1,43 @@ # Demo -* Clone the [stack-orchestrator](https://github.com/vulcanize/stack-orchestrator) and [go-ethereum](https://github.com/vulcanize/stack-orchestrator) repos. +* Clone the [stack-orchestrator](https://github.com/vulcanize/stack-orchestrator) repo. -* Checkout [v4 release](https://github.com/vulcanize/go-ethereum/releases/tag/v1.10.19-statediff-4.0.2-alpha) in go-ethereum repo. +* Create a `config.sh` file. ```bash - # In go-ethereum repo. - git checkout v1.10.19-statediff-4.0.2-alpha + cd stack-orchestrator/helper-scripts + ./create-config.sh ``` -* Create a `config.sh` file in `stack-orchestrator` repo. +* Setup the required repositories. - ```sh - # Path to go-ethereum repo. - vulcanize_go_ethereum=~/vulcanize/go-ethereum + ```bash + ./setup-repositories.sh + + ## Use ssh for cloning repos + # ./setup-repositories.sh -p ssh + ``` - genesis_file_path='start-up-files/go-ethereum/auto-genesis.json' - extra_args='--metrics --metrics.expensive --metrics.addr 0.0.0.0 --metrics.port 6060' - db_write=true - eth_forward_eth_calls=false - eth_proxy_on_error=true - eth_http_path='go-ethereum:8545' +* 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 ``` -* Run the stack-orchestrator for watcher +* Run the stack-orchestrator ```bash cd stack-orchestrator/helper-scripts ``` ```bash - ./wrapper.sh -b watcher \ - -s v4 \ - -l latest \ - -v remove \ - -p ../config.sh + ./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: From e6d67f46df8013a21439c4a4873a9b43b944c0a7 Mon Sep 17 00:00:00 2001 From: nabarun Date: Wed, 22 Jun 2022 12:38:52 +0530 Subject: [PATCH 3/3] Add step to check docker-compose version --- packages/erc721-watcher/demo.md | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/erc721-watcher/demo.md b/packages/erc721-watcher/demo.md index ceb87facf..3327f2eab 100644 --- a/packages/erc721-watcher/demo.md +++ b/packages/erc721-watcher/demo.md @@ -12,10 +12,7 @@ * Setup the required repositories. ```bash - ./setup-repositories.sh - - ## Use ssh for cloning repos - # ./setup-repositories.sh -p ssh + ./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. @@ -25,6 +22,14 @@ 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 @@ -44,7 +49,10 @@ ```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. @@ -52,12 +60,19 @@ ```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 ``` @@ -354,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.