diff options
author | tom <tewinget@gmail.com> | 2014-06-16 21:52:06 -0400 |
---|---|---|
committer | Thomas Winget <tewinget@gmail.com> | 2014-06-30 07:16:50 -0400 |
commit | 62109840d68d6eb439a4861bf38c64d6a857deb8 (patch) | |
tree | 9b0ff721ff50c26a664ada595e1679c6a0a5803c /src | |
parent | Added confirmation prompt if transactions are to be split (diff) | |
download | monero-62109840d68d6eb439a4861bf38c64d6a857deb8.tar.xz |
Transaction splitting *seems* to be working!!!
Diffstat (limited to 'src')
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 27 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 3 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 69aade89d..631f9d4b8 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -812,15 +812,21 @@ std::vector<std::vector<cryptonote::tx_destination_entry>> simple_wallet::split_ cryptonote::tx_destination_entry de; uint64_t amount; - amount = dsts[j].amount / num_splits; + amount = dsts[j].amount; + std::cout << "Amount before split: " << amount << "; num_splits: " << num_splits; + amount = amount / num_splits; + std::cout << "; amount after split: " << amount; // if last split, add remainder if (i + 1 == num_splits) { amount += dsts[j].amount % num_splits; + std::cout << "; amount after remainder: " << amount; } + std::cout << std::endl; de.addr = dsts[j].addr; + de.amount = amount; new_dsts.push_back(de); } @@ -839,13 +845,19 @@ std::vector<std::vector<cryptonote::tx_destination_entry>> simple_wallet::split_ void simple_wallet::create_transactions(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time, const uint64_t fee, const std::vector<uint8_t> extra) { // for now, limit to 5 attempts. TODO: discuss a good number to limit to. - const size_t MAX_ATTEMPTS = 30; + const size_t MAX_ATTEMPTS = 5; // failsafe split attempt counter size_t attempt_count = 0; - for(attempt_count = 1; attempt_count <= 5 ;attempt_count++) + for(attempt_count = 1; ;attempt_count++) { + if (attempt_count > 1) + { + std::string prompt = "Attempt #"; + prompt.append(std::to_string(attempt_count)); + command_line::input_line(prompt); + } auto split_values = split_amounts(dsts, attempt_count); // Throw if split_amounts comes back with a vector of size different than it should @@ -857,11 +869,12 @@ void simple_wallet::create_transactions(std::vector<cryptonote::tx_destination_e std::vector<tools::wallet2::pending_tx> ptx_vector; try { - for (size_t i=0; i < attempt_count; i++) + // for each new destination vector (i.e. for each new tx) + for (auto & dst_vector : split_values) { cryptonote::transaction tx; tools::wallet2::pending_tx ptx; - m_wallet->transfer(dsts, fake_outs_count, unlock_time, fee, extra, tx, ptx); + m_wallet->transfer(dst_vector, fake_outs_count, unlock_time, fee, extra, tx, ptx); ptx_vector.push_back(ptx); // mark transfers to be used as "spent" @@ -884,7 +897,7 @@ void simple_wallet::create_transactions(std::vector<cryptonote::tx_destination_e if (attempt_count > 1) { std::string prompt_str = "Your transaction needs to be split into "; - prompt_str += attempt_count; + prompt_str += std::to_string(attempt_count); prompt_str += " transactions. This will result in a fee of "; prompt_str += print_money(attempt_count * DEFAULT_FEE); prompt_str += ". Is this okay? (Y/Yes/N/No)"; @@ -906,6 +919,8 @@ void simple_wallet::create_transactions(std::vector<cryptonote::tx_destination_e ptx_vector.pop_back(); } + return; + } // only catch this here, other exceptions need to pass through to the calling function catch (const tools::error::tx_too_big& e) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index e8b9ec46e..3cdfaa849 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -23,6 +23,7 @@ #include "wallet_errors.h" +#include <iostream> #define DEFAULT_TX_SPENDABLE_AGE 10 #define WALLET_RCP_CONNECTION_TIMEOUT 200000 @@ -329,6 +330,8 @@ namespace tools THROW_WALLET_EXCEPTION_IF(needed_money < dt.amount, error::tx_sum_overflow, dsts, fee); } + std::cout << "Attempting to create transaction, needed money = " << needed_money << std::endl; + // randomly select inputs for transaction // throw if requested send amount is greater than amount available to send std::list<transfer_container::iterator> selected_transfers; |