Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
policy
feerate.h
Go to the documentation of this file.
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-present 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
#include <
util/feefrac.h
>
12
#include <
util/fees.h
>
13
14
15
#include <cstdint>
16
#include <string>
17
#include <type_traits>
18
19
inline
const
std::string
CURRENCY_UNIT
=
"BTC"
;
// One formatted unit
20
inline
const
std::string
CURRENCY_ATOM
=
"sat"
;
// One indivisible minimum value unit
21
22
enum class
FeeRateFormat
{
23
BTC_KVB
,
24
SAT_VB
,
25
};
26
31
class
CFeeRate
32
{
33
private
:
35
FeePerVSize
m_feerate
;
36
37
public
:
39
CFeeRate
() =
default
;
40
template
<std::
int
egral I>
// Disallow silent float -> int conversion
41
explicit
constexpr
CFeeRate
(
const
I m_feerate_kvb) :
m_feerate
(
FeePerVSize
(m_feerate_kvb, 1000)) {}
42
48
CFeeRate
(
const
CAmount
& nFeePaid, int32_t virtual_bytes);
49
57
explicit
CFeeRate
(
const
FeePerVSize
& feerate) :
m_feerate
{feerate.size > 0 ? feerate :
FeePerVSize
{}} {}
58
64
CAmount
GetFee
(int32_t virtual_bytes)
const
;
65
66
FeePerVSize
GetFeePerVSize
()
const
{
return
m_feerate
; }
67
71
CAmount
GetFeePerK
()
const
{
return
CAmount
(
m_feerate
.
EvaluateFeeDown
(1000)); }
72
friend
std::strong_ordering
operator<=>
(
const
CFeeRate
& a,
const
CFeeRate
& b)
noexcept
73
{
74
return
ByRatio
{a.m_feerate} <=>
ByRatio
{b.m_feerate};
75
}
76
friend
bool
operator==
(
const
CFeeRate
& a,
const
CFeeRate
& b)
noexcept
77
{
78
return
ByRatio
{a.m_feerate} ==
ByRatio
{b.m_feerate};
79
}
80
CFeeRate
&
operator+=
(
const
CFeeRate
& a) {
81
m_feerate
=
FeePerVSize
(
GetFeePerK
() + a.
GetFeePerK
(), 1000);
82
return
*
this
;
83
}
84
std::string
ToString
(
FeeRateFormat
fee_rate_format =
FeeRateFormat::BTC_KVB
)
const
;
85
friend
CFeeRate
operator*
(
const
CFeeRate
& f,
int
a) {
return
CFeeRate
(a * f.
m_feerate
.
fee
, f.
m_feerate
.
size
); }
86
friend
CFeeRate
operator*
(
int
a,
const
CFeeRate
& f) {
return
CFeeRate
(a * f.
m_feerate
.
fee
, f.
m_feerate
.
size
); }
87
88
SERIALIZE_METHODS
(
CFeeRate
, obj) {
READWRITE
(obj.m_feerate.fee, obj.m_feerate.size); }
89
};
90
91
#endif
// BITCOIN_POLICY_FEERATE_H
amount.h
CAmount
int64_t CAmount
Amount in satoshis (Can be negative).
Definition
amount.h:12
ToString
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition
string.h:250
ByRatio
Wrapper around FeeFrac & derived types, which adds a feerate-based ordering which treats equal-feerat...
Definition
feefrac.h:218
CFeeRate::CFeeRate
CFeeRate(const FeePerVSize &feerate)
Construct from a fee rate expressed as FeePerVSize.
Definition
feerate.h:57
CFeeRate::CFeeRate
CFeeRate()=default
Fee rate of 0 satoshis per 0 vB.
CFeeRate::operator==
friend bool operator==(const CFeeRate &a, const CFeeRate &b) noexcept
Definition
feerate.h:76
CFeeRate::operator*
friend CFeeRate operator*(int a, const CFeeRate &f)
Definition
feerate.h:86
CFeeRate::m_feerate
FeePerVSize m_feerate
Fee rate in sats/vB (satoshis per N virtualbytes).
Definition
feerate.h:35
CFeeRate::CFeeRate
constexpr CFeeRate(const I m_feerate_kvb)
Definition
feerate.h:41
CFeeRate::SERIALIZE_METHODS
SERIALIZE_METHODS(CFeeRate, obj)
Definition
feerate.h:88
CFeeRate::GetFeePerVSize
FeePerVSize GetFeePerVSize() const
Definition
feerate.h:66
CFeeRate::operator*
friend CFeeRate operator*(const CFeeRate &f, int a)
Definition
feerate.h:85
CFeeRate::operator<=>
friend std::strong_ordering operator<=>(const CFeeRate &a, const CFeeRate &b) noexcept
Definition
feerate.h:72
CFeeRate::GetFeePerK
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
Definition
feerate.h:71
CFeeRate::GetFee
CAmount GetFee(int32_t virtual_bytes) const
Return the fee in satoshis for the given vsize in vbytes.
Definition
feerate.cpp:21
CFeeRate::operator+=
CFeeRate & operator+=(const CFeeRate &a)
Definition
feerate.h:80
feefrac.h
FeePerVSize
FeePerUnit< VSizeTag > FeePerVSize
Definition
feefrac.h:204
CURRENCY_ATOM
const std::string CURRENCY_ATOM
Definition
feerate.h:20
FeeRateFormat
FeeRateFormat
Definition
feerate.h:22
FeeRateFormat::BTC_KVB
@ BTC_KVB
Use BTC/kvB fee rate unit.
Definition
feerate.h:23
FeeRateFormat::SAT_VB
@ SAT_VB
Use sat/vB fee rate unit.
Definition
feerate.h:24
CURRENCY_UNIT
const std::string CURRENCY_UNIT
Definition
feerate.h:19
serialize.h
READWRITE
#define READWRITE(...)
Definition
serialize.h:148
FeeFrac::fee
int64_t fee
Definition
feefrac.h:88
FeeFrac::EvaluateFeeDown
int64_t EvaluateFeeDown(int32_t at_size) const noexcept
Compute the fee for a given size at_size using this object's feerate, rounding down.
Definition
feefrac.h:173
FeeFrac::size
int32_t size
Definition
feefrac.h:89
fees.h
Generated on
for Bitcoin Core by
1.18.0