1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 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.
6 #ifndef BITCOIN_AMOUNT_H
7 #define BITCOIN_AMOUNT_H
14 typedef int64_t CAmount;
16 static const CAmount COIN = 100000000;
17 static const CAmount CENT = 1000000;
19 /** No amount larger than this (in satoshi) is valid */
20 static const CAmount MAX_MONEY = 21000000 * COIN;
21 inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
23 /** Type-safe wrapper class to for fee rates
24 * (how much to pay based on transaction size)
29 CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
31 CFeeRate() : nSatoshisPerK(0) { }
32 explicit CFeeRate(const CAmount& _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { }
33 CFeeRate(const CAmount& nFeePaid, size_t nSize);
34 CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
36 CAmount GetFee(size_t size) const; // unit returned is satoshis
37 CAmount GetFeePerK() const { return GetFee(1000); } // satoshis-per-1000-bytes
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 std::string ToString() const;
46 ADD_SERIALIZE_METHODS;
48 template <typename Stream, typename Operation>
49 inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
50 READWRITE(nSatoshisPerK);
54 #endif // BITCOIN_AMOUNT_H