diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-04-05 19:26:37 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-04-05 20:16:05 +0100 |
commit | d662ab5cec0b72780d0c24a2ba299237780d2369 (patch) | |
tree | 4400f72d10cc5d1caaff25593e7d86ac5e6486df | |
parent | rpc: add a do_not_relay boolean to tx submission (diff) | |
download | monero-d662ab5cec0b72780d0c24a2ba299237780d2369.tar.xz |
rpc: print human readable time since received when printing pool
-rw-r--r-- | src/daemon/rpc_command_executor.cpp | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index 933c93ed7..630f2098c 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -70,6 +70,23 @@ namespace { << "difficulty: " << boost::lexical_cast<std::string>(header.difficulty) << std::endl << "reward: " << boost::lexical_cast<std::string>(header.reward); } + + std::string get_human_time_ago(time_t t, time_t now) + { + if (t == now) + return "now"; + time_t dt = t > now ? t - now : now - t; + std::string s; + if (dt < 90) + s = boost::lexical_cast<std::string>(dt) + " seconds"; + else if (dt < 90 * 60) + s = boost::lexical_cast<std::string>(dt/60) + " minutes"; + else if (dt < 36 * 3600) + s = boost::lexical_cast<std::string>(dt/3600) + " hours"; + else + s = boost::lexical_cast<std::string>(dt/(3600*24)) + " days"; + return s + " " + (t > now ? "in the future" : "ago"); + } } t_rpc_command_executor::t_rpc_command_executor( @@ -669,6 +686,7 @@ bool t_rpc_command_executor::print_transaction_pool_long() { } if (! res.transactions.empty()) { + const time_t now = time(NULL); tools::msg_writer() << "Transactions: "; for (auto & tx_info : res.transactions) { @@ -676,7 +694,7 @@ bool t_rpc_command_executor::print_transaction_pool_long() { << tx_info.tx_json << std::endl << "blob_size: " << tx_info.blob_size << std::endl << "fee: " << cryptonote::print_money(tx_info.fee) << std::endl - << "receive_time: " << tx_info.receive_time << std::endl + << "receive_time: " << tx_info.receive_time << " (" << get_human_time_ago(tx_info.receive_time, now) << ")" << std::endl << "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl << "max_used_block_height: " << tx_info.max_used_block_height << std::endl << "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl @@ -747,17 +765,21 @@ bool t_rpc_command_executor::print_transaction_pool_short() { { tools::msg_writer() << "Pool is empty" << std::endl; } - for (auto & tx_info : res.transactions) + else { - tools::msg_writer() << "id: " << tx_info.id_hash << std::endl - << "blob_size: " << tx_info.blob_size << std::endl - << "fee: " << cryptonote::print_money(tx_info.fee) << std::endl - << "receive_time: " << tx_info.receive_time << std::endl - << "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl - << "max_used_block_height: " << tx_info.max_used_block_height << std::endl - << "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl - << "last_failed_height: " << tx_info.last_failed_height << std::endl - << "last_failed_id: " << tx_info.last_failed_id_hash << std::endl; + const time_t now = time(NULL); + for (auto & tx_info : res.transactions) + { + tools::msg_writer() << "id: " << tx_info.id_hash << std::endl + << "blob_size: " << tx_info.blob_size << std::endl + << "fee: " << cryptonote::print_money(tx_info.fee) << std::endl + << "receive_time: " << tx_info.receive_time << " (" << get_human_time_ago(tx_info.receive_time, now) << ")" << std::endl + << "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl + << "max_used_block_height: " << tx_info.max_used_block_height << std::endl + << "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl + << "last_failed_height: " << tx_info.last_failed_height << std::endl + << "last_failed_id: " << tx_info.last_failed_id_hash << std::endl; + } } return true; |