[Dev] Documenting Feathercoin Specific Software settings - Part 10
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/qt/coinnectordialog.cpp
Large new file, 283 lines code
+// Copyright (c) 2011-2013 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#if defined(HAVE_CONFIG_H) +#include "bitcoin-config.h" +#endif + +#include "coinnectordialog.h" +#include "ui_coinnectordialog.h" + +#include "bitcoinunits.h" +#include "guiutil.h" +#include "monitoreddatamapper.h" +#include "optionsmodel.h" + +#include "main.h" // for CTransaction::nMinTxFee and MAX_SCRIPTCHECK_THREADS +#include "netbase.h" +#include "txdb.h" // for -dbcache defaults + +#include <QDir> +#include <QIntValidator> +#include <QLocale> +#include <QMessageBox> +#include <QTimer> +#include <QNetworkReply> +#include <QNetworkRequest> +#include <QJsonObject> +#include <QJsonArray> +#include <QJsonDocument> +#include <QByteArray> +#include <QDateTime> +#include <QStandardItemModel> +#include <QDesktopServices> +#include <QUrl> + +CoinnectorDialog::CoinnectorDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::CoinnectorDialog), + model(0), + mapper(0), + fProxyIpValid(true) +{ + ui->setupUi(this); + GUIUtil::restoreWindowGeometry("nCoinnectorDialogWindow", this->size(), this); + + ui->label_6->installEventFilter(this); + ui->tableView->installEventFilter(this); + + manager = new QNetworkAccessManager(this); + connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyFinished(QNetworkReply*))); + manager->get(QNetworkRequest(QUrl("https://coinnector.com/API/ticker/"))); + + /* Widget-to-option mapper */ + mapper = new MonitoredDataMapper(this); + mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit); + mapper->setOrientation(Qt::Vertical); +} + +CoinnectorDialog::~CoinnectorDialog() +{ + GUIUtil::saveWindowGeometry("nCoinnectorDialogWindow", this); + delete ui; +} + +void CoinnectorDialog::replyFinished(QNetworkReply *reply) +{ + int sw=0; + QByteArray data = reply->readAll(); + QString result(data); + ui->textReplyEdit->setText(result); + //{"result":"success","timestamp":1432562645,"BTC_DASH":["81.2366199952",1],"DASH_BTC":["0.0116620098",-1],"BTC_DOGE":["1633333.333333333",0],"DOGE_BTC":["0.0000005782",0],"BTC_FTC":["50943.9640074796",0],"FTC_BTC":["0.0000164383",0],"BTC_LTC":["128.6659808144",-1],"LTC_BTC":["0.0073686355",1],"BTC_NMC":["623.9861305917",1],"NMC_BTC":["0.0013302033",-1],"BTC_PPC":["696.1033450117",-1],"PPC_BTC":["0.0013102915",1],"DASH_DOGE":["19047.9493465333",0],"DOGE_DASH":["0.000046971",0],"DASH_FTC":["594.1090077099",0],"FTC_DASH":["0.0013353946",0],"DASH_LTC":["1.5005039297",-1],"LTC_DASH":["0.5986030454",1],"DASH_NMC":["7.2769323725",1],"NMC_DASH":["0.1080612229",-1],"DASH_PPC":["8.1179640341",-1],"PPC_DASH":["0.1064436502",1],"DOGE_FTC":["0.0294558",0],"FTC_DOGE":["26.8492772333",0],"DOGE_LTC":["0.0000743947",-1],"LTC_DOGE":["12035.4380519333",1],"DOGE_NMC":["0.0003607888",1],"NMC_DOGE":["2172.6654488",-1],"DOGE_PPC":["0.000402487",-1],"PPC_DOGE":["2140.1427343333",1],"FTC_LTC":["0.0021150542",-1],"LTC_FTC":["375.3875038359",1],"FTC_NMC":["0.0102572918",-1],"NMC_FTC":["67.7658308718",1],"FTC_PPC":["0.0114427786",-1],"PPC_FTC":["66.751441487",1],"LTC_NMC":["4.5979263796",1],"NMC_LTC":["0.1711519169",-1],"LTC_PPC":["5.129331849",1],"PPC_LTC":["0.1685899371",-1],"NMC_PPC":["0.9259589917",-1],"PPC_NMC":["0.8176037043",1]} + + //listModel->setRowCount(6); + + QJsonParseError err;
Start of new file code
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/qt/coinnectordialog.h
New file 69 lines of code
+// Copyright (c) 2011-2013 The Feathercoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef COINNECTORDIALOG_H +#define COINNECTORDIALOG_H + +#include <QWidget> +#include <QDialog> +#include <QtNetwork> + +class MonitoredDataMapper; +class OptionsModel; +class QValidatedLineEdit; +class QStandardItemModel; + +namespace Ui { +class CoinnectorDialog; +} + +/** Preferences dialog. */ +class CoinnectorDialog : public QDialog +{ + Q_OBJECT + +public: + explicit CoinnectorDialog(QWidget *parent); + ~CoinnectorDialog(); + + void setModel(OptionsModel *model); + void setMapper(); + +protected: + bool eventFilter(QObject *object, QEvent *event); + +private slots: + /* enable OK button */ + void enableOkButton(); + /* disable OK button */ + void disableOkButton(); + /* set OK button state (enabled / disabled) */ + void setOkButtonState(bool fState); + void on_resetButton_clicked(); + void on_okButton_clicked(); + void on_cancelButton_clicked(); + void on_txStatButton_clicked(); + void on_postTransButton_clicked(); + void on_postFixButton_clicked(); + void on_pushButton_clicked(); + + void showRestartWarning(bool fPersistent = false); + void clearStatusLabel(); + void updateDisplayUnit(); + void doProxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort); + void replyFinished(QNetworkReply *); + +signals: + void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort); + +private: + Ui::CoinnectorDialog *ui; + OptionsModel *model; + MonitoredDataMapper *mapper; + bool fProxyIpValid; + QNetworkAccessManager *manager; + QStandardItemModel *listModel; +}; + +#endif // COINNECTORDIALOG_H
Code added new file
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/qt/feathercoin.qrc
+ <file alias="coinnector">res/icons/coinnector.png</file> + <file alias="coinnector">res/icons/coinnector.png</file>
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/qt/forms/coinnectordialog.ui
New file to define coinnector ,ui 108 lines of code
+<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>CoinnectorDialog</class> + <widget class="QDialog" name="CoinnectorDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>560</width> + <height>428</height> + </rect> + </property> + <property name="windowTitle"> + <string>Coinnector</string> + </property> + <property name="modal"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QFrame" name="frame"> + <property name="frameShadow"> + <enum>QFrame::Raised</enum> + </property> + <layout class="QVBoxLayout" name="verticalLayout_Bottom"> + <item> + <widget class="QTableView" name="tableView"/> + </item> + </layout> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_Buttons"> + <item> + <spacer name="horizontalSpacer_1"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>48</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLineEdit" name="textReplyEdit"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_6"> + <property name="font"> + <font> + <underline>true</underline> + </font> + </property> + <property name="cursor"> + <cursorShape>PointingHandCursor</cursorShape> + </property> + <property name="text"> + <string>Connect Coinnector API (experts only!)</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"/> + </item> + <item> + <widget class="QPushButton" name="pushButton"> + <property name="text"> + <string>Refresh</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width>
Start of new file code
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/qt/forms/opennamedialog.ui
New file to define opennamedialog 246 lines of code
+<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>OpennameDialog</class> + <widget class="QDialog" name="OpennameDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>556</width> + <height>375</height> + </rect> + </property> + <property name="windowTitle"> + <string>Insert your Opennames into blockchain</string> + </property> + <widget class="QPushButton" name="insertButton"> + <property name="geometry"> + <rect> + <x>230</x>
Start of new file code
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/qt/locale/*
Large number of updates to Translation files to cover, Feathercoin name changes.
src/qt/locale/bitcoin_en.ts
File updated
+ <source>About Feathercoin Core</source> + <translation>About Feathercoin Core</translation>
Example changes to transalation files
src/qt/locale/bitcoin_es.ts src/qt/locale/bitcoin_es.ts src/qt/locale/bitcoin_it.ts src/qt/locale/bitcoin_zh_CN.ts + <source>Copy Public &Hash160</source> + <translation>复制公匙Hash160</translation> + </message> + <message>
Example of Added Code / translations
+ <name>OpennameDialog</name> + <message> + <source>Wallet Message</source> + <translation>钱包信息</translation> + </message> + <message> + <source>Your openname length can not be above 40 charset !</source> + <translation>Openname信息长度不能超过40个字符!</translation> + </message>
Example added code
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/qt/optionsdialog.cpp
- ui->thirdPartyTxUrls->setPlaceholderText("http://explorer.feathercoin.com/tx/%s"); + ui->thirdPartyTxUrls->setPlaceholderText("http://block.ftc-c.com/tx/%s");
Code replaced : review…
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/qt/paymentserver.cpp
+ tr("URI can not be parsed! This can be caused by an invalid Feathercoin address or malformed URI parameters."),
Code replaced Feathercoin name
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/qt/res/icons/*
Additional icon files
src/qt/res/icons/coinnector.png src/qt/res/icons/openname.png src/qt/res/images/coinnector.png
Updated lated as well.
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/qt/utilitydialog.cpp
+#include "ui_opennamedialog.h" +#include "base40.h"
Code added
+/** "openname" dialog box */ +OpennameDialog::OpennameDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::OpennameDialog) +{ + ui->setupUi(this); + +} + +void OpennameDialog::setModel(WalletModel *model) +{ + + this->model = model; + + ui->cmbOpt->addItem("NAME_PREORDER", QVariant(OPENNAME_NAME_PREORDER)); + ui->cmbOpt->addItem("NAME_REGISTRATION", QVariant(OPENNAME_NAME_REGISTRATION)); + ui->cmbOpt->addItem("NAME_UPDATE", QVariant(OPENNAME_NAME_UPDATE)); + ui->cmbOpt->addItem("NAME_TRANSFER", QVariant(OPENNAME_NAME_TRANSFER)); + ui->cmbOpt->addItem("NAME_RENEWAL", QVariant(OPENNAME_NAME_RENEWAL)); + +} + +OpennameDialog::~OpennameDialog() +{ + delete ui; +} + +void OpennameDialog::on_pushButton_clicked() +{ + close(); +} + +void OpennameDialog::on_insertButton_clicked() +{ + if(!model || !model->getOptionsModel()) + return; + + LogPrintf("OpennameDialog........\n"); + QString payadress=ui->txtPayAdress->text(); + QString nameOP=ui->txtName->text(); + QString locaOP=ui->txtLocation->text(); + QString contOP=ui->txtContact->text(); + QString strOption=QString(ui->cmbOpt->currentData().toString()); //select operation currentText(),currentIndex() + LogPrintf("OpennameDialog strOption=%s\n", strOption.toStdString()); + QString privkeyOP=ui->txtNameAddress->text(); //paste hash160 from addressbookpage + + //name_hash:e00414720684e88cb7943fc6751527a94b2e0cdd + //hash160 = FeathercoinPrivateKey(private_key).public_key().hash160() + //script_pubkey = script_to_hex('OP_DUP OP_HASH160 %s OP_EQUALVERIFY OP_CHECKSIG' % hash160) + //name_hash = hash_name(name, script_pubkey) + /*def hash_name(name, script_pubkey): + bin_name = b40_to_bin(name) //return unhexlify(charset_to_hex(s, B40_CHARS)) + name_and_pubkey = bin_name + unhexlify(script_pubkey) + return hex_hash160(name_and_pubkey)*/ + + //1)script_pubkey + const char* pszMess = privkeyOP.toStdString().c_str();//hash160=6f01b45dd6685d5ac1717baa46e4cda8287c160b + //CScript scriptP = CScript() << OP_DUP << OP_HASH160 << vector<unsigned char>((const unsigned char*)pszMess, (const unsigned char*)pszMess + strlen(pszMess)) << OP_EQUALVERIFY << OP_CHECKSIG; + CScript scriptP = CScript() << OP_DUP << OP_HASH160 << ParseHex(pszMess) << OP_EQUALVERIFY << OP_CHECKSIG; + //const char* script_pubkey=HexStr(scriptP.begin(), scriptP.end(), true).c_str(); + const char* script_pubkey=HexStr(scriptP).c_str(); + LogPrintf("OpennameDialog script_pubkey=%s\n", script_pubkey);//ok=76a9146f01b45dd6685d5ac1717baa46e4cda8287c160b88ac + + //2)bin_name = b40_to_bin('lizhi') + std::string strName = nameOP.toStdString();//"lizhi";必须小写,属于base40字符集 + const std::vector<unsigned char> vch(strName.begin(), strName.end()); + uint64_t intermediate_integer=charset_to_int(&vch[0],&vch[0] + vch.size()); + LogPrintf("OpennameDialog bin_name,intermediate_integer=%d\n", intermediate_integer);//intermediate_integer=54968698 + + std::string output_string= int_to_charset(intermediate_integer); //B16_CHARS + LogPrintf("OpennameDialog bin_name,int_to_charset=%s\n", output_string.c_str());//int_to_charset=346c17a + + std::string bin_name=charset_to_hex(vch); + LogPrintf("OpennameDialog bin_name=%s\n", bin_name.c_str());//bin_name=0346c17a + //返回由十六进制字符串hexstr表示的二进制数据 + bin_name=unhexlify(bin_name); + LogPrintf("OpennameDialog bin_name,unhexlify=%s\n", bin_name.c_str());//ok unhexlify(bin_name)=F羫 + LogPrintf("OpennameDialog bin_name,unhexlify=%s\n", unhexlify("7B5a7D").c_str());//unhexlify={Z} + + //3)name_hash + std::string str_script_pubkey; + str_script_pubkey.assign(script_pubkey); + LogPrintf("OpennameDialog str_script_pubkey=%s\n", str_script_pubkey.c_str());//str_script_pubkey=76a9146f01b45dd6685d5ac1717baa46e4cda8287c160b88ac + std::string name_and_pubkey=bin_name+unhexlify(str_script_pubkey); + LogPrintf("OpennameDialog name_and_pubkey=%s\n", name_and_pubkey.c_str());//name_and_pubkey=F羫v?o碷謍]Z羜{狥渫?|埇 + std::vector<unsigned char> hash_name(name_and_pubkey.begin(), name_and_pubkey.end()); + uint160 hash_name_hash160=Hash160(hash_name); + LogPrintf("OpennameDialog hash_name_hash160 =%s\n", HexStr(hash_name_hash160).c_str());//hash_name_hash160=e00414720684e88cb7943fc6751527a94b2e0cdd + std::string name_hash=HexStr(hash_name_hash160); + LogPrintf("OpennameDialog name_hash=%s\n", name_hash.c_str());//name_hash=e00414720684e88cb7943fc6751527a94b2e0cdd + + //def build(name, script_pubkey, consensus_hash, testset=False): + //script = 'NAME_PREORDER %s %s' % (name_hash, consensus_hash) + //hex_script = name_script_to_hex(script) + //packaged_script = add_magic_bytes(hex_script, testset=testset) + //nulldata=packaged_script + std::string str_script="NAME_PREORDER"; + //consensus_hash + + QString textOP=QString(OPENNAME_MAGIC_BYTES_MAINSET) +strOption +QString(script_pubkey); + LogPrintf("OpennameDialog textOP=%s\n", textOP.toStdString());//08a76a9146f01b45dd6685d5ac1717baa46e4cda8287c160b88ac + + return; + + + //nulldata in OP_RETURN output 40 + if ((textOP.length())>=40) + { + QMessageBox::information(NULL, tr("Wallet Message"), tr("Your openname length can not be above 40 charset !"), QMessageBox::Yes , QMessageBox::Yes); + return; + } + + QList<SendCoinsRecipient> recipients; + SendCoinsRecipient rcptmp; + // Payment request + if (rcptmp.paymentRequest.IsInitialized()) + return ; + rcptmp.typeInd = AddressTableModel::AT_Normal; + rcptmp.address=payadress; + rcptmp.label="openname"; + rcptmp.amount=DUST_HARD_LIMIT*10; + rcptmp.message =textOP; + recipients.append(rcptmp); + + // Format confirmation message + QStringList formatted; + foreach(const SendCoinsRecipient &rcp, recipients) + { + // generate bold amount string + QString amount = "<b>" + BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount); + amount.append("</b>"); + // generate monospace address string + QString address = "<span style='font-family: monospace;'>" + rcp.address; + address.append("</span>"); + + QString recipientElement; + if (!rcp.paymentRequest.IsInitialized()) // normal payment + { + if(rcp.label.length() > 0) // label with address + { + recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.label)); + recipientElement.append(QString(" (%1)").arg(address)); + } + else // just address + { + recipientElement = tr("%1 to %2").arg(amount, address); + } + } + else if(!rcp.authenticatedMerchant.isEmpty()) // secure payment request + { + recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.authenticatedMerchant)); + } + else // insecure payment request + { + recipientElement = tr("%1 to %2").arg(amount, address); + } + + formatted.append(recipientElement); + } + + // prepare transaction for getting txFee earlier + WalletModelTransaction currentTransaction(recipients); + WalletModel::SendCoinsReturn prepareStatus; + if (model->getOptionsModel()->getCoinControlFeatures()) // coin control enabled + prepareStatus = model->prepareTransaction(currentTransaction, CoinControlDialog::coinControl); + else + prepareStatus = model->prepareTransaction(currentTransaction); + + // process prepareStatus and on error generate message shown to user + processSendCoinsReturn(prepareStatus, + BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), currentTransaction.getTransactionFee())); + + if(prepareStatus.status != WalletModel::OK) { + return; + } + + QString questionString = tr("Are you sure you want to send?"); + questionString.append("<br /><br />%1"); + qint64 txFee = currentTransaction.getTransactionFee(); + 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 = currentTransaction.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) + { + return; + } + + // now send the prepared transaction + WalletModel::SendCoinsReturn sendStatus = model->sendCoins(currentTransaction); + if (sendStatus.status == WalletModel::OK) + { + QMessageBox::information(NULL, tr("Wallet Message"), tr("Insert into blockchain ,Yes!!!"), QMessageBox::Yes , QMessageBox::Yes); + ui->txtName->setText(""); + ui->txtLocation->setText(""); + ui->txtContact->setText(""); + } +} + +void OpennameDialog::processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg) +{ + QPair<QString, CClientUIInterface::MessageBoxFlags> msgParams; + // Default to a warning message, override if error message is needed + msgParams.second = CClientUIInterface::MSG_WARNING; + + // This comment is specific to SendCoinsDialog usage of WalletModel::SendCoinsReturn. + // WalletModel::TransactionCommitFailed is used only in WalletModel::sendCoins() + // all others are used only in WalletModel::prepareTransaction() + switch(sendCoinsReturn.status) + { + case WalletModel::InvalidAddress: + msgParams.first = tr("The recipient address is not valid, please recheck."); + break; + case WalletModel::InvalidAmount: + msgParams.first = tr("The amount to pay must be larger than 0."); + break; + case WalletModel::AmountExceedsBalance: + msgParams.first = tr("The amount exceeds your balance."); + break; + case WalletModel::AmountWithFeeExceedsBalance: + msgParams.first = tr("The total exceeds your balance when the %1 transaction fee is included.").arg(msgArg); + break; + case WalletModel::DuplicateAddress: + msgParams.first = tr("Duplicate address found, can only send to each address once per send operation."); + break; + case WalletModel::TransactionCreationFailed: + msgParams.first = tr("Transaction creation failed!"); + msgParams.second = CClientUIInterface::MSG_ERROR; + break; + case WalletModel::TransactionCommitFailed: + msgParams.first = 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."); + msgParams.second = CClientUIInterface::MSG_ERROR; + break; + // included to prevent a compiler warning. + case WalletModel::OK: + default: + return; + } + + QMessageBox::information(NULL, tr("Wallet WARNING"), tr("Send Coins Failed:") + msgParams.first, QMessageBox::Yes , QMessageBox::Yes); + emit message(tr("Send Coins"), msgParams.first, msgParams.second); +} + + + + +
Code added
- if (textOP.length()>35) + if (textOP.length()>40) - QMessageBox::information(NULL, tr("Wallet Message"), tr("The comment length can not be above 35 charset !"), QMessageBox::Yes , QMessageBox::Yes); + QMessageBox::information(NULL, tr("Wallet Message"), tr("The comment length can not be above 40 charset !"), QMessageBox::Yes , QMessageBox::Yes);
Code replaced
+ // CSecret is a serialization of just the secret parameter (32 bytes) CSecret vchSecret = privKey.GetSecret(fCompressed); + // CPrivKey is a serialized private key, with all parameters included (279 bytes),use secp256k1 in key.cpp NID_secp256k1 + CPrivKey vchPrivKey=privKey.GetPrivKey(); + //LogPrintf("PaperWalletDialog CPrivKey=%s\n", HexStr(vchPrivKey).c_str()); + //LogPrintf("PaperWalletDialog CSecret=%s\n", HexStr(vchSecret).c_str());
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/qt/utilitydialog.h
+ class OpennameDialog;
Code added
+/** "openname" dialog box */ +OpennameDialog::OpennameDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::OpennameDialog) +{ + ui->setupUi(this); + +} + +void OpennameDialog::setModel(WalletModel *model) +{ + + this->model = model; + + ui->cmbOpt->addItem("NAME_PREORDER", QVariant(OPENNAME_NAME_PREORDER)); + ui->cmbOpt->addItem("NAME_REGISTRATION", QVariant(OPENNAME_NAME_REGISTRATION)); + ui->cmbOpt->addItem("NAME_UPDATE", QVariant(OPENNAME_NAME_UPDATE)); + ui->cmbOpt->addItem("NAME_TRANSFER", QVariant(OPENNAME_NAME_TRANSFER)); + ui->cmbOpt->addItem("NAME_RENEWAL", QVariant(OPENNAME_NAME_RENEWAL)); + +} + +OpennameDialog::~OpennameDialog() +{ + delete ui; +} + +void OpennameDialog::on_pushButton_clicked() +{ + close(); +} + +void OpennameDialog::on_insertButton_clicked() +{ + if(!model || !model->getOptionsModel()) + return; + + LogPrintf("OpennameDialog........\n"); + QString payadress=ui->txtPayAdress->text(); + QString nameOP=ui->txtName->text(); + QString locaOP=ui->txtLocation->text(); + QString contOP=ui->txtContact->text(); + QString strOption=QString(ui->cmbOpt->currentData().toString()); //select operation currentText(),currentIndex() + LogPrintf("OpennameDialog strOption=%s\n", strOption.toStdString()); + QString privkeyOP=ui->txtNameAddress->text(); //paste hash160 from addressbookpage + + //name_hash:e00414720684e88cb7943fc6751527a94b2e0cdd + //hash160 = FeathercoinPrivateKey(private_key).public_key().hash160() + //script_pubkey = script_to_hex('OP_DUP OP_HASH160 %s OP_EQUALVERIFY OP_CHECKSIG' % hash160) + //name_hash = hash_name(name, script_pubkey) + /*def hash_name(name, script_pubkey): + bin_name = b40_to_bin(name) //return unhexlify(charset_to_hex(s, B40_CHARS)) + name_and_pubkey = bin_name + unhexlify(script_pubkey) + return hex_hash160(name_and_pubkey)*/ + + //1)script_pubkey + const char* pszMess = privkeyOP.toStdString().c_str();//hash160=6f01b45dd6685d5ac1717baa46e4cda8287c160b + //CScript scriptP = CScript() << OP_DUP << OP_HASH160 << vector<unsigned char>((const unsigned char*)pszMess, (const unsigned char*)pszMess + strlen(pszMess)) << OP_EQUALVERIFY << OP_CHECKSIG; + CScript scriptP = CScript() << OP_DUP << OP_HASH160 << ParseHex(pszMess) << OP_EQUALVERIFY << OP_CHECKSIG; + //const char* script_pubkey=HexStr(scriptP.begin(), scriptP.end(), true).c_str(); + const char* script_pubkey=HexStr(scriptP).c_str(); + LogPrintf("OpennameDialog script_pubkey=%s\n", script_pubkey);//ok=76a9146f01b45dd6685d5ac1717baa46e4cda8287c160b88ac + + //2)bin_name = b40_to_bin('lizhi') + std::string strName = nameOP.toStdString();//"lizhi";必须小写,属于base40字符集 + const std::vector<unsigned char> vch(strName.begin(), strName.end()); + uint64_t intermediate_integer=charset_to_int(&vch[0],&vch[0] + vch.size()); + LogPrintf("OpennameDialog bin_name,intermediate_integer=%d\n", intermediate_integer);//intermediate_integer=54968698 + + std::string output_string= int_to_charset(intermediate_integer); //B16_CHARS + LogPrintf("OpennameDialog bin_name,int_to_charset=%s\n", output_string.c_str());//int_to_charset=346c17a + + std::string bin_name=charset_to_hex(vch); + LogPrintf("OpennameDialog bin_name=%s\n", bin_name.c_str());//bin_name=0346c17a + //返回由十六进制字符串hexstr表示的二进制数据 + bin_name=unhexlify(bin_name); + LogPrintf("OpennameDialog bin_name,unhexlify=%s\n", bin_name.c_str());//ok unhexlify(bin_name)=F羫 + LogPrintf("OpennameDialog bin_name,unhexlify=%s\n", unhexlify("7B5a7D").c_str());//unhexlify={Z} + + //3)name_hash + std::string str_script_pubkey; + str_script_pubkey.assign(script_pubkey); + LogPrintf("OpennameDialog str_script_pubkey=%s\n", str_script_pubkey.c_str());//str_script_pubkey=76a9146f01b45dd6685d5ac1717baa46e4cda8287c160b88ac + std::string name_and_pubkey=bin_name+unhexlify(str_script_pubkey); + LogPrintf("OpennameDialog name_and_pubkey=%s\n", name_and_pubkey.c_str());//name_and_pubkey=F羫v?o碷謍]Z羜{狥渫?|埇 + std::vector<unsigned char> hash_name(name_and_pubkey.begin(), name_and_pubkey.end()); + uint160 hash_name_hash160=Hash160(hash_name); + LogPrintf("OpennameDialog hash_name_hash160 =%s\n", HexStr(hash_name_hash160).c_str());//hash_name_hash160=e00414720684e88cb7943fc6751527a94b2e0cdd + std::string name_hash=HexStr(hash_name_hash160); + LogPrintf("OpennameDialog name_hash=%s\n", name_hash.c_str());//name_hash=e00414720684e88cb7943fc6751527a94b2e0cdd + + //def build(name, script_pubkey, consensus_hash, testset=False): + //script = 'NAME_PREORDER %s %s' % (name_hash, consensus_hash) + //hex_script = name_script_to_hex(script) + //packaged_script = add_magic_bytes(hex_script, testset=testset) + //nulldata=packaged_script + std::string str_script="NAME_PREORDER"; + //consensus_hash + + QString textOP=QString(OPENNAME_MAGIC_BYTES_MAINSET) +strOption +QString(script_pubkey); + LogPrintf("OpennameDialog textOP=%s\n", textOP.toStdString());//08a76a9146f01b45dd6685d5ac1717baa46e4cda8287c160b88ac + + return; + + + //nulldata in OP_RETURN output 40 + if ((textOP.length())>=40) + { + QMessageBox::information(NULL, tr("Wallet Message"), tr("Your openname length can not be above 40 charset !"), QMessageBox::Yes , QMessageBox::Yes); + return; + } + + QList<SendCoinsRecipient> recipients; + SendCoinsRecipient rcptmp; + // Payment request + if (rcptmp.paymentRequest.IsInitialized()) + return ; + rcptmp.typeInd = AddressTableModel::AT_Normal; + rcptmp.address=payadress; + rcptmp.label="openname"; + rcptmp.amount=DUST_HARD_LIMIT*10; + rcptmp.message =textOP; + recipients.append(rcptmp); + + // Format confirmation message + QStringList formatted; + foreach(const SendCoinsRecipient &rcp, recipients) + { + // generate bold amount string + QString amount = "<b>" + BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount); + amount.append("</b>"); + // generate monospace address string + QString address = "<span style='font-family: monospace;'>" + rcp.address; + address.append("</span>"); + + QString recipientElement; + if (!rcp.paymentRequest.IsInitialized()) // normal payment + { + if(rcp.label.length() > 0) // label with address + { + recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.label)); + recipientElement.append(QString(" (%1)").arg(address)); + } + else // just address + { + recipientElement = tr("%1 to %2").arg(amount, address); + } + } + else if(!rcp.authenticatedMerchant.isEmpty()) // secure payment request + { + recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.authenticatedMerchant)); + } + else // insecure payment request + { + recipientElement = tr("%1 to %2").arg(amount, address); + } + + formatted.append(recipientElement); + } + + // prepare transaction for getting txFee earlier + WalletModelTransaction currentTransaction(recipients); + WalletModel::SendCoinsReturn prepareStatus; + if (model->getOptionsModel()->getCoinControlFeatures()) // coin control enabled + prepareStatus = model->prepareTransaction(currentTransaction, CoinControlDialog::coinControl); + else + prepareStatus = model->prepareTransaction(currentTransaction); + + // process prepareStatus and on error generate message shown to user + processSendCoinsReturn(prepareStatus, + BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), currentTransaction.getTransactionFee())); + + if(prepareStatus.status != WalletModel::OK) { + return; + } + + QString questionString = tr("Are you sure you want to send?"); + questionString.append("<br /><br />%1"); + qint64 txFee = currentTransaction.getTransactionFee(); + 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 = currentTransaction.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) + { + return; + } + + // now send the prepared transaction + WalletModel::SendCoinsReturn sendStatus = model->sendCoins(currentTransaction); + if (sendStatus.status == WalletModel::OK) + { + QMessageBox::information(NULL, tr("Wallet Message"), tr("Insert into blockchain ,Yes!!!"), QMessageBox::Yes , QMessageBox::Yes); + ui->txtName->setText(""); + ui->txtLocation->setText(""); + ui->txtContact->setText(""); + } +} + +void OpennameDialog::processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg) +{ + QPair<QString, CClientUIInterface::MessageBoxFlags> msgParams; + // Default to a warning message, override if error message is needed + msgParams.second = CClientUIInterface::MSG_WARNING; + + // This comment is specific to SendCoinsDialog usage of WalletModel::SendCoinsReturn. + // WalletModel::TransactionCommitFailed is used only in WalletModel::sendCoins() + // all others are used only in WalletModel::prepareTransaction() + switch(sendCoinsReturn.status) + { + case WalletModel::InvalidAddress: + msgParams.first = tr("The recipient address is not valid, please recheck."); + break; + case WalletModel::InvalidAmount: + msgParams.first = tr("The amount to pay must be larger than 0."); + break; + case WalletModel::AmountExceedsBalance: + msgParams.first = tr("The amount exceeds your balance."); + break; + case WalletModel::AmountWithFeeExceedsBalance: + msgParams.first = tr("The total exceeds your balance when the %1 transaction fee is included.").arg(msgArg); + break; + case WalletModel::DuplicateAddress: + msgParams.first = tr("Duplicate address found, can only send to each address once per send operation."); + break; + case WalletModel::TransactionCreationFailed: + msgParams.first = tr("Transaction creation failed!"); + msgParams.second = CClientUIInterface::MSG_ERROR; + break; + case WalletModel::TransactionCommitFailed: + msgParams.first = 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."); + msgParams.second = CClientUIInterface::MSG_ERROR; + break; + // included to prevent a compiler warning. + case WalletModel::OK: + default: + return; + } + + QMessageBox::information(NULL, tr("Wallet WARNING"), tr("Send Coins Failed:") + msgParams.first, QMessageBox::Yes , QMessageBox::Yes); + emit message(tr("Send Coins"), msgParams.first, msgParams.second); +} + + + + +
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/qt/walletframe.cpp
+void WalletFrame::backupquitWallet() +{ + WalletView *walletView = currentWalletView(); + if (walletView) + walletView->backupquitWallet(); +} +
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/qt/walletframe.h
+ void backupquitWallet()
Code added
+ /** Openname dialog **/ + void opennameClicked();
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/qt/walletmodel.cpp
//insert message into blockchain - if (rcp.message.length()>=1) + if ((rcp.message.length()>=1)&&(rcp.label=="blockchain"))
Code replaced
+ //commit openname + if ((rcp.message.length()>=1)&&(rcp.label=="openname")) + { + std::string strMess = rcp.message.toStdString(); + const char* pszMess =strMess.c_str(); + CScript scriptP = CScript() << OP_RETURN << vector<unsigned char>((const unsigned char*)pszMess, (const unsigned char*)pszMess + strlen(pszMess)); + vecSend.push_back(std::pair<CScript, int64_t>(scriptP, 0)); + } + + //normal, do nothing
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/qt/walletview.cpp
+#include <QApplication> +#include <QProcess>
Code added
+void WalletView::backupquitWallet() +{ + QString filename = GUIUtil::getSaveFileName(this, + tr("Backup Wallet"), QString(), + tr("Wallet Data (*.dat)"), NULL); + + if (filename.isEmpty()) + return; + + if (!walletModel->backupWallet(filename)) { + //error + } + else { + //successfully + QApplication::quit(); + qApp->quit(); + } +} +
Code replaced
+} + +void WalletView::opennameClicked() +{ + if(!walletModel) + return; + + OpennameDialog dlg(this); + dlg.setModel(walletModel); + dlg.exec();
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/qt/walletview.h
+ void backupquitWallet(); + /** Openname dialog **/ + void opennameClicked();
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/rpcdump.cpp
+ "importprivkey \"feathercoinprivkey\" ( \"label\" rescan )\n"
Code replaced name change
+ "dumpprivkey \"feathercoinaddress\"\n" + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Feathercoin address");
Code replaced name change
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/script.h
white space removed : review change
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/wallet.cpp
- vchEphemPK.assign(itTxA, itTxA + 33); + vchEphemPK.assign(itTxA, itTxA + 33); //我补充的代码,关键,这个输出不能是空,应该是ephem_pubkey
Code replaced
-bool CWallet::SelectSharedCoins(int64 nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet, const CCoinControl* coinControl) const +bool CWallet::SelectSharedCoins(int64 nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet, const CCoinControl* coinControl) const
Code replaced
- int64 nValueIn = 0; + int64_t nValueIn = 0;
Code replaced
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
plugin and base40 encode : - commit
https://github.com/FeatherCoin/Feathercoin/commit/386f5cc1dc3d25bab04c44fc5d84abd269ad8f7b
src/wallet.h
- bool SelectSharedCoins(int64 nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet, const CCoinControl* coinControl=NULL) const; + bool SelectSharedCoins(int64 nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet, const CCoinControl* coinControl=NULL) const;
Code replaced