-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcommon_start.sh
72 lines (58 loc) · 1.24 KB
/
common_start.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
#!/bin/bash
declare -i NODE_PID
declare -i TAIL_PID
read -r -d INITIAL_TX_DATA << --EOF
{
"jsonrpc":"2.0",
"method":"eth_sendTransaction",
"params": [{
"value": "0x0",
"to":"0x0000000000000000000000000000000000000000",
"from":"${UNLOCK_ACCOUNT}",
"data":"0x",
"gasPrice":"0x1"
}],
"id": 1
}
--EOF
node_cleanup() {
kill $TAIL_PID $NODE_PID > /dev/null 2>&1
}
node_wait() {
wait $NODE_PID
}
trap node_cleanup INT TERM
eth_call() {
local response
response=$(curl --silent --show-error localhost:$RPCPORT -H "Content-Type: application/json" -X POST --data "${response}" 2>&1)
if [[ \
"${response}" == *'"error":'* || \
"${response}" == *'Connection refused'* || \
"${response}" == *'bad method'* \
]] ; then
echo "not ready"
else
echo "ready"
fi
}
eth_running() {
kill -0 $NODE_PID > /dev/null 2>&1
}
node_detect_ready() {
while eth_running && [[ $(eth_call $INITIAL_TX_DATA) == "not ready" ]] ; do sleep 1; done
}
start() {
node_start
node_detect_ready &
wait $!
if ! eth_running ; then
>&2 echo "Failed to start Ethereum Node, exiting"
RESULT=1
else
echo -e "\e[32mEthereum Node up and running!\e[0m"
node_wait
RESULT=0
fi
node_cleanup
exit $RESULT
}