mirror of
https://github.com/monero-project/monero.git
synced 2026-07-28 14:47:15 -07:00
simplewallet: deduplicate human-readable timespan function
This commit is contained in:
@@ -275,6 +275,11 @@ namespace tools
|
||||
|
||||
std::string get_human_readable_timespan(uint64_t seconds);
|
||||
|
||||
inline std::string get_human_readable_timespan(std::chrono::seconds seconds)
|
||||
{
|
||||
return get_human_readable_timespan(static_cast<uint64_t>(seconds.count()));
|
||||
}
|
||||
|
||||
std::string get_human_readable_bytes(uint64_t bytes);
|
||||
|
||||
void clear_screen();
|
||||
|
||||
@@ -162,9 +162,6 @@ using tools::fee_priority;
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static std::string get_human_readable_timespan(std::chrono::seconds seconds);
|
||||
static std::string get_human_readable_timespan(uint64_t seconds);
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr std::array<std::string_view, 5> allowed_priority_strings = tools::fee_priority_utilities::fee_priority_strings;
|
||||
@@ -2251,7 +2248,7 @@ bool simple_wallet::public_nodes(const std::vector<std::string> &args)
|
||||
message_writer() << boost::format("%32s %16s") % tr("address") % tr("last_seen");
|
||||
for (const auto &node: nodes)
|
||||
{
|
||||
const std::string last_seen = node.last_seen == 0 ? tr("never") : get_human_readable_timespan(std::chrono::seconds(now - node.last_seen));
|
||||
const std::string last_seen = node.last_seen == 0 ? tr("never") : tools::get_human_readable_timespan(std::chrono::seconds(now - node.last_seen));
|
||||
std::string host = node.host + ":" + std::to_string(node.rpc_port);
|
||||
message_writer() << boost::format("%32s %16s") % host % last_seen;
|
||||
}
|
||||
@@ -5852,11 +5849,11 @@ bool simple_wallet::show_balance_unlocked(bool detailed)
|
||||
uint64_t unlocked_balance = m_wallet->unlocked_balance(m_current_subaddress_account, false, &blocks_to_unlock, &time_to_unlock);
|
||||
std::string unlock_time_message;
|
||||
if (blocks_to_unlock > 0 && time_to_unlock > 0)
|
||||
unlock_time_message = (boost::format(" (%lu block(s) and %s to unlock)") % blocks_to_unlock % get_human_readable_timespan(time_to_unlock)).str();
|
||||
unlock_time_message = (boost::format(" (%lu block(s) and %s to unlock)") % blocks_to_unlock % tools::get_human_readable_timespan(time_to_unlock)).str();
|
||||
else if (blocks_to_unlock > 0)
|
||||
unlock_time_message = (boost::format(" (%lu block(s) to unlock)") % blocks_to_unlock).str();
|
||||
else if (time_to_unlock > 0)
|
||||
unlock_time_message = (boost::format(" (%s to unlock)") % get_human_readable_timespan(time_to_unlock)).str();
|
||||
unlock_time_message = (boost::format(" (%s to unlock)") % tools::get_human_readable_timespan(time_to_unlock)).str();
|
||||
success_msg_writer() << tr("Balance: ") << print_money(m_wallet->balance(m_current_subaddress_account, false)) << ", "
|
||||
<< tr("unlocked balance: ") << print_money(unlocked_balance) << unlock_time_message << extra;
|
||||
std::map<uint32_t, uint64_t> balance_per_subaddress = m_wallet->balance_per_subaddress(m_current_subaddress_account, false);
|
||||
@@ -8385,27 +8382,6 @@ bool simple_wallet::check_reserve_proof(const std::vector<std::string> &args)
|
||||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
static std::string get_human_readable_timespan(std::chrono::seconds seconds)
|
||||
{
|
||||
uint64_t ts = seconds.count();
|
||||
if (ts < 60)
|
||||
return std::to_string(ts) + sw::tr(" seconds");
|
||||
if (ts < 3600)
|
||||
return std::to_string((uint64_t)(ts / 60)) + sw::tr(" minutes");
|
||||
if (ts < 3600 * 24)
|
||||
return std::to_string((uint64_t)(ts / 3600)) + sw::tr(" hours");
|
||||
if (ts < 3600 * 24 * 30.5)
|
||||
return std::to_string((uint64_t)(ts / (3600 * 24))) + sw::tr(" days");
|
||||
if (ts < 3600 * 24 * 365.25)
|
||||
return std::to_string((uint64_t)(ts / (3600 * 24 * 30.5))) + sw::tr(" months");
|
||||
return sw::tr("a long time");
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
static std::string get_human_readable_timespan(uint64_t seconds)
|
||||
{
|
||||
return get_human_readable_timespan(std::chrono::seconds(seconds));
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// mutates local_args as it parses and consumes arguments
|
||||
bool simple_wallet::get_transfers(std::vector<std::string>& local_args, std::vector<transfer_view>& transfers)
|
||||
{
|
||||
@@ -8514,7 +8490,7 @@ bool simple_wallet::get_transfers(std::vector<std::string>& local_args, std::vec
|
||||
const uint64_t adjusted_time = m_wallet->get_daemon_adjusted_time();
|
||||
uint64_t threshold = adjusted_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)
|
||||
locked_msg = get_human_readable_timespan(std::chrono::seconds(pd.m_unlock_time - threshold));
|
||||
locked_msg = tools::get_human_readable_timespan(std::chrono::seconds(pd.m_unlock_time - threshold));
|
||||
}
|
||||
}
|
||||
transfers.push_back({
|
||||
@@ -10259,9 +10235,9 @@ bool simple_wallet::show_transfer(const std::vector<std::string> &args)
|
||||
const uint64_t adjusted_time = m_wallet->get_daemon_adjusted_time();
|
||||
uint64_t threshold = adjusted_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));
|
||||
success_msg_writer() << "unlocked for " << tools::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() << "locked for " << tools::get_human_readable_timespan(std::chrono::seconds(pd.m_unlock_time - threshold));
|
||||
}
|
||||
success_msg_writer() << "Address index: " << pd.m_subaddr_index.minor;
|
||||
success_msg_writer() << "Note: " << m_wallet->get_tx_note(txid);
|
||||
@@ -10637,7 +10613,7 @@ void simple_wallet::list_mms_messages(const std::vector<mms::message> &messages)
|
||||
m.wallet_height %
|
||||
m.round %
|
||||
ms.message_state_to_string(m.state) %
|
||||
(tools::get_human_readable_timestamp(m.modified) + ", " + get_human_readable_timespan(std::chrono::seconds(now - m.modified)) + tr(" ago"));
|
||||
(tools::get_human_readable_timestamp(m.modified) + ", " + tools::get_human_readable_timespan(std::chrono::seconds(now - m.modified)) + tr(" ago"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10703,7 +10679,7 @@ void simple_wallet::show_message(const mms::message &m)
|
||||
message_writer() << tr("In/out: ") << ms.message_direction_to_string(m.direction);
|
||||
message_writer() << tr("Type: ") << ms.message_type_to_string(m.type);
|
||||
message_writer() << tr("State: ") << boost::format(tr("%s since %s, %s ago")) %
|
||||
ms.message_state_to_string(m.state) % tools::get_human_readable_timestamp(m.modified) % get_human_readable_timespan(std::chrono::seconds(now - m.modified));
|
||||
ms.message_state_to_string(m.state) % tools::get_human_readable_timestamp(m.modified) % tools::get_human_readable_timespan(std::chrono::seconds(now - m.modified));
|
||||
if (m.sent == 0)
|
||||
{
|
||||
message_writer() << tr("Sent: Never");
|
||||
@@ -10711,7 +10687,7 @@ void simple_wallet::show_message(const mms::message &m)
|
||||
else
|
||||
{
|
||||
message_writer() << boost::format(tr("Sent: %s, %s ago")) %
|
||||
tools::get_human_readable_timestamp(m.sent) % get_human_readable_timespan(std::chrono::seconds(now - m.sent));
|
||||
tools::get_human_readable_timestamp(m.sent) % tools::get_human_readable_timespan(std::chrono::seconds(now - m.sent));
|
||||
}
|
||||
message_writer() << tr("Authorized signer: ") << ms.signer_to_string(signer, 100);
|
||||
message_writer() << tr("Content size: ") << m.content.length() << tr(" bytes");
|
||||
|
||||
Reference in New Issue
Block a user