-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·234 lines (206 loc) · 7.38 KB
/
run.sh
File metadata and controls
executable file
·234 lines (206 loc) · 7.38 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#! /bin/bash
BLACK='\033[0;30m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BROWN='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
LGRAY='\033[0;37m'
DGRAY='\033[1;30m'
WHITE='\033[1;37m'
NC='\033[0m'
TESTNET_DIR='/tmp/testnet'
EOS=~/bucky_eos/eos/build
BIOS_HTTP=8888
BIOS_P2P=9876
CLEOS=${EOS}/programs/cleos/cleos
NODEOS=${EOS}/programs/nodeos/nodeos
BIOS_PID=0
NODE_PIDS=()
PRODUCERS=()
NODES=0
if [ "$#" -gt "0" ] && [ "$1" -ge "1" ]; then
NODES=$1
fi
IFS=$' =' read -a var <<< $(sort -t= -nr -k3 net.map | head -1)
NODES=$(( var[0] > var[2] ? var[0] : var[2] ))
fix_config() {
sed -e 's/\${HTTP}/'"$2"'/g; s/\${P2P}/'"$3"'/g; s/\${STALE}/'"$4"'/g; s/\${PUB}/'"$5"'/g; s/\${PRIV}/'"$6"'/g; s/\${PROD_NAME}/'"$7"'/g' < config.ini > $1
}
run_bios() {
BIOS_DIR=${TESTNET_DIR}/bios
mkdir ${BIOS_DIR}
fix_config ${BIOS_DIR}/config.ini ${BIOS_HTTP} ${BIOS_P2P} true EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 eosio
printf "${CYAN}Starting Bios Node at [${WHITE}${BIOS_HTTP}, ${BIOS_P2P}${CYAN}]\n${NC}"
${NODEOS} -d ${BIOS_DIR} --config-dir ${BIOS_DIR} &> outputs/bios.out &
BIOS_PID=$!
sleep 0.7
WALLET_PW=`${CLEOS} -p ${BIOS_HTTP} wallet create | grep -e "\".*\"" | sed -e "s/\"//g"`
printf "${BLUE}Created wallet [${LGRAY}${WALLET_PW}${BLUE}]${NC}\n"
printf "${BLUE}Unlocking wallet ${NC}\n"
sleep 0.7
echo "spawn ${CLEOS} -p ${BIOS_HTTP} wallet unlock; expect \"password:\" {send \"${WALLET_PW}\r\"}" | expect &> /dev/null
printf "${BLUE}Setting eosio.bios ${NC}\n"
${CLEOS} -p ${BIOS_HTTP} set contract eosio ${EOS}/contracts/eosio.bios &> /dev/null
echo ""
}
run_node() {
NODE_DIR=${TESTNET_DIR}/node.$1
mkdir ${NODE_DIR}
KEY=`${CLEOS} -p ${BIOS_HTTP} create key`
PRIV=`echo $KEY | sed -e "s/Private key: //g; s/ Public.*//g"`
PUB=`echo $KEY | sed -e "s/.*Public key: //g"`
fix_config ${NODE_DIR}/config.ini 880$1 980$1 false ${PUB} ${PRIV} node.$1
cp ${BIOS_DIR}/genesis.json ${NODE_DIR}/genesis.json
printf "${BLUE}Creating account ${BROWN}node.$1${BLUE} with keys \n\tpublic:${LGRAY}${PUB}\n\t${BLUE}private:${LGRAY} ${PRIV}\n${NC}"
${CLEOS} -p ${BIOS_HTTP} create account eosio node.$1 ${PUB} ${PUB} &> /dev/null
printf "${CYAN}Starting node.$1 at [${WHITE}880$1, 980$1${CYAN}]\n${NC}"
${NODEOS} -d ${NODE_DIR} --config-dir ${NODE_DIR} &> outputs/node.$1.out &
NODE_PIDS+=($!)
PRODS+=("node.$1,${PUB}")
echo ""
}
set_producers() {
python set_prods.py ${PRODS[@]} > ${TESTNET_DIR}/prods.json
printf "${CYAN}Setting producers\n${NC}"
${CLEOS} -p ${BIOS_HTTP} push action eosio setprods ${TESTNET_DIR}/prods.json -p eosio@active &> /dev/null
echo ""
}
get_response() {
printf "${WHITE}Press [x|X] to quit, [k|K] to kill a node, [c|C] to connect a node, or [d|D] to disconnect a node${NC}"
read -r -p "" response
case "${response}" in
[kK])
printf "${BROWN}Kill which node?${NC}"
read -r -p "" _node
case "${_node}" in
[0])
printf "${BROWN}Killing bios node\n${NC}"
kill ${BIOS_PID}
;;
*)
printf "${BROWN}Killing node\n${NC}"
kill ${NODE_PIDS[${_node}]}
;;
esac
get_response
;;
[xX])
for pid in "${NODE_PIDS[@]}"; do
printf "${BROWN}Killing node\n${NC}"
kill ${pid} &> /dev/null
done
printf "${BROWN}Killing bios node\n${NC}"
kill ${BIOS_PID} &> /dev/null
rm -r ${TESTNET_DIR}
;;
[cC])
printf "${BROWN}Which node to connect?\n${NC}"
read -r -p "" _node
case "${_node}" in
[0])
printf "${BROWN}Connecting to which node?\n${NC}"
read -r -p "" __node
case "${__node}" in
[0])
printf "${BROWN}Connecting bios node to itself? ${__node}\n${NC}"
${CLEOS} -p8888 net connect localhost:9876
get_response
;;
*)
printf "${BROWN}Connecting node ${_node} to node ${__node}\n${NC}"
${CLEOS} -p880${_node} net connect localhost:980${__node}
get_response
;;
esac
;;
*)
printf "${BROWN}Connecting to which node?\n${NC}"
read -r -p "" __node
case "${__node}" in
[0])
printf "${BROWN}Connecting node ${_node} to bios node\n${NC}"
${CLEOS} -p880${_node} net connect localhost:9876
get_response
;;
["${_node}"])
printf "${BROWN}Connecting node ${_node} to itself? ${__node}\n${NC}"
${CLEOS} -p880${_node} net connect localhost:980${_node}
get_response
;;
*)
printf "${BROWN}Connecting node ${_node} to node ${__node}\n${NC}"
${CLEOS} -p880${_node} net connect localhost:980${__node}
get_response
;;
esac
;;
esac
;;
[dD])
printf "${BROWN}Which node to disconnect?\n${NC}"
read -r -p "" _node
case "${_node}" in
[0])
printf "${BROWN}Disconnecting to which node?\n${NC}"
read -r -p "" __node
case "${__node}" in
[0])
printf "${BROWN}Disconnecting bios node to itself? ${__node}\n${NC}"
${CLEOS} -p8888 net disconnect localhost:9876
get_response
;;
*)
printf "${BROWN}Disconnecting node ${_node} to node ${__node}\n${NC}"
${CLEOS} -p880${_node} net disconnect localhost:980${__node}
get_response
;;
esac
;;
*)
printf "${BROWN}Disconnecting to which node?\n${NC}"
read -r -p "" __node
case "${__node}" in
[0])
printf "${BROWN}Disconnecting node ${_node} to bios node\n${NC}"
${CLEOS} -p880${_node} net disconnect localhost:9876
get_response
;;
["${_node}"])
printf "${BROWN}Disconnecting node ${_node} to itself? ${__node}\n${NC}"
${CLEOS} -p880${_node} net disconnect localhost:980${_node}
get_response
;;
*)
printf "${BROWN}Disconnecting node ${_node} to node ${__node}\n${NC}"
${CLEOS} -p880${_node} net disconnect localhost:980${__node}
get_response
;;
esac
;;
esac
;;
*)
get_response
;;
esac
}
mkdir -p outputs
printf "${GREEN}\t--- Starting EOSIO Local Testnet ---\n\n${NC}"
printf "${RED}"
mkdir -p ${TESTNET_DIR}
if [ $? != 0 ]; then
printf "${RED}Error, ${LGRAY}Please verify that we are not overwriting anything, rm -r /tmp/testnet if not${NC}\n"
exit -1
fi
run_bios
for i in $(seq 1 $NODES); do
run_node $i
done
if [ "${#PRODS[@]}" -gt "0" ]; then
set_producers
fi
sleep 0.7
python parse_map.py net.map ${CLEOS}
get_response