Skip to content

Commit 2bc4fd6

Browse files
luke-jrlaanwj
authored andcommitted
Bitcoin-Qt signmessage GUI (pull request bitcoin#582)
1 parent 70f5535 commit 2bc4fd6

12 files changed

+418
-2
lines changed

bitcoin-qt.pro

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ contains(USE_SSL, 1) {
6868
DEFINES += USE_SSL
6969
}
7070

71+
# use: qmake "FIRST_CLASS_MESSAGING=1"
72+
contains(FIRST_CLASS_MESSAGING, 1) {
73+
message(Building with first-class messaging)
74+
DEFINES += FIRST_CLASS_MESSAGING
75+
}
76+
7177
contains(BITCOIN_NEED_QT_PLUGINS, 1) {
7278
DEFINES += BITCOIN_NEED_QT_PLUGINS
7379
QTPLUGIN += qcncodecs qjpcodecs qtwcodecs qkrcodecs
@@ -91,6 +97,7 @@ HEADERS += src/qt/bitcoingui.h \
9197
src/qt/optionsdialog.h \
9298
src/qt/sendcoinsdialog.h \
9399
src/qt/addressbookpage.h \
100+
src/qt/messagepage.h \
94101
src/qt/aboutdialog.h \
95102
src/qt/editaddressdialog.h \
96103
src/qt/bitcoinaddressvalidator.h \
@@ -154,6 +161,7 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
154161
src/qt/optionsdialog.cpp \
155162
src/qt/sendcoinsdialog.cpp \
156163
src/qt/addressbookpage.cpp \
164+
src/qt/messagepage.cpp \
157165
src/qt/aboutdialog.cpp \
158166
src/qt/editaddressdialog.cpp \
159167
src/qt/bitcoinaddressvalidator.cpp \
@@ -204,6 +212,7 @@ RESOURCES += \
204212
FORMS += \
205213
src/qt/forms/sendcoinsdialog.ui \
206214
src/qt/forms/addressbookpage.ui \
215+
src/qt/forms/messagepage.ui \
207216
src/qt/forms/aboutdialog.ui \
208217
src/qt/forms/editaddressdialog.ui \
209218
src/qt/forms/transactiondescdialog.ui \

src/bitcoinrpc.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,6 @@ Value sendtoaddress(const Array& params, bool fHelp)
589589
return wtx.GetHash().GetHex();
590590
}
591591

592-
static const string strMessageMagic = "Bitcoin Signed Message:\n";
593-
594592
Value signmessage(const Array& params, bool fHelp)
595593
{
596594
if (fHelp || params.size() != 2)

src/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ map<uint256, CDataStream*> mapOrphanTransactions;
5353
multimap<uint256, CDataStream*> mapOrphanTransactionsByPrev;
5454

5555

56+
const string strMessageMagic = "Bitcoin Signed Message:\n";
57+
58+
5659
double dHashesPerSec;
5760
int64 nHPSTimerStart;
5861

src/main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ extern uint64 nPooledTx;
7272
extern unsigned int nTransactionsUpdated;
7373
extern uint64 nLastBlockTx;
7474
extern uint64 nLastBlockSize;
75+
extern const std::string strMessageMagic;
7576
extern double dHashesPerSec;
7677
extern int64 nHPSTimerStart;
7778
extern int64 nTimeBestReceived;

src/qt/addressbookpage.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "ui_addressbookpage.h"
33

44
#include "addresstablemodel.h"
5+
#include "bitcoingui.h"
56
#include "editaddressdialog.h"
67
#include "csvmodelwriter.h"
78
#include "guiutil.h"
@@ -156,6 +157,24 @@ void AddressBookPage::onEditAction()
156157
dlg.exec();
157158
}
158159

160+
void AddressBookPage::on_signMessage_clicked()
161+
{
162+
QTableView *table = ui->tableView;
163+
QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address);
164+
QString addr;
165+
166+
foreach (QModelIndex index, indexes)
167+
{
168+
QVariant address = index.data();
169+
addr = address.toString();
170+
}
171+
172+
QObject *qoGUI = parent()->parent();
173+
BitcoinGUI *gui = qobject_cast<BitcoinGUI *>(qoGUI);
174+
if (gui)
175+
gui->gotoMessagePage(addr);
176+
}
177+
159178
void AddressBookPage::on_newAddressButton_clicked()
160179
{
161180
if(!model)
@@ -207,11 +226,13 @@ void AddressBookPage::selectionChanged()
207226
// In sending tab, allow deletion of selection
208227
ui->deleteButton->setEnabled(true);
209228
deleteAction->setEnabled(true);
229+
ui->signMessage->setEnabled(false);
210230
break;
211231
case ReceivingTab:
212232
// Deleting receiving addresses, however, is not allowed
213233
ui->deleteButton->setEnabled(false);
214234
deleteAction->setEnabled(false);
235+
ui->signMessage->setEnabled(true);
215236
break;
216237
}
217238
ui->copyToClipboard->setEnabled(true);
@@ -222,6 +243,7 @@ void AddressBookPage::selectionChanged()
222243
ui->deleteButton->setEnabled(false);
223244
ui->showQRCode->setEnabled(false);
224245
ui->copyToClipboard->setEnabled(false);
246+
ui->signMessage->setEnabled(false);
225247
}
226248
}
227249

