Browse Source

Add dev fee for testnet

import_zecw
Aditya Kulkarni 6 years ago
parent
commit
6f79abcc14
  1. 41
      src/confirm.ui
  2. 32
      src/sendtab.cpp
  3. 1
      src/settings.h
  4. 37
      src/ui_confirm.h
  5. 50
      src/utils.cpp
  6. 7
      src/utils.h

41
src/confirm.ui

@ -39,6 +39,16 @@
<string>To</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="1">
<widget class="QLabel" name="minerFee">
<property name="text">
<string>Miner Amount</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="Addr1">
<property name="text">
@ -66,6 +76,30 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelMinerFee">
<property name="text">
<string>Miner Fee</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelDevFee">
<property name="text">
<string>Dev Fee</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="devFee">
<property name="text">
<string>Dev Fee Amount</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -89,13 +123,6 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="feesLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">

32
src/sendtab.cpp

@ -42,7 +42,8 @@ void MainWindow::setupSendTab() {
QObject::connect(ui->tabWidget, &QTabWidget::currentChanged, [=] (int pos) {
if (pos == 1) {
// Set the fees
ui->sendTxFees->setText("0.0001 " + Utils::getTokenName());
ui->sendTxFees->setText(QString::number(Utils::getTotalFee(), 'g', 8) %
" " % Utils::getTokenName());
// Set focus to the first address box
ui->Address1->setFocus();
@ -221,7 +222,7 @@ void MainWindow::maxAmountChecked(int checked) {
auto amt = ui->sendToWidgets->findChild<QLineEdit*>(QString("Amount") % QString::number(i+1));
sumAllAmounts += amt->text().toDouble();
}
sumAllAmounts += settings->fees();
sumAllAmounts += Utils::getTotalFee();
auto addr = ui->inputsCombo->currentText().split("(")[0];
@ -276,6 +277,8 @@ void MainWindow::sendButton() {
return;
}
auto devAddress = Utils::getDevAddr(fromAddr, toAddrs);
// Get all the addresses and amounts
json allRecepients = json::array();
@ -336,6 +339,28 @@ void MainWindow::sendButton() {
}
}
// Add the dev fee to the transaction
if (!devAddress.isEmpty() && Utils::getDevFee() > 0) {
json devFee = json::object();
devFee["address"] = devAddress.toStdString();
devFee["amount"] = Utils::getDevFee();
allRecepients.push_back(devFee);
}
// Add two rows for fees
{
confirm.labelMinerFee->setText("Miner Fee");
confirm.minerFee->setText(QString::number(Utils::getMinerFee(), 'g', 8) % " " % Utils::getTokenName());
if (!devAddress.isEmpty() && Utils::getDevFee() > 0) {
confirm.labelDevFee->setText("Dev Fee");
confirm.devFee->setText(QString::number(Utils::getMinerFee(), 'g', 8) % " " % Utils::getTokenName());
} else {
confirm.labelDevFee->setText("");
confirm.devFee->setText("");
}
}
// Add sender
json params = json::array();
params.push_back(fromAddr.toStdString());
@ -344,9 +369,6 @@ void MainWindow::sendButton() {
// And show it in the confirm dialog
confirm.sendFrom->setText(fnSplitAddressForWrap(fromAddr));
// Fees in the confirm dialog
confirm.feesLabel->setText("Fee 0.0001 " % Utils::getTokenName());
// Show the dialog and submit it if the user confirms
if (d.exec() == QDialog::Accepted) {
rpc->sendZTransaction(params, [=](const json& reply) {

1
src/settings.h

@ -20,7 +20,6 @@ public:
QString getHost();
QString getPort();
double fees() { return 0.0001; }
bool loadFromSettings();
bool loadFromFile();

37
src/ui_confirm.h

@ -31,12 +31,15 @@ public:
QLabel *sendFrom;
QGroupBox *sendToAddrs;
QGridLayout *gridLayout;
QLabel *minerFee;
QLabel *Addr1;
QLabel *Amt1;
QLabel *Memo1;
QLabel *labelMinerFee;
QLabel *labelDevFee;
QLabel *devFee;
QSpacerItem *verticalSpacer;
QFrame *line;
QLabel *feesLabel;
QDialogButtonBox *buttonBox;
void setupUi(QDialog *confirm)
@ -63,6 +66,12 @@ public:
sendToAddrs->setObjectName(QStringLiteral("sendToAddrs"));
gridLayout = new QGridLayout(sendToAddrs);
gridLayout->setObjectName(QStringLiteral("gridLayout"));
minerFee = new QLabel(sendToAddrs);
minerFee->setObjectName(QStringLiteral("minerFee"));
minerFee->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
gridLayout->addWidget(minerFee, 2, 1, 1, 1);
Addr1 = new QLabel(sendToAddrs);
Addr1->setObjectName(QStringLiteral("Addr1"));
Addr1->setWordWrap(true);
@ -80,6 +89,22 @@ public:
gridLayout->addWidget(Memo1, 1, 0, 1, 2);
labelMinerFee = new QLabel(sendToAddrs);
labelMinerFee->setObjectName(QStringLiteral("labelMinerFee"));
gridLayout->addWidget(labelMinerFee, 2, 0, 1, 1);
labelDevFee = new QLabel(sendToAddrs);
labelDevFee->setObjectName(QStringLiteral("labelDevFee"));
gridLayout->addWidget(labelDevFee, 3, 0, 1, 1);
devFee = new QLabel(sendToAddrs);
devFee->setObjectName(QStringLiteral("devFee"));
devFee->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
gridLayout->addWidget(devFee, 3, 1, 1, 1);
verticalLayout->addWidget(sendToAddrs);
@ -94,11 +119,6 @@ public:
verticalLayout->addWidget(line);
feesLabel = new QLabel(confirm);
feesLabel->setObjectName(QStringLiteral("feesLabel"));
verticalLayout->addWidget(feesLabel);
buttonBox = new QDialogButtonBox(confirm);
buttonBox->setObjectName(QStringLiteral("buttonBox"));
buttonBox->setOrientation(Qt::Horizontal);
@ -120,10 +140,13 @@ public:
groupBox->setTitle(QApplication::translate("confirm", "From", nullptr));
sendFrom->setText(QString());
sendToAddrs->setTitle(QApplication::translate("confirm", "To", nullptr));
minerFee->setText(QApplication::translate("confirm", "Miner Amount", nullptr));
Addr1->setText(QApplication::translate("confirm", "TextLabel", nullptr));
Amt1->setText(QApplication::translate("confirm", "TextLabel", nullptr));
Memo1->setText(QApplication::translate("confirm", "TextLabel", nullptr));
feesLabel->setText(QString());
labelMinerFee->setText(QApplication::translate("confirm", "Miner Fee", nullptr));
labelDevFee->setText(QApplication::translate("confirm", "Dev Fee", nullptr));
devFee->setText(QApplication::translate("confirm", "Dev Fee Amount", nullptr));
} // retranslateUi
};

50
src/utils.cpp

@ -1,5 +1,6 @@
#include "utils.h"
#include "settings.h"
#include "mainwindow.h"
const QString Utils::txidStatusMessage = QString("Tx submitted (right click to copy) txid:");
@ -9,4 +10,51 @@ const QString Utils::getTokenName() {
} else {
return "ZEC";
}
}
}
// Get the dev fee address based on the transaction
const QString Utils::getDevAddr(const QString& fromAddr, const QList<ToFields>& toAddrs) {
auto testnetAddrLookup = [=] (const QString& addr) -> QString {
if (addr.startsWith("ztestsapling")) {
return "ztestsapling1kdp74adyfsmm9838jaupgfyx3npgw8ut63stjjx757pc248cuc0ymzphqeux60c64qe5qt68ygh";
} else if (addr.startsWith("zt")) {
return "ztbGDqgkmXQjheivgeirwEvJLD4SUNqsWCGwxwVg4YpGz1ARR8P2rXaptkT14z3NDKamcxNmQuvmvktyokMs7HkutRNSx1D";
} else {
return QString();
}
};
if (Settings::getInstance()->isTestnet()) {
auto devAddr = testnetAddrLookup(fromAddr);
if (!devAddr.isEmpty()) {
return devAddr;
}
// t-Addr, find if it is going to a sprout or sapling address
for (const ToFields& to : toAddrs) {
devAddr = testnetAddrLookup(to.addr);
if (!devAddr.isEmpty()) {
return devAddr;
}
}
// If this is a t-Addr -> t-Addr transaction, use the sapling address by default
return testnetAddrLookup("ztestsapling");
} else {
// Mainnet doesn't have a fee yet!
return QString();
}
}
double Utils::getMinerFee() {
return 0.0001;
}
double Utils::getDevFee() {
if (Settings::getInstance()->isTestnet()) {
return 0.0001;
} else {
return 0;
}
}
double Utils::getTotalFee() { return getMinerFee() + getDevFee(); }

7
src/utils.h

@ -3,12 +3,19 @@
#include "precompiled.h"
struct ToFields;
class Utils
{
public:
static const QString txidStatusMessage;
static const QString getTokenName();
static const QString getDevAddr(const QString& fromAddr, const QList<ToFields>& toAddrs);
static double getMinerFee();
static double getDevFee();
static double getTotalFee();
static const int updateSpeed = 20 * 1000; // 20 sec
private:

Loading…
Cancel
Save