Skip to content

Commit

Permalink
fix: Do reserve proof check before hour wait
Browse files Browse the repository at this point in the history
Do reserve proof check before hour wait, this way they dont wait for an unnecessary hour
  • Loading branch information
zachhildreth committed Mar 26, 2021
1 parent fa66a2c commit fe6a078
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 114 deletions.
86 changes: 43 additions & 43 deletions src/simplewallet/simplewallet.cpp
Expand Up @@ -2386,31 +2386,6 @@ bool simple_wallet::vote(const std::vector<std::string>& 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);

Expand Down Expand Up @@ -2450,6 +2425,31 @@ bool simple_wallet::vote(const std::vector<std::string>& 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();

Expand Down Expand Up @@ -3169,6 +3169,24 @@ bool simple_wallet::revote(const std::vector<std::string>& 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);

Expand All @@ -3194,24 +3212,6 @@ bool simple_wallet::revote(const std::vector<std::string>& 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();

Expand Down
50 changes: 25 additions & 25 deletions src/wallet/api/wallet.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down
92 changes: 46 additions & 46 deletions src/wallet/wallet_rpc_server.cpp
Expand Up @@ -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);

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);

Expand All @@ -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();

Expand Down

0 comments on commit fe6a078

Please sign in to comment.