Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/fees.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2017 The Bitcoin Core developers | // Copyright (c) 2009-2017 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <wallet/fees.h> | #include <wallet/fees.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
#include <txmempool.h> | #include <txmempool.h> | ||||
#include <util.h> | #include <util.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <wallet/coincontrol.h> | #include <wallet/coincontrol.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
Amount GetRequiredFee(unsigned int nTxBytes) { | Amount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes) { | ||||
return GetRequiredFeeRate().GetFeeCeiling(nTxBytes); | return GetRequiredFeeRate(wallet).GetFeeCeiling(nTxBytes); | ||||
} | } | ||||
Amount GetMinimumFee(unsigned int nTxBytes, const CCoinControl &coin_control, | Amount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes, | ||||
const CTxMemPool &pool) { | const CCoinControl &coin_control, const CTxMemPool &pool) { | ||||
Amount nFeeNeeded = | Amount nFeeNeeded = | ||||
GetMinimumFeeRate(coin_control, pool).GetFeeCeiling(nTxBytes); | GetMinimumFeeRate(wallet, coin_control, pool).GetFeeCeiling(nTxBytes); | ||||
// But always obey the maximum. | // But always obey the maximum. | ||||
if (nFeeNeeded > maxTxFee) { | if (nFeeNeeded > maxTxFee) { | ||||
nFeeNeeded = maxTxFee; | nFeeNeeded = maxTxFee; | ||||
} | } | ||||
return nFeeNeeded; | return nFeeNeeded; | ||||
} | } | ||||
CFeeRate GetRequiredFeeRate() { | CFeeRate GetRequiredFeeRate(const CWallet &wallet) { | ||||
return std::max(CWallet::minTxFee, ::minRelayTxFee); | return std::max(wallet.m_min_fee, ::minRelayTxFee); | ||||
} | } | ||||
CFeeRate GetMinimumFeeRate(const CCoinControl &coin_control, | CFeeRate GetMinimumFeeRate(const CWallet &wallet, | ||||
const CCoinControl &coin_control, | |||||
const CTxMemPool &pool) { | 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 | ||||
: payTxFee; | : wallet.m_pay_tx_fee; | ||||
if (neededFeeRate == CFeeRate()) { | if (neededFeeRate == CFeeRate()) { | ||||
neededFeeRate = pool.estimateFee(); | neededFeeRate = pool.estimateFee(); | ||||
// ... unless we don't have enough mempool data for estimatefee, then | // ... unless we don't have enough mempool data for estimatefee, then | ||||
// use fallbackFee. | // use fallback fee. | ||||
if (neededFeeRate == CFeeRate()) { | if (neededFeeRate == CFeeRate()) { | ||||
neededFeeRate = CWallet::fallbackFee; | 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()); | return std::max(neededFeeRate, GetRequiredFeeRate(wallet)); | ||||
} | } |