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

          Line data    Source code
       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2019 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 <amount.h>
      10             : #include <serialize.h>
      11             : 
      12             : #include <string>
      13             : 
      14       40522 : const std::string CURRENCY_UNIT = "BTC"; // One formatted unit
      15       40522 : const std::string CURRENCY_ATOM = "sat"; // One indivisible minimum value unit
      16             : 
      17             : /* Used to determine type of fee estimation requested */
      18             : enum class FeeEstimateMode {
      19             :     UNSET,        //!< Use default settings based on other criteria
      20             :     ECONOMICAL,   //!< Force estimateSmartFee to use non-conservative estimates
      21             :     CONSERVATIVE, //!< Force estimateSmartFee to use conservative estimates
      22             :     BTC_KB,       //!< Use explicit BTC/kB fee given in coin control
      23             :     SAT_B,        //!< Use explicit sat/B fee given in coin control
      24             : };
      25             : 
      26             : /**
      27             :  * Fee rate in satoshis per kilobyte: CAmount / kB
      28             :  */
      29             : class CFeeRate
      30             : {
      31             : private:
      32             :     CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
      33             : 
      34             : public:
      35             :     /** Fee rate of 0 satoshis per kB */
      36      269990 :     CFeeRate() : nSatoshisPerK(0) { }
      37             :     template<typename I>
      38     1230616 :     explicit CFeeRate(const I _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) {
      39             :         // We've previously had bugs creep in from silent double->int conversion...
      40             :         static_assert(std::is_integral<I>::value, "CFeeRate should be used without floats");
      41     1230616 :     }
      42             :     /** Constructor for a fee rate in satoshis per kB. The size in bytes must not exceed (2^63 - 1)*/
      43             :     CFeeRate(const CAmount& nFeePaid, size_t nBytes);
      44             :     /**
      45             :      * Return the fee in satoshis for the given size in bytes.
      46             :      */
      47             :     CAmount GetFee(size_t nBytes) const;
      48             :     /**
      49             :      * Return the fee in satoshis for a size of 1000 bytes
      50             :      */
      51      555588 :     CAmount GetFeePerK() const { return GetFee(1000); }
      52       75555 :     friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
      53       42467 :     friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
      54       52892 :     friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; }
      55         335 :     friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; }
      56           2 :     friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
      57        5630 :     friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; }
      58        4389 :     CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
      59             :     std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KB) const;
      60             : 
      61             :     SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.nSatoshisPerK); }
      62             : };
      63             : 
      64             : #endif //  BITCOIN_POLICY_FEERATE_H

Generated by: LCOV version 1.15