doc: Add getreceivedbyaddress release notes
[bitcoinplatinum.git] / src / policy / feerate.h
blob3449cdd6990d5a3af10479ef8e7feea6fd53fc6e
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 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_POLICY_FEERATE_H
7 #define BITCOIN_POLICY_FEERATE_H
9 #include "amount.h"
10 #include "serialize.h"
12 #include <string>
14 extern const std::string CURRENCY_UNIT;
16 /**
17 * Fee rate in satoshis per kilobyte: CAmount / kB
19 class CFeeRate
21 private:
22 CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
24 public:
25 /** Fee rate of 0 satoshis per kB */
26 CFeeRate() : nSatoshisPerK(0) { }
27 template<typename I>
28 CFeeRate(const I _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) {
29 // We've previously had bugs creep in from silent double->int conversion...
30 static_assert(std::is_integral<I>::value, "CFeeRate should be used without floats");
32 /** Constructor for a fee rate in satoshis per kB. The size in bytes must not exceed (2^63 - 1)*/
33 CFeeRate(const CAmount& nFeePaid, size_t nBytes);
34 /**
35 * Return the fee in satoshis for the given size in bytes.
37 CAmount GetFee(size_t nBytes) const;
38 /**
39 * Return the fee in satoshis for a size of 1000 bytes
41 CAmount GetFeePerK() const { return GetFee(1000); }
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 friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; }
45 friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; }
46 friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
47 friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; }
48 CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
49 std::string ToString() const;
51 ADD_SERIALIZE_METHODS;
53 template <typename Stream, typename Operation>
54 inline void SerializationOp(Stream& s, Operation ser_action) {
55 READWRITE(nSatoshisPerK);
59 #endif // BITCOIN_POLICY_FEERATE_H