]>
Commit | Line | Data |
---|---|---|
a372168e | 1 | // Copyright (c) 2009-2010 Satoshi Nakamoto |
f914f1a7 | 2 | // Copyright (c) 2009-2014 The Bitcoin Core developers |
e2efdf39 | 3 | // Distributed under the MIT software license, see the accompanying |
a372168e MF |
4 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
5 | ||
6 | #ifndef BITCOIN_AMOUNT_H | |
7 | #define BITCOIN_AMOUNT_H | |
8 | ||
eda37330 | 9 | #include "serialize.h" |
10 | ||
11 | #include <stdlib.h> | |
12 | #include <string> | |
a372168e MF |
13 | |
14 | typedef int64_t CAmount; | |
15 | ||
eda37330 | 16 | static const CAmount COIN = 100000000; |
17 | static const CAmount CENT = 1000000; | |
18 | ||
091b2116 RN |
19 | extern const std::string CURRENCY_UNIT; |
20 | ||
5e478618 PT |
21 | /** No amount larger than this (in satoshi) is valid. |
22 | * | |
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 | * */ | |
0a3a81e0 | 30 | //static const CAmount MAX_MONEY = 21000000 * COIN; |
31 | extern int64_t MAX_MONEY; | |
32 | ||
eda37330 | 33 | inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); } |
34 | ||
35 | /** Type-safe wrapper class to for fee rates | |
36 | * (how much to pay based on transaction size) | |
37 | */ | |
38 | class CFeeRate | |
39 | { | |
40 | private: | |
41 | CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes | |
42 | public: | |
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; } | |
47 | ||
48 | CAmount GetFee(size_t size) const; // unit returned is satoshis | |
49 | CAmount GetFeePerK() const { return GetFee(1000); } // satoshis-per-1000-bytes | |
50 | ||
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; | |
57 | ||
58 | ADD_SERIALIZE_METHODS; | |
59 | ||
60 | template <typename Stream, typename Operation> | |
61 | inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { | |
62 | READWRITE(nSatoshisPerK); | |
63 | } | |
64 | }; | |
65 | ||
e2efdf39 | 66 | #endif // BITCOIN_AMOUNT_H |