diff options
author | tom <tewinget@gmail.com> | 2014-06-15 17:20:16 -0400 |
---|---|---|
committer | Thomas Winget <tewinget@gmail.com> | 2014-06-30 07:16:50 -0400 |
commit | 79e59d155b9873156180f3b2f8b696cf9b8d84ab (patch) | |
tree | 4a91014e3e0663eed667caff802e8411b993003a /src/simplewallet | |
parent | Added comments to wallet functions (diff) | |
download | monero-79e59d155b9873156180f3b2f8b696cf9b8d84ab.tar.xz |
working on dividing functions in prep for tx splitting
Diffstat (limited to 'src/simplewallet')
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 89 | ||||
-rw-r--r-- | src/simplewallet/simplewallet.h | 4 |
2 files changed, 84 insertions, 9 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 6af0de9f9..6ef3ec214 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -785,6 +785,86 @@ bool simple_wallet::show_blockchain_height(const std::vector<std::string>& args) fail_msg_writer() << "failed to get blockchain height: " << err; return true; } + +// split_amounts(vector<cryptonote::tx_destination_entry> dsts, size_t num_splits) +// +// split amount for each dst in dsts into num_splits parts +// and make num_splits new vector<crypt...> instances to hold these new amounts +vector<vector<cryptonote::tx_destination_entry>> simple_wallet::split_amounts( + vector<cryptonote::tx_destination_entry> dsts, size_t num_splits) +{ + vector<vector<cryptonote::tx_destination_entry>> retVal; + + if (num_splits <= 1) + { + retVal.push_back(dsts); + return retVal; + } + + // for each split required + for (size_t i=0; i < num_splits; i++) + { + vector<cryptonote::tx_destination_entry> new_dsts; + + // for each destination + for (size_t j=0; j < dsts.size(); j++) + { + cryptonote::tx_destination_entry de; + uint64_t amount; + + amount = dsts[j].amount / num_splits; + + // if last split, add remainder + if (i + 1 == num_splits) + { + amount += dsts[j].amount % num_splits; + } + + de.addr = dsts[j].addr; + + new_dsts.push_back(de); + } + + retVal.push_back(new_dsts); + } + + return retVal; +} + +//---------------------------------------------------------------------------------------------------- +// separated the call(s) to wallet2::transfer into their own function +// +// this function will make multiple calls to wallet2::transfer if multiple +// transactions will be required +void simple_wallet::create_transactions(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) +{ + // failsafe split attempt counter + size_t attempt_count = 0; + + for(attempt_count = 1;;attempt_count++) + { + try + { + vector<cryptonote::transaction> tx_vector; + for (size_t i=0; i < attempt_count; i++) + { + cryptonote::transaction tx; + m_wallet->transfer(dsts, fake_outs_count, 0, DEFAULT_FEE, extra, tx); + tx_vector.push_back(tx); + } + // if we made it this far, we're OK to actually send the transactions + } + success_msg_writer(true) << "Money successfully sent, transaction " << get_transaction_hash(tx); + // only catch this here, other exceptions need to pass through to the calling function + catch (const tools::error::tx_too_big& e) + { + cryptonote::transaction tx = e.tx(); + fail_msg_writer() << "transaction " << get_transaction_hash(e.tx()) << " is too big. Transaction size: " << + get_object_blobsize(e.tx()) << " bytes, transaction size limit: " << e.tx_size_limit() << " bytes"; + } + } +} + //---------------------------------------------------------------------------------------------------- bool simple_wallet::transfer(const std::vector<std::string> &args_) { @@ -851,9 +931,6 @@ bool simple_wallet::transfer(const std::vector<std::string> &args_) try { - cryptonote::transaction tx; - m_wallet->transfer(dsts, fake_outs_count, 0, DEFAULT_FEE, extra, tx); - success_msg_writer(true) << "Money successfully sent, transaction " << get_transaction_hash(tx); } catch (const tools::error::daemon_busy&) { @@ -899,12 +976,6 @@ bool simple_wallet::transfer(const std::vector<std::string> &args_) { fail_msg_writer() << e.what(); } - catch (const tools::error::tx_too_big& e) - { - cryptonote::transaction tx = e.tx(); - fail_msg_writer() << "transaction " << get_transaction_hash(e.tx()) << " is too big. Transaction size: " << - get_object_blobsize(e.tx()) << " bytes, transaction size limit: " << e.tx_size_limit() << " bytes"; - } catch (const tools::error::zero_destination&) { fail_msg_writer() << "one of destinations is zero"; diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 006cdd08e..2f0d17313 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -54,6 +54,10 @@ namespace cryptonote bool show_payments(const std::vector<std::string> &args); bool show_blockchain_height(const std::vector<std::string> &args); bool transfer(const std::vector<std::string> &args); + vector<vector<cryptonote::tx_destination_entry>> simple_wallet::split_amounts( + vector<cryptonote::tx_destination_entry> dsts, size_t num_splits + ); + void create_transactions(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); bool print_address(const std::vector<std::string> &args = std::vector<std::string>()); bool save(const std::vector<std::string> &args); bool set_log(const std::vector<std::string> &args); |