Remove direct bitcoin calls from qt/sendcoinsdialog.cpp

This commit is contained in:
Russell Yanofsky 2017-04-20 12:28:58 -04:00 committed by John Newbery
parent e872c93ee8
commit 56f33ca349
3 changed files with 17 additions and 9 deletions

View file

@ -216,7 +216,9 @@ class NodeImpl : public Node
return result; return result;
} }
CFeeRate getDustRelayFee() override { return ::dustRelayFee; } CFeeRate getDustRelayFee() override { return ::dustRelayFee; }
CFeeRate getFallbackFee() override { CHECK_WALLET(return CWallet::fallbackFee); }
CFeeRate getPayTxFee() override { CHECK_WALLET(return ::payTxFee); } CFeeRate getPayTxFee() override { CHECK_WALLET(return ::payTxFee); }
void setPayTxFee(CFeeRate rate) override { CHECK_WALLET(::payTxFee = rate); }
UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) override UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) override
{ {
JSONRPCRequest req; JSONRPCRequest req;

View file

@ -173,9 +173,15 @@ public:
//! Get dust relay fee. //! Get dust relay fee.
virtual CFeeRate getDustRelayFee() = 0; virtual CFeeRate getDustRelayFee() = 0;
//! Get fallback fee.
virtual CFeeRate getFallbackFee() = 0;
//! Get pay tx fee. //! Get pay tx fee.
virtual CFeeRate getPayTxFee() = 0; virtual CFeeRate getPayTxFee() = 0;
//! Set pay tx fee.
virtual void setPayTxFee(CFeeRate rate) = 0;
//! Execute rpc command. //! Execute rpc command.
virtual UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) = 0; virtual UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) = 0;

View file

@ -18,7 +18,6 @@
#include <interface/node.h> #include <interface/node.h>
#include <key_io.h> #include <key_io.h>
#include <wallet/coincontrol.h> #include <wallet/coincontrol.h>
#include <validation.h> // mempool and minRelayTxFee
#include <ui_interface.h> #include <ui_interface.h>
#include <txmempool.h> #include <txmempool.h>
#include <policy/fees.h> #include <policy/fees.h>
@ -177,7 +176,7 @@ void SendCoinsDialog::setModel(WalletModel *_model)
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels())); connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels()));
connect(ui->optInRBF, SIGNAL(stateChanged(int)), this, SLOT(updateSmartFeeLabel())); connect(ui->optInRBF, SIGNAL(stateChanged(int)), this, SLOT(updateSmartFeeLabel()));
connect(ui->optInRBF, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels())); connect(ui->optInRBF, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels()));
ui->customFee->setSingleStep(GetRequiredFee(1000)); ui->customFee->setSingleStep(model->node().getRequiredFee(1000));
updateFeeSectionControls(); updateFeeSectionControls();
updateMinFeeLabel(); updateMinFeeLabel();
updateSmartFeeLabel(); updateSmartFeeLabel();
@ -575,7 +574,7 @@ void SendCoinsDialog::processSendCoinsReturn(const WalletModel::SendCoinsReturn
msgParams.second = CClientUIInterface::MSG_ERROR; msgParams.second = CClientUIInterface::MSG_ERROR;
break; break;
case WalletModel::AbsurdFee: case WalletModel::AbsurdFee:
msgParams.first = tr("A fee higher than %1 is considered an absurdly high fee.").arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), maxTxFee)); msgParams.first = tr("A fee higher than %1 is considered an absurdly high fee.").arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), model->node().getMaxTxFee()));
break; break;
case WalletModel::PaymentRequestExpired: case WalletModel::PaymentRequestExpired:
msgParams.first = tr("Payment request expired."); msgParams.first = tr("Payment request expired.");
@ -638,7 +637,7 @@ void SendCoinsDialog::useAvailableBalance(SendCoinsEntry* entry)
void SendCoinsDialog::setMinimumFee() void SendCoinsDialog::setMinimumFee()
{ {
ui->customFee->setValue(GetRequiredFee(1000)); ui->customFee->setValue(model->node().getRequiredFee(1000));
} }
void SendCoinsDialog::updateFeeSectionControls() void SendCoinsDialog::updateFeeSectionControls()
@ -670,7 +669,7 @@ void SendCoinsDialog::updateMinFeeLabel()
{ {
if (model && model->getOptionsModel()) if (model && model->getOptionsModel())
ui->checkBoxMinimumFee->setText(tr("Pay only the required fee of %1").arg( ui->checkBoxMinimumFee->setText(tr("Pay only the required fee of %1").arg(
BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), GetRequiredFee(1000)) + "/kB") BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), model->node().getRequiredFee(1000)) + "/kB")
); );
} }
@ -694,12 +693,13 @@ void SendCoinsDialog::updateSmartFeeLabel()
CCoinControl coin_control; CCoinControl coin_control;
updateCoinControlState(coin_control); updateCoinControlState(coin_control);
coin_control.m_feerate.reset(); // Explicitly use only fee estimation rate for smart fee labels coin_control.m_feerate.reset(); // Explicitly use only fee estimation rate for smart fee labels
FeeCalculation feeCalc; int returned_target;
CFeeRate feeRate = CFeeRate(GetMinimumFee(1000, coin_control, ::mempool, ::feeEstimator, &feeCalc)); FeeReason reason;
CFeeRate feeRate = CFeeRate(model->node().getMinimumFee(1000, coin_control, &returned_target, &reason));
ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), feeRate.GetFeePerK()) + "/kB"); ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), feeRate.GetFeePerK()) + "/kB");
if (feeCalc.reason == FeeReason::FALLBACK) { if (reason == FeeReason::FALLBACK) {
ui->labelSmartFee2->show(); // (Smart fee not initialized yet. This usually takes a few blocks...) ui->labelSmartFee2->show(); // (Smart fee not initialized yet. This usually takes a few blocks...)
ui->labelFeeEstimation->setText(""); ui->labelFeeEstimation->setText("");
ui->fallbackFeeWarningLabel->setVisible(true); ui->fallbackFeeWarningLabel->setVisible(true);
@ -711,7 +711,7 @@ void SendCoinsDialog::updateSmartFeeLabel()
else else
{ {
ui->labelSmartFee2->hide(); ui->labelSmartFee2->hide();
ui->labelFeeEstimation->setText(tr("Estimated to begin confirmation within %n block(s).", "", feeCalc.returnedTarget)); ui->labelFeeEstimation->setText(tr("Estimated to begin confirmation within %n block(s).", "", returned_target));
ui->fallbackFeeWarningLabel->setVisible(false); ui->fallbackFeeWarningLabel->setVisible(false);
} }