-
Notifications
You must be signed in to change notification settings - Fork 0
/
drharmony.sh
executable file
·2637 lines (2268 loc) · 78.2 KB
/
drharmony.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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Dr.Harmony version
DrHarmony_Version=$(cat ./drharmony.v)
cat << "EOF"
____ _ _
| _ \ _ __| | | | __ _ _ __ _ __ ___ ___ _ __ _ _
| | | | '__| |_| |/ _` | '__| '_ ` _ \ / _ \| '_ \| | | |
| |_| | | | _ | (_| | | | | | | | | (_) | | | | |_| |
|____/|_| |_| |_|\__,_|_| |_| |_| |_|\___/|_| |_|\__, |
|___/
EOF
echo " Version: $DrHarmony_Version"
echo " "
LOCAL_IP=$(hostname -I | awk '{print $1}')
PUBLIC_IP=$(dig @resolver3.opendns.com myip.opendns.com +short)
HEIGHT=22
WIDTH=40
CHOICE_HEIGHT=10
BACKTITLE="Harmony Node Utilities - Dr.Harmony-V$DrHarmony_Version"
MENU="Choose one of the following options:"
menu_result="notready"
function checkVersion {
RemoteVersion=$(curl --silent https://raw.githubusercontent.com/GheisMohammadi/Dr.Harmony/main/drharmony.v)
if [ "$DrHarmony_Version" != "$RemoteVersion" ]; then
echo "there is a new version:$RemoteVersion, let's update DrHarmony to newest version..."
rm ./drharmony.sh
curl --silent -O https://raw.githubusercontent.com/GheisMohammadi/Dr.Harmony/main/drharmony.sh && sudo chmod +x ./drharmony.sh
rm ./drharmony.v
curl --silent -O https://raw.githubusercontent.com/GheisMohammadi/Dr.Harmony/main/drharmony.v
sudo ./drharmony.sh
exit
fi
}
checkVersion
#========================================================================
# init binaries
#========================================================================
HMY=$(which hmy)
if [ -z "$HMY" ]; then
HMY=./hmy
if [[ ! -f $HMY ]]; then
HMY=/usr/sbin/hmy
if [[ ! -f $HMY ]]; then
HMY=~/hmy
if [[ ! -f $HMY ]]; then
# hmy is not installed
HMY=""
echo "hmy not found."
fi
fi
fi
fi
HARMONY=$(which harmony)
LOGS_DIR="${a%/*}/latest"
if [ -z "$HARMONY" ]; then
HARMONY=./harmony
LOGS_DIR="./latest"
if [[ ! -f $HARMONY ]]; then
HARMONY=/usr/sbin/harmony
LOGS_DIR="./usr/sbin"
if [[ ! -f $HARMONY ]]; then
HARMONY=~/harmony
LOGS_DIR="~"
if [[ ! -f $HARMONY ]]; then
# harmony is not installed
HARMONY=""
LOGS_DIR=""
echo "harmony not found."
fi
fi
fi
fi
#========================================================================
# User Inputs
#========================================================================
function waitForAnyKey {
echo "------------------------------------------"
read -p "Hit enter to continue ..."
}
function getUserInput {
exec 3>&1;
user_input=$(dialog --inputbox $input_msg 0 0 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
echo $user_input $exitcode;
}
#========================================================================
# Requirements
#========================================================================
function checkRequirements {
echo "Checking for dependencies..."
REQUIRED_PKG="dialog"
# check whether dialog is installed
#APT_OK=$(dpkg-query -W --showformat='${Status}\n' apt|grep "install ok installed")
#YUM_OK=$(dpkg-query -W --showformat='${Status}\n' yum|grep "install ok installed")
if [ -z "$(command -v $REQUIRED_PKG)" ]; then
if [ -n "$(command -v apt-get)" ]; then
echo "installing $REQUIRED_PKG (apt) ..."
sudo apt-get -y update
sudo apt-get install -y $REQUIRED_PKG
elif [ -n "$(command -v yum)" ]; then
echo "installing $REQUIRED_PKG (yum) ..."
sudo yum -y update
sudo yum install -y $REQUIRED_PKG
elif [ -n "$(command -v brew)" ]; then
echo "installing $REQUIRED_PKG (brew) ..."
sudo brew -y update
sudo brew install -y $REQUIRED_PKG
else
echo "install dependencies failed, it needs either apt, yum or brew"
fi
fi
if [ -z "$(command -v jq)" ]; then
if [ -n "$(command -v apt-get)" ]; then
echo "installing jq (apt) ..."
sudo apt-get -y update
sudo apt-get install -y jq
elif [ -n "$(command -v yum)" ]; then
echo "installing jq (yum) ..."
sudo yum -y update
sudo yum install -y jq
elif [ -n "$(command -v brew)" ]; then
echo "installing jq (brew) ..."
sudo brew -y update
sudo brew install -y jq
else
echo "install dependencies failed, it needs either apt, yum or brew"
fi
fi
if [ -f $HMY ]; then
echo "hmy command is ready"
else
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) #machine=Linux
curl -LO https://harmony.one/hmycli && mv hmycli hmy && chmod +x hmy
HMY=./hmy
;;
Darwin*) #machine=Mac
curl -O https://raw.githubusercontent.com/harmony-one/go-sdk/master/scripts/hmy.sh
chmod u+x hmy.sh
./hmy.sh -d
HMY=./hmy
;;
CYGWIN*) #machine=Cygwin
curl -LO https://harmony.one/hmycli && mv hmycli hmy && chmod +x hmy
HMY=./hmy
;;
MINGW*) #machine=MinGw
curl -LO https://harmony.one/hmycli && mv hmycli hmy && chmod +x hmy
HMY=./hmy
;;
*)
HMY=""
machine="UNKNOWN:${unameOut}"
echo "not supported os ($machine)!"
esac
fi
}
#========================================================================
# Dependencies
#========================================================================
function askForNetwork {
echo "setup new harmony validator "
network_options=(1 "mainnet"
2 "testnet"
3 "devnet")
new_node_network_id=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "Select network" \
--ok-label "Next" --nocancel \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${network_options[@]}" \
2>&1 >/dev/tty)
clear
new_node_network_name="unknown"
case $new_node_network_id in
1)
new_node_network_name="mainnet"
;;
2)
new_node_network_name="testnet"
;;
3)
new_node_network_name="devnet"
;;
esac
}
function installHarmonyDependenciesUsingApt {
#install harmony deps
sudo apt install -y git libgmp-dev libssl-dev make gcc g++ jq
}
function installHarmonyDependenciesUsingYum {
sudo yum install -y git glibc-static gmp-devel gmp-static openssl-libs openssl-static gcc-c++ jq
}
function installHarmonyDependenciesUsingBrew {
brew install gmp
brew install openssl
sudo ln -sf /usr/local/opt/openssl@1.1 /usr/local/opt/openssl
}
function installHarmonyDependencies {
#APT_OK=$(dpkg-query -W --showformat='${Status}\n' apt|grep "install ok installed")
#YUM_OK=$(dpkg-query -W --showformat='${Status}\n' yum|grep "install ok installed")
if [ -n "$(command -v apt)" ]; then
echo "installing dependencies (apt) ..."
installHarmonyDependenciesUsingApt
elif [ -n "$(command -v yum)" ]; then
echo "installing dependencies (yum) ..."
installHarmonyDependenciesUsingYum
elif [ -n "$(command -v brew)" ]; then
echo "installing dependencies (brew) ..."
installHarmonyDependenciesUsingBrew
else
echo "install dependencies failed, it needs either apt, yum or brew"
fi
}
function installGo {
GO_OK=$(go version|grep "go version")
if [ "$GO_OK" = "" ]; then
go_version="1.22.5"
go_file_name="go$go_version.linux-amd64.tar.gz"
go_url="https://storage.googleapis.com/golang/$go_file_name"
wget $go_url
#we have to remove current go folder, otherwise it creates a broken go
rm -rf /usr/local/go
sudo tar -C /usr/local -xzvf $go_file_name
rm $go_file_name
sudo ln -sfn /usr/local/go/bin/go /usr/bin/
sudo ln -sfn /usr/local/go/bin/gofmt /usr/bin/
echo "export PATH=\"/usr/local/go/bin:$PATH\"" >> ~/.bashrc
source ~/.bashrc
fi
CHECK_GO_INSTALL=$(go version|grep "go version")
if [ "$CHECK_GO_INSTALL" = "" ]; then
alias go=/usr/local/go/bin/go
alias gofmt=/usr/local/go/bin/gofmt
fi
go version
}
function downloadAndBuildSourceCode {
buildresult="FAIL"
GO_OK=$(go version|grep "go version")
if [ "$GO_OK" = "" ]; then
echo "can't find go language or maybe go language is not installed yet"
echo "please try 'source ~/.profile' and try again"
else
mkdir -p $(go env GOPATH)/src/github.com/harmony-one
cd $(go env GOPATH)/src/github.com/harmony-one
git clone https://github.com/harmony-one/mcl.git
git clone https://github.com/harmony-one/bls.git
git clone https://github.com/harmony-one/harmony.git
cd harmony
#if not using harmony repo
if [ $use_hmy_repo -eq 1 ]; then
git remote rm origin2
git remote add origin2 $repo
fi
git branch -vv
if [ ${#branch_name} -ge 3 ]; then
git checkout $branch_name
if [ $use_hmy_repo -eq 0 ]; then
git pull origin $branch_name
else
git pull origin2 $branch_name
fi
fi
go mod tidy
make
make linux_static
cp ./bin/harmony ~/
cd ~
chmod +x harmony
buildresult="OK"
fi
}
function buildHarmonyBinary {
exec 3>&1;
from_hmy_repo=$(dialog --yesno "build from harmony repository?" 0 0 2>&1 1>&3);
use_hmy_repo=$?;
exec 3>&-;
#if not using harmony repo, then ask the repo
if [ $use_hmy_repo -eq 1 ]; then
exec 3>&1;
repo=$(dialog --nocancel --ok-label "Next" --inputbox "please enter the repository url" 0 0 "https://github.com/GheisMohammadi/harmony.git" 2>&1 1>&3);
exitstatus=$?;
exec 3>&-;
echo "build from harmony repo:$repo";
fi
exec 3>&1;
branch_name=$(dialog --nocancel --ok-label "Next" --inputbox "build from which branch?" 0 0 "main" 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
echo "build from branch:$branch_name";
installHarmonyDependencies
installGo
downloadAndBuildSourceCode
echo "done"
}
#========================================================================
# Install New Node
#========================================================================
function createBlsKeys {
exec 3>&1;
shard_num=$(dialog --nocancel --ok-label "Next" --inputbox "shard number?" 0 0 "0" 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
echo "build validator key for shard: $shard_num";
exec 3>&1;
keys_count=$(dialog --nocancel --ok-label "Next" --inputbox "how many keys?" 0 0 "1" 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
echo "number of keys: $keys_count";
echo $shard_num > shard.txt
echo $new_node_network_name > network.txt
exec 3>&1;
key_password=$(dialog --nocancel --ok-label "Next" --inputbox "enter passphrase for keys" 0 0 "123" 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
echo $key_password > "./keypass.txt"
$HMY keys generate-bls-keys --count $keys_count --shard $shard_num --passphrase-file "./keypass.txt"
rm "./keypass.txt"
}
function setupSystemd {
if [ -z "$new_node_network_name" ]; then
askForNetwork
fi
echo "
[Unit]
Description=Harmony daemon
After=network-online.target
[Service]
Type=simple
Restart=always
RestartSec=1
User=$USER
WorkingDirectory=${HOME%/}
ExecStart=${HOME%/}/harmony --network $new_node_network_name --config './harmony.conf'
SyslogIdentifier=harmony
StartLimitInterval=0
LimitNOFILE=65536
LimitNPROC=65536
[Install]
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/harmony.service
sudo chmod 755 /etc/systemd/system/harmony.service
sudo systemctl enable harmony.service
}
function continueInstallNewNode {
# create bls keys
createBlsKeys
# move bls keys to .hmy/blskeys folder
mkdir -p ".hmy/blskeys"
# create passphrase files
for file in *.key; do
echo "$key_password" > "${file%.key}.pass"
done
mv *.key .hmy/blskeys
mv *.pass .hmy/blskeys
# download db for mainnet
if [ $new_node_network_name == "mainnet" ]; then
echo "install rclone and sync db using that, it may takes a couple of hours or a few days, so be patient plz ..."
rclone
fi
echo "dump the config file ..."
./harmony config dump ./harmony.conf --network $new_node_network_name
echo "run validator ..."
setupSystemd
sudo service harmony start
echo "new node is up and running!"
}
function installNewNodeFromBinaryFile {
echo "install new harmony node from binary file ..."
cd ~
binary_name="binary"
case $new_node_network_id in
1)
#"mainnet"
binary_name="binary"
;;
2)
#"testnet"
binary_name="binary_testnet"
;;
3)
#"devnet"
binary_name="binary-arm64"
;;
esac
curl -LO "https://harmony.one/$binary_name"
mv $binary_name harmony
chmod +x harmony
continueInstallNewNode
}
function installNewNodeFromSourceCode {
# install golang
# install deps
# install node
echo "install new harmony node from source code ..."
buildHarmonyBinary
if [ $buildresult == "OK" ]; then
continueInstallNewNode
else
echo "new node installation failed. as you fix the issue, try again"
fi
}
function installNewNode {
echo "setup new harmony validator "
install_options=(1 "build binary from source code"
2 "download binary"
3 "install rclone"
4 "create new bls key")
clear
new_node_menu_res="done"
while [ $new_node_menu_res == "done" ]
do
selected_install_option=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "Run New Validator" \
--ok-label "Install" --cancel-label "Back" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${install_options[@]}" \
2>&1 >/dev/tty)
clear
case $selected_install_option in
1)
askForNetwork
installNewNodeFromSourceCode
;;
2)
askForNetwork
installNewNodeFromBinaryFile
;;
3)
install_rclone
;;
4)
createBlsKeys
;;
*)
new_node_menu_res="back"
;;
esac
if [ $new_node_menu_res == "done" ]; then
waitForAnyKey
fi
done
}
#========================================================================
# Snap DB
#========================================================================
function createSnapDB {
./harmony dumpdb /data/harmony_db_0 /root/data/snapdb/harmony_db_0
}
#========================================================================
# Blockchain & RPC
#========================================================================
function getTransactionsHistory {
exec 3>&1;
accAddress=$(dialog --nocancel --ok-label "Next" --inputbox "account address" 0 0 "one..." 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
curl --location --request POST '0.0.0.0:9500' \
--header 'Content-Type: application/json' \
--data-raw "{
\"jsonrpc\": "2.0",
\"id\": 1,
\"method\": \"hmyv2_getTransactionsHistory\",
\"params\": [{
\"address\": \"$accAddress\",
\"pageIndex\": 0,
\"pageSize\": 1000,
\"fullTx\": true,
\"txType\": \"ALL\",
\"order\": \"DESC\"
}]
}"
waitForAnyKey
}
# sample result
# {"jsonrpc":"2.0","id":1,"result":"0x0"}
function hmyGetBalance {
exec 3>&1;
accAddress=$(dialog --nocancel --ok-label "Next" --inputbox "account address" 0 0 "one..." 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
ADDR="0x320b3FedBaF5A15Ad50F5c2ff4A659cf4dB64B02"
URL="0.0.0.0:9500"
curl $URL -H "Content-Type: application/json" -X POST --data "{\"jsonrpc\":\"2.0\",\"method\":\"hmy_getBalance\",\"params\":[\"${accAddress}\", \"latest\"],\"id\":1}"
waitForAnyKey
}
function getBlockByNumber {
exec 3>&1;
blknumber=$(dialog --nocancel --ok-label "Next" --inputbox "block number" 0 0 "123" 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
blknum=0x$(printf "%x\n" $blknumber)
URL="0.0.0.0:9500"
curl $URL -H "Content-Type: application/json" -X POST --data "{\"jsonrpc\":\"2.0\",\"method\":\"hmy_getBlockByNumber\",\"params\":[\"${blknum}\", true],\"id\":1}"
waitForAnyKey
}
function getBlockByHash {
exec 3>&1;
blkhash=$(dialog --nocancel --ok-label "Next" --inputbox "block hash" 0 0 "0x660fe701f580ffebfcfb4af1836c9929c1fd0014d8d79d60749fecf52df7a90d" 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
URL="0.0.0.0:9500"
curl $URL -H "Content-Type: application/json" -X POST --data "{\"jsonrpc\":\"2.0\",\"method\":\"hmy_getBlockByHash\",\"params\":[\"${blkhash}\", true],\"id\":1}"
waitForAnyKey
}
function getTransactionByHash {
exec 3>&1;
txHash=$(dialog --nocancel --ok-label "Next" --inputbox "transaction hash" 0 0 "0x1dff358dad4d0fc95b11acc9826b190d8b7971ac26b3f7ebdee83c10cafaf86f" 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
URL="0.0.0.0:9500"
curl $URL -H "Content-Type: application/json" -X POST --data "{\"jsonrpc\":\"2.0\",\"method\":\"hmy_getTransactionByHash\",\"params\":[\"${txHash}\"],\"id\":1}"
waitForAnyKey
}
function getTransactionByBlockNumber {
exec 3>&1;
blknumber=$(dialog --nocancel --ok-label "Next" --inputbox "block number" 0 0 "123" 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
blknum=0x$(printf "%x\n" $blknumber)
exec 3>&1;
txindex=$(dialog --nocancel --ok-label "Next" --inputbox "transaction index" 0 0 "0x0" 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
URL="0.0.0.0:9500"
curl $URL -H "Content-Type: application/json" -X POST --data "{\"jsonrpc\":\"2.0\",\"method\":\"hmy_getTransactionByBlockNumberAndIndex\",\"params\":[\"${blknum}\",\"${txindex}\"],\"id\":1}"
waitForAnyKey
}
function getTransactionByBlockHash {
exec 3>&1;
blkhash=$(dialog --nocancel --ok-label "Next" --inputbox "block hash" 0 0 "0x428ead93e632d5255ea3d1fb61b02ab8493cf562a398af2159c33ecd53c62c16" 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
exec 3>&1;
txindex=$(dialog --nocancel --ok-label "Next" --inputbox "transaction index" 0 0 "0x0" 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
URL="0.0.0.0:9500"
curl $URL -H "Content-Type: application/json" -X POST --data "{\"jsonrpc\":\"2.0\",\"method\":\"hmy_getTransactionByBlockHashAndIndex\",\"params\":[\"${blkhash}\",\"${txindex}\"],\"id\":1}"
waitForAnyKey
}
function getTransactionReceipt {
exec 3>&1;
txHash=$(dialog --nocancel --ok-label "Next" --inputbox "transaction hash" 0 0 "0x2fa714e40389cbbceda0f77e707035c0ec8aa940e8e10c0d445813177ea71e7d" 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
URL="0.0.0.0:9500"
curl $URL -H "Content-Type: application/json" -X POST --data "{\"jsonrpc\":\"2.0\",\"method\":\"hmy_getTransactionReceipt\",\"params\":[\"${txHash}\"],\"id\":1}"
waitForAnyKey
}
function getBlocksAndTxCount {
exec 3>&1;
nfrom=$(dialog --nocancel --ok-label "Next" --inputbox "from block number" 0 0 "123" 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
exec 3>&1;
nto=$(dialog --nocancel --ok-label "Next" --inputbox "to block number" 0 0 "456" 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
URL="0.0.0.0:9500"
for ((i = nfrom; i <= nto; i++))
do
blknum=0x$(printf "%x\n" $i)
txxCount=$(curl $URL -H "Content-Type: application/json" -X POST --data "{\"jsonrpc\":\"2.0\",\"method\":\"hmy_getBlockTransactionCountByNumber\",\"params\":[\"${blknum}\"],\"id\":1}" 2>/dev/null | jq -r ".result")
echo "blk: $i ($blknum) -> txs count: ${txxCount}"
done
waitForAnyKey
}
function ethGetBalance {
exec 3>&1;
accAddress=$(dialog --nocancel --ok-label "Next" --inputbox "account address" 0 0 "one..." 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
curl --location --request POST '0.0.0.0:9500' \
--header 'Content-Type: application/json' \
--data-raw "{
\"jsonrpc\": \"2.0\",
\"id\": 1,
\"method\": \"eth_getBalance\",
\"params\": [\"${accAddress}\", \"latest\"]
}"
waitForAnyKey
}
function showGasPrice {
curl -d '{
"jsonrpc":"2.0",
"method":"hmy_gasPrice",
"params":[],
"id":1
}' -H 'Content-Type:application/json' -X POST '0.0.0.0:9500'
waitForAnyKey
}
function blockchain {
blockchain_options=(1 "account transactions history"
2 "check account balance"
3 "eth get balance"
4 "gas price"
5 "block by number"
6 "block by hash"
7 "get transaction by hash"
8 "get transaction by block number and index"
9 "get transaction by block hash and index"
10 "get transaction receipt"
11 "get blocks and tx count")
blockchain_menu_result="done"
while [ $blockchain_menu_result == "done" ]
do
selected_bc_option=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "blockchain info" \
--ok-label "Next" --cancel-label "Back" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${blockchain_options[@]}" \
2>&1 >/dev/tty)
clear
case $selected_bc_option in
1)
getTransactionsHistory
;;
2)
hmyGetBalance
;;
3)
ethGetBalance
;;
4)
showGasPrice
;;
5)
getBlockByNumber
;;
6)
getBlockByHash
;;
7)
getTransactionByHash
;;
8)
getTransactionByBlockNumber
;;
9)
getTransactionByBlockHash
;;
10)
getTransactionReceipt
;;
11)
getBlocksAndTxCount
;;
*)
blockchain_menu_result="back"
esac
done
}
#========================================================================
# rclone
#========================================================================
function rclone {
set -x
FOLDER=${1:-mainnet.min}
HMY_DB_DIR=${2:-data}
NODE_TYPE=${3:-Validator}
while :; do
if command -v rclone; then
break
else
echo waiting for rclone ...
sleep 10
fi
done
sleep 3
# stop harmony service
sudo systemctl stop harmony.service
unset shard
# determine the shard number
shard=$(cat shard.txt)
if [ $shard != 0 ]; then #applicable for non S0 validator and explorer
rclone sync -P --checksum release:pub.harmony.one/${FOLDER}/harmony_db_${shard} ${HMY_DB_DIR}/harmony_db_${shard} --multi-thread-streams 4 --transfers=16
rclone sync -P --checksum release:pub.harmony.one/mainnet.snap/harmony_db_0 ${HMY_DB_DIR}/harmony_db_0 --multi-thread-streams 4 --transfers=64
else
if [ $NODE_TYPE = "Explorer" ]; then
rclone sync -P --checksum release:pub.harmony.one/${FOLDER}/harmony_db_0 ${HMY_DB_DIR}/harmony_db_0 --multi-thread-streams 4 --transfers=64
else
rclone sync -P --checksum release:pub.harmony.one/mainnet.snap/harmony_db_0 ${HMY_DB_DIR}/harmony_db_0 --multi-thread-streams 4 --transfers=64
fi
fi
# restart the harmony service
sudo systemctl start harmony.service
}
function install_rclone {
# error codes
# 0 - exited without problems
# 1 - parameters not supported were used or some unexpected error occurred
# 2 - OS not supported by this script
# 3 - installed version of rclone is up to date
# 4 - supported unzip tools are not available
set -e
#when adding a tool to the list make sure to also add its corresponding command further in the script
unzip_tools_list=('unzip' '7z' 'busybox')
usage() { echo "Usage: curl https://rclone.org/install.sh | sudo bash [-s beta]" 1>&2; exit 1; }
#check for beta flag
if [ -n "$1" ] && [ "$1" != "beta" ]; then
usage
fi
if [ -n "$1" ]; then
install_beta="beta "
fi
#create tmp directory and move to it with macOS compatibility fallback
tmp_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'rclone-install.XXXXXXXXXX')
cd "$tmp_dir"
#make sure unzip tool is available and choose one to work with
set +e
for tool in ${unzip_tools_list[*]}; do
trash=$(hash "$tool" 2>>errors)
if [ "$?" -eq 0 ]; then
unzip_tool="$tool"
break
fi
done
set -e
# exit if no unzip tools available
if [ -z "$unzip_tool" ]; then
printf "\nNone of the supported tools for extracting zip archives (${unzip_tools_list[*]}) were found. "
printf "Please install one of them and try again.\n\n"
exit 4
fi
# Make sure we don't create a root owned .config/rclone directory #2127
export XDG_CONFIG_HOME=config
#check installed version of rclone to determine if update is necessary
version=$(rclone --version 2>>errors | head -n 1)
if [ -z "$install_beta" ]; then
current_version=$(curl -fsS https://downloads.rclone.org/version.txt)
else
current_version=$(curl -fsS https://beta.rclone.org/version.txt)
fi
if [ "$version" = "$current_version" ]; then
printf "\nThe latest ${install_beta}version of rclone ${version} is already installed.\n\n"
exit 3
fi
#detect the platform
OS="$(uname)"
case $OS in
Linux)
OS='linux'
;;
FreeBSD)
OS='freebsd'
;;
NetBSD)
OS='netbsd'
;;
OpenBSD)
OS='openbsd'
;;
Darwin)
OS='osx'
;;
SunOS)
OS='solaris'
echo 'OS not supported'
exit 2
;;
*)
echo 'OS not supported'
exit 2
;;
esac
OS_type="$(uname -m)"
case "$OS_type" in
x86_64|amd64)
OS_type='amd64'
;;
i?86|x86)
OS_type='386'
;;
aarch64|arm64)
OS_type='arm64'
;;
arm*)
OS_type='arm'
;;
*)
echo 'OS type not supported'
exit 2
;;
esac
#download and unzip
if [ -z "$install_beta" ]; then
download_link="https://downloads.rclone.org/rclone-current-${OS}-${OS_type}.zip"
rclone_zip="rclone-current-${OS}-${OS_type}.zip"
else
download_link="https://beta.rclone.org/rclone-beta-latest-${OS}-${OS_type}.zip"
rclone_zip="rclone-beta-latest-${OS}-${OS_type}.zip"
fi
curl -OfsS "$download_link"
unzip_dir="tmp_unzip_dir_for_rclone"
# there should be an entry in this switch for each element of unzip_tools_list
case "$unzip_tool" in
'unzip')
unzip -a "$rclone_zip" -d "$unzip_dir"
;;
'7z')
7z x "$rclone_zip" "-o$unzip_dir"
;;
'busybox')
mkdir -p "$unzip_dir"
busybox unzip "$rclone_zip" -d "$unzip_dir"
;;
esac
cd $unzip_dir/*
#mounting rclone to environment
case "$OS" in
'linux')
#binary
cp rclone /usr/bin/rclone.new
chmod 755 /usr/bin/rclone.new
chown root:root /usr/bin/rclone.new
mv /usr/bin/rclone.new /usr/bin/rclone
#manual
if ! [ -x "$(command -v mandb)" ]; then
echo 'mandb not found. The rclone man docs will not be installed.'
else
mkdir -p /usr/local/share/man/man1
cp rclone.1 /usr/local/share/man/man1/
mandb
fi
;;
'freebsd'|'openbsd'|'netbsd')
#binary
cp rclone /usr/bin/rclone.new
chown root:wheel /usr/bin/rclone.new
mv /usr/bin/rclone.new /usr/bin/rclone
#manual
mkdir -p /usr/local/man/man1
cp rclone.1 /usr/local/man/man1/
makewhatis
;;
'osx')
#binary
mkdir -p /usr/local/bin
cp rclone /usr/local/bin/rclone.new
mv /usr/local/bin/rclone.new /usr/local/bin/rclone
#manual
mkdir -p /usr/local/share/man/man1
cp rclone.1 /usr/local/share/man/man1/
;;
*)
echo 'OS not supported'
exit 2
esac
#update version variable post install
version=$(rclone --version 2>>errors | head -n 1)
printf "\n${version} has successfully installed."