Add UpdatedBlockTip signal to CMainSignals and CValidationInterface
[bitcoinplatinum.git] / src / amount.h
blob90e6b5aa8ed577868a15da0ad50fbbcdcfc42f79
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
9 #include "serialize.h"
11 #include <stdlib.h>
12 #include <string>
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.
29 * */
30 static const CAmount MAX_MONEY = 21000000 * COIN;
31 inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
33 /** Type-safe wrapper class to for fee rates
34 * (how much to pay based on transaction size)
36 class CFeeRate
38 private:
39 CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
40 public:
41 CFeeRate() : nSatoshisPerK(0) { }
42 explicit CFeeRate(const CAmount& _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { }
43 CFeeRate(const CAmount& nFeePaid, size_t nSize);
44 CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
46 CAmount GetFee(size_t size) const; // unit returned is satoshis
47 CAmount GetFeePerK() const { return GetFee(1000); } // satoshis-per-1000-bytes
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 std::string ToString() const;
56 ADD_SERIALIZE_METHODS;
58 template <typename Stream, typename Operation>
59 inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
60 READWRITE(nSatoshisPerK);
64 #endif // BITCOIN_AMOUNT_H