Skip to content

Commit

Permalink
Bitcoin-Qt signmessage GUI (pull request #582)
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr authored and laanwj committed Jan 27, 2012
1 parent 70f5535 commit 2bc4fd6
Show file tree
Hide file tree
Showing 12 changed files with 418 additions and 2 deletions.
9 changes: 9 additions & 0 deletions bitcoin-qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ contains(USE_SSL, 1) {
DEFINES += USE_SSL
}

# use: qmake "FIRST_CLASS_MESSAGING=1"
contains(FIRST_CLASS_MESSAGING, 1) {
message(Building with first-class messaging)
DEFINES += FIRST_CLASS_MESSAGING
}

contains(BITCOIN_NEED_QT_PLUGINS, 1) {
DEFINES += BITCOIN_NEED_QT_PLUGINS
QTPLUGIN += qcncodecs qjpcodecs qtwcodecs qkrcodecs
Expand All @@ -91,6 +97,7 @@ HEADERS += src/qt/bitcoingui.h \
src/qt/optionsdialog.h \
src/qt/sendcoinsdialog.h \
src/qt/addressbookpage.h \
src/qt/messagepage.h \
src/qt/aboutdialog.h \
src/qt/editaddressdialog.h \
src/qt/bitcoinaddressvalidator.h \
Expand Down Expand Up @@ -154,6 +161,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/aboutdialog.cpp \
src/qt/editaddressdialog.cpp \
src/qt/bitcoinaddressvalidator.cpp \
Expand Down Expand Up @@ -204,6 +212,7 @@ RESOURCES += \
FORMS += \
src/qt/forms/sendcoinsdialog.ui \
src/qt/forms/addressbookpage.ui \
src/qt/forms/messagepage.ui \
src/qt/forms/aboutdialog.ui \
src/qt/forms/editaddressdialog.ui \
src/qt/forms/transactiondescdialog.ui \
Expand Down
2 changes: 0 additions & 2 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,6 @@ Value sendtoaddress(const Array& params, bool fHelp)
return wtx.GetHash().GetHex();
}

static const string strMessageMagic = "Bitcoin Signed Message:\n";

Value signmessage(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 2)
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ map<uint256, CDataStream*> mapOrphanTransactions;
multimap<uint256, CDataStream*> mapOrphanTransactionsByPrev;


const string strMessageMagic = "Bitcoin Signed Message:\n";


double dHashesPerSec;
int64 nHPSTimerStart;

Expand Down
1 change: 1 addition & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ extern uint64 nPooledTx;
extern unsigned int nTransactionsUpdated;
extern uint64 nLastBlockTx;
extern uint64 nLastBlockSize;
extern const std::string strMessageMagic;
extern double dHashesPerSec;
extern int64 nHPSTimerStart;
extern int64 nTimeBestReceived;
Expand Down
22 changes: 22 additions & 0 deletions src/qt/addressbookpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ui_addressbookpage.h"

#include "addresstablemodel.h"
#include "bitcoingui.h"
#include "editaddressdialog.h"
#include "csvmodelwriter.h"
#include "guiutil.h"
Expand Down Expand Up @@ -156,6 +157,24 @@ void AddressBookPage::onEditAction()
dlg.exec();
}

void AddressBookPage::on_signMessage_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<BitcoinGUI *>(qoGUI);
if (gui)
gui->gotoMessagePage(addr);
}

void AddressBookPage::on_newAddressButton_clicked()
{
if(!model)
Expand Down Expand Up @@ -207,11 +226,13 @@ void AddressBookPage::selectionChanged()
// In sending tab, allow deletion of selection
ui->deleteButton->setEnabled(true);
deleteAction->setEnabled(true);
ui->signMessage->setEnabled(false);
break;
case ReceivingTab:
// Deleting receiving addresses, however, is not allowed
ui->deleteButton->setEnabled(false);
deleteAction->setEnabled(false);
ui->signMessage->setEnabled(true);
break;
}
ui->copyToClipboard->setEnabled(true);
Expand All @@ -222,6 +243,7 @@ void AddressBookPage::selectionChanged()
ui->deleteButton->setEnabled(false);
ui->showQRCode->setEnabled(false);
ui->copyToClipboard->setEnabled(false);
ui->signMessage->setEnabled(false);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/qt/addressbookpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private slots:
void on_newAddressButton_clicked();
/** Copy address of currently selected address entry to clipboard */
void on_copyToClipboard_clicked();
void on_signMessage_clicked();
void selectionChanged();
void on_showQRCode_clicked();
/** Spawn contextual menu (right mouse menu) for address book entry */
Expand Down
47 changes: 47 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "transactiontablemodel.h"
#include "addressbookpage.h"
#include "sendcoinsdialog.h"
#include "messagepage.h"
#include "optionsdialog.h"
#include "aboutdialog.h"
#include "clientmodel.h"
Expand Down Expand Up @@ -99,12 +100,17 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):

sendCoinsPage = new SendCoinsDialog(this);

messagePage = new MessagePage(this);

