Bitcoin ABC 0.30.5
P2P Digital Currency
feerate.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// Copyright (c) 2017-2019 The Bitcoin developers
4// Distributed under the MIT software license, see the accompanying
5// file COPYING or http://www.opensource.org/licenses/mit-license.php.
6
7#ifndef BITCOIN_FEERATE_H
8#define BITCOIN_FEERATE_H
9
10#include <consensus/amount.h>
11#include <serialize.h>
12
13#include <cstdlib>
14#include <ostream>
15#include <string>
16#include <type_traits>
17
21class CFeeRate {
22private:
23 // unit is satoshis-per-1,000-bytes
25
26public:
30 constexpr CFeeRate() : nSatoshisPerK() {}
31 explicit constexpr CFeeRate(const Amount _nSatoshisPerK)
32 : nSatoshisPerK(_nSatoshisPerK) {}
33
38 CFeeRate(const Amount nFeePaid, size_t nBytes);
39
43 Amount GetFee(size_t nBytes) const;
44
49 Amount GetFeeCeiling(size_t nBytes) const;
50
54 Amount GetFeePerK() const { return GetFee(1000); }
55
59 friend constexpr bool operator==(const CFeeRate a, const CFeeRate b) {
60 return a.nSatoshisPerK == b.nSatoshisPerK;
61 }
62 friend constexpr bool operator!=(const CFeeRate a, const CFeeRate b) {
63 return !(a == b);
64 }
65
69 friend bool operator<(const CFeeRate &a, const CFeeRate &b) {
70 return a.nSatoshisPerK < b.nSatoshisPerK;
71 }
72 friend bool operator>(const CFeeRate &a, const CFeeRate &b) {
73 return a.nSatoshisPerK > b.nSatoshisPerK;
74 }
75 friend bool operator<=(const CFeeRate &a, const CFeeRate &b) {
76 return a.nSatoshisPerK <= b.nSatoshisPerK;
77 }
78 friend bool operator>=(const CFeeRate &a, const CFeeRate &b) {
79 return a.nSatoshisPerK >= b.nSatoshisPerK;
80 }
83 return *this;
84 }
85 std::string ToString() const;
86
87 SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.nSatoshisPerK); }
88};
89
90#endif // BITCOIN_FEERATE_H
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
constexpr CFeeRate()
Fee rate of 0 satoshis per kB.
Definition: feerate.h:30
friend constexpr bool operator!=(const CFeeRate a, const CFeeRate b)
Definition: feerate.h:62
friend bool operator>=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:78
std::string ToString() const
Definition: feerate.cpp:57
SERIALIZE_METHODS(CFeeRate, obj)
Definition: feerate.h:87
constexpr CFeeRate(const Amount _nSatoshisPerK)
Definition: feerate.h:31
friend bool operator>(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:72
Amount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:54
friend constexpr bool operator==(const CFeeRate a, const CFeeRate b)
Equality.
Definition: feerate.h:59
friend bool operator<(const CFeeRate &a, const CFeeRate &b)
Comparison.
Definition: feerate.h:69
Amount GetFee(size_t nBytes) const
Return the fee in satoshis for the given size in bytes.
Definition: feerate.cpp:49
Amount nSatoshisPerK
Definition: feerate.h:24
Amount GetFeeCeiling(size_t nBytes) const
Return the ceiling of a fee calculation in satoshis for the given size in bytes.
Definition: feerate.cpp:53
friend bool operator<=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:75
CFeeRate & operator+=(const CFeeRate &a)
Definition: feerate.h:81
#define READWRITE(...)
Definition: serialize.h:166
Definition: amount.h:19