interfaces, wallet: Expose migrate wallet

This commit is contained in:
Andrew Chow
2023-06-13 15:04:22 -04:00
parent da494186f2
commit 5b3a85b4c6
4 changed files with 28 additions and 1 deletions

View File

@@ -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());

View File

@@ -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

View File

@@ -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;