github.com/cosmos/cosmos-sdk@v0.50.10/scripts/validate-gentxs.sh (about) 1 #!/usr/bin/env bash 2 3 DAEMON_HOME="/tmp/simd$(date +%s)" 4 RANDOM_KEY="randomvalidatorkey" 5 6 echo "#############################################" 7 echo "### Ensure to set the below ENV settings ###" 8 echo "#############################################" 9 echo " 10 DAEMON= # ex: simd 11 CHAIN_ID= # ex: testnet-1 12 DENOM= # ex: ustake 13 GH_URL= # ex: https://github.com/cosmos/cosmos-sdk 14 BINARY_VERSION= # ex :v0.44.0 15 GO_VERSION=1.17 16 PRELAUNCH_GENESIS_URL= # ex: https://raw.githubusercontent.com/cosmos/cosmos-sdk/master/$CHAIN_ID/genesis-prelaunch.json 17 GENTXS_DIR= # ex: $GOPATH/github.com/cosmos/mainnet/$CHAIN_ID/gentxs" 18 echo 19 20 if [[ -z "${GH_URL}" ]]; then 21 echo "GH_URL in not set, required. Ex: https://github.com/cosmos/cosmos-sdk" 22 exit 0 23 fi 24 if [[ -z "${DAEMON}" ]]; then 25 echo "DAEMON is not set, required. Ex: simd, gaiad etc" 26 exit 0 27 fi 28 if [[ -z "${DENOM}" ]]; then 29 echo "DENOM in not set, required. Ex: stake, uatom etc" 30 exit 0 31 fi 32 if [[ -z "${GO_VERSION}" ]]; then 33 echo "GO_VERSION in not set, required. Ex: 1.15.2, 1.16.6 etc." 34 exit 0 35 fi 36 if [[ -z "${CHAIN_ID}" ]]; then 37 echo "CHAIN_ID in not set, required." 38 exit 0 39 fi 40 if [[ -z "${PRELAUNCH_GENESIS_URL}" ]]; then 41 echo "PRELAUNCH_GENESIS_URL (genesis file url) in not set, required." 42 exit 0 43 fi 44 if [[ -z "${GENTXS_DIR}" ]]; then 45 echo "GENTXS_DIR in not set, required." 46 exit 0 47 fi 48 49 command_exists () { 50 type "$1" &> /dev/null ; 51 } 52 53 if command_exists go ; then 54 echo "Golang is already installed" 55 else 56 read -s -p "Installing go using apt. Do you want to proceed (y/n)?: " useApt 57 58 if [ "$useApt" != "y" ]; then 59 echo 60 echo "Install go manually and execute this script" 61 exit 0; 62 fi 63 64 sudo apt update 65 sudo apt install build-essential -y 66 67 wget https://dl.google.com/go/go$GO_VERSION.linux-amd64.tar.gz 68 tar -xvf go$GO_VERSION.linux-amd64.tar.gz 69 sudo mv go /usr/local 70 71 echo "" >> ~/.profile 72 echo 'export GOPATH=$HOME/go' >> ~/.profile 73 echo 'export GOROOT=/usr/local/go' >> ~/.profile 74 echo 'export GOBIN=$GOPATH/bin' >> ~/.profile 75 echo 'export PATH=$PATH:/usr/local/go/bin:$GOBIN' >> ~/.profile 76 77 . ~/.profile 78 79 go version 80 fi 81 82 if [ "$(ls -A $GENTXS_DIR)" ]; then 83 echo "Install $DAEMON" 84 git clone $GH_URL $DAEMON 85 cd $DAEMON 86 git fetch && git checkout $BINARY_VERSION 87 make install 88 $DAEMON version 89 90 for GENTX_FILE in $GENTXS_DIR/*.json; do 91 if [ -f "$GENTX_FILE" ]; then 92 set -e 93 94 echo "GentxFile::::" 95 echo $GENTX_FILE 96 97 echo "...........Init a testnet.............." 98 $DAEMON init --chain-id $CHAIN_ID validator --home $DAEMON_HOME 99 100 $DAEMON keys add $RANDOM_KEY --keyring-backend test --home $DAEMON_HOME 101 102 echo "..........Fetching genesis......." 103 curl -s $PRELAUNCH_GENESIS_URL > $DAEMON_HOME/config/genesis.json 104 105 # this genesis time is different from original genesis time, just for validating gentx. 106 sed -i '/genesis_time/c\ \"genesis_time\" : \"2021-01-01T00:00:00Z\",' $DAEMON_HOME/config/genesis.json 107 108 GENACC=$(cat $GENTX_FILE | sed -n 's|.*"delegator_address":"\([^"]*\)".*|\1|p') 109 denomquery=$(jq -r '.body.messages[0].value.denom' $GENTX_FILE) 110 amountquery=$(jq -r '.body.messages[0].value.amount' $GENTX_FILE) 111 112 # only allow $DENOM tokens to be bonded 113 if [ $denomquery != $DENOM ]; then 114 echo "invalid denomination" 115 exit 1 116 fi 117 118 $DAEMON add-genesis-account $RANDOM_KEY 1000000000000000$DENOM --home $DAEMON_HOME \ 119 --keyring-backend test 120 121 $DAEMON gentx $RANDOM_KEY 900000000000000$DENOM --home $DAEMON_HOME \ 122 --keyring-backend test --chain-id $CHAIN_ID 123 124 cp $GENTX_FILE $DAEMON_HOME/config/gentx/ 125 126 echo "..........Collecting gentxs......." 127 $DAEMON collect-gentxs --home $DAEMON_HOME 128 $DAEMON validate-genesis --home $DAEMON_HOME 129 130 echo "..........Starting node......." 131 $DAEMON start --home $DAEMON_HOME & 132 133 sleep 10s 134 135 echo "...checking network status.." 136 echo "if this fails, most probably the gentx with address $GENACC is invalid" 137 $DAEMON status --node http://localhost:26657 138 139 echo "...Cleaning the stuff..." 140 killall $DAEMON >/dev/null 2>&1 141 sleep 2s 142 rm -rf $DAEMON_HOME 143 fi 144 done 145 else 146 echo "$GENTXS_DIR is empty, nothing to validate" 147 fi