Bitcoin Core 30.99.0
P2P Digital Currency
feerate.h
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-present 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#ifndef BITCOIN_POLICY_FEERATE_H
7#define BITCOIN_POLICY_FEERATE_H
8
9#include <consensus/amount.h>
10#include <serialize.h>
11#include <util/feefrac.h>
12
13
14#include <cstdint>
15#include <string>
16#include <type_traits>
17
18const std::string CURRENCY_UNIT = "BTC"; // One formatted unit
19const std::string CURRENCY_ATOM = "sat"; // One indivisible minimum value unit
20
21/* Used to determine type of fee estimation requested */
22enum class FeeEstimateMode {
23 UNSET,
26 BTC_KVB,
27 SAT_VB,
28};
29
35{
36private:
39
40public:
42 CFeeRate() = default;
43 template<std::integral I> // Disallow silent float -> int conversion
44 explicit CFeeRate(const I m_feerate_kvb) : m_feerate(FeePerVSize(m_feerate_kvb, 1000)) {}
45
51 CFeeRate(const CAmount& nFeePaid, int32_t virtual_bytes);
52
58 CAmount GetFee(int32_t virtual_bytes) const;
59
61
66 friend std::weak_ordering operator<=>(const CFeeRate& a, const CFeeRate& b) noexcept
67 {
68 return FeeRateCompare(a.m_feerate, b.m_feerate);
69 }
70 friend bool operator==(const CFeeRate& a, const CFeeRate& b) noexcept
71 {
72 return FeeRateCompare(a.m_feerate, b.m_feerate) == std::weak_ordering::equivalent;
73 }
76 return *this;
77 }
78 std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KVB) const;
79 friend CFeeRate operator*(const CFeeRate& f, int a) { return CFeeRate(a * f.m_feerate.fee, f.m_feerate.size); }
80 friend CFeeRate operator*(int a, const CFeeRate& f) { return CFeeRate(a * f.m_feerate.fee, f.m_feerate.size); }
81
82 SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.m_feerate.fee, obj.m_feerate.size); }
83};
84
85#endif // BITCOIN_POLICY_FEERATE_H
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
Definition: feerate.h:35
std::string ToString(const FeeEstimateMode &fee_estimate_mode=FeeEstimateMode::BTC_KVB) const
Definition: feerate.cpp:29
friend std::weak_ordering operator<=>(const CFeeRate &a, const CFeeRate &b) noexcept
Definition: feerate.h:66
CFeeRate()=default
Fee rate of 0 satoshis per 0 vB.
friend bool operator==(const CFeeRate &a, const CFeeRate &b) noexcept
Definition: feerate.h:70
CFeeRate(const I m_feerate_kvb)
Definition: feerate.h:44
friend CFeeRate operator*(int a, const CFeeRate &f)
Definition: feerate.h:80
FeePerVSize m_feerate
Fee rate in sats/vB (satoshis per N virtualbytes)
Definition: feerate.h:38
SERIALIZE_METHODS(CFeeRate, obj)
Definition: feerate.h:82
FeePerVSize GetFeePerVSize() const
Definition: feerate.h:60
friend CFeeRate operator*(const CFeeRate &f, int a)
Definition: feerate.h:79
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
Definition: feerate.h:65
CAmount GetFee(int32_t virtual_bytes) const
Return the fee in satoshis for the given vsize in vbytes.
Definition: feerate.cpp:20
CFeeRate & operator+=(const CFeeRate &a)
Definition: feerate.h:74
FeePerUnit< VSizeTag > FeePerVSize
Definition: feefrac.h:252
const std::string CURRENCY_ATOM
Definition: feerate.h:19
const std::string CURRENCY_UNIT
Definition: feerate.h:18
FeeEstimateMode
Definition: feerate.h:22
@ CONSERVATIVE
Force estimateSmartFee to use conservative estimates.
@ BTC_KVB
Use BTC/kvB fee rate unit.
@ ECONOMICAL
Force estimateSmartFee to use non-conservative estimates.
@ SAT_VB
Use sat/vB fee rate unit.
#define READWRITE(...)
Definition: serialize.h:145
int64_t fee
Definition: feefrac.h:107
int64_t EvaluateFeeDown(int32_t at_size) const noexcept
Compute the fee for a given size at_size using this object's feerate, rounding down.
Definition: feefrac.h:221
int32_t size
Definition: feefrac.h:108