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
10 #include "serialize.h"
14 extern const std::string CURRENCY_UNIT
;
17 * Fee rate in satoshis per kilobyte: CAmount / kB
22 CAmount nSatoshisPerK
; // unit is satoshis-per-1,000-bytes
24 /** Fee rate of 0 satoshis per kB */
25 CFeeRate() : nSatoshisPerK(0) { }
26 explicit CFeeRate(const CAmount
& _nSatoshisPerK
): nSatoshisPerK(_nSatoshisPerK
) { }
27 /** Constructor for a fee rate in satoshis per kB. The size in bytes must not exceed (2^63 - 1)*/
28 CFeeRate(const CAmount
& nFeePaid
, size_t nBytes
);
30 * Return the fee in satoshis for the given size in bytes.
32 CAmount
GetFee(size_t nBytes
) const;
34 * Return the fee in satoshis for a size of 1000 bytes
36 CAmount
GetFeePerK() const { return GetFee(1000); }
37 friend bool operator<(const CFeeRate
& a
, const CFeeRate
& b
) { return a
.nSatoshisPerK
< b
.nSatoshisPerK
; }
38 friend bool operator>(const CFeeRate
& a
, const CFeeRate
& b
) { return a
.nSatoshisPerK
> b
.nSatoshisPerK
; }
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 CFeeRate
& operator+=(const CFeeRate
& a
) { nSatoshisPerK
+= a
.nSatoshisPerK
; return *this; }
44 std::string
ToString() const;
46 ADD_SERIALIZE_METHODS
;
48 template <typename Stream
, typename Operation
>
49 inline void SerializationOp(Stream
& s
, Operation ser_action
) {
50 READWRITE(nSatoshisPerK
);
54 #endif // BITCOIN_POLICY_FEERATE_H