25#include <QApplication>
29#include <QMutexLocker>
42 , m_activity_thread(new QThread(this))
43 , m_activity_worker(new QObject)
44 , m_client_model(client_model)
46 , m_platform_style(platform_style)
47 , m_options_model(client_model.getOptionsModel())
72 std::map<std::string, std::pair<bool, std::string>> wallets;
77 auto it = wallets.find(wallet_model->wallet().getWalletName());
78 if (it != wallets.end()) it->second.first =
true;
93 QMessageBox box(parent);
94 box.setWindowTitle(tr(
"Close wallet"));
96 box.setInformativeText(tr(
"Closing the wallet for too long can result in having to resync the entire chain if pruning is enabled."));
97 box.setStandardButtons(QMessageBox::Yes|QMessageBox::Cancel);
98 box.setDefaultButton(QMessageBox::Yes);
99 if (box.exec() != QMessageBox::Yes)
return;
106 QMessageBox::StandardButton button = QMessageBox::question(parent, tr(
"Close all wallets"),
107 tr(
"Are you sure you wish to close all wallets?"),
108 QMessageBox::Yes|QMessageBox::Cancel,
110 if (button != QMessageBox::Yes)
return;
126 if (wallet_model->wallet().getWalletName() ==
name) {
141 wallet_model->moveToThread(
thread());
143 QMetaObject::invokeMethod(
this, [wallet_model,
this] {
144 wallet_model->setParent(
this);
152 const bool called = QMetaObject::invokeMethod(wallet_model,
"startPollBalance");
158 QWidget* active_dialog = QApplication::activeModalWidget();
159 if (active_dialog &&
dynamic_cast<QProgressDialog*
>(active_dialog) ==
nullptr) {
160 connect(qApp, &QApplication::focusWindowChanged, wallet_model, [
this, wallet_model]() {
161 if (!QApplication::activeModalWidget()) {
164 }, Qt::QueuedConnection);
168 }, Qt::QueuedConnection);
192 : QObject(wallet_controller)
193 , m_wallet_controller(wallet_controller)
194 , m_parent_widget(parent_widget)
202 progress_dialog->setAttribute(Qt::WA_DeleteOnClose);
205 progress_dialog->setWindowTitle(title_text);
206 progress_dialog->setLabelText(label_text);
207 progress_dialog->setRange(0, 0);
208 progress_dialog->setCancelButton(
nullptr);
209 progress_dialog->setWindowModality(Qt::ApplicationModal);
213 progress_dialog->setValue(0);
215 if (show_minimized) progress_dialog->showMinimized();
300 std::vector<std::unique_ptr<interfaces::ExternalSigner>> signers;
303 }
catch (
const std::runtime_error& e) {
304 QMessageBox::critical(
nullptr, tr(
"Can't list signers"), e.what());
306 if (signers.size() > 1) {
307 QMessageBox::critical(
nullptr, tr(
"Too many external signers found"), QString::fromStdString(
"More than one external signer found. Please connect only one at a time."));
357 tr(
"Opening Wallet <b>%1</b>…").arg(
name.toHtmlEscaped()));
359 QTimer::singleShot(0,
worker(), [
this, path] {
384 tr(
"Loading wallets…"),
385 show_loading_minimized);
387 QTimer::singleShot(0,
worker(), [
this] {
388 for (
auto&
wallet :
node().walletLoader().getWallets()) {
392 QTimer::singleShot(0,
this, [
this] { Q_EMIT
finished(); });
403 QString
name = QString::fromStdString(wallet_name);
407 tr(
"Restore Wallet"),
410 tr(
"Restoring Wallet <b>%1</b>…").arg(
name.toHtmlEscaped()));
412 QTimer::singleShot(0,
worker(), [
this, backup_file, wallet_name] {
435 QMessageBox::information(
m_parent_widget, tr(
"Restore wallet message"), QString::fromStdString(
Untranslated(
"Wallet restored successfully \n").translated));
446 if (
node().walletLoader().isEncrypted(
name)) {
449 if (dlg.exec() == QDialog::Rejected)
return;
454 QTimer::singleShot(0,
worker(), [
this,
name, passphrase, load_wallet] {
459 if (res->watchonly_wallet_name) {
462 if (res->solvables_wallet_name) {
469 m_success_message += QChar(
' ') + tr(
"The wallet was not loaded after migration. You can open it from the \"File > Open wallet\" menu.");
483 box.setWindowTitle(tr(
"Migrate wallet"));
485 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"
486 "If this wallet contains any watchonly scripts, a new wallet will be created which contains those watchonly scripts.\n"
487 "If this wallet contains any solvable but not watched scripts, a different and new wallet will be created which contains those scripts.\n\n"
488 "The migration process will create a backup of the wallet before migrating. This backup file will be named "
489 "<wallet name>-<timestamp>.legacy.bak and can be found in the directory for this wallet. In the event of "
490 "an incorrect migration, the backup can be restored with the \"Restore Wallet\" functionality."));
491 auto* load_wallet_checkbox =
new QCheckBox(tr(
"Load wallet after migration"), &box);
492 load_wallet_checkbox->setToolTip(tr(
"If the node is pruned and the wallet was created before the pruned height, the migration process may fail trying to load the migrated wallet."));
493 load_wallet_checkbox->setChecked(
true);
494 box.setCheckBox(load_wallet_checkbox);
495 box.setStandardButtons(QMessageBox::Yes|QMessageBox::Cancel);
496 box.setDefaultButton(QMessageBox::Yes);
497 if (box.exec() != QMessageBox::Yes)
return;
506 box.setWindowTitle(tr(
"Restore and Migrate wallet"));
508 box.setInformativeText(tr(
"Restoring the wallet will copy the backup file to the wallets directory and place it in the standard "
509 "wallet directory layout. The original file will not be modified.\n\n"
510 "Migrating the wallet will convert the restored wallet to one or more descriptor wallets. A new wallet backup will need to be made.\n"
511 "If this wallet contains any watchonly scripts, a new wallet will be created which contains those watchonly scripts.\n"
512 "If this wallet contains any solvable but not watched scripts, a different and new wallet will be created which contains those scripts.\n\n"
513 "The migration process will create a backup of the wallet before migrating. This backup file will be named "
514 "<wallet name>-<timestamp>.legacy.bak and can be found in the directory for this wallet. In the event of "
515 "an incorrect migration, the backup can be restored with the \"Restore Wallet\" functionality."));
516 box.setStandardButtons(QMessageBox::Yes|QMessageBox::Cancel);
517 box.setDefaultButton(QMessageBox::Yes);
518 if (box.exec() != QMessageBox::Yes)
return;
522 tr(
"Restore Wallet"),
527 QTimer::singleShot(0,
worker(), [
this, path, wallet_name] {
535 QTimer::singleShot(0,
this, [
this, wallet_name] {
Multifunctional dialog to ask for passphrases.
@ Encrypt
Ask passphrase twice and encrypt.
@ UnlockMigration
Ask passphrase for unlocking during migration.
Model for Bitcoin network client.
virtual ~CreateWalletActivity()
AskPassphraseDialog * m_passphrase_dialog
CreateWalletDialog * m_create_wallet_dialog
SecureString m_passphrase
CreateWalletActivity(WalletController *wallet_controller, QWidget *parent_widget)
void created(WalletModel *wallet_model)
Dialog for creating wallets.
bool isMakeBlankWalletChecked() const
QString walletName() const
bool isDisablePrivateKeysChecked() const
bool isEncryptWalletChecked() const
void setSigners(const std::vector< std::unique_ptr< interfaces::ExternalSigner > > &signers)
bool isExternalSignerChecked() const
void load(bool show_loading_minimized)
LoadWalletsActivity(WalletController *wallet_controller, QWidget *parent_widget)
void do_migrate(const std::string &name, bool load_wallet)
QString m_success_message
void restore_and_migrate(const fs::path &path, const std::string &wallet_name)
void migrated(WalletModel *wallet_model)
void migrate(const std::string &path)
void opened(WalletModel *wallet_model)
OpenWalletActivity(WalletController *wallet_controller, QWidget *parent_widget)
void open(const std::string &path)
void restore(const fs::path &backup_file, const std::string &wallet_name)
void restored(WalletModel *wallet_model)
RestoreWalletActivity(WalletController *wallet_controller, QWidget *parent_widget)
WalletModel * m_wallet_model
std::vector< bilingual_str > m_warning_message
WalletController *const m_wallet_controller
interfaces::Node & node() const
void showProgressDialog(const QString &title_text, const QString &label_text, bool show_minimized=false)
bilingual_str m_error_message
WalletControllerActivity(WalletController *wallet_controller, QWidget *parent_widget)
QWidget *const m_parent_widget
Controller between interfaces::Node, WalletModel instances and the GUI.
WalletController(ClientModel &client_model, const PlatformStyle *platform_style, QObject *parent)
WalletModel * getOrCreateWallet(std::unique_ptr< interfaces::Wallet > wallet)
ClientModel & m_client_model
void removeAndDeleteWallet(WalletModel *wallet_model)
void walletAdded(WalletModel *wallet_model)
void closeAllWallets(QWidget *parent=nullptr)
std::unique_ptr< interfaces::Handler > m_handler_load_wallet
QThread *const m_activity_thread
void coinsSent(WalletModel *wallet_model, SendCoinsRecipient recipient, QByteArray transaction)
QObject *const m_activity_worker
void walletRemoved(WalletModel *wallet_model)
const PlatformStyle *const m_platform_style
interfaces::Node & m_node
void closeWallet(WalletModel *wallet_model, QWidget *parent=nullptr)
std::map< std::string, std::pair< bool, std::string > > listWalletDir() const
Returns all wallet names in the wallet dir mapped to whether the wallet is loaded.
void removeWallet(WalletModel *wallet_model)
Starts the wallet closure procedure.
std::vector< WalletModel * > m_wallets
Interface to Bitcoin wallet from Qt view code.
interfaces::Wallet & wallet() const
void coinsSent(WalletModel *wallet, SendCoinsRecipient recipient, QByteArray transaction)
QString getDisplayName() const
virtual WalletLoader & walletLoader()=0
Get wallet loader.
virtual std::vector< std::unique_ptr< ExternalSigner > > listExternalSigners()=0
Return list of external signers (attached devices which can sign transactions).
virtual util::Result< WalletMigrationResult > migrateWallet(const std::string &name, const SecureString &passphrase, bool load_wallet)=0
Migrate a wallet.
virtual util::Result< std::unique_ptr< Wallet > > restoreWallet(const fs::path &backup_file, const std::string &wallet_name, std::vector< bilingual_str > &warnings, bool load_after_restore)=0
Restore backup wallet.
virtual util::Result< std::unique_ptr< Wallet > > createWallet(const std::string &name, const SecureString &passphrase, uint64_t wallet_creation_flags, std::vector< bilingual_str > &warnings)=0
Create new wallet.
virtual std::vector< std::pair< std::string, std::string > > listWalletDir()=0
Return available wallets in wallet directory.
virtual util::Result< std::unique_ptr< Wallet > > loadWallet(const std::string &name, std::vector< bilingual_str > &warnings)=0
Load existing wallet.
virtual std::unique_ptr< Handler > handleLoadWallet(LoadWalletFn fn)=0
static std::string PathToString(const path &path)
Convert path object to a byte string.
static const int MAX_PASSPHRASE_SIZE
std::thread thread
Thread variable should be after other struct members so the thread does not start until the other mem...
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
QString WalletDisplayName(const QString &name)
QString HtmlEscape(const QString &str, bool fMultiLine)
void PolishProgressDialog(QProgressDialog *dialog)
void ThreadRename(const std::string &)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name.
bilingual_str ErrorString(const Result< T > &result)
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
@ WALLET_FLAG_EXTERNAL_SIGNER
Indicates that the wallet needs an external signer.
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
@ WALLET_FLAG_BLANK_WALLET
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses,...
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.