Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/fees.cpp
Show All 12 Lines | |||||
#include <wallet/coincontrol.h> | #include <wallet/coincontrol.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
Amount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes) { | Amount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes) { | ||||
return GetRequiredFeeRate(wallet).GetFeeCeiling(nTxBytes); | return GetRequiredFeeRate(wallet).GetFeeCeiling(nTxBytes); | ||||
} | } | ||||
Amount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes, | Amount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes, | ||||
const CCoinControl &coin_control, const CTxMemPool &pool) { | const CCoinControl &coin_control) { | ||||
Amount nFeeNeeded = | Amount nFeeNeeded = | ||||
GetMinimumFeeRate(wallet, coin_control, pool).GetFeeCeiling(nTxBytes); | GetMinimumFeeRate(wallet, coin_control).GetFeeCeiling(nTxBytes); | ||||
// But always obey the maximum. | // But always obey the maximum. | ||||
const Amount max_tx_fee = wallet.chain().maxTxFee(); | const Amount max_tx_fee = wallet.chain().maxTxFee(); | ||||
if (nFeeNeeded > max_tx_fee) { | if (nFeeNeeded > max_tx_fee) { | ||||
nFeeNeeded = max_tx_fee; | nFeeNeeded = max_tx_fee; | ||||
} | } | ||||
return nFeeNeeded; | return nFeeNeeded; | ||||
} | } | ||||
CFeeRate GetRequiredFeeRate(const CWallet &wallet) { | CFeeRate GetRequiredFeeRate(const CWallet &wallet) { | ||||
return std::max(wallet.m_min_fee, wallet.chain().relayMinFee()); | return std::max(wallet.m_min_fee, wallet.chain().relayMinFee()); | ||||
} | } | ||||
CFeeRate GetMinimumFeeRate(const CWallet &wallet, | CFeeRate GetMinimumFeeRate(const CWallet &wallet, | ||||
const CCoinControl &coin_control, | const CCoinControl &coin_control) { | ||||
const CTxMemPool &pool) { | |||||
CFeeRate neededFeeRate = | CFeeRate neededFeeRate = | ||||
(coin_control.fOverrideFeeRate && coin_control.m_feerate) | (coin_control.fOverrideFeeRate && coin_control.m_feerate) | ||||
? *coin_control.m_feerate | ? *coin_control.m_feerate | ||||
: wallet.m_pay_tx_fee; | : wallet.m_pay_tx_fee; | ||||
if (neededFeeRate == CFeeRate()) { | if (neededFeeRate == CFeeRate()) { | ||||
neededFeeRate = pool.estimateFee(); | neededFeeRate = wallet.chain().estimateFee(); | ||||
// ... unless we don't have enough mempool data for estimatefee, then | // ... unless we don't have enough mempool data for estimatefee, then | ||||
// use fallback fee. | // use fallback fee. | ||||
if (neededFeeRate == CFeeRate()) { | if (neededFeeRate == CFeeRate()) { | ||||
neededFeeRate = wallet.m_fallback_fee; | neededFeeRate = wallet.m_fallback_fee; | ||||
} | } | ||||
} | } | ||||
// Prevent user from paying a fee below minRelayTxFee or minTxFee. | // Prevent user from paying a fee below minRelayTxFee or minTxFee. | ||||
return std::max(neededFeeRate, GetRequiredFeeRate(wallet)); | return std::max(neededFeeRate, GetRequiredFeeRate(wallet)); | ||||
} | } |