As hex link added to tx details

https://github.com/moneroexamples/onion-monero-blockchain-explorer/issues/133
This commit is contained in:
moneroexamples 2018-07-08 15:25:50 +08:00
parent b408e4b924
commit 2264d1d722
5 changed files with 59 additions and 2 deletions

View File

@ -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/<string>")
([&](const crow::request& req, string tx_hash) {
return crow::response(xmrblocks.show_tx_hex(remove_bad_chars(tx_hash)));
});
CROW_ROUTE(app, "/tx/<string>/<uint>")
([&](string tx_hash, uint16_t with_ring_signatures)
{

View File

@ -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<MempoolStatus::mempool_tx> 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,

View File

@ -531,7 +531,10 @@
{{^have_raw_tx}}
{{^with_ring_signatures}}
{{#show_more_details_link}}
<h5 style="margin-top:1px"><a href="/tx/{{tx_hash}}/1">More details</a></h5>
<h5 style="margin-top:1px">
<a href="/tx/{{tx_hash}}/1">More details</a>
| <a href="/txhex/{{tx_hash}}">As hex</a>
</h5>
{{/show_more_details_link}}
{{/with_ring_signatures}}
{{#with_ring_signatures}}

View File

@ -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));
}
}

View File

@ -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