/root/bitcoin/src/policy/feerate.h
Line | Count | Source |
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 | | |
17 | | const std::string CURRENCY_UNIT = "BTC"; // One formatted unit |
18 | | const std::string CURRENCY_ATOM = "sat"; // One indivisible minimum value unit |
19 | | |
20 | | /* Used to determine type of fee estimation requested */ |
21 | | enum class FeeEstimateMode { |
22 | | UNSET, //!< Use default settings based on other criteria |
23 | | ECONOMICAL, //!< Force estimateSmartFee to use non-conservative estimates |
24 | | CONSERVATIVE, //!< Force estimateSmartFee to use conservative estimates |
25 | | BTC_KVB, //!< Use BTC/kvB fee rate unit |
26 | | SAT_VB, //!< Use sat/vB fee rate unit |
27 | | }; |
28 | | |
29 | | /** |
30 | | * Fee rate in satoshis per kilovirtualbyte: CAmount / kvB |
31 | | */ |
32 | | class CFeeRate |
33 | | { |
34 | | private: |
35 | | /** Fee rate in sat/kvB (satoshis per 1000 virtualbytes) */ |
36 | | CAmount nSatoshisPerK; |
37 | | |
38 | | public: |
39 | | /** Fee rate of 0 satoshis per kvB */ |
40 | 0 | CFeeRate() : nSatoshisPerK(0) { } |
41 | | template<std::integral I> // Disallow silent float -> int conversion |
42 | 0 | explicit CFeeRate(const I _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { |
43 | 0 | } Unexecuted instantiation: _ZN8CFeeRateC2ITkSt8integrallEET_ Unexecuted instantiation: _ZN8CFeeRateC2ITkSt8integraljEET_ Unexecuted instantiation: _ZN8CFeeRateC2ITkSt8integraliEET_ Unexecuted instantiation: _ZN8CFeeRateC2ITkSt8integralxEET_ |
44 | | |
45 | | /** |
46 | | * Construct a fee rate from a fee in satoshis and a vsize in vB. |
47 | | * |
48 | | * param@[in] nFeePaid The fee paid by a transaction, in satoshis |
49 | | * param@[in] num_bytes The vsize of a transaction, in vbytes |
50 | | */ |
51 | | CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes); |
52 | | |
53 | | /** |
54 | | * Return the fee in satoshis for the given vsize in vbytes. |
55 | | * If the calculated fee would have fractional satoshis, then the |
56 | | * returned fee will always be rounded up to the nearest satoshi. |
57 | | */ |
58 | | CAmount GetFee(uint32_t num_bytes) const; |
59 | | |
60 | | /** |
61 | | * Return the fee in satoshis for a vsize of 1000 vbytes |
62 | | */ |
63 | 0 | CAmount GetFeePerK() const { return nSatoshisPerK; } |
64 | 0 | friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; } |
65 | 0 | friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; } |
66 | 0 | friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; } |
67 | 0 | friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; } |
68 | 0 | friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; } |
69 | 0 | friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; } |
70 | 0 | CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; } |
71 | | std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KVB) const; |
72 | 0 | friend CFeeRate operator*(const CFeeRate& f, int a) { return CFeeRate(a * f.nSatoshisPerK); } |
73 | 0 | friend CFeeRate operator*(int a, const CFeeRate& f) { return CFeeRate(a * f.nSatoshisPerK); } |
74 | | |
75 | 0 | SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.nSatoshisPerK); } Unexecuted instantiation: _ZN8CFeeRate16SerializationOpsI10DataStreamS_17ActionUnserializeEEvRT0_RT_T1_ Unexecuted instantiation: _ZN8CFeeRate16SerializationOpsI10DataStreamKS_15ActionSerializeEEvRT0_RT_T1_ |
76 | | }; |
77 | | |
78 | | #endif // BITCOIN_POLICY_FEERATE_H |