Skip to content

Commit c02e8a3

Browse files
committed
gui: Add a menu item to restore then migrate a wallet file
Some users will have backups of a legacy wallet which cannot be restored due to being a legacy wallet, and therefore cannot be migrated from the GUI. This menu item allows such users to restore and migrate their wallets in a single action.
1 parent 114b52d commit c02e8a3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/qt/bitcoingui.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,32 @@ void BitcoinGUI::createActions()
485485
QAction* action = m_migrate_wallet_menu->addAction(tr("No wallets available"));
486486
action->setEnabled(false);
487487
}
488+
m_migrate_wallet_menu->addSeparator();
489+
QAction* restore_migrate_file_action = m_migrate_wallet_menu->addAction(tr("Restore and Migrate Wallet File..."));
490+
restore_migrate_file_action->setEnabled(true);
491+
492+
connect(restore_migrate_file_action, &QAction::triggered, [this] {
493+
QString name_data_file = tr("Wallet Data");
494+
QString title_windows = tr("Restore and Migrate Wallet Backup");
495+
496+
QString backup_file = GUIUtil::getOpenFileName(this, title_windows, QString(), name_data_file + QLatin1String(" (*.dat)"), nullptr);
497+
if (backup_file.isEmpty()) return;
498+
499+
bool wallet_name_ok;
500+
/*: Title of pop-up window shown when the user is attempting to
501+
restore a wallet. */
502+
QString title = tr("Restore and Migrate Wallet");
503+
//: Label of the input field where the name of the wallet is entered.
504+
QString label = tr("Wallet Name");
505+
QString wallet_name = QInputDialog::getText(this, title, label, QLineEdit::Normal, "", &wallet_name_ok);
506+
if (!wallet_name_ok || wallet_name.isEmpty()) return;
507+
508+
auto activity = new MigrateWalletActivity(m_wallet_controller, this);
509+
connect(activity, &MigrateWalletActivity::migrated, this, &BitcoinGUI::setCurrentWallet);
510+
connect(activity, &MigrateWalletActivity::migrated, rpcConsole, &RPCConsole::setCurrentWallet);
511+
auto backup_file_path = fs::PathFromString(backup_file.toStdString());
512+
activity->restore_and_migrate(backup_file_path, wallet_name.toStdString());
513+
});
488514
});
489515
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::setPrivacy);
490516
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::enableHistoryAction);

0 commit comments

Comments
 (0)