Skip to content

Commit fa475e9

Browse files
author
MacroFake
committed
refactor: Return BResult from restoreWallet
1 parent fa8de09 commit fa475e9

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/interfaces/wallet.h

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

331331
//! Restore backup wallet
332-
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;
332+
virtual BResult<std::unique_ptr<Wallet>> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, std::vector<bilingual_str>& warnings) = 0;
333333

334334
//! Return available wallets in wallet directory.
335335
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
@@ -391,9 +391,10 @@ void RestoreWalletActivity::restore(const fs::path& backup_file, const std::stri
391391
tr("Restoring Wallet <b>%1</b>…").arg(name.toHtmlEscaped()));
392392

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

396-
if (wallet) m_wallet_model = m_wallet_controller->getOrCreateWallet(std::move(wallet));
396+
m_error_message = wallet ? bilingual_str{} : wallet.GetError();
397+
if (wallet) m_wallet_model = m_wallet_controller->getOrCreateWallet(wallet.ReleaseObj());
397398

398399
QTimer::singleShot(0, this, &RestoreWalletActivity::finish);
399400
});

src/wallet/interfaces.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,13 @@ class WalletLoaderImpl : public WalletLoader
569569
options.require_existing = true;
570570
return MakeWallet(m_context, LoadWallet(m_context, name, true /* load_on_start */, options, status, error, warnings));
571571
}
572-
std::unique_ptr<Wallet> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, bilingual_str& error, std::vector<bilingual_str>& warnings) override
572+
BResult<std::unique_ptr<Wallet>> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, std::vector<bilingual_str>& warnings) override
573573
{
574574
DatabaseStatus status;
575-
576-
return MakeWallet(m_context, RestoreWallet(m_context, backup_file, wallet_name, /*load_on_start=*/true, status, error, warnings));
575+
bilingual_str error;
576+
BResult<std::unique_ptr<Wallet>> wallet{MakeWallet(m_context, RestoreWallet(m_context, backup_file, wallet_name, /*load_on_start=*/true, status, error, warnings))};
577+
if (!wallet) return error;
578+
return wallet;
577579
}
578580
std::string getWalletDir() override
579581
{

0 commit comments

Comments
 (0)