PIVX Core  5.6.99
P2P Digital Currency
feerate.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2017 The Bitcoin Core developers
2 // Copyright (c) 2017-2020 The PIVX 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 PIVX_POLICY_FEERATE_H
7 #define PIVX_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 public:
25  explicit CFeeRate(const CAmount& _nSatoshisPerK) : nSatoshisPerK(_nSatoshisPerK) {}
26  CFeeRate(const CAmount& nFeePaid, size_t nSize);
27 
28  CAmount GetFee(size_t size) const; // unit returned is satoshis
29  CAmount GetFeePerK() const { return GetFee(1000); } // satoshis-per-1000-bytes
30 
31  friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
32  friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
33  friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; }
34  friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; }
35  friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
36  CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
37  std::string ToString() const;
38 
39  SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.nSatoshisPerK); }
40 };
41 
42 #endif // PIVX_POLICY_FEERATE_H
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
Fee rate in PIV per kilobyte: CAmount / kB.
Definition: feerate.h:20
CFeeRate & operator+=(const CFeeRate &a)
Definition: feerate.h:36
friend bool operator>=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:35
std::string ToString() const
Definition: feerate.cpp:31
CAmount GetFee(size_t size) const
Definition: feerate.cpp:21
CAmount nSatoshisPerK
Definition: feerate.h:22
SERIALIZE_METHODS(CFeeRate, obj)
Definition: feerate.h:39
friend bool operator==(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:33
friend bool operator>(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:32
CFeeRate(const CAmount &_nSatoshisPerK)
Definition: feerate.h:25
friend bool operator<(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:31
CAmount GetFeePerK() const
Definition: feerate.h:29
CFeeRate()
Definition: feerate.h:24
friend bool operator<=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:34
const std::string CURRENCY_UNIT
Definition: feerate.cpp:11
#define READWRITE(...)
Definition: serialize.h:183