hdac SDK
SDK for hdac blockchain development
amount.h
1 #ifndef AMOUNT_H
2 #define AMOUNT_H
3 
4 #include <utils/serialize.h>
5 #include <cstdint>
6 
7 typedef int64_t CAmount;
8 
9 // TODO : COIN is from nativecurrencymultiple param
10 static int64_t COIN = 100000000;
11 // TODO : MAX_MONEY is from "maximumperoutput"
12 static int64_t MAX_MONEY = 21000000 * COIN;
13 
14 inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
15 
19 class CFeeRate
20 {
21 private:
22  CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
23 public:
24  CFeeRate() : nSatoshisPerK(0) { }
25  explicit CFeeRate(const CAmount& _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { }
26  CFeeRate(const CAmount& nFeePaid, size_t nSize);
27  CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
28 
29  CAmount GetFee(size_t size) const; // unit returned is satoshis
30  CAmount GetFeePerK() const { return GetFee(1000); } // satoshis-per-1000-bytes
31 
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  friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
37  std::string ToString() const;
38 
39  ADD_SERIALIZE_METHODS;
40 
41  template <typename Stream, typename Operation>
42  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
43  READWRITE(nSatoshisPerK);
44  }
45 };
46 
47 #endif // AMOUNT_H
Definition: amount.h:19