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 CBitcreditAddress pubkeyhash; pubkeyhash.Set(pubkey.GetID()); // Create String versions of each std::string myPrivKey = CBitcreditSecret(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 AddEditAdrenalineNode::on_okButton_clicked() { if(ui->aliasLineEdit->text() == "") { QMessageBox msg; msg.setText("Please enter an alias."); msg.exec(); return; } else if(ui->addressLineEdit->text() == "") { QMessageBox msg; msg.setText("Please enter an address."); msg.exec(); return; } else { CAdrenalineNodeConfig c; c.sAlias = ui->aliasLineEdit->text().toStdString(); c.sAddress = ui->addressLineEdit->text().toStdString(); CKey secret; secret.MakeNewKey(false); c.sBasenodePrivKey = CBitcreditSecret(secret).ToString(); CWalletDB walletdb(pwalletMain->strWalletFile); CAccount account; walletdb.ReadAccount(c.sAlias, account); bool bKeyUsed = false; bool bForceNew = false; // Check if the current key has been used if (account.vchPubKey.IsValid()) { CScript scriptPubKey; scriptPubKey= GetScriptForDestination(account.vchPubKey.GetID()); for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end() && account.vchPubKey.IsValid(); ++it) { const CWalletTx& wtx = (*it).second; BOOST_FOREACH(const CTxOut& txout, wtx.vout) if (txout.scriptPubKey == scriptPubKey) bKeyUsed = true; } } // Generate a new key if (!account.vchPubKey.IsValid() || bForceNew || bKeyUsed) { if (!pwalletMain->GetKeyFromPool(account.vchPubKey)) { QMessageBox msg; msg.setText("Keypool ran out, please call keypoolrefill first."); msg.exec(); return; } pwalletMain->SetAddressBook(account.vchPubKey.GetID(), c.sAlias, "rush"); walletdb.WriteAccount(c.sAlias, account); } c.sCollateralAddress = CBitcreditAddress(account.vchPubKey.GetID()).ToString(); pwalletMain->mapMyAdrenalineNodes.insert(make_pair(c.sAddress, c)); walletdb.WriteAdrenalineNodeConfig(c.sAddress, c); uiInterface.NotifyAdrenalineNodeChanged(c); accept(); }