LCOV - code coverage report
Current view: top level - src/policy - feerate.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 20 21 95.2 %
Date: 2020-09-26 01:30:44 Functions: 4 4 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2018 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      175742 : CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nBytes_)
      11       87871 : {
      12       87871 :     assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
      13             :     int64_t nSize = int64_t(nBytes_);
      14             : 
      15       87871 :     if (nSize > 0)
      16       87868 :         nSatoshisPerK = nFeePaid * 1000 / nSize;
      17             :     else
      18           3 :         nSatoshisPerK = 0;
      19      175742 : }
      20             : 
      21     3103202 : CAmount CFeeRate::GetFee(size_t nBytes_) const
      22             : {
      23     3103202 :     assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
      24             :     int64_t nSize = int64_t(nBytes_);
      25             : 
      26     3103202 :     CAmount nFee = nSatoshisPerK * nSize / 1000;
      27             : 
      28     3103202 :     if (nFee == 0 && nSize != 0) {
      29      317597 :         if (nSatoshisPerK > 0)
      30           1 :             nFee = CAmount(1);
      31      317597 :         if (nSatoshisPerK < 0)
      32           1 :             nFee = CAmount(-1);
      33             :     }
      34             : 
      35     3103203 :     return nFee;
      36             : }
      37             : 
      38         851 : std::string CFeeRate::ToString(const FeeEstimateMode& fee_estimate_mode) const
      39             : {
      40         851 :     switch (fee_estimate_mode) {
      41           0 :     case FeeEstimateMode::SAT_B:  return strprintf("%d.%03d %s/B", nSatoshisPerK / 1000, nSatoshisPerK % 1000, CURRENCY_ATOM);
      42         851 :     default:                      return strprintf("%d.%08d %s/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
      43             :     }
      44         851 : }

Generated by: LCOV version 1.15