From 14c22abada6ee16f80efb0fe180a13816f8349f1 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Wed, 13 Apr 2016 15:00:07 +0800 Subject: [PATCH] timestamp changed to age --- src/page.h | 60 ++++++++++++++++++++++++++------------ src/templates/index.html | 4 +-- src/templates/mempool.html | 8 ++--- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/page.h b/src/page.h index 4bd6130..c919ea3 100644 --- a/src/page.h +++ b/src/page.h @@ -48,6 +48,7 @@ namespace xmreg { MicroCore* mcore; Blockchain* core_storage; rpccalls rpc; + time_t server_timestamp; public: @@ -61,7 +62,7 @@ namespace xmreg { index(bool refresh_page = false) { //get current server timestamp - time_t server_timestamp = std::time(nullptr); + server_timestamp = std::time(nullptr); // get the current blockchain height. Just to check if it reads ok. // uint64_t height = core_storage->get_current_blockchain_height() - 1; @@ -87,7 +88,6 @@ namespace xmreg { time_t prev_blk_timestamp {0}; // iterate over last no_of_last_blocks of blocks - //for (size_t i = height; i > height - no_of_last_blocks; --i) for (size_t i = height - no_of_last_blocks; i <= height; ++i) { // get block at the given height i @@ -98,14 +98,19 @@ namespace xmreg { // get block's hash crypto::hash blk_hash = core_storage->get_block_id_by_height(i); + uint64_t delta_hours {0}; uint64_t delta_minutes {0}; uint64_t delta_seconds {0}; if (prev_blk_timestamp > 0) { +// array delta_time = timestamp_difference( +// prev_blk_timestamp, blk.timestamp); + array delta_time = timestamp_difference( - prev_blk_timestamp, blk.timestamp); + server_timestamp, blk.timestamp); + delta_hours = delta_time[2]; delta_minutes = delta_time[3]; delta_seconds = delta_time[4]; } @@ -114,6 +119,10 @@ namespace xmreg { + fmt::format(" ({:02d}:{:02d})", delta_minutes, delta_seconds); + string age_str = fmt::format("{:02d}:{:02d}:{:02d}", + delta_hours, delta_minutes, + delta_seconds); + // get xmr in the block reward array coinbase_tx = sum_money_in_tx(blk.miner_tx); @@ -157,6 +166,7 @@ namespace xmreg { blocks.push_back(mstch::map { {"height" , to_string(i)}, {"timestamp" , timestamp_str}, + {"age" , age_str}, {"hash" , fmt::format("{:s}", blk_hash)}, {"block_reward", fmt::format("{:0.4f} ({:0.4f})", XMR_AMOUNT(coinbase_tx[1]), @@ -233,21 +243,33 @@ namespace xmreg { // get reference to blocks template map to be field below mstch::array& txs = boost::get(context["mempooltxs"]); + // std::sort(res.transactions.begin(), res.transactions.end(), + // [](const tx_info& _tx_info1, const tx_info& _tx_info2) + // { + // return _tx_info1.receive_time > _tx_info2.receive_time; + // }); + // for each transaction in the memory pool for (size_t i = 0; i < res.transactions.size(); ++i) { // get transaction info of the tx in the mempool - cryptonote::tx_info _tx_info = res.transactions.at(i); + tx_info _tx_info = res.transactions.at(i); - // display basic info - //fmt::print("Tx hash: {:s}\n", _tx_info.id_hash); + array delta_time = timestamp_difference( + server_timestamp, _tx_info.receive_time); - // fmt::print("Fee: {:0.10f} xmr, size {:d} bytes\n", - // XMR_AMOUNT(_tx_info.fee), - // _tx_info.blob_size); + uint64_t delta_hours {delta_time[1]*24 + delta_time[2]}; - // fmt::print("Receive time: {:s}\n", - // xmreg::timestamp_to_str(_tx_info.receive_time)); + string age_str = fmt::format("{:02d}:{:02d}:{:02d}", + delta_hours, + delta_time[3], delta_time[4]); + + if (delta_hours > 99) + { + age_str = fmt::format("{:03d}:{:02d}:{:02d}", + delta_hours, + delta_time[3], delta_time[4]); + } uint64_t sum_inputs = sum_xmr_inputs(_tx_info.tx_json); uint64_t sum_outputs = sum_xmr_outputs(_tx_info.tx_json); @@ -258,13 +280,14 @@ namespace xmreg { // set output page template map txs.push_back(mstch::map { - {"timestamp" , xmreg::timestamp_to_str(_tx_info.receive_time)}, - {"hash" , fmt::format("<{:s}>", _tx_info.id_hash)}, - {"fee" , fmt::format("{:0.4f}", XMR_AMOUNT(_tx_info.fee))}, - {"xmr_inputs" , fmt::format("{:0.2f}", XMR_AMOUNT(sum_inputs))}, - {"xmr_outputs" , fmt::format("{:0.2f}", XMR_AMOUNT(sum_outputs))}, - {"mixin" , fmt::format("{:d}", mixin_numbers.at(0))}, - {"txsize", fmt::format("{:0.2f}", static_cast(_tx_info.blob_size)/1024.0)} + {"timestamp" , xmreg::timestamp_to_str(_tx_info.receive_time)}, + {"age" , age_str}, + {"hash" , fmt::format("<{:s}>", _tx_info.id_hash)}, + {"fee" , fmt::format("{:0.4f}", XMR_AMOUNT(_tx_info.fee))}, + {"xmr_inputs" , fmt::format("{:0.2f}", XMR_AMOUNT(sum_inputs))}, + {"xmr_outputs" , fmt::format("{:0.2f}", XMR_AMOUNT(sum_outputs))}, + {"mixin" , fmt::format("{:d}", mixin_numbers.at(0))}, + {"txsize" , fmt::format("{:0.2f}", static_cast(_tx_info.blob_size)/1024.0)} }); } @@ -278,6 +301,7 @@ namespace xmreg { private: + uint64_t sum_xmr_outputs(const string& json_str) { diff --git a/src/templates/index.html b/src/templates/index.html index 9f821ae..2695902 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -21,7 +21,7 @@ - + @@ -32,7 +32,7 @@ {{#blocks}} - + diff --git a/src/templates/mempool.html b/src/templates/mempool.html index aa3c7ae..05b9440 100644 --- a/src/templates/mempool.html +++ b/src/templates/mempool.html @@ -4,9 +4,8 @@
heighttimestamp_(Δ mm:ss)Age (h:m:s) block hash reward (fees) no_of_txs
{{height}}{{timestamp}}{{age}} {{hash}} {{block_reward}} {{notx}}
- - - + + @@ -15,8 +14,7 @@ {{#mempooltxs}} - - +
heighttimestamp
Age (h:m:s) tx hash tx fee inputs/outputs
N/A{{timestamp}}{{age}} {{hash}} {{fee}} {{xmr_inputs}}/{{xmr_outputs}}