-
Notifications
You must be signed in to change notification settings - Fork 174
/
cntools.sh
executable file
·2357 lines (2064 loc) · 100 KB
/
cntools.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
# shellcheck disable=SC1090,SC2086,SC2154,SC2034
########## Global tasks ###########################################
# get common env variables
. "$(dirname $0)"/env
# get cntools config parameters
. "$(dirname $0)"/cntools.config
# get helper functions from library file
. "$(dirname $0)"/cntools.library
# create temporary directory if missing
mkdir -p "${TMP_FOLDER}" # Create if missing
if [[ ! -d "${TMP_FOLDER}" ]]; then
echo ""
say "${RED}ERROR${NC}: Failed to create directory for temporary files:"
say "${TMP_FOLDER}"
echo ""
exit 1
fi
# Get protocol parameters and save to ${TMP_FOLDER}/protparams.json
${CCLI} shelley query protocol-parameters --testnet-magic ${NWMAGIC} --out-file ${TMP_FOLDER}/protparams.json || {
say "\n"
say "${ORANGE}WARN${NC}: failed to query protocol parameters, node running and env parameters correct?"
say "\n${BLUE}Press c to continue or any other key to quit${NC}"
say "only offline functions will be available if you continue\n"
read -r -n 1 -s -p "" answer
[[ "${answer}" != "c" ]] && exit 1
}
# check for required command line tools
if ! need_cmd "curl" || \
! need_cmd "jq" || \
! need_cmd "bc" || \
! need_cmd "sed" || \
! need_cmd "awk" || \
! need_cmd "numfmt"; then exit 1
fi
###################################################################
function main {
while true; do # Main loop
# Start with a clean slate after each completed or canceled command excluding protparams.json from purge
find "${TMP_FOLDER:?}" -type f -not -name 'protparams.json' -delete
clear
say "$(printf "%-52s %s" " >> CNTools $CNTOOLS_VERSION << " "A Guild Operators collaboration")" "log"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo " Main Menu"
echo ""
echo " ) Wallet - create, show, remove and protect wallets"
echo " ) Funds - send, withdraw and delegate"
echo " ) Pool - pool creation and management"
echo " ) Blocks - show core node leader slots"
echo " ) Update - update cntools script and library config files"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
say " What would you like to do?\n"
case $(select_opt "[w] Wallet" "[f] Funds" "[p] Pool" "[b] Blocks" "[u] Update" "[q] Quit") in
0) OPERATION="wallet" ;;
1) OPERATION="funds" ;;
2) OPERATION="pool" ;;
3) OPERATION="blocks" ;;
4) OPERATION="update" ;;
5) clear && exit ;;
esac
case $OPERATION in
wallet)
clear
say " >> WALLET" "log"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo " Wallet Management"
echo ""
echo " ) New - create a new wallet"
echo " ) List - list all available wallets in a compact view"
echo " ) Show - show detailed view of a specific wallet"
echo " ) Remove - remove a wallet"
echo " ) Decrypt - remove write protection and decrypt wallet"
echo " ) Encrypt - encrypt wallet keys and make all files immutable"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
say " Select wallet operation\n"
case $(select_opt "[n] New" "[l] List" "[s] Show" "[r] Remove" "[d] Decrypt" "[e] Encrypt" "[h] Home") in
0) SUBCOMMAND="new" ;;
1) SUBCOMMAND="list" ;;
2) SUBCOMMAND="show" ;;
3) SUBCOMMAND="remove" ;;
4) SUBCOMMAND="decrypt" ;;
5) SUBCOMMAND="encrypt" ;;
6) continue ;;
esac
case $SUBCOMMAND in
new)
clear
say " >> WALLET >> NEW" "log"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo ""
read -r -p "Name of new wallet: " wallet_name
# Remove unwanted characters from wallet name
wallet_name=${wallet_name//[^[:alnum:]]/_}
if [[ -z "${wallet_name}" ]]; then
say "${RED}ERROR${NC}: Empty wallet name, please retry!"
waitForInput && continue
fi
echo ""
mkdir -p "${WALLET_FOLDER}/${wallet_name}"
# Wallet key filenames
payment_sk_file="${WALLET_FOLDER}/${wallet_name}/${WALLET_PAY_SK_FILENAME}"
payment_vk_file="${WALLET_FOLDER}/${wallet_name}/${WALLET_PAY_VK_FILENAME}"
stake_vk_file="${WALLET_FOLDER}/${wallet_name}/${WALLET_STAKE_VK_FILENAME}"
stake_sk_file="${WALLET_FOLDER}/${wallet_name}/${WALLET_STAKE_SK_FILENAME}"
if [[ $(find "${WALLET_FOLDER}/${wallet_name}" -type f -printf '.' | wc -c) -gt 0 ]]; then
say "${RED}WARN${NC}: A wallet ${GREEN}$wallet_name${NC} already exists"
say " Choose another name or delete the existing one"
waitForInput && continue
fi
${CCLI} shelley address key-gen --verification-key-file "${payment_vk_file}" --signing-key-file "${payment_sk_file}"
${CCLI} shelley stake-address key-gen --verification-key-file "${stake_vk_file}" --signing-key-file "${stake_sk_file}"
getAddress ${wallet_name}
say "New Wallet : ${GREEN}${wallet_name}${NC}" "log"
say "Address : ${base_addr}" "log"
say "\nYou can now send and receive ADA using this address."
say "Wallet will be automatically registered on chain if you\nchoose to delegate or pledge wallet when registering a stake pool."
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
waitForInput && continue
;; ###################################################################
list)
clear
say " >> WALLET >> LIST" "log"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
if [[ ! -f "${TMP_FOLDER}"/protparams.json ]]; then
say "${RED}ERROR${NC}: CNTools started without node access, only offline functions available!"
waitForInput && continue
fi
while IFS= read -r -d '' wallet; do
wallet_name=$(basename ${wallet})
enc_files=$(find "${wallet}" -mindepth 1 -maxdepth 1 -type f -name '*.gpg' -printf '.' | wc -c)
if getAddress ${wallet_name} || [[ ${enc_files} -gt 0 ]]; then
echo ""
if [[ ${enc_files} -gt 0 ]]; then
say "${GREEN}${wallet_name}${NC} (${ORANGE}encrypted${NC})" "log"
base_addr=$(cat "${wallet}/${WALLET_BASE_ADDR_FILENAME}")
else
say "${GREEN}${wallet_name}${NC}" "log"
fi
getBalance ${base_addr}
say "$(printf "%s\t${CYAN}%s${NC} ADA" "Funds" "$(numfmt --grouping ${base_ada})")" "log"
getRewards ${wallet_name}
if [[ "${reward_lovelace}" -eq -1 ]]; then
say "${ORANGE}Not a registered wallet on chain${NC}"
continue
fi
say "$(printf "%s\t${CYAN}%s${NC} ADA" "Rewards" "$(numfmt --grouping ${reward_ada})")" "log"
delegation_pool_id=$(jq -r '.delegation // empty' <<< "${stakeAddressInfo}")
if [[ -n ${delegation_pool_id} ]]; then
unset poolName
while IFS= read -r -d '' pool; do
pool_id=$(cat "${pool}/${POOL_ID_FILENAME}")
if [[ "${pool_id}" = "${delegation_pool_id}" ]]; then
poolName=$(basename ${pool}) && break
fi
done < <(find "${POOL_FOLDER}" -mindepth 1 -maxdepth 1 -type d -print0 | sort -z)
say "${RED}Delegated to${NC} ${BLUE}${poolName}${NC} ${RED}(${delegation_pool_id})${NC}" "log"
fi
fi
done < <(find "${WALLET_FOLDER}" -mindepth 1 -maxdepth 1 -type d -print0 | sort -z)
echo ""
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
waitForInput
;; ###################################################################
show)
clear
say " >> WALLET >> SHOW" "log"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo ""
if [[ ! -f ${TMP_FOLDER}/protparams.json ]]; then
say "${RED}ERROR${NC}: CNTools started without node access, only offline functions available!"
waitForInput && continue
fi
wallet_dirs=()
if ! getDirs "${WALLET_FOLDER}"; then continue; fi # dirs() array populated with all wallet folders
for dir in "${dirs[@]}"; do
enc_files=$(find "${WALLET_FOLDER}/${dir}" -mindepth 1 -maxdepth 1 -type f -name '*.gpg' -printf '.' | wc -c)
if ! getAddress "${dir}" && [[ ${enc_files} -eq 0 ]]; then continue; fi
wallet_dirs+=("${dir}")
done
if [[ ${#wallet_dirs[@]} -eq 0 ]]; then
say "${ORANGE}WARN${NC}: No wallets available!"
say "first create a wallet"
waitForInput && continue
fi
say "Select Wallet:\n"
if ! selectDir "${wallet_dirs[@]}"; then continue; fi # ${dir_name} populated by selectDir function
wallet_name=${dir_name}
enc_files=$(find "${WALLET_FOLDER}/${wallet_name}" -mindepth 1 -maxdepth 1 -type f -name '*.gpg' -printf '.' | wc -c)
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo ""
if [[ ${enc_files} -gt 0 ]]; then
base_addr=$(cat "${WALLET_FOLDER}/${wallet_name}/${WALLET_BASE_ADDR_FILENAME}")
say "$(printf "%-8s ${GREEN}%s${NC} ${ORANGE}%s${NC}" "Wallet" "${wallet_name}" "(encrypted)")" "log"
else
getAddress ${wallet_name}
say "$(printf "%-8s ${GREEN}%s${NC}" "Wallet" "${wallet_name}")" "log"
fi
getBalance ${base_addr}
if [[ -s ${TMP_FOLDER}/balance.out ]]; then
echo ""
say "${BLUE}UTxOs${NC}"
head -n 2 ${TMP_FOLDER}/fullUtxo.out
head -n 10 ${TMP_FOLDER}/balance.out
[[ ${utx0_count} -gt 10 ]] && say "... (top 10 UTx0 with most lovelace)"
fi
echo ""
say "$(printf "%-8s : %s" "Address" "${base_addr}")" "log"
say "$(printf "%-8s : ${CYAN}%s${NC} ADA" "Funds" "$(numfmt --grouping ${base_ada})")" "log"
getRewards ${wallet_name}
if [[ "${reward_lovelace}" -eq -1 ]]; then
echo ""
say "${ORANGE}Not a registered wallet on chain${NC}"
else
say "$(printf "%-8s : ${CYAN}%s${NC} ADA" "Rewards" "$(numfmt --grouping ${reward_ada})")" "log"
delegation_pool_id=$(jq -r '.delegation // empty' <<< "${stakeAddressInfo}")
if [[ -n ${delegation_pool_id} ]]; then
unset poolName
while IFS= read -r -d '' pool; do
pool_id=$(cat "${pool}/${POOL_ID_FILENAME}")
if [[ "${pool_id}" = "${delegation_pool_id}" ]]; then
poolName=$(basename ${pool}) && break
fi
done < <(find "${POOL_FOLDER}" -mindepth 1 -maxdepth 1 -type d -print0 | sort -z)
echo ""
say "${RED}Delegated to${NC} ${BLUE}${poolName}${NC} ${RED}(${delegation_pool_id})${NC}" "log"
fi
fi
echo ""
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
waitForInput
;; ###################################################################
remove)
clear
say " >> WALLET >> REMOVE" "log"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo ""
if [[ ! -f ${TMP_FOLDER}/protparams.json ]]; then
say "${RED}ERROR${NC}: CNTools started without node access, only offline functions available!"
waitForInput && continue
fi
if ! getDirs "${WALLET_FOLDER}"; then continue; fi # dirs() array populated with all wallet folders
if [[ ${#dirs[@]} -eq 0 ]]; then
say "${ORANGE}WARN${NC}: No wallets available!"
waitForInput && continue
fi
say "Select Wallet:\n"
if ! selectDir "${dirs[@]}"; then continue; fi # ${dir_name} populated by selectDir function
wallet_name="${dir_name}"
if ! getAddress ${wallet_name}; then
say "${RED}WARN${NC}: unable to get address for wallet and do a balance check"
say "\nAre you sure to delete wallet anyway?\n"
case $(select_opt "[y] Yes" "[n] No") in
0) rm -rf "${WALLET_FOLDER:?}/${wallet_name}"
echo "" && say "removed ${GREEN}${wallet_name}${NC}" "log"
;;
1) say "skipped removal process for ${GREEN}$wallet_name${NC}"
;;
esac
waitForInput && continue
fi
getBalance ${base_addr}
getRewards ${wallet_name}
if [[ ${base_lovelace} -eq 0 && ${reward_lovelace} -le 0 ]]; then
say "INFO: This wallet appears to be empty"
say "${RED}WARN${NC}: Deleting this wallet is final and you can not recover it unless you have a backup\n"
say "Are you sure to delete wallet?\n"
case $(select_opt "[y] Yes" "[n] No") in
0) rm -rf "${WALLET_FOLDER:?}/${wallet_name}"
echo "" && say "removed ${GREEN}${wallet_name}${NC}" "log"
;;
1) say "skipped removal process for ${GREEN}$wallet_name${NC}"
;;
esac
else
say "${RED}WARN${NC}: wallet not empty!"
if [[ ${base_lovelace} -gt 0 ]]; then
say "Funds: ${CYAN}$(numfmt --grouping ${base_ada})${NC} ADA"
fi
if [[ ${reward_lovelace} -gt 0 ]]; then
say "Rewards: ${CYAN}$(numfmt --grouping ${reward_ada})${NC} ADA"
fi
echo ""
say "${RED}WARN${NC}: Deleting this wallet is final and you can not recover it unless you have a backup\n"
say "Are you sure to delete wallet?\n"
case $(select_opt "[y] Yes" "[n] No") in
0) rm -rf "${WALLET_FOLDER:?}/${wallet_name}"
echo "" && say "removed ${GREEN}${wallet_name}${NC}" "log"
;;
1) say "skipped removal process for ${GREEN}$wallet_name${NC}"
;;
esac
fi
waitForInput
;; ###################################################################
decrypt)
clear
say " >> WALLET >> DECRYPT" "log"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo ""
protectionPreRequisites || continue
if ! getDirs "${WALLET_FOLDER}"; then continue; fi # dirs() array populated with all wallet folders
if [[ ${#dirs[@]} -eq 0 ]]; then
say "${ORANGE}WARN${NC}: No wallets available!"
say "first create a wallet"
waitForInput && continue
fi
say "Select Wallet:\n"
if ! selectDir "${dirs[@]}"; then continue; fi # ${dir_name} populated by selectDir function
wallet_name="${dir_name}"
filesUnlocked=0
keysDecrypted=0
say " -- Removing write protection from all wallet files --" "log"
while IFS= read -r -d '' file; do
if [[ $(lsattr -R "$file") =~ -i- ]]; then
sudo chattr -i "${file}" && \
chmod 600 "${file}" && \
filesUnlocked=$((++filesUnlocked))
say "${file}"
fi
done < <(find "${WALLET_FOLDER}/${wallet_name}" -mindepth 1 -maxdepth 1 -type f -print0)
echo ""
say " -- Decrypting GPG encrypted wallet files --" "log"
echo ""
say "Wallet ${GREEN}${wallet_name}${NC} Password"
echo ""
if ! getPassword; then # $password variable populated by getPassword function
echo -e "\n\n" && say "${RED}ERROR${NC}: password input aborted!"
waitForInput && continue
fi
while IFS= read -r -d '' file; do
decryptFile "${file}" "${password}" && \
chmod 600 "${file::-4}" && \
keysDecrypted=$((++keysDecrypted))
done < <(find "${WALLET_FOLDER}/${wallet_name}" -mindepth 1 -maxdepth 1 -type f -name '*.gpg' -print0)
unset password
echo ""
say "Wallet unprotected: ${GREEN}${wallet_name}${NC}" "log"
say "Files unlocked: ${filesUnlocked}" "log"
say "Files decrypted: ${keysDecrypted}" "log"
if [[ ${filesUnlocked} -ne 0 || ${keysDecrypted} -ne 0 ]]; then
echo ""
say "${ORANGE}Wallet files are now unprotected${NC}"
say "Use 'WALLET >> ENCRYPT' to re-lock"
fi
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
waitForInput
;; ###################################################################
encrypt)
clear
say " >> WALLET >> ENCRYPT" "log"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo ""
protectionPreRequisites || continue
if ! getDirs "${WALLET_FOLDER}"; then continue; fi # dirs() array populated with all wallet folders
if [[ ${#dirs[@]} -eq 0 ]]; then
say "${ORANGE}WARN${NC}: No wallets available!"
say "first create a wallet"
waitForInput && continue
fi
say "Select Wallet:\n"
if ! selectDir "${dirs[@]}"; then continue; fi # ${dir_name} populated by selectDir function
wallet_name="${dir_name}"
filesLocked=0
keysEncrypted=0
say " -- Encrypting sensitive wallet keys with GPG --" "log"
echo ""
say "Wallet ${GREEN}${wallet_name}${NC} Password"
echo ""
if ! getPassword confirm; then # $password variable populated by getPassword function
echo -e "\n\n" && say "${RED}ERROR${NC}: password input aborted!"
waitForInput && continue
fi
keyFiles=(
"${WALLET_FOLDER}/${wallet_name}/${WALLET_PAY_VK_FILENAME}"
"${WALLET_FOLDER}/${wallet_name}/${WALLET_PAY_SK_FILENAME}"
"${WALLET_FOLDER}/${wallet_name}/${WALLET_STAKE_VK_FILENAME}"
"${WALLET_FOLDER}/${wallet_name}/${WALLET_STAKE_SK_FILENAME}"
"${WALLET_FOLDER}/${wallet_name}/${WALLET_STAKE_CERT_FILENAME}"
)
for keyFile in "${keyFiles[@]}"; do
if [[ -f "${keyFile}" ]]; then
chmod 400 "${keyFile}" && \
encryptFile "${keyFile}" "${password}" && \
keysEncrypted=$((++keysEncrypted))
fi
done
unset password
echo ""
say " -- Write protecting all wallet files using 'chattr +i' --" "log"
while IFS= read -r -d '' file; do
if [[ ! $(lsattr -R "$file") =~ -i- ]]; then
chmod 400 "${file}" && \
sudo chattr +i "${file}" && \
filesLocked=$((++filesLocked)) && \
say "${file}"
fi
done < <(find "${WALLET_FOLDER}/${wallet_name}" -mindepth 1 -maxdepth 1 -type f -print0)
echo ""
say "Wallet protected: ${GREEN}${wallet_name}${NC}" "log"
say "Files locked: ${filesLocked}" "log"
say "Files encrypted: ${keysEncrypted}" "log"
if [[ ${filesLocked} -ne 0 || ${keysEncrypted} -ne 0 ]]; then
echo ""
say "${BLUE}Wallet files are now protected${NC}"
say "Use 'WALLET >> DECRYPT' to unlock"
fi
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
waitForInput
;; ###################################################################
esac
;; ###################################################################
funds)
clear
say " >> FUNDS" "log"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo " Handle Funds"
echo ""
echo " 1) Send - send ADA from a local wallet to an address or a wallet"
echo " 2) Delegate - delegate stake wallet to a pool"
echo " 3) Withdraw - withdraw earned rewards to base address"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
say " Select funds operation\n"
case $(select_opt "[s] Send" "[d] Delegate" "[w] Withdraw Rewards" "[h] Home") in
0) SUBCOMMAND="send" ;;
1) SUBCOMMAND="delegate" ;;
2) SUBCOMMAND="withdrawrewards" ;;
3) continue ;;
esac
case $SUBCOMMAND in
withdrawrewards)
clear
say " >> FUNDS >> WITHDRAW REWARDS" "log"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo ""
if [[ ! -f ${TMP_FOLDER}/protparams.json ]]; then
say "${RED}ERROR${NC}: CNTools started without node access, only offline functions available!"
waitForInput && continue
fi
wallet_dirs=()
if ! getDirs "${WALLET_FOLDER}"; then continue; fi # dirs() array populated with all wallet folders
wallet_count=${#dirs[@]}
for dir in "${dirs[@]}"; do
base_addr_file="${WALLET_FOLDER}/${dir}/${WALLET_BASE_ADDR_FILENAME}"
stake_addr_file="${WALLET_FOLDER}/${dir}/${WALLET_STAKE_ADDR_FILENAME}"
stake_sk_file="${WALLET_FOLDER}/${dir}/${WALLET_STAKE_SK_FILENAME}"
stake_vk_file="${WALLET_FOLDER}/${dir}/${WALLET_STAKE_VK_FILENAME}"
pay_payment_sk_file="${WALLET_FOLDER}/${dir}/${WALLET_PAY_SK_FILENAME}"
[[ ! -f "${base_addr_file}" || ! -f "${stake_addr_file}" || ! -f "${stake_sk_file}" || ! -f "${stake_vk_file}" || ! -f "${pay_payment_sk_file}" ]] && continue
if [[ ${wallet_count} -le ${WALLET_SELECTION_FILTER_LIMIT} ]]; then
getRewards ${dir}
[[ ${reward_lovelace} -le 0 ]] && continue
reward_ada=$(lovelacetoADA ${reward_lovelace})
wallet_dirs+=("${dir} (Rewards: ${CYAN}$(numfmt --grouping ${reward_ada})${NC} ADA)")
else
wallet_dirs+=("${dir}")
fi
done
if [[ ${#wallet_dirs[@]} -eq 0 ]]; then
say "${ORANGE}WARN${NC}: No wallets available that have rewards to withdraw!"
waitForInput && continue
fi
say "Select Wallet:\n"
if ! selectDir "${wallet_dirs[@]}"; then continue; fi # ${dir_name} populated by selectDir function
wallet_name="$(echo ${dir_name} | cut -d' ' -f1)"
getAddress ${wallet_name}
stake_addr_file="${WALLET_FOLDER}/${wallet_name}/${WALLET_STAKE_ADDR_FILENAME}"
stake_sk_file="${WALLET_FOLDER}/${wallet_name}/${WALLET_STAKE_SK_FILENAME}"
stake_vk_file="${WALLET_FOLDER}/${wallet_name}/${WALLET_STAKE_VK_FILENAME}"
pay_payment_sk_file="${WALLET_FOLDER}/${wallet_name}/${WALLET_PAY_SK_FILENAME}"
getBalance ${base_addr}
getRewards ${wallet_name}
if [[ ${reward_lovelace} -le 0 ]]; then
echo "Failed to locate any rewards associated with the chosen wallet, please try another one"
waitForInput && continue
fi
say "$(printf "%s\t${CYAN}%s${NC} ADA" "Funds" "$(numfmt --grouping ${base_ada})")" "log"
say "$(printf "%s\t${CYAN}%s${NC} ADA" "Rewards" "$(numfmt --grouping ${reward_ada})")" "log"
if ! withdrawRewards "${stake_vk_file}" "${stake_sk_file}" "${pay_payment_sk_file}" "${base_addr}" "${reward_addr}" ${reward_lovelace}; then
echo "" && say "${RED}ERROR${NC}: failure during withdrawal of rewards"
waitForInput && continue
fi
if ! waitNewBlockCreated; then
waitForInput && continue
fi
getBalance ${base_addr}
while [[ ${base_lovelace} -ne ${newBalance} ]]; do
echo ""
say "${ORANGE}WARN${NC}: Balance mismatch, transaction not included in latest block ($(numfmt --grouping ${base_lovelace}) != $(numfmt --grouping ${newBalance}))"
if ! waitNewBlockCreated; then
break
fi
getBalance ${base_addr}
done
if [[ ${base_lovelace} -ne ${newBalance} ]]; then
waitForInput && continue
fi
getRewards ${wallet_name}
echo ""
say "$(printf "%s\t${CYAN}%s${NC} ADA" "Funds" "$(numfmt --grouping ${base_ada})")" "log"
say "$(printf "%s\t${CYAN}%s${NC} ADA" "Rewards" "$(numfmt --grouping ${reward_ada})")" "log"
waitForInput
;; ###################################################################
send)
clear
say " >> FUNDS >> SEND" "log"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo ""
if [[ ! -f ${TMP_FOLDER}/protparams.json ]]; then
say "${RED}ERROR${NC}: CNTools started without node access, only offline functions available!"
waitForInput && continue
fi
say " -- Source Wallet --"
echo ""
s_wallet_dirs=()
if ! getDirs "${WALLET_FOLDER}"; then continue; fi # dirs() array populated with all wallet folders
wallet_count=${#dirs[@]}
for dir in "${dirs[@]}"; do
s_base_addr_file="${WALLET_FOLDER}/${dir}/${WALLET_BASE_ADDR_FILENAME}"
s_payment_sk_file="${WALLET_FOLDER}/${dir}/${WALLET_PAY_SK_FILENAME}"
[[ ! -f "${s_base_addr_file}" || ! -f "${s_payment_sk_file}" ]] && continue
if [[ ${wallet_count} -le ${WALLET_SELECTION_FILTER_LIMIT} ]]; then
if getAddress ${dir}; then
getBalance ${base_addr}
[[ ${base_lovelace} -eq 0 ]] && continue
s_wallet_dirs+=("${dir} (${CYAN}$(numfmt --grouping ${base_ada})${NC} ADA)")
fi
else
s_wallet_dirs+=("${dir}")
fi
done
if [[ ${#s_wallet_dirs[@]} -eq 0 ]]; then
say "${ORANGE}WARN${NC}: No wallets available that have funds to send!"
waitForInput && continue
fi
say "Select Source Wallet:\n"
if ! selectDir "${s_wallet_dirs[@]}"; then continue; fi # ${dir_name} populated by selectDir function
s_wallet="$(echo ${dir_name} | cut -d' ' -f1)"
s_addr="$(cat ${WALLET_FOLDER}/${s_wallet}/${WALLET_BASE_ADDR_FILENAME})"
s_payment_sk_file="${WALLET_FOLDER}/${s_wallet}/${WALLET_PAY_SK_FILENAME}"
getBalance ${s_addr}
if [[ ${base_lovelace} -gt 0 ]]; then
say "$(printf "%s\t${CYAN}%s${NC} ADA" "Funds in source wallet:" "$(numfmt --grouping ${base_ada})")" "log"
else
say "${RED}ERROR${NC}: no funds available for wallet ${GREEN}${wallet_name}${NC}"
waitForInput && continue
fi
# Amount
echo ""
say " -- Amount to Send (in ADA) --"
echo ""
say "Valid entry: ${BLUE}Integer (e.g. 15) or Decimal (e.g. 956.1235) - no commas allowed${NC}"
say " The string '${BLUE}all${NC}' to send all available funds in source wallet"
echo ""
say "Info: If destination and source wallet is the same and amount set to 'all',"
say " wallet will be defraged, ie converts multiple UTxO's to one"
echo ""
read -r -p "Amount (ADA): " amountADA
if [[ "${amountADA}" != "all" ]]; then
if ! ADAtoLovelace "${amountADA}" >/dev/null; then
waitForInput && continue
fi
amountLovelace=$(ADAtoLovelace "${amountADA}")
echo ""
say " -- Transaction Fee --"
echo ""
say "Fee payed by sender? [else amount sent is reduced]\n"
case $(select_opt "[y] Yes" "[n] No" "[c] Cancel") in
0) include_fee="no" ;;
1) include_fee="yes" ;;
2) continue ;;
esac
else
echo ""
amountADA=${base_ada}
amountLovelace=${base_lovelace}
say "ADA to send set to total supply: $(numfmt --grouping ${amountADA})" "log"
echo ""
include_fee="yes"
fi
# Destination
say " -- Destination Address / Wallet --"
echo ""
d_wallet=""
say "Is destination a local wallet or an address?\n"
case $(select_opt "[w] Wallet" "[a] Address" "[c] Cancel") in
0) d_wallet_dirs=()
if ! getDirs "${WALLET_FOLDER}"; then continue; fi # dirs() array populated with all wallet folders
for dir in "${dirs[@]}"; do
d_base_addr_file="${WALLET_FOLDER}/${dir}/${WALLET_BASE_ADDR_FILENAME}"
[[ ! -f ${d_base_addr_file} ]] && continue
d_wallet_dirs+=("${dir}")
done
say "Select Destination Wallet:\n"
if ! selectDir "${d_wallet_dirs[@]}"; then continue; fi # ${dir_name} populated by selectDir function
d_wallet="${dir_name}"
d_addr="$(cat ${WALLET_FOLDER}/${d_wallet}/${WALLET_BASE_ADDR_FILENAME})"
;;
1) echo "" && read -r -p "Address: " d_addr ;;
2) continue ;;
esac
# Destination could be empty, if so without getting a valid address
if [[ -z ${d_addr} ]]; then
say "${RED}ERROR${NC}: destination address field empty"
waitForInput && continue
fi
if ! sendADA "${d_addr}" "${amountLovelace}" "${s_addr}" "${s_payment_sk_file}" "${include_fee}"; then
waitForInput && continue
fi
echo ""
if ! waitNewBlockCreated; then
waitForInput && continue
fi
getBalance ${s_addr}
while [[ ${base_lovelace} -ne ${newBalance} ]]; do
say ""
say "${ORANGE}WARN${NC}: Balance mismatch, transaction not included in latest block ($(numfmt --grouping ${base_lovelace}) != $(numfmt --grouping ${newBalance}))"
if ! waitNewBlockCreated; then
break
fi
getBalance ${s_addr}
done
if [[ ${base_lovelace} -ne ${newBalance} ]]; then
waitForInput && continue
fi
s_balance_ada=${base_ada}
getBalance ${d_addr}
d_balance_ada=${base_ada}
say ""
say "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
say "Transaction" "log"
say " From : ${GREEN}${s_wallet}${NC}" "log"
say " Amount : $(numfmt --grouping ${amountADA}) ADA" "log"
if [[ -n "${d_wallet}" ]]; then
say " To : ${GREEN}${d_wallet}${NC}" "log"
else
say " To : ${d_addr}" "log"
fi
say " Fees : $(numfmt --grouping ${minFee}) Lovelaces" "log"
say " Balance" "log"
say " - Source : $(numfmt --grouping ${s_balance_ada}) ADA" "log"
say " - Destination : $(numfmt --grouping ${d_balance_ada}) ADA" "log"
say "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
say ""
waitForInput
;; ###################################################################
delegate) # [WALLET NAME] [POOL NAME]
clear
say " >> FUNDS >> DELEGATE" "log"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo ""
if [[ ! -f ${TMP_FOLDER}/protparams.json ]]; then
say "${RED}ERROR${NC}: CNTools started without node access, only offline functions available!"
waitForInput && continue
fi
wallet_dirs=()
if ! getDirs "${WALLET_FOLDER}"; then continue; fi # dirs() array populated with all wallet folders
wallet_count=${#dirs[@]}
for dir in "${dirs[@]}"; do
base_addr_file="${WALLET_FOLDER}/${dir}/${WALLET_BASE_ADDR_FILENAME}"
stake_addr_file="${WALLET_FOLDER}/${dir}/${WALLET_STAKE_ADDR_FILENAME}"
stake_sk_file="${WALLET_FOLDER}/${dir}/${WALLET_STAKE_SK_FILENAME}"
stake_vk_file="${WALLET_FOLDER}/${dir}/${WALLET_STAKE_VK_FILENAME}"
pay_payment_sk_file="${WALLET_FOLDER}/${dir}/${WALLET_PAY_SK_FILENAME}"
[[ ! -f "${base_addr_file}" || ! -f "${stake_addr_file}" || ! -f "${stake_sk_file}" || ! -f "${stake_vk_file}" || ! -f "${pay_payment_sk_file}" ]] && continue
if [[ ${wallet_count} -le ${WALLET_SELECTION_FILTER_LIMIT} ]]; then
getAddress ${dir}
getBalance ${base_addr}
[[ ${base_lovelace} -eq 0 ]] && continue
getRewardAddress ${dir}
delegation_pool_id=$(${CCLI} shelley query stake-address-info --testnet-magic ${NWMAGIC} --address "${reward_addr}" | jq -r '.[].delegation // empty')
unset poolName
if [[ -n ${delegation_pool_id} ]]; then
while IFS= read -r -d '' pool; do
pool_id=$(cat "${pool}/${POOL_ID_FILENAME}")
if [[ "${pool_id}" = "${delegation_pool_id}" ]]; then
poolName=$(basename ${pool}) && break
fi
done < <(find "${POOL_FOLDER}" -mindepth 1 -maxdepth 1 -type d -print0 | sort -z)
fi
if [[ -n ${poolName} ]]; then
wallet_dirs+=("${dir} (${CYAN}${base_ada}${NC} ADA - ${RED}delegated${NC} to ${BLUE}${poolName}${NC})")
elif [[ -n ${delegation_pool_id} ]]; then
wallet_dirs+=("${dir} (${CYAN}${base_ada}${NC} ADA - ${RED}delegated${NC} to external address)")
else
wallet_dirs+=("${dir} (${CYAN}${base_ada}${NC} ADA)")
fi
else
wallet_dirs+=("${dir}")
fi
done
if [[ ${#wallet_dirs[@]} -eq 0 ]]; then
say "${ORANGE}WARN${NC}: No wallets available that can be delegated!"
waitForInput && continue
fi
say "Select Wallet:\n"
if ! selectDir "${wallet_dirs[@]}"; then continue; fi # ${dir_name} populated by selectDir function
wallet_name="$(echo ${dir_name} | cut -d' ' -f1)"
getAddress ${wallet_name}
getBalance ${base_addr}
if [[ ${base_lovelace} -gt 0 ]]; then
say "$(printf "%s\t${CYAN}%s${NC} ADA" "Funds in wallet:" "$(numfmt --grouping ${base_ada})")" "log"
else
say "${RED}ERROR${NC}: no funds available for wallet ${GREEN}${wallet_name}${NC}"
waitForInput && continue
fi
getRewards ${wallet_name}
if [[ reward_lovelace -eq -1 ]] && ! registerStakeWallet ${wallet_name}; then
waitForInput && continue
fi
echo ""
say "$(printf "%s\t${CYAN}%s${NC} ADA" "Funds" "$(numfmt --grouping ${base_ada})")" "log"
say "$(printf "%s\t${CYAN}%s${NC} ADA" "Rewards" "$(numfmt --grouping ${reward_ada})")" "log"
echo ""
stake_sk_file="${WALLET_FOLDER}/${wallet_name}/${WALLET_STAKE_SK_FILENAME}"
stake_vk_file="${WALLET_FOLDER}/${wallet_name}/${WALLET_STAKE_VK_FILENAME}"
pay_payment_sk_file="${WALLET_FOLDER}/${wallet_name}/${WALLET_PAY_SK_FILENAME}"
say "Do you want to delegate to a local pool or specify the pools cold vkey cbor-hex?\n"
case $(select_opt "[p] Pool" "[v] Vkey" "[c] Cancel") in
0) pool_dirs=()
if ! getDirs "${POOL_FOLDER}"; then continue; fi # dirs() array populated with all pool folders
for dir in "${dirs[@]}"; do
pool_coldkey_vk_file="${POOL_FOLDER}/${dir}/${POOL_COLDKEY_VK_FILENAME}"
[[ ! -f "${pool_coldkey_vk_file}" ]] && continue
pool_dirs+=("${dir}")
done
if [[ ${#pool_dirs[@]} -eq 0 ]]; then
say "${ORANGE}WARN${NC}: No pools available to delegate to!"
say "first create and register a pool or choose to delegate using pools cold vkey cbor-hex"
waitForInput && continue
fi
say "Select Pool:\n"
if ! selectDir "${pool_dirs[@]}"; then continue; fi # ${dir_name} populated by selectDir function
pool_name="${dir_name}"
pool_coldkey_vk_file="${POOL_FOLDER}/${pool_name}/${POOL_COLDKEY_VK_FILENAME}"
;;
1) read -r -p "vkey cbor-hex(blank to cancel): " vkey_cbor
[[ -z "${vkey_cbor}" ]] && continue
pool_name="${vkey_cbor}"
pool_coldkey_vk_file="${TMP_FOLDER}/pool_delegation.vkey"
echo "type: Node operator verification key" > "${pool_coldkey_vk_file}"
echo "title: Stake pool operator key" >> "${pool_coldkey_vk_file}"
echo "cbor-hex:" >> "${pool_coldkey_vk_file}"
echo " ${vkey_cbor}" >> "${pool_coldkey_vk_file}"
;;
2) continue ;;
esac
#Generated Files
delegation_cert_file="${WALLET_FOLDER}/${wallet_name}/${WALLET_DELEGCERT_FILENAME}"
say "-- creating delegation cert --" "log"
${CCLI} shelley stake-address delegation-certificate --stake-verification-key-file "${stake_vk_file}" --cold-verification-key-file "${pool_coldkey_vk_file}" --out-file "${delegation_cert_file}"
if ! delegate "${stake_vk_file}" "${stake_sk_file}" "${pay_payment_sk_file}" "${base_addr}" "${pool_coldkey_vk_file}" "${delegation_cert_file}" ; then
echo "" && say "${RED}ERROR${NC}: failure during delegation, removing newly created delegation certificate file"
rm -f "${delegation_cert_file}"
waitForInput && continue
fi
if ! waitNewBlockCreated; then
waitForInput && continue
fi
getBalance ${base_addr}
while [[ ${base_lovelace} -ne ${newBalance} ]]; do
echo ""
say "${ORANGE}WARN${NC}: Balance mismatch, transaction not included in latest block ($(numfmt --grouping ${base_lovelace}) != $(numfmt --grouping ${newBalance}))"
if ! waitNewBlockCreated; then
break
fi
getBalance ${base_addr}
done
if [[ ${base_lovelace} -ne ${newBalance} ]]; then
waitForInput && continue
fi
say "Delegation successfully registered"
say "Wallet : ${GREEN}${wallet_name}${NC}"
say "Pool : ${GREEN}${pool_name}${NC}" "log"
say "Amount : $(numfmt --grouping ${base_ada}) ADA" "log"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo ""
waitForInput && continue
;; ###################################################################
esac
;; ###################################################################
pool)
clear
say " >> POOL" "log"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo " Pool Management"
echo ""
echo " ) New - create a new pool"
echo " ) Register - register created pool on chain using a stake wallet (pledge wallet)"
echo " ) Modify - change pool parameters and register updated pool values on chain"
echo " ) Retire - de-register stake pool from chain in specified epoch"
echo " ) List - a compact list view of available local pools"
echo " ) Show - detailed view of specified pool"
echo " ) Rotate - rotate pool KES keys"
echo " ) Decrypt - remove write protection and decrypt pool"
echo " ) Encrypt - encrypt pool cold keys and make all files immutable"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
say " Select wallet operation\n"
case $(select_opt "[n] New" "[r] Register" "[m] Modify" "[x] Retire" "[l] List" "[s] Show" "[o] Rotate" "[d] Decrypt" "[e] Encrypt" "[h] Home") in
0) SUBCOMMAND="new" ;;
1) SUBCOMMAND="register" ;;
2) SUBCOMMAND="modify" ;;
3) SUBCOMMAND="retire" ;;
4) SUBCOMMAND="list" ;;
5) SUBCOMMAND="show" ;;
6) SUBCOMMAND="rotate" ;;
7) SUBCOMMAND="decrypt" ;;
8) SUBCOMMAND="encrypt" ;;
9) continue ;;
esac
case $SUBCOMMAND in
new)
clear
say " >> POOL >> NEW" "log"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo ""
read -r -p "Pool Name: " pool_name
# Remove unwanted characters from pool name
pool_name=${pool_name//[^[:alnum:]]/_}
if [[ -z "${pool_name}" ]]; then
say "${RED}ERROR${NC}: Empty pool name, please retry!"
waitForInput && continue
fi
echo ""
mkdir -p "${POOL_FOLDER}/${pool_name}"
pool_id_file="${POOL_FOLDER}/${pool_name}/${POOL_ID_FILENAME}"
pool_hotkey_vk_file="${POOL_FOLDER}/${pool_name}/${POOL_HOTKEY_VK_FILENAME}"
pool_hotkey_sk_file="${POOL_FOLDER}/${pool_name}/${POOL_HOTKEY_SK_FILENAME}"
pool_coldkey_vk_file="${POOL_FOLDER}/${pool_name}/${POOL_COLDKEY_VK_FILENAME}"
pool_coldkey_sk_file="${POOL_FOLDER}/${pool_name}/${POOL_COLDKEY_SK_FILENAME}"
pool_opcert_counter_file="${POOL_FOLDER}/${pool_name}/${POOL_OPCERT_COUNTER_FILENAME}"
pool_opcert_file="${POOL_FOLDER}/${pool_name}/${POOL_OPCERT_FILENAME}"
pool_vrf_vk_file="${POOL_FOLDER}/${pool_name}/${POOL_VRF_VK_FILENAME}"
pool_vrf_sk_file="${POOL_FOLDER}/${pool_name}/${POOL_VRF_SK_FILENAME}"
pool_saved_kes_start="${POOL_FOLDER}/${pool_name}/${POOL_CURRENT_KES_START}"
if [[ -f "${pool_hotkey_vk_file}" ]]; then
say "${RED}WARN${NC}: A pool ${GREEN}$pool_name${NC} already exists"
say " Choose another name or delete the existing one"
waitForInput && continue
fi
#Calculate appropriate KES period
currSlot=$(getTip slot)
slotsPerKESPeriod=$(jq -r .slotsPerKESPeriod $GENESIS_JSON)
start_kes_period=$(( currSlot / slotsPerKESPeriod ))
echo "${start_kes_period}" > ${pool_saved_kes_start}
${CCLI} shelley node key-gen-KES --verification-key-file "${pool_hotkey_vk_file}" --signing-key-file "${pool_hotkey_sk_file}"
${CCLI} shelley node key-gen --cold-verification-key-file "${pool_coldkey_vk_file}" --cold-signing-key-file "${pool_coldkey_sk_file}" --operational-certificate-issue-counter-file "${pool_opcert_counter_file}"
${CCLI} shelley stake-pool id --verification-key-file "${pool_coldkey_vk_file}" > "${pool_id_file}"
${CCLI} shelley node issue-op-cert --kes-verification-key-file "${pool_hotkey_vk_file}" --cold-signing-key-file "${pool_coldkey_sk_file}" --operational-certificate-issue-counter-file "${pool_opcert_counter_file}" --kes-period "${start_kes_period}" --out-file "${pool_opcert_file}"
${CCLI} shelley node key-gen-VRF --verification-key-file "${pool_vrf_vk_file}" --signing-key-file "${pool_vrf_sk_file}"
say "Pool: ${GREEN}${pool_name}${NC}" "log"
say "PoolPubKey: $(cat "${pool_id_file}")" "log"
say "Start cardano node with the following run arguments:" "log"
say "--shelley-kes-key ${pool_hotkey_sk_file}" "log"
say "--shelley-vrf-key ${pool_vrf_sk_file}" "log"
say "--shelley-operational-certificate ${pool_opcert_file}" "log"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo ""
waitForInput && continue
;; ###################################################################
register)
clear