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 extern const std::string CURRENCY_UNIT;
21 /** No amount larger than this (in satoshi) is valid.
23 * Note that this constant is *not* the total money supply, which in Bitcoin
24 * currently happens to be less than 21,000,000 BTC for various reasons, but
25 * rather a sanity check. As this sanity check is used by consensus-critical
26 * validation code, the exact value of the MAX_MONEY constant is consensus
27 * critical; in unusual circumstances like a(nother) overflow bug that allowed
28 * for the creation of coins out of thin air modification could lead to a fork.
30 //static const CAmount MAX_MONEY = 21000000 * COIN;
31 extern int64_t MAX_MONEY;
33 inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
35 /** Type-safe wrapper class to for fee rates
36 * (how much to pay based on transaction size)
41 CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
43 CFeeRate() : nSatoshisPerK(0) { }
44 explicit CFeeRate(const CAmount& _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { }
45 CFeeRate(const CAmount& nFeePaid, size_t nSize);
46 CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
48 CAmount GetFee(size_t size) const; // unit returned is satoshis
49 CAmount GetFeePerK() const { return GetFee(1000); } // satoshis-per-1000-bytes
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 friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; }
55 friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
56 std::string ToString() const;
58 ADD_SERIALIZE_METHODS;
60 template <typename Stream, typename Operation>
61 inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
62 READWRITE(nSatoshisPerK);
66 #endif // BITCOIN_AMOUNT_H