Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 76b3077

Browse files
MacroFakevijaydasmp
authored andcommittedJun 7, 2025··
Merge bitcoin#25594: refactor: Return BResult from restoreWallet
fa475e9 refactor: Return BResult from restoreWallet (MacroFake) fa8de09 Prepare BResult for non-copyable types (MacroFake) Pull request description: This avoids the `error` in-out param (and if `warnings` is added to `BResult`, it will avoid passing that in-out param as well). Also, as it is needed for this change, prepare `BResult` for non-copyable types. ACKs for top commit: w0xlt: reACK bitcoin@fa475e9 ryanofsky: Code review ACK fa475e9. Changes since last review were replacing auto with explicit type and splitting commits Tree-SHA512: 46350883572f13721ddd198f5dfb88d2fa58ebcbda416f74da3563ea15c920fb1e6ff30558526a4ac91c36c21e6afe27751a4e51b7b8bcbcbe805209f4e9014b
1 parent 8e5346a commit 76b3077

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed
 

‎src/interfaces/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class WalletLoader : public ChainClient
352352
virtual std::string getWalletDir() = 0;
353353

354354
//! Restore backup wallet
355-
virtual std::unique_ptr<Wallet> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, bilingual_str& error, std::vector<bilingual_str>& warnings) = 0;
355+
virtual BResult<std::unique_ptr<Wallet>> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, std::vector<bilingual_str>& warnings) = 0;
356356

357357
//! Return available wallets in wallet directory.
358358
virtual std::vector<std::string> listWalletDir() = 0;

‎src/qt/walletcontroller.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,10 @@ void RestoreWalletActivity::restore(const fs::path& backup_file, const std::stri
369369
tr("Restoring Wallet <b>%1</b>…").arg(name.toHtmlEscaped()));
370370

371371
QTimer::singleShot(0, worker(), [this, backup_file, wallet_name] {
372-
std::unique_ptr<interfaces::Wallet> wallet = node().walletLoader().restoreWallet(backup_file, wallet_name, m_error_message, m_warning_message);
372+
auto wallet{node().walletLoader().restoreWallet(backup_file, wallet_name, m_warning_message)};
373373

374-
if (wallet) m_wallet_model = m_wallet_controller->getOrCreateWallet(std::move(wallet));
374+
m_error_message = wallet ? bilingual_str{} : wallet.GetError();
375+
if (wallet) m_wallet_model = m_wallet_controller->getOrCreateWallet(wallet.ReleaseObj());
375376

376377
QTimer::singleShot(0, this, &RestoreWalletActivity::finish);
377378
});

‎src/wallet/interfaces.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,13 @@ class WalletLoaderImpl : public WalletLoader
625625
options.require_existing = true;
626626
return MakeWallet(m_context, LoadWallet(m_context, name, true /* load_on_start */, options, status, error, warnings));
627627
}
628-
std::unique_ptr<Wallet> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, bilingual_str& error, std::vector<bilingual_str>& warnings) override
628+
BResult<std::unique_ptr<Wallet>> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, std::vector<bilingual_str>& warnings) override
629629
{
630630
DatabaseStatus status;
631-
return MakeWallet(m_context, RestoreWallet(m_context, backup_file, wallet_name, /*load_on_start=*/true, status, error, warnings));
631+
bilingual_str error;
632+
BResult<std::unique_ptr<Wallet>> wallet{MakeWallet(m_context, RestoreWallet(m_context, backup_file, wallet_name, /*load_on_start=*/true, status, error, warnings))};
633+
if (!wallet) return error;
634+
return wallet;
632635
}
633636
std::string getWalletDir() override
634637
{

0 commit comments

Comments
 (0)
Please sign in to comment.