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;
mlog_configure("", true);
(void) log_level;
//cast port number in string to uint
uint16_t app_port = boost::lexical_cast<uint16_t>(*port_opt);
@ -288,7 +290,7 @@ main(int ac, const char* av[])
};
CROW_ROUTE(app, "/")
([&](const crow::request& req) {
([&]() {
return crow::response(xmrblocks.index2());
});
@ -298,30 +300,35 @@ main(int ac, const char* av[])
});
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));
});
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)));
});
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)));
});
if (enable_as_hex)
{
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)));
});
CROW_ROUTE(app, "/blockhex/<uint>")
([&](const crow::request& req, size_t block_height) {
return crow::response(xmrblocks.show_block_hex(block_height));
([&](size_t 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)
{
CROW_ROUTE(app, "/rawtx")
([&](const crow::request& req) {
([&]() {
return xmrblocks.show_rawtx();
});
@ -452,7 +459,7 @@ main(int ac, const char* av[])
if (enable_key_image_checker)
{
CROW_ROUTE(app, "/rawkeyimgs")
([&](const crow::request& req) {
([&]() {
return xmrblocks.show_rawkeyimgs();
});
@ -483,7 +490,7 @@ main(int ac, const char* av[])
if (enable_output_key_checker)
{
CROW_ROUTE(app, "/rawoutputkeys")
([&](const crow::request& req) {
([&]() {
return xmrblocks.show_rawoutputkeys();
});
@ -518,13 +525,13 @@ main(int ac, const char* av[])
});
CROW_ROUTE(app, "/mempool")
([&](const crow::request& req) {
([&]() {
return xmrblocks.mempool(true);
});
// alias to "/mempool"
CROW_ROUTE(app, "/txpool")
([&](const crow::request& req) {
([&]() {
return xmrblocks.mempool(true);
});
@ -545,52 +552,52 @@ main(int ac, const char* av[])
cout << "Enable JavaScript checking of outputs and proving txs\n";
CROW_ROUTE(app, "/js/jquery.min.js")
([&](const crow::request& req) {
([&]() {
return xmrblocks.get_js_file("jquery.min.js");
});
CROW_ROUTE(app, "/js/crc32.js")
([&](const crow::request& req) {
([&]() {
return xmrblocks.get_js_file("crc32.js");
});
CROW_ROUTE(app, "/js/biginteger.js")
([&](const crow::request& req) {
([&]() {
return xmrblocks.get_js_file("biginteger.js");
});
CROW_ROUTE(app, "/js/crypto.js")
([&](const crow::request& req) {
([&]() {
return xmrblocks.get_js_file("crypto.js");
});
CROW_ROUTE(app, "/js/config.js")
([&](const crow::request& req) {
([&]() {
return xmrblocks.get_js_file("config.js");
});
CROW_ROUTE(app, "/js/nacl-fast-cn.js")
([&](const crow::request& req) {
([&]() {
return xmrblocks.get_js_file("nacl-fast-cn.js");
});
CROW_ROUTE(app, "/js/base58.js")
([&](const crow::request& req) {
([&]() {
return xmrblocks.get_js_file("base58.js");
});
CROW_ROUTE(app, "/js/cn_util.js")
([&](const crow::request& req) {
([&]() {
return xmrblocks.get_js_file("cn_util.js");
});
CROW_ROUTE(app, "/js/sha3.js")
([&](const crow::request& req) {
([&]() {
return xmrblocks.get_js_file("sha3.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
// from the above real files.
return xmrblocks.get_js_file("all_in_one.js");
@ -604,7 +611,7 @@ main(int ac, const char* av[])
cout << "Enable JSON API\n";
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))};
@ -612,7 +619,7 @@ main(int ac, const char* av[])
});
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))};
@ -620,7 +627,7 @@ main(int ac, const char* av[])
});
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))};
@ -628,7 +635,7 @@ main(int ac, const char* av[])
});
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))};
@ -636,7 +643,7 @@ main(int ac, const char* av[])
});
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))};
@ -677,7 +684,7 @@ main(int ac, const char* av[])
});
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))};
@ -685,7 +692,7 @@ main(int ac, const char* av[])
});
CROW_ROUTE(app, "/api/networkinfo")
([&](const crow::request &req) {
([&]() {
myxmr::jsonresponse r{xmrblocks.json_networkinfo()};
@ -693,7 +700,7 @@ main(int ac, const char* av[])
});
CROW_ROUTE(app, "/api/emission")
([&](const crow::request &req) {
([&]() {
myxmr::jsonresponse r{xmrblocks.json_emission()};
@ -769,7 +776,7 @@ main(int ac, const char* av[])
});
CROW_ROUTE(app, "/api/version")
([&](const crow::request &req) {
([&]() {
myxmr::jsonresponse r{xmrblocks.json_version()};

@ -80,6 +80,12 @@ MicroCore::get_core()
return m_blockchain_storage;
}
tx_memory_pool&
MicroCore::get_mempool()
{
return m_mempool;
}
/**
* Get block by its height
*
@ -260,6 +266,28 @@ init_blockchain(const string& path,
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
MicroCore::get_blkchain_path()
{

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

@ -1644,7 +1644,7 @@ public:
}
string
show_block_hex(size_t block_height)
show_block_hex(size_t block_height, bool complete_blk)
{
// get transaction
@ -1658,8 +1658,37 @@ public:
try
{
return epee::string_tools::buff_to_hex_nodelimer(
t_serializable_object_to_blob(blk));
if (complete_blk == false)
{
// 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)
{

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

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