1 #include "verifymessagedialog.h"
2 #include "ui_verifymessagedialog.h"
10 #include <QPlainTextEdit>
11 #include <QPushButton>
15 #include "walletmodel.h"
19 VerifyMessageDialog::VerifyMessageDialog(QWidget *parent) :
21 ui(new Ui::VerifyMessageDialog)
25 #if (QT_VERSION >= 0x040700)
26 /* Do not move this to the XML file, Qt before 4.7 will choke on it */
27 ui->lnAddress->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
28 ui->lnSig->setPlaceholderText(tr("Enter Bitcoin signature"));
31 GUIUtil::setupAddressWidget(ui->lnAddress, this);
32 ui->lnAddress->installEventFilter(this);
34 ui->lnSig->setFont(GUIUtil::bitcoinAddressFont());
36 ui->lnAddress->setFocus();
39 VerifyMessageDialog::~VerifyMessageDialog()
44 void VerifyMessageDialog::on_verifyMessage_clicked()
46 CBitcoinAddress addr(ui->lnAddress->text().toStdString());
49 ui->lnAddress->setValid(false);
50 ui->lblStatus->setStyleSheet("QLabel { color: red; }");
51 ui->lblStatus->setText(tr("\"%1\" is not a valid address.").arg(ui->lnAddress->text()) + QString(" ") + tr("Please check the address and try again."));
55 if (!addr.GetKeyID(keyID))
57 ui->lnAddress->setValid(false);
58 ui->lblStatus->setStyleSheet("QLabel { color: red; }");
59 ui->lblStatus->setText(tr("\"%1\" does not refer to a key.").arg(ui->lnAddress->text()) + QString(" ") + tr("Please check the address and try again."));
63 bool fInvalid = false;
64 std::vector<unsigned char> vchSig = DecodeBase64(ui->lnSig->text().toStdString().c_str(), &fInvalid);
68 ui->lnSig->setValid(false);
69 ui->lblStatus->setStyleSheet("QLabel { color: red; }");
70 ui->lblStatus->setText(tr("The signature could not be decoded.") + QString(" ") + tr("Please check the signature and try again."));
74 CDataStream ss(SER_GETHASH, 0);
75 ss << strMessageMagic;
76 ss << ui->edMessage->document()->toPlainText().toStdString();
79 if (!key.SetCompactSignature(Hash(ss.begin(), ss.end()), vchSig))
81 ui->lnSig->setValid(false);
82 ui->lblStatus->setStyleSheet("QLabel { color: red; }");
83 ui->lblStatus->setText(tr("The signature did not match the message digest.")+ QString(" ") + tr("Please check the signature and try again."));
87 if (!(CBitcoinAddress(key.GetPubKey().GetID()) == addr))
89 ui->lblStatus->setStyleSheet("QLabel { color: red; }");
90 ui->lblStatus->setText(QString("<nobr>") + tr("Message verification failed.") + QString("</nobr>"));
94 ui->lblStatus->setStyleSheet("QLabel { color: green; }");
95 ui->lblStatus->setText(QString("<nobr>") + tr("Message verified.") + QString("</nobr>"));
98 void VerifyMessageDialog::on_clearButton_clicked()
100 ui->lnAddress->clear();
102 ui->edMessage->clear();
103 ui->lblStatus->clear();
105 ui->edMessage->setFocus();
108 bool VerifyMessageDialog::eventFilter(QObject *object, QEvent *event)
110 if (object == ui->lnAddress && (event->type() == QEvent::MouseButtonPress ||
111 event->type() == QEvent::FocusIn))
113 // set lnAddress to valid, as QEvent::FocusIn would not reach QValidatedLineEdit::focusInEvent
114 ui->lnAddress->setValid(true);
115 ui->lnAddress->selectAll();
118 return QDialog::eventFilter(object, event);