LCOV - code coverage report
Current view: top level - src/policy - feerate.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 23 23 100.0 %
Date: 2022-04-21 14:51:19 Functions: 3 3 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 13 14 92.9 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2009-2010 Satoshi Nakamoto
#       2                 :            : // Copyright (c) 2009-2021 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 <policy/feerate.h>
#       7                 :            : 
#       8                 :            : #include <tinyformat.h>
#       9                 :            : 
#      10                 :            : #include <cmath>
#      11                 :            : 
#      12                 :            : CFeeRate::CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes)
#      13                 :     134863 : {
#      14                 :     134863 :     const int64_t nSize{num_bytes};
#      15                 :            : 
#      16         [ +  + ]:     134863 :     if (nSize > 0) {
#      17                 :     134857 :         nSatoshisPerK = nFeePaid * 1000 / nSize;
#      18                 :     134857 :     } else {
#      19                 :          6 :         nSatoshisPerK = 0;
#      20                 :          6 :     }
#      21                 :     134863 : }
#      22                 :            : 
#      23                 :            : CAmount CFeeRate::GetFee(uint32_t num_bytes) const
#      24                 :    2760431 : {
#      25                 :    2760431 :     const int64_t nSize{num_bytes};
#      26                 :            : 
#      27                 :            :     // Be explicit that we're converting from a double to int64_t (CAmount) here.
#      28                 :            :     // We've previously had issues with the silent double->int64_t conversion.
#      29                 :    2760431 :     CAmount nFee{static_cast<CAmount>(std::ceil(nSatoshisPerK * nSize / 1000.0))};
#      30                 :            : 
#      31 [ +  + ][ +  + ]:    2760431 :     if (nFee == 0 && nSize != 0) {
#      32         [ -  + ]:     359895 :         if (nSatoshisPerK > 0) nFee = CAmount(1);
#      33         [ +  + ]:     359895 :         if (nSatoshisPerK < 0) nFee = CAmount(-1);
#      34                 :     359895 :     }
#      35                 :            : 
#      36                 :    2760431 :     return nFee;
#      37                 :    2760431 : }
#      38                 :            : 
#      39                 :            : std::string CFeeRate::ToString(const FeeEstimateMode& fee_estimate_mode) const
#      40                 :       4633 : {
#      41                 :       4633 :     switch (fee_estimate_mode) {
#      42         [ +  + ]:       3506 :     case FeeEstimateMode::SAT_VB: return strprintf("%d.%03d %s/vB", nSatoshisPerK / 1000, nSatoshisPerK % 1000, CURRENCY_ATOM);
#      43         [ +  + ]:       1127 :     default:                      return strprintf("%d.%08d %s/kvB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
#      44                 :       4633 :     }
#      45                 :       4633 : }

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a