diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-03-14 19:13:55 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-03-16 12:07:45 +0000 |
commit | eac3a11ed330faefa01685e98cf91e9ac1e31135 (patch) | |
tree | 0ab820cc329d2cf61fbe257df9ee62a254e85d9d /src/simplewallet | |
parent | wallet2_api: add key reuse mitigations API (diff) | |
download | monero-eac3a11ed330faefa01685e98cf91e9ac1e31135.tar.xz |
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
Diffstat (limited to 'src/simplewallet')
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 61a234317..3c257979e 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -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)) + rings.push_back({key_image, ring}); + else if (!m_wallet->get_rings(txid, rings)) { - 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)"); + fail_msg_writer() << tr("Key image either not spent, or spent with mixin 0"); + return true; } - else + + for (const auto &ring: rings) { - fail_msg_writer() << tr("Key image either not spent, or spent with mixin 0"); + 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>...]"), |