-
Notifications
You must be signed in to change notification settings - Fork 267
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
Migrate legacy wallets that are not loaded #824
Changes from all commits
28fc562
bfba638
c391858
d56a450
8f2522d
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 |
---|---|---|
|
@@ -360,6 +360,7 @@ void BitcoinGUI::createActions() | |
m_migrate_wallet_action = new QAction(tr("Migrate Wallet"), this); | ||
m_migrate_wallet_action->setEnabled(false); | ||
m_migrate_wallet_action->setStatusTip(tr("Migrate a wallet")); | ||
m_migrate_wallet_menu = new QMenu(this); | ||
|
||
showHelpMessageAction = new QAction(tr("&Command-line options"), this); | ||
showHelpMessageAction->setMenuRole(QAction::NoRole); | ||
|
@@ -396,15 +397,15 @@ void BitcoinGUI::createActions() | |
connect(openAction, &QAction::triggered, this, &BitcoinGUI::openClicked); | ||
connect(m_open_wallet_menu, &QMenu::aboutToShow, [this] { | ||
m_open_wallet_menu->clear(); | ||
for (const std::pair<const std::string, bool>& i : m_wallet_controller->listWalletDir()) { | ||
const std::string& path = i.first; | ||
QString name = path.empty() ? QString("["+tr("default wallet")+"]") : QString::fromStdString(path); | ||
for (const auto& [path, info] : m_wallet_controller->listWalletDir()) { | ||
const auto& [loaded, _] = info; | ||
QString name = GUIUtil::WalletDisplayName(path); | ||
// An single ampersand in the menu item's text sets a shortcut for this item. | ||
// Single & are shown when && is in the string. So replace & with &&. | ||
name.replace(QChar('&'), QString("&&")); | ||
QAction* action = m_open_wallet_menu->addAction(name); | ||
|
||
if (i.second) { | ||
if (loaded) { | ||
// This wallet is already loaded | ||
action->setEnabled(false); | ||
continue; | ||
|
@@ -455,10 +456,31 @@ void BitcoinGUI::createActions() | |
connect(m_close_all_wallets_action, &QAction::triggered, [this] { | ||
m_wallet_controller->closeAllWallets(this); | ||
}); | ||
connect(m_migrate_wallet_action, &QAction::triggered, [this] { | ||
auto activity = new MigrateWalletActivity(m_wallet_controller, this); | ||
connect(activity, &MigrateWalletActivity::migrated, this, &BitcoinGUI::setCurrentWallet); | ||
activity->migrate(walletFrame->currentWalletModel()); | ||
connect(m_migrate_wallet_menu, &QMenu::aboutToShow, [this] { | ||
m_migrate_wallet_menu->clear(); | ||
for (const auto& [wallet_name, info] : m_wallet_controller->listWalletDir()) { | ||
const auto& [loaded, format] = info; | ||
|
||
if (format != "bdb") { // Skip already migrated wallets | ||
continue; | ||
} | ||
|
||
QString name = GUIUtil::WalletDisplayName(wallet_name); | ||
// An single ampersand in the menu item's text sets a shortcut for this item. | ||
// Single & are shown when && is in the string. So replace & with &&. | ||
name.replace(QChar('&'), QString("&&")); | ||
QAction* action = m_migrate_wallet_menu->addAction(name); | ||
|
||
connect(action, &QAction::triggered, [this, wallet_name] { | ||
auto activity = new MigrateWalletActivity(m_wallet_controller, this); | ||
connect(activity, &MigrateWalletActivity::migrated, this, &BitcoinGUI::setCurrentWallet); | ||
activity->migrate(wallet_name); | ||
}); | ||
} | ||
if (m_migrate_wallet_menu->isEmpty()) { | ||
QAction* action = m_migrate_wallet_menu->addAction(tr("No wallets available")); | ||
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: maybe a more descriptive text would be good? for people who don't know about the migration and why/what it is. sry for commenting post-merge |
||
action->setEnabled(false); | ||
} | ||
}); | ||
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::setPrivacy); | ||
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::enableHistoryAction); | ||
|
@@ -691,6 +713,8 @@ void BitcoinGUI::setWalletController(WalletController* wallet_controller, bool s | |
m_open_wallet_action->setEnabled(true); | ||
m_open_wallet_action->setMenu(m_open_wallet_menu); | ||
m_restore_wallet_action->setEnabled(true); | ||
m_migrate_wallet_action->setEnabled(true); | ||
m_migrate_wallet_action->setMenu(m_migrate_wallet_menu); | ||
|
||
GUIUtil::ExceptionSafeConnect(wallet_controller, &WalletController::walletAdded, this, &BitcoinGUI::addWallet); | ||
connect(wallet_controller, &WalletController::walletRemoved, this, &BitcoinGUI::removeWallet); | ||
|
@@ -771,7 +795,6 @@ void BitcoinGUI::setCurrentWallet(WalletModel* wallet_model) | |
} | ||
} | ||
updateWindowTitle(); | ||
m_migrate_wallet_action->setEnabled(wallet_model->wallet().isLegacy()); | ||
} | ||
|
||
void BitcoinGUI::setCurrentWalletBySelectorIndex(int index) | ||
|
@@ -805,7 +828,6 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) | |
openAction->setEnabled(enabled); | ||
m_close_wallet_action->setEnabled(enabled); | ||
m_close_all_wallets_action->setEnabled(enabled); | ||
m_migrate_wallet_action->setEnabled(enabled); | ||
} | ||
|
||
void BitcoinGUI::createTrayIcon() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,13 +61,11 @@ class WalletController : public QObject | |
|
||
//! Returns all wallet names in the wallet dir mapped to whether the wallet | ||
//! is loaded. | ||
std::map<std::string, bool> listWalletDir() const; | ||
std::map<std::string, std::pair<bool, std::string>> listWalletDir() const; | ||
|
||
void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr); | ||
void closeAllWallets(QWidget* parent = nullptr); | ||
|
||
void migrateWallet(WalletModel* wallet_model, QWidget* parent = nullptr); | ||
|
||
Comment on lines
-69
to
-70
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. Apparently, this code has been dead since introducing in #738. |
||
Q_SIGNALS: | ||
void walletAdded(WalletModel* wallet_model); | ||
void walletRemoved(WalletModel* wallet_model); | ||
|
@@ -186,7 +184,7 @@ class MigrateWalletActivity : public WalletControllerActivity | |
public: | ||
MigrateWalletActivity(WalletController* wallet_controller, QWidget* parent) : WalletControllerActivity(wallet_controller, parent) {} | ||
|
||
void migrate(WalletModel* wallet_model); | ||
void migrate(const std::string& path); | ||
|
||
Q_SIGNALS: | ||
void migrated(WalletModel* wallet_model); | ||
|
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.
Compilation error:
error: 'wallet_name' in capture list does not name a variable
.It seems the lambda expression cannot capture the structured binding. A local reference of the variable fixes it.
Same happens on the
m_open_wallet_menu
action lambda with the "path" variable.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.
What compiler? I'm not seeing this error, and it seems neither did CI.
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.
clang 14.0.3 (clang-1403.0.22.14.1).