Browse Source

Merge pull request #1368 from Diapolo/verifymessagepage

GUI: change verifymessagepage behaviour to match RPC-call "verifymessage"
miguelfreitas
Wladimir J. van der Laan 13 years ago
parent
commit
88d7bc930a
  1. 2
      src/qt/bitcoingui.cpp
  2. 77
      src/qt/forms/verifymessagedialog.ui
  3. 100
      src/qt/verifymessagedialog.cpp
  4. 6
      src/qt/verifymessagedialog.h

2
src/qt/bitcoingui.cpp

@ -849,7 +849,7 @@ void BitcoinGUI::changePassphrase()
void BitcoinGUI::verifyMessage() void BitcoinGUI::verifyMessage()
{ {
VerifyMessageDialog *dlg = new VerifyMessageDialog(walletModel->getAddressTableModel(), this); VerifyMessageDialog *dlg = new VerifyMessageDialog(this);
dlg->setAttribute(Qt::WA_DeleteOnClose); dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->show(); dlg->show();
} }

77
src/qt/forms/verifymessagedialog.ui

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>494</width> <width>650</width>
<height>342</height> <height>380</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -17,7 +17,7 @@
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>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.</string> <string>Enter the signing address, signature and message below (be careful to correctly copy newlines, spaces, tabs and other invisible characters) to verify the message.</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
@ -28,38 +28,28 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPlainTextEdit" name="edMessage"/> <widget class="QValidatedLineEdit" name="lnAddress">
</item>
<item>
<widget class="QLineEdit" name="lnSig">
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lnAddress"> <widget class="QValidatedLineEdit" name="lnSig">
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="lblStatus"> <widget class="QPlainTextEdit" name="edMessage"/>
<property name="text">
<string/>
</property>
</widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QPushButton" name="verifyMessage"> <widget class="QPushButton" name="verifyMessage">
<property name="toolTip"> <property name="toolTip">
<string>Verify a message and obtain the Bitcoin address used to sign the message</string> <string>Verify a message to ensure it was signed with the specified Bitcoin address</string>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Verify Message</string> <string>&amp;Verify Message</string>
@ -71,33 +61,51 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="copyToClipboard"> <widget class="QPushButton" name="clearButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Copy the currently selected address to the system clipboard</string> <string>Reset all verify message fields</string>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Copy Address</string> <string>Clear &amp;All</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../bitcoin.qrc"> <iconset resource="../bitcoin.qrc">
<normaloff>:/icons/editcopy</normaloff>:/icons/editcopy</iconset> <normaloff>:/icons/remove</normaloff>:/icons/remove</iconset>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="clearButton"> <spacer name="horizontalSpacer_2">
<property name="toolTip"> <property name="orientation">
<string>Reset all verify message fields</string> <enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lblStatus">
<property name="minimumSize">
<size>
<width>0</width>
<height>48</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property> </property>
<property name="text"> <property name="text">
<string>Clear &amp;All</string> <string/>
</property> </property>
<property name="icon"> <property name="wordWrap">
<iconset resource="../bitcoin.qrc"> <bool>true</bool>
<normaloff>:/icons/remove</normaloff>:/icons/remove</iconset>
</property> </property>
</widget> </widget>
</item> </item>
@ -118,6 +126,13 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>QValidatedLineEdit</class>
<extends>QLineEdit</extends>
<header>qvalidatedlineedit.h</header>
</customwidget>
</customwidgets>
<resources> <resources>
<include location="../bitcoin.qrc"/> <include location="../bitcoin.qrc"/>
</resources> </resources>

100
src/qt/verifymessagedialog.cpp

