mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-21 13:10:08 +01:00
wallet: replace reload_wallet with inline functionality
Also, update related comments because a reload is not happening anymore. It is done because the legacy wallets could not have been loaded prior to migration, so I don't think a reload is happening post a successful migration, it's just load IMO.
This commit is contained in:
@@ -4226,15 +4226,6 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
|
||||
|
||||
const std::string wallet_name = local_wallet->GetName();
|
||||
|
||||
// Helper to reload as normal for some of our exit scenarios
|
||||
const auto& reload_wallet = [&](std::shared_ptr<CWallet>& to_reload) {
|
||||
assert(to_reload.use_count() == 1);
|
||||
std::string name = to_reload->GetName();
|
||||
to_reload.reset();
|
||||
to_reload = LoadWallet(context, name, /*load_on_start=*/std::nullopt, options, status, error, warnings);
|
||||
return to_reload != nullptr;
|
||||
};
|
||||
|
||||
// Before anything else, check if there is something to migrate.
|
||||
if (local_wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
|
||||
return util::Error{_("Error: This wallet is already a descriptor wallet")};
|
||||
@@ -4289,10 +4280,10 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
|
||||
}
|
||||
}
|
||||
|
||||
// In case of reloading failure, we need to remember the wallet dirs to remove
|
||||
// Set is used as it may be populated with the same wallet directory paths multiple times,
|
||||
// both before and after reloading. This ensures the set is complete even if one of the wallets
|
||||
// fails to reload.
|
||||
// In case of loading failure, we need to remember the wallet dirs to remove.
|
||||
// A `set` is used as it may be populated with the same wallet directory paths multiple times,
|
||||
// both before and after loading. This ensures the set is complete even if one of the wallets
|
||||
// fails to load.
|
||||
std::set<fs::path> wallet_dirs;
|
||||
if (success) {
|
||||
Assume(!res.wallet); // We will set it here.
|
||||
@@ -4304,15 +4295,17 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
|
||||
for (const auto& path_to_remove : paths_to_remove) fs::remove_all(path_to_remove);
|
||||
}
|
||||
|
||||
// Migration successful, unload all wallets locally, then reload them.
|
||||
// Note: We use a pointer to the shared_ptr to avoid increasing its reference count,
|
||||
// as 'reload_wallet' expects to be the sole owner (use_count == 1).
|
||||
// Migration successful, load all the migrated wallets.
|
||||
for (std::shared_ptr<CWallet>* wallet_ptr : {&local_wallet, &res.watchonly_wallet, &res.solvables_wallet}) {
|
||||
if (success && *wallet_ptr) {
|
||||
std::shared_ptr<CWallet>& wallet = *wallet_ptr;
|
||||
// Save db path and reload wallet
|
||||
// Save db path and load wallet
|
||||
wallet_dirs.insert(fs::PathFromString(wallet->GetDatabase().Filename()).parent_path());
|
||||
success = reload_wallet(wallet);
|
||||
assert(wallet.use_count() == 1);
|
||||
std::string wallet_name = wallet->GetName();
|
||||
wallet.reset();
|
||||
wallet = LoadWallet(context, wallet_name, /*load_on_start=*/std::nullopt, options, status, error, warnings);
|
||||
success = (wallet != nullptr);
|
||||
|
||||
// When no wallet is set, set the main wallet.
|
||||
if (!res.wallet) {
|
||||
|
||||
Reference in New Issue
Block a user