Feathercoin daemon and wallet production version 0.17.0.2

[Dev] Documenting Feathercoin Specific Software settings - Part 7


  • Moderators | Tip wrapper

    Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*

    Adds in support for printing paper wallets : - commit

    https://github.com/FeatherCoin/Feathercoin/commit/3689244d7b94650c257cc4b7e8151b427b6cd6cf

    Adds support for printing paper wallets

    src/qt/res/fonts/*

     src/qt/res/fonts/ComicNeue-Bold-Oblique.ttf
    
     src/qt/res/fonts/ComicNeue-Bold.ttf
    
     src/qt/res/fonts/ComicNeue-Light-Oblique.ttf
    
     src/qt/res/fonts/ComicNeue-Light.ttf
    
     src/qt/res/fonts/ComicNeue-Regular-Oblique.ttf
    
     src/qt/res/fonts/ComicNeue-Regular.ttf
    
     src/qt/res/icons/print.png
    
      src/qt/res/images/paper_wallet.png
    

    New files added


  • Moderators | Tip wrapper

    Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*

    Adds in support for printing paper wallets : - commit

    https://github.com/FeatherCoin/Feathercoin/commit/3689244d7b94650c257cc4b7e8151b427b6cd6cf

    Adds support for printing paper wallets

    src/qt/utilitydialog.cpp

     +#include "ui_paperwalletdialog.h"
    
      + #include "bitcoinunits.h"
     + 
     + #ifdef ENABLE_WALLET
     + #include "sendcoinsdialog.h"
     + #include "sendcoinsentry.h"
     + #include "coincontrol.h"
     + #include "coincontroldialog.h"
     + #endif
    

    Code added

     + #include "net.h"
    
     + #include <QFont>
    
     + #include <QInputDialog>
     + 
     + #ifdef USE_QRCODE
     + #include <qrencode.h>
     + #endif
     + 
     + 
     + // Use QT5's new modular classes
     + #include <QtPrintSupport/QPrinter>
     + #include <QtPrintSupport/QPrintDialog>
     + #include <QtPrintSupport/QPrintPreviewDialog>
     + #include <QPainter>
     + #include "walletmodel.h"
    

    Code added

     + /** "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, tr("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
     +     string myPrivKey = CBitcoinSecret(privKey).ToString();
     +     string myPubKey = HexStr(pubkey.begin(), pubkey.end());
     +     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 publicKeyImage = QImage(code->width, code->width, QImage::Format_ARGB32);
     +     publicKeyImage.fill(0x000000);
     +     unsigned char *p = code->data;
     +     for (int y = 0; y < code->width; y++ )
     +     {
     +         for (int x = 0; x < code->width; x++ )
     +         {
     +             publicKeyImage.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 privateKeyImage = QImage(code->width, code->width, QImage::Format_ARGB32);
     +     privateKeyImage.fill(0x000000);
     +     p = code->data;
     +     for (int y = 0; y < code->width; y++ )
     +     {
     +         for (int x = 0; x < code->width; x++ )
     +         {
     +             privateKeyImage.setPixel(x, y, ((*p & 1) ? 0xff000000 : 0x0));
     +             p++ ;
     +         }
     +     }
     +     QRcode_free(code);
     + 
     +     // Populate the QR Codes
     +     ui->addressQRCode->setPixmap(QPixmap::fromImage(publicKeyImage).scaled(ui->addressQRCode->width(), ui->addressQRCode->height()));
     +     ui->privateKeyQRCode->setPixmap(QPixmap::fromImage(privateKeyImage).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 FTC 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;
     + 
     + }
     + 
     + 
    

    Large section of additional code


  • Moderators | Tip wrapper

    Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*

    Adds in support for printing paper wallets : - commit

    https://github.com/FeatherCoin/Feathercoin/commit/3689244d7b94650c257cc4b7e8151b427b6cd6cf

    Adds support for printing paper wallets

    src/qt/utilitydialog.h

     +#include "walletmodel.h"
    
     +    class PaperWalletDialog;
    

    Code added

     + /** "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();
     + };
     + 
    

    Section of code added


  • Moderators | Tip wrapper

    Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*

    Adds in support for printing paper wallets : - commit

    https://github.com/FeatherCoin/Feathercoin/commit/3689244d7b94650c257cc4b7e8151b427b6cd6cf

    Adds support for printing paper wallets

    src/qt/verticallabel.cpp

    New files

     + #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());
     + }
    

    Code added


  • Moderators | Tip wrapper

    Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*

    Adds in support for printing paper wallets : - commit

    https://github.com/FeatherCoin/Feathercoin/commit/3689244d7b94650c257cc4b7e8151b427b6cd6cf

    Adds support for printing paper wallets

    src/qt/verticallabel.h

     + #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
    

    Code added new file


  • Moderators | Tip wrapper

    Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*

    Adds in support for printing paper wallets : - commit

    https://github.com/FeatherCoin/Feathercoin/commit/3689244d7b94650c257cc4b7e8151b427b6cd6cf

    Adds support for printing paper wallets

    src/qt/walletframe.cpp

     +#include <iostream>
    

    Code added

     + void WalletFrame::printPaperWallets()
     + {
     +     WalletView *walletView = currentWalletView();
     +     if (walletView)
     +         walletView->printPaperWallets();
     + }
     + 
    

    Code added


  • Moderators | Tip wrapper

    Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*

    Adds in support for printing paper wallets : - commit

    https://github.com/FeatherCoin/Feathercoin/commit/3689244d7b94650c257cc4b7e8151b427b6cd6cf

    Adds support for printing paper wallets

    src/qt/walletframe.h

     +    /** Open the print paper wallets dialog **/
     +    void printPaperWallets();
    

    Code added


  • Moderators | Tip wrapper

    Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*

    Adds in support for printing paper wallets : - commit

    https://github.com/FeatherCoin/Feathercoin/commit/3689244d7b94650c257cc4b7e8151b427b6cd6cf

    Adds support for printing paper wallets

    src/qt/walletview.cpp

     +#include "utilitydialog.h"
    
     + 
     + void WalletView::printPaperWallets()
     + {
     +     if(!walletModel)
     +         return;
     + 
     +     PaperWalletDialog dlg(this);
     +     dlg.setModel(walletModel);
     +     dlg.exec();
     + } 
    

    Code added


  • Moderators | Tip wrapper

    Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*

    Adds in support for printing paper wallets : - commit

    https://github.com/FeatherCoin/Feathercoin/commit/3689244d7b94650c257cc4b7e8151b427b6cd6cf

    Adds support for printing paper wallets

    src/qt/walletview.h

    +    /** Open the print paper wallets dialog **/
    +    void printPaperWallets();
    

    Code added


  • Moderators | Tip Wellenreiter

    @wrapper said in [Dev] Documenting Feathercoin Specific Software settings - Part 7:

    Code replaced

    • moc_reportview.cpp \
    • moc_reportview.cpp
    • moc_merchantlist.cpp

    The moc_* files are created during compile and should be added to the .gitignore file