From 9ac357b208a0f8bc7cfc927f6dd66ebd779a0619 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Wed, 17 Dec 2025 19:32:37 +0530 Subject: [PATCH 1/6] qt: de-emphasize runtime arguments, isolate code path to wallet builds --- src/qt/forms/debugwindow.ui | 18 +++++++++--------- src/qt/rpcconsole.cpp | 10 +++++++--- src/qt/rpcconsole.h | 6 ++++-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/qt/forms/debugwindow.ui b/src/qt/forms/debugwindow.ui index 8a11de69c75d..16a749a87418 100644 --- a/src/qt/forms/debugwindow.ui +++ b/src/qt/forms/debugwindow.ui @@ -81,7 +81,7 @@ - &Wallet Repair + &Repair true @@ -1728,7 +1728,7 @@ - Wallet repair options. + Repair options. true @@ -1738,7 +1738,7 @@ - The buttons below will restart the wallet with command-line options to repair the wallet, fix issues with corrupt blockchain files or missing/obsolete transactions. + The buttons below will trigger repair actions to fix issues with corrupt files or missing/obsolete transactions. true @@ -1758,14 +1758,14 @@ - Rescan blockchain files 1 + Rescan Chain - -rescan=1: Rescan the block chain for missing wallet transactions starting from wallet creation time. + Rescan the chain for missing wallet transactions starting from wallet creation time. true @@ -1781,14 +1781,14 @@ - Rescan blockchain files 2 + Rescan Chain (full) - -rescan=2: Rescan the block chain for missing wallet transactions starting from genesis block. + Rescan the chain for missing wallet transactions starting from genesis block. true @@ -1798,14 +1798,14 @@ - Rebuild index + Rebuild Index - -reindex: Rebuild block chain index from current blk000??.dat files. + Restarts the client to rebuild the chain index from current blk000??.dat files. true diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index eca6536c1966..56d71687bc1c 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -574,12 +574,14 @@ RPCConsole::RPCConsole(interfaces::Node& node, QWidget* parent, Qt::WindowFlags ui->WalletSelector->setVisible(false); ui->WalletSelectorLabel->setVisible(false); - // Wallet Repair Buttons + // Repair Buttons // Disable wallet repair options that require a wallet (enable them later when a wallet is added) ui->btn_rescan1->setEnabled(false); ui->btn_rescan2->setEnabled(false); +#ifdef ENABLE_WALLET connect(ui->btn_rescan1, &QPushButton::clicked, this, &RPCConsole::walletRescan1); connect(ui->btn_rescan2, &QPushButton::clicked, this, &RPCConsole::walletRescan2); +#endif // ENABLE_WALLET connect(ui->btn_reindex, &QPushButton::clicked, this, &RPCConsole::walletReindex); // Register RPC timer interface @@ -917,17 +919,19 @@ void RPCConsole::setFontSize(int newSize) ui->messagesWidget->verticalScrollBar()->setValue(oldPosFactor * ui->messagesWidget->verticalScrollBar()->maximum()); } -/** Restart wallet with "-rescan=1" */ +#ifdef ENABLE_WALLET +/** Rescan wallet from wallet creation */ void RPCConsole::walletRescan1() { buildParameterlist(RESCAN1); } -/** Restart wallet with "-rescan=2" */ +/** Rescan wallet from genesis block */ void RPCConsole::walletRescan2() { buildParameterlist(RESCAN2); } +#endif /** Restart wallet with "-reindex" */ void RPCConsole::walletReindex() diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 8bb1c1b9dfdd..5e7caee32b2b 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -117,10 +117,12 @@ public Q_SLOTS: void fontSmaller(); void setFontSize(int newSize); - /** Wallet repair options */ + /** Repair options */ + void walletReindex(); +#ifdef ENABLE_WALLET void walletRescan1(); void walletRescan2(); - void walletReindex(); +#endif // ENABLE_WALLET /** Append the message to the message widget */ void message(int category, const QString &msg) { message(category, msg, false); } From 8b73a88f67f40922bdd7495427ad3ab1eb3f850b Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Fri, 19 Dec 2025 01:36:56 +0530 Subject: [PATCH 2/6] qt: add interface method to trigger rescans Co-authored-by: UdjinM6 --- src/interfaces/wallet.h | 4 ++++ src/wallet/interfaces.cpp | 32 ++++++++++++++++++++++++++++++++ src/wallet/wallet.h | 8 ++++++++ 3 files changed, 44 insertions(+) diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index e9f209df28f4..8c79ec01ca98 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -40,6 +40,7 @@ namespace wallet { class CCoinControl; class CWallet; enum isminetype : unsigned int; +enum class RescanStatus : uint8_t; struct CRecipient; struct WalletContext; using isminefilter = std::underlying_type::type; @@ -93,6 +94,9 @@ class Wallet virtual bool changeWalletPassphrase(const SecureString& old_wallet_passphrase, const SecureString& new_wallet_passphrase) = 0; + //! Initiate a rescan. Returns status indicating success, failure, abort, or already rescanning. + virtual wallet::RescanStatus startRescan(bool from_genesis) = 0; + //! Abort a rescan. virtual void abortRescan() = 0; diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp index 6d087a276594..71a5823edbe5 100644 --- a/src/wallet/interfaces.cpp +++ b/src/wallet/interfaces.cpp @@ -4,6 +4,7 @@ #include +#include #include #include #include @@ -173,6 +174,37 @@ class WalletImpl : public Wallet { return m_wallet->ChangeWalletPassphrase(old_wallet_passphrase, new_wallet_passphrase); } + wallet::RescanStatus startRescan(bool from_genesis) override + { + int rescan_height{0}; + if (!from_genesis) { + std::optional time_first_key; + for (auto spk_man : m_wallet->GetAllScriptPubKeyMans()) { + int64_t time = spk_man->GetTimeFirstKey(); + if (!time_first_key || time < *time_first_key) time_first_key = time; + } + if (time_first_key) { + m_wallet->chain().findFirstBlockWithTimeAndHeight(*time_first_key - TIMESTAMP_WINDOW, rescan_height, + FoundBlock().height(rescan_height)); + } + } + + WalletRescanReserver reserver(*m_wallet); + if (!reserver.reserve()) { + return wallet::RescanStatus::BUSY; + } + switch (m_wallet->ScanForWalletTransactions(m_wallet->chain().getBlockHash(rescan_height), rescan_height, /*max_height=*/std::nullopt, + reserver, /*fUpdate=*/true, /*save_progress=*/false).status) { + case CWallet::ScanResult::SUCCESS: + return wallet::RescanStatus::SUCCESS; + case CWallet::ScanResult::FAILURE: + return wallet::RescanStatus::FAILURE; + case CWallet::ScanResult::USER_ABORT: + return wallet::RescanStatus::USER_ABORT; + } + Assume(false); // unreachable + return wallet::RescanStatus::FAILURE; // fallback for release builds + } void abortRescan() override { m_wallet->AbortRescan(); } void autoLockMasternodeCollaterals() override { m_wallet->AutoLockMasternodeCollaterals(); } bool backupWallet(const std::string& filename) override { return m_wallet->BackupWallet(filename); } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 8e0966d4bfae..06222f82c3a2 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -250,6 +250,14 @@ struct WalletTxHasher } }; +/** Status of a wallet rescan operation */ +enum class RescanStatus : uint8_t { + BUSY, //!< Wallet is already rescanning + FAILURE, //!< Rescan failed + SUCCESS, //!< Rescan completed successfully + USER_ABORT, //!< User aborted the rescan +}; + class WalletRescanReserver; //forward declarations for ScanForWalletTransactions/RescanFromTime /** * A CWallet maintains a set of transactions and balances, and provides the ability to create new transactions. From 9fed372023359c92829840ca83aaf0a7477e61bf Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Fri, 19 Dec 2025 02:41:08 +0530 Subject: [PATCH 3/6] qt: add rescan wallet activity --- src/qt/bitcoingui.cpp | 2 ++ src/qt/rpcconsole.cpp | 23 ++++++++++++++++++++++ src/qt/rpcconsole.h | 7 +++++++ src/qt/walletcontroller.cpp | 39 +++++++++++++++++++++++++++++++++++++ src/qt/walletcontroller.h | 21 ++++++++++++++++++++ src/wallet/interfaces.cpp | 4 ++-- 6 files changed, 94 insertions(+), 2 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 3921618469ea..9a6bd98d15d8 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -936,6 +936,8 @@ void BitcoinGUI::setWalletController(WalletController* wallet_controller) m_wallet_controller = nullptr; }); + rpcConsole->setWalletController(wallet_controller); + auto activity = new LoadWalletsActivity(m_wallet_controller, this); activity->load(); } diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 56d71687bc1c..b8f7df75dafa 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -822,6 +823,11 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_ } #ifdef ENABLE_WALLET +void RPCConsole::setWalletController(WalletController* wallet_controller) +{ + m_wallet_controller = wallet_controller; +} + void RPCConsole::addWallet(WalletModel * const walletModel) { // use name for text and wallet model for internal data object (to allow to move to a wallet id later) @@ -920,6 +926,23 @@ void RPCConsole::setFontSize(int newSize) } #ifdef ENABLE_WALLET +void RPCConsole::walletRescan(bool from_genesis) +{ + if (!m_wallet_controller) { + QMessageBox::critical(this, PACKAGE_NAME, QObject::tr("Error: Wallet controller not available.")); + return; + } + + WalletModel* wallet_model{ui->WalletSelector->itemData(1).value()}; + if (!wallet_model) { + QMessageBox::critical(this, PACKAGE_NAME, QObject::tr("Error: Rescan failed. Wallet not loaded.")); + return; + } + + auto activity = new RescanWalletActivity(m_wallet_controller, this); + activity->rescan(wallet_model, from_genesis); +} + /** Rescan wallet from wallet creation */ void RPCConsole::walletRescan1() { diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 5e7caee32b2b..ef1e7dd349da 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -24,6 +24,7 @@ class ClientModel; class RPCExecutor; class RPCTimerInterface; +class WalletController; class WalletModel; namespace interfaces { @@ -58,6 +59,7 @@ class RPCConsole: public QWidget void setClientModel(ClientModel *model = nullptr, int bestblock_height = 0, int64_t bestblock_date = 0, uint256 bestblock_hash = uint256(), double verification_progress = 0.0); #ifdef ENABLE_WALLET + void setWalletController(WalletController* wallet_controller); void addWallet(WalletModel* const walletModel); void removeWallet(WalletModel* const walletModel); #endif // ENABLE_WALLET @@ -176,6 +178,10 @@ public Q_SLOTS: void setButtonIcons(); /** Reload some themes related widgets */ void reloadThemedWidgets(); +#ifdef ENABLE_WALLET + /** Initiate a wallet rescan */ + void walletRescan(bool from_genesis); +#endif // ENABLE_WALLET enum ColumnWidths { @@ -190,6 +196,7 @@ public Q_SLOTS: interfaces::Node& m_node; Ui::RPCConsole* const ui; ClientModel *clientModel = nullptr; + WalletController* m_wallet_controller{nullptr}; QButtonGroup* pageButtons = nullptr; QStringList history; int historyPtr = 0; diff --git a/src/qt/walletcontroller.cpp b/src/qt/walletcontroller.cpp index 55616a2f4914..74c4d787d784 100644 --- a/src/qt/walletcontroller.cpp +++ b/src/qt/walletcontroller.cpp @@ -511,3 +511,42 @@ void RestoreWalletActivity::finish() Q_EMIT finished(); } + +RescanWalletActivity::RescanWalletActivity(WalletController* wallet_controller, QWidget* parent_widget) + : WalletControllerActivity(wallet_controller, parent_widget) +{ +} + +void RescanWalletActivity::rescan(WalletModel* wallet_model, bool from_genesis) +{ + m_rescan_wallet_model = wallet_model; + + QTimer::singleShot(0, worker(), [this, from_genesis] { + // Emits its own progress bar + m_rescan_status = m_rescan_wallet_model->wallet().startRescan(from_genesis); + QTimer::singleShot(0, this, &RescanWalletActivity::finish); + }); +} + +void RescanWalletActivity::finish() +{ + switch (m_rescan_status) { + case wallet::RescanStatus::BUSY: + QMessageBox::warning(m_parent_widget, tr("Rescan unavailable"), tr("Wallet is currently rescanning. Abort existing rescan or wait.")); + Q_EMIT rescanFailed(); + break; + case wallet::RescanStatus::FAILURE: + QMessageBox::critical(m_parent_widget, tr("Rescan wallet failed"), tr("Rescan failed. Potentially corrupted data files.")); + Q_EMIT rescanFailed(); + break; + case wallet::RescanStatus::SUCCESS: + Q_EMIT rescanComplete(); + break; + case wallet::RescanStatus::USER_ABORT: + QMessageBox::information(m_parent_widget, tr("Rescan aborted"), tr("Wallet rescan was aborted.")); + Q_EMIT rescanFailed(); + break; + } + + Q_EMIT finished(); +} diff --git a/src/qt/walletcontroller.h b/src/qt/walletcontroller.h index ccb7dbc62d51..32f5eb3d7576 100644 --- a/src/qt/walletcontroller.h +++ b/src/qt/walletcontroller.h @@ -5,6 +5,7 @@ #ifndef BITCOIN_QT_WALLETCONTROLLER_H #define BITCOIN_QT_WALLETCONTROLLER_H +#include #include #include #include @@ -171,4 +172,24 @@ class RestoreWalletActivity : public WalletControllerActivity void finish(); }; +class RescanWalletActivity : public WalletControllerActivity +{ + Q_OBJECT + +public: + RescanWalletActivity(WalletController* wallet_controller, QWidget* parent_widget); + + void rescan(WalletModel* wallet_model, bool from_genesis); + +Q_SIGNALS: + void rescanComplete(); + void rescanFailed(); + +private: + void finish(); + + WalletModel* m_rescan_wallet_model{nullptr}; + wallet::RescanStatus m_rescan_status{}; +}; + #endif // BITCOIN_QT_WALLETCONTROLLER_H diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp index 71a5823edbe5..c260dd23ffc9 100644 --- a/src/wallet/interfaces.cpp +++ b/src/wallet/interfaces.cpp @@ -195,10 +195,10 @@ class WalletImpl : public Wallet } switch (m_wallet->ScanForWalletTransactions(m_wallet->chain().getBlockHash(rescan_height), rescan_height, /*max_height=*/std::nullopt, reserver, /*fUpdate=*/true, /*save_progress=*/false).status) { - case CWallet::ScanResult::SUCCESS: - return wallet::RescanStatus::SUCCESS; case CWallet::ScanResult::FAILURE: return wallet::RescanStatus::FAILURE; + case CWallet::ScanResult::SUCCESS: + return wallet::RescanStatus::SUCCESS; case CWallet::ScanResult::USER_ABORT: return wallet::RescanStatus::USER_ABORT; } From 9e160775bb73a22789fa788418905a835267c342 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Fri, 19 Dec 2025 02:41:43 +0530 Subject: [PATCH 4/6] qt: use `QPointer` to prevent potential dangling pointer on unload --- src/qt/walletcontroller.cpp | 9 +++++++-- src/qt/walletcontroller.h | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/qt/walletcontroller.cpp b/src/qt/walletcontroller.cpp index 74c4d787d784..bee53c3805d3 100644 --- a/src/qt/walletcontroller.cpp +++ b/src/qt/walletcontroller.cpp @@ -522,8 +522,13 @@ void RescanWalletActivity::rescan(WalletModel* wallet_model, bool from_genesis) m_rescan_wallet_model = wallet_model; QTimer::singleShot(0, worker(), [this, from_genesis] { - // Emits its own progress bar - m_rescan_status = m_rescan_wallet_model->wallet().startRescan(from_genesis); + if (m_rescan_wallet_model) { + // Emits its own progress bar + m_rescan_status = m_rescan_wallet_model->wallet().startRescan(from_genesis); + } else { + // Wallet was closed before rescan could start + m_rescan_status = wallet::RescanStatus::FAILURE; + } QTimer::singleShot(0, this, &RescanWalletActivity::finish); }); } diff --git a/src/qt/walletcontroller.h b/src/qt/walletcontroller.h index 32f5eb3d7576..5c47d5d045fa 100644 --- a/src/qt/walletcontroller.h +++ b/src/qt/walletcontroller.h @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -188,7 +189,7 @@ class RescanWalletActivity : public WalletControllerActivity private: void finish(); - WalletModel* m_rescan_wallet_model{nullptr}; + QPointer m_rescan_wallet_model; wallet::RescanStatus m_rescan_status{}; }; From 025df83893f0f24567544418457698c389a12526 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Wed, 17 Dec 2025 17:18:24 +0530 Subject: [PATCH 5/6] qt: switch over to rescan wallet activity --- src/qt/rpcconsole.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index b8f7df75dafa..e4f87b000e7e 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -71,8 +71,6 @@ const char fontSizeSettingsKey[] = "consoleFontSize"; const TrafficGraphData::GraphRange INITIAL_TRAFFIC_GRAPH_SETTING = TrafficGraphData::Range_30m; // Repair parameters -const QString RESCAN1("-rescan=1"); -const QString RESCAN2("-rescan=2"); const QString REINDEX("-reindex"); namespace { @@ -946,13 +944,13 @@ void RPCConsole::walletRescan(bool from_genesis) /** Rescan wallet from wallet creation */ void RPCConsole::walletRescan1() { - buildParameterlist(RESCAN1); + walletRescan(/*from_genesis=*/false); } /** Rescan wallet from genesis block */ void RPCConsole::walletRescan2() { - buildParameterlist(RESCAN2); + walletRescan(/*from_genesis=*/true); } #endif @@ -979,8 +977,6 @@ void RPCConsole::buildParameterlist(QString arg) } // Remove existing repair-options - args.removeAll(RESCAN1); - args.removeAll(RESCAN2); args.removeAll(REINDEX); // Append repair parameter to command line. From 931707c48b31cc2d2166d7ac52a7ba6ecce4a740 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Fri, 19 Dec 2025 02:40:53 +0530 Subject: [PATCH 6/6] feat(qt): enable wallet rescan for multiple loaded wallets Co-authored-by: UdjinM6 --- src/qt/rpcconsole.cpp | 56 ++++++++++++++++++++++++------------------- src/qt/rpcconsole.h | 2 ++ 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index e4f87b000e7e..1591e1580bbb 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -580,6 +580,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, QWidget* parent, Qt::WindowFlags #ifdef ENABLE_WALLET connect(ui->btn_rescan1, &QPushButton::clicked, this, &RPCConsole::walletRescan1); connect(ui->btn_rescan2, &QPushButton::clicked, this, &RPCConsole::walletRescan2); + connect(ui->WalletSelector, qOverload(&QComboBox::currentIndexChanged), this, &RPCConsole::onWalletChanged); #endif // ENABLE_WALLET connect(ui->btn_reindex, &QPushButton::clicked, this, &RPCConsole::walletReindex); @@ -833,40 +834,29 @@ void RPCConsole::addWallet(WalletModel * const walletModel) if (ui->WalletSelector->count() == 2) { // First wallet added, set to default to match wallet RPC behavior ui->WalletSelector->setCurrentIndex(1); - // The only loaded wallet - ui->btn_rescan1->setEnabled(true); - ui->btn_rescan2->setEnabled(true); - QString wallet_path = GUIUtil::PathToQString(GetWalletDir()) + QDir::separator().toLatin1(); - QString wallet_name = walletModel->getWalletName().isEmpty() ? "wallet.dat" : walletModel->getWalletName(); - ui->wallet_path->setText(wallet_path + wallet_name); - } else { + } + + // Update wallet path and button states for currently selected wallet + onWalletChanged(); + + // Show wallet selector when multiple wallets are loaded + if (ui->WalletSelector->count() > 2) { ui->WalletSelector->setVisible(true); ui->WalletSelectorLabel->setVisible(true); - // No wallet recovery for multiple loaded wallets - ui->btn_rescan1->setEnabled(false); - ui->btn_rescan2->setEnabled(false); - ui->wallet_path->clear(); } } void RPCConsole::removeWallet(WalletModel * const walletModel) { ui->WalletSelector->removeItem(ui->WalletSelector->findData(QVariant::fromValue(walletModel))); + + // Update wallet path and button states for currently selected wallet (or clear/disable if none) + onWalletChanged(); + + // Hide wallet selector when back to single wallet if (ui->WalletSelector->count() == 2) { ui->WalletSelector->setVisible(false); ui->WalletSelectorLabel->setVisible(false); - // Back to the only loaded wallet - ui->btn_rescan1->setEnabled(true); - ui->btn_rescan2->setEnabled(true); - WalletModel* wallet_model = ui->WalletSelector->itemData(1).value(); - QString wallet_path = GUIUtil::PathToQString(GetWalletDir()) + QDir::separator().toLatin1(); - QString wallet_name = wallet_model->getWalletName().isEmpty() ? "wallet.dat" : wallet_model->getWalletName(); - ui->wallet_path->setText(wallet_path + wallet_name); - } else { - // No wallet recovery for multiple loaded wallets - ui->btn_rescan1->setEnabled(false); - ui->btn_rescan2->setEnabled(false); - ui->wallet_path->clear(); } } @@ -875,6 +865,24 @@ void RPCConsole::setCurrentWallet(WalletModel* const wallet_model) QVariant data = QVariant::fromValue(wallet_model); ui->WalletSelector->setCurrentIndex(ui->WalletSelector->findData(data)); } + +void RPCConsole::onWalletChanged() +{ + WalletModel* wallet_model = ui->WalletSelector->currentData().value(); + if (wallet_model) { + QString wallet_path = GUIUtil::PathToQString(GetWalletDir()) + QDir::separator().toLatin1(); + QString wallet_name = wallet_model->getWalletName().isEmpty() ? "wallet.dat" : wallet_model->getWalletName(); + ui->wallet_path->setText(wallet_path + wallet_name); + // Enable rescan buttons when a valid wallet is selected + ui->btn_rescan1->setEnabled(true); + ui->btn_rescan2->setEnabled(true); + } else { + ui->wallet_path->clear(); + // Disable rescan buttons when no wallet is selected (e.g., "(none)") + ui->btn_rescan1->setEnabled(false); + ui->btn_rescan2->setEnabled(false); + } +} #endif static QString categoryClass(int category) @@ -931,7 +939,7 @@ void RPCConsole::walletRescan(bool from_genesis) return; } - WalletModel* wallet_model{ui->WalletSelector->itemData(1).value()}; + WalletModel* wallet_model{ui->WalletSelector->currentData().value()}; if (!wallet_model) { QMessageBox::critical(this, PACKAGE_NAME, QObject::tr("Error: Rescan failed. Wallet not loaded.")); return; diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index ef1e7dd349da..4046128cb8fc 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -181,6 +181,8 @@ public Q_SLOTS: #ifdef ENABLE_WALLET /** Initiate a wallet rescan */ void walletRescan(bool from_genesis); + /** Update wallet UI when selected wallet changes */ + void onWalletChanged(); #endif // ENABLE_WALLET enum ColumnWidths