Adding basic paper wallet generation with a reload button

This commit is contained in:
Andymeows 2014-07-30 23:35:07 -05:00 committed by Andy Mornes
parent 6cf01f410f
commit 0829467f76
8 changed files with 344 additions and 1 deletions

View File

@ -95,6 +95,7 @@ QT_FORMS_UI = \
forms/openuridialog.ui \
forms/optionsdialog.ui \
forms/overviewpage.ui \
forms/paperwalletdialog.ui \
forms/receivecoinsdialog.ui \
forms/receiverequestdialog.ui \
forms/rpcconsole.ui \
@ -144,6 +145,7 @@ QT_MOC_CPP = \
moc_transactiontablemodel.cpp \
moc_transactionview.cpp \
moc_utilitydialog.cpp \
moc_verticallabel.cpp \
moc_walletframe.cpp \
moc_walletmodel.cpp \
moc_walletview.cpp
@ -209,6 +211,7 @@ BITCOIN_QT_H = \
transactiontablemodel.h \
transactionview.h \
utilitydialog.h \
verticallabel.h \
walletframe.h \
walletmodel.h \
walletmodeltransaction.h \
@ -287,7 +290,8 @@ BITCOIN_QT_CPP = \
rpcconsole.cpp \
splashscreen.cpp \
trafficgraphwidget.cpp \
utilitydialog.cpp \
utilitydialog.cpp
verticallabel.cpp \
winshutdownmonitor.cpp
if ENABLE_WALLET
@ -314,6 +318,7 @@ BITCOIN_QT_CPP += \
transactionrecord.cpp \
transactiontablemodel.cpp \
transactionview.cpp \
verticallabel.cpp \
walletframe.cpp \
walletmodel.cpp \
walletmodeltransaction.cpp \

View File

