diff --git a/src/wallet/fees.cpp b/src/wallet/fees.cpp index 246a288dc..9041d52a8 100644 --- a/src/wallet/fees.cpp +++ b/src/wallet/fees.cpp @@ -1,45 +1,55 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2017 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include #include #include #include #include Amount GetRequiredFee(unsigned int nTxBytes) { - return GetConfig().GetMinFeePerKB().GetFee(nTxBytes); + return GetRequiredFeeRate().GetFeeCeiling(nTxBytes); } -Amount GetMinimumFee(unsigned int nTxBytes, const CCoinControl &coinControl, +Amount GetMinimumFee(unsigned int nTxBytes, const CCoinControl &coin_control, const CTxMemPool &pool) { - Amount targetFee = (coinControl.fOverrideFeeRate && coinControl.m_feerate) - ? coinControl.m_feerate->GetFee(nTxBytes) - : payTxFee.GetFeeCeiling(nTxBytes); - - Amount nFeeNeeded = targetFee; - if (nFeeNeeded == Amount::zero()) { - nFeeNeeded = pool.estimateFee().GetFeeCeiling(nTxBytes); - // ... unless we don't have enough mempool data for estimatefee, then - // use fallbackFee. - if (nFeeNeeded == Amount::zero()) { - nFeeNeeded = CWallet::fallbackFee.GetFeeCeiling(nTxBytes); - } - } - - // Prevent user from paying a fee below minRelayTxFee or minTxFee. - nFeeNeeded = std::max(nFeeNeeded, GetRequiredFee(nTxBytes)); + Amount nFeeNeeded = + GetMinimumFeeRate(coin_control, pool).GetFeeCeiling(nTxBytes); // But always obey the maximum. if (nFeeNeeded > maxTxFee) { nFeeNeeded = maxTxFee; } return nFeeNeeded; } + +CFeeRate GetRequiredFeeRate() { + return GetConfig().GetMinFeePerKB(); +} + +CFeeRate GetMinimumFeeRate(const CCoinControl &coin_control, + const CTxMemPool &pool) { + CFeeRate neededFeeRate = + (coin_control.fOverrideFeeRate && coin_control.m_feerate) + ? *coin_control.m_feerate + : payTxFee; + + if (neededFeeRate == CFeeRate()) { + neededFeeRate = pool.estimateFee(); + // ... unless we don't have enough mempool data for estimatefee, then + // use fallbackFee. + if (neededFeeRate == CFeeRate()) { + neededFeeRate = CWallet::fallbackFee; + } + } + + // Prevent user from paying a fee below minRelayTxFee or minTxFee. + return std::max(neededFeeRate, GetRequiredFeeRate()); +} diff --git a/src/wallet/fees.h b/src/wallet/fees.h index 4d5f07425..14ea689d3 100644 --- a/src/wallet/fees.h +++ b/src/wallet/fees.h @@ -1,28 +1,42 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2017 The Bitcoin Core developers // Copyright (c) 2018 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_WALLET_FEES_H #define BITCOIN_WALLET_FEES_H #include +#include class CCoinControl; class CTxMemPool; /** * Return the minimum required fee taking into account the * floating relay fee and user set minimum transaction fee */ Amount GetRequiredFee(unsigned int nTxBytes); /** * Estimate the minimum fee considering user set parameters * and the required fee */ Amount GetMinimumFee(unsigned int nTxBytes, const CCoinControl &coinControl, const CTxMemPool &pool); +/** + * Return the minimum required feerate taking into account the + * floating relay feerate and user set minimum transaction feerate + */ +CFeeRate GetRequiredFeeRate(); + +/** + * Estimate the minimum fee rate considering user set parameters + * and the required fee + */ +CFeeRate GetMinimumFeeRate(const CCoinControl &coin_control, + const CTxMemPool &pool); + #endif // BITCOIN_WALLET_FEES_H