src/qt/addressbookpage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ private slots:
5757
void on_newAddressButton_clicked();
5858
/** Copy address of currently selected address entry to clipboard */
5959
void on_copyToClipboard_clicked();
60+
void on_signMessage_clicked();
6061
void selectionChanged();
6162
void on_showQRCode_clicked();
6263
/** Spawn contextual menu (right mouse menu) for address book entry */

src/qt/bitcoingui.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "transactiontablemodel.h"
99
#include "addressbookpage.h"
1010
#include "sendcoinsdialog.h"
11+
#include "messagepage.h"
1112
#include "optionsdialog.h"
1213
#include "aboutdialog.h"
1314
#include "clientmodel.h"
@@ -99,12 +100,17 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
99100

100101
sendCoinsPage = new SendCoinsDialog(this);
101102

103+
messagePage = new MessagePage(this);
104+
102105
centralWidget = new QStackedWidget(this);
103106
centralWidget->addWidget(overviewPage);
104107
centralWidget->addWidget(transactionsPage);
105108
centralWidget->addWidget(addressBookPage);
106109
centralWidget->addWidget(receiveCoinsPage);
107110
centralWidget->addWidget(sendCoinsPage);
111+
#ifdef FIRST_CLASS_MESSAGING
112+
centralWidget->addWidget(messagePage);
113+
#endif
108114
setCentralWidget(centralWidget);
109115

110116
// Create status bar
@@ -192,6 +198,13 @@ void BitcoinGUI::createActions()
192198
sendCoinsAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_2));
193199
tabGroup->addAction(sendCoinsAction);
194200

201+
messageAction = new QAction(QIcon(":/icons/edit"), tr("Sign &message"), this);
202+
messageAction->setToolTip(tr("Prove you control an address"));
203+
#ifdef FIRST_CLASS_MESSAGING
204+
messageAction->setCheckable(true);
205+
#endif
206+
tabGroup->addAction(messageAction);
207+
195208
connect(overviewAction, SIGNAL(triggered()), this, SLOT(show()));
196209
connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
197210
connect(historyAction, SIGNAL(triggered()), this, SLOT(show()));
@@ -202,6 +215,8 @@ void BitcoinGUI::createActions()
202215
connect(receiveCoinsAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
203216
connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(show()));
204217
connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(gotoSendCoinsPage()));
218+
connect(messageAction, SIGNAL(triggered()), this, SLOT(show()));
219+
connect(messageAction, SIGNAL(triggered()), this, SLOT(gotoMessagePage()));
205220

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

248263
// Configure the menus
249264
QMenu *file = appMenuBar->addMenu(tr("&File"));
265+
#ifndef FIRST_CLASS_MESSAGING
266+
file->addAction(messageAction);
267+
file->addSeparator();
268+
#endif
250269
file->addAction(quitAction);
251270

252271
QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
@@ -269,6 +288,9 @@ void BitcoinGUI::createToolBars()
269288
toolbar->addAction(receiveCoinsAction);
270289
toolbar->addAction(historyAction);
271290
toolbar->addAction(addressBookAction);
291+
#ifdef FIRST_CLASS_MESSAGING
292+
toolbar->addAction(messageAction);
293+
#endif
272294

