diff --git a/src/page.h b/src/page.h index d5d919b..a2e97c6 100644 --- a/src/page.h +++ b/src/page.h @@ -145,6 +145,8 @@ namespace xmreg { end_height = end_height - start_height > no_of_last_blocks ? no_of_last_blocks : end_height; + time_t prev_blk_timestamp {0}; + // iterate over last no_of_last_blocks of blocks for (uint64_t i = start_height; i <= end_height; ++i) { @@ -170,6 +172,15 @@ namespace xmreg { context["age_format"] = age.second; + // get time difference [m] between previous and current blocks + string time_delta_str {}; + + if (prev_blk_timestamp > 0) + { + time_delta_str = fmt::format("{:0.2f}", + (double(blk.timestamp) - double(prev_blk_timestamp))/60.0); + } + // get xmr in the block reward array coinbase_tx = sum_money_in_tx(blk.miner_tx); @@ -215,6 +226,7 @@ namespace xmreg { blocks.push_back(mstch::map { {"height" , to_string(i)}, {"timestamp" , timestamp_str}, + {"time_delta" , time_delta_str}, {"age" , age.first}, {"hash" , blk_hash_str}, {"block_reward", fmt::format("{:0.4f}/{:0.4f}", @@ -230,13 +242,17 @@ namespace xmreg { {"blksize" , fmt::format("{:0.2f}", static_cast(blk_size) / 1024.0)} }); + + // save current's block timestamp as reference for the next one + prev_blk_timestamp = blk.timestamp; + } // for (uint64_t i = start_height; i <= end_height; ++i) // reverse blocks and remove last (i.e., oldest) // block. This is done so that time delats // are easier to calcualte in the above for loop std::reverse(blocks.begin(), blocks.end()); - //blocks.pop_back(); + blocks.pop_back(); // get memory pool rendered template string mempool_html = mempool(); diff --git a/src/templates/index.html b/src/templates/index.html index dfc2ee2..46b0272 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -27,7 +27,7 @@ - + @@ -38,7 +38,7 @@ {{#blocks}} - +
heightage {{age_format}}age {{age_format}} (Δm) block hash txs fees
{{height}}{{age}}{{age}} ({{time_delta}}) {{hash}} {{notx}} {{fees}}