forked from sge-network/networks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate-gentx.sh
124 lines (94 loc) · 3.58 KB
/
validate-gentx.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
#!/bin/bash
set -x
SGED_HOME="/tmp/sged$(date +%s)"
RANDOM_KEY="randomsgedvalidatorkey"
CHAIN_ID=sge-network-2
DENOM=usge
VALIDATOR_COINS=10000000000
GENTX_FILE=$(find ./$CHAIN_ID/gentxs -iname "*.json")
LEN_GENTX=$(echo ${#GENTX_FILE})
SGED_TAG="v0.0.5"
# Gentx Start date
start="2021-10-11 01:00:00Z"
# Compute the seconds since epoch for start date
stTime=$(date --date="$start" +%s)
# Gentx End date
end="2023-08-01 17:00:00Z"
# Compute the seconds since epoch for end date
endTime=$(date --date="$end" +%s)
# Current date
current=$(date +%Y-%m-%d\ %H:%M:%S)
# Compute the seconds since epoch for current date
curTime=$(date --date="$current" +%s)
if [[ $curTime < $stTime ]]; then
echo "start=$stTime:curent=$curTime:endTime=$endTime"
echo "Gentx submission is not open yet. Please close the PR and raise a new PR after 30-August-2021 10:00:00 UTC"
exit 1
else
if [[ $curTime > $endTime ]]; then
echo "start=$stTime:curent=$curTime:endTime=$endTime"
echo "Gentx submission is closed"
exit 1
else
echo "Gentx is now open"
echo "start=$stTime:curent=$curTime:endTime=$endTime"
fi
fi
if [ $LEN_GENTX -eq 0 ]; then
echo "No new gentx file found."
exit 1
else
set -e
echo "GentxFiles::::"
echo $GENTX_FILE
echo "...........Init Sged.............."
git clone https://github.com/sge-network/sge
cd sge
git fetch --tags
git checkout $SGED_TAG
go mod tidy
make install
sged keys add $RANDOM_KEY --keyring-backend test --home $SGED_HOME
sged init --chain-id $CHAIN_ID validator --home $SGED_HOME
echo "..........Fetching genesis......."
rm -rf $SGED_HOME/config/genesis.json
cp ../$CHAIN_ID/pre-genesis.json $SGED_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-09-02T16:00:00Z\",' $SGED_HOME/config/genesis.json
find ../$CHAIN_ID/gentxs -iname "*.json" -print0 |
while IFS= read -r -d '' line; do
GENACC=$(cat $line | sed -n 's|.*"delegator_address":"\([^"]*\)".*|\1|p')
denomquery=$(jq -r '.body.messages[0].value.denom' $line)
amountquery=$(jq -r '.body.messages[0].value.amount' $line)
echo $GENACC
echo $amountquery
echo $denomquery
# only allow $DENOM tokens to be bonded
if [ $denomquery != $DENOM ]; then
echo "invalid denomination"
exit 1
fi
# check the amount that can be bonded
if [ $amountquery != $VALIDATOR_COINS ]; then
echo "invalid amount of tokens"
exit 1
fi
sged add-genesis-account $(jq -r '.body.messages[0].delegator_address' $line) $VALIDATOR_COINS$DENOM --home $SGED_HOME
done
mkdir -p $SGED_HOME/config/gentx/
# add submitted gentxs
cp -r ../$CHAIN_ID/gentxs/* $SGED_HOME/config/gentx/
echo "..........Collecting gentxs......."
sged collect-gentxs --home $SGED_HOME &> log.txt
sed -i '/persistent_peers =/c\persistent_peers = ""' $SGED_HOME/config/config.toml
sed -i '/minimum-gas-prices =/c\minimum-gas-prices = "0.25usge"' $SGED_HOME/config/app.toml
sged validate-genesis --home $SGED_HOME
echo "..........Starting node......."
sged start --home $SGED_HOME &
sleep 10s
echo "...Сhecking network status.."
sged status --node http://localhost:26657
echo "...Cleaning the stuff..."
killall sged >/dev/null 2>&1
rm -rf $SGED_HOME >/dev/null 2>&1
fi