2011-12-23 16:14:57 +01:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2012-01-28 10:29:01 +01:00
|
|
|
#include <QClipboard>
|
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QList>
|
|
|
|
#include <QListWidgetItem>
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
2011-12-23 16:14:57 +01:00
|
|
|
#include "main.h"
|
|
|
|
#include "wallet.h"
|
|
|
|
#include "init.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
#include "messagepage.h"
|
|
|
|
#include "ui_messagepage.h"
|
|
|
|
|
|
|
|
#include "addressbookpage.h"
|
|
|
|
#include "guiutil.h"
|
|
|
|
#include "walletmodel.h"
|
|
|
|
|
|
|
|
MessagePage::MessagePage(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::MessagePage)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2012-05-07 00:19:22 +02:00
|
|
|
|
|
|
|
#if (QT_VERSION >= 0x040700)
|
|
|
|
/* Do not move this to the XML file, Qt before 4.7 will choke on it */
|
|
|
|
ui->signature->setPlaceholderText(tr("Click \"Sign Message\" to get signature"));
|
|
|
|
#endif
|
2011-12-23 16:14:57 +01:00
|
|
|
|
|
|
|
GUIUtil::setupAddressWidget(ui->signFrom, this);
|
2012-05-05 09:44:15 +02:00
|
|
|
ui->signature->installEventFilter(this);
|
2011-12-23 16:14:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MessagePage::~MessagePage()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessagePage::setModel(WalletModel *model)
|
|
|
|
{
|
|
|
|
this->model = model;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessagePage::setAddress(QString addr)
|
|
|
|
{
|
|
|
|
ui->signFrom->setText(addr);
|
|
|
|
ui->message->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessagePage::on_pasteButton_clicked()
|
|
|
|
{
|
|
|
|
setAddress(QApplication::clipboard()->text());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessagePage::on_addressBookButton_clicked()
|
|
|
|
{
|
|
|
|
AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::ReceivingTab, this);
|
|
|
|
dlg.setModel(model->getAddressTableModel());
|
|
|
|
if(dlg.exec())
|
|
|
|
{
|
|
|
|
setAddress(dlg.getReturnValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessagePage::on_copyToClipboard_clicked()
|
|
|
|
{
|
|
|
|
QApplication::clipboard()->setText(ui->signature->text());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessagePage::on_signMessage_clicked()
|
|
|
|
{
|
|
|
|
QString address = ui->signFrom->text();
|
|
|
|
|
|
|
|
CBitcoinAddress addr(address.toStdString());
|
|
|
|
if (!addr.IsValid())
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error signing"), tr("%1 is not a valid address.").arg(address),
|
|
|
|
QMessageBox::Abort, QMessageBox::Abort);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WalletModel::UnlockContext ctx(model->requestUnlock());
|
|
|
|
if(!ctx.isValid())
|
|
|
|
{
|
|
|
|
// Unlock wallet was cancelled
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CKey key;
|
|
|
|
if (!pwalletMain->GetKey(addr, key))
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error signing"), tr("Private key for %1 is not available.").arg(address),
|
|
|
|
QMessageBox::Abort, QMessageBox::Abort);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-16 14:56:45 +02:00
|
|
|
CDataStream ss(SER_GETHASH, 0);
|
2011-12-23 16:14:57 +01:00
|
|
|
ss << strMessageMagic;
|
|
|
|
ss << ui->message->document()->toPlainText().toStdString();
|
|
|
|
|
|
|
|
std::vector<unsigned char> vchSig;
|
|
|
|
if (!key.SignCompact(Hash(ss.begin(), ss.end()), vchSig))
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Error signing"), tr("Sign failed"),
|
|
|
|
QMessageBox::Abort, QMessageBox::Abort);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->signature->setText(QString::fromStdString(EncodeBase64(&vchSig[0], vchSig.size())));
|
|
|
|
ui->signature->setFont(GUIUtil::bitcoinAddressFont());
|
|
|
|
}
|
2012-04-30 01:11:53 +02:00
|
|
|
|
|
|
|
void MessagePage::on_clearButton_clicked()
|
|
|
|
{
|
|
|
|
ui->signFrom->clear();
|
|
|
|
ui->message->clear();
|
|
|
|
ui->signature->clear();
|
|
|
|
}
|
2012-05-05 09:44:15 +02:00
|
|
|
|
|
|
|
bool MessagePage::eventFilter(QObject *object, QEvent *event)
|
|
|
|
{
|
|
|
|
if(object == ui->signature && (event->type() == QEvent::MouseButtonPress ||
|
|
|
|
event->type() == QEvent::FocusIn))
|
|
|
|
{
|
|
|
|
ui->signature->selectAll();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return QDialog::eventFilter(object, event);
|
|
|
|
}
|