Coverage Report

Created: 2026-07-14 18:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/bitcoin/src/policy/feerate.cpp
Line
Count
Source
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
552k
{
13
552k
    if (virtual_bytes > 0) {
  Branch (13:9): [True: 552k, False: 0]
14
552k
        m_feerate = FeePerVSize(nFeePaid, virtual_bytes);
15
552k
    } else {
16
0
        m_feerate = FeePerVSize();
17
0
    }
18
552k
}
19
20
CAmount CFeeRate::GetFee(int32_t virtual_bytes) const
21
4.45M
{
22
4.45M
    Assume(virtual_bytes >= 0);
23
4.45M
    if (m_feerate.IsEmpty()) { return CAmount(0);}
  Branch (23:9): [True: 0, False: 4.45M]
24
4.45M
    CAmount nFee = CAmount(m_feerate.EvaluateFeeUp(virtual_bytes));
25
4.45M
    if (nFee == 0 && virtual_bytes != 0 && m_feerate.fee < 0) return CAmount(-1);
  Branch (25:9): [True: 1.04M, False: 3.41M]
  Branch (25:22): [True: 1.04M, False: 0]
  Branch (25:44): [True: 0, False: 1.04M]
26
4.45M
    return nFee;
27
4.45M
}
28
29
std::string CFeeRate::ToString(FeeRateFormat fee_rate_format) const
30
631
{
31
631
    const CAmount feerate_per_kvb{GetFeePerK()};
32
631
    switch (fee_rate_format) {
  Branch (32:13): [True: 0, False: 631]
33
523
    case FeeRateFormat::BTC_KVB: return strprintf("%d.%08d %s/kvB", feerate_per_kvb / COIN, feerate_per_kvb % COIN, CURRENCY_UNIT);
  Branch (33:5): [True: 523, False: 108]
34
108
    case FeeRateFormat::SAT_VB: return strprintf("%d.%03d %s/vB", feerate_per_kvb / 1000, feerate_per_kvb % 1000, CURRENCY_ATOM);
  Branch (34:5): [True: 108, False: 523]
35
631
    } // no default case, so the compiler can warn about missing cases
36
631
    assert(false);
  Branch (36:5): [Folded - Ignored]
37
0
}