@ -4,35 +4,36 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <QDialogButtonBox> #include <QDialog>
#include <QAbstractButton> #include <QLabel>
#include <QClipboard> #include <QLineEdit>
#include <QMessageBox> #include <QPlainTextEdit>
#include <QPushButton>
#include "main.h" #include "main.h"
#include "wallet.h" #include "wallet.h"
#include "walletmodel.h" #include "walletmodel.h"
#include "addresstablemodel.h"
#include "guiutil.h" #include "guiutil.h"
#include "base58.h" #include "base58.h"
VerifyMessageDialog::VerifyMessageDialog(AddressTableModel *addressModel, QWidget *parent) : VerifyMessageDialog::VerifyMessageDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::VerifyMessageDialog), ui(new Ui::VerifyMessageDialog)
model(addressModel)
{ {
ui->setupUi(this); ui->setupUi(this);
#if (QT_VERSION >= 0x040700) #if (QT_VERSION >= 0x040700)
/* Do not move this to the XML file, Qt before 4.7 will choke on it */ /* 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->lnSig->setPlaceholderText(tr("Enter Bitcoin signature"));
ui->lnAddress->setPlaceholderText(tr("Click \"Verify Message\" to obtain address"));
#endif #endif
GUIUtil::setupAddressWidget(ui->lnAddress, this); GUIUtil::setupAddressWidget(ui->lnAddress, this);
ui->lnAddress->installEventFilter(this); ui->lnAddress->installEventFilter(this);
ui->edMessage->setFocus(); ui->lnSig->setFont(GUIUtil::bitcoinAddressFont());
ui->lnAddress->setFocus();
} }
VerifyMessageDialog::~VerifyMessageDialog() VerifyMessageDialog::~VerifyMessageDialog()
@ -40,54 +41,65 @@ VerifyMessageDialog::~VerifyMessageDialog()
delete ui; delete ui;
} }
bool VerifyMessageDialog::checkAddress() void VerifyMessageDialog::on_verifyMessage_clicked()
{ {
CDataStream ss(SER_GETHASH, 0); CBitcoinAddress addr(ui->lnAddress->text().toStdString());
ss << strMessageMagic; if (!addr.IsValid())
ss << ui->edMessage->document()->toPlainText().toStdString(); {
uint256 hash = Hash(ss.begin(), ss.end()); 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; bool fInvalid = false;
std::vector<unsigned char> vchSig = DecodeBase64(ui->lnSig->text().toStdString().c_str(), &invalid); 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.")); ui->lnSig->setValid(false);
return 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; 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.")); ui->lnSig->setValid(false);
return 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()); if (!(CBitcoinAddress(key.GetPubKey().GetID()) == addr))
QString qStringAddress = QString::fromStdString(address.ToString()); {
ui->lnAddress->setText(qStringAddress); ui->lblStatus->setStyleSheet("QLabel { color: red; }");
ui->copyToClipboard->setEnabled(true); ui->lblStatus->setText(QString("<nobr>") + tr("Message verification failed.") + QString("</nobr>"));
return;
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();
}
void VerifyMessageDialog::on_copyToClipboard_clicked() ui->lblStatus->setStyleSheet("QLabel { color: green; }");
{ ui->lblStatus->setText(QString("<nobr>") + tr("Message verified.") + QString("</nobr>"));
QApplication::clipboard()->setText(ui->lnAddress->text());
} }
void VerifyMessageDialog::on_clearButton_clicked() void VerifyMessageDialog::on_clearButton_clicked()
{ {
ui->edMessage->clear();
ui->lnSig->clear();
ui->lnAddress->clear(); ui->lnAddress->clear();
ui->lnSig->clear();
ui->edMessage->clear();
ui->lblStatus->clear(); ui->lblStatus->clear();
ui->edMessage->setFocus(); ui->edMessage->setFocus();
@ -95,9 +107,11 @@ void VerifyMessageDialog::on_clearButton_clicked()
bool VerifyMessageDialog::eventFilter(QObject *object, QEvent *event) 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)) event->type() == QEvent::FocusIn))
{ {
// set lnAddress to valid, as QEvent::FocusIn would not reach QValidatedLineEdit::focusInEvent
ui->lnAddress->setValid(true);
ui->lnAddress->selectAll(); ui->lnAddress->selectAll();
return true; return true;
} }

6
src/qt/verifymessagedialog.h

@ -16,21 +16,17 @@ class VerifyMessageDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit VerifyMessageDialog(AddressTableModel *addressModel, QWidget *parent = 0); explicit VerifyMessageDialog(QWidget *parent);
~VerifyMessageDialog(); ~VerifyMessageDialog();
protected: protected:
bool eventFilter(QObject *object, QEvent *event); bool eventFilter(QObject *object, QEvent *event);
private: private:
bool checkAddress();
Ui::VerifyMessageDialog *ui; Ui::VerifyMessageDialog *ui;
AddressTableModel *model;
private slots: private slots:
void on_verifyMessage_clicked(); void on_verifyMessage_clicked();
void on_copyToClipboard_clicked();
void on_clearButton_clicked(); void on_clearButton_clicked();
}; };

Loading…
Cancel
Save