Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
policy
feerate.cpp
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
#include <
consensus/amount.h
>
7
#include <
policy/feerate.h
>
8
#include <
tinyformat.h
>
9
10
11
CFeeRate::CFeeRate
(
const
CAmount
& nFeePaid, int32_t virtual_bytes)
12
{
13
if
(virtual_bytes > 0) {
14
m_feerate
=
FeePerVSize
(nFeePaid, virtual_bytes);
15
}
else
{
16
m_feerate
=
FeePerVSize
();
17
}
18
}
19
20
CAmount
CFeeRate::GetFee
(int32_t virtual_bytes)
const
21
{
22
Assume
(virtual_bytes >= 0);
23
if
(
m_feerate
.IsEmpty()) {
return
CAmount
(0);}
24
CAmount
nFee =
CAmount
(
m_feerate
.EvaluateFeeUp(virtual_bytes));
25
if
(nFee == 0 && virtual_bytes != 0 &&
m_feerate
.fee < 0)
return
CAmount
(-1);
26
return
nFee;
27
}
28
29
std::string
CFeeRate::ToString
(
FeeRateFormat
fee_rate_format)
const
30
{
31
const
CAmount
feerate_per_kvb{
GetFeePerK
()};
32
switch
(fee_rate_format) {
33
case
FeeRateFormat::BTC_KVB
:
return
strprintf
(
"%d.%08d %s/kvB"
, feerate_per_kvb /
COIN
, feerate_per_kvb %
COIN
,
CURRENCY_UNIT
);
34
case
FeeRateFormat::SAT_VB
:
return
strprintf
(
"%d.%03d %s/vB"
, feerate_per_kvb / 1000, feerate_per_kvb % 1000,
CURRENCY_ATOM
);
35
}
// no default case, so the compiler can warn about missing cases
36
assert
(
false
);
37
}
amount.h
CAmount
int64_t CAmount
Amount in satoshis (Can be negative).
Definition
amount.h:12
COIN
static constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition
amount.h:15
Assume
#define Assume(val)
Assume is the identity function.
Definition
check.h:125
CFeeRate::ToString
std::string ToString(FeeRateFormat fee_rate_format=FeeRateFormat::BTC_KVB) const
Definition
feerate.cpp:29
CFeeRate::CFeeRate
CFeeRate()=default
Fee rate of 0 satoshis per 0 vB.
CFeeRate::m_feerate
FeePerVSize m_feerate
Fee rate in sats/vB (satoshis per N virtualbytes).
Definition
feerate.h:35
CFeeRate::GetFeePerK
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
Definition
feerate.h:62
CFeeRate::GetFee
CAmount GetFee(int32_t virtual_bytes) const
Return the fee in satoshis for the given vsize in vbytes.
Definition
feerate.cpp:20
FeePerVSize
FeePerUnit< VSizeTag > FeePerVSize
Definition
feefrac.h:252
feerate.h
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
tinyformat.h
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition
tinyformat.h:1172
assert
assert(!tx.IsCoinBase())
Generated on
for Bitcoin Core by
1.17.0