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