centralWidget = new QStackedWidget(this);
centralWidget->addWidget(overviewPage);
centralWidget->addWidget(transactionsPage);
centralWidget->addWidget(addressBookPage);
centralWidget->addWidget(receiveCoinsPage);
centralWidget->addWidget(sendCoinsPage);
#ifdef FIRST_CLASS_MESSAGING
centralWidget->addWidget(messagePage);
#endif
setCentralWidget(centralWidget);

// Create status bar
Expand Down Expand Up @@ -192,6 +198,13 @@ 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"));
#ifdef FIRST_CLASS_MESSAGING
messageAction->setCheckable(true);
#endif
tabGroup->addAction(messageAction);

connect(overviewAction, SIGNAL(triggered()), this, SLOT(show()));
connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
connect(historyAction, SIGNAL(triggered()), this, SLOT(show()));
Expand All @@ -202,6 +215,8 @@ void BitcoinGUI::createActions()
connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(show()));
connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
connect(messageAction, SIGNAL(triggered()), this, SLOT(show()));
connect(messageAction, SIGNAL(triggered()), this, SLOT(gotoMessagePage()));

quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit"), this);
quitAction->setToolTip(tr("Quit application"));
Expand Down Expand Up @@ -247,6 +262,10 @@ void BitcoinGUI::createMenuBar()

// Configure the menus
QMenu *file = appMenuBar->addMenu(tr("&File"));
#ifndef FIRST_CLASS_MESSAGING
file->addAction(messageAction);
file->addSeparator();
#endif
file->addAction(quitAction);

QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
Expand All @@ -269,6 +288,9 @@ void BitcoinGUI::createToolBars()
toolbar->addAction(receiveCoinsAction);
toolbar->addAction(historyAction);
toolbar->addAction(addressBookAction);
#ifdef FIRST_CLASS_MESSAGING
toolbar->addAction(messageAction);
#endif

QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
Expand Down Expand Up @@ -323,6 +345,7 @@ void BitcoinGUI::setWalletModel(WalletModel *walletModel)
addressBookPage->setModel(walletModel->getAddressTableModel());
receiveCoinsPage->setModel(walletModel->getAddressTableModel());
sendCoinsPage->setModel(walletModel);
messagePage->setModel(walletModel);

setEncryptionStatus(walletModel->getEncryptionStatus());
connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
Expand Down Expand Up @@ -358,6 +381,10 @@ void BitcoinGUI::createTrayIcon()
// Configuration of the tray icon (or dock icon) icon menu
trayIconMenu->addAction(openBitcoinAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(messageAction);
#ifndef FIRST_CLASS_MESSAGING
trayIconMenu->addSeparator();
#endif
trayIconMenu->addAction(receiveCoinsAction);
trayIconMenu->addAction(sendCoinsAction);
trayIconMenu->addSeparator();
Expand Down Expand Up @@ -648,6 +675,26 @@ void BitcoinGUI::gotoSendCoinsPage()
disconnect(exportAction, SIGNAL(triggered()), 0, 0);
}

void BitcoinGUI::gotoMessagePage()
{
#ifdef FIRST_CLASS_MESSAGING
messageAction->setChecked(true);
centralWidget->setCurrentWidget(messagePage);

exportAction->setEnabled(false);
disconnect(exportAction, SIGNAL(triggered()), 0, 0);
#else
messagePage->show();
messagePage->setFocus();
#endif
}

void BitcoinGUI::gotoMessagePage(QString addr)
{
gotoMessagePage();
messagePage->setAddress(addr);
}

void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
{
// Accept only URLs
Expand Down
6 changes: 6 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class TransactionView;
class OverviewPage;
class AddressBookPage;
class SendCoinsDialog;
class MessagePage;
class Notificator;

QT_BEGIN_NAMESPACE
Expand Down Expand Up @@ -62,6 +63,7 @@ class BitcoinGUI : public QMainWindow
AddressBookPage *addressBookPage;
AddressBookPage *receiveCoinsPage;
SendCoinsDialog *sendCoinsPage;
MessagePage *messagePage;

QLabel *labelEncryptionIcon;
QLabel *labelConnectionsIcon;
Expand All @@ -75,6 +77,7 @@ class BitcoinGUI : public QMainWindow
QAction *quitAction;
QAction *sendCoinsAction;
QAction *addressBookAction;
QAction *messageAction;
QAction *aboutAction;
QAction *receiveCoinsAction;
QAction *optionsAction;
Expand Down Expand Up @@ -125,6 +128,9 @@ public slots:
void askFee(qint64 nFeeRequired, bool *payFee);
void handleURL(QString strURL);

void gotoMessagePage();
void gotoMessagePage(QString);

private slots:
/** Switch to overview (home) page */
void gotoOverviewPage();
Expand Down
14 changes: 14 additions & 0 deletions src/qt/forms/addressbookpage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="signMessage">
<property name="toolTip">
<string>Sign a message to prove you own this address</string>
</property>
<property name="text">
<string>&amp;Sign Message</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/edit</normaloff>:/icons/edit</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteButton">
<property name="toolTip">
Expand Down
Loading

0 comments on commit 2bc4fd6

Please sign in to comment.