@@ -4226,15 +4226,6 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
4226
4226
4227
4227
const std::string wallet_name = local_wallet->GetName ();
4228
4228
4229
- // Helper to reload as normal for some of our exit scenarios
4230
- const auto & reload_wallet = [&](std::shared_ptr<CWallet>& to_reload) {
4231
- assert (to_reload.use_count () == 1 );
4232
- std::string name = to_reload->GetName ();
4233
- to_reload.reset ();
4234
- to_reload = LoadWallet (context, name, /* load_on_start=*/ std::nullopt, options, status, error, warnings);
4235
- return to_reload != nullptr ;
4236
- };
4237
-
4238
4229
// Before anything else, check if there is something to migrate.
4239
4230
if (local_wallet->IsWalletFlagSet (WALLET_FLAG_DESCRIPTORS)) {
4240
4231
return util::Error{_ (" Error: This wallet is already a descriptor wallet" )};
@@ -4289,10 +4280,10 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
4289
4280
}
4290
4281
}
4291
4282
4292
- // In case of reloading failure, we need to remember the wallet dirs to remove
4293
- // Set is used as it may be populated with the same wallet directory paths multiple times,
4294
- // both before and after reloading . This ensures the set is complete even if one of the wallets
4295
- // fails to reload .
4283
+ // In case of loading failure, we need to remember the wallet dirs to remove.
4284
+ // A `set` is used as it may be populated with the same wallet directory paths multiple times,
4285
+ // both before and after loading . This ensures the set is complete even if one of the wallets
4286
+ // fails to load .
4296
4287
std::set<fs::path> wallet_dirs;
4297
4288
if (success) {
4298
4289
Assume (!res.wallet ); // We will set it here.
@@ -4304,15 +4295,17 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
4304
4295
for (const auto & path_to_remove : paths_to_remove) fs::remove_all (path_to_remove);
4305
4296
}
4306
4297
4307
- // Migration successful, unload all wallets locally, then reload them.
4308
- // Note: We use a pointer to the shared_ptr to avoid increasing its reference count,
4309
- // as 'reload_wallet' expects to be the sole owner (use_count == 1).
4298
+ // Migration successful, load all the migrated wallets.
4310
4299
for (std::shared_ptr<CWallet>* wallet_ptr : {&local_wallet, &res.watchonly_wallet , &res.solvables_wallet }) {
4311
4300
if (success && *wallet_ptr) {
4312
4301
std::shared_ptr<CWallet>& wallet = *wallet_ptr;
4313
- // Save db path and reload wallet
4302
+ // Save db path and load wallet
4314
4303
wallet_dirs.insert (fs::PathFromString (wallet->GetDatabase ().Filename ()).parent_path ());
4315
- success = reload_wallet (wallet);
4304
+ assert (wallet.use_count () == 1 );
4305
+ std::string wallet_name = wallet->GetName ();
4306
+ wallet.reset ();
4307
+ wallet = LoadWallet (context, wallet_name, /* load_on_start=*/ std::nullopt, options, status, error, warnings);
4308
+ success = (wallet != nullptr );
4316
4309
4317
4310
// When no wallet is set, set the main wallet.
4318
4311
if (!res.wallet ) {
0 commit comments