Bitcoin ABC  0.24.7
P2P Digital Currency
feerate.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Copyright (c) 2017-2019 The Bitcoin developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef BITCOIN_FEERATE_H
8 #define BITCOIN_FEERATE_H
9 
10 #include <amount.h>
11 #include <serialize.h>
12 
13 #include <cstdlib>
14 #include <ostream>
15 #include <string>
16 #include <type_traits>
17 
21 class CFeeRate {
22 private:
23  // unit is satoshis-per-1,000-bytes
25 
26 public:
30  constexpr CFeeRate() : nSatoshisPerK() {}
31  explicit constexpr CFeeRate(const Amount _nSatoshisPerK)
32  : nSatoshisPerK(_nSatoshisPerK) {}
33 
38  CFeeRate(const Amount nFeePaid, size_t nBytes);
39 
43  Amount GetFee(size_t nBytes) const;
44 
49  Amount GetFeeCeiling(size_t nBytes) const;
50 
54  Amount GetFeePerK() const { return GetFee(1000); }
55 
59  friend constexpr bool operator==(const CFeeRate a, const CFeeRate b) {
60  return a.nSatoshisPerK == b.nSatoshisPerK;
61  }
62  friend constexpr bool operator!=(const CFeeRate a, const CFeeRate b) {
63  return !(a == b);
64  }
65 
69  friend bool operator<(const CFeeRate &a, const CFeeRate &b) {
70  return a.nSatoshisPerK < b.nSatoshisPerK;
71  }
72  friend bool operator>(const CFeeRate &a, const CFeeRate &b) {
73  return a.nSatoshisPerK > b.nSatoshisPerK;
74  }
75  friend bool operator<=(const CFeeRate &a, const CFeeRate &b) {
76  return a.nSatoshisPerK <= b.nSatoshisPerK;
77  }
78  friend bool operator>=(const CFeeRate &a, const CFeeRate &b) {
79  return a.nSatoshisPerK >= b.nSatoshisPerK;
80  }
83  return *this;
84  }
85  std::string ToString() const;
86 
87  SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.nSatoshisPerK); }
88 };
89 
90 #endif // BITCOIN_FEERATE_H
CFeeRate::nSatoshisPerK
Amount nSatoshisPerK
Definition: feerate.h:24
CFeeRate::operator>
friend bool operator>(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:72
CFeeRate::operator>=
friend bool operator>=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:78
CFeeRate::operator!=
constexpr 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:75
CFeeRate::operator==
constexpr friend bool operator==(const CFeeRate a, const CFeeRate b)
Equality.
Definition: feerate.h:59
CFeeRate
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
CFeeRate::GetFeePerK
Amount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:54
CFeeRate::SERIALIZE_METHODS
SERIALIZE_METHODS(CFeeRate, obj)
Definition: feerate.h:87
CFeeRate::CFeeRate
constexpr CFeeRate()
Fee rate of 0 satoshis per kB.
Definition: feerate.h:30
CFeeRate::operator+=
CFeeRate & operator+=(const CFeeRate &a)
Definition: feerate.h:81
CFeeRate::GetFee
Amount GetFee(size_t nBytes) const
Return the fee in satoshis for the given size in bytes.
Definition: feerate.cpp:51
READWRITE
#define READWRITE(...)
Definition: serialize.h:179
Amount
Definition: amount.h:19
CFeeRate::CFeeRate
constexpr CFeeRate(const Amount _nSatoshisPerK)
Definition: feerate.h:31
CFeeRate::operator<
friend bool operator<(const CFeeRate &a, const CFeeRate &b)
Comparison.
Definition: feerate.h:69
CFeeRate::ToString
std::string ToString() const
Definition: feerate.cpp:59
serialize.h
amount.h
CFeeRate::GetFeeCeiling
Amount GetFeeCeiling(size_t nBytes) const
Return the ceiling of a fee calculation in satoshis for the given size in bytes.
Definition: feerate.cpp:55