dev of show_block started

master
moneroexamples 9 years ago
parent cb7f080355
commit 76fc7594a9

@ -1 +1 @@
# crow-monero-test # Onion Monero Blockchain Explorer

@ -72,6 +72,16 @@ int main(int ac, const char* av[]) {
return xmrblocks.index(page_no); return xmrblocks.index(page_no);
}); });
CROW_ROUTE(app, "/block/<uint>")
([&](size_t block_height) {
return xmrblocks.show_block(block_height);
});
CROW_ROUTE(app, "/block/<string>")
([&](string block_hash) {
return xmrblocks.show_block(block_hash);
});
CROW_ROUTE(app, "/autorefresh") CROW_ROUTE(app, "/autorefresh")
([&]() { ([&]() {
uint64_t page_no {0}; uint64_t page_no {0};

@ -29,6 +29,7 @@
#define TMPL_MEMPOOL TMPL_DIR "/mempool.html" #define TMPL_MEMPOOL TMPL_DIR "/mempool.html"
#define TMPL_HEADER TMPL_DIR "/header.html" #define TMPL_HEADER TMPL_DIR "/header.html"
#define TMPL_FOOTER TMPL_DIR "/footer.html" #define TMPL_FOOTER TMPL_DIR "/footer.html"
#define TMPL_BLOCK TMPL_DIR "/block.html"
@ -92,7 +93,7 @@ namespace xmreg {
{"total_page_no" , fmt::format("{:d}", height / (no_of_last_blocks))}, {"total_page_no" , fmt::format("{:d}", height / (no_of_last_blocks))},
{"is_page_zero" , !bool(page_no)}, {"is_page_zero" , !bool(page_no)},
{"next_page" , fmt::format("{:d}", page_no + 1)}, {"next_page" , fmt::format("{:d}", page_no + 1)},
{"prev_page" , fmt::format("{:d}", (page_no > 0 ? page_no - 1 : 0))}, {"prev_page" , fmt::format("{:d}", (page_no > 0 ? page_no - 1 : 0))}
}; };
@ -216,7 +217,7 @@ namespace xmreg {
{"blksize" , fmt::format("{:0.2f}", {"blksize" , fmt::format("{:0.2f}",
static_cast<double>(blk_size) / 1024.0)} static_cast<double>(blk_size) / 1024.0)}
}); });
} } // for (uint64_t i = start_height; i <= end_height; ++i)
// reverse blocks and remove last (i.e., oldest) // reverse blocks and remove last (i.e., oldest)
// block. This is done so that time delats // block. This is done so that time delats
@ -316,6 +317,68 @@ namespace xmreg {
} }
string
show_block(uint64_t _blk_height)
{
// get block at the given height i
block blk;
if (!mcore->get_block_by_height(_blk_height, blk))
{
cerr << "Cant get block: " << _blk_height << endl;
return fmt::format("Block of height {:d} not found!", _blk_height);
}
// initalise page tempate map with basic info about blockchain
mstch::map context {
{"blk_height" , fmt::format("{:d}", _blk_height)}
};
// get block's hash
crypto::hash blk_hash = core_storage->get_block_id_by_height(_blk_height);
// read block.html
string block_html = xmreg::read(TMPL_BLOCK);
// add header and footer
string full_page = get_full_page(block_html);
// render the page
return mstch::render(full_page, context);
}
string
show_block(string _blk_hash)
{
crypto::hash blk_hash;
if (!xmreg::parse_str_secret_key(_blk_hash, blk_hash))
{
cerr << "Cant parse blk hash: " << blk_hash << endl;
return fmt::format("Cant parse block hash {:s}!", blk_hash);
}
uint64_t blk_height;
try
{
blk_height = core_storage->get_db().get_block_height(blk_hash);
}
catch (const BLOCK_DNE& e)
{
cerr << "Block does not exist: " << blk_hash << endl;
return fmt::format("Block of hash {:s} does not exist!", blk_hash);
}
catch (const std::exception& e)
{
cerr << "Cant get block: " << blk_hash << endl;
return fmt::format("Block of hash {:s} not found!", blk_hash);
}
return show_block(blk_height);
}
private: private:
uint64_t uint64_t

@ -0,0 +1,4 @@
<div>
Height: {{blk_height}}
</div>

@ -1,6 +1,6 @@
<div class="center"> <div class="center">
<h5> <h5>
<a href="https://github.com/moneroexamples/onion-monero-blockchain-explorer">source code</a>
</h5> </h5>
</div> </div>
</div> </div>

@ -59,4 +59,9 @@
</head> </head>
<body> <body>
<div> <div>
<div class="center">
<h1 class="center"><a href="/">Onion Monero Blockchain Explorer</a></h1>
<h4 style="font-size: 15px; margin: 0px">(no javascript - no web analytics trackers - no images - open sourced)</h4>
</div>

@ -1,7 +1,5 @@
<div class="center"> <div class="center">
<h1 class="center">Onion Monero Blockchain Explorer</h1>
<h4 style="font-size: 15px; margin: 0px">(no javascript - no web analytics trackers - no images - open sourced)</h4>
<h3 style="font-size: 12px; margin-top: 20px"> <h3 style="font-size: 12px; margin-top: 20px">
Server time: {{server_timestamp}} | Server time: {{server_timestamp}} |
@ -39,9 +37,9 @@
</tr> </tr>
{{#blocks}} {{#blocks}}
<tr> <tr>
<td>{{height}}</td> <td><a href="/block/{{height}}">{{height}}</a></td>
<td>{{age}}</td> <td>{{age}}</td>
<td>{{hash}}</td> <td><a href="/block/{{hash}}">{{hash}}</a></td>
<td>{{block_reward}}</td> <td>{{block_reward}}</td>
<td>{{notx}}</td> <td>{{notx}}</td>
<td>{{xmr_inputs}}/{{xmr_outputs}}</td> <td>{{xmr_inputs}}/{{xmr_outputs}}</td>

Loading…
Cancel
Save