Skip to content

Commit 8d0b5c1

Browse files
committed
gui: Use wallet name for wallet migration rather than WalletModel
To prepare for migrating wallets that are not loaded, when migration occurs in the GUI, it should not rely on a WalletModel existing.
1 parent 043e447 commit 8d0b5c1

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

src/qt/askpassphrasedialog.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ AskPassphraseDialog::AskPassphraseDialog(Mode _mode, QWidget *parent, SecureStri
4444
ui->passEdit1->hide();
4545
setWindowTitle(tr("Encrypt wallet"));
4646
break;
47+
case UnlockMigration:
4748
case Unlock: // Ask passphrase
4849
ui->warningLabel->setText(tr("This operation needs your wallet passphrase to unlock the wallet."));
4950
ui->passLabel2->hide();
@@ -80,7 +81,7 @@ void AskPassphraseDialog::setModel(WalletModel *_model)
8081
void AskPassphraseDialog::accept()
8182
{
8283
SecureString oldpass, newpass1, newpass2;
83-
if (!model && mode != Encrypt)
84+
if (!model && mode != Encrypt && mode != UnlockMigration)
8485
return;
8586
oldpass.reserve(MAX_PASSPHRASE_SIZE);
8687
newpass1.reserve(MAX_PASSPHRASE_SIZE);
@@ -181,6 +182,10 @@ void AskPassphraseDialog::accept()
181182
QMessageBox::critical(this, tr("Wallet unlock failed"), e.what());
182183
}
183184
break;
185+
case UnlockMigration:
186+
Assume(m_passphrase_out)->assign(oldpass);
187+
QDialog::accept();
188+
break;
184189
case ChangePass:
185190
if(newpass1 == newpass2)
186191
{
@@ -224,6 +229,7 @@ void AskPassphraseDialog::textChanged()
224229
case Encrypt: // New passphrase x2
225230
acceptable = !ui->passEdit2->text().isEmpty() && !ui->passEdit3->text().isEmpty();
226231
break;
232+
case UnlockMigration:
227233
case Unlock: // Old passphrase x1
228234
acceptable = !ui->passEdit1->text().isEmpty();
229235
break;

src/qt/askpassphrasedialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class AskPassphraseDialog : public QDialog
2626
Encrypt, /**< Ask passphrase twice and encrypt */
2727
Unlock, /**< Ask passphrase and unlock */
2828
ChangePass, /**< Ask old passphrase + new passphrase twice */
29+
UnlockMigration, /**< Ask passphrase for unlocking during migration */
2930
};
3031

3132
explicit AskPassphraseDialog(Mode mode, QWidget *parent, SecureString* passphrase_out = nullptr);

src/qt/bitcoingui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ void BitcoinGUI::createActions()
458458
connect(m_migrate_wallet_action, &QAction::triggered, [this] {
459459
auto activity = new MigrateWalletActivity(m_wallet_controller, this);
460460
connect(activity, &MigrateWalletActivity::migrated, this, &BitcoinGUI::setCurrentWallet);
461-
activity->migrate(walletFrame->currentWalletModel());
461+
activity->migrate(walletFrame->currentWalletModel()->wallet().getWalletName());
462462
});
463463
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::setPrivacy);
464464
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::enableHistoryAction);

src/qt/walletcontroller.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -437,45 +437,45 @@ void RestoreWalletActivity::finish()
437437
Q_EMIT finished();
438438
}
439439

440-
void MigrateWalletActivity::migrate(WalletModel* wallet_model)
440+
void MigrateWalletActivity::migrate(const std::string& name)
441441
{
442442
// Warn the user about migration
443443
QMessageBox box(m_parent_widget);
444444
box.setWindowTitle(tr("Migrate wallet"));
445-
box.setText(tr("Are you sure you wish to migrate the wallet <i>%1</i>?").arg(GUIUtil::HtmlEscape(wallet_model->getDisplayName())));
445+
box.setText(tr("Are you sure you wish to migrate the wallet <i>%1</i>?").arg(GUIUtil::HtmlEscape(GUIUtil::WalletDisplayName(name))));
446446
box.setInformativeText(tr("Migrating the wallet will convert this wallet to one or more descriptor wallets. A new wallet backup will need to be made.\n"
447447
"If this wallet contains any watchonly scripts, a new wallet will be created which contains those watchonly scripts.\n"
448448
"If this wallet contains any solvable but not watched scripts, a different and new wallet will be created which contains those scripts.\n\n"
449449
"The migration process will create a backup of the wallet before migrating. This backup file will be named "
450450
"<wallet name>-<timestamp>.legacy.bak and can be found in the directory for this wallet. In the event of "
451-
"an incorrect migration, the backup can be restored with the \"Restore Wallet\" functionality."));
452-
box.setStandardButtons(QMessageBox::Yes|QMessageBox::Cancel);
453-
box.setDefaultButton(QMessageBox::Yes);
454-
if (box.exec() != QMessageBox::Yes) return;
451+
"an incorrect migration, the backup can be restored with the \"Restore Wallet\" functionality.\n\n"
452+
"If your wallet is encrypted, please provide the passphrase now as by choosing \"Yes, encrypted\"."));
453+
QPushButton* yes_enc_button = box.addButton(tr("Yes, encrypted"), QMessageBox::YesRole);
454+
QPushButton* yes_button = box.addButton(QMessageBox::Yes);
455+
QPushButton* cancel_button = box.addButton(QMessageBox::Cancel);
456+
box.setDefaultButton(yes_button);
457+
box.exec();
458+
if (!box.clickedButton() || box.clickedButton() == (QAbstractButton*)cancel_button) return;
455459

