diff options
author | Riccardo Spagni <ric@spagni.net> | 2017-08-15 20:44:44 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2017-08-15 20:44:44 +0200 |
commit | 68ccc10b290606eb272333113b1aaa2e27c4b525 (patch) | |
tree | 8c543da8d13a5b0b8a94ef09193ea53ae0353aa3 /src/simplewallet | |
parent | Merge pull request #2295 (diff) | |
parent | wallet: return unlock_time in get_transfers (diff) | |
download | monero-68ccc10b290606eb272333113b1aaa2e27c4b525.tar.xz |
Merge pull request #2205
c97d1bd3 wallet: return unlock_time in get_transfers (moneromooo-monero)
Diffstat (limited to 'src/simplewallet')
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 596c298d7..940007635 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -3867,6 +3867,22 @@ static std::string get_human_readable_timestamp(uint64_t ts) return std::string(buffer); } //---------------------------------------------------------------------------------------------------- +static std::string get_human_readable_timespan(std::chrono::seconds seconds) +{ + uint64_t ts = seconds.count(); + if (ts < 60) + return std::to_string(ts) + tr(" seconds"); + if (ts < 3600) + return std::to_string((uint64_t)(ts / 60)) + tr(" minutes"); + if (ts < 3600 * 24) + return std::to_string((uint64_t)(ts / 3600)) + tr(" hours"); + if (ts < 3600 * 24 * 30.5) + return std::to_string((uint64_t)(ts / (3600 * 24))) + tr(" days"); + if (ts < 3600 * 24 * 365.25) + return std::to_string((uint64_t)(ts / (3600 * 24 * 365.25))) + tr(" months"); + return tr("a long time"); +} +//---------------------------------------------------------------------------------------------------- bool simple_wallet::show_transfers(const std::vector<std::string> &args_) { std::vector<std::string> local_args = args_; @@ -4673,6 +4689,8 @@ bool simple_wallet::show_transfer(const std::vector<std::string> &args) } crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data()); + const uint64_t last_block_height = m_wallet->get_blockchain_current_height(); + std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments; m_wallet->get_payments(payments, 0); for (std::list<std::pair<crypto::hash, tools::wallet2::payment_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) { @@ -4687,6 +4705,23 @@ bool simple_wallet::show_transfer(const std::vector<std::string> &args) success_msg_writer() << "Timestamp: " << get_human_readable_timestamp(pd.m_timestamp); success_msg_writer() << "Amount: " << print_money(pd.m_amount); success_msg_writer() << "Payment ID: " << payment_id; + if (pd.m_unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER) + { + uint64_t bh = std::max(pd.m_unlock_time, pd.m_block_height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE); + if (bh >= last_block_height) + success_msg_writer() << "Locked: " << (bh - last_block_height) << " blocks to unlock"; + else + success_msg_writer() << std::to_string(last_block_height - bh) << " confirmations"; + } + else + { + uint64_t current_time = static_cast<uint64_t>(time(NULL)); + uint64_t threshold = current_time + (m_wallet->use_fork_rules(2, 0) ? CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V2 : CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V1); + if (threshold >= pd.m_unlock_time) + success_msg_writer() << "unlocked for " << get_human_readable_timespan(std::chrono::seconds(threshold - pd.m_unlock_time)); + else + success_msg_writer() << "locked for " << get_human_readable_timespan(std::chrono::seconds(pd.m_unlock_time - threshold)); + } success_msg_writer() << "Note: " << m_wallet->get_tx_note(txid); return true; } |