timestamp changed to age

master
moneroexamples 9 years ago
parent f77c7ecfcd
commit 14c22abada

@ -48,6 +48,7 @@ namespace xmreg {
MicroCore* mcore; MicroCore* mcore;
Blockchain* core_storage; Blockchain* core_storage;
rpccalls rpc; rpccalls rpc;
time_t server_timestamp;
public: public:
@ -61,7 +62,7 @@ namespace xmreg {
index(bool refresh_page = false) index(bool refresh_page = false)
{ {
//get current server timestamp //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. // get the current blockchain height. Just to check if it reads ok.
// uint64_t height = core_storage->get_current_blockchain_height() - 1; // uint64_t height = core_storage->get_current_blockchain_height() - 1;
@ -87,7 +88,6 @@ namespace xmreg {
time_t prev_blk_timestamp {0}; time_t prev_blk_timestamp {0};
// iterate over last no_of_last_blocks of blocks // 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) for (size_t i = height - no_of_last_blocks; i <= height; ++i)
{ {
// get block at the given height i // get block at the given height i
@ -98,14 +98,19 @@ namespace xmreg {
// get block's hash // get block's hash
crypto::hash blk_hash = core_storage->get_block_id_by_height(i); 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_minutes {0};
uint64_t delta_seconds {0}; uint64_t delta_seconds {0};
if (prev_blk_timestamp > 0) if (prev_blk_timestamp > 0)
{ {
// array<size_t, 5> delta_time = timestamp_difference(
// prev_blk_timestamp, blk.timestamp);
array<size_t, 5> delta_time = timestamp_difference( array<size_t, 5> delta_time = timestamp_difference(
prev_blk_timestamp, blk.timestamp); server_timestamp, blk.timestamp);
delta_hours = delta_time[2];
delta_minutes = delta_time[3]; delta_minutes = delta_time[3];
delta_seconds = delta_time[4]; delta_seconds = delta_time[4];
} }
@ -114,6 +119,10 @@ namespace xmreg {
+ fmt::format(" ({:02d}:{:02d})", + fmt::format(" ({:02d}:{:02d})",
delta_minutes, delta_seconds); delta_minutes, delta_seconds);
string age_str = fmt::format("{:02d}:{:02d}:{:02d}",
delta_hours, delta_minutes,
delta_seconds);
// get xmr in the block reward // get xmr in the block reward
array<uint64_t, 2> coinbase_tx = sum_money_in_tx(blk.miner_tx); array<uint64_t, 2> coinbase_tx = sum_money_in_tx(blk.miner_tx);
@ -157,6 +166,7 @@ namespace xmreg {
blocks.push_back(mstch::map { blocks.push_back(mstch::map {
{"height" , to_string(i)}, {"height" , to_string(i)},
{"timestamp" , timestamp_str}, {"timestamp" , timestamp_str},
{"age" , age_str},
{"hash" , fmt::format("{:s}", blk_hash)}, {"hash" , fmt::format("{:s}", blk_hash)},
{"block_reward", fmt::format("{:0.4f} ({:0.4f})", {"block_reward", fmt::format("{:0.4f} ({:0.4f})",
XMR_AMOUNT(coinbase_tx[1]), XMR_AMOUNT(coinbase_tx[1]),
@ -233,21 +243,33 @@ namespace xmreg {
// get reference to blocks template map to be field below // get reference to blocks template map to be field below
mstch::array& txs = boost::get<mstch::array>(context["mempooltxs"]); mstch::array& txs = boost::get<mstch::array>(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 each transaction in the memory pool
for (size_t i = 0; i < res.transactions.size(); ++i) for (size_t i = 0; i < res.transactions.size(); ++i)
{ {
// get transaction info of the tx in the mempool // 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 array<size_t, 5> delta_time = timestamp_difference(
//fmt::print("Tx hash: {:s}\n", _tx_info.id_hash); server_timestamp, _tx_info.receive_time);
// fmt::print("Fee: {:0.10f} xmr, size {:d} bytes\n", uint64_t delta_hours {delta_time[1]*24 + delta_time[2]};
// XMR_AMOUNT(_tx_info.fee),
// _tx_info.blob_size);
// fmt::print("Receive time: {:s}\n", string age_str = fmt::format("{:02d}:{:02d}:{:02d}",
// xmreg::timestamp_to_str(_tx_info.receive_time)); 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_inputs = sum_xmr_inputs(_tx_info.tx_json);
uint64_t sum_outputs = sum_xmr_outputs(_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 // set output page template map
txs.push_back(mstch::map { txs.push_back(mstch::map {
{"timestamp" , xmreg::timestamp_to_str(_tx_info.receive_time)}, {"timestamp" , xmreg::timestamp_to_str(_tx_info.receive_time)},
{"hash" , fmt::format("<{:s}>", _tx_info.id_hash)}, {"age" , age_str},
{"fee" , fmt::format("{:0.4f}", XMR_AMOUNT(_tx_info.fee))}, {"hash" , fmt::format("<{:s}>", _tx_info.id_hash)},
{"xmr_inputs" , fmt::format("{:0.2f}", XMR_AMOUNT(sum_inputs))}, {"fee" , fmt::format("{:0.4f}", XMR_AMOUNT(_tx_info.fee))},
{"xmr_outputs" , fmt::format("{:0.2f}", XMR_AMOUNT(sum_outputs))}, {"xmr_inputs" , fmt::format("{:0.2f}", XMR_AMOUNT(sum_inputs))},
{"mixin" , fmt::format("{:d}", mixin_numbers.at(0))}, {"xmr_outputs" , fmt::format("{:0.2f}", XMR_AMOUNT(sum_outputs))},
{"txsize", fmt::format("{:0.2f}", static_cast<double>(_tx_info.blob_size)/1024.0)} {"mixin" , fmt::format("{:d}", mixin_numbers.at(0))},
{"txsize" , fmt::format("{:0.2f}", static_cast<double>(_tx_info.blob_size)/1024.0)}
}); });
} }
@ -278,6 +301,7 @@ namespace xmreg {
private: private:
uint64_t uint64_t
sum_xmr_outputs(const string& json_str) sum_xmr_outputs(const string& json_str)
{ {

@ -21,7 +21,7 @@
<table class="center"> <table class="center">
<tr> <tr>
<td>height</td> <td>height</td>
<td>timestamp_(Δ mm:ss)</td> <td>Age (h:m:s)</td>
<td>block hash</td> <td>block hash</td>
<td>reward (fees)</td> <td>reward (fees)</td>
<td>no_of_txs</td> <td>no_of_txs</td>
@ -32,7 +32,7 @@
{{#blocks}} {{#blocks}}
<tr> <tr>
<td>{{height}}</td> <td>{{height}}</td>
<td>{{timestamp}}</td> <td>{{age}}</td>
<td>{{hash}}</td> <td>{{hash}}</td>
<td>{{block_reward}}</td> <td>{{block_reward}}</td>
<td>{{notx}}</td> <td>{{notx}}</td>

@ -5,8 +5,7 @@
<table class="center"> <table class="center">
<tr> <tr>
<td>height</td> <td>Age (h:m:s)</td>
<td>timestamp</td>
<td>tx hash</td> <td>tx hash</td>
<td>tx fee</td> <td>tx fee</td>
<td>inputs/outputs</td> <td>inputs/outputs</td>
@ -15,8 +14,7 @@
</tr> </tr>
{{#mempooltxs}} {{#mempooltxs}}
<tr> <tr>
<td>N/A</td> <td>{{age}}</td>
<td>{{timestamp}}</td>
<td>{{hash}}</td> <td>{{hash}}</td>
<td>{{fee}}</td> <td>{{fee}}</td>
<td>{{xmr_inputs}}/{{xmr_outputs}}</td> <td>{{xmr_inputs}}/{{xmr_outputs}}</td>

Loading…
Cancel
Save