show_ringmemberstx_hex added

This commit is contained in:
moneroexamples 2018-11-26 13:38:05 +08:00
parent db8b46eb22
commit 90cd28c16c
3 changed files with 100 additions and 1 deletions

View File

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

View File

@ -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<txin_to_key> 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<string, vector<string>> all_mixin_txs;
for (txin_to_key const& in_key: input_key_imgs)
{
// get absolute offsets of mixins
std::vector<uint64_t> absolute_offsets
= cryptonote::relative_output_offsets_to_absolute(
in_key.key_offsets);
//tx_out_index is pair::<transaction hash, output index>
vector<tx_out_index> 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());
}

View File

@ -535,7 +535,8 @@
<a href="/tx/{{tx_hash}}/1">More details</a>
{{#enable_as_hex}}
| <a href="/txhex/{{tx_hash}}">Tx as hex</a>
| <a href="/ringmembershex/{{tx_hash}}">Tx ring members as hex</a>
| <a href="/ringmembershex/{{tx_hash}}">Ring member outputs/mixins as hex</a>
| <a href="/ringmemberstxhex/{{tx_hash}}">Full ring member txs as hex</a>
{{/enable_as_hex}}
</h5>
{{/show_more_details_link}}