Skip to content

Commit fbb105a

Browse files
committed
Merge bitcoin#521: [GUI] Make "For anonymization and staking only" checked by default
4e5b73e [GUI] Make "For anonymization and staking only" checked by default (Mrs-X) Tree-SHA512: 53d5aa663269efdb82cb2d8961f2eae4aebc03a6d96d15d990b357385584e365935f012eb9410b81de891a1d1ed75fbfe88937b2e87df12db148b1d6e3c015a5
2 parents 94b9bc9 + 4e5b73e commit fbb105a

16 files changed

+102
-53
lines changed

src/qt/addresstablemodel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "base58.h"
1313
#include "wallet.h"
14+
#include "askpassphrasedialog.h"
1415

1516
#include <QDebug>
1617
#include <QFont>
@@ -383,7 +384,7 @@ QString AddressTableModel::addRow(const QString& type, const QString& label, con
383384
// Generate a new address to associate with given label
384385
CPubKey newKey;
385386
if (!wallet->GetKeyFromPool(newKey)) {
386-
WalletModel::UnlockContext ctx(walletModel->requestUnlock(true));
387+
WalletModel::UnlockContext ctx(walletModel->requestUnlock(AskPassphraseDialog::Context::Unlock_Full, true));
387388
if (!ctx.isValid()) {
388389
// Unlock wallet failed or was cancelled
389390
editStatus = WALLET_UNLOCK_FAILURE;

src/qt/askpassphrasedialog.cpp

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
#include <QKeyEvent>
1717
#include <QMessageBox>
1818
#include <QPushButton>
19-
20-
AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget* parent, WalletModel* model) : QDialog(parent),
21-
ui(new Ui::AskPassphraseDialog),
22-
mode(mode),
23-
model(model),
24-
fCapsLock(false)
19+
#include <QWidget>
20+
21+
AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget* parent, WalletModel* model, Context context) : QDialog(parent),
22+
ui(new Ui::AskPassphraseDialog),
23+
mode(mode),
24+
model(model),
25+
context(context),
26+
fCapsLock(false)
2527
{
2628
ui->setupUi(this);
2729
this->setStyleSheet(GUIUtil::loadStyleSheet());
@@ -42,38 +44,48 @@ AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget* parent, WalletModel
4244
this->model = model;
4345

4446
switch (mode) {
45-
case Encrypt: // Ask passphrase x2
47+
case Mode::Encrypt: // Ask passphrase x2
4648
ui->warningLabel->setText(tr("Enter the new passphrase to the wallet.<br/>Please use a passphrase of <b>ten or more random characters</b>, or <b>eight or more words</b>."));
4749
ui->passLabel1->hide();
4850
ui->passEdit1->hide();
4951
setWindowTitle(tr("Encrypt wallet"));
5052
break;
51-
case UnlockAnonymize:
52-
ui->anonymizationCheckBox->setChecked(true);
53+
case Mode::UnlockAnonymize:
5354
ui->anonymizationCheckBox->show();
54-
case Unlock: // Ask passphrase
55+
case Mode::Unlock: // Ask passphrase
5556
ui->warningLabel->setText(tr("This operation needs your wallet passphrase to unlock the wallet."));
5657
ui->passLabel2->hide();
5758
ui->passEdit2->hide();
5859
ui->passLabel3->hide();
5960
ui->passEdit3->hide();
6061
setWindowTitle(tr("Unlock wallet"));
6162
break;
62-
case Decrypt: // Ask passphrase
63+
case Mode::Decrypt: // Ask passphrase
6364
ui->warningLabel->setText(tr("This operation needs your wallet passphrase to decrypt the wallet."));
6465
ui->passLabel2->hide();
6566
ui->passEdit2->hide();
6667
ui->passLabel3->hide();
6768
ui->passEdit3->hide();
6869
setWindowTitle(tr("Decrypt wallet"));
6970
break;
70-
case ChangePass: // Ask old passphrase + new passphrase x2
71+
case Mode::ChangePass: // Ask old passphrase + new passphrase x2
7172
setWindowTitle(tr("Change passphrase"));
7273
ui->warningLabel->setText(tr("Enter the old and new passphrase to the wallet."));
7374
break;
7475
}
7576

76-
ui->anonymizationCheckBox->setChecked(model->isAnonymizeOnlyUnlocked());
77+
// Set checkbox "For anonymization, automint, and staking only" depending on from where we were called
78+
if (context == Context::Unlock_Menu || context == Context::Mint_zPIV || context == Context::BIP_38) {
79+
ui->anonymizationCheckBox->setChecked(true);
80+
}
81+
else {
82+
ui->anonymizationCheckBox->setChecked(false);
83+
}
84+
85+
// It doesn't make sense to show the checkbox for sending PIV because you wouldn't check it anyway.
86+
if (context == Context::Send_PIV || context == Context::Send_zPIV) {
87+
ui->anonymizationCheckBox->hide();
88+
}
7789

7890
textChanged();
7991
connect(ui->passEdit1, SIGNAL(textChanged(QString)), this, SLOT(textChanged()));
@@ -105,7 +117,7 @@ void AskPassphraseDialog::accept()
105117
newpass2.assign(ui->passEdit3->text().toStdString().c_str());
106118

107119
switch (mode) {
108-
case Encrypt: {
120+
case Mode::Encrypt: {
109121
if (newpass1.empty() || newpass2.empty()) {
110122
// Cannot encrypt with empty passphrase
111123
break;
@@ -142,24 +154,24 @@ void AskPassphraseDialog::accept()
142154
QDialog::reject(); // Cancelled
143155
}
144156
} break;
145-
case UnlockAnonymize:
146-
case Unlock:
157+
case Mode::UnlockAnonymize:
158+
case Mode::Unlock:
147159
if (!model->setWalletLocked(false, oldpass, ui->anonymizationCheckBox->isChecked())) {
148160
QMessageBox::critical(this, tr("Wallet unlock failed"),
149161
tr("The passphrase entered for the wallet decryption was incorrect."));
150162
} else {
151163
QDialog::accept(); // Success
152164
}
153165
break;
154-
case Decrypt:
166+
case Mode::Decrypt:
155167
if (!model->setWalletEncrypted(false, oldpass)) {
156168
QMessageBox::critical(this, tr("Wallet decryption failed"),
157169
tr("The passphrase entered for the wallet decryption was incorrect."));
158170
} else {
159171
QDialog::accept(); // Success
160172
}
161173
break;
162-
case ChangePass:
174+
case Mode::ChangePass:
163175
if (newpass1 == newpass2) {
164176
if (model->changePassphrase(oldpass, newpass1)) {
165177
QMessageBox::information(this, tr("Wallet encrypted"),
@@ -182,15 +194,15 @@ void AskPassphraseDialog::textChanged()
182194
// Validate input, set Ok button to enabled when acceptable
183195
bool acceptable = false;
184196
switch (mode) {
185-
case Encrypt: // New passphrase x2
197+
case Mode::Encrypt: // New passphrase x2
186198
acceptable = !ui->passEdit2->text().isEmpty() && !ui->passEdit3->text().isEmpty();
187199
break;
188-
case UnlockAnonymize: // Old passphrase x1
189-
case Unlock: // Old passphrase x1
190-
case Decrypt:
200+
case Mode::UnlockAnonymize: // Old passphrase x1
201+
case Mode::Unlock: // Old passphrase x1
202+
case Mode::Decrypt:
191203
acceptable = !ui->passEdit1->text().isEmpty();
192204
break;
193-
case ChangePass: // Old passphrase x1, new passphrase x2
205+
case Mode::ChangePass: // Old passphrase x1, new passphrase x2
194206
acceptable = !ui->passEdit1->text().isEmpty() && !ui->passEdit2->text().isEmpty() && !ui->passEdit3->text().isEmpty();
195207
break;
196208
}

src/qt/askpassphrasedialog.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,31 @@ class AskPassphraseDialog : public QDialog
2121
Q_OBJECT
2222

2323
public:
24-
enum Mode {
24+
enum class Mode {
2525
Encrypt, /**< Ask passphrase twice and encrypt */
2626
UnlockAnonymize, /**< Ask passphrase and unlock only for anonymization */
2727
Unlock, /**< Ask passphrase and unlock */
2828
ChangePass, /**< Ask old passphrase + new passphrase twice */
2929
Decrypt /**< Ask passphrase and decrypt wallet */
3030
};
3131

32-
explicit AskPassphraseDialog(Mode mode, QWidget* parent, WalletModel* model);
32+
// Context from where / for what the passphrase dialog was called to set the status of the checkbox
33+
// Partly redundant to Mode above, but offers more flexibility for future enhancements
34+
enum class Context {
35+
Unlock_Menu, /** Unlock wallet from menu */
36+
Unlock_Full, /** Wallet needs to be fully unlocked */
37+
Encrypt, /** Encrypt unencrypted wallet */
38+
ToggleLock, /** Toggle wallet lock state */
39+
ChangePass, /** Change passphrase */
40+
Send_PIV, /** Send PIV */
41+
Send_zPIV, /** Send zPIV */
42+
Mint_zPIV, /** Mint zPIV */
43+
BIP_38, /** BIP38 menu */
44+
Multi_Sig, /** Multi-Signature dialog */
45+
Sign_Message /** Sign/verify message dialog */
46+
};
47+
48+
explicit AskPassphraseDialog(Mode mode, QWidget* parent, WalletModel* model, Context context);
3349
~AskPassphraseDialog();
3450

3551
void accept();
@@ -38,6 +54,7 @@ class AskPassphraseDialog : public QDialog
3854
Ui::AskPassphraseDialog* ui;
3955
Mode mode;
4056
WalletModel* model;
57+
Context context;
4158
bool fCapsLock;
4259

4360
private slots:

src/qt/bip38tooldialog.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "bip38.h"
1616
#include "init.h"
1717
#include "wallet.h"
18+
#include "askpassphrasedialog.h"
1819

1920
#include <string>
2021
#include <vector>
@@ -137,7 +138,7 @@ void Bip38ToolDialog::on_encryptKeyButton_ENC_clicked()
137138
return;
138139
}
139140

140-
WalletModel::UnlockContext ctx(model->requestUnlock(true));
141+
WalletModel::UnlockContext ctx(model->requestUnlock(AskPassphraseDialog::Context::BIP_38, true));
141142
if (!ctx.isValid()) {
142143
ui->statusLabel_ENC->setStyleSheet("QLabel { color: red; }");
143144
ui->statusLabel_ENC->setText(tr("Wallet unlock was cancelled."));
@@ -200,7 +201,7 @@ void Bip38ToolDialog::on_decryptKeyButton_DEC_clicked()
200201

201202
void Bip38ToolDialog::on_importAddressButton_DEC_clicked()
202203
{
203-
WalletModel::UnlockContext ctx(model->requestUnlock(true));
204+
WalletModel::UnlockContext ctx(model->requestUnlock(AskPassphraseDialog::Context::BIP_38, true));
204205
if (!ctx.isValid()) {
205206
ui->statusLabel_DEC->setStyleSheet("QLabel { color: red; }");
206207
ui->statusLabel_DEC->setText(tr("Wallet unlock was cancelled."));

src/qt/bitcoingui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ void BitcoinGUI::createActions(const NetworkStyle* networkStyle)
466466
connect(encryptWalletAction, SIGNAL(triggered(bool)), walletFrame, SLOT(encryptWallet(bool)));
467467
connect(backupWalletAction, SIGNAL(triggered()), walletFrame, SLOT(backupWallet()));
468468
connect(changePassphraseAction, SIGNAL(triggered()), walletFrame, SLOT(changePassphrase()));
469-
connect(unlockWalletAction, SIGNAL(triggered()), walletFrame, SLOT(unlockWallet()));
469+
connect(unlockWalletAction, SIGNAL(triggered(bool)), walletFrame, SLOT(unlockWallet(bool)));
470470
connect(lockWalletAction, SIGNAL(triggered()), walletFrame, SLOT(lockWallet()));
471471
connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
472472
connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab()));

src/qt/masternodelist.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "sync.h"
1212
#include "wallet.h"
1313
#include "walletmodel.h"
14+
#include "askpassphrasedialog.h"
1415

1516
#include <QMessageBox>
1617
#include <QTimer>
@@ -242,7 +243,7 @@ void MasternodeList::on_startButton_clicked()
242243
WalletModel::EncryptionStatus encStatus = walletModel->getEncryptionStatus();
243244

244245
if (encStatus == walletModel->Locked || encStatus == walletModel->UnlockedForAnonymizationOnly) {
245-
WalletModel::UnlockContext ctx(walletModel->requestUnlock());
246+
WalletModel::UnlockContext ctx(walletModel->requestUnlock(AskPassphraseDialog::Context::Unlock_Full));
246247

247248
if (!ctx.isValid()) return; // Unlock wallet was cancelled
248249

@@ -266,7 +267,7 @@ void MasternodeList::on_startAllButton_clicked()
266267
WalletModel::EncryptionStatus encStatus = walletModel->getEncryptionStatus();
267268

268269
if (encStatus == walletModel->Locked || encStatus == walletModel->UnlockedForAnonymizationOnly) {
269-
WalletModel::UnlockContext ctx(walletModel->requestUnlock());
270+
WalletModel::UnlockContext ctx(walletModel->requestUnlock(AskPassphraseDialog::Context::Unlock_Full));
270271

271272
if (!ctx.isValid()) return; // Unlock wallet was cancelled
272273

@@ -297,7 +298,7 @@ void MasternodeList::on_startMissingButton_clicked()
297298
WalletModel::EncryptionStatus encStatus = walletModel->getEncryptionStatus();
298299

299300
if (encStatus == walletModel->Locked || encStatus == walletModel->UnlockedForAnonymizationOnly) {
300-
WalletModel::UnlockContext ctx(walletModel->requestUnlock());
301+
WalletModel::UnlockContext ctx(walletModel->requestUnlock(AskPassphraseDialog::Context::Unlock_Full));
301302

302303
if (!ctx.isValid()) return; // Unlock wallet was cancelled
303304

src/qt/multisigdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ bool MultisigDialog::signMultisigTx(CMutableTransaction& tx, string& errorOut, Q
640640
}
641641
}else{
642642
if (model->getEncryptionStatus() == model->Locked) {
643-
if (!model->requestUnlock(true).isValid()) {
643+
if (!model->requestUnlock(AskPassphraseDialog::Context::Multi_Sig, true).isValid()) {
644644
// Unlock wallet was cancelled
645645
throw runtime_error("Error: Your wallet is locked. Please enter the wallet passphrase first.");
646646
}

src/qt/privacydialog.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "coincontrol.h"
1717
#include "zpivcontroldialog.h"
1818
#include "spork.h"
19+
#include "askpassphrasedialog.h"
1920

2021
#include <QClipboard>
2122
#include <QSettings>
@@ -173,7 +174,7 @@ void PrivacyDialog::on_pushButtonMintzPIV_clicked()
173174
// Request unlock if wallet was locked or unlocked for mixing:
174175
WalletModel::EncryptionStatus encStatus = walletModel->getEncryptionStatus();
175176
if (encStatus == walletModel->Locked) {
176-
WalletModel::UnlockContext ctx(walletModel->requestUnlock(true));
177+
WalletModel::UnlockContext ctx(walletModel->requestUnlock(AskPassphraseDialog::Context::Mint_zPIV, true));
177178
if (!ctx.isValid()) {
178179
// Unlock wallet was cancelled
179180
ui->TEMintStatus->setPlainText(tr("Error: Your wallet is locked. Please enter the wallet passphrase first."));
@@ -280,7 +281,7 @@ void PrivacyDialog::on_pushButtonSpendzPIV_clicked()
280281
// Request unlock if wallet was locked or unlocked for mixing:
281282
WalletModel::EncryptionStatus encStatus = walletModel->getEncryptionStatus();
282283
if (encStatus == walletModel->Locked || encStatus == walletModel->UnlockedForAnonymizationOnly) {
283-
WalletModel::UnlockContext ctx(walletModel->requestUnlock(true));
284+
WalletModel::UnlockContext ctx(walletModel->requestUnlock(AskPassphraseDialog::Context::Send_zPIV, true));
284285
if (!ctx.isValid()) {
285286
// Unlock wallet was cancelled
286287
return;

src/qt/sendcoinsdialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ void SendCoinsDialog::on_sendButton_clicked()
321321
// will call relock
322322
WalletModel::EncryptionStatus encStatus = model->getEncryptionStatus();
323323
if (encStatus == model->Locked || encStatus == model->UnlockedForAnonymizationOnly) {
324-
WalletModel::UnlockContext ctx(model->requestUnlock(true));
324+
WalletModel::UnlockContext ctx(model->requestUnlock(AskPassphraseDialog::Context::Send_PIV, true));
325325
if (!ctx.isValid()) {
326326
// Unlock wallet was cancelled
327327
fNewRecipientAllowed = true;
@@ -639,7 +639,7 @@ void SendCoinsDialog::processSendCoinsReturn(const WalletModel::SendCoinsReturn&
639639

640640
// Unlock wallet if it wasn't fully unlocked already
641641
if(fAskForUnlock) {
642-
model->requestUnlock(false);
642+
model->requestUnlock(AskPassphraseDialog::Context::Unlock_Full, false);
643643
if(model->getEncryptionStatus () != WalletModel::Unlocked) {
644644
msgParams.first = tr("Error: The wallet was unlocked only to anonymize coins. Unlock canceled.");
645645
}

src/qt/signverifymessagedialog.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "base58.h"
1515
#include "init.h"
1616
#include "wallet.h"
17+
#include "askpassphrasedialog.h"
1718

1819
#include <string>
1920
#include <vector>
@@ -118,7 +119,7 @@ void SignVerifyMessageDialog::on_signMessageButton_SM_clicked()
118119
return;
119120
}
120121

121-
WalletModel::UnlockContext ctx(model->requestUnlock(true));
122+
WalletModel::UnlockContext ctx(model->requestUnlock(AskPassphraseDialog::Context::Sign_Message, true));
122123
if (!ctx.isValid()) {
123124
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }");
124125
ui->statusLabel_SM->setText(tr("Wallet unlock was cancelled."));

0 commit comments

Comments
 (0)