Skip to content

Commit

Permalink
wallet: remove MigrateLegacyToDescriptor overload
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Jan 18, 2023
1 parent 8d957e3 commit 456780b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
9 changes: 1 addition & 8 deletions src/wallet/rpc/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,14 +750,7 @@ static RPCHelpMan migratewallet()
wallet_pass = request.params[1].isNull() ? "" : request.params[1].get_str().c_str();

WalletContext& context = EnsureWalletContext(request.context);
std::shared_ptr<CWallet> wallet = GetWallet(context, wallet_name);
util::Result<MigrationResult> res;
if (wallet) {
res = MigrateLegacyToDescriptor(std::move(wallet), wallet_pass, context);
} else {
res = MigrateLegacyToDescriptor(wallet_name, wallet_pass, context);
}

util::Result<MigrationResult> res = MigrateLegacyToDescriptor(wallet_name, wallet_pass, context);
if (!res) {
throw JSONRPCError(RPC_WALLET_ERROR, util::ErrorString(res).original);
}
Expand Down
10 changes: 8 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4110,7 +4110,7 @@ bool DoMigration(CWallet& wallet, WalletContext& context, bilingual_str& error,
return true;
}

util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>&& wallet, SecureString passphrase, WalletContext& context)
static util::Result<bool> UnloadWalletForMigration(std::shared_ptr<CWallet>& wallet, WalletContext& context)
{
std::vector<bilingual_str> warnings;
std::string wallet_name = wallet->GetName();
Expand All @@ -4121,7 +4121,7 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
}
UnloadWallet(std::move(wallet));

return MigrateLegacyToDescriptor(wallet_name, passphrase, context);
return true;
}

util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& wallet_name, SecureString passphrase, WalletContext& context)
Expand All @@ -4130,6 +4130,12 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& walle
bilingual_str error;
std::vector<bilingual_str> warnings;

// If it's loaded, unload wallet during the migration process
if (auto wallet = GetWallet(context, wallet_name)) {
auto res_unload = UnloadWalletForMigration(wallet, context);
if (!res_unload) return util::Error{util::ErrorString(res_unload)};
}

// Load the wallet but only in the context of this function.
// No signals should be connected nor should anything else be aware of this wallet
WalletContext empty_context;
Expand Down
1 change: 0 additions & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,6 @@ struct MigrationResult {
};

//! Do all steps to migrate a legacy wallet to a descriptor wallet
util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>&& wallet, SecureString passphrase, WalletContext& context);
util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& wallet_name, SecureString passphrase, WalletContext& context);
} // namespace wallet

Expand Down

0 comments on commit 456780b

Please sign in to comment.