aboutsummaryrefslogtreecommitdiff
path: root/src/qt/messagepage.cpp
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2011-12-23 10:14:57 -0500
committerWladimir J. van der Laan <laanwj@gmail.com>2012-01-27 08:41:55 +0100
commit2bc4fd609ca00d5a5cb0b6b3eba5f35cb334b967 (patch)
tree79eb64f0322a6b6fadaa72cbce3b3fc369a2a007 /src/qt/messagepage.cpp
parent70f55355e29c8e45b607e782c5d76609d23cc858 (diff)
Bitcoin-Qt signmessage GUI (pull request #582)
Diffstat (limited to 'src/qt/messagepage.cpp')
-rw-r--r--src/qt/messagepage.cpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/qt/messagepage.cpp b/src/qt/messagepage.cpp
new file mode 100644
index 0000000000..dee1837ed6
--- /dev/null
+++ b/src/qt/messagepage.cpp
@@ -0,0 +1,107 @@
+#include <string>
+#include <vector>
+
+#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"
+
+#include <QClipboard>
+#include <QInputDialog>
+#include <QList>
+#include <QListWidgetItem>
+#include <QMessageBox>
+
+MessagePage::MessagePage(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::MessagePage)
+{
+ ui->setupUi(this);
+
+ GUIUtil::setupAddressWidget(ui->signFrom, this);
+}
+
+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;
+ }
+
+ CDataStream ss(SER_GETHASH);
+ 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());
+}