Bitcoin ABC 0.30.5
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
13Amount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes) {
14 return GetRequiredFeeRate(wallet).GetFeeCeiling(nTxBytes);
15}
16
17Amount 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 the min relay fee.
43 return std::max(neededFeeRate, GetRequiredFeeRate(wallet));
44}
Coin Control Features.
Definition: coincontrol.h:21
std::optional< CFeeRate > m_feerate
Override the wallet's m_pay_tx_fee if set.
Definition: coincontrol.h:38
bool fOverrideFeeRate
Override automatic min/max checks on fee, m_feerate must be set if true.
Definition: coincontrol.h:36
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:53
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:254
Definition: amount.h:19
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
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
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
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