Dogecoin Core  1.14.2
P2P Digital Currency
amount.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 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 
15 typedef int64_t CAmount;
16 
17 static const CAmount COIN = 100000000;
18 static const CAmount CENT = 1000000;
19 
20 extern const std::string CURRENCY_UNIT;
21 
31 static const CAmount MAX_MONEY = 10000000000 * COIN; // Dogecoin: maximum of 100B coins (given some randomness), max transaction 10,000,000,000
32 inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
33 
37 class CFeeRate
38 {
39 private:
40  CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
41 public:
44  explicit CFeeRate(const CAmount& _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { }
46  CFeeRate(const CAmount& nFeePaid, size_t nBytes);
47  CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
51  CAmount GetFee(size_t nBytes) const;
55  CAmount GetFeePerK() const { return GetFee(1000); }
56  friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
57  friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
58  friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; }
59  friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; }
60  friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
61  CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
62  std::string ToString() const;
63 
65 
66  template <typename Stream, typename Operation>
67  inline void SerializationOp(Stream& s, Operation ser_action) {
69  }
70 };
71 
72 #endif // BITCOIN_AMOUNT_H
bool MoneyRange(const CAmount &nValue)
Definition: amount.h:32
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:15
const std::string CURRENCY_UNIT
Definition: amount.cpp:10
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: amount.h:38
CAmount GetFee(size_t nBytes) const
Return the fee in satoshis for the given size in bytes.
Definition: amount.cpp:23
CFeeRate & operator+=(const CFeeRate &a)
Definition: amount.h:61
friend bool operator>=(const CFeeRate &a, const CFeeRate &b)
Definition: amount.h:60
std::string ToString() const
Definition: amount.cpp:45
CAmount nSatoshisPerK
Definition: amount.h:40
void SerializationOp(Stream &s, Operation ser_action)
Definition: amount.h:67
friend bool operator==(const CFeeRate &a, const CFeeRate &b)
Definition: amount.h:58
CFeeRate(const CFeeRate &other)
Definition: amount.h:47
ADD_SERIALIZE_METHODS
Definition: amount.h:64
friend bool operator>(const CFeeRate &a, const CFeeRate &b)
Definition: amount.h:57
CFeeRate(const CAmount &_nSatoshisPerK)
Definition: amount.h:44
friend bool operator<(const CFeeRate &a, const CFeeRate &b)
Definition: amount.h:56
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: amount.h:55
CFeeRate()
Fee rate of 0 satoshis per kB.
Definition: amount.h:43
friend bool operator<=(const CFeeRate &a, const CFeeRate &b)
Definition: amount.h:59
#define READWRITE(obj)
Definition: serialize.h:151