From 186271e5d1633964a37220e3b6c1aebb4f691fd9 Mon Sep 17 00:00:00 2001 From: Horia Mihai David Date: Mon, 11 Jan 2021 22:20:12 +0100 Subject: monero-wallet-cli: Added command scan_tx To implement this feature, the wallet2::scan_tx API was implemented. --- src/simplewallet/simplewallet.cpp | 45 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'src/simplewallet/simplewallet.cpp') diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 0635520c6..dad4aab6c 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -282,6 +282,7 @@ namespace const char* USAGE_VERSION("version"); const char* USAGE_HELP("help [ | all]"); const char* USAGE_APROPOS("apropos [ ...]"); + const char* USAGE_SCAN_TX("scan_tx [ ...]"); std::string input_line(const std::string& prompt, bool yesno = false) { @@ -3214,6 +3215,45 @@ bool simple_wallet::apropos(const std::vector &args) return true; } +bool simple_wallet::scan_tx(const std::vector &args) +{ + if (args.empty()) + { + PRINT_USAGE(USAGE_SCAN_TX); + return true; + } + + // Parse and dedup args + std::unordered_set txids; + for (const auto &s : args) { + crypto::hash txid; + if (!epee::string_tools::hex_to_pod(s, txid)) { + fail_msg_writer() << tr("Invalid txid specified: ") << s; + return true; + } + txids.insert(txid); + } + std::vector txids_v(txids.begin(), txids.end()); + + if (!m_wallet->is_trusted_daemon()) { + message_writer(console_color_red, true) << tr("WARNING: this operation may reveal the txids to the remote node and affect your privacy"); + if (!command_line::is_yes(input_line("Do you want to continue?", true))) { + message_writer() << tr("You have canceled the operation"); + return true; + } + } + + LOCK_IDLE_SCOPE(); + m_in_manual_refresh.store(true); + try { + m_wallet->scan_tx(txids_v); + } catch (const std::exception &e) { + fail_msg_writer() << e.what(); + } + m_in_manual_refresh.store(false); + return true; +} + simple_wallet::simple_wallet() : m_allow_mismatched_daemon_version(false) , m_refresh_progress_reporter(*this) @@ -3763,6 +3803,10 @@ simple_wallet::simple_wallet() boost::bind(&simple_wallet::on_command, this, &simple_wallet::apropos, _1), tr(USAGE_APROPOS), tr("Search all command descriptions for keyword(s)")); + m_cmd_binder.set_handler("scan_tx", + boost::bind(&simple_wallet::on_command, this, &simple_wallet::scan_tx, _1), + tr(USAGE_SCAN_TX), + tr("Scan the transactions given by (s), processing them and looking for outputs")); m_cmd_binder.set_unknown_command_handler(boost::bind(&simple_wallet::on_command, this, &simple_wallet::on_unknown_command, _1)); m_cmd_binder.set_empty_command_handler(boost::bind(&simple_wallet::on_empty_command, this)); m_cmd_binder.set_cancel_handler(boost::bind(&simple_wallet::on_cancelled_command, this)); @@ -11648,4 +11692,3 @@ bool simple_wallet::mms(const std::vector &args) return true; } // End MMS ------------------------------------------------------------------------------------------------ - -- cgit v1.2.3