--enable-as-hex option added

master
moneroexamples 7 years ago
parent 2264d1d722
commit 22a9f6517e

@ -64,6 +64,7 @@ main(int ac, const char* av[])
auto enable_js_opt = opts.get_option<bool>("enable-js");
auto enable_mixin_details_opt = opts.get_option<bool>("enable-mixin-details");
auto enable_json_api_opt = opts.get_option<bool>("enable-json-api");
auto enable_as_hex_opt = opts.get_option<bool>("enable-as-hex");
auto enable_tx_cache_opt = opts.get_option<bool>("enable-tx-cache");
auto enable_block_cache_opt = opts.get_option<bool>("enable-block-cache");
auto show_cache_times_opt = opts.get_option<bool>("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,11 +312,19 @@ main(int ac, const char* av[])
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) {
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));
});
}
CROW_ROUTE(app, "/tx/<string>/<uint>")
([&](string tx_hash, uint16_t with_ring_signatures)
{

@ -45,6 +45,8 @@ namespace xmreg
"enable caching of block details")
("enable-js", value<bool>()->default_value(false)->implicit_value(true),
"enable checking outputs and proving txs using JavaScript on client side")
("enable-as-hex", value<bool>()->default_value(false)->implicit_value(true),
"enable links to provide hex represtations of a tx and a block")
("enable-autorefresh-option", value<bool>()->default_value(false)->implicit_value(true),
"enable users to have the index page on autorefresh")
("enable-emission-monitor", value<bool>()->default_value(false)->implicit_value(true),

@ -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,6 +1256,7 @@ 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},
@ -1637,6 +1641,31 @@ public:
}
}
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
show_my_outputs(string tx_hash_str,
string xmr_address_str,
@ -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;

@ -84,4 +84,11 @@
</table>
{{/have_txs}}
{{#enable_as_hex}}
<h5 style="margin-top:1px">
<a href="/blockhex/{{blk_height}}">Block as hex</a>
</h5>
{{/enable_as_hex}}
</div>

@ -533,7 +533,9 @@
{{#show_more_details_link}}
<h5 style="margin-top:1px">
<a href="/tx/{{tx_hash}}/1">More details</a>
| <a href="/txhex/{{tx_hash}}">As hex</a>
{{#enable_as_hex}}
| <a href="/txhex/{{tx_hash}}">Tx as hex</a>
{{/enable_as_hex}}
</h5>
{{/show_more_details_link}}
{{/with_ring_signatures}}

Loading…
Cancel
Save