mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-24 02:42:12 +02:00
Merge bitcoin/bitcoin#25594: refactor: Return BResult from restoreWallet
fa475e9c7977a952617738f2ee8cf600c07d4df8 refactor: Return BResult from restoreWallet (MacroFake)
fa8de09edc9ec4e6d171df80f746174a0ec58afb 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 fa475e9c79
ryanofsky:
Code review ACK fa475e9c7977a952617738f2ee8cf600c07d4df8. Changes since last review were replacing auto with explicit type and splitting commits
Tree-SHA512: 46350883572f13721ddd198f5dfb88d2fa58ebcbda416f74da3563ea15c920fb1e6ff30558526a4ac91c36c21e6afe27751a4e51b7b8bcbcbe805209f4e9014b
This commit is contained in:
commit
062b9db0cc
@ -329,7 +329,7 @@ public:
|
|||||||
virtual std::string getWalletDir() = 0;
|
virtual std::string getWalletDir() = 0;
|
||||||
|
|
||||||
//! Restore backup wallet
|
//! Restore backup wallet
|
||||||
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;
|
virtual BResult<std::unique_ptr<Wallet>> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, std::vector<bilingual_str>& warnings) = 0;
|
||||||
|
|
||||||
//! Return available wallets in wallet directory.
|
//! Return available wallets in wallet directory.
|
||||||
virtual std::vector<std::string> listWalletDir() = 0;
|
virtual std::vector<std::string> listWalletDir() = 0;
|
||||||
|
@ -391,9 +391,10 @@ void RestoreWalletActivity::restore(const fs::path& backup_file, const std::stri
|
|||||||
tr("Restoring Wallet <b>%1</b>…").arg(name.toHtmlEscaped()));
|
tr("Restoring Wallet <b>%1</b>…").arg(name.toHtmlEscaped()));
|
||||||
|
|
||||||
QTimer::singleShot(0, worker(), [this, backup_file, wallet_name] {
|
QTimer::singleShot(0, worker(), [this, backup_file, wallet_name] {
|
||||||
std::unique_ptr<interfaces::Wallet> wallet = node().walletLoader().restoreWallet(backup_file, wallet_name, m_error_message, m_warning_message);
|
auto wallet{node().walletLoader().restoreWallet(backup_file, wallet_name, m_warning_message)};
|
||||||
|
|
||||||
if (wallet) m_wallet_model = m_wallet_controller->getOrCreateWallet(std::move(wallet));
|
m_error_message = wallet ? bilingual_str{} : wallet.GetError();
|
||||||
|
if (wallet) m_wallet_model = m_wallet_controller->getOrCreateWallet(wallet.ReleaseObj());
|
||||||
|
|
||||||
QTimer::singleShot(0, this, &RestoreWalletActivity::finish);
|
QTimer::singleShot(0, this, &RestoreWalletActivity::finish);
|
||||||
});
|
});
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#define BITCOIN_UTIL_RESULT_H
|
#define BITCOIN_UTIL_RESULT_H
|
||||||
|
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
|
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -18,9 +19,9 @@ private:
|
|||||||
std::variant<bilingual_str, T> m_variant;
|
std::variant<bilingual_str, T> m_variant;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BResult() : m_variant(Untranslated("")) {}
|
BResult() : m_variant{Untranslated("")} {}
|
||||||
BResult(const T& _obj) : m_variant(_obj) {}
|
BResult(T obj) : m_variant{std::move(obj)} {}
|
||||||
BResult(const bilingual_str& error) : m_variant(error) {}
|
BResult(bilingual_str error) : m_variant{std::move(error)} {}
|
||||||
|
|
||||||
/* Whether the function succeeded or not */
|
/* Whether the function succeeded or not */
|
||||||
bool HasRes() const { return std::holds_alternative<T>(m_variant); }
|
bool HasRes() const { return std::holds_alternative<T>(m_variant); }
|
||||||
@ -30,6 +31,11 @@ public:
|
|||||||
assert(HasRes());
|
assert(HasRes());
|
||||||
return std::get<T>(m_variant);
|
return std::get<T>(m_variant);
|
||||||
}
|
}
|
||||||
|
T ReleaseObj()
|
||||||
|
{
|
||||||
|
assert(HasRes());
|
||||||
|
return std::move(std::get<T>(m_variant));
|
||||||
|
}
|
||||||
|
|
||||||
/* In case of failure, the error cause */
|
/* In case of failure, the error cause */
|
||||||
const bilingual_str& GetError() const {
|
const bilingual_str& GetError() const {
|
||||||
|
@ -569,11 +569,13 @@ public:
|
|||||||
options.require_existing = true;
|
options.require_existing = true;
|
||||||
return MakeWallet(m_context, LoadWallet(m_context, name, true /* load_on_start */, options, status, error, warnings));
|
return MakeWallet(m_context, LoadWallet(m_context, name, true /* load_on_start */, options, status, error, warnings));
|
||||||
}
|
}
|
||||||
std::unique_ptr<Wallet> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, bilingual_str& error, std::vector<bilingual_str>& warnings) override
|
BResult<std::unique_ptr<Wallet>> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, std::vector<bilingual_str>& warnings) override
|
||||||
{
|
{
|
||||||
DatabaseStatus status;
|
DatabaseStatus status;
|
||||||
|
bilingual_str error;
|
||||||
return MakeWallet(m_context, RestoreWallet(m_context, backup_file, wallet_name, /*load_on_start=*/true, status, error, warnings));
|
BResult<std::unique_ptr<Wallet>> wallet{MakeWallet(m_context, RestoreWallet(m_context, backup_file, wallet_name, /*load_on_start=*/true, status, error, warnings))};
|
||||||
|
if (!wallet) return error;
|
||||||
|
return wallet;
|
||||||
}
|
}
|
||||||
std::string getWalletDir() override
|
std::string getWalletDir() override
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user