mirror of
https://github.com/monero-project/monero.git
synced 2026-01-10 04:05:24 -08:00
Merge pull request #2205
c97d1bd3 wallet: return unlock_time in get_transfers (moneromooo-monero)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user