diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
--- a/src/wallet/wallet.cpp (revision 014231c3fd7bc479784cb187560d417118000e61)
+++ b/src/wallet/wallet.cpp (date 1697512277377)
@@ -4249,28 +4249,27 @@
std::set<fs::path> wallet_dirs;
if (success) {
// Migration successful, unload all wallets locally, then reload them.
- assert(local_wallet.use_count() == 1);
- wallet_dirs.insert(fs::PathFromString(local_wallet->GetDatabase().Filename()).parent_path());
- local_wallet.reset();
- res.wallet = LoadWallet(context, wallet_name, /*load_on_start=*/std::nullopt, options, status, error, warnings);
+ const auto& reload_wallet = [&](std::shared_ptr<CWallet>& to_reload) {
+ assert(to_reload.use_count() == 1);
+ std::string name = to_reload->GetName();
+ wallet_dirs.insert(fs::PathFromString(to_reload->GetDatabase().Filename()).parent_path());
+ to_reload.reset();
+ to_reload = LoadWallet(context, name, /*load_on_start=*/std::nullopt, options, status, error, warnings);
+ return to_reload != nullptr;
+ };
+
+ // Reload main wallet
+ success = reload_wallet(local_wallet);
+ res.wallet = local_wallet;
res.wallet_name = wallet_name;
- success = res.wallet != nullptr;
- }
- if (success && res.watchonly_wallet) {
- assert(res.watchonly_wallet.use_count() == 1);
- std::string watchonly_wallet_name = res.watchonly_wallet->GetName();
- wallet_dirs.insert(fs::PathFromString(res.watchonly_wallet->GetDatabase().Filename()).parent_path());
- res.watchonly_wallet.reset();
- res.watchonly_wallet = LoadWallet(context, watchonly_wallet_name, /*load_on_start=*/std::nullopt, options, status, error, warnings);
- success = res.watchonly_wallet != nullptr;
- }
- if (success && res.solvables_wallet) {
- assert(res.solvables_wallet.use_count() == 1);
- std::string solvables_wallet_name = res.solvables_wallet->GetName();
- wallet_dirs.insert(fs::PathFromString(res.solvables_wallet->GetDatabase().Filename()).parent_path());
- res.solvables_wallet.reset();
- res.solvables_wallet = LoadWallet(context, solvables_wallet_name, /*load_on_start=*/std::nullopt, options, status, error, warnings);
- success = res.solvables_wallet != nullptr;
+ // Reload watch-only wallet
+ if (success && res.watchonly_wallet) {
+ success = reload_wallet(res.watchonly_wallet);
+ }
+ // Reload solvables wallet
+ if (success && res.solvables_wallet) {
+ success = reload_wallet(res.solvables_wallet);
+ }
}
if (!success) {
// Migration failed, cleanup