mirror of
https://git.wownero.com/wownero/onion-wownero-blockchain-explorer.git
synced 2024-08-15 00:33:12 +00:00
dev of show_block started
This commit is contained in:
parent
cb7f080355
commit
76fc7594a9
7 changed files with 89 additions and 9 deletions
|
@ -1 +1 @@
|
|||
# crow-monero-test
|
||||
# Onion Monero Blockchain Explorer
|
||||
|
|
10
main.cpp
10
main.cpp
|
@ -72,6 +72,16 @@ int main(int ac, const char* av[]) {
|
|||
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")
|
||||
([&]() {
|
||||
uint64_t page_no {0};
|
||||
|
|
67
src/page.h
67
src/page.h
|
@ -29,6 +29,7 @@
|
|||
#define TMPL_MEMPOOL TMPL_DIR "/mempool.html"
|
||||
#define TMPL_HEADER TMPL_DIR "/header.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))},
|
||||
{"is_page_zero" , !bool(page_no)},
|
||||
{"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}",
|
||||
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)
|
||||
// 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:
|
||||
|
||||
uint64_t
|
||||
|
|
4
src/templates/block.html
Normal file
4
src/templates/block.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
<div>
|
||||
Height: {{blk_height}}
|
||||
</div>
|
|
@ -1,6 +1,6 @@
|
|||
<div class="center">
|
||||
<h5>
|
||||
|
||||
<a href="https://github.com/moneroexamples/onion-monero-blockchain-explorer">source code</a>
|
||||
</h5>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -60,3 +60,8 @@
|
|||
</head>
|
||||
<body>
|
||||
<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">
|
||||
<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">
|
||||
|
||||
Server time: {{server_timestamp}} |
|
||||
|
@ -39,9 +37,9 @@
|
|||
</tr>
|
||||
{{#blocks}}
|
||||
<tr>
|
||||
<td>{{height}}</td>
|
||||
<td><a href="/block/{{height}}">{{height}}</a></td>
|
||||
<td>{{age}}</td>
|
||||
<td>{{hash}}</td>
|
||||
<td><a href="/block/{{hash}}">{{hash}}</a></td>
|
||||
<td>{{block_reward}}</td>
|
||||
<td>{{notx}}</td>
|
||||
<td>{{xmr_inputs}}/{{xmr_outputs}}</td>
|
||||
|
|
Loading…
Reference in a new issue