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