From 90cd28c16c4cfc257289fa8fd7a059a62e238666 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Mon, 26 Nov 2018 13:38:05 +0800 Subject: [PATCH] show_ringmemberstx_hex added --- main.cpp | 6 ++ src/page.h | 92 ++++++++++++++++++++++++++ src/templates/partials/tx_details.html | 3 +- 3 files changed, 100 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index e6b7020..4729298 100644 --- a/main.cpp +++ b/main.cpp @@ -335,6 +335,12 @@ main(int ac, const char* av[]) ([&](size_t block_height) { return crow::response(xmrblocks.show_block_hex(block_height, true)); }); + + CROW_ROUTE(app, "/ringmemberstxhex/") + ([&](string tx_hash) { + return crow::response(xmrblocks.show_ringmemberstx_hex(remove_bad_chars(tx_hash))); + }); + } CROW_ROUTE(app, "/tx//") diff --git a/src/page.h b/src/page.h index d66144c..3d27334 100644 --- a/src/page.h +++ b/src/page.h @@ -1747,7 +1747,99 @@ show_ringmembers_hex(string const& tx_hash_str) // return as all_mixin_outputs vector hex return epee::string_tools ::buff_to_hex_nodelimer(oss.str()); +} +string +show_ringmemberstx_hex(string const& tx_hash_str) +{ + transaction tx; + crypto::hash tx_hash; + + if (!get_tx(tx_hash_str, tx, tx_hash)) + return string {"Cant get tx: "} + tx_hash_str; + + vector input_key_imgs = xmreg::get_key_images(tx); + + // key: constracted from concatenation of in_key.amount and absolute_offsets, + // value: vector of string where string is transaction hash + output index + tx_hex + // will have to cut this string when de-seraializing this data + // later in the unit tests + // transaction hash and output index represent tx_out_index + std::map> all_mixin_txs; + + for (txin_to_key const& in_key: input_key_imgs) + { + // get absolute offsets of mixins + std::vector absolute_offsets + = cryptonote::relative_output_offsets_to_absolute( + in_key.key_offsets); + + //tx_out_index is pair:: + vector indices; + + // get tx hashes and indices in the txs for the + // given outputs of mixins + // this cant THROW DB_EXCEPTION + try + { + // get tx of the real output + core_storage->get_db().get_output_tx_and_index( + in_key.amount, absolute_offsets, indices); + } + catch (exception const& e) + { + + string out_msg = fmt::format( + "Cant get ring member tx_out_index for tx {:s}", tx_hash_str + ); + + cerr << out_msg << endl; + + return string(out_msg); + } + + string map_key = std::to_string(in_key.amount); + + for (auto const& ao: absolute_offsets) + map_key += std::to_string(ao); + + // serialize each mixin tx + for (auto const& txi : indices) + { + auto const& mixin_tx_hash = txi.first; + auto const& output_index_in_tx = txi.second; + + transaction mixin_tx; + + if (!mcore->get_tx(mixin_tx_hash, mixin_tx)) + { + throw std::runtime_error("Cant get tx: " + + pod_to_hex(mixin_tx_hash)); + } + + // serialize tx + string tx_hex = epee::string_tools::buff_to_hex_nodelimer( + t_serializable_object_to_blob(mixin_tx)); + + all_mixin_txs[map_key].push_back( + pod_to_hex(mixin_tx_hash) + + std::to_string(output_index_in_tx) + + tx_hex); + } + + } // for (txin_to_key const& in_key: input_key_imgs) + + if (all_mixin_txs.empty()) + return string {"No ring members to serialize"}; + + // archive all_mixin_outputs vector + std::ostringstream oss; + boost::archive::portable_binary_oarchive archive(oss); + archive << all_mixin_txs; + + // return as all_mixin_outputs vector hex + return epee::string_tools + ::buff_to_hex_nodelimer(oss.str()); } diff --git a/src/templates/partials/tx_details.html b/src/templates/partials/tx_details.html index 5ca84e0..bd4459a 100644 --- a/src/templates/partials/tx_details.html +++ b/src/templates/partials/tx_details.html @@ -535,7 +535,8 @@ More details {{#enable_as_hex}} | Tx as hex - | Tx ring members as hex + | Ring member outputs/mixins as hex + | Full ring member txs as hex {{/enable_as_hex}} {{/show_more_details_link}}