basic display of few last block hashes

This commit is contained in:
moneroexamples 2016-04-07 14:32:28 +08:00
parent 38a77c6cbf
commit 87c40f4e5a
1 changed files with 23 additions and 2 deletions

View File

@ -42,12 +42,33 @@ int main() {
fmt::print("\n\n"
"Top block height : {:d}\n", height);
std::string view {"Blockchain height {{height}}"};
std::string view {
"Blockchain height {{height}}\n\n"
"{{#blocks}}{{height}}: {{hash}} \n{{/blocks}}"
};
mstch::map context {
{"height", fmt::format("{:d}", height)}
{"height", fmt::format("{:d}", height)},
{"blocks", mstch::array()}
};
size_t no_of_last_blocks {10};
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)}
});
}
crow::SimpleApp app;
CROW_ROUTE(app, "/")