Fabcoin Core  0.16.2
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 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef FABCOIN_POLICY_FEERATE_H
7 #define FABCOIN_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 
20 class CFeeRate
21 {
22 private:
23  CAmount nSatoshisPerK; // unit is liu-per-1,000-bytes
24 public:
26  CFeeRate() : nSatoshisPerK(0) { }
27  explicit CFeeRate(const CAmount& _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { }
29  CFeeRate(const CAmount& nFeePaid, size_t nBytes);
30  CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
34  CAmount GetFee(size_t nBytes) const;
38  CAmount GetFeePerK() const { return GetFee(1000); }
39  friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
40  friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
41  friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; }
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  CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
46  std::string ToString() const;
47 
49 
50  template <typename Stream, typename Operation>
51  inline void SerializationOp(Stream& s, Operation ser_action) {
52  READWRITE(nSatoshisPerK);
53  }
54 };
55 
56 #endif // FABCOIN_POLICY_FEERATE_H
CAmount GetFeePerK() const
Return the fee in liu for a size of 1000 bytes.
Definition: feerate.h:38
#define READWRITE(obj)
Definition: serialize.h:179
friend bool operator>=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:43
friend bool operator<=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:42
friend bool operator>(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:40
CFeeRate(const CAmount &_nSatoshisPerK)
Definition: feerate.h:27
CAmount nSatoshisPerK
Definition: feerate.h:23
ADD_SERIALIZE_METHODS
Definition: feerate.h:48
int64_t CAmount
Amount in lius (Can be negative)
Definition: amount.h:15
#define a(i)
CFeeRate & operator+=(const CFeeRate &a)
Definition: feerate.h:45
const std::string CURRENCY_UNIT
Definition: feerate.cpp:10
void SerializationOp(Stream &s, Operation ser_action)
Definition: feerate.h:51
CFeeRate(const CFeeRate &other)
Definition: feerate.h:30
#define b(i, j)
std::string ToString() const
Definition: feerate.cpp:40
CAmount GetFee(size_t nBytes) const
Return the fee in liu for the given size in bytes.
Definition: feerate.cpp:23
friend bool operator<(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:39
CFeeRate()
Fee rate of 0 liu per kB.
Definition: feerate.h:26
Fee rate in liu per kilobyte: CAmount / kB.
Definition: feerate.h:20
friend bool operator==(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:41
friend bool operator!=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:44