-
Notifications
You must be signed in to change notification settings - Fork 352
Add menu option to migrate a wallet #738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -167,6 +167,9 @@ void AskPassphraseDialog::accept() | |||||||||
| "passphrase to avoid this issue in the future.")); | ||||||||||
| } | ||||||||||
| } else { | ||||||||||
| if (m_passphrase_out) { | ||||||||||
| m_passphrase_out->assign(oldpass); | ||||||||||
| } | ||||||||||
|
Comment on lines
+170
to
+172
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||||||
| QDialog::accept(); // Success | ||||||||||
| } | ||||||||||
| } catch (const std::runtime_error& e) { | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -432,3 +432,67 @@ void RestoreWalletActivity::finish() | |||||
|
|
||||||
| Q_EMIT finished(); | ||||||
| } | ||||||
|
|
||||||
| void MigrateWalletActivity::migrate(WalletModel* wallet_model) | ||||||
| { | ||||||
| // Warn the user about migration | ||||||
| QMessageBox box(m_parent_widget); | ||||||
| box.setWindowTitle(tr("Migrate wallet")); | ||||||
| box.setText(tr("Are you sure you wish to migrate the wallet <i>%1</i>?").arg(GUIUtil::HtmlEscape(wallet_model->getDisplayName()))); | ||||||
| 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" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed that all the new strings introduced here are nicely transferred over to be translated after running While not a blocker; the longer I look at this, the more I think it can be slimmed down. Will have another look tomorrow. At least this is a chunky boy to translate, and will need a good translator comment: |
||||||
| "If this wallet contains any watchonly scripts, a new wallet will be created which contains those watchonly scripts.\n" | ||||||
| "If this wallet contains any solvable but not watched scripts, a different and new wallet will be created which contains those scripts.\n\n" | ||||||
| "The migration process will create a backup of the wallet before migrating. This backup file will be named " | ||||||
| "<wallet name>-<timestamp>.legacy.bak and can be found in the directory for this wallet. In the event of " | ||||||
| "an incorrect migration, the backup can be restored with the \"Restore Wallet\" functionality.")); | ||||||
| box.setStandardButtons(QMessageBox::Yes|QMessageBox::Cancel); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit
Suggested change
|
||||||
| box.setDefaultButton(QMessageBox::Yes); | ||||||
| if (box.exec() != QMessageBox::Yes) return; | ||||||
|
|
||||||
| // Get the passphrase if it is encrypted regardless of it is locked or unlocked. We need the passphrase itself. | ||||||
| SecureString passphrase; | ||||||
| WalletModel::EncryptionStatus enc_status = wallet_model->getEncryptionStatus(); | ||||||
|
achow101 marked this conversation as resolved.
|
||||||
| if (enc_status == WalletModel::EncryptionStatus::Locked || enc_status == WalletModel::EncryptionStatus::Unlocked) { | ||||||
| AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, m_parent_widget, &passphrase); | ||||||
| dlg.setModel(wallet_model); | ||||||
| dlg.exec(); | ||||||
| } | ||||||
|
|
||||||
| // GUI needs to remove the wallet so that it can actually be unloaded by migration | ||||||
| const std::string name = wallet_model->wallet().getWalletName(); | ||||||
| m_wallet_controller->removeAndDeleteWallet(wallet_model); | ||||||
|
|
||||||
| showProgressDialog(tr("Migrate Wallet"), tr("Migrating Wallet <b>%1</b>…").arg(GUIUtil::HtmlEscape(name))); | ||||||
|
|
||||||
| QTimer::singleShot(0, worker(), [this, name, passphrase] { | ||||||
| auto res{node().walletLoader().migrateWallet(name, passphrase)}; | ||||||
|
|
||||||
| if (res) { | ||||||
| m_success_message = tr("The wallet '%1' was migrated successfully.").arg(GUIUtil::HtmlEscape(res->wallet->getWalletName())); | ||||||
| if (res->watchonly_wallet_name) { | ||||||
| m_success_message += tr(" Watchonly scripts have been migrated to a new wallet named '%1'.").arg(GUIUtil::HtmlEscape(res->watchonly_wallet_name.value())); | ||||||
| } | ||||||
| if (res->solvables_wallet_name) { | ||||||
| m_success_message += tr(" Solvable but not watched scripts have been migrated to a new wallet named '%1'.").arg(GUIUtil::HtmlEscape(res->solvables_wallet_name.value())); | ||||||
| } | ||||||
|
Comment on lines
+471
to
+477
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we can refactor this piece a bit, maybe extracting the message building to other functions? |
||||||
| m_wallet_model = m_wallet_controller->getOrCreateWallet(std::move(res->wallet)); | ||||||
| } else { | ||||||
| m_error_message = util::ErrorString(res); | ||||||
| } | ||||||
|
|
||||||
| QTimer::singleShot(0, this, &MigrateWalletActivity::finish); | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| void MigrateWalletActivity::finish() | ||||||
| { | ||||||
| if (!m_error_message.empty()) { | ||||||
| QMessageBox::critical(m_parent_widget, tr("Migration failed"), QString::fromStdString(m_error_message.translated)); | ||||||
| } else { | ||||||
| QMessageBox::information(m_parent_widget, tr("Migration Successful"), m_success_message); | ||||||
| } | ||||||
|
|
||||||
| if (m_wallet_model) Q_EMIT migrated(m_wallet_model); | ||||||
|
|
||||||
| Q_EMIT finished(); | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we seem to use this style now, although it's not officially documented, so only nit