wallet: more user friendly print_ring

It can now take a txid (to display rings for all its inputs),
and will print rings in a format that set_ring understands
This commit is contained in:
moneromooo-monero 2018-03-14 19:13:55 +00:00
parent 798535149d
commit eac3a11ed3
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
6 changed files with 101 additions and 15 deletions

View file

@ -1297,9 +1297,10 @@ bool simple_wallet::export_raw_multisig(const std::vector<std::string> &args)
bool simple_wallet::print_ring(const std::vector<std::string> &args)
{
crypto::key_image key_image;
crypto::hash txid;
if (args.size() != 1)
{
fail_msg_writer() << tr("usage: print_ring <key_image>");
fail_msg_writer() << tr("usage: print_ring <key_image|txid>");
return true;
}
@ -1308,20 +1309,32 @@ bool simple_wallet::print_ring(const std::vector<std::string> &args)
fail_msg_writer() << tr("Invalid key image");
return true;
}
// this one will always work, they're all 32 byte hex
if (!epee::string_tools::hex_to_pod(args[0], txid))
{
fail_msg_writer() << tr("Invalid txid");
return true;
}
std::vector<uint64_t> ring;
std::vector<std::pair<crypto::key_image, std::vector<uint64_t>>> rings;
try
{
if (m_wallet->get_ring(key_image, ring))
{
std::stringstream str;
for (const auto &x: ring)
str << x << " ";
success_msg_writer() << tr("Ring size ") << std::to_string(ring.size()) << ": " << str.str() << tr(" (absolute)");
}
else
rings.push_back({key_image, ring});
else if (!m_wallet->get_rings(txid, rings))
{
fail_msg_writer() << tr("Key image either not spent, or spent with mixin 0");
return true;
}
for (const auto &ring: rings)
{
std::stringstream str;
for (const auto &x: ring.second)
str << x<< " ";
// do NOT translate this "absolute" below, the lin can be used as input to set_ring
success_msg_writer() << epee::string_tools::pod_to_hex(ring.first) << " absolute " << str.str();
}
}
catch (const std::exception &e)
@ -2239,8 +2252,8 @@ simple_wallet::simple_wallet()
tr("Export a signed multisig transaction to a file"));
m_cmd_binder.set_handler("print_ring",
boost::bind(&simple_wallet::print_ring, this, _1),
tr("print_ring <key_image>"),
tr("Print the ring used to spend a given key image (if the ring size is > 1)"));
tr("print_ring <key_image> | <txid>"),
tr("Print the ring(s) used to spend a given key image or transaction (if the ring size is > 1)"));
m_cmd_binder.set_handler("set_ring",
boost::bind(&simple_wallet::set_ring, this, _1),
tr("set_ring <key_image> absolute|relative <index> [<index>...]"),