From cd07e57738fbc0732337103893a0ddecc155f605 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 9 Feb 2018 14:33:40 -0500 Subject: [PATCH] paperwallet added --- gostcoin-qt.pro | 6 +- src/qt/paperwallet.cpp | 118 +++++++++++++++++++++++++++++++ src/qt/paperwallet.h | 9 +++ src/qt/paperwallet.qrc | 5 ++ src/qt/res/html/paperwallet.html | 77 ++++++++++++++++++++ 5 files changed, 213 insertions(+), 2 deletions(-) create mode 100644 src/qt/paperwallet.cpp create mode 100644 src/qt/paperwallet.h create mode 100644 src/qt/paperwallet.qrc create mode 100644 src/qt/res/html/paperwallet.html diff --git a/gostcoin-qt.pro b/gostcoin-qt.pro index 01c35ee..d4a4927 100644 --- a/gostcoin-qt.pro +++ b/gostcoin-qt.pro @@ -307,9 +307,11 @@ FORMS += src/qt/forms/sendcoinsdialog.ui \ src/qt/forms/showi2paddresses.ui contains(USE_QRCODE, 1) { -HEADERS += src/qt/qrcodedialog.h -SOURCES += src/qt/qrcodedialog.cpp +HEADERS += src/qt/qrcodedialog.h src/qt/paperwallet.h +SOURCES += src/qt/qrcodedialog.cpp src/qt/paperwallet.cpp FORMS += src/qt/forms/qrcodedialog.ui +RESOURCES += src/qt/paperwallet.qrc +QT += printsupport } contains(BITCOIN_QT_TEST, 1) { diff --git a/src/qt/paperwallet.cpp b/src/qt/paperwallet.cpp new file mode 100644 index 0000000..fb4ea27 --- /dev/null +++ b/src/qt/paperwallet.cpp @@ -0,0 +1,118 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "key.h" +#include "base58.h" +#include "paperwallet.h" + +static void printAsQR(QPainter &painter, QString &vchKey, int shift) +{ + QRcode *qr = QRcode_encodeString(vchKey.toStdString().c_str(), 1, QR_ECLEVEL_L, QR_MODE_8, 1); + if (qr) + { + QPaintDevice *pd = painter.device(); + const double w = pd->width(); + const double h = pd->height(); + QColor bg("white"); + QColor fg("black"); + painter.setBrush(bg); + painter.fillRect(0, 0, w, h, bg); + painter.setPen(Qt::SolidLine); + painter.setPen(fg); + painter.setBrush(fg); + const int s=qr->width > 0 ? qr->width : 1; + const double aspect = w / h; + const double scale = ((aspect > 1.0) ? h : w) / s;// * 0.3; + for(int y = 0; y < s; y++) + { + const int yy = y*s; + for(int x = 0; x < s; x++) + { + const int xx = yy + x; + const unsigned char b = qr->data[xx]; + if(b & 0x01) + { + const double rx1 = x*scale, ry1 = y*scale; + QRectF r(rx1 + shift, ry1, scale, scale); + painter.drawRects(&r, 1); + } + } + } + QRcode_free(qr); + } +} + +static bool readHtmlTemplate(const QString &res_name, QString &htmlContent) +{ + QFile htmlFile(res_name); + if (!htmlFile.open(QIODevice::ReadOnly | QIODevice::Text)) + { + printf("Cant open %s\n", res_name.toStdString().c_str ()); + return false; + } + + QTextStream in(&htmlFile); + in.setCodec("UTF-8"); + htmlContent = in.readAll(); + return true; +} + +void PrintPaperWallet (QWidget * parent) +{ + RandAddSeedPerfmon(); + CKey secret; + secret.MakeNewKey(true); + + CPrivKey privkey = secret.GetPrivKey(); + CPubKey pubkey = secret.GetPubKey(); + CKeyID keyid = pubkey.GetID(); + + std::string secret_str = CBitcoinSecret(secret).ToString(); + std::string address = CBitcoinAddress(keyid).ToString(); + + QString qsecret = QString::fromStdString(secret_str); + QString qaddress = QString::fromStdString(address); + + QPrinter printer(QPrinter::HighResolution); + printer.setPageMargins(0, 10, 0, 0, QPrinter::Millimeter); + + QPrintDialog dlg(&printer, parent); + if(dlg.exec() == QDialog::Accepted) + { + QImage img1(200, 200, QImage::Format_ARGB32); + QImage img2(200, 200, QImage::Format_ARGB32); + QPainter painter(&img1); + painter.setRenderHint(QPainter::Antialiasing, false); + painter.setRenderHint(QPainter::TextAntialiasing, false); + painter.setRenderHint(QPainter::SmoothPixmapTransform, false); + painter.setRenderHint(QPainter::HighQualityAntialiasing, false); + painter.setRenderHint(QPainter::NonCosmeticDefaultPen, false); + printAsQR(painter, qaddress, 0); + painter.end(); + + painter.begin(&img2); + printAsQR(painter, qsecret, 0); + painter.end(); + + QString html; + readHtmlTemplate(":/html/paperwallet", html); + + html.replace("__ADDRESS__", qaddress); + html.replace("__PRIVATE__", qsecret); + + QTextDocument document; + document.addResource(QTextDocument::ImageResource, QUrl(":qr1.png" ), img1); + document.addResource(QTextDocument::ImageResource, QUrl(":qr2.png" ), img2); + document.setHtml(html); + document.setPageSize(QSizeF(printer.pageRect(QPrinter::Point).size())); + document.print(&printer); + } +} diff --git a/src/qt/paperwallet.h b/src/qt/paperwallet.h new file mode 100644 index 0000000..4e5f21e --- /dev/null +++ b/src/qt/paperwallet.h @@ -0,0 +1,9 @@ +#ifndef PAPERWALLET_H__ +#define PAPERWALLET_H__ + +#include + +void PrintPaperWallet (QWidget * parent); + +#endif + diff --git a/src/qt/paperwallet.qrc b/src/qt/paperwallet.qrc new file mode 100644 index 0000000..5a12a09 --- /dev/null +++ b/src/qt/paperwallet.qrc @@ -0,0 +1,5 @@ + + + res/html/paperwallet.html + + diff --git a/src/qt/res/html/paperwallet.html b/src/qt/res/html/paperwallet.html new file mode 100644 index 0000000..0dccbc6 --- /dev/null +++ b/src/qt/res/html/paperwallet.html @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + +
+ +

+ Your deposit address: +

+
+ __ADDRESS__ +
+
+

Use this address to deposit your Gostcoins.

+

The balance and transactoin history you can find in public blockchain: http://explorer.gostco.in





+ +
+
+ + +

+ Your key to send Gostcoins: +

+
+ __PRIVATE__ +
+
+

To send your Gostcoins you need to import this key into you wallet, using importprivkey command.

+
+
+

+ Attention! +

+
+
    +
  • You should use a paper wallet only once. When you import your key it stays forever
  • +
  • If you lose your key, you will lose your Gostcoins
  • +
  • All transactions on the Gostcoin network irrevocable, they can not be canceled. Be careful when entering addresses to avoid typos. If possible, use the QR-code reading function.
  • +
+
+
+ + + + + +
+
+ +
+
+
+

GOST Coin (GST)

+
+

+ Paper wallet +

+
+
+
+
+ +