From 4bfdcc181c7d7050ef515668bf4498e5e7bf47af Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Mon, 2 Mar 2015 07:26:38 +0300 Subject: [PATCH] fix IX and DS fee calculations / use coincontrol to show live calculations --- src/coincontrol.h | 4 ++++ src/qt/coincontroldialog.cpp | 10 ++++++++++ src/qt/sendcoinsdialog.cpp | 10 +++++++++- src/qt/sendcoinsdialog.h | 1 + src/wallet.cpp | 8 ++------ 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/coincontrol.h b/src/coincontrol.h index 97c30c271..6e47a0973 100644 --- a/src/coincontrol.h +++ b/src/coincontrol.h @@ -12,6 +12,8 @@ class CCoinControl { public: CTxDestination destChange; + bool useDarkSend; + bool useInstantX; CCoinControl() { @@ -22,6 +24,8 @@ public: { destChange = CNoDestination(); setSelected.clear(); + useInstantX = false; + useDarkSend = true; } bool HasSelected() const diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp index d0640d056..e2d35ee29 100644 --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -530,6 +530,9 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) // Fee int64_t nFee = nTransactionFee * (1 + (int64_t)nBytes / 1000); + // IX Fee + if(coinControl->useInstantX) nFee = max(nFee, CENT); + // Min Fee int64_t nMinFee = GetMinFee(txDummy, nBytes, AllowFree(dPriority), GMF_SEND); @@ -539,6 +542,13 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) { nChange = nAmount - nPayFee - nPayAmount; + // DS Fee = overpay + if(coinControl->useDarkSend && nChange > 0) + { + nPayFee += nChange; + nChange = 0; + } + // if sub-cent change is required, the fee must be raised to at least CTransaction::nMinTxFee if (nPayFee < CTransaction::nMinTxFee && nChange > 0 && nChange < CENT) { diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index cbbae8626..2564a8842 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -47,7 +47,7 @@ SendCoinsDialog::SendCoinsDialog(QWidget *parent) : connect(ui->checkBoxCoinControlChange, SIGNAL(stateChanged(int)), this, SLOT(coinControlChangeChecked(int))); connect(ui->lineEditCoinControlChange, SIGNAL(textEdited(const QString &)), this, SLOT(coinControlChangeEdited(const QString &))); connect(ui->checkUseDarksend, SIGNAL(stateChanged ( int )), this, SLOT(updateDisplayUnit())); - connect(ui->checkInstantX, SIGNAL(stateChanged ( int )), this, SLOT(updateDisplayUnit())); + connect(ui->checkInstantX, SIGNAL(stateChanged ( int )), this, SLOT(updateInstantX())); // Coin Control: clipboard actions QAction *clipboardQuantityAction = new QAction(tr("Copy quantity"), this); @@ -473,6 +473,14 @@ void SendCoinsDialog::setBalance(qint64 balance, qint64 unconfirmedBalance, qint void SendCoinsDialog::updateDisplayUnit() { setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(), model->getAnonymizedBalance()); + CoinControlDialog::coinControl->useDarkSend = ui->checkUseDarksend->isChecked(); + coinControlUpdateLabels(); +} + +void SendCoinsDialog::updateInstantX() +{ + CoinControlDialog::coinControl->useInstantX = ui->checkInstantX->isChecked(); + coinControlUpdateLabels(); } void SendCoinsDialog::processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg) diff --git a/src/qt/sendcoinsdialog.h b/src/qt/sendcoinsdialog.h index 5df779567..6f8605731 100644 --- a/src/qt/sendcoinsdialog.h +++ b/src/qt/sendcoinsdialog.h @@ -64,6 +64,7 @@ private slots: void on_sendButton_clicked(); void removeEntry(SendCoinsEntry* entry); void updateDisplayUnit(); + void updateInstantX(); void coinControlFeatureChanged(bool); void coinControlButtonClicked(); void coinControlChangeChecked(int); diff --git a/src/wallet.cpp b/src/wallet.cpp index 06a17b1ab..5171ab85d 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1838,7 +1838,7 @@ bool CWallet::CreateTransaction(const vector >& vecSend, LOCK2(cs_main, cs_wallet); { nFeeRet = nTransactionFee; - if(useIX && nFeeRet < CENT) nFeeRet = CENT; + if(useIX) nFeeRet = max(CENT, nFeeRet); while (true) { wtxNew.vin.clear(); @@ -1912,13 +1912,9 @@ bool CWallet::CreateTransaction(const vector >& vecSend, //over pay for denominated transactions if(coin_type == ONLY_DENOMINATED) { - nFeeRet = nChange; + nFeeRet += nChange; nChange = 0; wtxNew.mapValue["DS"] = "1"; - } else if(useIX && nFeeRet < CENT && nChange > (CENT-nFeeRet)) { - // IX has a minimum fee of 0.01 DRK - nChange -= CENT-nFeeRet; - nFeeRet = CENT; } if (nChange > 0)