mirror of
https://git.wownero.com/wownero/onion-wownero-blockchain-explorer.git
synced 2024-08-15 00:33:12 +00:00
basic index page
This commit is contained in:
parent
28a7df74e0
commit
9ea9dfdf7b
5 changed files with 89 additions and 52 deletions
35
main.cpp
35
main.cpp
|
@ -37,45 +37,14 @@ int main() {
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// get the current blockchain height. Just to check if it reads ok.
|
||||
uint64_t height = core_storage->get_current_blockchain_height() - 1;
|
||||
|
||||
fmt::print("\n\n"
|
||||
"Top block height : {:d}\n", height);
|
||||
|
||||
|
||||
xmreg::page xmrblocks;
|
||||
|
||||
std::string view = xmrblocks.index();
|
||||
|
||||
mstch::map context {
|
||||
{"height", fmt::format("{:d}", height)},
|
||||
{"blocks", mstch::array()}
|
||||
};
|
||||
|
||||
size_t no_of_last_blocks {50};
|
||||
|
||||
mstch::array& blocks = boost::get<mstch::array>(context["blocks"]);
|
||||
|
||||
for (size_t i = height; i > height - no_of_last_blocks; --i)
|
||||
{
|
||||
//cryptonote::block blk;
|
||||
//core_storage.get_block_by_hash(block_id, blk);
|
||||
|
||||
crypto::hash blk_hash = core_storage->get_block_id_by_height(i);
|
||||
blocks.push_back(mstch::map {
|
||||
{"height", to_string(i)},
|
||||
{"hash" , fmt::format("{:s}", blk_hash)}
|
||||
});
|
||||
}
|
||||
xmreg::page xmrblocks(&mcore, core_storage);
|
||||
|
||||
|
||||
crow::SimpleApp app;
|
||||
|
||||
CROW_ROUTE(app, "/")
|
||||
([&]() {
|
||||
return mstch::render(view, context);
|
||||
return xmrblocks.index();
|
||||
});
|
||||
|
||||
app.port(8080).multithreaded().run();
|
||||
|
|
67
src/page.h
67
src/page.h
|
@ -7,34 +7,93 @@
|
|||
|
||||
|
||||
|
||||
#include "../ext/minicsv.h"
|
||||
#include "mstch/mstch.hpp"
|
||||
#include "../ext/format.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#include "monero_headers.h"
|
||||
|
||||
#include "MicroCore.h"
|
||||
#include "tools.h"
|
||||
|
||||
|
||||
#define TMPL_DIR "./templates"
|
||||
#define TMPL_INDEX TMPL_DIR "/index.html"
|
||||
#define TMPL_DIR "./templates"
|
||||
#define TMPL_INDEX TMPL_DIR "/index.html"
|
||||
#define TMPL_HEADER TMPL_DIR "/header.html"
|
||||
#define TMPL_FOOTER TMPL_DIR "/footer.html"
|
||||
|
||||
#define READ_TMPL(tmpl_path) xmreg::read(tmpl_path)
|
||||
|
||||
namespace xmreg {
|
||||
|
||||
using namespace cryptonote;
|
||||
using namespace crypto;
|
||||
using namespace std;
|
||||
|
||||
class page {
|
||||
|
||||
|
||||
MicroCore* mcore;
|
||||
Blockchain* core_storage;
|
||||
|
||||
public:
|
||||
|
||||
page(MicroCore* _mcore, Blockchain* _core_storage)
|
||||
: mcore {_mcore}, core_storage {_core_storage}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
string
|
||||
index()
|
||||
{
|
||||
// get the current blockchain height. Just to check if it reads ok.
|
||||
uint64_t height = core_storage->get_current_blockchain_height() - 1;
|
||||
|
||||
mstch::map context {
|
||||
{"height", fmt::format("{:d}", height)},
|
||||
{"blocks", mstch::array()}
|
||||
};
|
||||
|
||||
size_t no_of_last_blocks {50};
|
||||
|
||||
mstch::array& blocks = boost::get<mstch::array>(context["blocks"]);
|
||||
|
||||
for (size_t i = height; i > height - no_of_last_blocks; --i)
|
||||
{
|
||||
block blk;
|
||||
|
||||
mcore->get_block_by_height(i, blk);
|
||||
|
||||
crypto::hash blk_hash = core_storage->get_block_id_by_height(i);
|
||||
|
||||
blocks.push_back(mstch::map {
|
||||
{"height" , to_string(i)},
|
||||
{"timestamp" , xmreg::timestamp_to_str(blk.timestamp)},
|
||||
{"hash" , fmt::format("{:s}", blk_hash)},
|
||||
{"notx" , fmt::format("{:d}", blk.tx_hashes.size())}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
std::string view = READ_TMPL(TMPL_INDEX);
|
||||
|
||||
return view;
|
||||
string full_page = get_full_page(view);
|
||||
|
||||
return mstch::render(view, context);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
string
|
||||
get_full_page(string& middle)
|
||||
{
|
||||
return READ_TMPL(TMPL_HEADER)
|
||||
+ middle
|
||||
+ READ_TMPL(TMPL_FOOTER);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
|
3
src/templates/footer.html
Normal file
3
src/templates/footer.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
</div>
|
||||
</body>
|
||||
</html>
|
8
src/templates/header.html
Normal file
8
src/templates/header.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Monero blocks</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
|
@ -1,21 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Monero blocks</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<h1>Detailed Monero blockchain explorer</h1>
|
||||
|
||||
<h1>Hidden Monero blockchain explorer</h1>
|
||||
<h2>Current height: {{height}}</h2>
|
||||
<div>
|
||||
<ul>
|
||||
{{#blocks}}
|
||||
<li> {{height}}: {{hash}} </li>
|
||||
{{/blocks}}
|
||||
<table>
|
||||
{{#blocks}}
|
||||
<tr>
|
||||
<td>{{height}}</td>
|
||||
<td>{{timestamp}}</td>
|
||||
<td>{{hash}}</td>
|
||||
<td>{{notx}}</td>
|
||||
</tr>
|
||||
{{/blocks}}
|
||||
</table>
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue