mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
interfaces, wallet: Expose migrate wallet
This commit is contained in:
@@ -42,6 +42,7 @@ using interfaces::Wallet;
|
||||
using interfaces::WalletAddress;
|
||||
using interfaces::WalletBalances;
|
||||
using interfaces::WalletLoader;
|
||||
using interfaces::WalletMigrationResult;
|
||||
using interfaces::WalletOrderForm;
|
||||
using interfaces::WalletTx;
|
||||
using interfaces::WalletTxOut;
|
||||
@@ -631,6 +632,18 @@ public:
|
||||
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
|
||||
{
|
||||
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.
|
||||
assert(local_wallet.use_count() == 1);
|
||||
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;
|
||||
} else {
|
||||
// Migration failed, cleanup
|
||||
|
||||
@@ -1068,6 +1068,7 @@ bool FillInputToWeight(CTxIn& txin, int64_t target_weight);
|
||||
|
||||
struct MigrationResult {
|
||||
std::string wallet_name;
|
||||
std::shared_ptr<CWallet> wallet;
|
||||
std::shared_ptr<CWallet> watchonly_wallet;
|
||||
std::shared_ptr<CWallet> solvables_wallet;
|
||||
fs::path backup_path;
|
||||
|
||||
Reference in New Issue
Block a user