Bitcoin Core  29.1.0
P2P Digital Currency
feerate.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2022 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 
13 #include <cstdint>
14 #include <string>
15 #include <type_traits>
16 
17 const std::string CURRENCY_UNIT = "BTC"; // One formatted unit
18 const std::string CURRENCY_ATOM = "sat"; // One indivisible minimum value unit
19 
20 /* Used to determine type of fee estimation requested */
21 enum class FeeEstimateMode {
22  UNSET,
23  ECONOMICAL,
24  CONSERVATIVE,
25  BTC_KVB,
26  SAT_VB,
27 };
28 
32 class CFeeRate
33 {
34 private:
37 
38 public:
41  template<std::integral I> // Disallow silent float -> int conversion
42  explicit CFeeRate(const I _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) {
43  }
44 
48  CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes);
49 
55  CAmount GetFee(uint32_t num_bytes) const;
56 
60  CAmount GetFeePerK() const { return 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  friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; }
65  friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
66  friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; }
67  CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
68  std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KVB) const;
69  friend CFeeRate operator*(const CFeeRate& f, int a) { return CFeeRate(a * f.nSatoshisPerK); }
70  friend CFeeRate operator*(int a, const CFeeRate& f) { return CFeeRate(a * f.nSatoshisPerK); }
71 
72  SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.nSatoshisPerK); }
73 };
74 
75 #endif // BITCOIN_POLICY_FEERATE_H
friend CFeeRate operator*(const CFeeRate &f, int a)
Definition: feerate.h:69
friend bool operator>=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:65
friend bool operator<=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:64
friend bool operator>(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:62
Force estimateSmartFee to use non-conservative estimates.
Use sat/vB fee rate unit.
CAmount nSatoshisPerK
Fee rate in sat/kvB (satoshis per 1000 virtualbytes)
Definition: feerate.h:36
Force estimateSmartFee to use conservative estimates.
SERIALIZE_METHODS(CFeeRate, obj)
Definition: feerate.h:72
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
const std::string CURRENCY_ATOM
Definition: feerate.h:18
std::string ToString(const FeeEstimateMode &fee_estimate_mode=FeeEstimateMode::BTC_KVB) const
Definition: feerate.cpp:39
FeeEstimateMode
Definition: feerate.h:21
CFeeRate & operator+=(const CFeeRate &a)
Definition: feerate.h:67
const std::string CURRENCY_UNIT
Definition: feerate.h:17
friend CFeeRate operator*(int a, const CFeeRate &f)
Definition: feerate.h:70
Use default settings based on other criteria.
friend bool operator<(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:61
CFeeRate()
Fee rate of 0 satoshis per kvB.
Definition: feerate.h:40
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
Definition: feerate.h:32
CAmount GetFee(uint32_t num_bytes) const
Return the fee in satoshis for the given vsize in vbytes.
Definition: feerate.cpp:23
friend bool operator==(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:63
friend bool operator!=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:66
Use BTC/kvB fee rate unit.
#define READWRITE(...)
Definition: serialize.h:156
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
Definition: feerate.h:60
CFeeRate(const I _nSatoshisPerK)
Definition: feerate.h:42