diff --git a/main.cpp b/main.cpp index b240db5..9a4963b 100644 --- a/main.cpp +++ b/main.cpp @@ -309,6 +309,11 @@ 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))); + }); + CROW_ROUTE(app, "/tx//") ([&](string tx_hash, uint16_t with_ring_signatures) { diff --git a/src/page.h b/src/page.h index 3df822a..f90065b 100644 --- a/src/page.h +++ b/src/page.h @@ -1595,6 +1595,48 @@ public: return mstch::render(template_file["tx"], context, partials); } + string + show_tx_hex(string tx_hash_str) + { + crypto::hash tx_hash; + + if (!epee::string_tools::hex_to_pod(tx_hash_str, tx_hash)) + { + string msg = fmt::format("Cant parse {:s} as tx hash!", tx_hash_str); + cerr << msg << endl; + return msg; + } + + // get transaction + transaction tx; + + if (!mcore->get_tx(tx_hash, tx)) + { + cerr << "Cant get tx in blockchain: " << tx_hash + << ". \n Check mempool now" << endl; + + vector found_txs; + + search_mempool(tx_hash, found_txs); + + if (found_txs.empty()) + { + // tx is nowhere to be found :-( + return string("Cant get tx: " + tx_hash_str); + } + } + + try + { + return tx_to_hex(tx); + } + catch (std::exception const& e) + { + cerr << e.what() << endl; + return string {"Failed to obtain hex of tx due to: "} + e.what(); + } + } + string show_my_outputs(string tx_hash_str, string xmr_address_str, diff --git a/src/templates/partials/tx_details.html b/src/templates/partials/tx_details.html index 00a405c..8c3a833 100644 --- a/src/templates/partials/tx_details.html +++ b/src/templates/partials/tx_details.html @@ -531,7 +531,10 @@ {{^have_raw_tx}} {{^with_ring_signatures}} {{#show_more_details_link}} -
More details
+
+ More details + | As hex +
{{/show_more_details_link}} {{/with_ring_signatures}} {{#with_ring_signatures}} diff --git a/src/tools.cpp b/src/tools.cpp index f5d6d30..5cfa59c 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -1266,4 +1266,10 @@ pause_execution(uint64_t no_seconds, const string& text) cout << endl; } +string +tx_to_hex(transaction const& tx) +{ + return epee::string_tools::buff_to_hex_nodelimer(t_serializable_object_to_blob(tx)); +} + } diff --git a/src/tools.h b/src/tools.h index 1063d20..c7d4b08 100644 --- a/src/tools.h +++ b/src/tools.h @@ -370,7 +370,8 @@ calc_median(It it_begin, It it_end) void 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