2012-02-27 12:55:04 +01:00
|
|
|
#include "verifymessagedialog.h"
|
|
|
|
#include "ui_verifymessagedialog.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QAbstractButton>
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include "wallet.h"
|
|
|
|
#include "walletmodel.h"
|
|
|
|
#include "addresstablemodel.h"
|
|
|
|
#include "guiutil.h"
|
|
|
|
|
|
|
|
VerifyMessageDialog::VerifyMessageDialog(AddressTableModel *addressModel, QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::VerifyMessageDialog),
|
|
|
|
model(addressModel)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2012-05-14 23:22:45 +02:00
|
|
|
#if (QT_VERSION >= 0x040700)
|
|
|
|
/* Do not move this to the XML file, Qt before 4.7 will choke on it */
|
|
|
|
ui->lnSig->setPlaceholderText(tr("Enter Bitcoin signature"));
|
|
|
|
ui->lnAddress->setPlaceholderText(tr("Click \"Apply\" to obtain address"));
|
|
|
|
#endif
|
|
|
|
|
2012-02-27 12:55:04 +01:00
|
|
|
GUIUtil::setupAddressWidget(ui->lnAddress, this);
|
2012-05-14 23:22:45 +02:00
|
|
|
ui->lnAddress->installEventFilter(this);
|
|
|
|
|
|
|
|
ui->edMessage->setFocus();
|
2012-02-27 12:55:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
VerifyMessageDialog::~VerifyMessageDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VerifyMessageDialog::checkAddress()
|
|
|
|
{
|
|
|
|
CDataStream ss(SER_GETHASH, 0);
|
|
|
|
ss << strMessageMagic;
|
|
|
|
ss << ui->edMessage->document()->toPlainText().toStdString();
|
|
|
|
uint256 hash = Hash(ss.begin(), ss.end());
|
|
|
|
|
|
|
|
bool invalid = true;
|
|
|
|
std::vector<unsigned char> vchSig = DecodeBase64(ui->lnSig->text().toStdString().c_str(), &invalid);
|
|
|
|
|
|
|
|
if(invalid)
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, tr("Invalid Signature"), tr("The signature could not be decoded. Please check the signature and try again."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CKey key;
|
|
|
|
if(!key.SetCompactSignature(hash, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
CBitcoinAddress address(key.GetPubKey());
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:22:45 +02:00
|
|
|
void VerifyMessageDialog::on_verifyMessage_clicked()
|
2012-02-27 12:55:04 +01:00
|
|
|
{
|
2012-05-14 23:22:45 +02:00
|
|
|
checkAddress();
|
2012-02-27 12:55:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VerifyMessageDialog::on_copyToClipboard_clicked()
|
|
|
|
{
|
|
|
|
QApplication::clipboard()->setText(ui->lnAddress->text());
|
|
|
|
}
|
2012-05-14 23:22:45 +02:00
|
|
|
|
|
|
|
void VerifyMessageDialog::on_clearButton_clicked()
|
|
|
|
{
|
|
|
|
ui->edMessage->clear();
|
|
|
|
ui->lnSig->clear();
|
|
|
|
ui->lnAddress->clear();
|
|
|
|
ui->lblStatus->clear();
|
|
|
|
|
|
|
|
ui->edMessage->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VerifyMessageDialog::eventFilter(QObject *object, QEvent *event)
|
|
|
|
{
|
|
|
|
if(object == ui->lnAddress && (event->type() == QEvent::MouseButtonPress ||
|
|
|
|
event->type() == QEvent::FocusIn))
|
|
|
|
{
|
|
|
|
ui->lnAddress->selectAll();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return QDialog::eventFilter(object, event);
|
|
|
|
}
|