From 91be33581a946d3eeb5d26d56af8319488a09e9d Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 3 Dec 2019 02:18:45 +0100 Subject: [PATCH] added command to simplewallet for printing output distribution --- src/simplewallet/simplewallet.cpp | 13 +++++++++++++ src/simplewallet/simplewallet.h | 1 + src/wallet/wallet2.cpp | 10 ++++++++++ src/wallet/wallet2.h | 1 + 4 files changed, 25 insertions(+) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 98cd5ba6..87532a6a 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -207,6 +207,7 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("fix_collisions", boost::bind(&simple_wallet::fix_collisions, this, _1), "Rescan transfers for key image collisions"); m_cmd_binder.set_handler("scan_transfers_for_id", boost::bind(&simple_wallet::scan_transfers_for_id, this, _1), "Rescan transfers for tx_id"); m_cmd_binder.set_handler("scan_transfers_for_ki", boost::bind(&simple_wallet::scan_transfers_for_ki, this, _1), "Rescan transfers for key image"); + m_cmd_binder.set_handler("print_utxo_distribution", boost::bind(&simple_wallet::print_utxo_distribution, this, _1), "Prints utxo distribution"); m_cmd_binder.set_handler("address", boost::bind(&simple_wallet::print_address, this, _1), "Show current wallet public address"); m_cmd_binder.set_handler("integrated_address", boost::bind(&simple_wallet::integrated_address, this, _1), "integrated_address [| &args) print_td_list(td); return true; } +//---------------------------------------------------------------------------------------------------- +bool simple_wallet::print_utxo_distribution(const std::vector &args) +{ + std::map distribution; + m_wallet->get_utxo_distribution(distribution); + for (auto& e : distribution) + { + message_writer() << std::left << setw(25) << print_money(e.first) << "|" << e.second; + } + return true; +} + //---------------------------------------------------------------------------------------------------- bool simple_wallet::get_transfer_info(const std::vector &args) { diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 34ba13b2..91fccfd3 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -67,6 +67,7 @@ namespace currency bool fix_collisions(const std::vector &args ); bool scan_transfers_for_id(const std::vector &args); bool scan_transfers_for_ki(const std::vector &args); + bool print_utxo_distribution(const std::vector &args); bool show_blockchain_height(const std::vector &args); bool show_wallet_bcheight(const std::vector &args); bool transfer(const std::vector &args); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 3e18a9ea..996b50fa 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2442,6 +2442,16 @@ void wallet2::sign_transfer_files(const std::string& tx_sources_file, const std: THROW_IF_FALSE_WALLET_CMN_ERR_EX(r, "failed to store signed tx to file " << signed_tx_file); } //---------------------------------------------------------------------------------------------------- +bool wallet2::get_utxo_distribution(std::map& distribution) +{ + prepare_free_transfers_cache(0); + for (auto ent : m_found_free_amounts) + { + distribution[ent.first] = ent.second.size(); + } + return true; +} +//---------------------------------------------------------------------------------------------------- void wallet2::submit_transfer(const std::string& signed_tx_blob, currency::transaction& tx) { // decrypt sources diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 74c5e00f..382bac78 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -740,6 +740,7 @@ namespace tools std::string get_log_prefix() const { return m_log_prefix; } static uint64_t get_max_unlock_time_from_receive_indices(const currency::transaction& tx, const money_transfer2_details& td); + bool get_utxo_distribution(std::map& distribution); private: void add_transfers_to_expiration_list(const std::vector& selected_transfers, uint64_t expiration, uint64_t change_amount, const crypto::hash& related_tx_id);