Bitcoin Core  0.20.99
P2P Digital Currency
feerate.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2019 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 <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_KB,
23  SAT_B,
24 };
25 
29 class CFeeRate
30 {
31 private:
32  CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
33 
34 public:
36  CFeeRate() : nSatoshisPerK(0) { }
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  }
43  CFeeRate(const CAmount& nFeePaid, size_t nBytes);
47  CAmount GetFee(size_t nBytes) const;
51  CAmount GetFeePerK() const { return GetFee(1000); }
52  friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
53  friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
54  friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; }
55  friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; }
56  friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
57  friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; }
58  CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
59  std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KB) const;
60 
61  SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.nSatoshisPerK); }
62 };
63 
64 #endif // BITCOIN_POLICY_FEERATE_H
friend bool operator>=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:56
friend bool operator<=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:55
friend bool operator>(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:53
Force estimateSmartFee to use non-conservative estimates.
CAmount nSatoshisPerK
Definition: feerate.h:32
Force estimateSmartFee to use conservative estimates.
SERIALIZE_METHODS(CFeeRate, obj)
Definition: feerate.h:61
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:69
const std::string CURRENCY_ATOM
Definition: feerate.h:15
FeeEstimateMode
Definition: feerate.h:18
CFeeRate & operator+=(const CFeeRate &a)
Definition: feerate.h:58
const std::string CURRENCY_UNIT
Definition: feerate.h:14
Use explicit BTC/kB fee given in coin control.
Use default settings based on other criteria.
friend bool operator<(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:52
CFeeRate()
Fee rate of 0 satoshis per kB.
Definition: feerate.h:36
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:29
friend bool operator==(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:54
friend bool operator!=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:57
Use explicit sat/B fee given in coin control.
#define READWRITE(...)
Definition: serialize.h:171
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:51
CFeeRate(const I _nSatoshisPerK)
Definition: feerate.h:38