diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-03-13 21:51:41 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-03-22 09:19:24 +0000 |
commit | 18faa6da0c868720d78d985e64cd60b30932b5c7 (patch) | |
tree | ebcdd15b491bf00801d11c65f973d8fd172dcf78 /src/simplewallet | |
parent | Merge pull request #5267 (diff) | |
download | monero-18faa6da0c868720d78d985e64cd60b30932b5c7.tar.xz |
wallet: add freeze/thaw/frozen commands
These commands let one freeze outputs by key image, so they
do not appear in balance, nor are considered when creating
a transaction, etc
This is helpful when receiving an output from a suspected spy,
who might try to track your other outputs by seeing with what
other outputs it gets spent.
The frozen command may be used without parameters to list all
currently frozen outputs.
Diffstat (limited to 'src/simplewallet')
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 87 | ||||
-rw-r--r-- | src/simplewallet/simplewallet.h | 6 |
2 files changed, 90 insertions, 3 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index f390b7675..c839a186a 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -237,6 +237,9 @@ namespace const char* USAGE_MARK_OUTPUT_SPENT("mark_output_spent <amount>/<offset> | <filename> [add]"); const char* USAGE_MARK_OUTPUT_UNSPENT("mark_output_unspent <amount>/<offset>"); const char* USAGE_IS_OUTPUT_SPENT("is_output_spent <amount>/<offset>"); + const char* USAGE_FREEZE("freeze <key_image>"); + const char* USAGE_THAW("thaw <key_image>"); + const char* USAGE_FROZEN("frozen <key_image>"); const char* USAGE_VERSION("version"); const char* USAGE_HELP("help [<command>]"); @@ -2025,6 +2028,74 @@ bool simple_wallet::save_known_rings(const std::vector<std::string> &args) return true; } +bool simple_wallet::freeze_thaw(const std::vector<std::string> &args, bool freeze) +{ + if (args.empty()) + { + fail_msg_writer() << boost::format(tr("usage: %s <key_image>|<pubkey>")) % (freeze ? "freeze" : "thaw"); + return true; + } + crypto::key_image ki; + if (!epee::string_tools::hex_to_pod(args[0], ki)) + { + fail_msg_writer() << tr("failed to parse key image"); + return true; + } + try + { + if (freeze) + m_wallet->freeze(ki); + else + m_wallet->thaw(ki); + } + catch (const std::exception &e) + { + fail_msg_writer() << e.what(); + return true; + } + + return true; +} + +bool simple_wallet::freeze(const std::vector<std::string> &args) +{ + return freeze_thaw(args, true); +} + +bool simple_wallet::thaw(const std::vector<std::string> &args) +{ + return freeze_thaw(args, false); +} + +bool simple_wallet::frozen(const std::vector<std::string> &args) +{ + if (args.empty()) + { + size_t ntd = m_wallet->get_num_transfer_details(); + for (size_t i = 0; i < ntd; ++i) + { + if (!m_wallet->frozen(i)) + continue; + const tools::wallet2::transfer_details &td = m_wallet->get_transfer_details(i); + message_writer() << tr("Frozen: ") << td.m_key_image << " " << cryptonote::print_money(td.amount()); + } + } + else + { + crypto::key_image ki; + if (!epee::string_tools::hex_to_pod(args[0], ki)) + { + fail_msg_writer() << tr("failed to parse key image"); + return true; + } + if (m_wallet->frozen(ki)) + message_writer() << tr("Frozen: ") << ki; + else + message_writer() << tr("Not frozen: ") << ki; + } + return true; +} + bool simple_wallet::version(const std::vector<std::string> &args) { message_writer() << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")"; @@ -2600,7 +2671,7 @@ simple_wallet::simple_wallet() tr(USAGE_INCOMING_TRANSFERS), tr("Show the incoming transfers, all or filtered by availability and address index.\n\n" "Output format:\n" - "Amount, Spent(\"T\"|\"F\"), \"locked\"|\"unlocked\", RingCT, Global Index, Transaction Hash, Address Index, [Public Key, Key Image] ")); + "Amount, Spent(\"T\"|\"F\"), \"frozen\"|\"locked\"|\"unlocked\", RingCT, Global Index, Transaction Hash, Address Index, [Public Key, Key Image] ")); m_cmd_binder.set_handler("payments", boost::bind(&simple_wallet::show_payments, this, _1), tr(USAGE_PAYMENTS), @@ -3012,6 +3083,18 @@ simple_wallet::simple_wallet() boost::bind(&simple_wallet::blackballed, this, _1), tr(USAGE_IS_OUTPUT_SPENT), tr("Checks whether an output is marked as spent")); + m_cmd_binder.set_handler("freeze", + boost::bind(&simple_wallet::freeze, this, _1), + tr(USAGE_FREEZE), + tr("Freeze a single output by key image so it will not be used")); + m_cmd_binder.set_handler("thaw", + boost::bind(&simple_wallet::thaw, this, _1), + tr(USAGE_THAW), + tr("Thaw a single output by key image so it may be used again")); + m_cmd_binder.set_handler("frozen", + boost::bind(&simple_wallet::frozen, this, _1), + tr(USAGE_FROZEN), + tr("Checks whether a given output is currently frozen by key image")); m_cmd_binder.set_handler("version", boost::bind(&simple_wallet::version, this, _1), tr(USAGE_VERSION), @@ -4987,7 +5070,7 @@ bool simple_wallet::show_incoming_transfers(const std::vector<std::string>& args boost::format("%21s%8s%12s%8s%16u%68s%16u%s") % print_money(td.amount()) % (td.m_spent ? tr("T") : tr("F")) % - (m_wallet->is_transfer_unlocked(td) ? tr("unlocked") : tr("locked")) % + (m_wallet->frozen(td) ? tr("[frozen]") : m_wallet->is_transfer_unlocked(td) ? tr("unlocked") : tr("locked")) % (td.is_rct() ? tr("RingCT") : tr("-")) % td.m_global_output_index % td.m_txid % diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 7bcb92190..c9a5c55e8 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -238,9 +238,12 @@ namespace cryptonote bool blackball(const std::vector<std::string>& args); bool unblackball(const std::vector<std::string>& args); bool blackballed(const std::vector<std::string>& args); + bool freeze(const std::vector<std::string>& args); + bool thaw(const std::vector<std::string>& args); + bool frozen(const std::vector<std::string>& args); bool version(const std::vector<std::string>& args); - bool cold_sign_tx(const std::vector<tools::wallet2::pending_tx>& ptx_vector, tools::wallet2::signed_tx_set &exported_txs, std::vector<cryptonote::address_parse_info> &dsts_info, std::function<bool(const tools::wallet2::signed_tx_set &)> accept_func); + bool cold_sign_tx(const std::vector<tools::wallet2::pending_tx>& ptx_vector, tools::wallet2::signed_tx_set &exported_txs, std::vector<cryptonote::address_parse_info> &dsts_info, std::function<bool(const tools::wallet2::signed_tx_set &)> accept_func); uint64_t get_daemon_blockchain_height(std::string& err); bool try_connect_to_daemon(bool silent = false, uint32_t* version = nullptr); bool ask_wallet_create_if_needed(); @@ -253,6 +256,7 @@ namespace cryptonote void key_images_sync_intern(); void on_refresh_finished(uint64_t start_height, uint64_t fetched_blocks, bool is_init, bool received_money); std::pair<std::string, std::string> show_outputs_line(const std::vector<uint64_t> &heights, uint64_t blockchain_height, uint64_t highlight_height = std::numeric_limits<uint64_t>::max()) const; + bool freeze_thaw(const std::vector<std::string>& args, bool freeze); struct transfer_view { |