Bitcoin Core 28.99.0
P2P Digital Currency
feerate.h
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-2022 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_POLICY_FEERATE_H
7#define BITCOIN_POLICY_FEERATE_H
8
9#include <consensus/amount.h>
10#include <serialize.h>
11
12
13#include <cstdint>
14#include <string>
15#include <type_traits>
16
17const std::string CURRENCY_UNIT = "BTC"; // One formatted unit
18const std::string CURRENCY_ATOM = "sat"; // One indivisible minimum value unit
19
20/* Used to determine type of fee estimation requested */
21enum class FeeEstimateMode {
22 UNSET,
25 BTC_KVB,
26 SAT_VB,
27};
28
33{
34private:
37
38public:
41 template<std::integral I> // Disallow silent float -> int conversion
42 explicit CFeeRate(const I _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) {
43 }
44
51 CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes);
52
58 CAmount GetFee(uint32_t num_bytes) const;
59
63 CAmount GetFeePerK() const { return nSatoshisPerK; }
64 friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
65 friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
66 friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; }
67 friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; }
68 friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
69 friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; }
70 CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
71 std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KVB) const;
72 friend CFeeRate operator*(const CFeeRate& f, int a) { return CFeeRate(a * f.nSatoshisPerK); }
73 friend CFeeRate operator*(int a, const CFeeRate& f) { return CFeeRate(a * f.nSatoshisPerK); }
74
75 SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.nSatoshisPerK); }
76};
77
78#endif // BITCOIN_POLICY_FEERATE_H
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
Definition: feerate.h:33
std::string ToString(const FeeEstimateMode &fee_estimate_mode=FeeEstimateMode::BTC_KVB) const
Definition: feerate.cpp:39
friend bool operator>=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:68
CAmount GetFee(uint32_t num_bytes) const
Return the fee in satoshis for the given vsize in vbytes.
Definition: feerate.cpp:23
friend CFeeRate operator*(int a, const CFeeRate &f)
Definition: feerate.h:73
CAmount nSatoshisPerK
Fee rate in sat/kvB (satoshis per 1000 virtualbytes)
Definition: feerate.h:36
SERIALIZE_METHODS(CFeeRate, obj)
Definition: feerate.h:75
friend CFeeRate operator*(const CFeeRate &f, int a)
Definition: feerate.h:72
friend bool operator==(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:66
friend bool operator>(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:65
friend bool operator<(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:64
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
Definition: feerate.h:63
friend bool operator!=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:69
CFeeRate(const I _nSatoshisPerK)
Definition: feerate.h:42
CFeeRate()
Fee rate of 0 satoshis per kvB.
Definition: feerate.h:40
friend bool operator<=(const CFeeRate &a, const CFeeRate &b)
Definition: feerate.h:67
CFeeRate & operator+=(const CFeeRate &a)
Definition: feerate.h:70
const std::string CURRENCY_ATOM
Definition: feerate.h:18
const std::string CURRENCY_UNIT
Definition: feerate.h:17
FeeEstimateMode
Definition: feerate.h:21
@ CONSERVATIVE
Force estimateSmartFee to use conservative estimates.
@ UNSET
Use default settings based on other criteria.
@ BTC_KVB
Use BTC/kvB fee rate unit.
@ ECONOMICAL
Force estimateSmartFee to use non-conservative estimates.
@ SAT_VB
Use sat/vB fee rate unit.
#define READWRITE(...)
Definition: serialize.h:156