diff --git a/bitcoin-qt.pro b/bitcoin-qt.pro index 22f624d59..ed6ce85aa 100644 --- a/bitcoin-qt.pro +++ b/bitcoin-qt.pro @@ -100,7 +100,7 @@ HEADERS += src/qt/bitcoingui.h \ src/qt/optionsdialog.h \ src/qt/sendcoinsdialog.h \ src/qt/addressbookpage.h \ - src/qt/messagepage.h \ + src/qt/signverifymessagedialog.h \ src/qt/aboutdialog.h \ src/qt/editaddressdialog.h \ src/qt/bitcoinaddressvalidator.h \ @@ -160,8 +160,7 @@ HEADERS += src/qt/bitcoingui.h \ src/qt/qtipcserver.h \ src/allocators.h \ src/ui_interface.h \ - src/qt/rpcconsole.h \ - src/qt/verifymessagedialog.h + src/qt/rpcconsole.h SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \ src/qt/transactiontablemodel.cpp \ @@ -169,7 +168,7 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \ src/qt/optionsdialog.cpp \ src/qt/sendcoinsdialog.cpp \ src/qt/addressbookpage.cpp \ - src/qt/messagepage.cpp \ + src/qt/signverifymessagedialog.cpp \ src/qt/aboutdialog.cpp \ src/qt/editaddressdialog.cpp \ src/qt/bitcoinaddressvalidator.cpp \ @@ -220,7 +219,6 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \ src/qt/notificator.cpp \ src/qt/qtipcserver.cpp \ src/qt/rpcconsole.cpp \ - src/qt/verifymessagedialog.cpp \ src/noui.cpp RESOURCES += \ @@ -229,7 +227,7 @@ RESOURCES += \ FORMS += \ src/qt/forms/sendcoinsdialog.ui \ src/qt/forms/addressbookpage.ui \ - src/qt/forms/messagepage.ui \ + src/qt/forms/signverifymessagedialog.ui \ src/qt/forms/aboutdialog.ui \ src/qt/forms/editaddressdialog.ui \ src/qt/forms/transactiondescdialog.ui \ @@ -237,7 +235,6 @@ FORMS += \ src/qt/forms/sendcoinsentry.ui \ src/qt/forms/askpassphrasedialog.ui \ src/qt/forms/rpcconsole.ui \ - src/qt/forms/verifymessagedialog.ui \ src/qt/forms/optionsdialog.ui contains(USE_QRCODE, 1) { diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp index 663ff6866..e502d9bc3 100644 --- a/src/qt/addressbookpage.cpp +++ b/src/qt/addressbookpage.cpp @@ -67,6 +67,7 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : QAction *editAction = new QAction(tr("&Edit"), this); QAction *showQRCodeAction = new QAction(ui->showQRCode->text(), this); QAction *signMessageAction = new QAction(ui->signMessage->text(), this); + QAction *verifyMessageAction = new QAction(ui->verifyMessage->text(), this); deleteAction = new QAction(ui->deleteButton->text(), this); // Build context menu @@ -80,6 +81,8 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : contextMenu->addAction(showQRCodeAction); if(tab == ReceivingTab) contextMenu->addAction(signMessageAction); + else if(tab == SendingTab) + contextMenu->addAction(verifyMessageAction); // Connect signals for context menu actions connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(on_copyToClipboard_clicked())); @@ -88,6 +91,7 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) : connect(deleteAction, SIGNAL(triggered()), this, SLOT(on_deleteButton_clicked())); connect(showQRCodeAction, SIGNAL(triggered()), this, SLOT(on_showQRCode_clicked())); connect(signMessageAction, SIGNAL(triggered()), this, SLOT(on_signMessage_clicked())); + connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(on_verifyMessage_clicked())); connect(ui->tableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint))); @@ -189,7 +193,25 @@ void AddressBookPage::on_signMessage_clicked() QObject *qoGUI = parent()->parent(); BitcoinGUI *gui = qobject_cast(qoGUI); if (gui) - gui->gotoMessagePage(addr); + gui->gotoSignMessageTab(addr); +} + +void AddressBookPage::on_verifyMessage_clicked() +{ + QTableView *table = ui->tableView; + QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address); + QString addr; + + foreach (QModelIndex index, indexes) + { + QVariant address = index.data(); + addr = address.toString(); + } + + QObject *qoGUI = parent()->parent(); + BitcoinGUI *gui = qobject_cast(qoGUI); + if (gui) + gui->gotoVerifyMessageTab(addr); } void AddressBookPage::on_newAddressButton_clicked() @@ -237,6 +259,8 @@ void AddressBookPage::selectionChanged() deleteAction->setEnabled(true); ui->signMessage->setEnabled(false); ui->signMessage->setVisible(false); + ui->verifyMessage->setEnabled(true); + ui->verifyMessage->setVisible(true); break; case ReceivingTab: // Deleting receiving addresses, however, is not allowed @@ -245,6 +269,8 @@ void AddressBookPage::selectionChanged() deleteAction->setEnabled(false); ui->signMessage->setEnabled(true); ui->signMessage->setVisible(true); + ui->verifyMessage->setEnabled(false); + ui->verifyMessage->setVisible(false); break; } ui->copyToClipboard->setEnabled(true); @@ -256,6 +282,7 @@ void AddressBookPage::selectionChanged() ui->showQRCode->setEnabled(false); ui->copyToClipboard->setEnabled(false); ui->signMessage->setEnabled(false); + ui->verifyMessage->setEnabled(false); } } diff --git a/src/qt/addressbookpage.h b/src/qt/addressbookpage.h index e94c55613..fae688fc9 100644 --- a/src/qt/addressbookpage.h +++ b/src/qt/addressbookpage.h @@ -63,6 +63,7 @@ private slots: /** Copy address of currently selected address entry to clipboard */ void on_copyToClipboard_clicked(); void on_signMessage_clicked(); + void on_verifyMessage_clicked(); void selectionChanged(); void on_showQRCode_clicked(); /** Spawn contextual menu (right mouse menu) for address book entry */ diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 3ef03c437..775d676ee 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -8,8 +8,7 @@ #include "transactiontablemodel.h" #include "addressbookpage.h" #include "sendcoinsdialog.h" -#include "messagepage.h" -#include "verifymessagedialog.h" +#include "signverifymessagedialog.h" #include "optionsdialog.h" #include "aboutdialog.h" #include "clientmodel.h" @@ -108,7 +107,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): sendCoinsPage = new SendCoinsDialog(this); - messagePage = new MessagePage(this); + signVerifyMessageDialog = new SignVerifyMessageDialog(this); centralWidget = new QStackedWidget(this); centralWidget->addWidget(overviewPage); @@ -117,7 +116,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): centralWidget->addWidget(receiveCoinsPage); centralWidget->addWidget(sendCoinsPage); #ifdef FIRST_CLASS_MESSAGING - centralWidget->addWidget(messagePage); + centralWidget->addWidget(signVerifyMessageDialog); #endif setCentralWidget(centralWidget); @@ -212,12 +211,20 @@ void BitcoinGUI::createActions() sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2)); tabGroup->addAction(sendCoinsAction); - messageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this); - messageAction->setToolTip(tr("Prove you control an address")); + signMessageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message..."), this); + signMessageAction->setToolTip(tr("Sign a message to prove you own a Bitcoin address")); + tabGroup->addAction(signMessageAction); + + verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this); + verifyMessageAction->setToolTip(tr("Verify a message to ensure it was signed with a specified Bitcoin address")); + tabGroup->addAction(verifyMessageAction); + #ifdef FIRST_CLASS_MESSAGING - messageAction->setCheckable(true); + firstClassMessagingAction = new QAction(QIcon(":/icons/edit"), tr("S&ignatures"), this); + firstClassMessagingAction->setToolTip(signMessageAction->toolTip() + QString(". / ") + verifyMessageAction->toolTip() + QString(".")); + firstClassMessagingAction->setCheckable(true); + tabGroup->addAction(firstClassMessagingAction); #endif - tabGroup->addAction(messageAction); connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage())); @@ -229,8 +236,15 @@ void BitcoinGUI::createActions() connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage())); connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage())); - connect(messageAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); - connect(messageAction, SIGNAL(triggered()), this, SLOT(gotoMessagePage())); + connect(signMessageAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); + connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab())); + connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); + connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(gotoVerifyMessageTab())); +#ifdef FIRST_CLASS_MESSAGING + connect(firstClassMessagingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); + // Always start with the sign message tab for FIRST_CLASS_MESSAGING + connect(firstClassMessagingAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab())); +#endif quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this); quitAction->setToolTip(tr("Quit application")); @@ -258,8 +272,6 @@ void BitcoinGUI::createActions() changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption")); openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this); openRPCConsoleAction->setToolTip(tr("Open debugging and diagnostic console")); - verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this); - verifyMessageAction->setToolTip(tr("Verify a message signature")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked())); @@ -269,7 +281,6 @@ void BitcoinGUI::createActions() connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool))); connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet())); connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase())); - connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(verifyMessage())); } void BitcoinGUI::createMenuBar() @@ -287,9 +298,9 @@ void BitcoinGUI::createMenuBar() file->addAction(backupWalletAction); file->addAction(exportAction); #ifndef FIRST_CLASS_MESSAGING - file->addAction(messageAction); -#endif + file->addAction(signMessageAction); file->addAction(verifyMessageAction); +#endif file->addSeparator(); file->addAction(quitAction); @@ -316,7 +327,7 @@ void BitcoinGUI::createToolBars() toolbar->addAction(historyAction); toolbar->addAction(addressBookAction); #ifdef FIRST_CLASS_MESSAGING - toolbar->addAction(messageAction); + toolbar->addAction(firstClassMessagingAction); #endif QToolBar *toolbar2 = addToolBar(tr("Actions toolbar")); @@ -377,7 +388,7 @@ void BitcoinGUI::setWalletModel(WalletModel *walletModel) addressBookPage->setModel(walletModel->getAddressTableModel()); receiveCoinsPage->setModel(walletModel->getAddressTableModel()); sendCoinsPage->setModel(walletModel); - messagePage->setModel(walletModel); + signVerifyMessageDialog->setModel(walletModel); setEncryptionStatus(walletModel->getEncryptionStatus()); connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int))); @@ -417,7 +428,7 @@ void BitcoinGUI::createTrayIcon() #ifndef FIRST_CLASS_MESSAGING trayIconMenu->addSeparator(); #endif - trayIconMenu->addAction(messageAction); + trayIconMenu->addAction(signMessageAction); trayIconMenu->addAction(verifyMessageAction); trayIconMenu->addSeparator(); trayIconMenu->addAction(optionsAction); @@ -719,20 +730,42 @@ void BitcoinGUI::gotoSendCoinsPage() disconnect(exportAction, SIGNAL(triggered()), 0, 0); } -void BitcoinGUI::gotoMessagePage(QString addr) +void BitcoinGUI::gotoSignMessageTab(QString addr) { +#ifdef FIRST_CLASS_MESSAGING + firstClassMessagingAction->setChecked(true); + centralWidget->setCurrentWidget(signVerifyMessageDialog); + + exportAction->setEnabled(false); + disconnect(exportAction, SIGNAL(triggered()), 0, 0); + + signVerifyMessageDialog->showTab_SM(false); +#else + // call show() in showTab_SM() + signVerifyMessageDialog->showTab_SM(true); +#endif + if(!addr.isEmpty()) - messagePage->setAddress(addr); + signVerifyMessageDialog->setAddress_SM(addr); +} +void BitcoinGUI::gotoVerifyMessageTab(QString addr) +{ #ifdef FIRST_CLASS_MESSAGING - messageAction->setChecked(true); - centralWidget->setCurrentWidget(messagePage); + firstClassMessagingAction->setChecked(true); + centralWidget->setCurrentWidget(signVerifyMessageDialog); exportAction->setEnabled(false); disconnect(exportAction, SIGNAL(triggered()), 0, 0); + + signVerifyMessageDialog->showTab_VM(false); #else - messagePage->show(); + // call show() in showTab_VM() + signVerifyMessageDialog->showTab_VM(true); #endif + + if(!addr.isEmpty()) + signVerifyMessageDialog->setAddress_VM(addr); } void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event) @@ -835,13 +868,6 @@ void BitcoinGUI::changePassphrase() dlg.exec(); } -void BitcoinGUI::verifyMessage() -{ - VerifyMessageDialog *dlg = new VerifyMessageDialog(this); - dlg->setAttribute(Qt::WA_DeleteOnClose); - dlg->show(); -} - void BitcoinGUI::unlockWallet() { if(!walletModel) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 3c82cbc96..4a395012e 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -11,7 +11,7 @@ class TransactionView; class OverviewPage; class AddressBookPage; class SendCoinsDialog; -class MessagePage; +class SignVerifyMessageDialog; class Notificator; class RPCConsole; @@ -64,7 +64,7 @@ private: AddressBookPage *addressBookPage; AddressBookPage *receiveCoinsPage; SendCoinsDialog *sendCoinsPage; - MessagePage *messagePage; + SignVerifyMessageDialog *signVerifyMessageDialog; QLabel *labelEncryptionIcon; QLabel *labelConnectionsIcon; @@ -78,8 +78,9 @@ private: QAction *quitAction; QAction *sendCoinsAction; QAction *addressBookAction; - QAction *messageAction; + QAction *signMessageAction; QAction *verifyMessageAction; + QAction *firstClassMessagingAction; QAction *aboutAction; QAction *receiveCoinsAction; QAction *optionsAction; @@ -131,7 +132,8 @@ public slots: void askFee(qint64 nFeeRequired, bool *payFee); void handleURI(QString strURI); - void gotoMessagePage(QString addr = ""); + void gotoSignMessageTab(QString addr = ""); + void gotoVerifyMessageTab(QString addr = ""); private slots: /** Switch to overview (home) page */ @@ -164,8 +166,6 @@ private slots: void backupWallet(); /** Change encrypted wallet passphrase */ void changePassphrase(); - /** Verify a message signature */ - void verifyMessage(); /** Ask for pass phrase to unlock wallet temporarily */ void unlockWallet(); diff --git a/src/qt/forms/addressbookpage.ui b/src/qt/forms/addressbookpage.ui index bca0a8dcd..7708e1536 100644 --- a/src/qt/forms/addressbookpage.ui +++ b/src/qt/forms/addressbookpage.ui @@ -6,7 +6,7 @@ 0 0 - 627 + 691 347 @@ -17,10 +17,10 @@ - These are your Bitcoin addresses for receiving payments. You may want to give a different one to each sender so you can keep track of who is paying you. + These are your Bitcoin addresses for receiving payments. You may want to give a different one to each sender so you can keep track of who is paying you. - Qt::AutoText + Qt::PlainText true @@ -99,7 +99,7 @@ - Sign a message to prove you own this address + Sign a message to prove you own a Bitcoin address &Sign Message @@ -110,6 +110,20 @@ + + + + Verify a message to ensure it was signed with a specified Bitcoin address + + + &Verify Message + + + + :/icons/transaction_0:/icons/transaction_0 + + + diff --git a/src/qt/forms/messagepage.ui b/src/qt/forms/messagepage.ui deleted file mode 100644 index 0b685aae1..000000000 --- a/src/qt/forms/messagepage.ui +++ /dev/null @@ -1,181 +0,0 @@ - - - MessagePage - - - - 0 - 0 - 627 - 380 - - - - Sign Message - - - - - - You can sign messages with your addresses to prove you own them. Be careful not to sign anything vague, as phishing attacks may try to trick you into signing your identity over to them. Only sign fully-detailed statements you agree to. - - - Qt::AutoText - - - true - - - - - - - 0 - - - - - The address to sign the message with (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L) - - - 34 - - - - - - - Choose adress from address book - - - - - - - :/icons/address-book:/icons/address-book - - - Alt+A - - - false - - - false - - - - - - - Paste address from clipboard - - - - - - - :/icons/editpaste:/icons/editpaste - - - Alt+P - - - false - - - - - - - - - Enter the message you want to sign here - - - - - - - - true - - - - true - - - - - - - - - Sign a message to prove you own this address - - - &Sign Message - - - - :/icons/edit:/icons/edit - - - - - - - Copy the current signature to the system clipboard - - - &Copy Signature - - - - :/icons/editcopy:/icons/editcopy - - - - - - - Reset all sign message fields - - - Clear &All - - - - :/icons/remove:/icons/remove - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - QValidatedLineEdit - QLineEdit -
qvalidatedlineedit.h
-
-
- - - - -
diff --git a/src/qt/forms/signverifymessagedialog.ui b/src/qt/forms/signverifymessagedialog.ui new file mode 100644 index 000000000..e22aea867 --- /dev/null +++ b/src/qt/forms/signverifymessagedialog.ui @@ -0,0 +1,386 @@ + + + SignVerifyMessageDialog + + + + 0 + 0 + 700 + 380 + + + + Messaging - Sign / Verify a Message + + + true + + + + + + 0 + + + + &Sign Message + + + + + + You can sign messages with your addresses to prove you own them. Be careful not to sign anything vague, as phishing attacks may try to trick you into signing your identity over to them. Only sign fully-detailed statements you agree to. + + + Qt::PlainText + + + true + + + + + + + 0 + + + + + The address to sign the message with (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L) + + + 34 + + + + + + + Choose an address from the address book + + + + + + + :/icons/address-book:/icons/address-book + + + Alt+A + + + false + + + + + + + Paste address from clipboard + + + + + + + :/icons/editpaste:/icons/editpaste + + + Alt+P + + + false + + + + + + + + + Enter the message you want to sign here + + + + + + + 0 + + + + + + true + + + + true + + + + + + + Copy the current signature to the system clipboard + + + + + + + :/icons/editcopy:/icons/editcopy + + + false + + + + + + + + + + + Sign the message to prove you own this Bitcoin address + + + &Sign Message + + + + :/icons/edit:/icons/edit + + + false + + + + + + + Reset all sign message fields + + + Clear &All + + + + :/icons/remove:/icons/remove + + + false + + + + + + + Qt::Horizontal + + + + 40 + 48 + + + + + + + + + 75 + true + + + + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 48 + + + + + + + + + + + &Verify Message + + + + + + Enter the signing address, message (ensure you copy line breaks, spaces, tabs, etc. exactly) and signature below to verify the message. Be careful not to read more into the signature than what is in the signed message itself, to avoid being tricked by a man-in-the-middle attack. + + + Qt::PlainText + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + 0 + + + + + The address the message was signed with (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L) + + + 34 + + + + + + + Choose an address from the address book + + + + + + + :/icons/address-book:/icons/address-book + + + Alt+A + + + false + + + + + + + + + + + + + + + + + Verify the message to ensure it was signed with the specified Bitcoin address + + + &Verify Message + + + + :/icons/transaction_0:/icons/transaction_0 + + + false + + + + + + + Reset all verify message fields + + + Clear &All + + + + :/icons/remove:/icons/remove + + + false + + + + + + + Qt::Horizontal + + + + 40 + 48 + + + + + + + + + 75 + true + + + + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 48 + + + + + + + + + + + + + + + QValidatedLineEdit + QLineEdit +
qvalidatedlineedit.h
+
+
+ + + + +
diff --git a/src/qt/forms/verifymessagedialog.ui b/src/qt/forms/verifymessagedialog.ui deleted file mode 100644 index afe98b05a..000000000 --- a/src/qt/forms/verifymessagedialog.ui +++ /dev/null @@ -1,140 +0,0 @@ - - - VerifyMessageDialog - - - - 0 - 0 - 650 - 380 - - - - Verify Signed Message - - - - - - Enter the signing address, signature and message below (be careful to correctly copy newlines, spaces, tabs and other invisible characters) to verify the message. - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - Verify a message to ensure it was signed with the specified Bitcoin address - - - &Verify Message - - - - :/icons/transaction_0:/icons/transaction_0 - - - - - - - Reset all verify message fields - - - Clear &All - - - - :/icons/remove:/icons/remove - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 48 - - - - - 75 - true - - - - - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - QValidatedLineEdit - QLineEdit -
qvalidatedlineedit.h
-
-
- - - - -
diff --git a/src/qt/messagepage.cpp b/src/qt/messagepage.cpp deleted file mode 100644 index ab3ea5a0c..000000000 --- a/src/qt/messagepage.cpp +++ /dev/null @@ -1,143 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include - -#include "main.h" -#include "wallet.h" -#include "init.h" -#include "base58.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); - -#if (QT_VERSION >= 0x040700) - /* Do not move this to the XML file, Qt before 4.7 will choke on it */ - ui->signFrom->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)")); - ui->signature->setPlaceholderText(tr("Click \"Sign Message\" to get signature")); -#endif - - GUIUtil::setupAddressWidget(ui->signFrom, this); - ui->signature->installEventFilter(this); - - ui->signFrom->setFocus(); -} - -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; - } - CKeyID keyID; - if (!addr.GetKeyID(keyID)) - { - QMessageBox::critical(this, tr("Error signing"), tr("%1 does not refer to a key.").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(keyID, 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, 0); - ss << strMessageMagic; - ss << ui->message->document()->toPlainText().toStdString(); - - std::vector 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()); -} - -void MessagePage::on_clearButton_clicked() -{ - ui->signFrom->clear(); - ui->message->clear(); - ui->signature->clear(); - - ui->signFrom->setFocus(); -} - -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); -} diff --git a/src/qt/messagepage.h b/src/qt/messagepage.h deleted file mode 100644 index d668ae98d..000000000 --- a/src/qt/messagepage.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef MESSAGEPAGE_H -#define MESSAGEPAGE_H - -#include - -namespace Ui { - class MessagePage; -} -class WalletModel; - -QT_BEGIN_NAMESPACE -QT_END_NAMESPACE - -class MessagePage : public QDialog -{ - Q_OBJECT - -public: - explicit MessagePage(QWidget *parent = 0); - ~MessagePage(); - - void setModel(WalletModel *model); - - void setAddress(QString); - -protected: - bool eventFilter(QObject *object, QEvent *event); - -private: - Ui::MessagePage *ui; - WalletModel *model; - -private slots: - void on_pasteButton_clicked(); - void on_addressBookButton_clicked(); - - void on_signMessage_clicked(); - void on_copyToClipboard_clicked(); - void on_clearButton_clicked(); -}; - -#endif // MESSAGEPAGE_H diff --git a/src/qt/signverifymessagedialog.cpp b/src/qt/signverifymessagedialog.cpp new file mode 100644 index 000000000..f8edbf80e --- /dev/null +++ b/src/qt/signverifymessagedialog.cpp @@ -0,0 +1,274 @@ +#include "signverifymessagedialog.h" +#include "ui_signverifymessagedialog.h" + +#include "addressbookpage.h" +#include "base58.h" +#include "guiutil.h" +#include "init.h" +#include "main.h" +#include "optionsmodel.h" +#include "walletmodel.h" +#include "wallet.h" + +#include +#include + +#include + +SignVerifyMessageDialog::SignVerifyMessageDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SignVerifyMessageDialog), + model(0) +{ + ui->setupUi(this); + +#if (QT_VERSION >= 0x040700) + /* Do not move this to the XML file, Qt before 4.7 will choke on it */ + ui->addressIn_SM->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)")); + ui->signatureOut_SM->setPlaceholderText(tr("Click \"Sign Message\" to generate signature")); + + ui->addressIn_VM->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)")); + ui->signatureIn_VM->setPlaceholderText(tr("Enter Bitcoin signature")); +#endif + + GUIUtil::setupAddressWidget(ui->addressIn_SM, this); + GUIUtil::setupAddressWidget(ui->addressIn_VM, this); + + ui->addressIn_SM->installEventFilter(this); + ui->messageIn_SM->installEventFilter(this); + ui->signatureOut_SM->installEventFilter(this); + ui->addressIn_VM->installEventFilter(this); + ui->messageIn_VM->installEventFilter(this); + ui->signatureIn_VM->installEventFilter(this); + + ui->signatureOut_SM->setFont(GUIUtil::bitcoinAddressFont()); + ui->signatureIn_VM->setFont(GUIUtil::bitcoinAddressFont()); +} + +SignVerifyMessageDialog::~SignVerifyMessageDialog() +{ + delete ui; +} + +void SignVerifyMessageDialog::setModel(WalletModel *model) +{ + this->model = model; +} + +void SignVerifyMessageDialog::setAddress_SM(QString address) +{ + ui->addressIn_SM->setText(address); + ui->messageIn_SM->setFocus(); +} + +void SignVerifyMessageDialog::setAddress_VM(QString address) +{ + ui->addressIn_VM->setText(address); + ui->messageIn_VM->setFocus(); +} + +void SignVerifyMessageDialog::showTab_SM(bool fShow) +{ + ui->tabWidget->setCurrentIndex(0); + + if (fShow) + this->show(); +} + +void SignVerifyMessageDialog::showTab_VM(bool fShow) +{ + ui->tabWidget->setCurrentIndex(1); + if (fShow) + this->show(); +} + +void SignVerifyMessageDialog::on_addressBookButton_SM_clicked() +{ + if (model && model->getAddressTableModel()) + { + AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::ReceivingTab, this); + dlg.setModel(model->getAddressTableModel()); + if (dlg.exec()) + { + setAddress_SM(dlg.getReturnValue()); + } + } +} + +void SignVerifyMessageDialog::on_pasteButton_SM_clicked() +{ + setAddress_SM(QApplication::clipboard()->text()); +} + +void SignVerifyMessageDialog::on_signMessageButton_SM_clicked() +{ + /* Clear old signature to ensure users don't get confused on error with an old signature displayed */ + ui->signatureOut_SM->clear(); + + CBitcoinAddress addr(ui->addressIn_SM->text().toStdString()); + if (!addr.IsValid()) + { + ui->addressIn_SM->setValid(false); + ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel_SM->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again.")); + return; + } + CKeyID keyID; + if (!addr.GetKeyID(keyID)) + { + ui->addressIn_SM->setValid(false); + ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel_SM->setText(tr("The entered address does not refer to a key.") + QString(" ") + tr("Please check the address and try again.")); + return; + } + + WalletModel::UnlockContext ctx(model->requestUnlock()); + if (!ctx.isValid()) + { + ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel_SM->setText(tr("Wallet unlock was canceled.")); + return; + } + + CKey key; + if (!pwalletMain->GetKey(keyID, key)) + { + ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel_SM->setText(tr("Private key for the entered address is not available.")); + return; + } + + CDataStream ss(SER_GETHASH, 0); + ss << strMessageMagic; + ss << ui->messageIn_SM->document()->toPlainText().toStdString(); + + std::vector vchSig; + if (!key.SignCompact(Hash(ss.begin(), ss.end()), vchSig)) + { + ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel_SM->setText(QString("") + tr("Message signing failed.") + QString("")); + return; + } + + ui->statusLabel_SM->setStyleSheet("QLabel { color: green; }"); + ui->statusLabel_SM->setText(QString("") + tr("Message signed.") + QString("")); + + ui->signatureOut_SM->setText(QString::fromStdString(EncodeBase64(&vchSig[0], vchSig.size()))); +} + +void SignVerifyMessageDialog::on_copySignatureButton_SM_clicked() +{ + QApplication::clipboard()->setText(ui->signatureOut_SM->text()); +} + +void SignVerifyMessageDialog::on_clearButton_SM_clicked() +{ + ui->addressIn_SM->clear(); + ui->messageIn_SM->clear(); + ui->signatureOut_SM->clear(); + ui->statusLabel_SM->clear(); + + ui->addressIn_SM->setFocus(); +} + +void SignVerifyMessageDialog::on_addressBookButton_VM_clicked() +{ + if (model && model->getAddressTableModel()) + { + AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this); + dlg.setModel(model->getAddressTableModel()); + if (dlg.exec()) + { + setAddress_VM(dlg.getReturnValue()); + } + } +} + +void SignVerifyMessageDialog::on_verifyMessageButton_VM_clicked() +{ + CBitcoinAddress addr(ui->addressIn_VM->text().toStdString()); + if (!addr.IsValid()) + { + ui->addressIn_VM->setValid(false); + ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel_VM->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again.")); + return; + } + CKeyID keyID; + if (!addr.GetKeyID(keyID)) + { + ui->addressIn_VM->setValid(false); + ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel_VM->setText(tr("The entered address does not refer to a key.") + QString(" ") + tr("Please check the address and try again.")); + return; + } + + bool fInvalid = false; + std::vector vchSig = DecodeBase64(ui->signatureIn_VM->text().toStdString().c_str(), &fInvalid); + + if (fInvalid) + { + ui->signatureIn_VM->setValid(false); + ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel_VM->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->messageIn_VM->document()->toPlainText().toStdString(); + + CKey key; + if (!key.SetCompactSignature(Hash(ss.begin(), ss.end()), vchSig)) + { + ui->signatureIn_VM->setValid(false); + ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel_VM->setText(tr("The signature did not match the message digest.") + QString(" ") + tr("Please check the signature and try again.")); + return; + } + + if (!(CBitcoinAddress(key.GetPubKey().GetID()) == addr)) + { + ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel_VM->setText(QString("") + tr("Message verification failed.") + QString("")); + return; + } + + ui->statusLabel_VM->setStyleSheet("QLabel { color: green; }"); + ui->statusLabel_VM->setText(QString("") + tr("Message verified.") + QString("")); +} + +void SignVerifyMessageDialog::on_clearButton_VM_clicked() +{ + ui->addressIn_VM->clear(); + ui->signatureIn_VM->clear(); + ui->messageIn_VM->clear(); + ui->statusLabel_VM->clear(); + + ui->addressIn_VM->setFocus(); +} + +bool SignVerifyMessageDialog::eventFilter(QObject *object, QEvent *event) +{ + if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::FocusIn) + { + if (ui->tabWidget->currentIndex() == 0) + { + /* Clear status message on focus change */ + ui->statusLabel_SM->clear(); + + /* Select generated signature */ + if (object == ui->signatureOut_SM) + { + ui->signatureOut_SM->selectAll(); + return true; + } + } + else if (ui->tabWidget->currentIndex() == 1) + { + /* Clear status message on focus change */ + ui->statusLabel_VM->clear(); + } + } + return QDialog::eventFilter(object, event); +} diff --git a/src/qt/signverifymessagedialog.h b/src/qt/signverifymessagedialog.h new file mode 100644 index 000000000..5569c8bf3 --- /dev/null +++ b/src/qt/signverifymessagedialog.h @@ -0,0 +1,49 @@ +#ifndef SIGNVERIFYMESSAGEDIALOG_H +#define SIGNVERIFYMESSAGEDIALOG_H + +#include + +namespace Ui { + class SignVerifyMessageDialog; +} +class WalletModel; + +QT_BEGIN_NAMESPACE +QT_END_NAMESPACE + +class SignVerifyMessageDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SignVerifyMessageDialog(QWidget *parent = 0); + ~SignVerifyMessageDialog(); + + void setModel(WalletModel *model); + void setAddress_SM(QString address); + void setAddress_VM(QString address); + + void showTab_SM(bool fShow); + void showTab_VM(bool fShow); + +protected: + bool eventFilter(QObject *object, QEvent *event); + +private: + Ui::SignVerifyMessageDialog *ui; + WalletModel *model; + +private slots: + /* sign message */ + void on_addressBookButton_SM_clicked(); + void on_pasteButton_SM_clicked(); + void on_signMessageButton_SM_clicked(); + void on_copySignatureButton_SM_clicked(); + void on_clearButton_SM_clicked(); + /* verify message */ + void on_addressBookButton_VM_clicked(); + void on_verifyMessageButton_VM_clicked(); + void on_clearButton_VM_clicked(); +}; + +#endif // SIGNVERIFYMESSAGEDIALOG_H diff --git a/src/qt/verifymessagedialog.cpp b/src/qt/verifymessagedialog.cpp deleted file mode 100644 index 92f58328a..000000000 --- a/src/qt/verifymessagedialog.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include "verifymessagedialog.h" -#include "ui_verifymessagedialog.h" - -#include -#include - -#include -#include -#include -#include -#include - -#include "main.h" -#include "wallet.h" -#include "walletmodel.h" -#include "guiutil.h" -#include "base58.h" - -VerifyMessageDialog::VerifyMessageDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::VerifyMessageDialog) -{ - ui->setupUi(this); - -#if (QT_VERSION >= 0x040700) - /* 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")); -#endif - - GUIUtil::setupAddressWidget(ui->lnAddress, this); - ui->lnAddress->installEventFilter(this); - - ui->lnSig->setFont(GUIUtil::bitcoinAddressFont()); - - ui->lnAddress->setFocus(); -} - -VerifyMessageDialog::~VerifyMessageDialog() -{ - delete ui; -} - -void VerifyMessageDialog::on_verifyMessage_clicked() -{ - CBitcoinAddress addr(ui->lnAddress->text().toStdString()); - if (!addr.IsValid()) - { - 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 fInvalid = false; - std::vector vchSig = DecodeBase64(ui->lnSig->text().toStdString().c_str(), &fInvalid); - - if (fInvalid) - { - ui->lnSig->setValid(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; - if (!key.SetCompactSignature(Hash(ss.begin(), ss.end()), vchSig)) - { - ui->lnSig->setValid(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; - } - - if (!(CBitcoinAddress(key.GetPubKey().GetID()) == addr)) - { - ui->lblStatus->setStyleSheet("QLabel { color: red; }"); - ui->lblStatus->setText(QString("") + tr("Message verification failed.") + QString("")); - return; - } - - ui->lblStatus->setStyleSheet("QLabel { color: green; }"); - ui->lblStatus->setText(QString("") + tr("Message verified.") + QString("")); -} - -void VerifyMessageDialog::on_clearButton_clicked() -{ - ui->lnAddress->clear(); - ui->lnSig->clear(); - ui->edMessage->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)) - { - // set lnAddress to valid, as QEvent::FocusIn would not reach QValidatedLineEdit::focusInEvent - ui->lnAddress->setValid(true); - ui->lnAddress->selectAll(); - return true; - } - return QDialog::eventFilter(object, event); -} diff --git a/src/qt/verifymessagedialog.h b/src/qt/verifymessagedialog.h deleted file mode 100644 index 0bed442d4..000000000 --- a/src/qt/verifymessagedialog.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef VERIFYMESSAGEDIALOG_H -#define VERIFYMESSAGEDIALOG_H - -#include - -namespace Ui { - class VerifyMessageDialog; -} -class AddressTableModel; - -QT_BEGIN_NAMESPACE -QT_END_NAMESPACE - -class VerifyMessageDialog : public QDialog -{ - Q_OBJECT - -public: - explicit VerifyMessageDialog(QWidget *parent); - ~VerifyMessageDialog(); - -protected: - bool eventFilter(QObject *object, QEvent *event); - -private: - Ui::VerifyMessageDialog *ui; - -private slots: - void on_verifyMessage_clicked(); - void on_clearButton_clicked(); -}; - -#endif // VERIFYMESSAGEDIALOG_H