-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAleoCustomScript.sh
182 lines (162 loc) · 6.59 KB
/
AleoCustomScript.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
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
#!/bin/bash
# Config
wallet_address="$aleo_wallet_address"
explorer_url_template="https://nodes.guru/aleo/aleochecker?q="
# Default variables
language="EN"
raw_output="true"
# Options
. <(wget -qO- https://raw.githubusercontent.com/SecorD0/utils/main/colors.sh) --
option_value(){ echo $1 | sed -e 's%^--[^=]*=%%g; s%^-[^=]*=%%g'; }
while test $# -gt 0; do
case "$1" in
-h|--help)
. <(wget -qO- https://raw.githubusercontent.com/SecorD0/utils/main/logo.sh)
echo
echo -e "${C_LGn}Functionality${RES}: the script shows information about an Aleo node"
echo
echo -e "Usage: script ${C_LGn}[OPTIONS]${RES}"
echo
echo -e "${C_LGn}Options${RES}:"
echo -e " -h, --help show help page"
echo -e " -l, --language LANGUAGE use the LANGUAGE for texts"
echo -e " LANGUAGE is '${C_LGn}EN${RES}' (default), '${C_LGn}RU${RES}'"
echo -e " -ro, --raw-output the raw JSON output"
echo
echo -e "You can use either \"=\" or \" \" as an option and value ${C_LGn}delimiter${RES}"
echo
echo -e "${C_LGn}Useful URLs${RES}:"
echo -e "https://github.com/SecorD0/Aleo/blob/main/node_info.sh — script URL"
echo -e " (you can send Pull request with new texts to add a language)"
echo -e "https://t.me/letskynode — node Community"
echo
return 0 2>/dev/null; exit 0
;;
-l*|--language*)
if ! grep -q "=" <<< $1; then shift; fi
language=`option_value $1`
shift
;;
-ro|--raw-output)
raw_output="true"
shift
;;
*|--)
break
;;
esac
done
# Functions
printf_n(){ printf "$1\n" "${@:2}"; }
main() {
# Texts
if [ "$language" = "RU" ]; then
local t_wa="\nАдрес кошелька: ${C_LGn}%s${RES}"
local t_mb="Блоков намайнено: ${C_LGn}%d${RES}"
local t_lbp="Место в таблице лидеров: ${C_LGn}%d${RES}"
local t_lbs="Очков набрано: ${C_LGn}%d${RES}"
local t_nv="\nВерсия ноды: ${C_LGn}%s${RES}"
local t_lb="Последний блок: ${C_LGn}%d${RES}"
local t_sy1="Нода синхронизирована: ${C_LR}нет${RES}"
local t_sy2="Осталось нагнать: ${C_LR}%d-%d=%d (около %.2f мин.)${RES}"
local t_sy3="Нода синхронизирована: ${C_LGn}да${RES}"
local t_sy_err="${C_LR}\nНода не запущена или запускается!${RES}"
# Send Pull request with new texts to add a language - https://github.com/SecorD0/Aleo/blob/main/node_info.sh
#elif [ "$language" = ".." ]; then
else
local t_wa="\nWallet address: ${C_LGn}%s${RES}"
local t_mb="Blocks mined: ${C_LGn}%d${RES}"
local t_lbp="Leaderboard position: ${C_LGn}%d${RES}"
local t_lbs="Scored points: ${C_LGn}%d${RES}"
local t_nv="\nNode version: ${C_LGn}%s${RES}"
local t_lb="Latest block height: ${C_LGn}%d${RES}"
local t_sy1="Node is synchronized: ${C_LR}no${RES}"
local t_sy2="It remains to catch up: ${C_LR}%d-%d=%d (about %.2f min.)${RES}"
local t_sy3="Node is synchronized: ${C_LGn}yes${RES}"
local t_sy_err="${C_LR}\nThe node isn't running or is starting!${RES}"
fi
# Actions
sudo apt install wget jq bc -y &>/dev/null
if [ -n "$ALEO_ADDRESS" ]; then local wallet_address="$ALEO_ADDRESS"; fi
if [ -f /etc/systemd/system/aleod.service ]; then
local service_file_path="/etc/systemd/system/aleod.service"
local service_file="aleod.service"
printf_n "-f service file"
elif [ -f /etc/systemd/system/aleod-miner.service ]; then
local service_file_path="/etc/systemd/system/aleod-miner.service"
local service_file="aleod.service"
else
printf_n "${C_R}Change the name of the service file to ${C_LGn}aleod.service${RES}"
return 1 2>/dev/null; exit 1
fi
local port=`cat "$service_file_path" 2>/dev/null | grep -oPm1 "(?<=rpc )([^%]+)(?=$)" | grep -oPm1 "(?<=:)([^%]+)(?=$)"`
printf_n "$service_file_path"
if [ ! -n "$port" ]; then
local port=`cat "$service_file_path" 2>/dev/null | grep -oPm1 "(?<=rpc )([^%]+)(?= --)" | grep -oPm1 "(?<=:)([^%]+)(?=$)"`
printf_n "port success"
if [ ! -n "$port" ]; then
local port="3032"
fi
fi
local local_rpc="http://localhost:${port}/"
printf_n "Local Host + Port: $local_rpc"
local node_info=`wget -qO- -t 1 -T 5 --post-data '{"jsonrpc": "2.0", "id":"documentation", "method": "getnodestate", "params": [] }' "$local_rpc" 2>/dev/null | jq`
printf_n "Node info: $node_info"
local leaderboard_info=`wget -qO- "https://www.aleo.network/api/miner-info?address=$wallet_address" | jq`
printf_n "Leaderboard info: $leaderboard_info"
local mined_blocks=`jq -r ".blocksMined | length" <<< "$leaderboard_info"`
printf_n "Mined Blocks: $mined_blocks"
local position=`jq -r ".position" <<< "$leaderboard_info"`
printf_n "Position: $position"
local points=`jq -r ".score" <<< "$leaderboard_info"`
printf_n "points: $points"
printf_n "Wallet Address : $wallet_address "
local node_version="`snarkos --version` v`jq -r '.result.version' <<< \"$node_info\"`"
printf_n "Node Version: $node_version"
local latest_block_height=`jq -r ".result.latest_block_height" <<< $node_info`
printf_n "Latest Block Height: $latest_block_height"
local status=`jq -r ".result.status" <<< $node_info`
printf_n "Status: $status"
if grep -q "$status" <<< "Mining Ready"; then
local catching_up="false"
else
local catching_up="true"
fi
# Output
if [ "$raw_output" = "true" ]; then
printf_n '{"wallet_address": "%s", "mined_blocks": %d, "position": %d, "points": %d, "node_version": "%s", "latest_block_height": %d, "catching_up": %b}' \
"$wallet_address" \
"$mined_blocks" \
"$position" \
"$points" \
"$node_version" \
"$latest_block_height" \
"$catching_up" 2>/dev/null
else
if [ -n "$wallet_address" ]; then
printf_n "$t_wa" "$wallet_address"
printf_n "$t_mb" "$mined_blocks"
printf_n "$t_lbp" "$position"
printf_n "$t_lbs" "$points"
printf_n "testNodeInfo" "$node_info"
printf_n "testNodeVersion" "$node_version"
fi
if [ -n "$node_info" ]; then
printf_n "$t_nv" "$node_version"
printf_n "$t_lb" "$latest_block_height"
if [ "$catching_up" = "true" ]; then
local current_block=`wget -qO- -t 1 -T 5 --post-data '{"jsonrpc": "2.0", "id":"documentation", "method": "latestblockheight", "params": [] }' http://95.78.238.174:3032/ 2>/dev/null | jq ".result"`
local diff=`bc -l <<< "$current_block-$latest_block_height"`
local takes_time=`bc -l <<< "$diff/20/60"`
printf_n "$t_sy1"
printf_n "$t_sy2" "$current_block" "$latest_block_height" "$diff" "$takes_time"
else
printf_n "$t_sy3"
fi
else
printf_n "$t_sy_err"
fi
printf_n
fi
}
main