Bitcoin Core  0.19.99
P2P Digital Currency
feerate.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2018 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 extern const std::string CURRENCY_UNIT;
15 
19 class CFeeRate
20 {
21 private:
22  CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
23 
24 public:
26  CFeeRate() : nSatoshisPerK(0) { }
27  template<typename I>
28  explicit CFeeRate(const I _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) {
29  // We've previously had bugs creep in from silent double->int conversion...
30  static_assert(std::is_integral<I>::value, "CFeeRate should be used without floats");
31  }
33  CFeeRate(const CAmount& nFeePaid, size_t nBytes);
37  CAmount GetFee(size_t nBytes) const;
41  CAmount GetFeePerK() const { return GetFee(1000); }
42  friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
43  friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
44  friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; }
45  friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; }
46  friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
47  friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; }
48  CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
49  std::string ToString() const;
50 
52 
53  template <typename Stream, typename Operation>
54  inline void SerializationOp(Stream& s, Operation ser_action) {
55  READWRITE(nSatoshisPerK);
56  }
57 };
58 
59 #endif // BITCOIN_POLICY_FEERATE_H
friend bool operator>=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:46
friend bool operator<=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:45
friend bool operator>(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:43
CAmount nSatoshisPerK
Definition: feerate.h:22
ADD_SERIALIZE_METHODS
Definition: feerate.h:51
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
CFeeRate & operator+=(const CFeeRate &a)
Definition: feerate.h:48
const std::string CURRENCY_UNIT
Definition: feerate.cpp:10
void SerializationOp(Stream &s, Operation ser_action)
Definition: feerate.h:54
friend bool operator<(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:42
CFeeRate()
Fee rate of 0 satoshis per kB.
Definition: feerate.h:26
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:19
friend bool operator==(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:44
friend bool operator!=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:47
std::string ToString() const
Definition: feerate.cpp:40
#define READWRITE(...)
Definition: serialize.h:184
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:41
CFeeRate(const I _nSatoshisPerK)
Definition: feerate.h:28
CAmount GetFee(size_t nBytes) const
Return the fee in satoshis for the given size in bytes.
Definition: feerate.cpp:23