Skip to content

Commit bc38ce6

Browse files
authored
Use KMD for wallet creation (#31)
1 parent 9d5795d commit bc38ce6

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

install.sh

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ headless_install=0
77
is_root=0
88
skip_account_setup=0
99
migrate_host_based_setup=0
10+
kmd_token=""
11+
wallet_password=""
1012

1113
bold=$(tput bold)
1214
normal=$(tput sgr0)
@@ -229,12 +231,43 @@ catchup_node() {
229231
display_banner "Caught up with the network!"
230232
}
231233

234+
ask_for_password() {
235+
local password
236+
local password_repeat
237+
while true; do
238+
# shellcheck disable=SC2162
239+
read -sp "Password: " password
240+
echo
241+
# shellcheck disable=SC2162
242+
read -sp "Repeat password: " password_repeat
243+
echo
244+
if [[ ${password} == "${password_repeat}" ]]; then
245+
wallet_password=${password}
246+
break
247+
else
248+
# shellcheck disable=SC2028
249+
echo -e "\n"
250+
echo "Passwords do not match. Please try again."
251+
fi
252+
done
253+
}
254+
232255
create_wallet() {
233256
if [[ $(execute_docker_command "goal wallet list | wc -l") -eq 1 ]]; then
234257
echo "Let's create a new wallet for you. Please provide a password for security."
235-
echo "Seeing the wallet's mnemonic is optional. Any Voi will be linked with the account we'll create or import after wallet creation."
236258

237-
execute_interactive_docker_command "goal wallet new voi"
259+
get_kmd_token
260+
261+
ask_for_password
262+
263+
read -r -d '' json_data <<EOF
264+
{\"wallet_name\": \"voi\",\"wallet_driver_name\": \"sqlite\", \"wallet_password\": \"${wallet_password}\"}
265+
EOF
266+
267+
response_code=$(execute_docker_command "curl -s -o /dev/null -w '%{http_code}' -X POST -H 'Content-Type: application/json' -H 'X-KMD-API-Token: ${kmd_token}' -d '${json_data}' http://localhost:7833/v1/wallet")
268+
if [[ response_code -ne 200 ]]; then
269+
abort "Error creating wallet. Exiting the program."
270+
fi
238271
else
239272
echo "Wallet already exists. Skipping wallet creation."
240273
fi
@@ -260,7 +293,7 @@ get_account_info() {
260293
allow_one_account=$1
261294

262295
if execute_sudo 'test ! -f "/var/lib/voi/algod/data/voitest-v1/accountList.json"'; then
263-
abort "Account list not found. Exiting the program."
296+
return 0
264297
fi
265298

266299
accounts_json=$(execute_sudo 'cat /var/lib/voi/algod/data/voitest-v1/accountList.json')
@@ -388,6 +421,14 @@ generate_participation_key() {
388421
fi
389422
}
390423

424+
start_kmd() {
425+
execute_docker_command "goal kmd start -t 600"
426+
}
427+
428+
get_kmd_token() {
429+
kmd_token=$(execute_docker_command "cat /algod/data/kmd-v0.5/kmd.token")
430+
}
431+
391432
display_banner() {
392433
echo
393434
echo "********************************************************************************"
@@ -707,7 +748,7 @@ fi
707748
mkdir -p "${voi_home}"
708749

709750
display_banner "Fetching the latest Voi Network updates and scripts."
710-
curl -L https://api.github.com/repos/VoiNetwork/voi-swarm/tarball/main --output "${voi_home}"/voi-swarm.tar.gz
751+
curl -sSL https://api.github.com/repos/VoiNetwork/voi-swarm/tarball/main --output "${voi_home}"/voi-swarm.tar.gz
711752
tar -xzf "${voi_home}"/voi-swarm.tar.gz -C "${voi_home}" --strip-components=1
712753
rm "${voi_home}"/voi-swarm.tar.gz
713754

@@ -727,12 +768,13 @@ if [[ -n ${VOINETWORK_SKIP_WALLET_SETUP} && ${VOINETWORK_SKIP_WALLET_SETUP} -eq
727768
exit 0
728769
fi
729770

771+
start_kmd
772+
730773
display_banner "Initiating setup for Voi wallets and accounts."
731774

732775
create_wallet
733776

734777
if [[ -n ${VOINETWORK_IMPORT_ACCOUNT} && ${VOINETWORK_IMPORT_ACCOUNT} -eq 1 ]]; then
735-
736778
if ! (check_if_account_exists true); then
737779
echo "An account already exists. No need to import, skipping this step."
738780
else

0 commit comments

Comments
 (0)