Bitcoin ABC 0.34.2
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).GetFee(static_cast<int32_t>(nTxBytes));
15}
16
17Amount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes,
18 const CCoinControl &coin_control) {
19 return GetMinimumFeeRate(wallet, coin_control)
20 .GetFee(static_cast<int32_t>(nTxBytes));
21}
22
24 return std::max(wallet.m_min_fee, wallet.chain().relayMinFee());
25}
26
28 const CCoinControl &coin_control) {
29 CFeeRate neededFeeRate =
30 (coin_control.fOverrideFeeRate && coin_control.m_feerate)
31 ? *coin_control.m_feerate
32 : wallet.m_pay_tx_fee;
33
34 if (neededFeeRate == CFeeRate(Amount::zero())) {
35 neededFeeRate = wallet.chain().estimateFee();
36 // ... unless we don't have enough mempool data for estimatefee, then
37 // use fallback fee.
38 if (neededFeeRate == CFeeRate(Amount::zero())) {
39 neededFeeRate = wallet.m_fallback_fee;
40 }
41 }
42
43 // Prevent user from paying a fee below the min relay fee.
44 return std::max(neededFeeRate, GetRequiredFeeRate(wallet));
45}
Coin Control Features.
Definition: coincontrol.h:20
std::optional< CFeeRate > m_feerate
Override the wallet's m_pay_tx_fee if set.
Definition: coincontrol.h:37
bool fOverrideFeeRate
Override automatic min/max checks on fee, m_feerate must be set if true.
Definition: coincontrol.h:35
Fee rate in satoshis per virtualbyte: Amount / vB the feerate is represented internally as FeeFrac.
Definition: feerate.h:24
Amount GetFee(int32_t virtual_bytes) const
Return the fee in satoshis for the given size in bytes.
Definition: feerate.cpp:23
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:270
Definition: amount.h:23
static constexpr Amount zero() noexcept
Definition: amount.h:36
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:27
CFeeRate GetRequiredFeeRate(const CWallet &wallet)
Return the minimum required feerate taking into account the minimum relay feerate and user set minimu...
Definition: fees.cpp:23