diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index a4bb63886..546a39f43 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -849,7 +849,7 @@ void BitcoinGUI::changePassphrase() void BitcoinGUI::verifyMessage() { - VerifyMessageDialog *dlg = new VerifyMessageDialog(walletModel->getAddressTableModel(), this); + VerifyMessageDialog *dlg = new VerifyMessageDialog(this); dlg->setAttribute(Qt::WA_DeleteOnClose); dlg->show(); } diff --git a/src/qt/forms/verifymessagedialog.ui b/src/qt/forms/verifymessagedialog.ui index a7c99716e..afe98b05a 100644 --- a/src/qt/forms/verifymessagedialog.ui +++ b/src/qt/forms/verifymessagedialog.ui @@ -6,8 +6,8 @@ 0 0 - 494 - 342 + 650 + 380 @@ -17,7 +17,7 @@ - Enter the message and signature below (be careful to correctly copy newlines, spaces, tabs and other invisible characters) to obtain the Bitcoin address used to sign the message. + Enter the signing address, signature and message below (be careful to correctly copy newlines, spaces, tabs and other invisible characters) to verify the message. Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop @@ -28,38 +28,28 @@ - - - - + - + - - true - - - - - - + - Verify a message and obtain the Bitcoin address used to sign the message + Verify a message to ensure it was signed with the specified Bitcoin address &Verify Message @@ -71,33 +61,51 @@ - - - false - + - Copy the currently selected address to the system clipboard + Reset all verify message fields - &Copy Address + Clear &All - :/icons/editcopy:/icons/editcopy + :/icons/remove:/icons/remove - - - Reset all verify message fields + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 48 + + + + + 75 + true + - Clear &All + - - - :/icons/remove:/icons/remove + + true @@ -118,6 +126,13 @@ + + + QValidatedLineEdit + QLineEdit +
qvalidatedlineedit.h
+
+
diff --git a/src/qt/verifymessagedialog.cpp b/src/qt/verifymessagedialog.cpp index d71568d2e..92f58328a 100644 --- a/src/qt/verifymessagedialog.cpp +++ b/src/qt/verifymessagedialog.cpp @@ -4,35 +4,36 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "main.h" #include "wallet.h" #include "walletmodel.h" -#include "addresstablemodel.h" #include "guiutil.h" #include "base58.h" -VerifyMessageDialog::VerifyMessageDialog(AddressTableModel *addressModel, QWidget *parent) : +VerifyMessageDialog::VerifyMessageDialog(QWidget *parent) : QDialog(parent), - ui(new Ui::VerifyMessageDialog), - model(addressModel) + ui(new Ui::VerifyMessageDialog) { ui->setupUi(this); #if (QT_VERSION >= 0x040700) /* Do not move this to the XML file, Qt before 4.7 will choke on it */ + ui->lnAddress->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)")); ui->lnSig->setPlaceholderText(tr("Enter Bitcoin signature")); - ui->lnAddress->setPlaceholderText(tr("Click \"Verify Message\" to obtain address")); #endif GUIUtil::setupAddressWidget(ui->lnAddress, this); ui->lnAddress->installEventFilter(this); - ui->edMessage->setFocus(); + ui->lnSig->setFont(GUIUtil::bitcoinAddressFont()); + + ui->lnAddress->setFocus(); } VerifyMessageDialog::~VerifyMessageDialog() @@ -40,54 +41,65 @@ VerifyMessageDialog::~VerifyMessageDialog() delete ui; } -bool VerifyMessageDialog::checkAddress() +void VerifyMessageDialog::on_verifyMessage_clicked() { - CDataStream ss(SER_GETHASH, 0); - ss << strMessageMagic; - ss << ui->edMessage->document()->toPlainText().toStdString(); - uint256 hash = Hash(ss.begin(), ss.end()); + CBitcoinAddress addr(ui->lnAddress->text().toStdString()); + if (!addr.IsValid()) + { + ui->lnAddress->setValid(false); + ui->lblStatus->setStyleSheet("QLabel { color: red; }"); + ui->lblStatus->setText(tr("\"%1\" is not a valid address.").arg(ui->lnAddress->text()) + QString(" ") + tr("Please check the address and try again.")); + return; + } + CKeyID keyID; + if (!addr.GetKeyID(keyID)) + { + ui->lnAddress->setValid(false); + ui->lblStatus->setStyleSheet("QLabel { color: red; }"); + ui->lblStatus->setText(tr("\"%1\" does not refer to a key.").arg(ui->lnAddress->text()) + QString(" ") + tr("Please check the address and try again.")); + return; + } - bool invalid = true; - std::vector vchSig = DecodeBase64(ui->lnSig->text().toStdString().c_str(), &invalid); + bool fInvalid = false; + std::vector vchSig = DecodeBase64(ui->lnSig->text().toStdString().c_str(), &fInvalid); - if(invalid) + if (fInvalid) { - QMessageBox::warning(this, tr("Invalid Signature"), tr("The signature could not be decoded. Please check the signature and try again.")); - return false; + ui->lnSig->setValid(false); + ui->lblStatus->setStyleSheet("QLabel { color: red; }"); + ui->lblStatus->setText(tr("The signature could not be decoded.") + QString(" ") + tr("Please check the signature and try again.")); + return; } + CDataStream ss(SER_GETHASH, 0); + ss << strMessageMagic; + ss << ui->edMessage->document()->toPlainText().toStdString(); + CKey key; - if(!key.SetCompactSignature(hash, vchSig)) + if (!key.SetCompactSignature(Hash(ss.begin(), ss.end()), vchSig)) { - QMessageBox::warning(this, tr("Invalid Signature"), tr("The signature did not match the message digest. Please check the signature and try again.")); - return false; + ui->lnSig->setValid(false); + ui->lblStatus->setStyleSheet("QLabel { color: red; }"); + ui->lblStatus->setText(tr("The signature did not match the message digest.")+ QString(" ") + tr("Please check the signature and try again.")); + return; } - CBitcoinAddress address(key.GetPubKey().GetID()); - QString qStringAddress = QString::fromStdString(address.ToString()); - ui->lnAddress->setText(qStringAddress); - ui->copyToClipboard->setEnabled(true); - - QString label = model->labelForAddress(qStringAddress); - ui->lblStatus->setText(label.isEmpty() ? tr("Address not found in address book.") : tr("Address found in address book: %1").arg(label)); - return true; -} - -void VerifyMessageDialog::on_verifyMessage_clicked() -{ - checkAddress(); -} + if (!(CBitcoinAddress(key.GetPubKey().GetID()) == addr)) + { + ui->lblStatus->setStyleSheet("QLabel { color: red; }"); + ui->lblStatus->setText(QString("") + tr("Message verification failed.") + QString("")); + return; + } -void VerifyMessageDialog::on_copyToClipboard_clicked() -{ - QApplication::clipboard()->setText(ui->lnAddress->text()); + ui->lblStatus->setStyleSheet("QLabel { color: green; }"); + ui->lblStatus->setText(QString("") + tr("Message verified.") + QString("")); } void VerifyMessageDialog::on_clearButton_clicked() { - ui->edMessage->clear(); - ui->lnSig->clear(); ui->lnAddress->clear(); + ui->lnSig->clear(); + ui->edMessage->clear(); ui->lblStatus->clear(); ui->edMessage->setFocus(); @@ -95,9 +107,11 @@ void VerifyMessageDialog::on_clearButton_clicked() bool VerifyMessageDialog::eventFilter(QObject *object, QEvent *event) { - if(object == ui->lnAddress && (event->type() == QEvent::MouseButtonPress || + if (object == ui->lnAddress && (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::FocusIn)) { + // set lnAddress to valid, as QEvent::FocusIn would not reach QValidatedLineEdit::focusInEvent + ui->lnAddress->setValid(true); ui->lnAddress->selectAll(); return true; } diff --git a/src/qt/verifymessagedialog.h b/src/qt/verifymessagedialog.h index 9a3fb4341..0bed442d4 100644 --- a/src/qt/verifymessagedialog.h +++ b/src/qt/verifymessagedialog.h @@ -16,21 +16,17 @@ class VerifyMessageDialog : public QDialog Q_OBJECT public: - explicit VerifyMessageDialog(AddressTableModel *addressModel, QWidget *parent = 0); + explicit VerifyMessageDialog(QWidget *parent); ~VerifyMessageDialog(); protected: bool eventFilter(QObject *object, QEvent *event); private: - bool checkAddress(); - Ui::VerifyMessageDialog *ui; - AddressTableModel *model; private slots: void on_verifyMessage_clicked(); - void on_copyToClipboard_clicked(); void on_clearButton_clicked(); };