-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstellar-cli
More file actions
1000 lines (867 loc) · 38.4 KB
/
stellar-cli
File metadata and controls
1000 lines (867 loc) · 38.4 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
APP_ID="HERE YOUR APP ID"
API_KEY="HERE YOUR API KEY"
cat << banner
░░░░░░░██╗░█████╗░████████████████╗██╗░░░░░░███╗░░██╗ ░█▀▀█ ▒█▀▀█ ▀█▀ █▀▀
██╗░░░██╔╝██╔══██╗╚══██╔═════██╔══╝██║░░░██╗████╗░██║ ▒█▄▄█ ▒█▄▄█ ▒█░ ▀▀█
╚██╗░██╔╝░██║░░██║░░░██║░░░░░██║░░░██║░░░██║██╔██╗██║ ▒█░▒█ ▒█░░░ ▄█▄ ▀▀▀
░╚████╔╝░░██║░░██║░░░██║░░░░░██║░░░██║░░░██║██║╚████║
░░╚██╔╝░░░╚█████╔╝░░░██║░░░░░██║░░░╚██████╔╝██║░╚███║ Stellar CLI v1.0.0
░░░╚═╝░░░░░╚════╝░░░░╚═╝░░░░░╚═╝░░░░╚═════╝░╚═╝░░╚══╝ Scripted by @borj404
banner
help(){ # HELP MENU
cat << menu
Type the function and fill in the required parameters
Press ⏎ after each prompt to continue
To undo the previous entry type << , .. , !undo , !back or !del
"All parameter inputs are handled dynamically, so you must NOT quote strings, even in arrays"
(Optional parameters are indicated in parentheses)
For detailed information about this APIs, visit: https://docs.vottun.io/api/coreStellar
❮❮❮ AVAILABLE FUNCTIONS ❯❯❯
~$ fund ―▸ Fund an account on Testnet or Futurenet
~$ balance ―▸ Retrieve the account balance on the desired network
~$ save ―▸ Attach a smart contract to the Vottun ecosystem
~$ upload ―▸ Upload and compile one or more contracts by selecting the directory (no need to zip the content)
~$ deploy ―▸ Deploy a contract on the desired network
~$ est_deploy ―▸ Estimate the cost of deploying a contract on the desired network
~$ invoke ―▸ Invoke any method of a deployed contract
~$ est_invoke ―▸ Estimate the cost of invoking any method of a contract
~$ extend ―▸ Extend the time a transaction remains valid
~$ methods ―▸ Retrieve all the methods of a contract
~$ alive ―▸ Check if an installed contract is alive
~$ instance_info ―▸ Retrieve a contract instance's TTL info
~$ tx_info ―▸ Retrieve information about any transaction
menu
}
auth=("--header" "x-application-vkn: $APP_ID" "--header" "Authorization: Bearer $API_KEY")
ct_json="--header 'Content-Type: application/json'"
_check_input() {
local prompt="$1" var_name="$2" undo_step="$3" required="$4" validate_cmd="$5" empty_err="$6" format_err="$7"
while true; do
read -e -p "$prompt" input
if [[ "$input" =~ ^(<<|\.\.|!undo|!back|!del)$ ]]; then
if [[ "$undo_step" -ne -1 ]]; then
return 99
else
echo "Nothing to undo!"
continue
fi
fi
if [[ "$required" == "true" && -z "$input" ]]; then
echo "Error: $empty_err"
elif [ -n "$input" ] && ! eval "$validate_cmd"; then
echo "Error: $format_err"
else
eval "$var_name=\"\$input\""
return 0
fi
done
}
_step_back() {
[[ $? -eq 99 ]] && step=$((step - 1))
}
_parse_params() {
local input="$1"
[[ "$input" =~ ^[0-9]+$ && (${#input} -gt 31 || "$input" =~ (999999999999999|000000000000000)) ]] && { echo "\"$input\""; return; }
if [[ "$input" =~ ^\[.*\]$ ]]; then
local result="[" trimmed buffer="" depth=0 first=true
trimmed=$(echo "$input" | sed -E 's/^\[|\]$//g')
while IFS= read -r -n1 char; do
[[ "$char" == "[" ]] && ((depth++))
[[ "$char" == "]" ]] && ((depth--))
if [[ "$char" == "," && $depth -eq 0 ]]; then
if [ -n "$buffer" ]; then
$first || result+=", "
result+="$(_parse_params "$buffer")"
buffer=""
first=false
fi
else
buffer+="$char"
fi
done <<< "$trimmed"
[[ -n "$buffer" ]] && {
$first || result+=", "
result+="$(_parse_params "$buffer")"
}
result+="]"
echo "$result"
return
fi
[[ "$input" =~ ^\"[0-9]+\"$|^\"(true|false)\"$|^[0-9]+$|^(true|false)$ ]] && echo "$input" || echo "\"$input\""
}
_display_params() {
local -n params_ref=$1
[[ ${#params_ref[@]} -gt 0 ]] && {
echo "Params: ["
local total=${#params_ref[@]}
for ((i=0; i<total; i++)); do
param="${params_ref[$i]}"
if [[ "$param" =~ ^\[.*\]$ ]]; then
echo -n " ["
local first=true
while IFS= read -r item; do
$first || echo -n ", "; first=false
[[ "$item" =~ ^[0-9]+$|^(true|false)$ ]] && echo -n "$item" || echo -n "\"${item//\"/}\""
done <<< "$(echo "$param" | sed -E 's/^\[|\]$//g' | tr ',' '\n')"
echo -n "]"
elif [[ "$param" =~ ^[0-9]+$ && (${#param} -gt 31 || "$param" =~ (999999999999999|000000000000000)) ]]; then
echo -n " $param"
elif [[ "$param" =~ ^[0-9]+$|^(true|false)$|^\".*\"$ ]]; then
echo -n " $param"
else
echo -n " \"$param\""
fi
[[ $i -lt $((total-1)) ]] && echo "," || echo ""
done
echo "]"
}
}
_confirmation() {
while true; do
read -e -p "Do you want to proceed with these parameters? (Y/N): " confirm
[[ "$confirm" =~ ^(<<|\.\.|!undo|!back|!del)$ ]] && return 99
case "$confirm" in
[Yy]*)
echo
return 0
;;
[Nn]*)
echo
echo "Process cancelled."
return 1
;;
*)
echo "Invalid input! Try again..."
;;
esac
done
}
_network_details() {
local network=$1 net_name identifier url_address url_tx
case $network in
0)
net_name="Testnet"
identifier=100000000
url_address="https://testnet.steexp.com/account/"
url_tx="https://testnet.steexp.com/tx/"
;;
1)
net_name="Futurenet"
identifier=100000001
url_address="https://futurenet.steexp.com/account/"
url_tx="https://futurenet.steexp.com/tx/"
;;
2)
net_name="Pubnet"
identifier=100000002
url_address="https://steexp.com/account/"
url_tx="https://steexp.com/tx/"
;;
esac
echo "$net_name|$identifier|$url_address|$url_tx"
}
_loading() {
local duration=0.5 bar_length=24
for ((i = 0; i <= bar_length; i++)); do
local progress=$(for ((j = 0; j < i; j++)); do printf "\033[44m \033[0m "; done)
local empty=$(for ((j = i; j < bar_length; j++)); do printf " "; done)
printf "\r%s%s" "$progress" "$empty"
sleep $(bc <<< "$duration / $bar_length")
done
echo
}
####################
### STELLAR CORE ###
####################
fund() { # FUND AN ACCOUNT ON TESTNET OR FUTURNET
local account networkId step=1
echo "Please enter the following parameters to fund your account:"
echo -e "account networkId\n"
while true; do
case $step in
1)
_check_input "Account: " account -1 "true" '[[ "$input" =~ ^[0-9A-Z]{56}$ ]]' \
"Account is required." "Account must be 56 characters long."
[[ $? -eq 99 ]] && continue
step=2
;;
2)
echo -e "Choose the network number you want to use:\n0. Testnet\n1. Futurenet"
_check_input "Network ID: " networkId 1 "true" '[[ "$input" =~ ^[01]$ ]]' \
"Network ID is required." "Please, choose '0' or '1'."
_step_back && continue
step=3
;;
3)
IFS='|' read -r net_name identifier url_address url_tx <<< "$(_network_details "$networkId")"
echo -e "\nYou've entered the following parameters:"
echo "Account: $account"
echo -e "Network: $net_name\n"
_confirmation && step=0 || { _step_back || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local data=$(jq -n \
--arg account "$account" \
--argjson networkId "$identifier" \
'{
account: $account,
networkId: $networkId
}')
local response=$(curl --silent --location --request POST 'https://api.vottun.tech/stellar/v1/account/fund' \
"${auth[@]}" $ct_json --data-raw "$data")
_loading
echo -e "Server response:\n$response"
}
balance() { # RETRIEVE THE ACCOUNT BALANCE ON THE DESIRED NETWORK
local account networkId step=1
echo "Please enter the following parameters to retrieve the account balance:"
echo -e "account networkId\n"
while true; do
case $step in
1)
_check_input "Account: " account -1 "true" '[[ "$input" =~ ^[0-9A-Z]{56}$ ]]' \
"Account is required." "Account must be 56 characters long."
[[ $? -eq 99 ]] && continue
step=2
;;
2)
echo -e "Choose the network number you want to use:\n0. Testnet\n1. Futurenet\n2. Pubnet"
_check_input "Network ID: " networkId 1 "true" '[[ "$input" =~ ^[012]$ ]]' \
"Network ID is required." "Please, choose '0', '1' or '2'."
_step_back && continue
step=3
;;
3)
IFS='|' read -r net_name identifier url_address url_tx <<< "$(_network_details "$networkId")"
echo -e "\nYou've entered the following parameters:"
echo "Account: $account"
echo -e "Network: $net_name\n"
_confirmation && step=0 || { _step_back || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local data=$(jq -n \
--arg account "$account" \
--argjson networkId "$identifier" \
'{
account: $account,
networkId: $networkId
}')
local response=$(curl --silent --location --request GET 'https://api.vottun.tech/stellar/v1/account/balance' \
"${auth[@]}" $ct_json --data-raw "$data")
echo -e "Server response:\n$response"
}
save(){ # ATTACH A SMART CONTRACT TO THE VOTTUN ECOSYSTEM
local file name description step=1
echo "Please enter the following parameters to save the smart contract:"
echo -e "file name (description)\n"
while true; do
case $step in
1)
_check_input "File: " file -1 "true" 'true' "File is required." ""
[[ $? -eq 99 ]] && continue
[[ ! "$file" =~ \.wasm$ ]] && { echo "Error: File must have a .wasm extension."; continue; }
[ -f "$file" ] || { echo "Error: File doesn't exist at the specified path."; continue; }
step=2
;;
2)
_check_input "Name: " name 1 "true" 'true' "Name is required." ""
_step_back && continue
step=3
;;
3)
_check_input "Description (optional): " description 2 "false" '' "" ""
_step_back && continue
step=4
;;
4)
echo -e "\nYou've entered the following parameters:"
echo "File: $file"
echo "Name: $name"
[ -n "$description" ] && echo "Description: $description"
echo
_confirmation && step=0 || { _step_back || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local response=$(curl --silent --location --request POST 'https://api.vottun.tech/stellar/v1/contract/save' \
"${auth[@]}" --header 'Content-Type: multipart/form-data' \
--form 'file=@"'"$file"'"' \
--form 'name="'"$name"'"' \
${description:+--form 'description="'"$description"'"'})
_loading
echo -e "\nServer response:\n$response"
}
upload(){ # UPLOAD AND COMPILE ONE OR MORE CONTRACTS BY SELECTING THE DIRECTORY (NO NEED TO ZIP THE CONTENT)
local file tempZip zipFiles extractDir
echo -e "Please enter the directory path to upload one or more contracts:\n"
while true; do
_check_input "Directory path: " file -1 "true" 'true' "Directory path is required." ""
[[ $? -eq 99 ]] && continue
if [ -d "$file" ]; then
tempZip="${file%/}.zip"
zipFiles=$(find "$file" -maxdepth 1 -type f -name "*.zip")
if [[ -n "$zipFiles" ]]; then
if [[ $(echo "$zipFiles" | wc -l) -eq 1 ]]; then
file="$zipFiles"
else
extractDir="$file/_temp_extract"
mkdir -p "$extractDir"
for zip in $zipFiles; do
unzip -o "$zip" -d "$extractDir" || {
echo "Error: Failed to extract $zip";
return 1;
}
done
(cd "$extractDir" && zip -r "../$(basename "$file").zip" .) || {
echo "Error: Failed to create zip file.";
return 1;
}
rm -rf "$extractDir"
file="$tempZip"
fi
else
(cd "$file" && zip -r "../$(basename "$file").zip" .) || {
echo "Error: Failed to create zip file.";
return 1;
}
file="$tempZip"
fi
elif [ ! -f "$file" ]; then
echo "Error: Directory path doesn't exist.";
continue
fi
echo -e "\nYou've entered the following parameter:\nPath: $file\n"
_confirmation && break || [[ $? -eq 99 ]] || return 1
done
local response=$(curl --silent --location --request POST \
'https://api.vottun.tech/stellar/v1/contract/upload' "${auth[@]}" \
--header 'Content-Type: multipart/form-data' \
--form 'file=@"'"$file"'"')
_loading
echo -e "\nServer response:\n$response"
[[ -f "$tempZip" ]] && rm -f "$tempZip"
}
deploy() { # DEPLOY A CONTRACT ON THE DESIRED NETWORK
local contractSpecsId myReference blockchainNetwork step=1
echo "Please enter the following parameters to deploy the contract:"
echo -e "contractSpecsId blockchainNetwork (myReference)\n"
while true; do
case $step in
1)
_check_input "Contract Specs ID: " contractSpecsId -1 "true" '[[ "$input" =~ ^[0-9]+$ ]]' \
"Contract Specs ID is required." "Contract Specs ID must be an integer number."
[[ $? -eq 99 ]] && continue
step=2
;;
2)
_check_input "My Reference (optional): " myReference 1 "false" '' "" ""
_step_back && continue
step=3
;;
3)
echo -e "Choose the network number you want to use:\n0. Testnet\n1. Futurenet\n2. Pubnet"
_check_input "Network ID: " blockchainNetwork 2 "true" '[[ "$input" =~ ^[012]$ ]]' \
"Network ID is required." "Please, choose '0', '1' or '2'."
_step_back && continue
step=4
;;
4)
IFS='|' read -r net_name identifier url_address url_tx <<< "$(_network_details "$blockchainNetwork")"
echo -e "\nYou've entered the following parameters:"
echo "Contract Specs ID: $contractSpecsId"
echo "Network: $net_name"
[ -n "$myReference" ] && echo "My Reference: $myReference"
echo
_confirmation && step=0 || { _step_back || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local data=$(jq -n \
--argjson contractSpecsId "$contractSpecsId" \
--argjson blockchainNetwork "$identifier" \
--arg myReference "$myReference" \
'{
contractSpecsId: $contractSpecsId,
blockchainNetwork: $blockchainNetwork
} +
(if $myReference != "" then {myReference: $myReference} else {} end)')
local response=$(curl --silent --location --request POST 'https://api.vottun.tech/stellar/v1/contract/deployment' \
"${auth[@]}" $ct_json --data-raw "$data")
echo -e "Server response:\n$response"
txHash=$(echo "$response" | jq -r '.txHash // empty')
if [[ -n "$txHash" ]]; then
address=$(echo "$response" | jq -r '.address // empty')
echo -e "\nDeploying the contract on $net_name..."
_loading
echo -e "\nBlock explorer URLs:\n$url_address$address\n$url_tx$txHash"
fi
}
est_deploy() { # ESTIMATE THE COST OF DEPLOYING A CONTRACT ON THE DESIRED NETWORK
local contractSpecsId myReference blockchainNetwork step=1
echo "Please enter the following parameters to estimate the contract deployment cost:"
echo -e "contractSpecsId blockchainNetwork (myReference)\n"
while true; do
case $step in
1)
_check_input "Contract Specs ID: " contractSpecsId -1 "true" '[[ "$input" =~ ^[0-9]+$ ]]' \
"Contract Specs ID is required." "Contract Specs ID must be an integer number."
[[ $? -eq 99 ]] && continue
step=2
;;
2)
echo -e "Choose the network number you want to use:\n0. Testnet\n1. Futurenet\n2. Pubnet"
_check_input "Network ID: " blockchainNetwork 1 "true" '[[ "$input" =~ ^[012]$ ]]' \
"Network ID is required." "Please, choose '0', '1' or '2'."
_step_back && continue
step=3
;;
3)
IFS='|' read -r net_name identifier url_address url_tx <<< "$(_network_details "$blockchainNetwork")"
echo -e "\nYou've entered the following parameters:"
echo "Contract Specs ID: $contractSpecsId"
echo "Network: $net_name"
[ -n "$myReference" ] && echo "My Reference: $myReference"
echo
_confirmation && step=0 || { _step_back || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local data=$(jq -n \
--argjson contractSpecsId "$contractSpecsId" \
--argjson blockchainNetwork "$identifier" \
'{
contractSpecsId: $contractSpecsId,
blockchainNetwork: $blockchainNetwork
}')
local response=$(curl --silent --location --request POST 'https://api.vottun.tech/stellar/v1/contract/deployment/estimate' \
"${auth[@]}" $ct_json --data-raw "$data")
echo -e "Server response:\n$response"
}
invoke() { # INVOKE ANY METHOD OF A DEPLOYED CONTRACT
local blockchainNetwork myReference restore address method numParams params step=1
echo "Please enter the following parameters to invoke the contract method:"
echo -e "blockchainNetwork restore address method params (myReference)\n"
while true; do
case $step in
1)
echo -e "Choose the network number you want to use:\n0. Testnet\n1. Futurenet\n2. Pubnet"
_check_input "Network ID: " blockchainNetwork -1 "true" '[[ "$input" =~ ^[012]$ ]]' \
"Network ID is required." "Please, choose '0', '1' or '2'."
[[ $? -eq 99 ]] && continue
step=2
;;
2)
_check_input "My Reference (optional): " myReference 1 "false" '' "" ""
_step_back && continue
step=3
;;
3)
echo -e "Extend the TTL?\n0. False\n1. True"
_check_input "Choose '0' or '1': " restore 2 "true" '[[ "$input" =~ ^[01]$ ]]' \
"This flag is required." "Please choose '0' (false) or '1' (true)."
_step_back && continue
restore=false
[[ "$input" == "1" ]] && restore=true
step=4
;;
4)
_check_input "Address: " address 3 "true" '[[ "$input" =~ ^[0-9A-Z]{56}$ ]]' \
"Address is required." "Address must be 56 characters long."
_step_back && continue
step=5
;;
5)
_check_input "Method: " method 4 "true" '[[ "$input" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]' \
"Method is required." "Method format is wrong."
_step_back && continue
step=6
;;
6)
_check_input "How many parameters do you want to input? " numParams 5 "false" \
'[[ "$input" =~ ^[0-9]+$ ]]' "" "Please enter a valid integer."
_step_back && continue
numParams=${numParams:-0}
params=()
step=7
;;
7)
local i=1
while (( i <= numParams )); do
read -e -p "Param $i: " input
if [[ "$input" =~ ^(<<|\.\.|!undo|!back|!del)$ ]]; then
if (( i == 1 )); then
step=6 && break
elif (( i > 1 )); then
params=("${params[@]:0:${#params[@]}-1}") && ((i--))
fi
elif [[ -n "$input" ]]; then
params+=("$input") && ((i++))
else
echo "Parameter $i is required."
fi
done
(( i > numParams )) && step=8
;;
8)
IFS='|' read -r net_name identifier url_address url_tx <<< "$(_network_details "$blockchainNetwork")"
echo -e "\nYou've entered the following parameters:"
echo "Network: $net_name"
echo "Restore: $restore"
echo "Address: $address"
echo "Method: $method"
local final_params=$(jq -n '[]')
for param in "${params[@]}"; do
final_params=$(echo "$final_params" | jq ". + [$(_parse_params "$param")]")
done
_display_params params
[ -n "$myReference" ] && echo "My Reference: $myReference"
echo
_confirmation && step=0 || { [[ $? -eq 99 ]] && step=6 || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local data=$(jq -n \
--argjson blockchainNetwork "$identifier" \
--arg myReference "$myReference" \
--argjson restore "$restore" \
--arg address "$address" \
--arg method "$method" \
'{
blockchainNetwork: $blockchainNetwork,
restore: $restore,
address: $address,
method: $method
} +
(if $myReference != "" then {myReference: $myReference} else {} end)')
data=$(echo "$data" | jq --argjson params "$final_params" '. + {params: $params}')
data=$(echo "$data" | sed -E 's/"([0-9]{16,})"/\1/g')
local response=$(curl --silent --location --request POST 'https://api.vottun.tech/stellar/v1/contract/invoke' \
"${auth[@]}" $ct_json --data-raw "$data")
_loading
echo -e "\nServer response:\n$response"
txHash=$(echo "$response" | jq -r '.txHash // empty')
[[ -n "$txHash" ]] && echo -e "\nBlock explorer URL:\n$url_tx$txHash"
}
est_invoke() { # ESTIMATE THE COST OF INVOKING ANY METHOD OF A CONTRACT
local blockchainNetwork myReference restore address method numParams params step=1
echo "Please enter the following parameters to estimate the cost of invoking the contract method:"
echo -e "blockchainNetwork restore address method params (myReference)\n"
while true; do
case $step in
1)
echo -e "Choose the network number you want to use:\n0. Testnet\n1. Futurenet\n2. Pubnet"
_check_input "Network ID: " blockchainNetwork -1 "true" '[[ "$input" =~ ^[012]$ ]]' \
"Network ID is required." "Please, choose '0', '1' or '2'."
[[ $? -eq 99 ]] && continue
step=2
;;
2)
_check_input "My Reference (optional): " myReference 1 "false" '' "" ""
_step_back && continue
step=3
;;
3)
echo -e "Extend the TTL?\n0. False\n1. True"
_check_input "Choose '0' or '1': " restore 2 "true" '[[ "$input" =~ ^[01]$ ]]' \
"This flag is required." "Please choose '0' (false) or '1' (true)."
_step_back && continue
restore=false
[[ "$input" == "1" ]] && restore=true
step=4
;;
4)
_check_input "Address: " address 3 "true" '[[ "$input" =~ ^[0-9A-Z]{56}$ ]]' \
"Address is required." "Address must be 56 characters long."
_step_back && continue
step=5
;;
5)
_check_input "Method: " method 4 "true" '[[ "$input" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]' \
"Method is required." "Method format is wrong."
_step_back && continue
step=6
;;
6)
_check_input "How many parameters do you want to input? " numParams 5 "false" \
'[[ "$input" =~ ^[0-9]+$ ]]' "" "Please enter a valid integer."
_step_back && continue
numParams=${numParams:-0}
params=()
step=7
;;
7)
local i=1
while (( i <= numParams )); do
read -e -p "Param $i: " input
if [[ "$input" =~ ^(<<|\.\.|!undo|!back|!del)$ ]]; then
if (( i == 1 )); then
step=6 && break
elif (( i > 1 )); then
params=("${params[@]:0:${#params[@]}-1}") && ((i--))
fi
elif [[ -n "$input" ]]; then
params+=("$input") && ((i++))
else
echo "Parameter $i is required."
fi
done
(( i > numParams )) && step=8
;;
8)
IFS='|' read -r net_name identifier url_address url_tx <<< "$(_network_details "$blockchainNetwork")"
echo -e "\nYou've entered the following parameters:"
echo "Network: $net_name"
echo "Restore: $restore"
echo "Address: $address"
echo "Method: $method"
local final_params=$(jq -n '[]')
for param in "${params[@]}"; do
final_params=$(echo "$final_params" | jq ". + [$(_parse_params "$param")]")
done
_display_params params
[ -n "$myReference" ] && echo "My Reference: $myReference"
echo
_confirmation && step=0 || { [[ $? -eq 99 ]] && step=6 || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local data=$(jq -n \
--argjson blockchainNetwork "$identifier" \
--arg myReference "$myReference" \
--argjson restore "$restore" \
--arg address "$address" \
--arg method "$method" \
'{
blockchainNetwork: $blockchainNetwork,
restore: $restore,
address: $address,
method: $method
} +
(if $myReference != "" then {myReference: $myReference} else {} end)')
data=$(echo "$data" | jq --argjson params "$final_params" '. + {params: $params}')
data=$(echo "$data" | sed -E 's/"([0-9]{16,})"/\1/g')
local response=$(curl --silent --location --request POST 'https://api.vottun.tech/stellar/v1/contract/invoke/estimate' \
"${auth[@]}" $ct_json --data-raw "$data")
echo -e "Server response:\n$response"
}
extend() { # EXTEND THE TIME A TRANSACTION REMAINS VALID
local blockchainNetwork address extend_to step=1
echo "Please enter the following parameters to extend the transaction's TTL:"
echo -e "blockchainNetwork address extend_to\n"
while true; do
case $step in
1)
echo -e "Choose the network number you want to use:\n0. Testnet\n1. Futurenet\n2. Pubnet"
_check_input "Network ID: " blockchainNetwork -1 "true" '[[ "$input" =~ ^[012]$ ]]' \
"Network ID is required." "Please, choose '0', '1' or '2'."
[[ $? -eq 99 ]] && continue
step=2
;;
2)
_check_input "Address: " address -1 "true" '[[ "$input" =~ ^[0-9A-Z]{56}$ ]]' \
"Address is required." "Address must be 56 characters long."
_step_back && continue
step=3
;;
3)
_check_input "Extend To: " extend_to 2 "true" '[[ "$input" =~ ^[0-9]+$ ]]' \
"Extend To is required." "Extend To must be an integer number."
_step_back && continue
step=4
;;
4)
IFS='|' read -r net_name identifier url_address url_tx <<< "$(_network_details "$blockchainNetwork")"
echo -e "\nYou've entered the following parameters:"
echo "Network: $net_name"
echo "Address: $address"
echo -e "Extend To: $extend_to\n"
_confirmation && step=0 || { _step_back || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local data=$(jq -n \
--argjson blockchainNetwork "$identifier" \
--arg address "$address" \
--argjson extend_to "$extend_to" \
'{
blockchainNetwork: $blockchainNetwork,
address: $address,
extend_to: $extend_to
}')
local response=$(curl --silent --location --request POST 'https://api.vottun.tech/stellar/v1/contract/invoke/extendttl' \
"${auth[@]}" $ct_json --data-raw "$data")
_loading
echo -e "\nServer response:\n$response"
txHash=$(echo "$response" | jq -r '.txHash // empty')
[[ -n "$txHash" ]] && echo -e "\nBlock explorer URL:\n$url_tx$txHash"
}
methods(){ # RETRIEVE ALL THE METHODS OF A CONTRACT
local contractId blockchainNetwork step=1
echo "Please enter the following parameters to retrieve the methods of the contract:"
echo -e "contractSpecsId blockchainNetwork\n"
while true; do
case $step in
1)
_check_input "Contract Specs ID: " contractId -1 "true" '[[ "$input" =~ ^[0-9]+$ ]]' \
"Contract Specs ID is required." "Contract Specs ID must be an integer number."
[[ $? -eq 99 ]] && continue
step=2
;;
2)
echo -e "Choose the network number you want to use:\n0. Testnet\n1. Futurenet\n2. Pubnet"
_check_input "Network ID: " blockchainNetwork 1 "true" '[[ "$input" =~ ^[012]$ ]]' \
"Network ID is required." "Please, choose '0', '1' or '2'."
_step_back && continue
step=3
;;
3)
IFS='|' read -r net_name identifier url_address url_tx <<< "$(_network_details "$blockchainNetwork")"
echo -e "\nYou've entered the following parameters:"
echo "Contract Specs ID: $contractId"
echo -e "Network: $net_name\n"
_confirmation && step=0 || { _step_back || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local data=$(jq -n \
--argjson blockchainNetwork "$identifier" \
'{
blockchainNetwork: $blockchainNetwork
}')
local response=$(curl --silent --location --request GET \
'https://api.vottun.tech/stellar/v1/contract/'$contractId'/methods' \
"${auth[@]}" $ct_json --data-raw "$data")
echo -e "Server response:\n$response"
}
alive(){ # CHECK IF AN INSTALLED CONTRACT IS ALIVE
local contractId blockchainNetwork step=1
echo "Please enter the following parameters to check if the contract is alive:"
echo -e "contractSpecsId blockchainNetwork\n"
while true; do
case $step in
1)
_check_input "Contract Specs ID: " contractId -1 "true" '[[ "$input" =~ ^[0-9]+$ ]]' \
"Contract Specs ID is required." "Contract Specs ID must be an integer number."
[[ $? -eq 99 ]] && continue
step=2
;;
2)
echo -e "Choose the network number you want to use:\n0. Testnet\n1. Futurenet\n2. Pubnet"
_check_input "Network ID: " blockchainNetwork 1 "true" '[[ "$input" =~ ^[012]$ ]]' \
"Network ID is required." "Please, choose '0', '1' or '2'."
_step_back && continue
step=3
;;
3)
IFS='|' read -r net_name identifier url_address url_tx <<< "$(_network_details "$blockchainNetwork")"
echo -e "\nYou've entered the following parameters:"
echo "Contract Specs ID: $contractId"
echo -e "Network: $net_name\n"
_confirmation && step=0 || { _step_back || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local data=$(jq -n \
--argjson blockchainNetwork "$identifier" \
'{
blockchainNetwork: $blockchainNetwork
}')
local response=$(curl --silent --location --request GET \
'https://api.vottun.tech/stellar/v1/contract/'$contractId'/contracttl' \
"${auth[@]}" $ct_json --data-raw "$data")
echo -e "Server response:\n$response"
}
instance_info(){ # RETRIEVE A CONTRACT INSTANCE'S TTL INFO
local address blockchainNetwork sourceAccount step=1
echo "Please enter the following parameters to retrieve the contract instance's TTL info:"
echo -e "address blockchainNetwork sourceAccount\n"
while true; do
case $step in
1)
_check_input "Contract Address: " address -1 "true" '[[ "$input" =~ ^[0-9A-Z]{56}$ ]]' \
"Contract Address is required." "Contract Address must be 56 characters long."
[[ $? -eq 99 ]] && continue
step=2
;;
2)
echo -e "Choose the network number you want to use:\n0. Testnet\n1. Futurenet\n2. Pubnet"
_check_input "Network ID: " blockchainNetwork 1 "true" '[[ "$input" =~ ^[012]$ ]]' \
"Network ID is required." "Please, choose '0', '1' or '2'."
_step_back && continue
step=3
;;
3)
_check_input "Source Account: " sourceAccount 2 "true" '[[ "$input" =~ ^[0-9A-Z]{56}$ ]]' \
"Source Account is required." "Source Account must be 56 characters long."
_step_back && continue
step=4
;;
4)
IFS='|' read -r net_name identifier url_address url_tx <<< "$(_network_details "$blockchainNetwork")"
echo -e "\nYou've entered the following parameters:"
echo "Contract Address: $address"
echo "Network: $net_name"
echo -e "Source Account: $sourceAccount\n"
_confirmation && step=0 || { _step_back || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local data=$(jq -n \
--argjson blockchainNetwork "$identifier" \
--arg sourceAccount "$sourceAccount" \
'{
blockchainNetwork: $blockchainNetwork,
sourceAccount: $sourceAccount
}')
local response=$(curl --silent --location --request GET \
'https://api.vottun.tech/stellar/v1/contract/'$address'/instancettl' \
"${auth[@]}" $ct_json --data-raw "$data")
echo -e "Server response:\n$response"
}
tx_info(){ # RETRIEVE INFORMATION ABOUT ANY TRANSACTION
local txHash blockchainNetwork step=1
echo "Please enter the following parameters to retrieve the transaction info:"
echo -e "txHash blockchainNetwork\n"
while true; do
case $step in
1)
_check_input "Tx Hash: " txHash -1 "true" '[[ "$input" =~ ^[0-9a-fA-F]{64}$ ]]' \
"Tx Hash is required." "Tx Hash must be 64 characters long."
[[ $? -eq 99 ]] && continue
step=2
;;
2)
echo -e "Choose the network number you want to use:\n0. Testnet\n1. Futurenet\n2. Pubnet"
_check_input "Network ID: " blockchainNetwork 1 "true" '[[ "$input" =~ ^[012]$ ]]' \
"Network ID is required." "Please, choose '0', '1' or '2'."
_step_back && continue
step=3
;;
3)
IFS='|' read -r net_name identifier url_address url_tx <<< "$(_network_details "$blockchainNetwork")"
echo -e "\nYou've entered the following parameters:"
echo "Tx Hash: $txHash"
echo -e "Network: $net_name\n"
_confirmation && step=0 || { _step_back || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local response=$(curl --silent --location --request GET \
'https://api.vottun.tech/stellar/v1/transaction/'$txHash'/info?network='$identifier'' "${auth[@]}")
echo -e "Server response:\n$response"
}