-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitia.sh
273 lines (224 loc) · 10 KB
/
initia.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
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/bin/bash
# 检查是否以root用户运行脚本
if [ "$(id -u)" != "0" ]; then
echo "此脚本需要以root用户权限运行。"
echo "请尝试使用 'sudo -i' 命令切换到root用户,然后再次运行此脚本。"
exit 1
fi
# 检查并安装 Node.js 和 npm
function install_nodejs_and_npm() {
if command -v node > /dev/null 2>&1; then
echo "Node.js 已安装"
else
echo "Node.js 未安装,正在安装..."
curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
apt-get install -y nodejs
fi
if command -v npm > /dev/null 2>&1; then
echo "npm 已安装"
else
echo "npm 未安装,正在安装..."
apt-get install -y npm
fi
}
# 检查并安装 PM2
function install_pm2() {
if command -v pm2 > /dev/null 2>&1; then
echo "PM2 已安装"
else
echo "PM2 未安装,正在安装..."
npm install pm2@latest -g
fi
}
# 检查Go环境
function check_go_installation() {
if command -v go > /dev/null 2>&1; then
echo "Go 环境已安装"
return 0
else
echo "Go 环境未安装,正在安装..."
return 1
fi
}
# 节点安装功能
function install_node() {
install_nodejs_and_npm
install_pm2
# 更新和安装必要的软件
apt update && apt upgrade -y
apt install -y curl iptables build-essential git wget jq make gcc nano tmux htop nvme-cli pkg-config libssl-dev libleveldb-dev tar clang bsdmainutils ncdu unzip libleveldb-dev lz4 snapd
# 安装 Go
if ! check_go_installation; then
rm -rf /usr/local/go
curl -L https://go.dev/dl/go1.22.0.linux-amd64.tar.gz | tar -xzf - -C /usr/local
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> $HOME/.bash_profile
source $HOME/.bash_profile
go version
fi
# 安装所有二进制文件
git clone https://github.com/initia-labs/initia
cd initia
make install
initiad version
# 配置initiad
initiad init "Moniker" --chain-id initiation-1
initiad config set client chain-id initiation-1
# 获取初始文件和地址簿
wget -O $HOME/.initia/config/genesis.json https://initia.s3.ap-southeast-1.amazonaws.com/initiation-1/genesis.json
wget -O $HOME/.initia/config/addrbook.json https://rpc-initia-testnet.trusted-point.com/addrbook.json
sed -i -e "s|^minimum-gas-prices *=.*|minimum-gas-prices = \"0.15uinit,0.01uusdc\"|" $HOME/.initia/config/app.toml
# 配置节点
PEERS="40d3f977d97d3c02bd5835070cc139f289e774da@168.119.10.134:26313,841c6a4b2a3d5d59bb116cc549565c8a16b7fae1@23.88.49.233:26656,e6a35b95ec73e511ef352085cb300e257536e075@37.252.186.213:26656,2a574706e4a1eba0e5e46733c232849778faf93b@84.247.137.184:53456,ff9dbc6bb53227ef94dc75ab1ddcaeb2404e1b0b@178.170.47.171:26656,edcc2c7098c42ee348e50ac2242ff897f51405e9@65.109.34.205:36656,07632ab562028c3394ee8e78823069bfc8de7b4c@37.27.52.25:19656,028999a1696b45863ff84df12ebf2aebc5d40c2d@37.27.48.77:26656,140c332230ac19f118e5882deaf00906a1dba467@185.219.142.119:53456,1f6633bc18eb06b6c0cab97d72c585a6d7a207bc@65.109.59.22:25756,065f64fab28cb0d06a7841887d5b469ec58a0116@84.247.137.200:53456,767fdcfdb0998209834b929c59a2b57d474cc496@207.148.114.112:26656,093e1b89a498b6a8760ad2188fbda30a05e4f300@35.240.207.217:26656,12526b1e95e7ef07a3eb874465662885a586e095@95.216.78.111:26656"
sed -i 's|^persistent_peers *=.*|persistent_peers = "'$PEERS'"|' $HOME/.initia/config/config.toml
# 配置端口
node_address="tcp://localhost:53457"
sed -i -e "s%^proxy_app = \"tcp://127.0.0.1:26658\"%proxy_app = \"tcp://127.0.0.1:53458\"%; s%^laddr = \"tcp://127.0.0.1:26657\"%laddr = \"tcp://127.0.0.1:53457\"%; s%^pprof_laddr = \"localhost:6060\"%pprof_laddr = \"localhost:53460\"%; s%^laddr = \"tcp://0.0.0.0:26656\"%laddr = \"tcp://0.0.0.0:53456\"%; s%^prometheus_listen_addr = \":26660\"%prometheus_listen_addr = \":53466\"%" $HOME/.initia/config/config.toml
sed -i -e "s%^address = \"tcp://localhost:1317\"%address = \"tcp://0.0.0.0:53417\"%; s%^address = \":8080\"%address = \":53480\"%; s%^address = \"localhost:9090\"%address = \"0.0.0.0:53490\"%; s%^address = \"localhost:9091\"%address = \"0.0.0.0:53491\"%; s%:8545%:53445%; s%:8546%:53446%; s%:6065%:53465%" $HOME/.initia/config/app.toml
echo "export initiad_RPC_PORT=$node_address" >> $HOME/.bash_profile
source $HOME/.bash_profile
# 配置预言机
git clone https://github.com/skip-mev/slinky.git
cd slinky
# checkout proper version
git checkout v0.4.3
make build
# 配置预言机启用
sed -i -e 's/^enabled = "false"/enabled = "true"/' \
-e 's/^oracle_address = ""/oracle_address = "127.0.0.1:8080"/' \
-e 's/^client_timeout = "2s"/client_timeout = "500ms"/' \
-e 's/^metrics_enabled = "false"/metrics_enabled = "false"/' $HOME/.initia/config/app.toml
pm2 start initiad -- start && pm2 save && pm2 startup
pm2 stop initiad
# 配置快照
sudo apt install lz4 -y
curl -o - -L https://snapshots.polkachu.com/testnet-snapshots/initia/initia_218063.tar.lz4 | lz4 -c -d - | tar -x -C $HOME/.initia
mv $HOME/.initia/priv_validator_state.json.backup $HOME/.initia/data/priv_validator_state.json
pm2 start ./build/slinky -- --oracle-config-path ./config/core/oracle.json --market-map-endpoint 0.0.0.0:53490
pm2 restart initiad
echo '====================== 安装完成,请退出脚本后执行 source $HOME/.bash_profile 以加载环境变量==========================='
}
# 查看initia 服务状态
function check_service_status() {
pm2 list
}
# initia 节点日志查询
function view_logs() {
pm2 logs initiad
}
# 卸载节点功能
function uninstall_node() {
echo "你确定要卸载initia 节点程序吗?这将会删除所有相关的数据。[Y/N]"
read -r -p "请确认: " response
case "$response" in
[yY][eE][sS]|[yY])
echo "开始卸载节点程序..."
pm2 stop initiad && pm2 delete initiad
rm -rf $HOME/.initiad && rm -rf $HOME/initia $(which initiad) && rm -rf $HOME/.initia
echo "节点程序卸载完成。"
;;
*)
echo "取消卸载操作。"
;;
esac
}
# 创建钱包
function add_wallet() {
initiad keys add wallet
}
# 导入钱包
function import_wallet() {
initiad keys add wallet --recover
}
# 查询余额
function check_balances() {
read -p "请输入钱包地址: " wallet_address
initiad query bank balances "$wallet_address" --node $initiad_RPC_PORT
}
# 查看节点同步状态
function check_sync_status() {
initiad status --node $initiad_RPC_PORT | jq .sync_info
}
# 创建验证者
function add_validator() {
read -p "请输入您的钱包名称: " wallet_name
read -p "请输入您想设置的验证者的名字: " validator_name
read -p "请输入您的验证者详情(例如'吊毛资本'): " details
initiad tx mstaking create-validator --amount=1000000uinit --pubkey=$(initiad tendermint show-validator) --moniker=$validator_name --chain-id=initiation-1 --commission-rate=0.05 --commission-max-rate=0.10 --commission-max-change-rate=0.01 --from=$wallet_name --identity="" --website="" --details="" --gas=2000000 --fees=300000uinit --node $initiad_RPC_PORT
}
# 给自己地址验证者质押
function delegate_self_validator() {
read -p "请输入质押代币数量,比如你有1个init,请输入1000000,以此类推: " math
read -p "请输入钱包名称: " wallet_name
initiad tx mstaking delegate $(initiad keys show wallet --bech val -a) ${math}uinit --from $wallet_name --chain-id initiation-1 --gas=2000000 --fees=300000uinit --node $initiad_RPC_PORT -y
}
function unjail() {
read -p "请输入钱包名称: " wallet_name
initiad tx slashing unjail --from $wallet_name --fees=10000amf --chain-id=initiation-1 --node $initiad_RPC_PORT
}
# 导出验证者key
function export_priv_validator_key() {
echo "====================请将下方所有内容备份到自己的记事本或者excel表格中记录==========================================="
cat ~/.initia/config/priv_validator_key.json
}
function update_node() {
cd $HOME
cd initia
git fetch --tags
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
if [ -z "$latest_tag" ]; then
echo "未找到最新的标签。"
exit 1
fi
git checkout $latest_tag
make install
pm2 restart initiad
echo "升级到最新版本 $latest_tag 完成。"
}
# 主菜单
function main_menu() {
while true; do
clear
echo "================================================================"
echo "节点社区 Telegram 群组:https://t.me/niuwuriji"
echo "节点社区 Telegram 频道:https://t.me/niuwuriji"
echo "节点社区 Discord 社群:https://discord.gg/GbMV5EcNWF"
echo "退出脚本,请按键盘ctrl c退出即可"
echo "请选择要执行的操作:"
echo "1. 安装节点"
echo "2. 创建钱包"
echo "3. 导入钱包"
echo "4. 查看钱包地址余额"
echo "5. 查看节点同步状态"
echo "6. 查看当前服务状态"
echo "7. 运行日志查询"
echo "8. 卸载节点"
echo "9. 设置快捷键"
echo "10. 创建验证者"
echo "11. 给自己质押"
echo "12. 释放出监狱"
echo "13. 备份验证者私钥"
echo "14. 升级节点"
read -p "请输入选项(1-12): " OPTION
case $OPTION in
1) install_node ;;
2) add_wallet ;;
3) import_wallet ;;
4) check_balances ;;
5) check_sync_status ;;
6) check_service_status ;;
7) view_logs ;;
8) uninstall_node ;;
9) check_and_set_alias ;;
10) add_validator ;;
11) delegate_self_validator ;;
12) unjail ;;
13) export_priv_validator_key ;;
14) update_node ;;
*) echo "无效选项。" ;;
esac
echo "按任意键返回主菜单..."
read -n 1
done
}
# 显示主菜单
main_menu