diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index c8e89560206..08c6e0adef8 100755 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -2386,31 +2386,6 @@ bool simple_wallet::vote(const std::vector& args) // ask for the password SCOPED_WALLET_UNLOCK(); - // wait until the next valid data time - sync_minutes_and_seconds(1); - - // get the current block verifiers list - if ((string = get_current_block_verifiers_list()) == "") - { - fail_msg_writer() << tr("Failed to send the vote\n"); - return true; - } - - total_delegates = std::count(string.begin(), string.end(), '|') / 3; - if (total_delegates > BLOCK_VERIFIERS_AMOUNT) - { - total_delegates = BLOCK_VERIFIERS_AMOUNT; - } - total_delegates_valid_amount = ceil(total_delegates * BLOCK_VERIFIERS_VALID_AMOUNT_PERCENTAGE); - - // initialize the current_block_verifiers_list struct - for (count = 0, count2 = string.find("block_verifiers_IP_address_list")+35, count3 = 0; count < total_delegates; count++) - { - count3 = string.find("|",count2); - block_verifiers_IP_address[count] = string.substr(count2,count3 - count2); - count2 = count3 + 1; - } - // get the wallet transfers m_wallet->get_transfers(transfers); @@ -2450,6 +2425,31 @@ bool simple_wallet::vote(const std::vector& args) return true; } + // wait until the next valid data time + sync_minutes_and_seconds(1); + + // get the current block verifiers list + if ((string = get_current_block_verifiers_list()) == "") + { + fail_msg_writer() << tr("Failed to send the vote\n"); + return true; + } + + total_delegates = std::count(string.begin(), string.end(), '|') / 3; + if (total_delegates > BLOCK_VERIFIERS_AMOUNT) + { + total_delegates = BLOCK_VERIFIERS_AMOUNT; + } + total_delegates_valid_amount = ceil(total_delegates * BLOCK_VERIFIERS_VALID_AMOUNT_PERCENTAGE); + + // initialize the current_block_verifiers_list struct + for (count = 0, count2 = string.find("block_verifiers_IP_address_list")+35, count3 = 0; count < total_delegates; count++) + { + count3 = string.find("|",count2); + block_verifiers_IP_address[count] = string.substr(count2,count3 - count2); + count2 = count3 + 1; + } + // get the current block height current_block_height = m_wallet->get_blockchain_current_height(); @@ -3169,6 +3169,24 @@ bool simple_wallet::revote(const std::vector& args) return true; } + // create a reserve proof for the wallets balance + try + { + reserve_proof = m_wallet->get_reserve_proof(account_minreserve, ""); + } + catch (...) + { + fail_msg_writer() << tr("Failed to create the reserve proof"); + return true; + } + + // check if the reserve proof is not over the maximum length + if (reserve_proof.length() > BUFFER_SIZE_RESERVE_PROOF) + { + fail_msg_writer() << tr("Failed to revote\nReserve proof is over the maximum length"); + return true; + } + // wait until the next valid data time sync_minutes_and_seconds(1); @@ -3194,24 +3212,6 @@ bool simple_wallet::revote(const std::vector& args) count2 = count3 + 1; } - // create a reserve proof for the wallets balance - try - { - reserve_proof = m_wallet->get_reserve_proof(account_minreserve, ""); - } - catch (...) - { - fail_msg_writer() << tr("Failed to create the reserve proof"); - return true; - } - - // check if the reserve proof is not over the maximum length - if (reserve_proof.length() > BUFFER_SIZE_RESERVE_PROOF) - { - fail_msg_writer() << tr("Failed to revote\nReserve proof is over the maximum length"); - return true; - } - // get the current block height current_block_height = m_wallet->get_blockchain_current_height(); diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 7ae5fc03bd5..5fbe5932e0d 100755 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -2649,31 +2649,7 @@ std::string WalletImpl::delegate_register(const std::string &delegate_name,cons try { - // wait until the next valid data time - sync_minutes_and_seconds(1); - - // get the current block verifiers list - if ((string = get_current_block_verifiers_list()) == "") - { - return "Failed to send the vote with timeout"; - } - - total_delegates = std::count(string.begin(), string.end(), '|') / 3; - if (total_delegates > BLOCK_VERIFIERS_AMOUNT) - { - total_delegates = BLOCK_VERIFIERS_AMOUNT; - } - total_delegates_valid_amount = ceil(total_delegates * BLOCK_VERIFIERS_VALID_AMOUNT_PERCENTAGE); - - // initialize the current_block_verifiers_list struct - for (count = 0, count2 = string.find("block_verifiers_IP_address_list")+35, count3 = 0; count < total_delegates; count++) - { - count3 = string.find("|",count2); - block_verifiers_IP_address[count] = string.substr(count2,count3 - count2); - count2 = count3 + 1; - } - - // get the wallet transfers + // get the wallet transfers m_wallet->get_transfers(transfers); // get the wallets public address @@ -2709,6 +2685,30 @@ std::string WalletImpl::delegate_register(const std::string &delegate_name,cons return "Failed to send the vote\nReserve proof is over the maximum length"; } + // wait until the next valid data time + sync_minutes_and_seconds(1); + + // get the current block verifiers list + if ((string = get_current_block_verifiers_list()) == "") + { + return "Failed to send the vote with timeout"; + } + + total_delegates = std::count(string.begin(), string.end(), '|') / 3; + if (total_delegates > BLOCK_VERIFIERS_AMOUNT) + { + total_delegates = BLOCK_VERIFIERS_AMOUNT; + } + total_delegates_valid_amount = ceil(total_delegates * BLOCK_VERIFIERS_VALID_AMOUNT_PERCENTAGE); + + // initialize the current_block_verifiers_list struct + for (count = 0, count2 = string.find("block_verifiers_IP_address_list")+35, count3 = 0; count < total_delegates; count++) + { + count3 = string.find("|",count2); + block_verifiers_IP_address[count] = string.substr(count2,count3 - count2); + count2 = count3 + 1; + } + // get the current block height current_block_height = m_wallet->get_blockchain_current_height(); diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index b209956dea5..cb1af1d593a 100755 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -3499,32 +3499,6 @@ bool wallet_rpc_server::on_vote(const wallet_rpc::COMMAND_RPC_VOTE::request& req return false; } - // wait until the next valid data time - sync_minutes_and_seconds(1); - - // get the current block verifiers list - if ((string = get_current_block_verifiers_list()) == "") - { - er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS; - er.message = "Invalid address"; - return false; - } - - total_delegates = std::count(string.begin(), string.end(), '|') / 3; - if (total_delegates > BLOCK_VERIFIERS_AMOUNT) - { - total_delegates = BLOCK_VERIFIERS_AMOUNT; - } - total_delegates_valid_amount = ceil(total_delegates * BLOCK_VERIFIERS_VALID_AMOUNT_PERCENTAGE); - - // initialize the current_block_verifiers_list struct - for (count = 0, count2 = string.find("block_verifiers_IP_address_list")+35, count3 = 0; count < total_delegates; count++) - { - count3 = string.find("|",count2); - block_verifiers_IP_address[count] = string.substr(count2,count3 - count2); - count2 = count3 + 1; - } - // get the wallet transfers m_wallet->get_transfers(transfers); @@ -3567,6 +3541,32 @@ bool wallet_rpc_server::on_vote(const wallet_rpc::COMMAND_RPC_VOTE::request& req return false; } + // wait until the next valid data time + sync_minutes_and_seconds(1); + + // get the current block verifiers list + if ((string = get_current_block_verifiers_list()) == "") + { + er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS; + er.message = "Invalid address"; + return false; + } + + total_delegates = std::count(string.begin(), string.end(), '|') / 3; + if (total_delegates > BLOCK_VERIFIERS_AMOUNT) + { + total_delegates = BLOCK_VERIFIERS_AMOUNT; + } + total_delegates_valid_amount = ceil(total_delegates * BLOCK_VERIFIERS_VALID_AMOUNT_PERCENTAGE); + + // initialize the current_block_verifiers_list struct + for (count = 0, count2 = string.find("block_verifiers_IP_address_list")+35, count3 = 0; count < total_delegates; count++) + { + count3 = string.find("|",count2); + block_verifiers_IP_address[count] = string.substr(count2,count3 - count2); + count2 = count3 + 1; + } + // get the current block height current_block_height = m_wallet->get_blockchain_current_height(); @@ -4239,6 +4239,26 @@ bool wallet_rpc_server::on_revote(const wallet_rpc::COMMAND_RPC_REVOTE::request& delegate_name = string.substr(15,string.find(",")-15); + // create a reserve proof for the wallets balance + try + { + reserve_proof = m_wallet->get_reserve_proof(account_minreserve, ""); + } + catch (...) + { + er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; + er.message = "Failed to revote"; + return false; + } + + // check if the reserve proof is not over the maximum length + if (reserve_proof.length() > BUFFER_SIZE_RESERVE_PROOF) + { + er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; + er.message = "Failed to revote, Invalid reserve proof length"; + return false; + } + // wait until the next valid data time sync_minutes_and_seconds(1); @@ -4265,26 +4285,6 @@ bool wallet_rpc_server::on_revote(const wallet_rpc::COMMAND_RPC_REVOTE::request& count2 = count3 + 1; } - // create a reserve proof for the wallets balance - try - { - reserve_proof = m_wallet->get_reserve_proof(account_minreserve, ""); - } - catch (...) - { - er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; - er.message = "Failed to revote"; - return false; - } - - // check if the reserve proof is not over the maximum length - if (reserve_proof.length() > BUFFER_SIZE_RESERVE_PROOF) - { - er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; - er.message = "Failed to revote, Invalid reserve proof length"; - return false; - } - // get the current block height current_block_height = m_wallet->get_blockchain_current_height();