LCOV - code coverage report
Current view: top level - src/util - fees.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 10 37 27.0 %
Date: 2023-11-12 01:39:15 Functions: 3 8 37.5 %
Branches: 9 60 15.0 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2                 :            : // Copyright (c) 2009-2020 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 <util/fees.h>
       7                 :            : 
       8                 :            : #include <policy/fees.h>
       9                 :            : #include <util/strencodings.h>
      10                 :            : #include <util/string.h>
      11                 :            : 
      12                 :            : #include <map>
      13                 :            : #include <string>
      14                 :            : #include <vector>
      15                 :            : #include <utility>
      16                 :            : 
      17         [ +  - ]:          2 : std::string StringForFeeReason(FeeReason reason)
      18         [ +  - ]:          2 : {
      19 [ #  # ][ #  # ]:          0 :     static const std::map<FeeReason, std::string> fee_reason_strings = {
                 [ #  # ]
      20         [ #  # ]:          0 :         {FeeReason::NONE, "None"},
      21         [ #  # ]:          0 :         {FeeReason::HALF_ESTIMATE, "Half Target 60% Threshold"},
      22         [ #  # ]:          0 :         {FeeReason::FULL_ESTIMATE, "Target 85% Threshold"},
      23         [ #  # ]:          0 :         {FeeReason::DOUBLE_ESTIMATE, "Double Target 95% Threshold"},
      24         [ #  # ]:          0 :         {FeeReason::CONSERVATIVE, "Conservative Double Target longer horizon"},
      25         [ #  # ]:          0 :         {FeeReason::MEMPOOL_MIN, "Mempool Min Fee"},
      26         [ #  # ]:          0 :         {FeeReason::PAYTXFEE, "PayTxFee set"},
      27         [ #  # ]:          0 :         {FeeReason::FALLBACK, "Fallback fee"},
      28         [ #  # ]:          0 :         {FeeReason::REQUIRED, "Minimum Required Fee"},
      29                 :            :     };
      30                 :          0 :     auto reason_string = fee_reason_strings.find(reason);
      31                 :            : 
      32 [ #  # ][ #  # ]:          0 :     if (reason_string == fee_reason_strings.end()) return "Unknown";
      33                 :            : 
      34                 :          0 :     return reason_string->second;
      35                 :          0 : }
      36                 :            : 
      37                 :          2 : const std::vector<std::pair<std::string, FeeEstimateMode>>& FeeModeMap()
      38                 :            : {
      39 [ +  + ][ -  + ]:          2 :     static const std::vector<std::pair<std::string, FeeEstimateMode>> FEE_MODES = {
                 [ +  - ]
      40         [ +  - ]:          1 :         {"unset", FeeEstimateMode::UNSET},
      41         [ +  - ]:          1 :         {"economical", FeeEstimateMode::ECONOMICAL},
      42         [ +  - ]:          1 :         {"conservative", FeeEstimateMode::CONSERVATIVE},
      43                 :            :     };
      44                 :          2 :     return FEE_MODES;
      45                 :          0 : }
      46                 :            : 
      47                 :          2 : std::string FeeModes(const std::string& delimiter)
      48                 :            : {
      49                 :          8 :     return Join(FeeModeMap(), delimiter, [&](const std::pair<std::string, FeeEstimateMode>& i) { return i.first; });
      50                 :            : }
      51                 :            : 
      52                 :          0 : std::string InvalidEstimateModeErrorMessage()
      53                 :            : {
      54 [ #  # ][ #  # ]:          0 :     return "Invalid estimate_mode parameter, must be one of: \"" + FeeModes("\", \"") + "\"";
         [ #  # ][ #  # ]
      55                 :          0 : }
      56                 :            : 
      57                 :          0 : bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode)
      58                 :            : {
      59                 :          0 :     auto searchkey = ToUpper(mode_string);
      60 [ #  # ][ #  # ]:          0 :     for (const auto& pair : FeeModeMap()) {
      61 [ #  # ][ #  # ]:          0 :         if (ToUpper(pair.first) == searchkey) {
      62                 :          0 :             fee_estimate_mode = pair.second;
      63                 :          0 :             return true;
      64                 :            :         }
      65                 :            :     }
      66                 :          0 :     return false;
      67                 :          0 : }

Generated by: LCOV version 1.14