273295
QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
274296
toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
@@ -323,6 +345,7 @@ void BitcoinGUI::setWalletModel(WalletModel *walletModel)
323345
addressBookPage->setModel(walletModel->getAddressTableModel());
324346
receiveCoinsPage->setModel(walletModel->getAddressTableModel());
325347
sendCoinsPage->setModel(walletModel);
348+
messagePage->setModel(walletModel);
326349

327350
setEncryptionStatus(walletModel->getEncryptionStatus());
328351
connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
@@ -358,6 +381,10 @@ void BitcoinGUI::createTrayIcon()
358381
// Configuration of the tray icon (or dock icon) icon menu
359382
trayIconMenu->addAction(openBitcoinAction);
360383
trayIconMenu->addSeparator();
384+
trayIconMenu->addAction(messageAction);
385+
#ifndef FIRST_CLASS_MESSAGING
386+
trayIconMenu->addSeparator();
387+
#endif
361388
trayIconMenu->addAction(receiveCoinsAction);
362389
trayIconMenu->addAction(sendCoinsAction);
363390
trayIconMenu->addSeparator();
@@ -648,6 +675,26 @@ void BitcoinGUI::gotoSendCoinsPage()
648675
disconnect(exportAction, SIGNAL(triggered()), 0, 0);
649676
}
650677

678+
void BitcoinGUI::gotoMessagePage()
679+
{
680+
#ifdef FIRST_CLASS_MESSAGING
681+
messageAction->setChecked(true);
682+
centralWidget->setCurrentWidget(messagePage);
683+
684+
exportAction->setEnabled(false);
685+
disconnect(exportAction, SIGNAL(triggered()), 0, 0);
686+
#else
687+
messagePage->show();
688+
messagePage->setFocus();
689+
#endif
690+
}
691+
692+
void BitcoinGUI::gotoMessagePage(QString addr)
693+
{
694+
gotoMessagePage();
695+
messagePage->setAddress(addr);
696+
}
697+
651698
void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
652699
{
653700
// Accept only URLs

src/qt/bitcoingui.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class TransactionView;
1111
class OverviewPage;
1212
class AddressBookPage;
1313
class SendCoinsDialog;
14+
class MessagePage;
1415
class Notificator;
1516

1617
QT_BEGIN_NAMESPACE
@@ -62,6 +63,7 @@ class BitcoinGUI : public QMainWindow
6263
AddressBookPage *addressBookPage;
6364
AddressBookPage *receiveCoinsPage;
6465
SendCoinsDialog *sendCoinsPage;
66+
MessagePage *messagePage;
6567

6668
QLabel *labelEncryptionIcon;
6769
QLabel *labelConnectionsIcon;
@@ -75,6 +77,7 @@ class BitcoinGUI : public QMainWindow
7577
QAction *quitAction;
7678
QAction *sendCoinsAction;
7779
QAction *addressBookAction;
80+
QAction *messageAction;
7881
QAction *aboutAction;
7982
QAction *receiveCoinsAction;
8083
QAction *optionsAction;
@@ -125,6 +128,9 @@ public slots:
125128
void askFee(qint64 nFeeRequired, bool *payFee);
126129
void handleURL(QString strURL);
127130

131+
void gotoMessagePage();
132+
void gotoMessagePage(QString);
133+
128134
private slots:
129135
/** Switch to overview (home) page */
130136
void gotoOverviewPage();

src/qt/forms/addressbookpage.ui

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@
9090
</property>
9191
</widget>
9292
</item>
93+
<item>
94+
<widget class="QPushButton" name="signMessage">
95+
<property name="toolTip">
96+
<string>Sign a message to prove you own this address</string>
97+
</property>
98+
<property name="text">
99+
<string>&amp;Sign Message</string>
100+
</property>
101+
<property name="icon">
102+
<iconset resource="../bitcoin.qrc">
103+
<normaloff>:/icons/edit</normaloff>:/icons/edit</iconset>
104+
</property>
105+
</widget>
106+
</item>
93107
<item>
94108
<widget class="QPushButton" name="deleteButton">
95109
<property name="toolTip">

0 commit comments

Comments
 (0)