Dash Core  0.12.2.1
P2P Digital Currency
amount.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 BITCOIN_AMOUNT_H
7 #define BITCOIN_AMOUNT_H
8 
9 #include "serialize.h"
10 
11 #include <stdlib.h>
12 #include <string>
13 
14 typedef int64_t CAmount;
15 
16 static const CAmount COIN = 100000000;
17 static const CAmount CENT = 1000000;
18 
19 extern const std::string CURRENCY_UNIT;
20 
30 static const CAmount MAX_MONEY = 21000000 * COIN;
31 inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
32 
36 class CFeeRate
37 {
38 private:
39  CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
40 public:
42  explicit CFeeRate(const CAmount& _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { }
43  CFeeRate(const CAmount& nFeePaid, size_t nSize);
44  CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
45 
46  CAmount GetFee(size_t size) const; // unit returned is satoshis
47  CAmount GetFeePerK() const { return GetFee(1000); } // satoshis-per-1000-bytes
48 
49  friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
50  friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
51  friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; }
52  friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; }
53  friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
54  CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
55  std::string ToString() const;
56 
58 
59  template <typename Stream, typename Operation>
60  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
62  }
63 };
64 
65 #endif // BITCOIN_AMOUNT_H
const std::string CURRENCY_UNIT
Definition: amount.cpp:10
CFeeRate(const CAmount &_nSatoshisPerK)
Definition: amount.h:42
#define READWRITE(obj)
Definition: serialize.h:175
static const CAmount MAX_MONEY
Definition: amount.h:30
static const CAmount COIN
Definition: amount.h:16
bool MoneyRange(const CAmount &nValue)
Definition: amount.h:31
friend bool operator>(const CFeeRate &a, const CFeeRate &b)
Definition: amount.h:50
CFeeRate(const CFeeRate &other)
Definition: amount.h:44
CAmount GetFee(size_t size) const
Definition: amount.cpp:20
ADD_SERIALIZE_METHODS
Definition: amount.h:57
int64_t CAmount
Definition: amount.h:14
CAmount nSatoshisPerK
Definition: amount.h:39
std::string ToString() const
Definition: amount.cpp:30
CAmount GetFeePerK() const
Definition: amount.h:47
CFeeRate()
Definition: amount.h:41
static const CAmount CENT
Definition: amount.h:17
friend bool operator==(const CFeeRate &a, const CFeeRate &b)
Definition: amount.h:51
friend bool operator<(const CFeeRate &a, const CFeeRate &b)
Definition: amount.h:49
CFeeRate & operator+=(const CFeeRate &a)
Definition: amount.h:54
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: amount.h:60
friend bool operator>=(const CFeeRate &a, const CFeeRate &b)
Definition: amount.h:53
friend bool operator<=(const CFeeRate &a, const CFeeRate &b)
Definition: amount.h:52