Bitcoin ABC 0.34.2
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-present 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#include <util/feefrac.h>
13
14#include <cstdint>
15#include <cstdlib>
16#include <ostream>
17#include <string>
18#include <type_traits>
19
24class CFeeRate {
25private:
26 // unit is satoshis-per-N-vbytes
28
29public:
30 CFeeRate() = delete;
31 explicit CFeeRate(const Amount m_feerate_kvb)
32 : m_feerate(FeePerVSize(m_feerate_kvb / SATOSHI, 1000)) {}
33
43 CFeeRate(const Amount nFeePaid, int32_t virtual_bytes);
44
50 Amount GetFee(int32_t virtual_bytes) const;
51
56 return m_feerate.EvaluateFeeDown(1000) * SATOSHI;
57 }
58
59 friend std::weak_ordering operator<=>(const CFeeRate &a,
60 const CFeeRate &b) noexcept {
61 return FeeRateCompare(a.m_feerate, b.m_feerate);
62 }
63 friend bool operator==(const CFeeRate &a, const CFeeRate &b) noexcept {
64 return FeeRateCompare(a.m_feerate, b.m_feerate) ==
65 std::weak_ordering::equivalent;
66 }
68 m_feerate =
69 FeePerVSize((GetFeePerK() + a.GetFeePerK()) / SATOSHI, 1000);
70 return *this;
71 }
72
73 std::string ToString() const;
74
76 READWRITE(obj.m_feerate.fee, obj.m_feerate.size);
77 }
78};
79
80#endif // BITCOIN_FEERATE_H
static constexpr Amount SATOSHI
Definition: amount.h:153
Fee rate in satoshis per virtualbyte: Amount / vB the feerate is represented internally as FeeFrac.
Definition: feerate.h:24
friend std::weak_ordering operator<=>(const CFeeRate &a, const CFeeRate &b) noexcept
Definition: feerate.h:59
friend bool operator==(const CFeeRate &a, const CFeeRate &b) noexcept
Definition: feerate.h:63
Amount GetFee(int32_t virtual_bytes) const
Return the fee in satoshis for the given size in bytes.
Definition: feerate.cpp:23
CFeeRate()=delete
std::string ToString() const
Definition: feerate.cpp:43
FeePerVSize m_feerate
Definition: feerate.h:27
SERIALIZE_METHODS(CFeeRate, obj)
Definition: feerate.h:75
Amount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:55
CFeeRate(const Amount m_feerate_kvb)
Definition: feerate.h:31
CFeeRate & operator+=(const CFeeRate &a)
Definition: feerate.h:67
FeePerUnit< VSizeTag > FeePerVSize
Definition: feefrac.h:254
#define READWRITE(...)
Definition: serialize.h:176
Definition: amount.h:23
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:228