mirror of https://github.com/GOSTSec/gostcoin
orignal
7 years ago
5 changed files with 213 additions and 2 deletions
@ -0,0 +1,118 @@
@@ -0,0 +1,118 @@
|
||||
#include <stdio.h> |
||||
#include <QPainter> |
||||
#include <QTextStream> |
||||
#include <QTextDocument> |
||||
#include <QUrl> |
||||
#include <QFile> |
||||
#include <QPrintDialog> |
||||
#include <QPrinter> |
||||
|
||||
#include <qrencode.h> |
||||
|
||||
#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); |
||||
} |
||||
} |
@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
|
||||
#ifndef PAPERWALLET_H__ |
||||
#define PAPERWALLET_H__ |
||||
|
||||
#include <QWidget> |
||||
|
||||
void PrintPaperWallet (QWidget * parent); |
||||
|
||||
#endif |
||||
|
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
<!DOCTYPE RCC><RCC version="1.0"> |
||||
<qresource prefix="/html"> |
||||
<file alias="paperwallet">res/html/paperwallet.html</file> |
||||
</qresource> |
||||
</RCC> |
@ -0,0 +1,77 @@
@@ -0,0 +1,77 @@
|
||||
<!DOCTYPE html> |
||||
<html> |
||||
<head lang="en"> |
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
||||
<title></title> |
||||
</head> |
||||
<body style="font-family: sans-serif; font-size: 9px; height: 842px; width: 595px; margin-left: auto; margin-right: auto;"> |
||||
<table style="width: 100%; margin-bottom: 10px" border="1px" cellpadding="10px"> |
||||
<tr style="vertical-align: top"> |
||||
<td align="left" width="50%"> |
||||
<img src=":qr1.png"/> |
||||
<h4> |
||||
Your deposit address: |
||||
</h4> |
||||
<div style="margin-bottom: 10px"> |
||||
__ADDRESS__ |
||||
</div> |
||||
<div> |
||||
<p>Use this address to deposit your Gostcoins. </p> |
||||
<p>The balance and transactoin history you can find in public blockchain: <a href=«http://explorer.gostco.in»>http://explorer.gostco.in</a></p> <br /><br /><br /><br /> |
||||
|
||||
</div> |
||||
</td> |
||||
<td align="left" width="50%"> |
||||
<img src=":qr2.png"/> |
||||
<!--width="150" height="150"/>--> |
||||
<h4> |
||||
Your key to send Gostcoins: |
||||
</h4> |
||||
<div style="margin-bottom: 10px"> |
||||
__PRIVATE__ |
||||
</div> |
||||
<div> |
||||
<p>To send your Gostcoins you need to import this key into you wallet, using importprivkey command.</p> |
||||
</div> |
||||
</td> |
||||
</tr> |
||||
<tr style="margin-bottom: 20px"> |
||||
<td colspan="2" > |
||||
<h3> |
||||
Attention! |
||||
</h3> |
||||
<div> |
||||
<ul> |
||||
<li> You should use a paper wallet only once. When you import your key it stays forever</li> |
||||
<li>If you lose your key, you will lose your Gostcoins</li> |
||||
<li>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.</li> |
||||
</ul> |
||||
</div> |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<td colspan="2"> |
||||
<table style="margin-bottom: 10px; margin-top: 10px"> |
||||
<tr> |
||||
<td width="200"> |
||||
<div style="display: inline-block;"> |
||||
<img src=":/icons/che_cash_print" width="160" height="107"> |
||||
</div> |
||||
</td> |
||||
<td> |
||||
<div style="display: inline-block; vertical-align: top; margin-left: 20px"> |
||||
<h2>GOST Coin (GST)</h2> |
||||
<div> |
||||
<h3> |
||||
Paper wallet |
||||
</h3> |
||||
</div> |
||||
</div> |
||||
</td> |
||||
</tr> |
||||
</table> |
||||
</td> |
||||
</tr> |
||||
</table> |
||||
</body> |
||||
</html> |
Loading…
Reference in new issue