From 3333b372d6d85e5bc2a3c9011e7e01d4ad9c7261 Mon Sep 17 00:00:00 2001 From: Artem Ryabov Date: Tue, 1 Dec 2020 19:04:57 +0300 Subject: [PATCH] Aligned with net.ton.dev --- scripts/check_node_sync_status.sh | 14 --- scripts/confirmer/README.md | 12 ++ scripts/confirmer/confirm.sh | 62 +++++++++++ scripts/confirmer/p.txt | 5 + scripts/confirmer/tonlabs-cli.conf.json | 12 ++ scripts/confirmer/wallets.txt | 4 + scripts/create_wallet.sh | 14 --- scripts/deploy_wallet.sh | 14 --- scripts/env.sh | 14 --- scripts/msig_genaddr.sh | 15 --- scripts/preinit.sh | 14 --- scripts/run.sh | 14 --- scripts/setup.sh | 14 --- scripts/tonlabs-cli.conf.json | 13 ++- scripts/validator.sh | 14 --- scripts/validator_msig.sh | 142 +++++++++++++----------- 16 files changed, 187 insertions(+), 190 deletions(-) create mode 100644 scripts/confirmer/README.md create mode 100755 scripts/confirmer/confirm.sh create mode 100644 scripts/confirmer/p.txt create mode 100644 scripts/confirmer/tonlabs-cli.conf.json create mode 100644 scripts/confirmer/wallets.txt diff --git a/scripts/check_node_sync_status.sh b/scripts/check_node_sync_status.sh index 27cff76..6c35547 100755 --- a/scripts/check_node_sync_status.sh +++ b/scripts/check_node_sync_status.sh @@ -1,19 +1,5 @@ #!/bin/bash -eE -# Copyright 2020 TON DEV SOLUTIONS LTD. -# -# Licensed under the SOFTWARE EVALUATION License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at: -# -# https://www.ton.dev/licenses -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific TON DEV software governing permissions and limitations -# under the License. - SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) # shellcheck source=env.sh . "${SCRIPT_DIR}/env.sh" diff --git a/scripts/confirmer/README.md b/scripts/confirmer/README.md new file mode 100644 index 0000000..eee3c8d --- /dev/null +++ b/scripts/confirmer/README.md @@ -0,0 +1,12 @@ +Confirmer script do: + +Confirming multisig transactions. + +Using two files `wallets.txt` and `p.txt` as wallets adreses and passphrases source. + +Doing simple test for un empty payload and elector destinaton adress. + + +You need to dowload latest tonoscli and SafeMultisigWallet.abi.json as usual and put it near the script. +Install `jq` too. + diff --git a/scripts/confirmer/confirm.sh b/scripts/confirmer/confirm.sh new file mode 100755 index 0000000..b72d67b --- /dev/null +++ b/scripts/confirmer/confirm.sh @@ -0,0 +1,62 @@ +#!/bin/bash -eE + +#check for the destination wallet + +L_PATH="./" +L_FILE="confirmer.log" + +function f_output() { + TS=$(date +%s) + TD=$(date +%FT%T%Z) + echo "${TD};${TS};${1}" >>"${L_PATH}${L_FILE}" + echo "${TD};${TS};${1}" +} + +function f_check_trans() { + W_SOURCE=$1 # Source wallet + W_DEST=$2 # Destination wallet + W_PHRASE=$3 # seed phrase + TRAN=0 + + OUTPUT=$(${L_PATH}tonos-cli run "${W_SOURCE}" getTransactions {} --abi ${L_PATH}SafeMultisigWallet.abi.json | sed -ne '/Result/,$ p' | sed 's/Result: //') + N_TRAN=$(echo "${OUTPUT}" | jq '.transactions | length') + + if [ "${N_TRAN}" == "" ]; then + f_output "${W_SOURCE};Bad_contract;" + elif [ "${N_TRAN}" -eq 0 ]; then + f_output "${W_SOURCE};No_transactions;" + else + while [ "${TRAN}" -lt "${N_TRAN}" ]; do + T_DEST=$(echo "${OUTPUT}" | jq -r ".transactions[${TRAN}].dest") + T_ID=$(echo "${OUTPUT}" | jq -r ".transactions[${TRAN}].id") + T_VALUE=$(echo "${OUTPUT}" | jq -r ".transactions[${TRAN}].value") + T_PAYLOAD=$(echo "${OUTPUT}" | jq -r ".transactions[${TRAN}].payload") + T_VALUE_D=$(printf "%d\n" "${T_VALUE}") + if [ "${T_DEST}" == "${W_DEST}" ] && [ "${T_PAYLOAD}" != "te6ccgEBAQEAAgAAAA==" ]; then + # shellcheck disable=SC2086 + # shellcheck disable=SC2015 + ${L_PATH}tonos-cli call "${W_SOURCE}" confirmTransaction \ + '{"transactionId":"'${T_ID}'"}' \ + --abi ${L_PATH}SafeMultisigWallet.abi.json \ + --sign "${W_PHRASE}" && + f_output "${W_SOURCE};${T_ID};${T_DEST};${T_VALUE_D};Good;" || + f_output "${W_SOURCE};${T_ID};${T_DEST};${T_VALUE_D};Network_error;" + else + f_output "${W_SOURCE};${T_ID};${T_DEST};${T_VALUE_D};Bad" + fi + TRAN=$((TRAN + 1)) + done + fi +} + +# ========= MAIN + +# shellcheck disable=SC2207 +WALLETS=($(cat ${L_PATH}wallets.txt)) +WALLETS_NUM=$(wc -l ${L_PATH}wallets.txt | awk '{print $1}') +IFS=$'\n' +# shellcheck disable=SC2207 +PHRASES=($(cat ${L_PATH}/p.txt)) +for i in $(seq 0 $((WALLETS_NUM - 1))); do + f_check_trans "${WALLETS["$i"]}" -1:3333333333333333333333333333333333333333333333333333333333333333 "${PHRASES["$i"]}" +done diff --git a/scripts/confirmer/p.txt b/scripts/confirmer/p.txt new file mode 100644 index 0000000..1f6e8ca --- /dev/null +++ b/scripts/confirmer/p.txt @@ -0,0 +1,5 @@ +put your phrases there one by one +second passphrace for the wallet one +plus one +etc + diff --git a/scripts/confirmer/tonlabs-cli.conf.json b/scripts/confirmer/tonlabs-cli.conf.json new file mode 100644 index 0000000..7ada55e --- /dev/null +++ b/scripts/confirmer/tonlabs-cli.conf.json @@ -0,0 +1,12 @@ +{ + "url": "https://main.ton.dev", + "wc": 0, + "addr": null, + "wallet": null, + "abi_path": null, + "keys_path": null, + "retries": 5, + "timeout": 60000, + "is_json": false, + "depool_fee": 0.5 +} diff --git a/scripts/confirmer/wallets.txt b/scripts/confirmer/wallets.txt new file mode 100644 index 0000000..e40ed03 --- /dev/null +++ b/scripts/confirmer/wallets.txt @@ -0,0 +1,4 @@ +put your wallets there one by one +-1:xxx +-1:yyy +-1:zzz \ No newline at end of file diff --git a/scripts/create_wallet.sh b/scripts/create_wallet.sh index f9b4076..604032e 100755 --- a/scripts/create_wallet.sh +++ b/scripts/create_wallet.sh @@ -1,19 +1,5 @@ #!/bin/bash -eE -# Copyright 2020 TON DEV SOLUTIONS LTD. -# -# Licensed under the SOFTWARE EVALUATION License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at: -# -# https://www.ton.dev/licenses -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific TON DEV software governing permissions and limitations -# under the License - SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) # shellcheck source=env.sh . "${SCRIPT_DIR}/env.sh" diff --git a/scripts/deploy_wallet.sh b/scripts/deploy_wallet.sh index 759b1c0..310493c 100755 --- a/scripts/deploy_wallet.sh +++ b/scripts/deploy_wallet.sh @@ -1,19 +1,5 @@ #!/bin/bash -eE -# Copyright 2020 TON DEV SOLUTIONS LTD. -# -# Licensed under the SOFTWARE EVALUATION License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at: -# -# https://www.ton.dev/licenses -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific TON DEV software governing permissions and limitations -# under the License. - SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) # shellcheck source=env.sh . "${SCRIPT_DIR}/env.sh" diff --git a/scripts/env.sh b/scripts/env.sh index 984295e..5b47f85 100755 --- a/scripts/env.sh +++ b/scripts/env.sh @@ -1,19 +1,5 @@ #!/bin/bash -eE -# Copyright 2020 TON DEV SOLUTIONS LTD. -# -# Licensed under the SOFTWARE EVALUATION License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at: -# -# https://www.ton.dev/licenses -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific TON DEV software governing permissions and limitations -# under the License. - if [ "$DEBUG" = "yes" ] then set -x diff --git a/scripts/msig_genaddr.sh b/scripts/msig_genaddr.sh index 6577ad3..d0093bf 100755 --- a/scripts/msig_genaddr.sh +++ b/scripts/msig_genaddr.sh @@ -1,20 +1,5 @@ #!/bin/bash -eE -# Copyright 2020 TON DEV SOLUTIONS LTD. -# -# Licensed under the SOFTWARE EVALUATION License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at: -# -# https://www.ton.dev/licenses -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific TON DEV software governing permissions and limitations -# under the License. -# - SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) # shellcheck source=env.sh . "${SCRIPT_DIR}/env.sh" diff --git a/scripts/preinit.sh b/scripts/preinit.sh index 9835259..f797716 100755 --- a/scripts/preinit.sh +++ b/scripts/preinit.sh @@ -1,19 +1,5 @@ #!/bin/bash -eE -# Copyright 2020 TON DEV SOLUTIONS LTD. -# -# Licensed under the SOFTWARE EVALUATION License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at: -# -# https://www.ton.dev/licenses -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific TON DEV software governing permissions and limitations -# under the License. - SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) # shellcheck source=env.sh . "${SCRIPT_DIR}/env.sh" diff --git a/scripts/run.sh b/scripts/run.sh index 69711e8..9168d07 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -1,19 +1,5 @@ #!/bin/bash -eE -# Copyright 2020 TON DEV SOLUTIONS LTD. -# -# Licensed under the SOFTWARE EVALUATION License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at: -# -# https://www.ton.dev/licenses -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific TON DEV software governing permissions and limitations -# under the License. - SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) # shellcheck source=env.sh . "${SCRIPT_DIR}/env.sh" diff --git a/scripts/setup.sh b/scripts/setup.sh index cfe1267..db960e8 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -1,19 +1,5 @@ #!/bin/bash -eE -# Copyright 2020 TON DEV SOLUTIONS LTD. -# -# Licensed under the SOFTWARE EVALUATION License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at: -# -# https://www.ton.dev/licenses -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific TON DEV software governing permissions and limitations -# under the License. - SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) # shellcheck source=env.sh . "${SCRIPT_DIR}/env.sh" diff --git a/scripts/tonlabs-cli.conf.json b/scripts/tonlabs-cli.conf.json index 469cedd..7ada55e 100644 --- a/scripts/tonlabs-cli.conf.json +++ b/scripts/tonlabs-cli.conf.json @@ -1 +1,12 @@ -{"url":"https://main.ton.dev","wc":0,"addr":null,"abi_path":null,"keys_path":null} +{ + "url": "https://main.ton.dev", + "wc": 0, + "addr": null, + "wallet": null, + "abi_path": null, + "keys_path": null, + "retries": 5, + "timeout": 60000, + "is_json": false, + "depool_fee": 0.5 +} diff --git a/scripts/validator.sh b/scripts/validator.sh index 57e1f06..6c04a8e 100755 --- a/scripts/validator.sh +++ b/scripts/validator.sh @@ -1,19 +1,5 @@ #!/bin/bash -eE -# Copyright 2020 TON DEV SOLUTIONS LTD. -# -# Licensed under the SOFTWARE EVALUATION License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at: -# -# https://www.ton.dev/licenses -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific TON DEV software governing permissions and limitations -# under the License. - #DEBUG="yes" if [ "$DEBUG" = "yes" ]; then diff --git a/scripts/validator_msig.sh b/scripts/validator_msig.sh index 6dfefdc..1f07538 100755 --- a/scripts/validator_msig.sh +++ b/scripts/validator_msig.sh @@ -1,22 +1,7 @@ -#!/bin/bash -eEx +#!/bin/bash -eE set -o pipefail -# Copyright 2018-2020 TON DEV SOLUTIONS LTD. -# -# Licensed under the SOFTWARE EVALUATION License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at: -# -# https://www.ton.dev/licenses -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific TON DEV software governing permissions and limitations -# under the License. -# - if [ "$DEBUG" = "yes" ]; then set -x fi @@ -35,14 +20,13 @@ if [ -z "${STAKE}" ]; then exit 1 fi -TONOS_CLI_SEND_ATTEMPTS="100" +MAX_FACTOR=${MAX_FACTOR:-3} +TONOS_CLI_SEND_ATTEMPTS="10" MSIG_ADDR=$(cat "${KEYS_DIR}/${VALIDATOR_NAME}.addr") echo "INFO: MSIG_ADDR = ${MSIG_ADDR}" ELECTIONS_WORK_DIR="${KEYS_DIR}/elections" mkdir -p "${ELECTIONS_WORK_DIR}" -NANOSTAKE=$("${UTILS_DIR}/tonos-cli" convert tokens "$STAKE" | tail -1) - "${TON_BUILD_DIR}/lite-client/lite-client" \ -p "${KEYS_DIR}/liteserver.pub" \ -a 127.0.0.1:3031 \ @@ -69,52 +53,57 @@ awk '{ election_id=$(cat "${ELECTIONS_WORK_DIR}/election-id") -if [ "$election_id" == "0" ]; then - date +"INFO: %F %T No current elections" - - elector_addr=$(cat "${ELECTIONS_WORK_DIR}/elector-addr-base64") - - "${TON_BUILD_DIR}/lite-client/lite-client" \ - -p "${KEYS_DIR}/liteserver.pub" -a 127.0.0.1:3031 \ - -rc "runmethod ${elector_addr} compute_returned_stake 0x$(echo "${MSIG_ADDR}" | cut -d ':' -f 2)" \ - -rc "quit" &>"${ELECTIONS_WORK_DIR}/recover-state" - - awk '{ - if ($1 == "result:") { - print $3 - } - }' "${ELECTIONS_WORK_DIR}/recover-state" >"${ELECTIONS_WORK_DIR}/recover-amount" - - recover_amount=$(cat "${ELECTIONS_WORK_DIR}/recover-amount") - - if [ "$recover_amount" != "0" ]; then - "${TON_BUILD_DIR}/crypto/fift" -I "${TON_SRC_DIR}/crypto/fift/lib:${TON_SRC_DIR}/crypto/smartcont" -s recover-stake.fif "${ELECTIONS_WORK_DIR}/recover-query.boc" - - recover_query_boc=$(base64 --wrap=0 "${ELECTIONS_WORK_DIR}/recover-query.boc") +elector_addr=$(cat "${ELECTIONS_WORK_DIR}/elector-addr-base64") - for i in $(seq ${TONOS_CLI_SEND_ATTEMPTS}); do - echo "INFO: tonos-cli submitTransaction attempt #${i}..." - if ! "${UTILS_DIR}/tonos-cli" call "${MSIG_ADDR}" submitTransaction \ - "{\"dest\":\"${elector_addr}\",\"value\":\"1000000000\",\"bounce\":true,\"allBalance\":false,\"payload\":\"${recover_query_boc}\"}" \ - --abi "${CONFIGS_DIR}/SafeMultisigWallet.abi.json" \ - --sign "${KEYS_DIR}/msig.keys.json"; then - echo "INFO: tonos-cli submitTransaction attempt #${i}... FAIL" - else - echo "INFO: tonos-cli submitTransaction attempt #${i}... PASS" - break - fi - done +"${TON_BUILD_DIR}/lite-client/lite-client" \ + -p "${KEYS_DIR}/liteserver.pub" -a 127.0.0.1:3031 \ + -rc "runmethod ${elector_addr} compute_returned_stake 0x$(echo "${MSIG_ADDR}" | cut -d ':' -f 2)" \ + -rc "quit" &>"${ELECTIONS_WORK_DIR}/recover-state" - date +"INFO: %F %T Recover of $recover_amount GR requested" - fi +awk '{ + if ($1 == "result:") { + print $3 + } +}' "${ELECTIONS_WORK_DIR}/recover-state" >"${ELECTIONS_WORK_DIR}/recover-amount" + +recover_amount=$(cat "${ELECTIONS_WORK_DIR}/recover-amount") +echo "INFO: recover_amount = ${recover_amount} nanotokens" + +if [ "$recover_amount" != "0" ]; then + "${TON_BUILD_DIR}/crypto/fift" -I "${TON_SRC_DIR}/crypto/fift/lib:${TON_SRC_DIR}/crypto/smartcont" -s recover-stake.fif "${ELECTIONS_WORK_DIR}/recover-query.boc" + + recover_query_boc=$(base64 --wrap=0 "${ELECTIONS_WORK_DIR}/recover-query.boc") + + for i in $(seq ${TONOS_CLI_SEND_ATTEMPTS}); do + echo "INFO: tonos-cli submitTransaction attempt #${i}..." + set -x + if ! "${UTILS_DIR}/tonos-cli" call "${MSIG_ADDR}" submitTransaction \ + "{\"dest\":\"${elector_addr}\",\"value\":\"1000000000\",\"bounce\":true,\"allBalance\":false,\"payload\":\"${recover_query_boc}\"}" \ + --abi "${CONFIGS_DIR}/SafeMultisigWallet.abi.json" \ + --sign "${KEYS_DIR}/msig.keys.json"; then + echo "INFO: tonos-cli submitTransaction attempt #${i}... FAIL" + else + echo "INFO: tonos-cli submitTransaction attempt #${i}... PASS" + break + fi + set +x + done + + date +"INFO: %F %T Recover of $recover_amount GR requested" + exit 0 +else + echo "INFO: nothing to recover" +fi +if [ "$election_id" == "0" ]; then + date +"INFO: %F %T No current elections" echo "INFO: $(basename "$0") END $(date +%s) / $(date)" - exit + exit 0 fi if [ -f "${ELECTIONS_WORK_DIR}/stop-election" ]; then echo "INFO: $(basename "$0") END $(date +%s) / $(date)" - exit + exit 0 fi if [ -f "${ELECTIONS_WORK_DIR}/active-election-id" ]; then @@ -122,7 +111,7 @@ if [ -f "${ELECTIONS_WORK_DIR}/active-election-id" ]; then if [ "$active_election_id" = "$election_id" ]; then date +"INFO: %F %T Elections $election_id, already submitted" echo "INFO: $(basename "$0") END $(date +%s) / $(date)" - exit + exit 0 fi fi @@ -150,7 +139,8 @@ date +"INFO: %F %T Elections $election_id" &>"${ELECTIONS_WORK_DIR}/elector-params" awk -v validator="${VALIDATOR_NAME}" -v wallet_addr="$MSIG_ADDR" -v TON_BUILD_DIR="${TON_BUILD_DIR}" \ - -v KEYS_DIR="${KEYS_DIR}" -v ELECTIONS_WORK_DIR="${ELECTIONS_WORK_DIR}" -v TON_SRC_DIR="${TON_SRC_DIR}" '{ + -v KEYS_DIR="${KEYS_DIR}" -v ELECTIONS_WORK_DIR="${ELECTIONS_WORK_DIR}" -v TON_SRC_DIR="${TON_SRC_DIR}" \ + -v MAX_FACTOR="${MAX_FACTOR}" '{ if (NR == 1) { election_start = $1 + 0 } else if (($1 == "created") && ($2 == "new") && ($3 == "key")) { @@ -180,7 +170,7 @@ awk -v validator="${VALIDATOR_NAME}" -v wallet_addr="$MSIG_ADDR" -v TON_BUILD_DI printf TON_BUILD_DIR "/crypto/fift "; printf "-I " TON_SRC_DIR "/crypto/fift/lib:" TON_SRC_DIR "/crypto/smartcont "; printf "-s validator-elect-req.fif " wallet_addr; - printf " " election_start " 2 " key_adnl " " ELECTIONS_WORK_DIR "/validator-to-sign.bin "; + printf " " election_start " " MAX_FACTOR " " key_adnl " " ELECTIONS_WORK_DIR "/validator-to-sign.bin "; print "> " ELECTIONS_WORK_DIR "/" validator "-request-dump" } }' "${ELECTIONS_WORK_DIR}/election-id" "${ELECTIONS_WORK_DIR}/${VALIDATOR_NAME}-election-key" \ @@ -202,7 +192,7 @@ awk -v validator="${VALIDATOR_NAME}" -v TON_BUILD_DIR="${TON_BUILD_DIR}" -v KEYS bash "${ELECTIONS_WORK_DIR}/elector-run2" awk -v validator="${VALIDATOR_NAME}" -v wallet_addr="$MSIG_ADDR" -v TON_BUILD_DIR="${TON_BUILD_DIR}" \ - -v ELECTIONS_WORK_DIR="${ELECTIONS_WORK_DIR}" -v TON_SRC_DIR="${TON_SRC_DIR}" '{ + -v ELECTIONS_WORK_DIR="${ELECTIONS_WORK_DIR}" -v TON_SRC_DIR="${TON_SRC_DIR}" -v MAX_FACTOR="${MAX_FACTOR}" '{ if (NR == 1) { election_start = $1 + 0 } else if (($1 == "got") && ($2 == "public") && ($3 == "key:")) { @@ -212,7 +202,7 @@ awk -v validator="${VALIDATOR_NAME}" -v wallet_addr="$MSIG_ADDR" -v TON_BUILD_DI } else if (($1 == "created") && ($2 == "new") && ($3 == "key")) { printf TON_BUILD_DIR "/crypto/fift "; printf "-I " TON_SRC_DIR "/crypto/fift/lib:" TON_SRC_DIR "/crypto/smartcont "; - printf "-s validator-elect-signed.fif " wallet_addr " " election_start " 2 " $4; + printf "-s validator-elect-signed.fif " wallet_addr " " election_start " " MAX_FACTOR " " $4; printf " " key " " signature " " ELECTIONS_WORK_DIR "/validator-query.boc "; print "> " ELECTIONS_WORK_DIR "/" validator "-request-dump2" } @@ -224,8 +214,35 @@ bash "${ELECTIONS_WORK_DIR}/elector-run3" validator_query_boc=$(base64 --wrap=0 "${ELECTIONS_WORK_DIR}/validator-query.boc") elector_addr=$(cat "${ELECTIONS_WORK_DIR}/elector-addr-base64") +VALIDATOR_ACTUAL_BALANCE=$("${UTILS_DIR}/tonos-cli" account "${MSIG_ADDR}" | grep balance | awk '{print $2}') # in nano tokens +VALIDATOR_ACTUAL_BALANCE=$((VALIDATOR_ACTUAL_BALANCE / 1000000000)) # in tokens +echo "INFO: ${MSIG_ADDR} VALIDATOR_ACTUAL_BALANCE = ${VALIDATOR_ACTUAL_BALANCE} tokens" + +echo "INFO: STAKE = $STAKE tokens" + +if [ "$STAKE" -ge ${VALIDATOR_ACTUAL_BALANCE} ]; then + echo "ERROR: not enough tokens in ${MSIG_ADDR} wallet" + echo "INFO: VALIDATOR_ACTUAL_BALANCE = ${VALIDATOR_ACTUAL_BALANCE}" + echo "INFO: $(basename "$0") END $(date +%s) / $(date)" + exit 1 +fi + +MIN_STAKE=$("${TON_BUILD_DIR}/lite-client/lite-client" -p "${KEYS_DIR}/liteserver.pub" -a 127.0.0.1:3031 \ + -rc 'getconfig 17' -rc quit 2>&1 | grep -C 1 min_stake | grep value | awk -F: '{print $4}' | tr -d ')') # in nanotokens +MIN_STAKE=$((MIN_STAKE / 1000000000)) # in tokens +echo "INFO: MIN_STAKE = ${MIN_STAKE} tokens" + +if [ "$STAKE" -lt "${MIN_STAKE}" ]; then + echo "ERROR: STAKE ($STAKE tokens) is less than MIN_STAKE (${MIN_STAKE} tokens)" + exit 1 +fi + +NANOSTAKE=$("${UTILS_DIR}/tonos-cli" convert tokens "$STAKE" | tail -1) +echo "INFO: NANOSTAKE = $NANOSTAKE nanotokens" + for i in $(seq ${TONOS_CLI_SEND_ATTEMPTS}); do echo "INFO: tonos-cli submitTransaction attempt #${i}..." + set -x if ! "${UTILS_DIR}/tonos-cli" call "${MSIG_ADDR}" submitTransaction \ "{\"dest\":\"${elector_addr}\",\"value\":\"${NANOSTAKE}\",\"bounce\":true,\"allBalance\":false,\"payload\":\"${validator_query_boc}\"}" \ --abi "${CONFIGS_DIR}/SafeMultisigWallet.abi.json" \ @@ -235,6 +252,7 @@ for i in $(seq ${TONOS_CLI_SEND_ATTEMPTS}); do echo "INFO: tonos-cli submitTransaction attempt #${i}... PASS" break fi + set +x done date +"INFO: %F %T prepared for elections"