Bitcoin Core  22.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-2020 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 
12 #include <string>
13 
14 const std::string CURRENCY_UNIT = "BTC"; // One formatted unit
15 const std::string CURRENCY_ATOM = "sat"; // One indivisible minimum value unit
16 
17 /* Used to determine type of fee estimation requested */
18 enum class FeeEstimateMode {
19  UNSET,
20  ECONOMICAL,
21  CONSERVATIVE,
22  BTC_KVB,
23  SAT_VB,
24 };
25 
29 class CFeeRate
30 {
31 private:
32  CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
33 
34 public:
37  template<typename I>
38  explicit CFeeRate(const I _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) {
39  // We've previously had bugs creep in from silent double->int conversion...
40  static_assert(std::is_integral<I>::value, "CFeeRate should be used without floats");
41  }
48  CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes);
53  CAmount GetFee(uint32_t num_bytes) const;
57  CAmount GetFeePerK() const { return GetFee(1000); }
58  friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
59  friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
60  friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; }
61  friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; }
62  friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
63  friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; }
64  CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
65  std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KVB) const;
66 
67  SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.nSatoshisPerK); }
68 };
69 
70 #endif // BITCOIN_POLICY_FEERATE_H
FeeEstimateMode::BTC_KVB
@ BTC_KVB
Use BTC/kvB fee rate unit.
CFeeRate::operator>
friend bool operator>(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:59
CFeeRate::operator>=
friend bool operator>=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:62
CFeeRate::operator<=
friend bool operator<=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:61
CFeeRate
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:29
CFeeRate::nSatoshisPerK
CAmount nSatoshisPerK
Definition: feerate.h:32
FeeEstimateMode::ECONOMICAL
@ ECONOMICAL
Force estimateSmartFee to use non-conservative estimates.
CURRENCY_UNIT
const std::string CURRENCY_UNIT
Definition: feerate.h:14
FeeEstimateMode::SAT_VB
@ SAT_VB
Use sat/vB fee rate unit.
CFeeRate::SERIALIZE_METHODS
SERIALIZE_METHODS(CFeeRate, obj)
Definition: feerate.h:67
FeeEstimateMode
FeeEstimateMode
Definition: feerate.h:18
CFeeRate::operator+=
CFeeRate & operator+=(const CFeeRate &a)
Definition: feerate.h:64
CURRENCY_ATOM
const std::string CURRENCY_ATOM
Definition: feerate.h:15
CAmount
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
READWRITE
#define READWRITE(...)
Definition: serialize.h:147
CFeeRate::ToString
std::string ToString(const FeeEstimateMode &fee_estimate_mode=FeeEstimateMode::BTC_KVB) const
Definition: feerate.cpp:39
FeeEstimateMode::UNSET
@ UNSET
Use default settings based on other criteria.
FeeEstimateMode::CONSERVATIVE
@ CONSERVATIVE
Force estimateSmartFee to use conservative estimates.
CFeeRate::operator<
friend bool operator<(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:58
CFeeRate::operator!=
friend bool operator!=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:63
serialize.h
CFeeRate::CFeeRate
CFeeRate()
Fee rate of 0 satoshis per kB.
Definition: feerate.h:36
CFeeRate::GetFee
CAmount GetFee(uint32_t num_bytes) const
Return the fee in satoshis for the given size in bytes.
Definition: feerate.cpp:23
CFeeRate::operator==
friend bool operator==(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:60
CFeeRate::GetFeePerK
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:57
amount.h
CFeeRate::CFeeRate
CFeeRate(const I _nSatoshisPerK)
Definition: feerate.h:38