diff options
author | Riccardo Spagni <ric@spagni.net> | 2017-09-02 11:30:07 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2017-09-02 11:30:07 +0200 |
commit | e19b68b005ad75816b9f8d44dc2ad89aeef5390c (patch) | |
tree | 70c29e79ae2aadda10b3bd0c74dfea8a88e6749f /src/simplewallet | |
parent | Merge pull request #2342 (diff) | |
parent | simplewallet: new "fee" command to display fee information (diff) | |
download | monero-e19b68b005ad75816b9f8d44dc2ad89aeef5390c.tar.xz |
Merge pull request #2362
adce8ae4 simplewallet: new "fee" command to display fee information (moneromooo-monero)
Diffstat (limited to 'src/simplewallet')
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 69 | ||||
-rw-r--r-- | src/simplewallet/simplewallet.h | 1 |
2 files changed, 67 insertions, 3 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index e4b061529..857e2af6e 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -391,6 +391,61 @@ bool simple_wallet::payment_id(const std::vector<std::string> &args/* = std::vec return true; } +bool simple_wallet::print_fee_info(const std::vector<std::string> &args/* = std::vector<std::string>()*/) +{ + if (!try_connect_to_daemon()) + { + fail_msg_writer() << tr("Cannot connect to daemon"); + return true; + } + const uint64_t per_kb_fee = m_wallet->get_per_kb_fee(); + const uint64_t typical_size_kb = 13; + message_writer() << (boost::format(tr("Current fee is %s monero per kB")) % print_money(per_kb_fee)).str(); + + std::vector<uint64_t> fees; + for (uint32_t priority = 1; priority <= 4; ++priority) + { + uint64_t mult = m_wallet->get_fee_multiplier(priority); + fees.push_back(per_kb_fee * typical_size_kb * mult); + } + std::vector<std::pair<uint64_t, uint64_t>> blocks; + try + { + uint64_t base_size = typical_size_kb * 1024; + blocks = m_wallet->estimate_backlog(base_size, base_size + 1023, fees); + } + catch (const std::exception &e) + { + fail_msg_writer() << tr("Error: failed to estimate backlog array size: ") << e.what(); + return true; + } + if (blocks.size() != 4) + { + fail_msg_writer() << tr("Error: bad estimated backlog array size"); + return true; + } + + for (uint32_t priority = 1; priority <= 4; ++priority) + { + uint64_t nblocks_low = blocks[priority - 1].first; + uint64_t nblocks_high = blocks[priority - 1].second; + if (nblocks_low > 0) + { + std::string msg; + if (priority == m_wallet->get_default_priority() || (m_wallet->get_default_priority() == 0 && priority == 2)) + msg = tr(" (current)"); + uint64_t minutes_low = nblocks_low * DIFFICULTY_TARGET_V2 / 60, minutes_high = nblocks_high * DIFFICULTY_TARGET_V2 / 60; + if (nblocks_high == nblocks_low) + message_writer() << (boost::format(tr("%u block (%u minutes) backlog at priority %u%s")) % nblocks_low % minutes_low % priority % msg).str(); + else + message_writer() << (boost::format(tr("%u to %u block (%u to %u minutes) backlog at priority %u")) % nblocks_low % nblocks_high % minutes_low % minutes_high % priority).str(); + } + else + message_writer() << tr("No backlog at priority ") << priority; + } + return true; +} + bool simple_wallet::set_always_confirm_transfers(const std::vector<std::string> &args/* = std::vector<std::string>()*/) { const auto pwd_container = get_and_verify_password(); @@ -722,6 +777,7 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("show_transfer", boost::bind(&simple_wallet::show_transfer, this, _1), tr("Show information about a transfer to/from this address")); m_cmd_binder.set_handler("password", boost::bind(&simple_wallet::change_password, this, _1), tr("Change wallet password")); m_cmd_binder.set_handler("payment_id", boost::bind(&simple_wallet::payment_id, this, _1), tr("Generate a new random full size payment id - these will be unencrypted on the blockchain, see integrated_address for encrypted short payment ids")); + m_cmd_binder.set_handler("fee", boost::bind(&simple_wallet::print_fee_info, this, _1), tr("Print information about fee and current transaction backlog")); m_cmd_binder.set_handler("help", boost::bind(&simple_wallet::help, this, _1), tr("Show this help")); } //---------------------------------------------------------------------------------------------------- @@ -2462,9 +2518,16 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri } try { - uint64_t nblocks = m_wallet->estimate_backlog(size, fee); - if (nblocks > 0) - prompt << (boost::format(tr("There is currently a %u block backlog at that fee level. Is this okay? (Y/Yes/N/No)")) % nblocks).str(); + std::vector<std::pair<uint64_t, uint64_t>> nblocks = m_wallet->estimate_backlog(size, size, {fee}); + if (nblocks.size() != 1) + { + prompt << "Internal error checking for backlog. " << tr("Is this okay anyway? (Y/Yes/N/No): "); + } + else + { + if (nblocks[0].first > 0) + prompt << (boost::format(tr("There is currently a %u block backlog at that fee level. Is this okay? (Y/Yes/N/No)")) % nblocks[0].first).str(); + } } catch (const std::exception &e) { diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index eac4cbc99..079fae9f5 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -175,6 +175,7 @@ namespace cryptonote bool show_transfer(const std::vector<std::string> &args); bool change_password(const std::vector<std::string>& args); bool payment_id(const std::vector<std::string> &args); + bool print_fee_info(const std::vector<std::string> &args); uint64_t get_daemon_blockchain_height(std::string& err); bool try_connect_to_daemon(bool silent = false, uint32_t* version = nullptr); |