LCOV - code coverage report
Current view: top level - src/util - fees.h (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 100.0 % 7 7
Test Date: 2026-08-25 06:30:02 Functions: 100.0 % 2 2
Branches: 100.0 % 4 4

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) The Bitcoin Core developers
       2                 :             : // Distributed under the MIT software license, see the accompanying
       3                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4                 :             : 
       5                 :             : #ifndef BITCOIN_UTIL_FEES_H
       6                 :             : #define BITCOIN_UTIL_FEES_H
       7                 :             : 
       8                 :             : #include <attributes.h>
       9                 :             : #include <util/expected.h>
      10                 :             : #include <util/feefrac.h>
      11                 :             : 
      12                 :             : #include <string>
      13                 :             : #include <string_view>
      14                 :             : #include <utility>
      15                 :             : 
      16                 :             : /* Used to determine type of fee estimation requested */
      17                 :             : enum class FeeEstimateMode {
      18                 :             :     UNSET,        //!< Use default settings based on other criteria
      19                 :             :     ECONOMICAL,   //!< Force Fee rate estimator to return non-conservative estimates
      20                 :             :     CONSERVATIVE, //!< Force Fee rate estimator to return conservative estimates
      21                 :             : };
      22                 :             : 
      23                 :             : /* Used to determine the reason a wallet selected a transaction fee rate */
      24                 :             : enum class FeeReason {
      25                 :             :     FEE_RATE_ESTIMATOR,
      26                 :             :     MEMPOOL_MIN,
      27                 :             :     USER_SPECIFIED,
      28                 :             :     FALLBACK,
      29                 :             :     REQUIRED,
      30                 :             : };
      31                 :             : 
      32                 :             : /**
      33                 :             :  * @enum FeeRateEstimatorType
      34                 :             :  * Identifier for fee rate estimator.
      35                 :             :  */
      36                 :             : enum class FeeRateEstimatorType {
      37                 :             :     NONE,
      38                 :             :     BLOCK_POLICY,
      39                 :             :     MEMPOOL_POLICY,
      40                 :             : };
      41                 :             : 
      42                 :             : /**
      43                 :             :  * @struct FeeRateEstimation
      44                 :             :  * A successful fee rate estimate returned by a fee rate estimator.
      45                 :             :  */
      46                 :             : struct FeeRateEstimation {
      47                 :             :     //! This identifies which fee rate estimator is providing this feerate estimate
      48                 :             :     FeeRateEstimatorType feerate_estimator;
      49                 :             :     //! Fee rate sufficient for confirmation within target.
      50                 :             :     FeePerVSize feerate;
      51                 :             :     //! The returned confirmation target for the estimate.
      52                 :             :     int returned_target;
      53                 :             :     /**
      54                 :             :      * Compare two FeeRateEstimation objects based on fee rate
      55                 :             :      * @param other The other FeeRateEstimation object to compare with
      56                 :             :      * @return strong ordering of either less, greater or equal; based on feerate ratio comparison.
      57                 :             :      */
      58                 :        3091 :     auto operator<=>(const FeeRateEstimation& other) const
      59                 :             :     {
      60         [ +  + ]:        3091 :         return ByRatio{feerate} <=> ByRatio{other.feerate};
      61                 :             :     }
      62                 :             : };
      63                 :             : 
      64                 :             : /**
      65                 :             :  * @struct FeeRateEstimationError
      66                 :             :  * A failed fee rate estimation, carrying the zero-value estimation that
      67                 :             :  * identifies the estimator and target alongside the error reason.
      68                 :             :  */
      69                 :       17633 : struct FeeRateEstimationError {
      70                 :             :     FeeRateEstimation estimation;
      71                 :             :     std::string reason;
      72                 :             : };
      73                 :             : 
      74                 :             : /**
      75                 :             :  * Build a fee rate estimation error result: a zero-value estimation
      76                 :             :  * identifying the estimator and target, alongside the error message.
      77                 :             :  */
      78                 :        3539 : inline util::Unexpected<FeeRateEstimationError> EstimationError(FeeRateEstimatorType estimator, int returned_target, std::string error)
      79                 :             : {
      80                 :        3539 :     return util::Unexpected{FeeRateEstimationError{{estimator, FeePerVSize{0, 0}, returned_target}, std::move(error)}};
      81                 :             : }
      82                 :             : 
      83                 :             : /**
      84                 :             :  * Return the estimation carried by a fee rate estimate result: the
      85                 :             :  * successful estimation, or the error's zero-value estimation.
      86                 :             :  */
      87                 :        3070 : inline const FeeRateEstimation& FeeRateEstimationRef(const util::Expected<FeeRateEstimation, FeeRateEstimationError>& result LIFETIMEBOUND)
      88                 :             : {
      89         [ +  + ]:        3070 :     return result ? *result : result.error().estimation;
      90                 :             : }
      91                 :             : 
      92                 :             : std::string_view FeeRateEstimatorTypeToString(FeeRateEstimatorType feerate_estimator_type);
      93                 :             : FeeRateEstimatorType FeeRateEstimatorTypeFromString(std::string_view feerate_estimator_type);
      94                 :             : 
      95                 :             : #endif // BITCOIN_UTIL_FEES_H
        

Generated by: LCOV version 2.0-1