aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndymeows <[email protected]>2014-07-29 23:49:51 -0500
committerRoss Nicoll <[email protected]>2015-08-07 22:16:51 +0100
commita245210cbe01b4f3f2ba7321958768e1df3df5e3 (patch)
tree50eb6923d11f576137cd243f55042dc3d19b5f00 /src
parentMerge pull request #1227 from kaykurokawa/1.10-dev (diff)
downloaddiscoin-a245210cbe01b4f3f2ba7321958768e1df3df5e3.tar.xz
discoin-a245210cbe01b4f3f2ba7321958768e1df3df5e3.zip
Add paper wallet generator to QT wallet
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.qt.include9
-rw-r--r--src/init.cpp2
-rw-r--r--src/pubkey.cpp12
-rw-r--r--src/pubkey.h3
-rw-r--r--src/qt/bitcoin.cpp2
-rw-r--r--src/qt/bitcoin.qrc2
-rw-r--r--src/qt/bitcoingui.cpp5
-rw-r--r--src/qt/bitcoingui.h1
-rw-r--r--src/qt/bitcoinstrings.cpp3
-rw-r--r--src/qt/forms/paperwalletdialog.ui339
-rw-r--r--src/qt/res/icons/paper_wallet.pngbin0 -> 213735 bytes
-rw-r--r--src/qt/res/icons/print.pngbin0 -> 2280 bytes
-rw-r--r--src/qt/utilitydialog.cpp322
-rw-r--r--src/qt/utilitydialog.h24
-rw-r--r--src/qt/verticallabel.cpp40
-rw-r--r--src/qt/verticallabel.h21
-rw-r--r--src/qt/walletframe.cpp8
-rw-r--r--src/qt/walletframe.h2
-rw-r--r--src/qt/walletview.cpp11
-rw-r--r--src/qt/walletview.h2
20 files changed, 805 insertions, 3 deletions
diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include
index 6b7c42285..61a497c28 100644
--- a/src/Makefile.qt.include
+++ b/src/Makefile.qt.include
@@ -85,6 +85,7 @@ QT_FORMS_UI = \
qt/forms/openuridialog.ui \
qt/forms/optionsdialog.ui \
qt/forms/overviewpage.ui \
+ qt/forms/paperwalletdialog.ui \
qt/forms/receivecoinsdialog.ui \
qt/forms/receiverequestdialog.ui \
qt/forms/rpcconsole.ui \
@@ -134,6 +135,7 @@ QT_MOC_CPP = \
qt/moc_transactiontablemodel.cpp \
qt/moc_transactionview.cpp \
qt/moc_utilitydialog.cpp \
+ qt/moc_verticallabel.cpp \
qt/moc_walletframe.cpp \
qt/moc_walletmodel.cpp \
qt/moc_walletview.cpp
@@ -204,6 +206,7 @@ BITCOIN_QT_H = \
qt/transactiontablemodel.h \
qt/transactionview.h \
qt/utilitydialog.h \
+ qt/verticallabel.h \
qt/walletframe.h \
qt/walletmodel.h \
qt/walletmodeltransaction.h \
@@ -244,6 +247,8 @@ RES_ICONS = \
qt/res/icons/lock_open.png \
qt/res/icons/open.png \
qt/res/icons/overview.png \
+ qt/res/icons/paper_wallet.png \
+ qt/res/icons/print.png \
qt/res/icons/quit.png \
qt/res/icons/receive.png \
qt/res/icons/remove.png \
@@ -279,7 +284,8 @@ BITCOIN_QT_CPP = \
qt/scicon.cpp \
qt/splashscreen.cpp \
qt/trafficgraphwidget.cpp \
- qt/utilitydialog.cpp
+ qt/utilitydialog.cpp \
+ qt/verticallabel.cpp
if TARGET_WINDOWS
BITCOIN_QT_CPP += qt/winshutdownmonitor.cpp
@@ -309,6 +315,7 @@ BITCOIN_QT_CPP += \
qt/transactionrecord.cpp \
qt/transactiontablemodel.cpp \
qt/transactionview.cpp \
+ qt/verticallabel.cpp \
qt/walletframe.cpp \
qt/walletmodel.cpp \
qt/walletmodeltransaction.cpp \
diff --git a/src/init.cpp b/src/init.cpp
index 88a716a5a..c3a326841 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -448,7 +448,7 @@ std::string LicenseInfo()
"\n" +
FormatParagraph(_("Distributed under the MIT software license, see the accompanying file COPYING or <http://www.opensource.org/licenses/mit-license.php>.")) + "\n" +
"\n" +
- FormatParagraph(_("This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit <https://www.openssl.org/> and cryptographic software written by Eric Young and UPnP software written by Thomas Bernard.")) +
+ FormatParagraph(_("This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit <https://www.openssl.org/> and cryptographic software written by Eric Young and UPnP software written by Thomas Bernard. Paper wallet art provided by Anacoluthia.")) +
"\n";
}
diff --git a/src/pubkey.cpp b/src/pubkey.cpp
index bdab13760..ebd94c482 100644
--- a/src/pubkey.cpp
+++ b/src/pubkey.cpp
@@ -42,6 +42,18 @@ bool CPubKey::IsFullyValid() const {
return true;
}
+bool CPubKey::Compress() {
+ if (!IsValid())
+ return false;
+ CECKey key;
+ if (!key.SetPubKey(begin(), size()))
+ return false;
+ std::vector<unsigned char> pubkey;
+ key.GetPubKey(pubkey, true);
+ Set(pubkey.begin(), pubkey.end());
+ return true;
+}
+
bool CPubKey::Decompress() {
if (!IsValid())
return false;
diff --git a/src/pubkey.h b/src/pubkey.h
index cce9c826e..1bd7c252a 100644
--- a/src/pubkey.h
+++ b/src/pubkey.h
@@ -180,6 +180,9 @@ public:
//! Recover a public key from a compact signature.
bool RecoverCompact(const uint256& hash, const std::vector<unsigned char>& vchSig);
+ //! Turn this public key into a compressed public key.
+ bool Compress();
+
//! Turn this public key into an uncompressed public key.
bool Decompress();
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index 8740b98b7..a0133e339 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -62,7 +62,9 @@ Q_IMPORT_PLUGIN(AccessibleFactory)
#if defined(QT_QPA_PLATFORM_XCB)
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
#elif defined(QT_QPA_PLATFORM_WINDOWS)
+Q_IMPORT_PLUGIN(QMinimalIntegrationPlugin);
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
+Q_IMPORT_PLUGIN(QWindowsPrinterSupportPlugin);
#elif defined(QT_QPA_PLATFORM_COCOA)
Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
#endif
diff --git a/src/qt/bitcoin.qrc b/src/qt/bitcoin.qrc
index c899e9550..5c008866a 100644
--- a/src/qt/bitcoin.qrc
+++ b/src/qt/bitcoin.qrc
@@ -46,6 +46,8 @@
<file alias="about_qt">res/icons/about_qt.png</file>
<file alias="verify">res/icons/verify.png</file>
<file alias="warning">res/icons/warning.png</file>
+ <file alias="paper_wallet">res/icons/paper_wallet.png</file>
+ <file alias="print">res/icons/print.png</file>
</qresource>
<qresource prefix="/movies">
<file alias="spinner-000">res/movies/spinner-000.png</file>
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index efba0f5e1..87a9fbaf6 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -327,6 +327,8 @@ void BitcoinGUI::createActions()
signMessageAction->setStatusTip(tr("Sign messages with your Bitcoin addresses to prove you own them"));
verifyMessageAction = new QAction(TextColorIcon(":/icons/verify"), tr("&Verify message..."), this);
verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Bitcoin addresses"));
+ paperWalletAction = new QAction(QIcon(":/icons/print"), tr("&Print paper wallets"), this);
+ paperWalletAction->setStatusTip(tr("Print paper wallets"));
openRPCConsoleAction = new QAction(TextColorIcon(":/icons/debugwindow"), tr("&Debug window"), this);
openRPCConsoleAction->setStatusTip(tr("Open debugging and diagnostic console"));
@@ -360,6 +362,7 @@ void BitcoinGUI::createActions()
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()), walletFrame, SLOT(printPaperWallets()));
}
#endif // ENABLE_WALLET
}
@@ -382,6 +385,7 @@ void BitcoinGUI::createMenuBar()
file->addAction(backupWalletAction);
file->addAction(signMessageAction);
file->addAction(verifyMessageAction);
+ file->addAction(paperWalletAction);
file->addSeparator();
file->addAction(usedSendingAddressesAction);
file->addAction(usedReceivingAddressesAction);
@@ -506,6 +510,7 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled)
usedSendingAddressesAction->setEnabled(enabled);
usedReceivingAddressesAction->setEnabled(enabled);
openAction->setEnabled(enabled);
+ paperWalletAction->setEnabled(enabled);
}
void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle)
diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h
index 494541f00..3b7f11c04 100644
--- a/src/qt/bitcoingui.h
+++ b/src/qt/bitcoingui.h
@@ -95,6 +95,7 @@ private:
QAction *usedReceivingAddressesAction;
QAction *signMessageAction;
QAction *verifyMessageAction;
+ QAction *paperWalletAction;
QAction *aboutAction;
QAction *receiveCoinsAction;
QAction *receiveCoinsMenuAction;
diff --git a/src/qt/bitcoinstrings.cpp b/src/qt/bitcoinstrings.cpp
index 85287f9ca..78ce76b88 100644
--- a/src/qt/bitcoinstrings.cpp
+++ b/src/qt/bitcoinstrings.cpp
@@ -112,7 +112,8 @@ QT_TRANSLATE_NOOP("bitcoin-core", ""
QT_TRANSLATE_NOOP("bitcoin-core", ""
"This product includes software developed by the OpenSSL Project for use in "
"the OpenSSL Toolkit <https://www.openssl.org/> and cryptographic software "
-"written by Eric Young and UPnP software written by Thomas Bernard."),
+"written by Eric Young and UPnP software written by Thomas Bernard. "
+"Paper wallet art provided by Anacoluthia."),
QT_TRANSLATE_NOOP("bitcoin-core", ""
"To use bitcoind, or the -server option to bitcoin-qt, you must set an "
"rpcpassword in the configuration file:\n"
diff --git a/src/qt/forms/paperwalletdialog.ui b/src/qt/forms/paperwalletdialog.ui
new file mode 100644
index 000000000..60a36e2ef
--- /dev/null
+++ b/src/qt/forms/paperwalletdialog.ui
@@ -0,0 +1,339 @@
+<?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>450</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Print Your Paper Wallets</string>
+ </property>
+ <widget class="QLabel" name="privateKeyQRCode">
+ <property name="geometry">
+ <rect>
+ <x>524</x>
+ <y>159</y>
+ <width>149</width>
+ <height>149</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="scaledContents">
+ <bool>true</bool>
+ </property>
+ </widget>
+ <widget class="QLabel" name="addressQRCode">
+ <property name="geometry">
+ <rect>
+ <x>47</x>
+ <y>86</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>415</y>
+ <width>151</width>
+ <height>26</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Very New Address</string>
+ </property>
+ <property name="icon">
+ <iconset resource="../bitcoin.qrc">
+ <normaloff>:/icons/add</normaloff>:/icons/add</iconset>
+ </property>
+ </widget>
+ <widget class="QLabel" name="paperTemplate">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>10</y>
+ <width>675</width>
+ <height>362</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string notr="true"/>
+ </property>
+ <property name="pixmap">
+ <pixmap resource="../bitcoin.qrc">:/icons/paper_wallet</pixmap>
+ </property>
+ </widget>
+ <widget class="VerticalLabel" name="addressText">
+ <property name="geometry">
+ <rect>
+ <x>212</x>
+ <y>20</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>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ <property name="textInteractionFlags">
+ <set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+ </property>
+ </widget>
+ <widget class="VerticalLabel" name="privateKeyText">
+ <property name="geometry">
+ <rect>
+ <x>500</x>
+ <y>10</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>
+ <property name="scaledContents">
+ <bool>true</bool>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ <property name="textInteractionFlags">
+ <set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="printButton">
+ <property name="geometry">
+ <rect>
+ <x>420</x>
+ <y>415</y>
+ <width>111</width>
+ <height>26</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>So Print</string>
+ </property>
+ <property name="icon">
+ <iconset resource="../bitcoin.qrc">
+ <normaloff>:/icons/receiving_addresses</normaloff>:/icons/receiving_addresses</iconset>
+ </property>
+ </widget>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="geometry">
+ <rect>
+ <x>610</x>
+ <y>415</y>
+ <width>81</width>
+ <height>26</height>
+ </rect>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::NoButton</set>
+ </property>
+ <property name="centerButtons">
+ <bool>true</bool>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label">
+ <property name="geometry">
+ <rect>
+ <x>190</x>
+ <y>415</y>
+ <width>91</width>
+ <height>26</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Many Wallets?</string>
+ </property>
+ </widget>
+ <widget class="QComboBox" name="walletCount">
+ <property name="geometry">
+ <rect>
+ <x>290</x>
+ <y>415</y>
+ <width>74</width>
+ <height>26</height>
+ </rect>
+ </property>
+ <property name="editable">
+ <bool>false</bool>
+ </property>
+ <item>
+ <property name="text">
+ <string>1</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>2</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>3</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>4</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>5</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>6</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>7</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>8</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>9</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>10</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>11</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>12</string>
+ </property>
+ </item>
+ </widget>
+ <widget class="QTextEdit" name="publicKey">
+ <property name="geometry">
+ <rect>
+ <x>100</x>
+ <y>378</y>
+ <width>600</width>
+ <height>30</height>
+ </rect>
+ </property>
+ <property name="undoRedoEnabled">
+ <bool>false</bool>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ <property name="html">
+ <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
+&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
+p, li { white-space: pre-wrap; }
+&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
+&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ </property>
+ <property name="acceptRichText">
+ <bool>false</bool>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_2">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>380</y>
+ <width>91</width>
+ <height>26</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Public Key:</string>
+ </property>
+ </widget>
+ <zorder>getNewAddress</zorder>
+ <zorder>paperTemplate</zorder>
+ <zorder>addressQRCode</zorder>
+ <zorder>privateKeyQRCode</zorder>
+ <zorder>addressText</zorder>
+ <zorder>privateKeyText</zorder>
+ <zorder>printButton</zorder>
+ <zorder>buttonBox</zorder>
+ <zorder>label</zorder>
+ <zorder>walletCount</zorder>
+ <zorder>publicKey</zorder>
+ <zorder>label_2</zorder>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>VerticalLabel</class>
+ <extends>QLabel</extends>
+ <header>verticallabel.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources>
+ <include location="../bitcoin.qrc"/>
+ </resources>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>PaperWalletDialog</receiver>
+ <slot>close()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>650</x>
+ <y>408</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>357</x>
+ <y>214</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/src/qt/res/icons/paper_wallet.png b/src/qt/res/icons/paper_wallet.png
new file mode 100644
index 000000000..f67138d62
--- /dev/null
+++ b/src/qt/res/icons/paper_wallet.png
Binary files differ
diff --git a/src/qt/res/icons/print.png b/src/qt/res/icons/print.png
new file mode 100644
index 000000000..f958cdcfa
--- /dev/null
+++ b/src/qt/res/icons/print.png
Binary files differ
diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp
index 386cf31d7..be3086a50 100644
--- a/src/qt/utilitydialog.cpp
+++ b/src/qt/utilitydialog.cpp
@@ -5,7 +5,18 @@
#include "utilitydialog.h"
#include "ui_helpmessagedialog.h"
+#include "ui_paperwalletdialog.h"
+#include "bitcoinunits.h"
+
+#ifdef ENABLE_WALLET
+#include "sendcoinsdialog.h"
+#include "sendcoinsentry.h"
+#include "coincontrol.h"
+#include "coincontroldialog.h"
+#endif
+
+#include "optionsmodel.h"
#include "bitcoingui.h"
#include "clientmodel.h"
#include "guiutil.h"
@@ -13,15 +24,35 @@
#include "clientversion.h"
#include "init.h"
#include "util.h"
+#include "net.h"
#include <stdio.h>
#include <QCloseEvent>
+#include <QFont>
#include <QLabel>
#include <QRegExp>
#include <QTextTable>
#include <QTextCursor>
#include <QVBoxLayout>
+#include <QInputDialog>
+
+#ifdef USE_QRCODE
+#include <qrencode.h>
+#endif
+
+#if QT_VERSION < 0x050000
+#include <QPrinter>
+#include <QPrintDialog>
+#include <QPrintPreviewDialog>
+#else
+// Use QT5's new modular classes
+#include <QtPrintSupport/QPrinter>
+#include <QtPrintSupport/QPrintDialog>
+#include <QtPrintSupport/QPrintPreviewDialog>
+#endif
+#include <QPainter>
+#include "walletmodel.h"
/** "Help message" or "About" dialog box */
HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
@@ -137,6 +168,297 @@ void HelpMessageDialog::on_okButton_accepted()
close();
}
+/** "PaperWallet" dialog box */
+PaperWalletDialog::PaperWalletDialog(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::PaperWalletDialog)
+{
+ ui->setupUi(this);
+
+ ui->buttonBox->addButton(tr("Close"), QDialogButtonBox::RejectRole);
+
+ // Begin with a small bold monospace font for the textual version of the key and address.
+ QFont font("Monospace");
+ font.setBold(true);
+ font.setStyleHint(QFont::TypeWriter);
+ font.setPixelSize(1);
+ ui->addressText->setFont(font);
+ ui->privateKeyText->setFont(font);
+ ui->addressText->setAlignment(Qt::AlignJustify);
+ ui->privateKeyText->setAlignment(Qt::AlignJustify);
+
+ if (vNodes.size() > 0) {
+ QMessageBox::critical(this, "Warning: Network Activity Detected", tr("It is recommended to disconnect from the internet before printing paper wallets. Even though paper wallets are generated on your local computer, it is still possible to unknowingly have malware that transmits your screen to a remote location. It is also recommended to print to a local printer vs a network printer since that network traffic can be monitored. Some advanced printers also store copies of each printed document. Proceed with caution relative to the amount of value you plan to store on each address."), QMessageBox::Ok, QMessageBox::Ok);
+ }
+}
+
+void PaperWalletDialog::setModel(WalletModel *model)
+{
+ RandAddSeed();
+ this->model = model;
+ this->on_getNewAddress_clicked();
+}
+
+PaperWalletDialog::~PaperWalletDialog()
+{
+ delete ui;
+}
+
+void PaperWalletDialog::on_getNewAddress_clicked()
+{
+ // Create a new private key
+ CKey privKey;
+ privKey.MakeNewKey(true);
+
+ // Derive the public key
+ CPubKey pubkey = privKey.GetPubKey();
+
+ // Derive the public key hash
+ CBitcoinAddress pubkeyhash;
+ pubkeyhash.Set(pubkey.GetID());
+
+ // Create String versions of each
+ std::string myPrivKey = CBitcoinSecret(privKey).ToString();
+ std::string myPubKey = HexStr(pubkey.begin(), pubkey.end());
+ std::string myAddress = pubkeyhash.ToString();
+
+
+#ifdef USE_QRCODE
+ // Generate the address QR code
+ QRcode *code = QRcode_encodeString(myAddress.c_str(), 0, QR_ECLEVEL_M, QR_MODE_8, 1);
+ if (!code) {
+ ui->addressQRCode->setText(tr("Error encoding Address into QR Code."));
+ return;
+ }
+ QImage myImage = QImage(code->width, code->width, QImage::Format_ARGB32);
+ myImage.fill(QColor(0, 0, 0, 0));
+ unsigned char* p = code->data;
+ for (int y = 0; y < code->width; y++) {
+ for (int x = 0; x < code->width; x++) {
+ myImage.setPixel(x, y, ((*p & 1) ? 0xff000000 : 0x0));
+ p++;
+ }
+ }
+ QRcode_free(code);
+
+
+ // Generate the private key QR code
+ code = QRcode_encodeString(myPrivKey.c_str(), 0, QR_ECLEVEL_M, QR_MODE_8, 1);
+ if (!code) {
+ ui->privateKeyQRCode->setText(tr("Error encoding private key into QR Code."));
+ return;
+ }
+ QImage myImagePriv = QImage(code->width, code->width, QImage::Format_ARGB32);
+ myImagePriv.fill(QColor(0, 0, 0, 0));
+ p = code->data;
+ for (int y = 0; y < code->width; y++) {
+ for (int x = 0; x < code->width; x++) {
+ myImagePriv.setPixel(x, y, ((*p & 1) ? 0xff000000 : 0x0));
+ p++;
+ }
+ }
+ QRcode_free(code);
+
+ // Populate the QR Codes
+ ui->addressQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(ui->addressQRCode->width(), ui->addressQRCode->height()));
+ ui->privateKeyQRCode->setPixmap(QPixmap::fromImage(myImagePriv).scaled(ui->privateKeyQRCode->width(), ui->privateKeyQRCode->height()));
+#endif
+
+ // Populate the Texts
+ ui->addressText->setText(myAddress.c_str());
+ ui->privateKeyText->setText(tr(myPrivKey.c_str()));
+
+ ui->publicKey->setHtml(myPubKey.c_str());
+
+ // Update the fonts to fit the height of the wallet.
+ // This should only really trigger the first time since the font size persists.
+ double paperHeight = (double)ui->paperTemplate->height();
+ double maxTextWidth = paperHeight * 0.99;
+ double minTextWidth = paperHeight * 0.95;
+ int pixelSizeStep = 1;
+
+ int addressTextLength = ui->addressText->fontMetrics().boundingRect(ui->addressText->text()).width();
+ QFont font = ui->addressText->font();
+ for (int i = 0; i < PAPER_WALLET_READJUST_LIMIT; i++) {
+ if (addressTextLength < minTextWidth) {
+ font.setPixelSize(font.pixelSize() + pixelSizeStep);
+ ui->addressText->setFont(font);
+ addressTextLength = ui->addressText->fontMetrics().boundingRect(ui->addressText->text()).width();
+ } else {
+ break;
+ }
+ }
+ if (addressTextLength > maxTextWidth) {
+ font.setPixelSize(font.pixelSize() - pixelSizeStep);
+ ui->addressText->setFont(font);
+ addressTextLength = ui->addressText->fontMetrics().boundingRect(ui->addressText->text()).width();
+ }
+
+ int privateKeyTextLength = ui->privateKeyText->fontMetrics().boundingRect(ui->privateKeyText->text()).width();
+ font = ui->privateKeyText->font();
+ for (int i = 0; i < PAPER_WALLET_READJUST_LIMIT; i++) {
+ if (privateKeyTextLength < minTextWidth) {
+ font.setPixelSize(font.pixelSize() + pixelSizeStep);
+ ui->privateKeyText->setFont(font);
+ privateKeyTextLength = ui->privateKeyText->fontMetrics().boundingRect(ui->privateKeyText->text()).width();
+ } else {
+ break;
+ }
+ }
+ if (privateKeyTextLength > maxTextWidth) {
+ font.setPixelSize(font.pixelSize() - pixelSizeStep);
+ ui->privateKeyText->setFont(font);
+ privateKeyTextLength = ui->privateKeyText->fontMetrics().boundingRect(ui->privateKeyText->text()).width();
+ }
+}
+
+void PaperWalletDialog::on_printButton_clicked()
+{
+ QPrinter printer(QPrinter::HighResolution);
+ QPrintDialog* qpd = new QPrintDialog(&printer, this);
+
+ qpd->setPrintRange(QAbstractPrintDialog::AllPages);
+
+ QList<QString> recipientPubKeyHashes;
+
+ if (qpd->exec() != QDialog::Accepted) {
+ return;
+ }
+
+ // Hardcode these values
+ printer.setOrientation(QPrinter::Portrait);
+ printer.setPaperSize(QPrinter::A4);
+ printer.setFullPage(true);
+
+ QPainter painter;
+ if (!painter.begin(&printer)) { // failed to open file
+ QMessageBox::critical(this, "Printing Error", tr("failed to open file, is it writable?"), QMessageBox::Ok, QMessageBox::Ok);
+ return;
+ }
+
+ int walletCount = ui->walletCount->currentIndex() + 1;
+ int walletsPerPage = 4;
+
+ int pageHeight = printer.pageRect().height() - PAPER_WALLET_PAGE_MARGIN;
+ int walletHeight = ui->paperTemplate->height();
+ double computedWalletHeight = 0.9 * pageHeight / walletsPerPage;
+ double scale = computedWalletHeight / walletHeight;
+ double walletPadding = pageHeight * 0.05 / (walletsPerPage - 1) / scale;
+
+ QRegion walletRegion = QRegion(ui->paperTemplate->x(), ui->paperTemplate->y(), ui->paperTemplate->width(), ui->paperTemplate->height());
+ painter.scale(scale, scale);
+
+ for (int i = 0; i < walletCount; i++) {
+ QPoint point = QPoint(PAPER_WALLET_PAGE_MARGIN, (PAPER_WALLET_PAGE_MARGIN / 2) + (i % walletsPerPage) * (walletHeight + walletPadding));
+ this->render(&painter, point, walletRegion);
+ recipientPubKeyHashes.append(ui->addressText->text());
+
+ if (i % walletsPerPage == (walletsPerPage - 1)) {
+ printer.newPage();
+ }
+
+ this->on_getNewAddress_clicked();
+ }
+
+ painter.end();
+
+#ifdef ENABLE_WALLET
+ QStringList formatted;
+
+ WalletModelTransaction* tx;
+ while (true) {
+ bool ok;
+
+ // Ask for an amount to send to each paper wallet. It might be better to try to use the BitcoinAmountField, but this works fine.
+ double amountInput = QInputDialog::getDouble(this, tr("Load Paper Wallets"), tr("The paper wallet printing process has begun.<br/>Please wait for the wallets to print completely and verify that everything printed correctly.<br/>Check for misalignments, ink bleeding, smears, or anything else that could make the private keys unreadable.<br/>Now, enter the number of DOGE you wish to send to each wallet:"), 0, 0, 2147483647, 8, &ok);
+
+ if (!ok) {
+ return;
+ }
+
+
+ WalletModel::UnlockContext ctx(this->model->requestUnlock());
+ if (!ctx.isValid()) {
+ return;
+ }
+
+ QList<SendCoinsRecipient> recipients;
+ quint64 amount = (quint64)(amountInput * COIN);
+ foreach (const QString& dest, recipientPubKeyHashes) {
+ recipients.append(SendCoinsRecipient(dest, tr("Paper wallet %1").arg(dest), amount, ""));
+ formatted.append(tr("<b>%1</b> to Paper Wallet <span style='font-family: monospace;'>%2</span>").arg(QString::number(amountInput, 'f', 8), GUIUtil::HtmlEscape(dest)));
+ }
+
+ tx = new WalletModelTransaction(recipients);
+
+ WalletModel::SendCoinsReturn prepareStatus;
+ if (this->model->getOptionsModel()->getCoinControlFeatures()) // coin control enabled
+ prepareStatus = this->model->prepareTransaction(*tx, CoinControlDialog::coinControl);
+ else
+ prepareStatus = this->model->prepareTransaction(*tx);
+
+ if (prepareStatus.status == WalletModel::InvalidAddress) {
+ QMessageBox::critical(this, tr("Send Coins"), tr("The recipient address is not valid, please recheck."), QMessageBox::Ok, QMessageBox::Ok);
+ } else if (prepareStatus.status == WalletModel::InvalidAmount) {
+ QMessageBox::critical(this, tr("Send Coins"), tr("The amount to pay must be larger than 0"), QMessageBox::Ok, QMessageBox::Ok);
+ } else if (prepareStatus.status == WalletModel::AmountExceedsBalance) {
+ QMessageBox::critical(this, tr("Send Coins"), tr("The amount exceeds your balance."), QMessageBox::Ok, QMessageBox::Ok);
+ } else if (prepareStatus.status == WalletModel::AmountWithFeeExceedsBalance) {
+ QMessageBox::critical(this, tr("Send Coins"), tr("The total exceeds your balance when the transaction fee is included"), QMessageBox::Ok, QMessageBox::Ok);
+ } else if (prepareStatus.status == WalletModel::DuplicateAddress) {
+ QMessageBox::critical(this, tr("Send Coins"), tr("Duplicate address found, can only send to each address once per send operation."), QMessageBox::Ok, QMessageBox::Ok);
+ } else if (prepareStatus.status == WalletModel::TransactionCreationFailed) {
+ QMessageBox::critical(this, tr("Send Coins"), tr("Transaction creation failed!"), QMessageBox::Ok, QMessageBox::Ok);
+ } else if (prepareStatus.status == WalletModel::OK) {
+ break;
+ } else {
+ delete tx;
+ return;
+ }
+ }
+
+ // Stolen from sendcoinsdialog.cpp
+ qint64 txFee = tx->getTransactionFee();
+ QString questionString = tr("Are you sure you want to send?");
+ questionString.append("<br /><br />%1");
+
+ if (txFee > 0) {
+ // append fee string if a fee is required
+ questionString.append("<hr /><span style='color:#aa0000;'>");
+ questionString.append(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), txFee));
+ questionString.append("</span> ");
+ questionString.append(tr("added as transaction fee"));
+ }
+
+ // add total amount in all subdivision units
+ questionString.append("<hr />");
+ qint64 totalAmount = tx->getTotalTransactionAmount() + txFee;
+ QStringList alternativeUnits;
+ foreach (BitcoinUnits::Unit u, BitcoinUnits::availableUnits()) {
+ if (u != model->getOptionsModel()->getDisplayUnit())
+ alternativeUnits.append(BitcoinUnits::formatWithUnit(u, totalAmount));
+ }
+
+ questionString.append(tr("Total Amount %1 (= %2)")
+ .arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), totalAmount))
+ .arg(alternativeUnits.join(" " + tr("or") + " ")));
+
+ QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm send coins"), questionString.arg(formatted.join("<br />")), QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
+
+ if (retval != QMessageBox::Yes) {
+ delete tx;
+ return;
+ }
+
+ WalletModel::SendCoinsReturn sendStatus = this->model->sendCoins(*tx);
+
+ if (sendStatus.status == WalletModel::TransactionCommitFailed) {
+ QMessageBox::critical(this, tr("Send Coins"), tr("The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."), QMessageBox::Ok, QMessageBox::Ok);
+ }
+ delete tx;
+#endif
+ return;
+}
/** "Shutdown" window */
ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
diff --git a/src/qt/utilitydialog.h b/src/qt/utilitydialog.h
index 288b985f1..bc19f648b 100644
--- a/src/qt/utilitydialog.h
+++ b/src/qt/utilitydialog.h
@@ -7,14 +7,38 @@
#include <QDialog>
#include <QObject>
+#include "walletmodel.h"
class BitcoinGUI;
class ClientModel;
namespace Ui {
class HelpMessageDialog;
+ class PaperWalletDialog;
}
+/** "Paper Wallet" dialog box */
+class PaperWalletDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit PaperWalletDialog(QWidget *parent);
+ ~PaperWalletDialog();
+
+ void setModel(WalletModel *model);
+
+private:
+ Ui::PaperWalletDialog *ui;
+ WalletModel *model;
+ static const int PAPER_WALLET_READJUST_LIMIT = 20;
+ static const int PAPER_WALLET_PAGE_MARGIN = 50;
+
+private slots:
+ void on_getNewAddress_clicked();
+ void on_printButton_clicked();
+};
+
/** "Help message" dialog box */
class HelpMessageDialog : public QDialog
{
diff --git a/src/qt/verticallabel.cpp b/src/qt/verticallabel.cpp
new file mode 100644
index 000000000..44594a2b1
--- /dev/null
+++ b/src/qt/verticallabel.cpp
@@ -0,0 +1,40 @@
+#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());
+}
diff --git a/src/qt/verticallabel.h b/src/qt/verticallabel.h
new file mode 100644
index 000000000..dd0c65c28
--- /dev/null
+++ b/src/qt/verticallabel.h
@@ -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
diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp
index 892947bf3..7b2abf541 100644
--- a/src/qt/walletframe.cpp
+++ b/src/qt/walletframe.cpp
@@ -8,6 +8,7 @@
#include "walletview.h"
#include <cstdio>
+#include <iostream>
#include <QHBoxLayout>
#include <QLabel>
@@ -175,6 +176,13 @@ void WalletFrame::unlockWallet()
walletView->unlockWallet();
}
+void WalletFrame::printPaperWallets()
+{
+ WalletView *walletView = currentWalletView();
+ if (walletView)
+ walletView->printPaperWallets();
+}
+
void WalletFrame::usedSendingAddresses()
{
WalletView *walletView = currentWalletView();
diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h
index eea97defc..4368fb71c 100644
--- a/src/qt/walletframe.h
+++ b/src/qt/walletframe.h
@@ -71,6 +71,8 @@ public slots:
/** Ask for passphrase to unlock wallet temporarily */
void unlockWallet();
+ void printPaperWallets();
+
/** Show used sending addresses */
void usedSendingAddresses();
/** Show used receiving addresses */
diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp
index 956c8b891..7bcc980f6 100644
--- a/src/qt/walletview.cpp
+++ b/src/qt/walletview.cpp
@@ -18,6 +18,7 @@
#include "transactiontablemodel.h"
#include "transactionview.h"
#include "walletmodel.h"
+#include "utilitydialog.h"
#include "ui_interface.h"
@@ -310,3 +311,13 @@ void WalletView::showProgress(const QString &title, int nProgress)
else if (progressDialog)
progressDialog->setValue(nProgress);
}
+
+void WalletView::printPaperWallets()
+{
+ if(!walletModel)
+ return;
+
+ PaperWalletDialog dlg(this);
+ dlg.setModel(walletModel);
+ dlg.exec();
+}
diff --git a/src/qt/walletview.h b/src/qt/walletview.h
index 1840e21e9..011f1b746 100644
--- a/src/qt/walletview.h
+++ b/src/qt/walletview.h
@@ -93,6 +93,8 @@ public slots:
void changePassphrase();
/** Ask for passphrase to unlock wallet temporarily */
void unlockWallet();
+ /** Open the print paper wallets dialog **/
+ void printPaperWallets();
/** Show used sending addresses */
void usedSendingAddresses();