diff --git a/main.cpp b/main.cpp index 9a4963b..6c27d47 100644 --- a/main.cpp +++ b/main.cpp @@ -64,6 +64,7 @@ main(int ac, const char* av[]) auto enable_js_opt = opts.get_option("enable-js"); auto enable_mixin_details_opt = opts.get_option("enable-mixin-details"); auto enable_json_api_opt = opts.get_option("enable-json-api"); + auto enable_as_hex_opt = opts.get_option("enable-as-hex"); auto enable_tx_cache_opt = opts.get_option("enable-tx-cache"); auto enable_block_cache_opt = opts.get_option("enable-block-cache"); auto show_cache_times_opt = opts.get_option("show-cache-times"); @@ -91,6 +92,7 @@ main(int ac, const char* av[]) bool enable_output_key_checker {*enable_output_key_checker_opt}; bool enable_mixin_details {*enable_mixin_details_opt}; bool enable_json_api {*enable_json_api_opt}; + bool enable_as_hex {*enable_as_hex_opt}; bool enable_tx_cache {*enable_tx_cache_opt}; bool enable_block_cache {*enable_block_cache_opt}; bool enable_emission_monitor {*enable_emission_monitor_opt}; @@ -262,6 +264,7 @@ main(int ac, const char* av[]) nettype, enable_pusher, enable_js, + enable_as_hex, enable_key_image_checker, enable_output_key_checker, enable_autorefresh_option, @@ -309,10 +312,18 @@ main(int ac, const char* av[]) return crow::response(xmrblocks.show_tx(remove_bad_chars(tx_hash))); }); - CROW_ROUTE(app, "/txhex/") - ([&](const crow::request& req, string tx_hash) { - return crow::response(xmrblocks.show_tx_hex(remove_bad_chars(tx_hash))); - }); + if (enable_as_hex) + { + CROW_ROUTE(app, "/txhex/") + ([&](const crow::request& req, 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)); + }); + } CROW_ROUTE(app, "/tx//") ([&](string tx_hash, uint16_t with_ring_signatures) diff --git a/src/CmdLineOptions.cpp b/src/CmdLineOptions.cpp index b04fdf8..3ff85c4 100644 --- a/src/CmdLineOptions.cpp +++ b/src/CmdLineOptions.cpp @@ -45,6 +45,8 @@ namespace xmreg "enable caching of block details") ("enable-js", value()->default_value(false)->implicit_value(true), "enable checking outputs and proving txs using JavaScript on client side") + ("enable-as-hex", value()->default_value(false)->implicit_value(true), + "enable links to provide hex represtations of a tx and a block") ("enable-autorefresh-option", value()->default_value(false)->implicit_value(true), "enable users to have the index page on autorefresh") ("enable-emission-monitor", value()->default_value(false)->implicit_value(true), diff --git a/src/page.h b/src/page.h index f90065b..5c849a2 100644 --- a/src/page.h +++ b/src/page.h @@ -365,6 +365,7 @@ class page bool enable_mixins_details; bool enable_tx_cache; bool enable_block_cache; + bool enable_as_hex; bool show_cache_times; @@ -415,6 +416,7 @@ public: cryptonote::network_type _nettype, bool _enable_pusher, bool _enable_js, + bool _enable_as_hex, bool _enable_key_image_checker, bool _enable_output_key_checker, bool _enable_autorefresh_option, @@ -434,6 +436,7 @@ public: nettype {_nettype}, enable_pusher {_enable_pusher}, enable_js {_enable_js}, + enable_as_hex {_enable_as_hex}, enable_key_image_checker {_enable_key_image_checker}, enable_output_key_checker {_enable_output_key_checker}, enable_autorefresh_option {_enable_autorefresh_option}, @@ -1253,11 +1256,12 @@ public: {"blk_timestamp_epoch" , blk.timestamp}, {"prev_hash" , prev_hash_str}, {"next_hash" , next_hash_str}, + {"enable_as_hex" , enable_as_hex}, {"have_next_hash" , have_next_hash}, {"have_prev_hash" , have_prev_hash}, {"have_txs" , have_txs}, {"no_txs" , std::to_string( - blk.tx_hashes.size())}, + blk.tx_hashes.size())}, {"blk_age" , age.first}, {"delta_time" , delta_time}, {"blk_nonce" , blk.nonce}, @@ -1632,9 +1636,34 @@ public: } catch (std::exception const& e) { - cerr << e.what() << endl; + cerr << e.what() << endl; return string {"Failed to obtain hex of tx due to: "} + e.what(); + } + } + + string + show_block_hex(size_t block_height) + { + + // get transaction + block blk; + + if (!mcore->get_block_by_height(block_height, blk)) + { + cerr << "Cant get block in blockchain: " << block_height + << ". \n Check mempool now\n"; + } + + try + { + return epee::string_tools::buff_to_hex_nodelimer( + t_serializable_object_to_blob(blk)); } + catch (std::exception const& e) + { + cerr << e.what() << endl; + return string {"Failed to obtain hex of a block due to: "} + e.what(); + } } string @@ -6063,6 +6092,7 @@ private: context["inputs_xmr_sum"] = xmreg::xmr_amount_to_str(inputs_xmr_sum); context["server_time"] = server_time_str; context["enable_mixins_details"] = detailed_view; + context["enable_as_hex"] = enable_as_hex; context["show_part_of_inputs"] = show_part_of_inputs; context["max_no_of_inputs_to_show"] = max_no_of_inputs_to_show; diff --git a/src/templates/block.html b/src/templates/block.html index 94e89ab..23f6a0d 100644 --- a/src/templates/block.html +++ b/src/templates/block.html @@ -82,6 +82,13 @@ {{/blk_txs}} - {{/have_txs}} + {{/have_txs}} + + + {{#enable_as_hex}} +
+ Block as hex +
+ {{/enable_as_hex}} diff --git a/src/templates/partials/tx_details.html b/src/templates/partials/tx_details.html index 8c3a833..0d2f89c 100644 --- a/src/templates/partials/tx_details.html +++ b/src/templates/partials/tx_details.html @@ -533,7 +533,9 @@ {{#show_more_details_link}}
More details - | As hex + {{#enable_as_hex}} + | Tx as hex + {{/enable_as_hex}}
{{/show_more_details_link}} {{/with_ring_signatures}}