]>
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 | ||
19 | /** No amount larger than this (in satoshi) is valid */ | |
3a02f67b | 20 | static const CAmount MAX_MONEY = 200000000 * COIN; |
eda37330 | 21 | inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); } |
22 | ||
23 | /** Type-safe wrapper class to for fee rates | |
24 | * (how much to pay based on transaction size) | |
25 | */ | |
26 | class CFeeRate | |
27 | { | |
28 | private: | |
29 | CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes | |
30 | public: | |
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; } | |
35 | ||
36 | CAmount GetFee(size_t size) const; // unit returned is satoshis | |
37 | CAmount GetFeePerK() const { return GetFee(1000); } // satoshis-per-1000-bytes | |
38 | ||
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; | |
45 | ||
46 | ADD_SERIALIZE_METHODS; | |
47 | ||
48 | template <typename Stream, typename Operation> | |
49 | inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { | |
50 | READWRITE(nSatoshisPerK); | |
51 | } | |
52 | }; | |
53 | ||
e2efdf39 | 54 | #endif // BITCOIN_AMOUNT_H |