LCOV - code coverage report
Current view: top level - src/policy - feerate.h (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 100.0 % 13 13
Test Date: 2024-11-04 05:10:19 Functions: - 0 0
Branches: 53.5 % 516 276

             Branch data     Line data    Source code
       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         [ +  + ]:        7234 :     CFeeRate() : nSatoshisPerK(0) { }
      41                 :             :     template<std::integral I> // Disallow silent float -> int conversion
      42   [ +  +  +  -  :     1122878 :     explicit CFeeRate(const I _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) {
           +  - ][ +  +  
             +  -  +  - ]
           [ +  +  +  + ]
           [ +  -  +  -  
             +  -  +  - ]
           [ +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
           - ][ +  -  +  
          -  +  -  +  -  
          +  -  +  -  -  
           - ][ +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  +  +  
             -  +  -  -  
           - ][ +  -  +  
          -  +  -  +  -  
          +  -  +  -  #  
                      # ]
      43                 :       24449 :     }
      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   [ -  +  +  -  :      645124 :     CAmount GetFeePerK() const { return nSatoshisPerK; }
             +  -  +  - ]
           [ +  +  #  # ]
           [ +  +  +  +  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
           [ +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  +  
           - ][ +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  -  
          -  -  +  -  #  
                      # ]
      64   [ +  +  #  # ]:       13744 :     friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
           [ +  +  +  + ]
           [ +  +  +  +  
             -  +  +  + ]
      65         [ +  + ]:       31201 :     friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
           [ +  +  +  + ]
           [ +  -  +  -  
                   +  - ]
      66 [ +  + ][ +  +  :        7119 :     friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; }
             +  +  +  + ]
           [ +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
           -  #  # ][ +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  -  +  +  -  
          +  -  -  +  -  
           + ][ +  -  +  
          -  -  +  +  -  
             -  +  +  - ]
      67 [ +  + ][ +  -  :        1616 :     friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; }
          +  +  +  +  +  
          +  +  +  +  +  
                   +  + ]
      68                 :             :     friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
      69   [ +  +  +  + ]:        3254 :     friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; }
                 [ +  + ]
      70                 :         236 :     CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
      71         [ +  - ]:        1219 :     std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KVB) const;
           [ +  -  +  - ]
           [ +  -  +  -  
                   +  - ]
      72   [ +  -  +  -  :           5 :     friend CFeeRate operator*(const CFeeRate& f, int a) { return CFeeRate(a * f.nSatoshisPerK); }
          +  -  +  -  +  
                      - ]
      73 [ +  + ][ +  -  :        4912 :     friend CFeeRate operator*(int a, const CFeeRate& f) { return CFeeRate(a * f.nSatoshisPerK); }
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
      74                 :             : 
      75                 :             :     SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.nSatoshisPerK); }
      76                 :             : };
      77                 :             : 
      78                 :             : #endif // BITCOIN_POLICY_FEERATE_H
        

Generated by: LCOV version 2.0-1