Skip to content

Commit c3e5365

Browse files
committed
Bugfix: Wallet: Return util::Error rather than non-error nullptr when CreateWallet/LoadWallet/RestoreWallet fail
1 parent 335ff98 commit c3e5365

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/wallet/interfaces.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,12 @@ class WalletLoaderImpl : public WalletLoader
560560
options.create_flags = wallet_creation_flags;
561561
options.create_passphrase = passphrase;
562562
bilingual_str error;
563-
util::Result<std::unique_ptr<Wallet>> wallet{MakeWallet(m_context, CreateWallet(m_context, name, /*load_on_start=*/true, options, status, error, warnings))};
564-
return wallet ? std::move(wallet) : util::Error{error};
563+
std::unique_ptr<Wallet> wallet{MakeWallet(m_context, CreateWallet(m_context, name, /*load_on_start=*/true, options, status, error, warnings))};
564+
if (wallet) {
565+
return {std::move(wallet)};
566+
} else {
567+
return util::Error{error};
568+
}
565569
}
566570
util::Result<std::unique_ptr<Wallet>> loadWallet(const std::string& name, std::vector<bilingual_str>& warnings) override
567571
{
@@ -570,15 +574,23 @@ class WalletLoaderImpl : public WalletLoader
570574
ReadDatabaseArgs(*m_context.args, options);
571575
options.require_existing = true;
572576
bilingual_str error;
573-
util::Result<std::unique_ptr<Wallet>> wallet{MakeWallet(m_context, LoadWallet(m_context, name, /*load_on_start=*/true, options, status, error, warnings))};
574-
return wallet ? std::move(wallet) : util::Error{error};
577+
std::unique_ptr<Wallet> wallet{MakeWallet(m_context, LoadWallet(m_context, name, /*load_on_start=*/true, options, status, error, warnings))};
578+
if (wallet) {
579+
return {std::move(wallet)};
580+
} else {
581+
return util::Error{error};
582+
}
575583
}
576584
util::Result<std::unique_ptr<Wallet>> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, std::vector<bilingual_str>& warnings) override
577585
{
578586
DatabaseStatus status;
579587
bilingual_str error;
580-
util::Result<std::unique_ptr<Wallet>> wallet{MakeWallet(m_context, RestoreWallet(m_context, backup_file, wallet_name, /*load_on_start=*/true, status, error, warnings))};
581-
return wallet ? std::move(wallet) : util::Error{error};
588+
std::unique_ptr<Wallet> wallet{MakeWallet(m_context, RestoreWallet(m_context, backup_file, wallet_name, /*load_on_start=*/true, status, error, warnings))};
589+
if (wallet) {
590+
return {std::move(wallet)};
591+
} else {
592+
return util::Error{error};
593+
}
582594
}
583595
std::string getWalletDir() override
584596
{

0 commit comments

Comments
 (0)