]> Git Repo - VerusCoin.git/blob - src/amount.h
Merge pull request #7 from jl777/beta
[VerusCoin.git] / src / amount.h
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.
5
6 #ifndef BITCOIN_AMOUNT_H
7 #define BITCOIN_AMOUNT_H
8
9 #include "serialize.h"
10
11 #include <stdlib.h>
12 #include <string>
13
14 typedef int64_t CAmount;
15
16 static const CAmount COIN = 100000000;
17 static const CAmount CENT = 1000000;
18
19 extern const std::string CURRENCY_UNIT;
20
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  * */
30 //static const CAmount MAX_MONEY = 21000000 * COIN;
31 extern int64_t MAX_MONEY;
32
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
66 #endif //  BITCOIN_AMOUNT_H
This page took 0.030595 seconds and 4 git commands to generate.