@ -311,6 +311,8 @@ void BitcoinGUI::createActions(bool fIsTestnet)
signMessageAction->setStatusTip(tr("Sign messages with your Dogecoin addresses to prove you own them"));
verifyMessageAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Verify message..."), this);
verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Dogecoin addresses"));
paperWalletAction = new QAction(QIcon(":/icons/transaction_0"), tr("&Print paper wallets"), this);
paperWalletAction->setStatusTip(tr("Print paper wallets"));
openRPCConsoleAction = new QAction(QIcon(":/icons/debugwindow"), tr("&Debug window"), this);
openRPCConsoleAction->setStatusTip(tr("Open debugging and diagnostic console"));
@ -343,6 +345,7 @@ void BitcoinGUI::createActions(bool fIsTestnet)
connect(usedSendingAddressesAction, SIGNAL(triggered()), walletFrame, SLOT(usedSendingAddresses()));
connect(usedReceivingAddressesAction, SIGNAL(triggered()), walletFrame, SLOT(usedReceivingAddresses()));
connect(openAction, SIGNAL(triggered()), this, SLOT(openClicked()));
connect(paperWalletAction, SIGNAL(triggered()), this, SLOT(paperWalletClicked()));
}
#endif
}
@ -365,6 +368,7 @@ void BitcoinGUI::createMenuBar()
file->addAction(backupWalletAction);
file->addAction(signMessageAction);
file->addAction(verifyMessageAction);
file->addAction(paperWalletAction);
file->addSeparator();
file->addAction(usedSendingAddressesAction);
file->addAction(usedReceivingAddressesAction);
@ -566,6 +570,16 @@ void BitcoinGUI::aboutClicked()
dlg.exec();
}
void BitcoinGUI::paperWalletClicked()
{
if(!clientModel)
return;
PaperWalletDialog dlg(this);
dlg.setModel(clientModel);
dlg.exec();
}
void BitcoinGUI::showHelpMessageClicked()
{
HelpMessageDialog *help = new HelpMessageDialog(this);
@ -616,6 +630,7 @@ void BitcoinGUI::gotoVerifyMessageTab(QString addr)
{
if (walletFrame) walletFrame->gotoVerifyMessageTab(addr);
}
#endif
void BitcoinGUI::setNumConnections(int count)

View File

@ -83,6 +83,7 @@ private:
QAction *usedReceivingAddressesAction;
QAction *signMessageAction;
QAction *verifyMessageAction;
QAction *paperWalletAction;
QAction *aboutAction;
QAction *receiveCoinsAction;
QAction *optionsAction;
@ -177,6 +178,7 @@ private slots:
void optionsClicked();
/** Show about dialog */
void aboutClicked();
void paperWalletClicked();
/** Show help message dialog */
void showHelpMessageClicked();
#ifndef Q_OS_MAC

View File

@ -0,0 +1,149 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PaperWalletDialog</class>
<widget class="QDialog" name="PaperWalletDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>716</width>
<height>445</height>
</rect>
</property>
<property name="windowTitle">
<string>Print Your Paper Wallets</string>
</property>
<widget class="QRImageWidget" name="privateKey">
<property name="geometry">
<rect>
<x>524</x>
<y>219</y>
<width>149</width>
<height>149</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
<widget class="QRImageWidget" name="publicKey">
<property name="geometry">
<rect>
<x>47</x>
<y>146</y>
<width>120</width>
<height>120</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="getNewAddress">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>151</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Very New Address</string>
</property>
<property name="icon">
<iconset resource="../../../../../Dogecoin/dogecoin/src/qt/dogecoin.qrc">
<normaloff>:/icons/add</normaloff>:/icons/add</iconset>
</property>
</widget>
<widget class="QRImageWidget" name="paperTemplate">
<property name="geometry">
<rect>
<x>20</x>
<y>70</y>
<width>675</width>
<height>362</height>
</rect>
</property>
<property name="text">
<string notr="true"/>
</property>
<property name="pixmap">
<pixmap resource="../../../../../Dogecoin/dogecoin/src/qt/dogecoin.qrc">:/images/paper_wallet</pixmap>
</property>
</widget>
<widget class="VerticalLabel" name="publicKeyText">
<property name="geometry">
<rect>
<x>212</x>
<y>80</y>
<width>31</width>
<height>341</height>
</rect>
</property>
<property name="font">
<font>
<family>Monospace</family>
<pointsize>12</pointsize>
<weight>75</weight>
<italic>false</italic>
<bold>true</bold>
</font>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="VerticalLabel" name="privateKeyText">
<property name="geometry">
<rect>
<x>500</x>
<y>70</y>
<width>31</width>
<height>361</height>
</rect>
</property>
<property name="font">
<font>
<family>Monospace</family>
<pointsize>8</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="text">
<string/>
</property>
</widget>
<zorder>getNewAddress</zorder>
<zorder>paperTemplate</zorder>
<zorder>publicKey</zorder>
<zorder>privateKey</zorder>
<zorder>publicKeyText</zorder>
<zorder>privateKeyText</zorder>
</widget>
<customwidgets>
<customwidget>
<class>QRImageWidget</class>
<extends>QLabel</extends>
<header>receiverequestdialog.h</header>
</customwidget>
<customwidget>
<class>VerticalLabel</class>
<extends>QLabel</extends>
<header>verticallabel.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../../../../../Dogecoin/dogecoin/src/qt/dogecoin.qrc"/>
<include location="../../../../../.designer/dogecoin.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -5,6 +5,7 @@
#include "utilitydialog.h"
#include "ui_aboutdialog.h"
#include "ui_paperwalletdialog.h"
#include "ui_helpmessagedialog.h"
#include "bitcoingui.h"
@ -18,6 +19,17 @@
#include <QLabel>
#include <QVBoxLayout>
#ifdef USE_QRCODE
#include <qrencode.h>
#endif
#include <QPrinter>
#include <QPainter>
#include <QPrintPreviewDialog>
#include <QPrintDialog>
#include <QGraphicsScene>
/** "About" dialog box */
AboutDialog::AboutDialog(QWidget *parent) :
QDialog(parent),
@ -56,6 +68,85 @@ void AboutDialog::on_buttonBox_accepted()
close();
}
/** "PaperWallet" dialog box */
PaperWalletDialog::PaperWalletDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::PaperWalletDialog)
{
ui->setupUi(this);
}
void PaperWalletDialog::setModel(ClientModel *model)
{
RandAddSeed();
this->on_getNewAddress_clicked();
}
PaperWalletDialog::~PaperWalletDialog()
{
delete ui;
}
void PaperWalletDialog::on_getNewAddress_clicked()
{
CKey newKey;
newKey.MakeNewKey(false);
CPubKey pub = newKey.GetPubKey();
CBitcoinAddress myaddr;
myaddr.Set(pub.GetID());
string myPubKey;
string myPrivKey;
myPubKey = myaddr.ToString();
myPrivKey = CBitcoinSecret(newKey).ToString();
QRcode *code = QRcode_encodeString(myPubKey.c_str(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);
if (!code)
{
ui->publicKey->setText(tr("Error encoding URI into QR Code."));
return;
}
QImage myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
myImage.fill(0xffffff);
unsigned char *p = code->data;
for (int y = 0; y < code->width; y++)
{
for (int x = 0; x < code->width; x++)
{
myImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
p++;
}
}
QRcode_free(code);
ui->publicKey->setPixmap(QPixmap::fromImage(myImage).scaled(125, 125));
ui->publicKeyText->setText(tr(myPubKey.c_str()));
QRcode *codePriv = QRcode_encodeString(myPrivKey.c_str(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);
if (!codePriv)
{
ui->privateKey->setText(tr("Error encoding URI into QR Code."));
return;
}
QImage myImagePriv = QImage(codePriv->width + 8, codePriv->width + 8, QImage::Format_RGB32);
myImagePriv.fill(0xffffff);
unsigned char *p2 = codePriv->data;
for (int y2 = 0; y2 < codePriv->width; y2++)
{
for (int x2 = 0; x2 < codePriv->width; x2++)
{
myImagePriv.setPixel(x2 + 4, y2 + 4, ((*p2 & 1) ? 0x0 : 0xffffff));
p2++;
}
}
QRcode_free(codePriv);
ui->privateKey->setPixmap(QPixmap::fromImage(myImagePriv).scaled(140, 140));
ui->privateKeyText->setText(tr(myPrivKey.c_str()));
}
/** "Help message" dialog box */
HelpMessageDialog::HelpMessageDialog(QWidget *parent) :
QDialog(parent),

View File

@ -13,6 +13,7 @@ class ClientModel;
namespace Ui {
class AboutDialog;
class PaperWalletDialog;
class HelpMessageDialog;
}
@ -34,6 +35,24 @@ private slots:
void on_buttonBox_accepted();
};
/** "Paper Wallet" dialog box */
class PaperWalletDialog : public QDialog
{
Q_OBJECT
public:
explicit PaperWalletDialog(QWidget *parent);
~PaperWalletDialog();
void setModel(ClientModel *model);
private:
Ui::PaperWalletDialog *ui;
private slots:
void on_getNewAddress_clicked();
};
/** "Help message" dialog box */
class HelpMessageDialog : public QDialog
{

41
src/qt/verticallabel.cpp Normal file
View File

@ -0,0 +1,41 @@
#include "verticallabel.h"
#include <QPainter>
VerticalLabel::VerticalLabel(QWidget *parent)
: QLabel(parent)
{
}
VerticalLabel::VerticalLabel(const QString &text, QWidget *parent)
: QLabel(text, parent)
{
}
VerticalLabel::~VerticalLabel()
{
}
void VerticalLabel::paintEvent(QPaintEvent*)
{
QPainter painter(this);
painter.setPen(Qt::black);
painter.setBrush(Qt::Dense1Pattern);
painter.translate(width()/2,height());
painter.rotate(270);
painter.drawText(0,0, text());
}
QSize VerticalLabel::minimumSizeHint() const
{
QSize s = QLabel::minimumSizeHint();
return QSize(s.height(), s.width());
}
QSize VerticalLabel::sizeHint() const
{
QSize s = QLabel::sizeHint();
return QSize(s.height(), s.width());
}

21
src/qt/verticallabel.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef VERTICALLABEL_H
#define VERTICALLABEL_H
#include <QLabel>
class VerticalLabel : public QLabel
{
Q_OBJECT
public:
explicit VerticalLabel(QWidget *parent=0);
explicit VerticalLabel(const QString &text, QWidget *parent=0);
~VerticalLabel();
protected:
void paintEvent(QPaintEvent*);
QSize sizeHint() const ;
QSize minimumSizeHint() const;
};
#endif // VERTICALLABEL_H