blockhexcomplete url added

master
moneroexamples 6 years ago
parent d9c042a1a6
commit 3e1631643e

@ -103,6 +103,8 @@ main(int ac, const char* av[])
uint32_t log_level = 0; uint32_t log_level = 0;
mlog_configure("", true); mlog_configure("", true);
(void) log_level;
//cast port number in string to uint //cast port number in string to uint
uint16_t app_port = boost::lexical_cast<uint16_t>(*port_opt); uint16_t app_port = boost::lexical_cast<uint16_t>(*port_opt);
@ -288,7 +290,7 @@ main(int ac, const char* av[])
}; };
CROW_ROUTE(app, "/") CROW_ROUTE(app, "/")
([&](const crow::request& req) { ([&]() {
return crow::response(xmrblocks.index2()); return crow::response(xmrblocks.index2());
}); });
@ -298,30 +300,35 @@ main(int ac, const char* av[])
}); });
CROW_ROUTE(app, "/block/<uint>") CROW_ROUTE(app, "/block/<uint>")
([&](const crow::request& req, size_t block_height) { ([&](size_t block_height) {
return crow::response(xmrblocks.show_block(block_height)); return crow::response(xmrblocks.show_block(block_height));
}); });
CROW_ROUTE(app, "/block/<string>") CROW_ROUTE(app, "/block/<string>")
([&](const crow::request& req, string block_hash) { ([&](string block_hash) {
return crow::response(xmrblocks.show_block(remove_bad_chars(block_hash))); return crow::response(xmrblocks.show_block(remove_bad_chars(block_hash)));
}); });
CROW_ROUTE(app, "/tx/<string>") CROW_ROUTE(app, "/tx/<string>")
([&](const crow::request& req, string tx_hash) { ([&](string tx_hash) {
return crow::response(xmrblocks.show_tx(remove_bad_chars(tx_hash))); return crow::response(xmrblocks.show_tx(remove_bad_chars(tx_hash)));
}); });
if (enable_as_hex) if (enable_as_hex)
{ {
CROW_ROUTE(app, "/txhex/<string>") CROW_ROUTE(app, "/txhex/<string>")
([&](const crow::request& req, string tx_hash) { ([&](string tx_hash) {
return crow::response(xmrblocks.show_tx_hex(remove_bad_chars(tx_hash))); return crow::response(xmrblocks.show_tx_hex(remove_bad_chars(tx_hash)));
}); });
CROW_ROUTE(app, "/blockhex/<uint>") CROW_ROUTE(app, "/blockhex/<uint>")
([&](const crow::request& req, size_t block_height) { ([&](size_t block_height) {
return crow::response(xmrblocks.show_block_hex(block_height)); return crow::response(xmrblocks.show_block_hex(block_height, false));
});
CROW_ROUTE(app, "/blockhexcomplete/<uint>")
([&](size_t block_height) {
return crow::response(xmrblocks.show_block_hex(block_height, true));
}); });
} }
@ -422,7 +429,7 @@ main(int ac, const char* av[])
if (enable_pusher) if (enable_pusher)
{ {
CROW_ROUTE(app, "/rawtx") CROW_ROUTE(app, "/rawtx")
([&](const crow::request& req) { ([&]() {
return xmrblocks.show_rawtx(); return xmrblocks.show_rawtx();
}); });
@ -452,7 +459,7 @@ main(int ac, const char* av[])
if (enable_key_image_checker) if (enable_key_image_checker)
{ {
CROW_ROUTE(app, "/rawkeyimgs") CROW_ROUTE(app, "/rawkeyimgs")
([&](const crow::request& req) { ([&]() {
return xmrblocks.show_rawkeyimgs(); return xmrblocks.show_rawkeyimgs();
}); });
@ -483,7 +490,7 @@ main(int ac, const char* av[])
if (enable_output_key_checker) if (enable_output_key_checker)
{ {
CROW_ROUTE(app, "/rawoutputkeys") CROW_ROUTE(app, "/rawoutputkeys")
([&](const crow::request& req) { ([&]() {
return xmrblocks.show_rawoutputkeys(); return xmrblocks.show_rawoutputkeys();
}); });
@ -518,13 +525,13 @@ main(int ac, const char* av[])
}); });
CROW_ROUTE(app, "/mempool") CROW_ROUTE(app, "/mempool")
([&](const crow::request& req) { ([&]() {
return xmrblocks.mempool(true); return xmrblocks.mempool(true);
}); });
// alias to "/mempool" // alias to "/mempool"
CROW_ROUTE(app, "/txpool") CROW_ROUTE(app, "/txpool")
([&](const crow::request& req) { ([&]() {
return xmrblocks.mempool(true); return xmrblocks.mempool(true);
}); });
@ -545,52 +552,52 @@ main(int ac, const char* av[])
cout << "Enable JavaScript checking of outputs and proving txs\n"; cout << "Enable JavaScript checking of outputs and proving txs\n";
CROW_ROUTE(app, "/js/jquery.min.js") CROW_ROUTE(app, "/js/jquery.min.js")
([&](const crow::request& req) { ([&]() {
return xmrblocks.get_js_file("jquery.min.js"); return xmrblocks.get_js_file("jquery.min.js");
}); });
CROW_ROUTE(app, "/js/crc32.js") CROW_ROUTE(app, "/js/crc32.js")
([&](const crow::request& req) { ([&]() {
return xmrblocks.get_js_file("crc32.js"); return xmrblocks.get_js_file("crc32.js");
}); });
CROW_ROUTE(app, "/js/biginteger.js") CROW_ROUTE(app, "/js/biginteger.js")
([&](const crow::request& req) { ([&]() {
return xmrblocks.get_js_file("biginteger.js"); return xmrblocks.get_js_file("biginteger.js");
}); });
CROW_ROUTE(app, "/js/crypto.js") CROW_ROUTE(app, "/js/crypto.js")
([&](const crow::request& req) { ([&]() {
return xmrblocks.get_js_file("crypto.js"); return xmrblocks.get_js_file("crypto.js");
}); });
CROW_ROUTE(app, "/js/config.js") CROW_ROUTE(app, "/js/config.js")
([&](const crow::request& req) { ([&]() {
return xmrblocks.get_js_file("config.js"); return xmrblocks.get_js_file("config.js");
}); });
CROW_ROUTE(app, "/js/nacl-fast-cn.js") CROW_ROUTE(app, "/js/nacl-fast-cn.js")
([&](const crow::request& req) { ([&]() {
return xmrblocks.get_js_file("nacl-fast-cn.js"); return xmrblocks.get_js_file("nacl-fast-cn.js");
}); });
CROW_ROUTE(app, "/js/base58.js") CROW_ROUTE(app, "/js/base58.js")
([&](const crow::request& req) { ([&]() {
return xmrblocks.get_js_file("base58.js"); return xmrblocks.get_js_file("base58.js");
}); });
CROW_ROUTE(app, "/js/cn_util.js") CROW_ROUTE(app, "/js/cn_util.js")
([&](const crow::request& req) { ([&]() {
return xmrblocks.get_js_file("cn_util.js"); return xmrblocks.get_js_file("cn_util.js");
}); });
CROW_ROUTE(app, "/js/sha3.js") CROW_ROUTE(app, "/js/sha3.js")
([&](const crow::request& req) { ([&]() {
return xmrblocks.get_js_file("sha3.js"); return xmrblocks.get_js_file("sha3.js");
}); });
CROW_ROUTE(app, "/js/all_in_one.js") CROW_ROUTE(app, "/js/all_in_one.js")
([&](const crow::request& req) { ([&]() {
// /js/all_in_one.js file does not exist. it is generated on the fly // /js/all_in_one.js file does not exist. it is generated on the fly
// from the above real files. // from the above real files.
return xmrblocks.get_js_file("all_in_one.js"); return xmrblocks.get_js_file("all_in_one.js");
@ -604,7 +611,7 @@ main(int ac, const char* av[])
cout << "Enable JSON API\n"; cout << "Enable JSON API\n";
CROW_ROUTE(app, "/api/transaction/<string>") CROW_ROUTE(app, "/api/transaction/<string>")
([&](const crow::request &req, string tx_hash) { ([&](string tx_hash) {
myxmr::jsonresponse r{xmrblocks.json_transaction(remove_bad_chars(tx_hash))}; myxmr::jsonresponse r{xmrblocks.json_transaction(remove_bad_chars(tx_hash))};
@ -612,7 +619,7 @@ main(int ac, const char* av[])
}); });
CROW_ROUTE(app, "/api/rawtransaction/<string>") CROW_ROUTE(app, "/api/rawtransaction/<string>")
([&](const crow::request &req, string tx_hash) { ([&](string tx_hash) {
myxmr::jsonresponse r{xmrblocks.json_rawtransaction(remove_bad_chars(tx_hash))}; myxmr::jsonresponse r{xmrblocks.json_rawtransaction(remove_bad_chars(tx_hash))};
@ -620,7 +627,7 @@ main(int ac, const char* av[])
}); });
CROW_ROUTE(app, "/api/detailedtransaction/<string>") CROW_ROUTE(app, "/api/detailedtransaction/<string>")
([&](const crow::request &req, string tx_hash) { ([&](string tx_hash) {
myxmr::jsonresponse r{xmrblocks.json_detailedtransaction(remove_bad_chars(tx_hash))}; myxmr::jsonresponse r{xmrblocks.json_detailedtransaction(remove_bad_chars(tx_hash))};
@ -628,7 +635,7 @@ main(int ac, const char* av[])
}); });
CROW_ROUTE(app, "/api/block/<string>") CROW_ROUTE(app, "/api/block/<string>")
([&](const crow::request &req, string block_no_or_hash) { ([&](string block_no_or_hash) {
myxmr::jsonresponse r{xmrblocks.json_block(remove_bad_chars(block_no_or_hash))}; myxmr::jsonresponse r{xmrblocks.json_block(remove_bad_chars(block_no_or_hash))};
@ -636,7 +643,7 @@ main(int ac, const char* av[])
}); });
CROW_ROUTE(app, "/api/rawblock/<string>") CROW_ROUTE(app, "/api/rawblock/<string>")
([&](const crow::request &req, string block_no_or_hash) { ([&](string block_no_or_hash) {
myxmr::jsonresponse r{xmrblocks.json_rawblock(remove_bad_chars(block_no_or_hash))}; myxmr::jsonresponse r{xmrblocks.json_rawblock(remove_bad_chars(block_no_or_hash))};
@ -677,7 +684,7 @@ main(int ac, const char* av[])
}); });
CROW_ROUTE(app, "/api/search/<string>") CROW_ROUTE(app, "/api/search/<string>")
([&](const crow::request &req, string search_value) { ([&](string search_value) {
myxmr::jsonresponse r{xmrblocks.json_search(remove_bad_chars(search_value))}; myxmr::jsonresponse r{xmrblocks.json_search(remove_bad_chars(search_value))};
@ -685,7 +692,7 @@ main(int ac, const char* av[])
}); });
CROW_ROUTE(app, "/api/networkinfo") CROW_ROUTE(app, "/api/networkinfo")
([&](const crow::request &req) { ([&]() {
myxmr::jsonresponse r{xmrblocks.json_networkinfo()}; myxmr::jsonresponse r{xmrblocks.json_networkinfo()};
@ -693,7 +700,7 @@ main(int ac, const char* av[])
}); });
CROW_ROUTE(app, "/api/emission") CROW_ROUTE(app, "/api/emission")
([&](const crow::request &req) { ([&]() {
myxmr::jsonresponse r{xmrblocks.json_emission()}; myxmr::jsonresponse r{xmrblocks.json_emission()};
@ -769,7 +776,7 @@ main(int ac, const char* av[])
}); });
CROW_ROUTE(app, "/api/version") CROW_ROUTE(app, "/api/version")
([&](const crow::request &req) { ([&]() {
myxmr::jsonresponse r{xmrblocks.json_version()}; myxmr::jsonresponse r{xmrblocks.json_version()};

@ -80,6 +80,12 @@ MicroCore::get_core()
return m_blockchain_storage; return m_blockchain_storage;
} }
tx_memory_pool&
MicroCore::get_mempool()
{
return m_mempool;
}
/** /**
* Get block by its height * Get block by its height
* *
@ -260,6 +266,28 @@ init_blockchain(const string& path,
return true; return true;
} }
bool
MicroCore::get_block_complete_entry(block const& b, block_complete_entry& bce)
{
bce.block = cryptonote::block_to_blob(b);
for (const auto &tx_hash: b.tx_hashes)
{
transaction tx;
if (!get_tx(tx_hash, tx))
return false;
cryptonote::blobdata txblob = tx_to_blob(tx);
bce.txs.push_back(txblob);
}
return true;
}
string string
MicroCore::get_blkchain_path() MicroCore::get_blkchain_path()
{ {

@ -44,6 +44,9 @@ namespace xmreg
Blockchain& Blockchain&
get_core(); get_core();
tx_memory_pool&
get_mempool();
bool bool
get_block_by_height(const uint64_t& height, block& blk); get_block_by_height(const uint64_t& height, block& blk);
@ -62,6 +65,9 @@ namespace xmreg
uint64_t uint64_t
get_blk_timestamp(uint64_t blk_height); get_blk_timestamp(uint64_t blk_height);
bool
get_block_complete_entry(block const& b, block_complete_entry& bce);
string string
get_blkchain_path(); get_blkchain_path();

@ -1644,7 +1644,7 @@ public:
} }
string string
show_block_hex(size_t block_height) show_block_hex(size_t block_height, bool complete_blk)
{ {
// get transaction // get transaction
@ -1658,8 +1658,37 @@ public:
try try
{ {
return epee::string_tools::buff_to_hex_nodelimer( if (complete_blk == false)
t_serializable_object_to_blob(blk)); {
// get only block data as hex
return epee::string_tools::buff_to_hex_nodelimer(
t_serializable_object_to_blob(blk));
}
else
{
// get block_complete_entry (block and its txs) as hex
block_complete_entry complete_block_data;
if (!mcore->get_block_complete_entry(blk, complete_block_data))
{
cerr << "Failed to obtain complete block data " << endl;
return string {"Failed to obtain complete block data "};
}
std::string complete_block_data_str;
if(!epee::serialization::store_t_to_binary(
complete_block_data, complete_block_data_str))
{
cerr << "Failed to serialize complete_block_data\n";
return string {"Failed to obtain complete block data"};
}
return epee::string_tools
::buff_to_hex_nodelimer(complete_block_data_str);
}
} }
catch (std::exception const& e) catch (std::exception const& e)
{ {

@ -88,6 +88,7 @@
{{#enable_as_hex}} {{#enable_as_hex}}
<h5 style="margin-top:1px"> <h5 style="margin-top:1px">
<a href="/blockhex/{{blk_height}}">Block as hex</a> <a href="/blockhex/{{blk_height}}">Block as hex</a>
| <a href="/blockhexcomplete/{{blk_height}}">Complete block as hex</a>
</h5> </h5>
{{/enable_as_hex}} {{/enable_as_hex}}

@ -372,6 +372,7 @@ pause_execution(uint64_t no_seconds, const string& text = "now");
string string
tx_to_hex(transaction const& tx); tx_to_hex(transaction const& tx);
} }
#endif //XMREG01_TOOLS_H #endif //XMREG01_TOOLS_H
Loading…
Cancel
Save