diff --git a/build-aux/m4/bitcoin_qt.m4 b/build-aux/m4/bitcoin_qt.m4 index 9813ae144..3136cbe90 100644 --- a/build-aux/m4/bitcoin_qt.m4 +++ b/build-aux/m4/bitcoin_qt.m4 @@ -152,8 +152,9 @@ AC_DEFUN([BITCOIN_QT_CONFIGURE],[ Q_IMPORT_PLUGIN(qjpcodecs) Q_IMPORT_PLUGIN(qtwcodecs) Q_IMPORT_PLUGIN(qkrcodecs) - Q_IMPORT_PLUGIN(AccessibleFactory)], - [-lqcncodecs -lqjpcodecs -lqtwcodecs -lqkrcodecs -lqtaccessiblewidgets]) + Q_IMPORT_PLUGIN(AccessibleFactory) + Q_IMPORT_PLUGIN(QWindowsPrinterSupportPlugin)], + [-lqcncodecs -lqjpcodecs -lqtwcodecs -lqkrcodecs -lqtaccessiblewidgets -lwindowsprintersupport]) fi fi CPPFLAGS=$TEMP_CPPFLAGS diff --git a/contrib/bitcoin-qt.pro b/contrib/bitcoin-qt.pro index b8133bf78..9915f3b3c 100644 --- a/contrib/bitcoin-qt.pro +++ b/contrib/bitcoin-qt.pro @@ -19,3 +19,7 @@ FORMS += \ RESOURCES += \ ../src/qt/bitcoin.qrc + + +QT += \ + printsupport diff --git a/depends/packages/fontconfig.mk b/depends/packages/fontconfig.mk index fb97e0b9e..12695db4b 100644 --- a/depends/packages/fontconfig.mk +++ b/depends/packages/fontconfig.mk @@ -13,7 +13,13 @@ define $(package)_config_cmds $($(package)_autoconf) endef +# 2.12.1 uses CHAR_WIDTH which is reserved and clashes with some glibc versions, but newer versions of fontconfig +# have broken makefiles which needlessly attempt to re-generate headers with gperf. +# Instead, change all uses of CHAR_WIDTH, and disable the rule that forces header re-generation. +# This can be removed once the upstream build is fixed. define $(package)_build_cmds + sed -i 's/CHAR_WIDTH/CHARWIDTH/g' fontconfig/fontconfig.h src/fcobjshash.gperf src/fcobjs.h src/fcobjshash.h && \ + sed -i 's/fcobjshash.h: fcobjshash.gperf/fcobjshash.h:/' src/Makefile && \ $(MAKE) endef diff --git a/depends/packages/qt.mk b/depends/packages/qt.mk index 045ec4862..2b0afc550 100644 --- a/depends/packages/qt.mk +++ b/depends/packages/qt.mk @@ -78,8 +78,6 @@ $(package)_config_opts += -reduce-exports $(package)_config_opts += -static $(package)_config_opts += -silent $(package)_config_opts += -v -$(package)_config_opts += -no-feature-printer -$(package)_config_opts += -no-feature-printdialog ifneq ($(build_os),darwin) $(package)_config_opts_darwin = -xplatform macx-clang-linux diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 832c5b932..7736cc04b 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -105,6 +105,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/debugwindow.ui \ @@ -156,6 +157,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 @@ -228,6 +230,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 \ @@ -275,6 +278,8 @@ RES_ICONS = \ qt/res/icons/network_disabled.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 \ @@ -313,7 +318,8 @@ BITCOIN_QT_BASE_CPP = \ qt/rpcconsole.cpp \ qt/splashscreen.cpp \ qt/trafficgraphwidget.cpp \ - qt/utilitydialog.cpp + qt/utilitydialog.cpp \ + qt/verticallabel.cpp BITCOIN_QT_WINDOWS_CPP = qt/winshutdownmonitor.cpp @@ -340,6 +346,7 @@ BITCOIN_QT_WALLET_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 8c0847a76..0b7777fa0 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -525,7 +525,7 @@ std::string LicenseInfo() _("This is experimental software.") + "\n" + strprintf(_("Distributed under the MIT software license, see the accompanying file %s or %s"), "COPYING", "") + "\n" + "\n" + - strprintf(_("This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit %s and cryptographic software written by Eric Young and UPnP software written by Thomas Bernard."), "") + + strprintf(_("This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit %s 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 e57fa238c..b0407cbee 100644 --- a/src/pubkey.cpp +++ b/src/pubkey.cpp @@ -211,6 +211,19 @@ bool CPubKey::IsFullyValid() const { return secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, &(*this)[0], size()); } +bool CPubKey::Compress() { + if (!IsValid()) + return false; + secp256k1_pubkey pubkey; + if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, &(*this)[0], size())) + return false; + unsigned char pub[33]; + size_t publen = 33; + secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, SECP256K1_EC_COMPRESSED); + Set(pub, pub + publen); + return true; +} + bool CPubKey::Decompress() { if (!IsValid()) return false; diff --git a/src/pubkey.h b/src/pubkey.h index dbf0e23f2..490e8072a 100644 --- a/src/pubkey.h +++ b/src/pubkey.h @@ -183,6 +183,9 @@ public: //! Recover a public key from a compact signature. bool RecoverCompact(const uint256& hash, const std::vector& 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 6c9c0960b..b16a55f4d 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -67,7 +67,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 1976a4ef7..4ba52b03e 100644 --- a/src/qt/bitcoin.qrc +++ b/src/qt/bitcoin.qrc @@ -54,6 +54,8 @@ res/icons/hd_disabled.png res/icons/network_disabled.png res/icons/wallet_bgcoin.png + res/icons/paper_wallet.png + res/icons/print.png res/movies/spinner-000.png diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index dec8c13cd..670e4f2c6 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -374,6 +374,8 @@ void BitcoinGUI::createActions() signMessageAction->setStatusTip(tr("Sign messages with your Dogecoin addresses to prove you own them")); verifyMessageAction = new QAction(platformStyle->TextColorIcon(":/icons/verify"), tr("&Verify message..."), this); verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Dogecoin addresses")); + paperWalletAction = new QAction(QIcon(":/icons/print"), tr("&Print paper wallets"), this); + paperWalletAction->setStatusTip(tr("Print paper wallets")); openRPCConsoleAction = new QAction(platformStyle->TextColorIcon(":/icons/debugwindow"), tr("&Debug window"), this); openRPCConsoleAction->setStatusTip(tr("Open debugging and diagnostic console")); @@ -413,6 +415,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 @@ -438,6 +441,7 @@ void BitcoinGUI::createMenuBar() file->addAction(backupWalletAction); file->addAction(signMessageAction); file->addAction(verifyMessageAction); + file->addAction(paperWalletAction); file->addSeparator(); file->addAction(usedSendingAddressesAction); file->addAction(usedReceivingAddressesAction); @@ -583,6 +587,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 62d419d3e..6b0cc65c5 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -101,6 +101,7 @@ private: QAction *usedReceivingAddressesAction; QAction *signMessageAction; QAction *verifyMessageAction; + QAction *paperWalletAction; QAction *aboutAction; QAction *receiveCoinsAction; QAction *receiveCoinsMenuAction; 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 @@ + + + PaperWalletDialog + + + + 0 + 0 + 716 + 450 + + + + Print Your Paper Wallets + + + + + 524 + 159 + 149 + 149 + + + + + + + true + + + + + + 47 + 86 + 120 + 120 + + + + + + + true + + + + + + 20 + 415 + 151 + 26 + + + + Very New Address + + + + :/icons/add:/icons/add + + + + + + 20 + 10 + 675 + 362 + + + + + + + :/icons/paper_wallet + + + + + + 212 + 20 + 31 + 341 + + + + + Monospace + 12 + 75 + false + true + + + + + + + Qt::AlignCenter + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + 500 + 10 + 31 + 361 + + + + + Monospace + 8 + 50 + false + false + + + + + + + true + + + Qt::AlignCenter + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + 420 + 415 + 111 + 26 + + + + So Print + + + + :/icons/receiving_addresses:/icons/receiving_addresses + + + + + + 610 + 415 + 81 + 26 + + + + QDialogButtonBox::NoButton + + + true + + + + + + 190 + 415 + 91 + 26 + + + + Many Wallets? + + + + + + 290 + 415 + 74 + 26 + + + + false + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + 6 + + + + + 7 + + + + + 8 + + + + + 9 + + + + + 10 + + + + + 11 + + + + + 12 + + + + + + + 100 + 378 + 600 + 30 + + + + false + + + true + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + false + + + + + + 20 + 380 + 91 + 26 + + + + Public Key: + + + getNewAddress + paperTemplate + addressQRCode + privateKeyQRCode + addressText + privateKeyText + printButton + buttonBox + label + walletCount + publicKey + label_2 + + + + VerticalLabel + QLabel +
verticallabel.h
+
+
+ + + + + + buttonBox + rejected() + PaperWalletDialog + close() + + + 650 + 408 + + + 357 + 214 + + + + +
diff --git a/src/qt/locale/bitcoin_en.ts b/src/qt/locale/bitcoin_en.ts index 5b53da23d..8ed8412f2 100644 --- a/src/qt/locale/bitcoin_en.ts +++ b/src/qt/locale/bitcoin_en.ts @@ -448,6 +448,16 @@ Verify messages to ensure they were signed with specified Dogecoin addresses Verify messages to ensure they were signed with specified Dogecoin addresses + + + &Print paper wallets + + + + + Print paper wallets + + &Debug window @@ -499,12 +509,12 @@ - + &File &File - + &Settings &Settings @@ -519,7 +529,7 @@ Tabs toolbar - + %1 client @@ -718,7 +728,7 @@ Wallet is <b>encrypted</b> and currently <b>locked</b> - + A fatal error occurred. Dogecoin can no longer continue safely and will quit. @@ -1012,7 +1022,7 @@ HelpMessageDialog - + version version @@ -1626,6 +1636,219 @@ + + PaperWalletDialog + + + Print Your Paper Wallets + + + + + Very New Address + + + + + So Print + + + + + Many Wallets? + + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + 6 + + + + + 7 + + + + + 8 + + + + + 9 + + + + + 10 + + + + + 11 + + + + + 12 + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + + + Public Key: + + + + + Close + + + + + 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. + + + + + Error encoding Address into QR Code. + + + + + Error encoding private key into QR Code. + + + + + failed to open file, is it writable? + + + + + Load Paper Wallets + + + + + 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: + + + + + Paper wallet %1 + + + + + <b>%1</b> to Paper Wallet <span style='font-family: monospace;'>%2</span> + + + + + + + + + + + Send Coins + Send Coins + + + + The recipient address is not valid, please recheck. + + + + + The amount to pay must be larger than 0 + + + + + The amount exceeds your balance. + + + + + The total exceeds your balance when the transaction fee is included + + + + + Duplicate address found, can only send to each address once per send operation. + + + + + Transaction creation failed! + + + + + Are you sure you want to send? + + + + + added as transaction fee + + + + + Total Amount %1 (= %2) + + + + + or + + + + + Confirm send coins + + + + + 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. + + + PaymentServer @@ -3023,7 +3246,7 @@ ShutdownWindow - + %1 is shutting down... @@ -3836,7 +4059,7 @@ WalletFrame - + No wallet has been loaded. @@ -3852,7 +4075,7 @@ WalletView - + &Export &Export 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 Binary files /dev/null and b/src/qt/res/icons/paper_wallet.png differ diff --git a/src/qt/res/icons/print.png b/src/qt/res/icons/print.png new file mode 100644 index 000000000..5e3f9eb5c Binary files /dev/null and b/src/qt/res/icons/print.png differ diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index 5f3756750..e25e8cf7b 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -9,7 +9,17 @@ #include "utilitydialog.h" #include "ui_helpmessagedialog.h" +#include "ui_paperwalletdialog.h" +#include "bitcoinunits.h" + +#ifdef ENABLE_WALLET +#include "sendcoinsdialog.h" +#include "sendcoinsentry.h" +#include "coincontroldialog.h" +#endif + +#include "optionsmodel.h" #include "bitcoingui.h" #include "clientmodel.h" #include "guiconstants.h" @@ -20,15 +30,36 @@ #include "clientversion.h" #include "init.h" #include "util.h" +#include "net.h" +#include "utilstrencodings.h" #include #include +#include #include #include #include #include #include +#include + +#ifdef USE_QRCODE +#include +#endif + +#if QT_VERSION < 0x050000 +#include +#include +#include +#else +// Use QT5's new modular classes +#include +#include +#include +#endif +#include +#include "walletmodel.h" /** "Help message" or "About" dialog box */ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : @@ -159,6 +190,304 @@ 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); + setFixedSize(size()); +} + +void PaperWalletDialog::setClientModel(ClientModel *_clientModel) +{ + this->clientModel = _clientModel; + + // FIXME: This cannot be the right way of doing something on open + if (_clientModel && _clientModel->getNetworkActive()) { + 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 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.
Please wait for the wallets to print completely and verify that everything printed correctly.
Check for misalignments, ink bleeding, smears, or anything else that could make the private keys unreadable.
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 recipients; + quint64 amount = (quint64)(amountInput * COIN); + Q_FOREACH (const QString& dest, recipientPubKeyHashes) { + recipients.append(SendCoinsRecipient(dest, tr("Paper wallet %1").arg(dest), amount, "")); + formatted.append(tr("%1 to Paper Wallet %2").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("

%1"); + + if (txFee > 0) { + // append fee string if a fee is required + questionString.append("
"); + questionString.append(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), txFee)); + questionString.append(" "); + questionString.append(tr("added as transaction fee")); + } + + // add total amount in all subdivision units + questionString.append("
"); + qint64 totalAmount = tx->getTotalTransactionAmount() + txFee; + QStringList alternativeUnits; + Q_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("
")), 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 1b6781c5f..e3b08bb0f 100644 --- a/src/qt/utilitydialog.h +++ b/src/qt/utilitydialog.h @@ -7,14 +7,40 @@ #include #include +#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 setClientModel(ClientModel *clientModel); + void setModel(WalletModel *model); + +private: + Ui::PaperWalletDialog *ui; + ClientModel *clientModel; + WalletModel *model; + static const int PAPER_WALLET_READJUST_LIMIT = 20; + static const int PAPER_WALLET_PAGE_MARGIN = 50; + +private Q_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 + +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 + +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 f3183320f..b2bb7d554 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -8,6 +8,7 @@ #include "walletview.h" #include +#include #include #include @@ -178,6 +179,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 42ce69fea..a04a5b340 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -85,6 +85,8 @@ public Q_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 4a18c0bd4..e7a1753ef 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" @@ -328,3 +329,14 @@ void WalletView::requestedSyncWarningInfo() { Q_EMIT outOfSyncWarningClicked(); } + +void WalletView::printPaperWallets() +{ + if(!walletModel) + return; + + PaperWalletDialog dlg(this); + dlg.setModel(walletModel); + dlg.setClientModel(clientModel); + dlg.exec(); +} diff --git a/src/qt/walletview.h b/src/qt/walletview.h index c1f8422f0..67d163fa0 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -98,6 +98,8 @@ public Q_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();