index2 corrected

master
moneroexamples 9 years ago
parent 9f8ead6323
commit 2effdc04eb

@ -109,7 +109,7 @@ int main(int ac, const char* av[]) {
([&]() { ([&]() {
uint64_t page_no {0}; uint64_t page_no {0};
bool refresh_page {true}; bool refresh_page {true};
return xmrblocks.index(page_no, refresh_page); return xmrblocks.index2(page_no, refresh_page);
}); });
// run the crow http server // run the crow http server

@ -100,18 +100,32 @@ namespace xmreg {
string pid_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", payment_id)); string pid_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", payment_id));
string pid8_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", payment_id8)); string pid8_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", payment_id8));
string mixin_str {"N/A"};
string fee_str {"N/A"};
string fee_short_str {"N/A"};
if (!input_key_imgs.empty())
{
mixin_str = std::to_string(mixin_no - 1);
fee_str = fmt::format("{:0.6f}", XMR_AMOUNT(fee));
fee_short_str = fmt::format("{:0.3f}", XMR_AMOUNT(fee));
}
//cout << "extra: " << extra_str << endl; //cout << "extra: " << extra_str << endl;
mstch::map txd_map { mstch::map txd_map {
{"hash" , tx_hash_str}, {"hash" , tx_hash_str},
{"pub_key" , tx_pk_str}, {"pub_key" , tx_pk_str},
{"tx_fee" , fmt::format("{:0.6f}", XMR_AMOUNT(fee))}, {"tx_fee" , fee_str},
{"tx_fee_short" , fee_short_str},
{"sum_inputs" , fmt::format("{:0.6f}", XMR_AMOUNT(xmr_inputs))}, {"sum_inputs" , fmt::format("{:0.6f}", XMR_AMOUNT(xmr_inputs))},
{"sum_outputs" , fmt::format("{:0.6f}", XMR_AMOUNT(xmr_outputs))}, {"sum_outputs" , fmt::format("{:0.6f}", XMR_AMOUNT(xmr_outputs))},
{"sum_inputs_short" , fmt::format("{:0.3f}", XMR_AMOUNT(xmr_inputs))},
{"sum_outputs_short" , fmt::format("{:0.3f}", XMR_AMOUNT(xmr_outputs))},
{"no_inputs" , input_key_imgs.size()}, {"no_inputs" , input_key_imgs.size()},
{"no_outputs" , output_pub_keys.size()}, {"no_outputs" , output_pub_keys.size()},
{"mixin" , std::to_string(mixin_no - 1)}, {"mixin" , mixin_str},
{"version" , std::to_string(version)}, {"version" , std::to_string(version)},
{"has_payment_id" , payment_id != null_hash}, {"has_payment_id" , payment_id != null_hash},
{"has_payment_id8" , payment_id8 != null_hash8}, {"has_payment_id8" , payment_id8 != null_hash8},
@ -119,7 +133,10 @@ namespace xmreg {
{"extra" , get_extra_str()}, {"extra" , get_extra_str()},
{"payment_id8" , pid8_str}, {"payment_id8" , pid8_str},
{"unlock_time" , std::to_string(unlock_time)}, {"unlock_time" , std::to_string(unlock_time)},
{"tx_size" , fmt::format("{:0.4f}", static_cast<double>(size)/1024.0)} {"tx_size" , fmt::format("{:0.4f}",
static_cast<double>(size)/1024.0)},
{"tx_size_short" , fmt::format("{:0.2f}",
static_cast<double>(size)/1024.0)}
}; };
@ -400,11 +417,11 @@ namespace xmreg {
server_timestamp = std::time(nullptr); server_timestamp = std::time(nullptr);
// number of last blocks to show // number of last blocks to show
uint64_t no_of_last_blocks {20 + 1}; uint64_t no_of_last_blocks {50 + 1};
// get the current blockchain height. Just to check // get the current blockchain height. Just to check
uint64_t height = uint64_t height =
xmreg::MyLMDB::get_blockchain_height(mcore->get_blkchain_path()); xmreg::MyLMDB::get_blockchain_height(mcore->get_blkchain_path()) - 1;
// initalise page tempate map with basic info about blockchain // initalise page tempate map with basic info about blockchain
mstch::map context { mstch::map context {
@ -427,6 +444,14 @@ namespace xmreg {
uint64_t start_height = height - no_of_last_blocks * (page_no + 1); uint64_t start_height = height - no_of_last_blocks * (page_no + 1);
uint64_t end_height = height - no_of_last_blocks * (page_no); uint64_t end_height = height - no_of_last_blocks * (page_no);
// check few conditions to make sure we are whithin the avaliable range
//@TODO its too messed up. needs to find cleaner way.
start_height = start_height > 0 ? start_height : 0;
end_height = end_height < height ? end_height : height;
start_height = start_height > end_height ? 0 : start_height;
end_height = end_height - start_height > no_of_last_blocks
? no_of_last_blocks : end_height;
// previous blk timestamp, initalised to lowest possible value // previous blk timestamp, initalised to lowest possible value
double prev_blk_timestamp {std::numeric_limits<double>::lowest()}; double prev_blk_timestamp {std::numeric_limits<double>::lowest()};
@ -459,7 +484,7 @@ namespace xmreg {
if (prev_blk_timestamp > std::numeric_limits<double>::lowest()) if (prev_blk_timestamp > std::numeric_limits<double>::lowest())
{ {
time_delta_str = fmt::format("{:0.2f}", time_delta_str = fmt::format("({:06.2f})",
(double(blk.timestamp) - double(prev_blk_timestamp))/60.0); (double(blk.timestamp) - double(prev_blk_timestamp))/60.0);
} }
@ -475,6 +500,8 @@ namespace xmreg {
continue; continue;
} }
uint64_t tx_i {0};
for (const cryptonote::transaction& tx : blk_txs) for (const cryptonote::transaction& tx : blk_txs)
{ {
tx_details txd = get_tx_details(tx); tx_details txd = get_tx_details(tx);
@ -487,9 +514,23 @@ namespace xmreg {
txd_map.insert({"time_delta", time_delta_str}); txd_map.insert({"time_delta", time_delta_str});
txd_map.insert({"age" , age.first}); txd_map.insert({"age" , age.first});
// do not show block info for other than
// first tx in the block
if (tx_i > 0)
{
txd_map["height"] = string("");
txd_map["age"] = string("");
txd_map["time_delta"] = string("");
}
txs.push_back(txd_map); txs.push_back(txd_map);
++tx_i;
} }
// save current's block timestamp as reference for the next one
prev_blk_timestamp = static_cast<double>(blk.timestamp);
} // for (uint64_t i = start_height; i <= end_height; ++i) } // for (uint64_t i = start_height; i <= end_height; ++i)
// reverse txs and remove last (i.e., oldest) // reverse txs and remove last (i.e., oldest)
@ -501,7 +542,7 @@ namespace xmreg {
// the last block, i.e. genesis one. // the last block, i.e. genesis one.
if (!(start_height < 2)) if (!(start_height < 2))
{ {
txs.pop_back(); //txs.pop_back();
} }
// get memory pool rendered template // get memory pool rendered template

@ -16,7 +16,7 @@
{{{mempool_info}}} {{{mempool_info}}}
{{#is_page_zero}} {{#is_page_zero}}
<h2>20 recent blocks<!--(height: {{height}})--></h2> <h2>Transactions in the last 50 blocks</h2>
{{/is_page_zero}} {{/is_page_zero}}
{{^is_page_zero}} {{^is_page_zero}}
<h2>older blocks<!--(height: {{height}})--></h2> <h2>older blocks<!--(height: {{height}})--></h2>
@ -31,20 +31,22 @@
<td>tx hash</td> <td>tx hash</td>
<td>fees</td> <td>fees</td>
<td>outputs</td> <td>outputs</td>
<td>mixins</td> <td>in/out</td>
<td>mixin</td>
<td>size [kB]</td> <td>size [kB]</td>
</tr> </tr>
{{#blocks}} {{#txs}}
<tr> <tr>
<td><a href="/block/{{height}}">{{height}}</a></td> <td><a href="/block/{{height}}">{{height}}</a></td>
<td>{{age}} ({{time_delta}})</td> <td>{{age}} {{time_delta}}</td>
<td><a href="/tx/{{hash}}">{{hash}}</a></td> <td><a href="/tx/{{hash}}">{{hash}}</a></td>
<td>{{fees}}</td> <td>{{tx_fee_short}}</td>
<td>{{sum_outputs}}</td> <td>{{sum_outputs_short}}</td>
<td>{{no_inputs}}/{{no_outputs}}</td>
<td>{{mixin}}</td> <td>{{mixin}}</td>
<td>{{tx_size}}</td> <td>{{tx_size_short}}</td>
</tr> </tr>
{{/blocks}} {{/txs}}
</table> </table>
<div class="center" style="text-align: center;"> <div class="center" style="text-align: center;">

Loading…
Cancel
Save