From e03c6a200933b4e24745a96cd3fc6696faedc225 Mon Sep 17 00:00:00 2001 From: jpk68 Date: Mon, 17 Aug 2026 20:12:32 -0400 Subject: [PATCH] simplewallet: allow closing wallet when locked due to inactivity --- src/simplewallet/simplewallet.cpp | 17 +++++++++++++++-- src/simplewallet/simplewallet.h | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index cdadcc50e..f94500fa5 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -4618,14 +4618,18 @@ std::string simple_wallet::get_mnemonic_language() return language_list_self[language_number]; } //---------------------------------------------------------------------------------------------------- -boost::optional simple_wallet::get_and_verify_password() const +boost::optional simple_wallet::get_and_verify_password(bool *read_failed) const { + if (read_failed) *read_failed = false; const bool verify = m_wallet_file.empty(); auto pwd_container = (m_wallet->is_background_wallet() && m_wallet->background_sync_type() == tools::wallet2::BackgroundSyncCustomPassword) ? background_sync_cache_password_prompter(verify) : default_password_prompter(verify); if (!pwd_container) + { + if (read_failed) *read_failed = true; return boost::none; + } if (!m_wallet->verify_password(pwd_container->password())) { @@ -6208,6 +6212,7 @@ bool simple_wallet::prompt_if_old(const std::vector //---------------------------------------------------------------------------------------------------- void simple_wallet::check_for_inactivity_lock(bool user) { + bool close_wallet = false; if (m_locked) { #ifdef HAVE_READLINE @@ -6269,7 +6274,8 @@ void simple_wallet::check_for_inactivity_lock(bool user) } try { - const auto pwd_container = get_and_verify_password(); + bool read_failed = false; + const auto pwd_container = get_and_verify_password(&read_failed); if (pwd_container) { if (started_background_sync) @@ -6279,6 +6285,12 @@ void simple_wallet::check_for_inactivity_lock(bool user) } break; } + if (read_failed) + { + // Password read was interrupted; close the wallet instead of looping back to the prompt + close_wallet = true; + break; + } } catch (const std::exception &e) { @@ -6297,6 +6309,7 @@ void simple_wallet::check_for_inactivity_lock(bool user) m_in_command = false; m_locked = false; } + if (close_wallet) stop(); } //---------------------------------------------------------------------------------------------------- bool simple_wallet::on_command(bool (simple_wallet::*cmd)(const std::vector&), const std::vector &args) diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 54c4e00c7..1d1ac8af0 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -94,7 +94,7 @@ namespace cryptonote void wallet_idle_thread(); //! \return Prompts user for password and verifies against local file. Logs on error and returns `none` - boost::optional get_and_verify_password() const; + boost::optional get_and_verify_password(bool *read_failed = nullptr) const; boost::optional new_wallet(const boost::program_options::variables_map& vm, const crypto::secret_key& recovery_key, bool recover, bool two_random, const std::string &old_language);