456-
// Get the passphrase if it is encrypted regardless of it is locked or unlocked. We need the passphrase itself.
457460
SecureString passphrase;
458-
WalletModel::EncryptionStatus enc_status = wallet_model->getEncryptionStatus();
459-
if (enc_status == WalletModel::EncryptionStatus::Locked || enc_status == WalletModel::EncryptionStatus::Unlocked) {
460-
AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, m_parent_widget, &passphrase);
461-
dlg.setModel(wallet_model);
462-
dlg.exec();
461+
if (box.clickedButton() == (QAbstractButton*)yes_enc_button) {
462+
// Get the passphrase for the wallet
463+
AskPassphraseDialog dlg(AskPassphraseDialog::UnlockMigration, m_parent_widget, &passphrase);
464+
if (dlg.exec() == QDialog::Rejected) return;
463465
}
464466

465-
// GUI needs to remove the wallet so that it can actually be unloaded by migration
466-
const std::string name = wallet_model->wallet().getWalletName();
467467
showProgressDialog(tr("Migrate Wallet"), tr("Migrating Wallet <b>%1</b>…").arg(GUIUtil::HtmlEscape(name)));
468468

469469
QTimer::singleShot(0, worker(), [this, name, passphrase] {
470470
auto res{node().walletLoader().migrateWallet(name, passphrase)};
471471

472472
if (res) {
473-
m_success_message = tr("The wallet '%1' was migrated successfully.").arg(GUIUtil::HtmlEscape(res->wallet->getWalletName()));
473+
m_success_message = tr("The wallet '%1' was migrated successfully.").arg(GUIUtil::HtmlEscape(GUIUtil::WalletDisplayName(res->wallet->getWalletName())));
474474
if (res->watchonly_wallet_name) {
475-
m_success_message += QChar(' ') + tr("Watchonly scripts have been migrated to a new wallet named '%1'.").arg(GUIUtil::HtmlEscape(res->watchonly_wallet_name.value()));
475+
m_success_message += QChar(' ') + tr("Watchonly scripts have been migrated to a new wallet named '%1'.").arg(GUIUtil::HtmlEscape(GUIUtil::WalletDisplayName(res->watchonly_wallet_name.value())));
476476
}
477477
if (res->solvables_wallet_name) {
478-
m_success_message += QChar(' ') + tr("Solvable but not watched scripts have been migrated to a new wallet named '%1'.").arg(GUIUtil::HtmlEscape(res->solvables_wallet_name.value()));
478+
m_success_message += QChar(' ') + tr("Solvable but not watched scripts have been migrated to a new wallet named '%1'.").arg(GUIUtil::HtmlEscape(GUIUtil::WalletDisplayName(res->solvables_wallet_name.value())));
479479
}
480480
m_wallet_model = m_wallet_controller->getOrCreateWallet(std::move(res->wallet));
481481
} else {

src/qt/walletcontroller.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ class WalletController : public QObject
6666
void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
6767
void closeAllWallets(QWidget* parent = nullptr);
6868

69-
void migrateWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
70-
7169
Q_SIGNALS:
7270
void walletAdded(WalletModel* wallet_model);
7371
void walletRemoved(WalletModel* wallet_model);
@@ -186,7 +184,7 @@ class MigrateWalletActivity : public WalletControllerActivity
186184
public:
187185
MigrateWalletActivity(WalletController* wallet_controller, QWidget* parent) : WalletControllerActivity(wallet_controller, parent) {}
188186

189-
void migrate(WalletModel* wallet_model);
187+
void migrate(const std::string& path);
190188

191189
Q_SIGNALS:
192190
void migrated(WalletModel* wallet_model);

0 commit comments

Comments
 (0)