aboutsummaryrefslogtreecommitdiff
path: root/src/qt/verifymessagedialog.cpp
diff options
context:
space:
mode:
authorPhilip Kaufmann <phil.kaufmann@t-online.de>2012-05-21 14:13:16 +0200
committerPhilip Kaufmann <phil.kaufmann@t-online.de>2012-06-01 11:13:44 +0200
commit8103b0bb622a927a07d0bbd2696469eb5969e246 (patch)
tree500729164275e75e40d8972d7f0542356e8f318a /src/qt/verifymessagedialog.cpp
parent98474d3d6f07ff03f25f59f2016baf1f1385fbed (diff)
change verifymessagepage behaviour to match RPC-call "verifymessage" (input address, signature and message) / display messages in status label (remove message boxes) / resize window to make signature fully readable / change signature font to BC-address font (like in messagepage) / remove checkAddress() and place code directly in on_verifyMessage_clicked() / add visual feedback to LineEdits / remove AddressTableModel references, as they are now unused / add addr.GetKeyID(keyID) check
Diffstat (limited to 'src/qt/verifymessagedialog.cpp')
-rw-r--r--src/qt/verifymessagedialog.cpp100
1 files changed, 57 insertions, 43 deletions
diff --git a/src/qt/verifymessagedialog.cpp b/src/qt/verifymessagedialog.cpp
index d71568d2e9..92f58328a4 100644
--- a/src/qt/verifymessagedialog.cpp
+++ b/src/qt/verifymessagedialog.cpp
@@ -4,35 +4,36 @@
#include <string>
#include <vector>
-#include <QDialogButtonBox>
-#include <QAbstractButton>
-#include <QClipboard>
-#include <QMessageBox>
+#include <QDialog>
+#include <QLabel>
+#include <QLineEdit>
+#include <QPlainTextEdit>
+#include <QPushButton>
#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<unsigned char> vchSig = DecodeBase64(ui->lnSig->text().toStdString().c_str(), &invalid);
+ bool fInvalid = false;
+ std::vector<unsigned char> 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("<nobr>") + tr("Message verification failed.") + QString("</nobr>"));
+ return;
+ }
-void VerifyMessageDialog::on_copyToClipboard_clicked()
-{
- QApplication::clipboard()->setText(ui->lnAddress->text());
+ ui->lblStatus->setStyleSheet("QLabel { color: green; }");
+ ui->lblStatus->setText(QString("<nobr>") + tr("Message verified.") + QString("</nobr>"));
}
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;
}