Skip to content

Commit ffe22eb

Browse files
committed
Enable staking support as default
1 parent cf91a94 commit ffe22eb

File tree

1 file changed

+110
-113
lines changed

1 file changed

+110
-113
lines changed

install.sh

Lines changed: 110 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -832,136 +832,133 @@ joined_network_instructions() {
832832

833833
check_staking_accounts() {
834834
account_addresses=$(get_account_addresses)
835-
if [[ $? -eq 1 ]]; then
836-
return
837-
else
838-
set_staking_url
839835

840-
for account in ${account_addresses}; do
841-
local staking_endpoint
842-
local response
843-
local http_code
844-
local json_response
836+
set_staking_url
845837

846-
staking_endpoint="${staking_url}?owner=${account}&deleted=0"
847-
response=$(curl -s --max-time 5 -w "%{http_code}" "${staking_endpoint}")
848-
http_code=$(echo "${response}" | awk '{print substr($0, length($0) - 2)}')
849-
json_response=$(echo "${response}" | awk '{print substr($0, 1, length($0) - 3)}')
838+
for account in ${account_addresses}; do
839+
local staking_endpoint
840+
local response
841+
local http_code
842+
local json_response
843+
844+
staking_endpoint="${staking_url}?owner=${account}&deleted=0"
845+
response=$(curl -s --max-time 5 -w "%{http_code}" "${staking_endpoint}")
846+
http_code=$(echo "${response}" | awk '{print substr($0, length($0) - 2)}')
847+
json_response=$(echo "${response}" | awk '{print substr($0, 1, length($0) - 3)}')
848+
849+
if [[ "${http_code}" -eq 200 ]]; then
850+
accounts_length=$(jq '.accounts | length' <<< "${json_response}")
851+
if [[ "${accounts_length}" -gt 0 ]]; then
852+
display_banner "Staking contract detected"
853+
854+
echo "Staking contract has been detected for owner ${account}"
855+
echo ""
850856

851-
if [[ "${http_code}" -eq 200 ]]; then
852-
accounts_length=$(jq '.accounts | length' <<< "${json_response}")
853-
if [[ "${accounts_length}" -gt 0 ]]; then
854-
display_banner "Staking contract detected"
857+
local balance
858+
balance=$(get_account_balance "${account_addr}")
855859

856-
echo "Staking contract has been detected for owner ${account}"
857-
echo ""
860+
if [[ ${balance} -lt "1000" ]]; then
861+
echo "Balance is below 1,000 microVoi. Skipping staking account setup."
862+
continue
863+
fi
858864

859-
local balance
860-
balance=$(get_account_balance "${account_addr}")
865+
local staking_accounts
866+
staking_accounts=$(jq -c '.accounts[]' <<< "${json_response}")
867+
for staking_account in ${staking_accounts}; do
868+
local last_committed_block
869+
local contract_address
870+
local contract_id
871+
local part_vote_k
872+
local part_vote_lst
873+
local participation_key_id
861874

862-
if [[ ${balance} -lt "1000" ]]; then
863-
echo "Balance is below 1,000 microVoi. Skipping staking account setup."
864-
continue
865-
fi
875+
contract_id=$(jq -r '.contractId' <<< "${staking_account}")
876+
contract_address=$(jq -r '.contractAddress' <<< "${staking_account}")
877+
last_committed_block=$(get_last_committed_block)
866878

867-
local staking_accounts
868-
staking_accounts=$(jq -c '.accounts[]' <<< "${json_response}")
869-
for staking_account in ${staking_accounts}; do
870-
local last_committed_block
871-
local contract_address
872-
local contract_id
873-
local part_vote_k
874-
local part_vote_lst
875-
local participation_key_id
876-
877-
contract_id=$(jq -r '.contractId' <<< "${staking_account}")
878-
contract_address=$(jq -r '.contractAddress' <<< "${staking_account}")
879-
last_committed_block=$(get_last_committed_block)
880-
881-
part_vote_k=$(jq -r '.part_vote_k' <<< "${staking_account}")
882-
part_vote_lst=$(jq -r '.part_vote_lst' <<< "${staking_account}")
883-
884-
# shellcheck disable=SC2046
885-
participation_key_id=$(get_participation_key_id_from_vote_key "${part_vote_k}")
886-
887-
if [[ "${part_vote_k}" == "null" || $((part_vote_lst-last_committed_block)) -le 417104 || -z "${participation_key_id}" ]]; then
888-
889-
if [[ "${part_vote_k}" == "null" ]]; then
890-
echo "No staking participation key detected."
891-
elif [[ -z ${participation_key_id} ]]; then
892-
echo "Registered staking participation key is not installed locally."
893-
else
894-
local existing_expiration_date
895-
existing_expiration_date=$(get_participation_expiration_eta "${part_vote_lst}" "${last_committed_block}")
896-
897-
echo "Current participation key for account ${account} is expected to expire at: ${existing_expiration_date}"
898-
echo "Currently the network is at block: ${last_committed_block}"
899-
echo "Current participation key expires at block: ${part_vote_lst}"
900-
echo ""
901-
echo "This is below the required threshold of 417,104 blocks / ~14 days."
902-
fi
879+
part_vote_k=$(jq -r '.part_vote_k' <<< "${staking_account}")
880+
part_vote_lst=$(jq -r '.part_vote_lst' <<< "${staking_account}")
903881

904-
echo ""
905-
echo "Generating new key for owner ${account} and contract address ${contract_address}"
906-
907-
generate_new_key "${contract_address}"
908-
909-
local partkey_info
910-
local voting_key
911-
local selection_key
912-
local first_round
913-
local last_round
914-
local key_dilution
915-
local stateproof_key
916-
917-
partkey_info=$(get_most_recent_participation_key_details "${contract_address}")
918-
voting_key=$(jq -r '.voting_key' <<< "${partkey_info}")
919-
selection_key=$(jq -r '.selection_key' <<< "${partkey_info}")
920-
first_round=$(jq -r '.first_round' <<< "${partkey_info}")
921-
last_round=$(jq -r '.last_valid' <<< "${partkey_info}")
922-
key_dilution=$(jq -r '.key_dilution' <<< "${partkey_info}")
923-
stateproof_key=$(jq -r '.stateproof_key' <<< "${partkey_info}")
924-
925-
echo "Sending transactions to staking contract ${contract_address} for owner ${account}"
926-
echo "This will update the staking contract with the new participation key info, allowing participation in the network"
927-
echo "You will be asked to enter your password multiple times to confirm the transactions."
928-
929-
execute_interactive_docker_command "/node/bin/goal clerk send -a 1000 -f ${account} -t ${contract_address} --out=/tmp/payment.txn"
930-
execute_interactive_docker_command "/node/bin/goal app call --app-id ${contract_id} --from ${account} --app-arg 'b64:zSTeiA==' --app-arg 'b64:${voting_key}' --app-arg 'b64:${selection_key}' --app-arg 'int:${first_round}' --app-arg 'int:${last_round}' --app-arg 'int:${key_dilution}' --app-arg 'b64:${stateproof_key}' --out=/tmp/app_call.txn"
931-
932-
execute_docker_command "cat /tmp/{payment,app_call}.txn > /tmp/combined.txn"
933-
execute_interactive_docker_command "/node/bin/goal clerk group -i /tmp/combined.txn -o /tmp/grouped.txn > /dev/null"
934-
execute_interactive_docker_command "/node/bin/goal clerk split -i /tmp/grouped.txn -o /tmp/split.txn > /dev/null"
935-
execute_interactive_docker_command "/node/bin/goal clerk sign -i /tmp/split-0.txn -o /tmp/signed-0.txn"
936-
execute_interactive_docker_command "/node/bin/goal clerk sign -i /tmp/split-1.txn -o /tmp/signed-1.txn"
937-
execute_docker_command "cat /tmp/signed-{0,1}.txn > /tmp/signed-combined.txn"
938-
execute_interactive_docker_command "/node/bin/goal clerk rawsend -f /tmp/signed-combined.txn"
939-
940-
if [[ -n ${participation_key_id} ]]; then
941-
execute_interactive_docker_command "/node/bin/goal account deletepartkey --partkeyid ${participation_key_id}"
942-
fi
882+
# shellcheck disable=SC2046
883+
participation_key_id=$(get_participation_key_id_from_vote_key "${part_vote_k}")
884+
885+
if [[ "${part_vote_k}" == "null" || $((part_vote_lst-last_committed_block)) -le 417104 || -z "${participation_key_id}" ]]; then
886+
887+
if [[ "${part_vote_k}" == "null" ]]; then
888+
echo "No staking participation key detected."
889+
elif [[ -z ${participation_key_id} ]]; then
890+
echo "Registered staking participation key is not installed locally."
943891
else
944892
local existing_expiration_date
945893
existing_expiration_date=$(get_participation_expiration_eta "${part_vote_lst}" "${last_committed_block}")
946894

947-
echo "Current staking participation key for owner ${account}, and"
948-
echo "contract address ${contract_address} is expected to expire at: ${existing_expiration_date}"
949-
echo "This is above the required threshold of 417,104 blocks / ~14 days."
950-
echo "No new staking participation key will be generated."
895+
echo "Current participation key for account ${account} is expected to expire at: ${existing_expiration_date}"
896+
echo "Currently the network is at block: ${last_committed_block}"
897+
echo "Current participation key expires at block: ${part_vote_lst}"
951898
echo ""
899+
echo "This is below the required threshold of 417,104 blocks / ~14 days."
952900
fi
953-
done
954901

955-
echo ""
956-
echo "${bold}To learn how to use your staking contract visit: https://staking.voi.network${normal}"
957-
else
958-
display_banner "No staking contract detected"
902+
echo ""
903+
echo "Generating new key for owner ${account} and contract address ${contract_address}"
904+
905+
generate_new_key "${contract_address}"
906+
907+
local partkey_info
908+
local voting_key
909+
local selection_key
910+
local first_round
911+
local last_round
912+
local key_dilution
913+
local stateproof_key
914+
915+
partkey_info=$(get_most_recent_participation_key_details "${contract_address}")
916+
voting_key=$(jq -r '.voting_key' <<< "${partkey_info}")
917+
selection_key=$(jq -r '.selection_key' <<< "${partkey_info}")
918+
first_round=$(jq -r '.first_round' <<< "${partkey_info}")
919+
last_round=$(jq -r '.last_valid' <<< "${partkey_info}")
920+
key_dilution=$(jq -r '.key_dilution' <<< "${partkey_info}")
921+
stateproof_key=$(jq -r '.stateproof_key' <<< "${partkey_info}")
922+
923+
echo "Sending transactions to staking contract ${contract_address} for owner ${account}"
924+
echo "This will update the staking contract with the new participation key info, allowing participation in the network"
925+
echo "You will be asked to enter your password multiple times to confirm the transactions."
926+
927+
execute_interactive_docker_command "/node/bin/goal clerk send -a 1000 -f ${account} -t ${contract_address} --out=/tmp/payment.txn"
928+
execute_interactive_docker_command "/node/bin/goal app call --app-id ${contract_id} --from ${account} --app-arg 'b64:zSTeiA==' --app-arg 'b64:${voting_key}' --app-arg 'b64:${selection_key}' --app-arg 'int:${first_round}' --app-arg 'int:${last_round}' --app-arg 'int:${key_dilution}' --app-arg 'b64:${stateproof_key}' --out=/tmp/app_call.txn"
929+
930+
execute_docker_command "cat /tmp/{payment,app_call}.txn > /tmp/combined.txn"
931+
execute_interactive_docker_command "/node/bin/goal clerk group -i /tmp/combined.txn -o /tmp/grouped.txn > /dev/null"
932+
execute_interactive_docker_command "/node/bin/goal clerk split -i /tmp/grouped.txn -o /tmp/split.txn > /dev/null"
933+
execute_interactive_docker_command "/node/bin/goal clerk sign -i /tmp/split-0.txn -o /tmp/signed-0.txn"
934+
execute_interactive_docker_command "/node/bin/goal clerk sign -i /tmp/split-1.txn -o /tmp/signed-1.txn"
935+
execute_docker_command "cat /tmp/signed-{0,1}.txn > /tmp/signed-combined.txn"
936+
execute_interactive_docker_command "/node/bin/goal clerk rawsend -f /tmp/signed-combined.txn"
937+
938+
if [[ -n ${participation_key_id} ]]; then
939+
execute_interactive_docker_command "/node/bin/goal account deletepartkey --partkeyid ${participation_key_id}"
940+
fi
941+
else
942+
local existing_expiration_date
943+
existing_expiration_date=$(get_participation_expiration_eta "${part_vote_lst}" "${last_committed_block}")
944+
945+
echo "Current staking participation key for owner ${account}, and"
946+
echo "contract address ${contract_address} is expected to expire at: ${existing_expiration_date}"
947+
echo "This is above the required threshold of 417,104 blocks / ~14 days."
948+
echo "No new staking participation key will be generated."
949+
echo ""
950+
fi
951+
done
959952

960-
echo "No staking contracts found for owner ${account}. To learn more visit: https://staking.voi.network"
961-
fi
953+
echo ""
954+
echo "${bold}To learn how to use your staking contract visit: https://staking.voi.network${normal}"
955+
else
956+
display_banner "No staking contract detected"
957+
958+
echo "No staking contracts found for owner ${account}. To learn more visit: https://staking.voi.network"
962959
fi
963-
done
964-
fi
960+
fi
961+
done
965962
}
966963

967964
change_account_online_status() {

0 commit comments

Comments
 (0)