Skip to content

Commit 2e78881

Browse files
committed
gui: Add restore_and_migrate function to restore then migrate a wallet
restore_and_migrate first restores a wallet file to the wallets directory in the expected layout, then it performs legacy to descriptor wallet migration on the restored wallet.
1 parent 8db890a commit 2e78881

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/qt/walletcontroller.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,45 @@ void MigrateWalletActivity::migrate(const std::string& name)
489489
do_migrate(name);
490490
}
491491

492+
void MigrateWalletActivity::restore_and_migrate(const fs::path& path, const std::string& wallet_name)
493+
{
494+
// Warn the user about migration
495+
QMessageBox box(m_parent_widget);
496+
box.setWindowTitle(tr("Restore and Migrate wallet"));
497+
box.setText(tr("Are you sure you wish to restore the wallet file <i>%1</i> to <i>%2</i> and migrate it?").arg(GUIUtil::HtmlEscape(path), GUIUtil::HtmlEscape(GUIUtil::WalletDisplayName(wallet_name))));
498+
box.setInformativeText(tr("Restoring the wallet will copy the backup file to the wallets directory and place it in the standard "
499+
"wallet directory layout. The original file will not be modified.\n\n"
500+
"Migrating the wallet will convert the restored wallet to one or more descriptor wallets. A new wallet backup will need to be made.\n"
501+
"If this wallet contains any watchonly scripts, a new wallet will be created which contains those watchonly scripts.\n"
502+
"If this wallet contains any solvable but not watched scripts, a different and new wallet will be created which contains those scripts.\n\n"
503+
"The migration process will create a backup of the wallet before migrating. This backup file will be named "
504+
"<wallet name>-<timestamp>.legacy.bak and can be found in the directory for this wallet. In the event of "
505+
"an incorrect migration, the backup can be restored with the \"Restore Wallet\" functionality."));
506+
box.setStandardButtons(QMessageBox::Yes|QMessageBox::Cancel);
507+
box.setDefaultButton(QMessageBox::Yes);
508+
if (box.exec() != QMessageBox::Yes) return;
509+
510+
showProgressDialog(
511+
//: Title of progress window which is displayed when wallets are being restored.
512+
tr("Restore Wallet"),
513+
/*: Descriptive text of the restore wallets progress window which indicates to
514+
the user that wallets are currently being restored.*/
515+
tr("Restoring Wallet <b>%1</b>…").arg(GUIUtil::HtmlEscape(GUIUtil::WalletDisplayName(wallet_name))));
516+
517+
QTimer::singleShot(0, worker(), [this, path, wallet_name] {
518+
auto res{node().walletLoader().restoreWallet(path, wallet_name, m_warning_message, /*load_after_restore=*/false)};
519+
520+
if (!res) {
521+
m_error_message = util::ErrorString(res);
522+
QTimer::singleShot(0, this, &MigrateWalletActivity::finish);
523+
return;
524+
}
525+
QTimer::singleShot(0, this, [this, wallet_name] {
526+
do_migrate(wallet_name);
527+
});
528+
});
529+
}
530+
492531
void MigrateWalletActivity::finish()
493532
{
494533
if (!m_error_message.empty()) {

src/qt/walletcontroller.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class MigrateWalletActivity : public WalletControllerActivity
187187
public:
188188
MigrateWalletActivity(WalletController* wallet_controller, QWidget* parent) : WalletControllerActivity(wallet_controller, parent) {}
189189

190+
void restore_and_migrate(const fs::path& path, const std::string& wallet_name);
190191
void migrate(const std::string& path);
191192

192193
Q_SIGNALS:

0 commit comments

Comments
 (0)