mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-21 14:22:38 +02:00
interfaces, wallet: Expose migrate wallet
This commit is contained in:
parent
da494186f2
commit
5b3a85b4c6
@ -50,6 +50,7 @@ struct WalletBalances;
|
|||||||
struct WalletTx;
|
struct WalletTx;
|
||||||
struct WalletTxOut;
|
struct WalletTxOut;
|
||||||
struct WalletTxStatus;
|
struct WalletTxStatus;
|
||||||
|
struct WalletMigrationResult;
|
||||||
|
|
||||||
using WalletOrderForm = std::vector<std::pair<std::string, std::string>>;
|
using WalletOrderForm = std::vector<std::pair<std::string, std::string>>;
|
||||||
using WalletValueMap = std::map<std::string, std::string>;
|
using WalletValueMap = std::map<std::string, std::string>;
|
||||||
@ -332,6 +333,9 @@ public:
|
|||||||
//! Restore backup wallet
|
//! Restore backup wallet
|
||||||
virtual util::Result<std::unique_ptr<Wallet>> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, std::vector<bilingual_str>& warnings) = 0;
|
virtual util::Result<std::unique_ptr<Wallet>> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, std::vector<bilingual_str>& warnings) = 0;
|
||||||
|
|
||||||
|
//! Migrate a wallet
|
||||||
|
virtual util::Result<WalletMigrationResult> migrateWallet(const std::string& name, const SecureString& passphrase) = 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;
|
||||||
|
|
||||||
@ -423,6 +427,15 @@ struct WalletTxOut
|
|||||||
bool is_spent = false;
|
bool is_spent = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! Migrated wallet info
|
||||||
|
struct WalletMigrationResult
|
||||||
|
{
|
||||||
|
std::unique_ptr<Wallet> wallet;
|
||||||
|
std::optional<std::string> watchonly_wallet_name;
|
||||||
|
std::optional<std::string> solvables_wallet_name;
|
||||||
|
fs::path backup_path;
|
||||||
|
};
|
||||||
|
|
||||||
//! Return implementation of Wallet interface. This function is defined in
|
//! Return implementation of Wallet interface. This function is defined in
|
||||||
//! dummywallet.cpp and throws if the wallet component is not compiled.
|
//! dummywallet.cpp and throws if the wallet component is not compiled.
|
||||||
std::unique_ptr<Wallet> MakeWallet(wallet::WalletContext& context, const std::shared_ptr<wallet::CWallet>& wallet);
|
std::unique_ptr<Wallet> MakeWallet(wallet::WalletContext& context, const std::shared_ptr<wallet::CWallet>& wallet);
|
||||||
|
@ -42,6 +42,7 @@ using interfaces::Wallet;
|
|||||||
using interfaces::WalletAddress;
|
using interfaces::WalletAddress;
|
||||||
using interfaces::WalletBalances;
|
using interfaces::WalletBalances;
|
||||||
using interfaces::WalletLoader;
|
using interfaces::WalletLoader;
|
||||||
|
using interfaces::WalletMigrationResult;
|
||||||
using interfaces::WalletOrderForm;
|
using interfaces::WalletOrderForm;
|
||||||
using interfaces::WalletTx;
|
using interfaces::WalletTx;
|
||||||
using interfaces::WalletTxOut;
|
using interfaces::WalletTxOut;
|
||||||
@ -631,6 +632,18 @@ public:
|
|||||||
return util::Error{error};
|
return util::Error{error};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
util::Result<WalletMigrationResult> migrateWallet(const std::string& name, const SecureString& passphrase) override
|
||||||
|
{
|
||||||
|
auto res = wallet::MigrateLegacyToDescriptor(name, passphrase, m_context);
|
||||||
|
if (!res) return util::Error{util::ErrorString(res)};
|
||||||
|
WalletMigrationResult out{
|
||||||
|
.wallet = MakeWallet(m_context, res->wallet),
|
||||||
|
.watchonly_wallet_name = res->watchonly_wallet ? std::make_optional(res->watchonly_wallet->GetName()) : std::nullopt,
|
||||||
|
.solvables_wallet_name = res->solvables_wallet ? std::make_optional(res->solvables_wallet->GetName()) : std::nullopt,
|
||||||
|
.backup_path = res->backup_path,
|
||||||
|
};
|
||||||
|
return {std::move(out)}; // std::move to work around clang bug
|
||||||
|
}
|
||||||
std::string getWalletDir() override
|
std::string getWalletDir() override
|
||||||
{
|
{
|
||||||
return fs::PathToString(GetWalletDir());
|
return fs::PathToString(GetWalletDir());
|
||||||
|
@ -4253,7 +4253,7 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& walle
|
|||||||
// Migration successful, unload the wallet locally, then reload it.
|
// Migration successful, unload the wallet locally, then reload it.
|
||||||
assert(local_wallet.use_count() == 1);
|
assert(local_wallet.use_count() == 1);
|
||||||
local_wallet.reset();
|
local_wallet.reset();
|
||||||
LoadWallet(context, wallet_name, /*load_on_start=*/std::nullopt, options, status, error, warnings);
|
res.wallet = LoadWallet(context, wallet_name, /*load_on_start=*/std::nullopt, options, status, error, warnings);
|
||||||
res.wallet_name = wallet_name;
|
res.wallet_name = wallet_name;
|
||||||
} else {
|
} else {
|
||||||
// Migration failed, cleanup
|
// Migration failed, cleanup
|
||||||
|
@ -1068,6 +1068,7 @@ bool FillInputToWeight(CTxIn& txin, int64_t target_weight);
|
|||||||
|
|
||||||
struct MigrationResult {
|
struct MigrationResult {
|
||||||
std::string wallet_name;
|
std::string wallet_name;
|
||||||
|
std::shared_ptr<CWallet> wallet;
|
||||||
std::shared_ptr<CWallet> watchonly_wallet;
|
std::shared_ptr<CWallet> watchonly_wallet;
|
||||||
std::shared_ptr<CWallet> solvables_wallet;
|
std::shared_ptr<CWallet> solvables_wallet;
|
||||||
fs::path backup_path;
|
fs::path backup_path;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user