diff --git a/localnet/Dockerfile b/localnet/Dockerfile new file mode 100644 index 00000000..469ab915 --- /dev/null +++ b/localnet/Dockerfile @@ -0,0 +1,57 @@ +FROM ubuntu:20.04 + +RUN apt-get update && apt-get install -y git build-essential wget +RUN wget https://github.com/mikefarah/yq/releases/download/v4.9.3/yq_linux_amd64 -O /usr/bin/yq && chmod +x /usr/bin/yq + +COPY install-golang.sh install-golang.sh + +RUN sh install-golang.sh + +ENV GOROOT /usr/local/go +ENV GOPATH /go +ENV GOBIN /go/bin +ENV PATH $GOBIN:$GOROOT/bin:$PATH + +RUN git clone https://github.com/bitsongofficial/go-bitsong + +WORKDIR /go-bitsong + +# Change the commit hash if you want. +RUN git fetch && git checkout testnet + +# Build daemon. +RUN make build + +WORKDIR /go-bitsong/build + +RUN ./bitsongd init localnet --chain-id localnet-1 + +# configurations +RUN sed -i 's#tcp://127.0.0.1:26657#tcp://0.0.0.0:26657#g' ~/.bitsongd/config/config.toml +RUN sed -i 's/cors_allowed_origins = \[\]/cors_allowed_origins = \["*"\]/g' ~/.bitsongd/config/config.toml +RUN sed -i 's/timeout_commit = "5s"/timeout_commit = "1s"/g' ~/.bitsongd/config/config.toml +RUN sed -i 's/seeds = ".*"/seeds = ""/g' ~/.bitsongd/config/config.toml +RUN sed -i 's/"stake"/"ubtsg"/g' ~/.bitsongd/config/genesis.json +RUN sed -i 's/pruning = "default"/pruning = "nothing"/g' ~/.bitsongd/config/app.toml +RUN sed -i 's/enable = false/enable = true/g' ~/.bitsongd/config/app.toml +RUN sed -i 's/swagger = false/swagger = true/g' ~/.bitsongd/config/app.toml +RUN sed -i 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/g' ~/.bitsongd/config/app.toml +RUN sed -i 's/"voting_period": "172800s"/"voting_period": "300s"/g' ~/.bitsongd/config/genesis.json + +RUN echo "memory fault antenna oppose warfare mutual clap fossil earth solution matrix feel alley tired mix oppose melt plug marriage fiber pride hint cheap hand" | ./bitsongd keys add validator --recover --keyring-backend test +RUN echo "silk cricket salt museum voice unable unaware piece excess blue crawl juice soda during learn arrange amused pony excess float grit manage notice dinner" | ./bitsongd keys add user1 --recover --keyring-backend test +RUN echo "expose drastic inhale gain match pause alter drift across cluster sorry oven capital river wolf used soccer slim twelve wheel notice focus put dad" | ./bitsongd keys add user2 --recover --keyring-backend test +RUN echo "gap wave quantum merge online sausage process grow upset fossil capital high alcohol cost mansion oak truck like ask cancel random bachelor odor rich" | ./bitsongd keys add user3 --recover --keyring-backend test + +RUN ./bitsongd add-genesis-account $(./bitsongd keys show validator -a --keyring-backend test) 1000000000000ubtsg +RUN ./bitsongd add-genesis-account $(./bitsongd keys show user1 -a --keyring-backend test) 1000000000000ubtsg +RUN ./bitsongd add-genesis-account $(./bitsongd keys show user2 -a --keyring-backend test) 1000000000000ubtsg +RUN ./bitsongd add-genesis-account $(./bitsongd keys show user3 -a --keyring-backend test) 1000000000000ubtsg + +RUN ./bitsongd gentx validator 10000000000ubtsg --chain-id localnet-1 --keyring-backend test +RUN ./bitsongd collect-gentxs + +EXPOSE 26657 +EXPOSE 1317 +EXPOSE 9090 +CMD ./bitsongd start --trace \ No newline at end of file diff --git a/localnet/install-golang.sh b/localnet/install-golang.sh new file mode 100644 index 00000000..b3fd1c07 --- /dev/null +++ b/localnet/install-golang.sh @@ -0,0 +1,14 @@ +#! /bin/bash -x +set -e + +GOLANG_URL=https://dl.google.com/go/go1.17.3.linux-amd64.tar.gz +GOLANG_FILENAME=go1.17.3.linux-amd64.tar.gz + +if [ "aarch64" = $(uname -m) ]; then + GOLANG_URL=https://dl.google.com/go/go1.17.3.linux-arm64.tar.gz + GOLANG_FILENAME=go1.17.3.linux-arm64.tar.gz +fi + +wget $GOLANG_URL +tar -xvf $GOLANG_FILENAME +mv go /usr/local \ No newline at end of file diff --git a/localnet/mnemonics.txt b/localnet/mnemonics.txt new file mode 100644 index 00000000..915aece7 --- /dev/null +++ b/localnet/mnemonics.txt @@ -0,0 +1,4 @@ +memory fault antenna oppose warfare mutual clap fossil earth solution matrix feel alley tired mix oppose melt plug marriage fiber pride hint cheap hand +silk cricket salt museum voice unable unaware piece excess blue crawl juice soda during learn arrange amused pony excess float grit manage notice dinner +expose drastic inhale gain match pause alter drift across cluster sorry oven capital river wolf used soccer slim twelve wheel notice focus put dad +gap wave quantum merge online sausage process grow upset fossil capital high alcohol cost mansion oak truck like ask cancel random bachelor odor rich \ No newline at end of file diff --git a/package.json b/package.json index f42d9ce4..6fd0a6ea 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,9 @@ "private": true, "scripts": { "lint": "eslint --ext .js,.ts,.vue ./", - "test": "echo \"No test specified\" && exit 0" + "test": "echo \"No test specified\" && exit 0", + "localnet:start": "sh ./scripts/run-localnet.sh", + "localnet:stop": "docker rm --force bitsong_localnet" }, "dependencies": { "@bitsongjs/sdk": "1.0.0-dev-9", diff --git a/scripts/run-localnet.sh b/scripts/run-localnet.sh new file mode 100755 index 00000000..df79068b --- /dev/null +++ b/scripts/run-localnet.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +#DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +DIR=$(pwd) + +# Build the docker image first. +docker build --tag bitsong/localnet "$DIR"/localnet + +# Make sure that previous container not exist. +docker rm --force bitsong_localnet + +# Start container as daemon with some ports opening. +docker run -d -p 1317:1317 -p 26657:26657 -p 9090:9090 --name bitsong_localnet bitsong/localnet + +echo "Validator mnemonic: memory fault antenna oppose warfare mutual clap fossil earth solution matrix feel alley tired mix oppose melt plug marriage fiber pride hint cheap hand" +echo "Account1 mnemonic: silk cricket salt museum voice unable unaware piece excess blue crawl juice soda during learn arrange amused pony excess float grit manage notice dinner" +echo "Account2 mnemonic: expose drastic inhale gain match pause alter drift across cluster sorry oven capital river wolf used soccer slim twelve wheel notice focus put dad" +echo "Account2 mnemonic: gap wave quantum merge online sausage process grow upset fossil capital high alcohol cost mansion oak truck like ask cancel random bachelor odor rich" +echo "Each account has the balances (1000000000000ubtsg)" + +echo "Docker container is running on \"bitsong_localnet\"" +echo "After testing, to remove existing container, run \"sudo docker rm --force bitsong_localnet\"" \ No newline at end of file