From 3a803498aa3f7e8faf601e832164125880a0b326 Mon Sep 17 00:00:00 2001 From: CedarMist <134699267+CedarMist@users.noreply.github.com> Date: Thu, 8 Jun 2023 16:07:11 +0100 Subject: [PATCH 1/7] PNPM inside Docker, via Makefile --- opl-secret-ballot/.gitignore | 3 +++ opl-secret-ballot/Makefile | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 opl-secret-ballot/Makefile diff --git a/opl-secret-ballot/.gitignore b/opl-secret-ballot/.gitignore index 552f221..d5bfd4c 100644 --- a/opl-secret-ballot/.gitignore +++ b/opl-secret-ballot/.gitignore @@ -1,2 +1,5 @@ node_modules/ *.log +.cache +.bashrc +.local diff --git a/opl-secret-ballot/Makefile b/opl-secret-ballot/Makefile new file mode 100644 index 0000000..ca6a44c --- /dev/null +++ b/opl-secret-ballot/Makefile @@ -0,0 +1,26 @@ +ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) + +DOCKER=docker run --rm -it --hostname=opl -u `id -u`:`id -g` -e HISTFILESIZE=0 -e HOME=/src --network=host -w /src -v $(ROOT_DIR):/src node:latest + +PNPM=$(DOCKER) .local/share/pnpm/pnpm + +all: pnpm-install build + +pnpm-install: + $(DOCKER) bash -c 'curl -fsSL https://get.pnpm.io/install.sh | SHELL=bash sh -' + $(PNPM) install + +build: + $(PNPM) run -C /src/backend build:compile + $(PNPM) run -C /src/backend build:cjs + $(PNPM) run -C /src/backend build:esm + $(PNPM) run -C /src/frontend build + +shell: + $(DOCKER) bash + +clean: + rm -rf .bash_history .npm package-lock.json package.json .local .cache .bashrc .bash_history + rm -rf node_modules functions/node_modules frontend/node_modules backend/node_modules + rm -rf backend/typechain-types backend/cache backend/artifacts backend/lib + rm -rf frontend/dist From 54f91584c83e3bbf9ea8d69e6da60a9d80cc7346 Mon Sep 17 00:00:00 2001 From: CedarMist <134699267+CedarMist@users.noreply.github.com> Date: Fri, 9 Jun 2023 07:52:23 +0100 Subject: [PATCH 2/7] Improved readme with metamask network instructions + Makefile info Makefile includes targets for backend deployment, running VITE etc. --- opl-secret-ballot/.gitignore | 2 ++ opl-secret-ballot/Makefile | 19 ++++++++++++++++--- opl-secret-ballot/README.md | 19 ++++++++++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/opl-secret-ballot/.gitignore b/opl-secret-ballot/.gitignore index d5bfd4c..e8e0a82 100644 --- a/opl-secret-ballot/.gitignore +++ b/opl-secret-ballot/.gitignore @@ -3,3 +3,5 @@ node_modules/ .cache .bashrc .local +.bash_history +.npm diff --git a/opl-secret-ballot/Makefile b/opl-secret-ballot/Makefile index ca6a44c..9f7e115 100644 --- a/opl-secret-ballot/Makefile +++ b/opl-secret-ballot/Makefile @@ -1,8 +1,8 @@ ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) -DOCKER=docker run --rm -it --hostname=opl -u `id -u`:`id -g` -e HISTFILESIZE=0 -e HOME=/src --network=host -w /src -v $(ROOT_DIR):/src node:latest +DOCKER=docker run --rm -it --hostname=opl -u `id -u`:`id -g` -e HISTFILESIZE=0 -e HOME=/src --network=host -w /src -v $(ROOT_DIR):/src node:lts -PNPM=$(DOCKER) .local/share/pnpm/pnpm +PNPM=$(DOCKER) /src/.local/share/pnpm/pnpm all: pnpm-install build @@ -10,12 +10,25 @@ pnpm-install: $(DOCKER) bash -c 'curl -fsSL https://get.pnpm.io/install.sh | SHELL=bash sh -' $(PNPM) install -build: +build: build-backend build-frontend + +build-backend: $(PNPM) run -C /src/backend build:compile $(PNPM) run -C /src/backend build:cjs $(PNPM) run -C /src/backend build:esm + +build-frontend: $(PNPM) run -C /src/frontend build +frontend-dev: + $(PNPM) run -C /src/frontend dev + +backend-deploy: + $(DOCKER) bash -c 'cd /src/backend && /src/.local/share/pnpm/pnpm hardhat deploy-local --network localhost' + +backend-node: + $(DOCKER) bash -c 'cd /src/backend && /src/.local/share/pnpm/pnpm hardhat node' + shell: $(DOCKER) bash diff --git a/opl-secret-ballot/README.md b/opl-secret-ballot/README.md index 94d7e51..8d8c774 100644 --- a/opl-secret-ballot/README.md +++ b/opl-secret-ballot/README.md @@ -74,4 +74,21 @@ npm run dev Navigate to http://localhost:5173, and you should be able to create a new poll. -You can use one of the deployed test accounts and associated private key with MetaMask. +You can use one of the pre-funded test accounts and associated private key with MetaMask, use 'Add a network manually' with these parameters to connect to your local Hardhat node: + + * Network name: `Hardhat` + * New RPC URL: `http://127.0.0.1:8545/` + * Chain ID: `1337` (or leave blank to auto-detect) + * Currency symbol: `ETH` (or leave blank) + +### Docker + Makefile + +If you prefer to run everything safely inside inside a Docker container, a Makefile is provided for your convenience: + +``` +make pnpm-install # Install pnpm and all frontend+backend dependencies +make backend-node & # Run local Hardhat node +make backend-deploy # Deploy contracts to local node +make frontend-dev & # Run VITE development server +make shell # Bash shell inside container +``` From 96e24365cc72d5b764f833af6f04a1e2548ad025 Mon Sep 17 00:00:00 2001 From: CedarMist <134699267+CedarMist@users.noreply.github.com> Date: Mon, 19 Jun 2023 13:59:48 +0100 Subject: [PATCH 3/7] Updated Makefile with feedback comments --- opl-secret-ballot/Makefile | 44 +++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/opl-secret-ballot/Makefile b/opl-secret-ballot/Makefile index 9f7e115..9d4f737 100644 --- a/opl-secret-ballot/Makefile +++ b/opl-secret-ballot/Makefile @@ -1,37 +1,57 @@ ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) +# Runs a local ephemeral docker instance, with current dir bind-mounted to /src DOCKER=docker run --rm -it --hostname=opl -u `id -u`:`id -g` -e HISTFILESIZE=0 -e HOME=/src --network=host -w /src -v $(ROOT_DIR):/src node:lts -PNPM=$(DOCKER) /src/.local/share/pnpm/pnpm - -all: pnpm-install build +DOCKER_PNPM=$(DOCKER) /src/.local/share/pnpm/pnpm + +PNPM=pnpm + +all: + @echo If you\'re not using docker, run: + @echo + @echo $$ make pnpm-install + @echo $$ make build + @echo + @echo To install PNPM + package.json dependencies inside a container, run: + @echo + @echo $$ make docker-pnpm-install + @echo + @echo Then to open a shell inside the container: + @echo + @echo $$ make docker-shell + @echo pnpm-install: - $(DOCKER) bash -c 'curl -fsSL https://get.pnpm.io/install.sh | SHELL=bash sh -' $(PNPM) install +docker-pnpm-install: + $(DOCKER) bash -c 'curl -fsSL https://get.pnpm.io/install.sh | SHELL=bash sh -' + $(DOCKER_PNPM) install + build: build-backend build-frontend build-backend: - $(PNPM) run -C /src/backend build:compile - $(PNPM) run -C /src/backend build:cjs - $(PNPM) run -C /src/backend build:esm + $(PNPM) run -C backend build:compile + $(PNPM) run -C backend build:cjs + $(PNPM) run -C backend build:esm build-frontend: - $(PNPM) run -C /src/frontend build + $(PNPM) run -C frontend build frontend-dev: - $(PNPM) run -C /src/frontend dev + $(PNPM) run -C frontend dev backend-deploy: - $(DOCKER) bash -c 'cd /src/backend && /src/.local/share/pnpm/pnpm hardhat deploy-local --network localhost' + cd backend && $(PNPM) hardhat deploy-local --network localhost backend-node: - $(DOCKER) bash -c 'cd /src/backend && /src/.local/share/pnpm/pnpm hardhat node' + cd backend && $(PNPM) hardhat node -shell: +docker-shell: $(DOCKER) bash +.PHONY: clean clean: rm -rf .bash_history .npm package-lock.json package.json .local .cache .bashrc .bash_history rm -rf node_modules functions/node_modules frontend/node_modules backend/node_modules From 68efef0afc785d5cb26ead9413cb1239bdddff8a Mon Sep 17 00:00:00 2001 From: CedarMist <134699267+CedarMist@users.noreply.github.com> Date: Mon, 19 Jun 2023 15:50:42 +0100 Subject: [PATCH 4/7] Updated README to account for new makefile + docker instructions --- opl-secret-ballot/README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/opl-secret-ballot/README.md b/opl-secret-ballot/README.md index 8d8c774..c8a9335 100644 --- a/opl-secret-ballot/README.md +++ b/opl-secret-ballot/README.md @@ -86,9 +86,10 @@ You can use one of the pre-funded test accounts and associated private key with If you prefer to run everything safely inside inside a Docker container, a Makefile is provided for your convenience: ``` -make pnpm-install # Install pnpm and all frontend+backend dependencies -make backend-node & # Run local Hardhat node -make backend-deploy # Deploy contracts to local node -make frontend-dev & # Run VITE development server -make shell # Bash shell inside container +make docker-pnpm-install # Install pnpm & package.json dependencies inside the Docker container +make shell # Bash shell inside container +node@opl:~$ make build +node@opl:~$ make backend-node & # Run local Hardhat node +node@opl:~$ make backend-deploy # Deploy contracts to local node +node@opl:~$ make frontend-dev & # Run VITE development server ``` From 9df4b0db657cdca67d08abd93b690a950f98118e Mon Sep 17 00:00:00 2001 From: CedarMist <134699267+CedarMist@users.noreply.github.com> Date: Mon, 26 Jun 2023 10:44:52 +0100 Subject: [PATCH 5/7] Changed from ETH to TEST for currency in Metamask --- opl-secret-ballot/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opl-secret-ballot/README.md b/opl-secret-ballot/README.md index c8a9335..2c0ac48 100644 --- a/opl-secret-ballot/README.md +++ b/opl-secret-ballot/README.md @@ -79,7 +79,7 @@ You can use one of the pre-funded test accounts and associated private key with * Network name: `Hardhat` * New RPC URL: `http://127.0.0.1:8545/` * Chain ID: `1337` (or leave blank to auto-detect) - * Currency symbol: `ETH` (or leave blank) + * Currency symbol: `TEST` (or leave blank) ### Docker + Makefile From a3da8b2103f79dc0f2eccaef98bb7b01a931f9d8 Mon Sep 17 00:00:00 2001 From: CedarMist <134699267+CedarMist@users.noreply.github.com> Date: Mon, 26 Jun 2023 18:19:56 +0100 Subject: [PATCH 6/7] Improved Makefiles rules (matevz suggestion) + minor txtual cleanups --- opl-secret-ballot/.gitignore | 1 + opl-secret-ballot/Makefile | 36 ++++++++++++++++++++---------------- opl-secret-ballot/README.md | 6 +++--- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/opl-secret-ballot/.gitignore b/opl-secret-ballot/.gitignore index e8e0a82..0d53616 100644 --- a/opl-secret-ballot/.gitignore +++ b/opl-secret-ballot/.gitignore @@ -5,3 +5,4 @@ node_modules/ .local .bash_history .npm +.bashrc diff --git a/opl-secret-ballot/Makefile b/opl-secret-ballot/Makefile index 9d4f737..a816e9b 100644 --- a/opl-secret-ballot/Makefile +++ b/opl-secret-ballot/Makefile @@ -3,57 +3,61 @@ ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) # Runs a local ephemeral docker instance, with current dir bind-mounted to /src DOCKER=docker run --rm -it --hostname=opl -u `id -u`:`id -g` -e HISTFILESIZE=0 -e HOME=/src --network=host -w /src -v $(ROOT_DIR):/src node:lts -DOCKER_PNPM=$(DOCKER) /src/.local/share/pnpm/pnpm - +DOCKER_PNPM=.local/share/pnpm/pnpm PNPM=pnpm all: - @echo If you\'re not using docker, run: + @echo If you\'re not using Docker, run: @echo - @echo $$ make pnpm-install - @echo $$ make build + @echo " $$ make build" @echo - @echo To install PNPM + package.json dependencies inside a container, run: + @echo Or, to run open a shell development inside a Docker container: @echo - @echo $$ make docker-pnpm-install + @echo " $$ make docker-shell" @echo - @echo Then to open a shell inside the container: + @echo And then build the project as if you were not using Docker: @echo - @echo $$ make docker-shell + @echo " node@opl:~$$ make build" @echo -pnpm-install: +node_modules backend/node_modules frontend/node_modules: $(PNPM) install -docker-pnpm-install: +$(DOCKER_PNPM): $(DOCKER) bash -c 'curl -fsSL https://get.pnpm.io/install.sh | SHELL=bash sh -' - $(DOCKER_PNPM) install +.PHONY: build build: build-backend build-frontend -build-backend: +.PHONY: build-backend +build-backend: backend/node_modules $(PNPM) run -C backend build:compile $(PNPM) run -C backend build:cjs $(PNPM) run -C backend build:esm -build-frontend: +.PHONY: build-frontend +build-frontend: frontend/node_modules $(PNPM) run -C frontend build +.PHONY: frontend-dev frontend-dev: $(PNPM) run -C frontend dev +.PHONY: backend-deploy backend-deploy: cd backend && $(PNPM) hardhat deploy-local --network localhost +.PHONY: backend-node backend-node: cd backend && $(PNPM) hardhat node -docker-shell: +.PHONY: docker-shell +docker-shell: $(DOCKER_PNPM) $(DOCKER) bash .PHONY: clean clean: - rm -rf .bash_history .npm package-lock.json package.json .local .cache .bashrc .bash_history + rm -rf .bash_history .npm package-lock.json package.json .local .cache .bashrc .config rm -rf node_modules functions/node_modules frontend/node_modules backend/node_modules rm -rf backend/typechain-types backend/cache backend/artifacts backend/lib rm -rf frontend/dist diff --git a/opl-secret-ballot/README.md b/opl-secret-ballot/README.md index 2c0ac48..f28be66 100644 --- a/opl-secret-ballot/README.md +++ b/opl-secret-ballot/README.md @@ -83,11 +83,11 @@ You can use one of the pre-funded test accounts and associated private key with ### Docker + Makefile -If you prefer to run everything safely inside inside a Docker container, a Makefile is provided for your convenience: +If you prefer to run everything safely inside inside a Docker container, +a Makefile is provided for your convenience: ``` -make docker-pnpm-install # Install pnpm & package.json dependencies inside the Docker container -make shell # Bash shell inside container +make docker-shell # Bash shell inside container node@opl:~$ make build node@opl:~$ make backend-node & # Run local Hardhat node node@opl:~$ make backend-deploy # Deploy contracts to local node From 496e9e52fba89225c45cdfde9ef81afc7362d5ad Mon Sep 17 00:00:00 2001 From: CedarMist <134699267+CedarMist@users.noreply.github.com> Date: Tue, 27 Jun 2023 15:45:13 +0100 Subject: [PATCH 7/7] Updated README.md to limit to approx 100 chars line width max --- opl-secret-ballot/README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/opl-secret-ballot/README.md b/opl-secret-ballot/README.md index f28be66..7602670 100644 --- a/opl-secret-ballot/README.md +++ b/opl-secret-ballot/README.md @@ -1,7 +1,8 @@ ## Secret Ballot Lite This is a demo or light weight version of [opl-secret-ballot](https://github.com/oasislabs/opl-secret-ballot). -There are two key smart contracts that we will deploy, one interacting with a host chain such as Binance and one interacting with OPL or an enclave on Sapphire. +There are two key smart contracts that we will deploy, one interacting with a host chain +such as Binance and one interacting with OPL or an enclave on Sapphire. ### Backend @@ -37,7 +38,8 @@ pnpm run build ### Local Development -We will use [Hardhat](https://hardhat.org/hardhat-runner/docs/getting-started#overview) and [Hardhat-deploy](https://github.com/wighawag/hardhat-deploy) to simplify development. +We will use [Hardhat](https://hardhat.org/hardhat-runner/docs/getting-started#overview) +and [Hardhat-deploy](https://github.com/wighawag/hardhat-deploy) to simplify development. Start local Hardhat network ```sh @@ -60,8 +62,8 @@ and VITE_DAO_V1_ADDR=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 ``` -Additionally, we will need a [Pinata](https://www.pinata.cloud) API [key](https://docs.pinata.cloud/pinata-api/authentication) to access the pinning -service with which we store our ballots as JSON. +Additionally, we will need a [Pinata](https://www.pinata.cloud) API [key](https://docs.pinata.cloud/pinata-api/authentication) +to access the pinning service with which we store our ballots as JSON. ```yaml VITE_PINATA_JWT= @@ -74,7 +76,8 @@ npm run dev Navigate to http://localhost:5173, and you should be able to create a new poll. -You can use one of the pre-funded test accounts and associated private key with MetaMask, use 'Add a network manually' with these parameters to connect to your local Hardhat node: +You can use one of the pre-funded test accounts and associated private key with MetaMask, +use 'Add a network manually' with these parameters to connect to your local Hardhat node: * Network name: `Hardhat` * New RPC URL: `http://127.0.0.1:8545/`