diff --git a/main.cpp b/main.cpp index 6c27d47..0a8bdf0 100644 --- a/main.cpp +++ b/main.cpp @@ -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(*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/") - ([&](const crow::request& req, size_t block_height) { + ([&](size_t block_height) { return crow::response(xmrblocks.show_block(block_height)); }); CROW_ROUTE(app, "/block/") - ([&](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/") - ([&](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/") - ([&](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/") - ([&](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/") + ([&](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/") - ([&](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/") - ([&](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/") - ([&](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/") - ([&](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/") - ([&](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/") - ([&](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()}; diff --git a/src/MicroCore.cpp b/src/MicroCore.cpp index 79dd64f..6d46db5 100644 --- a/src/MicroCore.cpp +++ b/src/MicroCore.cpp @@ -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() { diff --git a/src/MicroCore.h b/src/MicroCore.h index 0cd5d5e..57016ce 100644 --- a/src/MicroCore.h +++ b/src/MicroCore.h @@ -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(); diff --git a/src/page.h b/src/page.h index 951e2f8..55032b5 100644 --- a/src/page.h +++ b/src/page.h @@ -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) { diff --git a/src/templates/block.html b/src/templates/block.html index 23f6a0d..6f1b8ed 100644 --- a/src/templates/block.html +++ b/src/templates/block.html @@ -88,6 +88,7 @@ {{#enable_as_hex}}
Block as hex + | Complete block as hex
{{/enable_as_hex}} diff --git a/src/tools.h b/src/tools.h index c7d4b08..10df3d8 100644 --- a/src/tools.h +++ b/src/tools.h @@ -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 \ No newline at end of file +#endif //XMREG01_TOOLS_H