-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdiginode.sh
More file actions
executable file
·6827 lines (5595 loc) · 305 KB
/
Copy pathdiginode.sh
File metadata and controls
executable file
·6827 lines (5595 loc) · 305 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
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
#
# Name: DigiNode Dashboard v0.11.3
#
# Purpose: Monitor and manage the status of you DigiByte Node and DigiAsset Node.
#
# Compatibility: Supports x86_86 or arm64 hardware with Raspberry Pi OS, Ubuntu or Debian 64-bit distros.
# A Raspberry Pi with at least 8Gb RAM running Raspberry Pi OS Lite 64-bit is recommended.
#
# Author: Olly Stedall [ Bluesky: @olly.st ]
#
# Website: https://diginode.tools
#
# Support: Telegram - https://t.me/DigiNodeTools
# Bluesky - https://bsky.app/profile/diginode.tools
#
# -----------------------------------------------------------------------------------------------------
#####################################################
##### IMPORTANT INFORMATION #########################
#####################################################
# Please note that this script requires the diginode-setup.sh script to be with it
# in the same folder when it runs. Tne setup script contains functions and variables
# used by this one.
#
# Both DigiNode Setup and Dashboard scripts make use of a settings file
# located at: ~/.digibyte/diginode.settings
#
# It want to make changes to folder locations etc. please edit this file.
# (e.g. To move your DigiByte data folder to an external drive.)
#
# Note: The default location of the diginode.settings file can be changed at the top of
# the setup script, but this is not recommended.
######################################################
######### VARIABLES ##################################
######################################################
# For better maintainability, we store as much information that can change in variables
# This allows us to make a change in one place that can propagate to all instances of the variable
# These variables should all be GLOBAL variables, written in CAPS
# Local variables will be in lowercase and will exist only within functions
# This variable stores the version number of this release of 'DigiNode Tools'.
# Whenever there is a new release, this number gets updated to match the release number on GitHub.
# The version number should be three numbers seperated by a period
# Do not change this number or the mechanism for installing updates may no longer work.
DGNT_VER_LOCAL=0.11.3
# Last Updated: 2025-04-22
# Convert to a fixed width string of 9 characters to display in the script
DGNT_VER_LOCAL_FW=$(printf "%-9s" "v$DGNT_VER_LOCAL")
# This is the command people will enter to run the install script.
DGNT_SETUP_OFFICIAL_CMD="curl -sSL setup.diginode.tools | bash"
########################################################
#### UPDATE THESE VALUES FROM DIGINODE SETUP FIRST #####
########################################################
# These colour and text formatting variables are included in both scripts since they are required before diginode-setup.sh is sourced into this one.
# Changes to these variables should be first made in the setup script and then copied here, to help ensure the settings remain identical in both scripts.
# Set these values so we can still run in color
COL_NC='\e[0m' # No Color
COL_LIGHT_GREEN='\e[1;32m'
COL_LIGHT_RED='\e[1;31m'
COL_LIGHT_CYAN='\e[1;96m'
COL_BOLD_WHITE='\e[1;37m'
COL_LIGHT_YEL='\e[1;33m'
TICK=" [${COL_LIGHT_GREEN}✓${COL_NC}]"
CROSS=" [${COL_LIGHT_RED}✗${COL_NC}]"
WARN=" [${COL_LIGHT_RED}!${COL_NC}]"
INFO=" [${COL_BOLD_WHITE}i${COL_NC}]"
SKIP=" [${COL_BOLD_WHITE}-${COL_NC}]"
INDENT=" "
# shellcheck disable=SC2034
DONE="${COL_LIGHT_GREEN} done!${COL_NC}"
OVER="\\r\\033[K"
## Set ANSI code variables for colors and formatting
txtred=$(tput setaf 1) # Red
txtgrn=$(tput setaf 2) # Green
txtylw=$(tput setaf 3) # Yellow
txtblu=$(tput setaf 4) # Blue
txtpur=$(tput setaf 5) # Purple
txtcyn=$(tput setaf 6) # Cyan
txtwht=$(tput setaf 7) # White
txtbred=$(tput setaf 9) # Bright Red
txtbgrn=$(tput setaf 10) # Bright Green
txtbylw=$(tput setaf 11) # Bright Yellow
txtbblu=$(tput setaf 12) # Bright Blue
txtbpur=$(tput setaf 13) # Bright Purple
txtbcyn=$(tput setaf 14) # Bright Cyan
txtbwht=$(tput setaf 15) # Bright White
txtrst=$(tput sgr0) # Text reset.
# tput setab [1-7] : Set a background colour using ANSI escape
# tput setb [1-7] : Set a background colour
# tput setaf [1-7] : Set a foreground colour using ANSI escape
# tput setf [1-7] : Set a foreground colour
txtbld=$(tput bold) # Set bold mode
# tput dim : turn on half-bright mode
# tput smul : begin underline mode
# tput rmul : exit underline mode
# tput rev : Turn on reverse mode
# tput smso : Enter standout mode (bold on rxvt)
# tput rmso : Exit standout mode
# Dashboard colors
dbcol_bwht="\e[97m" # Bright White
dbcol_bred="\e[91m" # Bright Red
dbcol_bylw="\e[93m" # Bright Yellow
dbcol_bgrn="\e[92m" # Bright Green
dbcol_bblu="\e[94m" # Bright Blue
#########
dbcol_bld="\e[1m" # Bold Text
dbcol_rst="\e[0m" # Text Reset
#########
dbcol_bld_bwht="\e[1;37m" # Bold Bright White Text
######## Undocumented Flags. Shhh ########
# These are undocumented flags;
VERBOSE_MODE=false # Set this to true to get more verbose feedback. Very useful for debugging.
UNINSTALL=false
LOCATE_DIGIBYTE=false
DISPLAY_HELP=false
EDIT_DGBCONF=false
EDIT_DGNTSET=false
VIEW_DGBLOG=false
VIEW_DGB2LOG=false
VIEW_DGBLOGMN=false
VIEW_DGBLOGTN=false
VIEW_DGBLOGRT=false
VIEW_DGBLOGSN=false
VIEW_WALLETS=false
CREATE_WALLET=false
LOAD_WALLET=false
CHANGE_WALLET=false
DGBCORE_RESTART=false
DGBCORE_STOP=false
DGB2CORE_RESTART=false
DGB2CORE_STOP=false
DGBPEERS=false
DGB2PEERS=false
VIEW_RPC_CREDENTIALS=false
UNKNOWN_FLAG=false
REENABLE_PORT_TEST=false
# Check arguments for the undocumented flags
# --dgndev (-d) will use and install the develop branch of DigiNode Tools (used during development)
for var in "$@"; do
case "$var" in
"--uninstall" ) UNINSTALL=true;;
"--verbose" ) VERBOSE_MODE=true;;
"--verboseoff" ) VERBOSE_MODE=false;;
"--locatedgb" ) LOCATE_DIGIBYTE=true;;
"--help" ) DISPLAY_HELP=true;;
"-h" ) DISPLAY_HELP=true;;
"--dgbconf" ) EDIT_DGBCONF=true;;
"--settings" ) EDIT_DGNTSET=true;;
"--dgblog" ) VIEW_DGBLOG=true;;
"--dgb2log" ) VIEW_DGB2LOG=true;;
"--dgblogmn" ) VIEW_DGBLOGMN=true;;
"--dgblogtn" ) VIEW_DGBLOGTN=true;;
"--dgblogrt" ) VIEW_DGBLOGRT=true;;
"--dgblogsn" ) VIEW_DGBLOGSN=true;;
"--listwallets" ) VIEW_WALLETS=true;;
"--createwallet" ) CREATE_WALLET=true;;
# "--loadwallet" ) LOAD_WALLET=true;;
"--changewallet" ) CHANGE_WALLET=true;;
"--dgbrestart" ) DGBCORE_RESTART=true;;
"--dgbstop" ) DGBCORE_STOP=true;;
"--dgb2restart" ) DGB2CORE_RESTART=true;;
"--dgb2stop" ) DGB2CORE_STOP=true;;
"--dgbpeers" ) DGBPEERS=true;;
"--dgb2peers" ) DGB2PEERS=true;;
"--rpc" ) VIEW_RPC_CREDENTIALS=true;;
"--porttest" ) REENABLE_PORT_TEST=true;;
# If an unknown flag is used...
*) UNKNOWN_FLAG=true;;
esac
done
######################################################
######### FUNCTIONS ##################################
######################################################
# Run a command via a launch flag
flag_commands() {
if [ $UNKNOWN_FLAG = true ] || \
[ $EDIT_DGBCONF = true ] || \
[ $EDIT_DGNTSET = true ] || \
[ $VIEW_DGBLOG = true ] || \
[ $VIEW_DGB2LOG = true ] || \
[ $VIEW_DGBLOGMN = true ] || \
[ $VIEW_DGBLOGTN = true ] || \
[ $VIEW_DGBLOGRT = true ] || \
[ $VIEW_DGBLOGSN = true ] || \
[ $VIEW_WALLETS = true ] || \
[ $LOAD_WALLET = true ] || \
[ $CREATE_WALLET = true ] || \
[ $CHANGE_WALLET = true ] || \
[ $DGBCORE_RESTART = true ] || \
[ $DGBCORE_STOP = true ] || \
[ $DGB2CORE_RESTART = true ] || \
[ $DGB2CORE_STOP = true ] || \
[ $DGB2CORE_STOP = true ] || \
[ $DGBPEERS = true ] || \
[ $DGB2PEERS = true ] || \
[ $VIEW_RPC_CREDENTIALS = true ] || \
[ $REENABLE_PORT_TEST = true ]; then
printf "\\n"
get_script_location # Find which folder this script is running in (in case this is an unnoficial DigiNode)
import_setup_functions # Import diginode-setup.sh file because it contains functions we need
# If this is an unknown flag, warn and quit
if [ $UNKNOWN_FLAG = true ]; then #
printf "%b ERROR: Unrecognised flag used: $var\\n" "${WARN}"
printf "\\n"
printf "%b For help, enter:\\n" "${INDENT}"
printf "\\n"
printf "%b$ %bdiginode --help%b\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}"
printf "\\n"
exit
fi
# Work out which DigiByte log file to display based on which chain is in use
if [ $VIEW_DGBLOG = true ]; then # --dgblog
diginode_tools_import_settings silent
query_digibyte_chain
if [ "$DGB_NETWORK_CURRENT" = "TESTNET" ]; then
VIEW_DGBLOGTN=true
elif [ "$DGB_NETWORK_CURRENT" = "REGTEST" ]; then
VIEW_DGBLOGRT=true
elif [ "$DGB_NETWORK_CURRENT" = "SIGNET" ]; then
VIEW_DGBLOGSN=true
elif [ "$DGB_NETWORK_CURRENT" = "MAINNET" ]; then
VIEW_DGBLOGMN=true
fi
fi
if [ $EDIT_DGBCONF = true ]; then # --dgbconf
diginode_tools_import_settings silent
set_text_editor
if test -f $DGB_CONF_FILE; then
exec $TEXTEDITOR $DGB_CONF_FILE
else
printf "%bError: digibyte.conf file does not exist\\n\\n" "${INDENT}"
exit 1
fi
elif [ $EDIT_DGNTSET = true ]; then # --settings
diginode_tools_import_settings silent
set_text_editor
if test -f $DGNT_SETTINGS_FILE ; then
exec $TEXTEDITOR $DGNT_SETTINGS_FILE
else
printf "%bError: diginode.settings file does not exist\\n\\n" "${INDENT}"
fi
elif [ $VIEW_DGBLOGMN = true ]; then # --dgblogmn
if [ "$DGB_SETTINGS_LOCATION" = "" ]; then
diginode_tools_import_settings silent
fi
if test -f $DGB_SETTINGS_LOCATION/debug.log ; then
echo " ====================================="
echo " DigiByte Core MAINNET debug.log"
echo " ====================================="
echo ""
echo " Displaying the last 50 lines from mainnet log file. Press Ctrl-C to Stop."
echo ""
exec tail -n50 -f $DGB_SETTINGS_LOCATION/debug.log
else
printf "%bError: DigiByte Core MAINNET log file does not exist\\n\\n" "${INDENT}"
exit 1
fi
elif [ $VIEW_DGBLOGTN = true ] || [ $VIEW_DGB2LOG = true ]; then # --dgblogtn
if [ "$DGB_SETTINGS_LOCATION" = "" ]; then
diginode_tools_import_settings silent
fi
if test -f $DGB_SETTINGS_LOCATION/testnet4/debug.log ; then
echo " ====================================="
echo " DigiByte Core TESTNET debug.log"
echo " ====================================="
echo ""
echo " Displaying the last 50 lines from testnet log file. Press Ctrl-C to Stop."
echo ""
exec tail -n50 -f $DGB_SETTINGS_LOCATION/testnet4/debug.log
else
printf "%bError: DigiByte Core TESTNET log file does not exist\\n\\n" "${INDENT}"
exit 1
fi
elif [ $VIEW_DGBLOGRT = true ]; then # --dgblogrt
if [ "$DGB_SETTINGS_LOCATION" = "" ]; then
diginode_tools_import_settings silent
fi
if test -f $DGB_SETTINGS_LOCATION/regtest/debug.log ; then
echo " ====================================="
echo " DigiByte Core REGTEST debug.log"
echo " ====================================="
echo ""
echo " Displaying the last 50 lines from regtest log file. Press Ctrl-C to Stop."
echo ""
exec tail -n50 -f $DGB_SETTINGS_LOCATION/regtest/debug.log
else
printf "%bError: DigiByte Core REGTEST log file does not exist\\n\\n" "${INDENT}"
exit 1
fi
elif [ $VIEW_DGBLOGSN = true ]; then # --dgblogrt
if [ "$DGB_SETTINGS_LOCATION" = "" ]; then
diginode_tools_import_settings silent
fi
if test -f $DGB_SETTINGS_LOCATION/signet/debug.log ; then
echo " ====================================="
echo " DigiByte Core SIGNET debug.log"
echo " ====================================="
echo ""
echo " Displaying the last 50 lines from signet log file. Press Ctrl-C to Stop."
echo ""
exec tail -n50 -f $DGB_SETTINGS_LOCATION/signet/debug.log
else
printf "%bError: DigiByte Core SIGNET log file does not exist\\n\\n" "${INDENT}"
exit 1
fi
elif [ $VIEW_WALLETS = true ]; then # --listwallets
diginode_tools_import_settings silent
query_digibyte_chain
printf "DigiByte $DGB_NETWORK_CURRENT Wallets:\n\n"
if check_service_active "digibyted"; then
query_wallets=$($DGB_CLI listwallets 2>/dev/null)
wallets=$(echo $query_wallets | jq -r '.[]')
if [ "$query_wallets" = "" ]; then
echo "- ERROR: DigiByte $DGB_NETWORK_CURRENT node is currently starting up. Please try again in a minute."
elif [ -z "$wallets" ] && ! grep -q '""' <<< "$query_wallets"; then
echo "- No wallets loaded."
else
# Collect wallet information
wallet_info_list=()
while IFS= read -r wallet; do
if [ "$wallet" == "" ]; then
wallet_display_name="Default Wallet"
wallet_info=$($DGB_CLI -rpcwallet="" getwalletinfo 2>/dev/null)
else
wallet_display_name="$wallet"
wallet_info=$($DGB_CLI -rpcwallet="$wallet" getwalletinfo 2>/dev/null)
fi
if [ $? -ne 0 ]; then
wallet_info_list+=("$wallet_display_name: Error retrieving wallet info")
continue
fi
balance=$(echo $wallet_info | jq -r '.balance')
if [ -z "$balance" ] || [ "$balance" = "0" ]; then
balance="0.00000000"
fi
wallet_info_list+=("- \"$wallet_display_name\" : $balance DGB")
done <<< "$wallets"
# Find the maximum length of wallet names
max_length=0
for info in "${wallet_info_list[@]}"; do
wallet_name=$(echo "$info" | cut -d':' -f1)
if [ ${#wallet_name} -gt $max_length ]; then
max_length=${#wallet_name}
fi
done
# Print the wallet information with right-aligned balances
for info in "${wallet_info_list[@]}"; do
wallet_name=$(echo "$info" | cut -d':' -f1)
balance=$(echo "$info" | cut -d':' -f2)
printf "%-${max_length}s: %s\n" "$wallet_name" "$balance"
done
fi
printf "\n"
else
printf "ERROR: DigiByte $DGB_NETWORK_CURRENT Node is not running.\n"
printf "\n"
fi
if [ "$DGB_DUAL_NODE" = "YES" ]; then
printf "DigiByte TESTNET Wallets:\n\n"
if check_service_active "digibyted-testnet"; then
query_wallets=$($DGB_CLI -testnet listwallets 2>/dev/null)
wallets=$(echo $query_wallets | jq -r '.[]')
if [ "$query_wallets" = "" ]; then
echo "- ERROR: DigiByte TESTNET node is currently starting up. Please try again in a minute."
elif [ -z "$wallets" ] && ! grep -q '""' <<< "$query_wallets"; then
echo "- No wallets loaded."
else
# Collect wallet information
wallet_info_list=()
while IFS= read -r wallet; do
if [ "$wallet" == "" ]; then
wallet_display_name="Default Wallet"
wallet_info=$($DGB_CLI -testnet -rpcwallet="" getwalletinfo 2>/dev/null)
else
wallet_display_name="$wallet"
wallet_info=$($DGB_CLI -testnet -rpcwallet="$wallet" getwalletinfo 2>/dev/null)
fi
if [ $? -ne 0 ]; then
wallet_info_list+=("$wallet_display_name: Error retrieving wallet info")
continue
fi
balance=$(echo $wallet_info | jq -r '.balance')
if [ -z "$balance" ] || [ "$balance" = "0" ]; then
balance="0.00000000"
fi
wallet_info_list+=("- \"$wallet_display_name\" : $balance DGB")
done <<< "$wallets"
# Find the maximum length of wallet names
max_length=0
for info in "${wallet_info_list[@]}"; do
wallet_name=$(echo "$info" | cut -d':' -f1)
if [ ${#wallet_name} -gt $max_length ]; then
max_length=${#wallet_name}
fi
done
# Print the wallet information with right-aligned balances
for info in "${wallet_info_list[@]}"; do
wallet_name=$(echo "$info" | cut -d':' -f1)
balance=$(echo "$info" | cut -d':' -f2)
printf "%-${max_length}s: %s\n" "$wallet_name" "$balance"
done
fi
printf "\n"
else
printf "ERROR: DigiByte TESTNET Node is not running.\n"
printf "\n"
fi
fi
exit
elif [ $CREATE_WALLET = true ]; then # --createwallet
diginode_tools_import_settings silent
query_digibyte_chain
# create ~/.digibyte folder if it does not exist
if [ ! -d "$DGNT_SETTINGS_LOCATION" ]; then
str="Creating ~/.digibyte folder..."
printf "\\n%b %s" "${INFO}" "${str}"
sudo -u $USER_ACCOUNT mkdir $DGNT_SETTINGS_LOCATION
fi
# create ~/.digibyte/wallets folder if it does not exist
if [ ! -d "$DGNT_SETTINGS_LOCATION/wallets" ]; then
str="Creating ~/.digibyte/wallets folder..."
printf "\\n%b %s" "${INFO}" "${str}"
sudo -u $USER_ACCOUNT mkdir $DGNT_SETTINGS_LOCATION/wallets
fi
# Are we running a dual node and is the secondary testnet node?
if [ "$DGB_DUAL_NODE" = "YES" ] && check_service_active "digibyted-testnet"; then
is_secondary_node_running="yes"
secondary_node="TESTNET"
else
is_secondary_node_running="no"
secondary_node="TESTNET"
fi
# Is the primary node running and what type is it?
if check_service_active "digibyted"; then
is_primary_node_running="yes"
primary_node=$DGB_NETWORK_CURRENT
else
is_primary_node_running="no"
secondary_node=$DGB_NETWORK_CURRENT
fi
# If two nodes are running ask the user which they want to create a wallet for
if [ "$is_secondary_node_running" = "yes" ] && [ "$is_secondary_node_running" = "yes" ]; then
echo "dual node"
fi
if check_service_active "digibyted"; then
wallets=$($DGB_CLI listwallets | jq -r '.[]')
printf "DigiByte $DGB_NETWORK_CURRENT Wallets:\n\n"
if [ -z "$wallets" ]; then
echo "- No wallets loaded."
else
# Collect wallet information
wallet_info_list=()
while IFS= read -r wallet; do
if [ "$wallet" == "" ]; then
wallet_display_name="Default Wallet"
wallet_info=$($DGB_CLI -rpcwallet="" getwalletinfo 2>/dev/null)
else
wallet_display_name="$wallet"
wallet_info=$($DGB_CLI -rpcwallet="$wallet" getwalletinfo 2>/dev/null)
fi
if [ $? -ne 0 ]; then
wallet_info_list+=("$wallet_display_name: Error retrieving wallet info")
continue
fi
balance=$(echo $wallet_info | jq -r '.balance')
if [ -z "$balance" ] || [ "$balance" = "0" ]; then
balance="0.00000000"
fi
wallet_info_list+=("- \"$wallet_display_name\" : $balance DGB")
done <<< "$wallets"
# Find the maximum length of wallet names
max_length=0
for info in "${wallet_info_list[@]}"; do
wallet_name=$(echo "$info" | cut -d':' -f1)
if [ ${#wallet_name} -gt $max_length ]; then
max_length=${#wallet_name}
fi
done
# Print the wallet information with right-aligned balances
for info in "${wallet_info_list[@]}"; do
wallet_name=$(echo "$info" | cut -d':' -f1)
balance=$(echo "$info" | cut -d':' -f2)
printf "%-${max_length}s: %s\n" "$wallet_name" "$balance"
done
fi
printf "\n"
else
printf "ERROR: DigiByte Node is not running.\n"
printf "\n"
fi
if [ "$DGB_DUAL_NODE" = "YES" ]; then
if check_service_active "digibyted-testnet"; then
wallets=$($DGB_CLI -testnet listwallets | jq -r '.[]')
printf "DigiByte TESTNET Wallets:\n\n"
if [ -z "$wallets" ]; then
echo "- No wallets loaded."
else
# Collect wallet information
wallet_info_list=()
while IFS= read -r wallet; do
if [ "$wallet" == "" ]; then
wallet_display_name="Default Wallet"
wallet_info=$($DGB_CLI -testnet -rpcwallet="" getwalletinfo 2>/dev/null)
else
wallet_display_name="$wallet"
wallet_info=$($DGB_CLI -testnet -rpcwallet="$wallet" getwalletinfo 2>/dev/null)
fi
if [ $? -ne 0 ]; then
wallet_info_list+=("$wallet_display_name: Error retrieving wallet info")
continue
fi
balance=$(echo $wallet_info | jq -r '.balance')
if [ -z "$balance" ] || [ "$balance" = "0" ]; then
balance="0.00000000"
fi
wallet_info_list+=("- \"$wallet_display_name\" : $balance DGB")
done <<< "$wallets"
# Find the maximum length of wallet names
max_length=0
for info in "${wallet_info_list[@]}"; do
wallet_name=$(echo "$info" | cut -d':' -f1)
if [ ${#wallet_name} -gt $max_length ]; then
max_length=${#wallet_name}
fi
done
# Print the wallet information with right-aligned balances
for info in "${wallet_info_list[@]}"; do
wallet_name=$(echo "$info" | cut -d':' -f1)
balance=$(echo "$info" | cut -d':' -f2)
printf "%-${max_length}s: %s\n" "$wallet_name" "$balance"
done
fi
printf "\n"
else
printf "ERROR: DigiByte TESTNET Node is not running.\n"
printf "\n"
fi
fi
exit
# banana
elif [ $LOAD_WALLET = true ]; then # --loadwallet
diginode_tools_import_settings silent
query_digibyte_chain
if check_service_active "digibyted"; then
loaded_wallets=$($DGB_CLI listwallets | jq -r '.[]')
# Search for wallet.dat files
wallet_paths=()
wallet_names=()
already_loaded_names=()
# Add old default wallet if it exists
if [ -f ~/.digibyte/wallet.dat ]; then
if grep -q '^$' <<< "$loaded_wallets"; then
already_loaded_names+=("Default Wallet")
else
wallet_paths+=("~/.digibyte/wallet.dat")
wallet_names+=("Default Wallet")
fi
fi
# Add default wallet 2 if it exists
if [ -f ~/.digibyte/wallets/wallet.dat ]; then
if grep -q '^$' <<< "$loaded_wallets"; then
already_loaded_names+=("Default Wallet 2")
else
wallet_paths+=("~/.digibyte/wallets/wallet.dat")
wallet_names+=("Default Wallet 2")
fi
fi
# Search in ~/.digibyte/wallets subdirectories
for wallet in ~/.digibyte/wallets/*/wallet.dat; do
if [ -f "$wallet" ]; then
wallet_name=$(basename "$(dirname "$wallet")")
if grep -q "^$wallet_name$" <<< "$loaded_wallets"; then
already_loaded_names+=("$wallet_name")
else
wallet_paths+=("$wallet")
wallet_names+=("$wallet_name")
fi
fi
done
# Check if all wallets are already loaded
if [ ${#wallet_paths[@]} -eq 0 ]; then
echo "All discovered wallets are already loaded:"
for loaded_wallet in "${already_loaded_names[@]}"; do
echo "- $loaded_wallet"
done
exit 0
fi
# Add option to load all wallets if there are two or more unloaded wallets
if [ ${#wallet_paths[@]} -gt 1 ]; then
wallet_names+=("ALL WALLETS")
wallet_paths+=("")
fi
# Create menu options
menu_options=()
for i in "${!wallet_names[@]}"; do
menu_options+=($((i+1)) "${wallet_names[i]}")
done
# Create the message for already loaded wallets
loaded_wallets_msg="Please select a wallet to load:"
if [ ${#already_loaded_names[@]} -gt 0 ]; then
loaded_wallets_msg="These wallets are already loaded:\n"
for loaded_wallet in "${already_loaded_names[@]}"; do
loaded_wallets_msg+="- $loaded_wallet\n"
done
loaded_wallets_msg+="\nPlease select a wallet to load:"
fi
# Determine dialog box height
dialog_height=$(( ${#wallet_names[@]} + ${#already_loaded_names[@]} + 10 ))
# Display dialog menu
choice=$(dialog --clear --backtitle "Wallet Selection" \
--title "Choose a wallet to load" \
--menu "$loaded_wallets_msg" $dialog_height 50 ${#menu_options[@]} \
"${menu_options[@]}" 2>&1 >/dev/tty)
clear
# Exit if Cancel is chosen
if [ -z "$choice" ]; then
echo "No wallet selected. Exiting."
exit 0
fi
# Get the chosen wallet path
chosen_wallet_path="${wallet_paths[$((choice-1))]}"
chosen_wallet_name="${wallet_names[$((choice-1))]}"
if [ "$chosen_wallet_name" == "ALL WALLETS" ]; then
echo "Loading all wallets..."
for i in "${!wallet_paths[@]}"; do
if [ "${wallet_paths[i]}" == "" ]; then
continue
fi
wallet_to_load="${wallet_names[i]}"
if [ "$wallet_to_load" == "Default Wallet" ]; then
wallet_to_load=""
fi
load_result=$($DGB_CLI loadwallet "$wallet_to_load" 2>&1)
if [[ $load_result == *"error code:"* ]]; then
echo "Error loading wallet: ${wallet_names[i]} - $load_result"
else
echo "Wallet loaded successfully: ${wallet_names[i]}"
fi
done
$DGB_CLI listwallets
else
echo "Loading wallet: $chosen_wallet_name"
if [ "$chosen_wallet_name" == "Default Wallet" ]; then
load_result=$($DGB_CLI loadwallet "" 2>&1)
else
load_result=$($DGB_CLI loadwallet "$chosen_wallet_name" 2>&1)
fi
if [[ $load_result == *"error code:"* ]]; then
echo "Error loading wallet: $load_result"
else
echo "Wallet loaded successfully."
$DGB_CLI listwallets
fi
fi
else
echo "ERROR: DigiByte Node is not running."
fi
exit
elif [ $DGBCORE_RESTART = true ]; then # --dgbrestart
local str="Restarting digibyted service"
printf "%b %s..." "${INFO}" "${str}"
# If systemctl exists,
if $(command -v systemctl >/dev/null 2>&1); then
sudo systemctl restart digibyted &> /dev/null
else
# Otherwise, fall back to the service command
sudo service digibyted restart &> /dev/null
fi
printf "%b%b %s...\\n\\n" "${OVER}" "${TICK}" "${str}"
exit
elif [ $DGBCORE_STOP = true ]; then # --stopdgb
local str="Stopping digibyted service"
printf "%b %s..." "${INFO}" "${str}"
# If systemctl exists,
if $(command -v systemctl >/dev/null 2>&1); then
sudo systemctl stop digibyted &> /dev/null
else
# Otherwise, fall back to the service command
sudo service digibyted stop &> /dev/null
fi
printf "%b%b %s...\\n\\n" "${OVER}" "${TICK}" "${str}"
exit
elif [ $DGB2CORE_RESTART = true ]; then # --dgbrestart
diginode_tools_import_settings silent
if [ "$DGB_DUAL_NODE" = "YES" ]; then
local str="Restarting digibyted-testnet service"
printf "%b %s..." "${INFO}" "${str}"
# If systemctl exists,
if $(command -v systemctl >/dev/null 2>&1); then
sudo systemctl restart digibyted-testnet &> /dev/null
else
# Otherwise, fall back to the service command
sudo service digibyted-testnet restart &> /dev/null
fi
printf "%b%b %s...\\n\\n" "${OVER}" "${TICK}" "${str}"
else
printf "%bError: DigiByte Dual Node not installed.\\n\\n" "${INDENT}"
fi
exit
elif [ $DGB2CORE_STOP = true ]; then # --stopdgb
diginode_tools_import_settings silent
if [ "$DGB_DUAL_NODE" = "YES" ]; then
local str="Stopping digibyted-testnet service"
printf "%b %s..." "${INFO}" "${str}"
# If systemctl exists,
if $(command -v systemctl >/dev/null 2>&1); then
sudo systemctl stop digibyted-testnet &> /dev/null
else
# Otherwise, fall back to the service command
sudo service digibyted-testnet stop &> /dev/null
fi
printf "%b%b %s...\\n\\n" "${OVER}" "${TICK}" "${str}"
else
printf "%bError: DigiByte Dual Node not installed.\\n\\n" "${INDENT}"
fi
exit
elif [ $DGBPEERS = true ]; then # --dgbpeers
diginode_tools_import_settings silent
query_digibyte_chain
if check_service_active "digibyted"; then
printf "DigiByte $DGB_NETWORK_CURRENT Peers:\\n\\n"
printf "IP4 Peers:\\n"
#store peers
mainnetpeers=$($DGB_CLI getpeerinfo)
ip4peers=$(echo $mainnetpeers | jq -r '.[] | {ip: .addr} | select(.ip | test("^[0-9]") and (test("\\.onion$") | not)) | .ip' | sort)
if [ -z "$ip4peers" ]; then
echo "none"
else
echo "$ip4peers"
fi
printf "\\n"
printf "IP6 Peers:\\n"
ip6peers=$(echo $mainnetpeers | jq -r '.[] | {ip: .addr, port: .port} | "\(.ip):\(.port)"' | sed 's/:null$//' | grep --color=never -E '^\[' | sort)
if [ -z "$ip6peers" ]; then
echo "none"
else
echo "$ip6peers"
fi
printf "\\n"
printf "Onion Peers:\\n"
onionpeers=$(echo $mainnetpeers | jq -r '.[].addr' | awk -F ':' '$1 ~ /\.onion$/ {print $0}' | sort)
if [ -z "$onionpeers" ]; then
echo "none"
else
echo "$onionpeers"
fi
printf "\\n"
exit
else
printf "%b %bERROR: DigiByte $DGB_NETWORK_CURRENT Node is not running.%b\\n" "${INFO}" "${COL_LIGHT_RED}" "${COL_NC}"
printf "\\n"
exit 1
fi
elif [ $DGB2PEERS = true ]; then # --dgb2peers
diginode_tools_import_settings silent
if check_service_active "digibyted-testnet"; then
printf "DigiByte TESTNET Node Peers:\\n\\n"
printf "IP4 Peers:\\n"
#store peers
testnetpeers=$($DGB_CLI -testnet getpeerinfo)
ip4peers=$(echo $testnetpeers | jq -r '.[] | {ip: .addr} | select(.ip | test("^[0-9]+\\.") and (test("\\.onion$") | not)) | .ip' | sort)
if [ -z "$ip4peers" ]; then
echo "none"
else
echo "$ip4peers"
fi
printf "\\n"
printf "IP6 Peers:\\n"
ip6peers=$(echo $testnetpeers | jq -r '.[] | {ip: .addr, port: .port} | "\(.ip):\(.port)"' | sed 's/:null$//' | grep --color=never -E '^\[' | sort)
if [ -z "$ip6peers" ]; then
echo "none"
else
echo "$ip6peers"
fi
printf "\\n"
printf "Onion Peers:\\n"
onionpeers=$(echo $testnetpeers | jq -r '.[].addr' | awk -F ':' '$1 ~ /\.onion$/ {print $0}' | sort)
if [ -z "$onionpeers" ]; then
echo "none"
else
echo "$onionpeers"
fi
printf "\\n"
exit
else
printf "%b %bERROR: DigiByte TESTNET Node is not running.%b\\n" "${INFO}" "${COL_LIGHT_RED}" "${COL_NC}"
printf "\\n"
exit 1
fi
elif [ $VIEW_RPC_CREDENTIALS = true ]; then # --rpc
diginode_tools_import_settings silent
scrape_digibyte_conf
query_digibyte_chain
query_digibyte_rpc
printf "DigiByte Core RPC Credentials:\\n\\n"
printf " RPC User: $RPC_USER\\n\\n"
printf " RPC Password: $RPC_PASSWORD\\n\\n"
if [ "$DGB_DUAL_NODE" = "YES" ]; then
printf " RPC Ports: $RPC_PORT (%s) $RPC2_PORT (Testnet)\\n\\n" "$(echo "${DGB_NETWORK_CURRENT,,}" | sed 's/./\U&/1')"
else
printf " RPC Ports: $RPC_PORT (%s)\\n\\n" "$(echo "${DGB_NETWORK_CURRENT,,}" | sed 's/./\U&/1')"
fi
exit
elif [ $REENABLE_PORT_TEST = true ]; then # --porttest
diginode_tools_import_settings silent
printf "%b Re-enabling DigiByte Core MAINNET Port Test...\n" "${INFO}"
DGB_MAINNET_PORT_TEST_ENABLED="YES"
sed -i -e "/^DGB_MAINNET_PORT_TEST_ENABLED=/s|.*|DGB_MAINNET_PORT_TEST_ENABLED=\"$DGB_MAINNET_PORT_TEST_ENABLED\"|" $DGNT_SETTINGS_FILE
DGB_MAINNET_PORT_FWD_STATUS=""
sed -i -e "/^DGB_MAINNET_PORT_FWD_STATUS=/s|.*|DGB_MAINNET_PORT_FWD_STATUS=\"$DGB_MAINNET_PORT_FWD_STATUS\"|" $DGNT_SETTINGS_FILE
DGB_MAINNET_PORT_TEST_PASS_DATE=""
sed -i -e "/^DGB_MAINNET_PORT_TEST_PASS_DATE=/s|.*|DGB_MAINNET_PORT_TEST_PASS_DATE=\"$DGB_MAINNET_PORT_TEST_PASS_DATE\"|" $DGNT_SETTINGS_FILE
DGB_MAINNET_PORT_TEST_EXTERNAL_IP=""
sed -i -e "/^DGB_MAINNET_PORT_TEST_EXTERNAL_IP=/s|.*|DGB_MAINNET_PORT_TEST_EXTERNAL_IP=\"$DGB_MAINNET_PORT_TEST_EXTERNAL_IP\"|" $DGNT_SETTINGS_FILE
DGB_MAINNET_PORT_NUMBER_SAVED=""
sed -i -e "/^DGB_MAINNET_PORT_NUMBER_SAVED=/s|.*|DGB_MAINNET_PORT_NUMBER_SAVED=\"$DGB_MAINNET_PORT_NUMBER_SAVED\"|" $DGNT_SETTINGS_FILE
printf "%b Re-enabling DigiByte Core TESTNET Port Test...\n" "${INFO}"
DGB_TESTNET_PORT_TEST_ENABLED="YES"
sed -i -e "/^DGB_TESTNET_PORT_TEST_ENABLED=/s|.*|DGB_TESTNET_PORT_TEST_ENABLED=\"$DGB_TESTNET_PORT_TEST_ENABLED\"|" $DGNT_SETTINGS_FILE
DGB_TESTNET_PORT_FWD_STATUS=""
sed -i -e "/^DGB_TESTNET_PORT_FWD_STATUS=/s|.*|DGB_TESTNET_PORT_FWD_STATUS=\"$DGB_TESTNET_PORT_FWD_STATUS\"|" $DGNT_SETTINGS_FILE
DGB_TESTNET_PORT_TEST_PASS_DATE=""
sed -i -e "/^DGB_TESTNET_PORT_TEST_PASS_DATE=/s|.*|DGB_TESTNET_PORT_TEST_PASS_DATE=\"$DGB_TESTNET_PORT_TEST_PASS_DATE\"|" $DGNT_SETTINGS_FILE
DGB_TESTNET_PORT_TEST_EXTERNAL_IP=""
sed -i -e "/^DGB_TESTNET_PORT_TEST_EXTERNAL_IP=/s|.*|DGB_TESTNET_PORT_TEST_EXTERNAL_IP=\"$DGB_TESTNET_PORT_TEST_EXTERNAL_IP\"|" $DGNT_SETTINGS_FILE
DGB_TESTNET_PORT_NUMBER_SAVED=""
sed -i -e "/^DGB_TESTNET_PORT_NUMBER_SAVED=/s|.*|DGB_TESTNET_PORT_NUMBER_SAVED=\"$DGB_TESTNET_PORT_NUMBER_SAVED\"|" $DGNT_SETTINGS_FILE
printf "%b Re-enabling IPFS Port Test...\n" "${INFO}"
IPFS_PORT_TEST_ENABLED="YES"
sed -i -e "/^IPFS_PORT_TEST_ENABLED=/s|.*|IPFS_PORT_TEST_ENABLED=\"$IPFS_PORT_TEST_ENABLED\"|" $DGNT_SETTINGS_FILE
IPFS_PORT_FWD_STATUS=""
sed -i -e "/^IPFS_PORT_FWD_STATUS=/s|.*|IPFS_PORT_FWD_STATUS=\"$IPFS_PORT_FWD_STATUS\"|" $DGNT_SETTINGS_FILE
IPFS_PORT_TEST_PASS_DATE=""
sed -i -e "/^IPFS_PORT_TEST_PASS_DATE=/s|.*|IPFS_PORT_TEST_PASS_DATE=\"$IPFS_PORT_TEST_PASS_DATE\"|" $DGNT_SETTINGS_FILE
IPFS_PORT_TEST_EXTERNAL_IP=""
sed -i -e "/^IPFS_PORT_TEST_EXTERNAL_IP=/s|.*|IPFS_PORT_TEST_EXTERNAL_IP=\"$IPFS_PORT_TEST_EXTERNAL_IP\"|" $DGNT_SETTINGS_FILE
IPFS_PORT_NUMBER_SAVED=""
sed -i -e "/^IPFS_PORT_NUMBER_SAVED=/s|.*|IPFS_PORT_NUMBER_SAVED=\"$IPFS_PORT_NUMBER_SAVED\"|" $DGNT_SETTINGS_FILE
sleep 2
fi
fi
}
# Display DigiNode Setup help screen if the --help or -h flags was used
display_help() {
if [ "$DISPLAY_HELP" = true ]; then
echo ""
get_script_location # Find which folder this script is running in (in case this is an unnoficial DigiNode)
import_setup_functions # Import diginode-setup.sh file because it contains functions we need
diginode_tools_import_settings silent
query_digibyte_chain
# Is Dual Node detected?
if [ -f "$DGB2_SYSTEMD_SERVICE_FILE" ] || [ -f "$DGB2_UPSTART_SERVICE_FILE" ]; then
DGB_DUAL_NODE="YES"
else
DGB_DUAL_NODE="NO"
fi
echo ""
echo " ╔════════════════════════════════════════════════════════╗"
echo " ║ ║"
echo " ║ ${txtbld}D I G I N O D E C L I${txtrst} $DGNT_VER_LOCAL_FW ║"
echo " ║ ║"
echo " ║ Manage your DigiNode from the Command Line ║"
echo " ║ ║"
echo " ╚════════════════════════════════════════════════════════╝"
echo ""
printf "%b%b--help%b or %b-h%b - Display this help screen.\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}" "${COL_BOLD_WHITE}" "${COL_NC}"
printf "%b%b--verbose%b - Enable verbose mode in DigiNode Dashboard.\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}"
printf "\\n"
if [ "$DGB_DUAL_NODE" = "YES" ]; then
printf "%b%b--dgbrestart%b - Restart primary DigiByte Node ($DGB_NETWORK_CURRENT).\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}"
printf "%b%b--dgbstop%b - Stop primary DigiByte Node ($DGB_NETWORK_CURRENT).\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}"
printf "%b%b--dgbpeers%b - List peers for primary DigiByte Node ($DGB_NETWORK_CURRENT).\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}"
else
printf "%b%b--dgbrestart%b - Restart DigiByte Node ($DGB_NETWORK_CURRENT).\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}"
printf "%b%b--dgbstop%b - Stop DigiByte Node ($DGB_NETWORK_CURRENT).\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}"
printf "%b%b--dgbpeers%b - List peers for DigiByte Node ($DGB_NETWORK_CURRENT).\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}"
fi
if [ "$DGB_DUAL_NODE" = "YES" ]; then
printf "%b%b--dgb2restart%b - Restart secondary DigiByte Node (TESTNET).\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}"
printf "%b%b--dgb2stop%b - Stop secondary DigiByte Node (TESTNET).\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}"
printf "%b%b--dgb2peers%b - List peers for secondary DigiByte Node (TESTNET).\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}"
fi
printf "\\n"
printf "%b%b--listwallets%b - View currently loaded DigiByte wallets.\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}"
# printf "%b%b--loadwallet%b - Load DigiByte wallet.\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}"
printf "\\n"
printf "%b%b--dgbconf%b - Edit digibyte.conf file.\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}"
printf "%b%b--settings%b - Edit diginode.settings file.\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}"
printf "%b%b--rpc%b - View DigiByte Core RPC credentials.\\n" "${INDENT}" "${COL_BOLD_WHITE}" "${COL_NC}"