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> | ||||
static Amount GetMinimumFee(unsigned int nTxBytes, const CTxMemPool &pool, | Amount GetRequiredFee(unsigned int nTxBytes) { | ||||
Amount targetFee) { | return GetConfig().GetMinFeePerKB().GetFee(nTxBytes); | ||||
} | |||||
Amount GetMinimumFee(unsigned int nTxBytes, const CCoinControl &coinControl, | |||||
const CTxMemPool &pool) { | |||||
Amount targetFee = (coinControl.fOverrideFeeRate && coinControl.m_feerate) | |||||
? coinControl.m_feerate->GetFee(nTxBytes) | |||||
: payTxFee.GetFeeCeiling(nTxBytes); | |||||
Amount nFeeNeeded = targetFee; | Amount nFeeNeeded = targetFee; | ||||
if (nFeeNeeded == Amount::zero()) { | if (nFeeNeeded == Amount::zero()) { | ||||
nFeeNeeded = pool.estimateFee().GetFeeCeiling(nTxBytes); | nFeeNeeded = pool.estimateFee().GetFeeCeiling(nTxBytes); | ||||
// ... 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 fallbackFee. | ||||
if (nFeeNeeded == Amount::zero()) { | if (nFeeNeeded == Amount::zero()) { | ||||
nFeeNeeded = CWallet::fallbackFee.GetFeeCeiling(nTxBytes); | nFeeNeeded = CWallet::fallbackFee.GetFeeCeiling(nTxBytes); | ||||
} | } | ||||
} | } | ||||
// Prevent user from paying a fee below minRelayTxFee or minTxFee. | // Prevent user from paying a fee below minRelayTxFee or minTxFee. | ||||
nFeeNeeded = | nFeeNeeded = std::max(nFeeNeeded, GetRequiredFee(nTxBytes)); | ||||
std::max(nFeeNeeded, GetConfig().GetMinFeePerKB().GetFee(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; | ||||
} | } | ||||
Amount GetMinimumFee(unsigned int nTxBytes, const CTxMemPool &pool) { | |||||
// payTxFee is the user-set global for desired feerate. | |||||
return GetMinimumFee(nTxBytes, pool, payTxFee.GetFeeCeiling(nTxBytes)); | |||||
} | |||||
Amount GetMinimumFee(unsigned int nTxBytes, const CTxMemPool &pool, | |||||
const CCoinControl &coinControl) { | |||||
if (coinControl.fOverrideFeeRate && coinControl.m_feerate) { | |||||
return GetMinimumFee(nTxBytes, pool, | |||||
coinControl.m_feerate->GetFee(nTxBytes)); | |||||
} else { | |||||
return GetMinimumFee(nTxBytes, pool); | |||||
} | |||||
} |