Bitcoin ABC  0.22.13
P2P Digital Currency
fees.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2017 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <wallet/fees.h>
7 
8 #include <config.h>
9 #include <txmempool.h>
10 #include <wallet/coincontrol.h>
11 #include <wallet/wallet.h>
12 
13 Amount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes) {
14  return GetRequiredFeeRate(wallet).GetFeeCeiling(nTxBytes);
15 }
16 
17 Amount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes,
18  const CCoinControl &coin_control) {
19  return GetMinimumFeeRate(wallet, coin_control).GetFeeCeiling(nTxBytes);
20 }
21 
23  return std::max(wallet.m_min_fee, wallet.chain().relayMinFee());
24 }
25 
27  const CCoinControl &coin_control) {
28  CFeeRate neededFeeRate =
29  (coin_control.fOverrideFeeRate && coin_control.m_feerate)
30  ? *coin_control.m_feerate
31  : wallet.m_pay_tx_fee;
32 
33  if (neededFeeRate == CFeeRate()) {
34  neededFeeRate = wallet.chain().estimateFee();
35  // ... unless we don't have enough mempool data for estimatefee, then
36  // use fallback fee.
37  if (neededFeeRate == CFeeRate()) {
38  neededFeeRate = wallet.m_fallback_fee;
39  }
40  }
41 
42  // Prevent user from paying a fee below minRelayTxFee or minTxFee.
43  return std::max(neededFeeRate, GetRequiredFeeRate(wallet));
44 }
CFeeRate m_pay_tx_fee
Definition: wallet.h:1206
Definition: amount.h:17
Amount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes)
Return the minimum required absolute fee for this size based on the required fee rate.
Definition: fees.cpp:13
bool fOverrideFeeRate
Override automatic min/max checks on fee, m_feerate must be set if true.
Definition: coincontrol.h:32
Coin Control Features.
Definition: coincontrol.h:19
CFeeRate m_min_fee
Definition: wallet.h:1211
interfaces::Chain & chain() const
Interface for accessing chain state.
Definition: wallet.h:896
CFeeRate m_fallback_fee
If fee estimation does not have enough data to provide estimates, use this fee instead.
Definition: wallet.h:1217
virtual CFeeRate estimateFee() const =0
Estimate fee.
CFeeRate GetRequiredFeeRate(const CWallet &wallet)
Return the minimum required feerate taking into account the minimum relay feerate and user set minimu...
Definition: fees.cpp:22
CFeeRate GetMinimumFeeRate(const CWallet &wallet, const CCoinControl &coin_control)
Estimate the minimum fee rate considering user set parameters and the required fee.
Definition: fees.cpp:26
std::optional< CFeeRate > m_feerate
Override the wallet&#39;s m_pay_tx_fee if set.
Definition: coincontrol.h:34
Amount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes, const CCoinControl &coin_control)
Estimate the minimum fee considering user set parameters and the required fee.
Definition: fees.cpp:17
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:679
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
Amount GetFeeCeiling(size_t nBytes) const
Return the ceiling of a fee calculation in satoshis for the given size in bytes.
Definition: feerate.cpp:55
virtual CFeeRate relayMinFee()=0
Relay current minimum fee (from -minrelaytxfee settings).