LCOV - code coverage report
Current view: top level - src/util - fees.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 34 35 97.1 %
Date: 2020-09-26 01:30:44 Functions: 5 5 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             : #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        2594 : std::string StringForFeeReason(FeeReason reason)
      18             : {
      19        3562 :     static const std::map<FeeReason, std::string> fee_reason_strings = {
      20         121 :         {FeeReason::NONE, "None"},
      21         121 :         {FeeReason::HALF_ESTIMATE, "Half Target 60% Threshold"},
      22         121 :         {FeeReason::FULL_ESTIMATE, "Target 85% Threshold"},
      23         121 :         {FeeReason::DOUBLE_ESTIMATE, "Double Target 95% Threshold"},
      24         121 :         {FeeReason::CONSERVATIVE, "Conservative Double Target longer horizon"},
      25         121 :         {FeeReason::MEMPOOL_MIN, "Mempool Min Fee"},
      26         121 :         {FeeReason::PAYTXFEE, "PayTxFee set"},
      27         121 :         {FeeReason::FALLBACK, "Fallback fee"},
      28         121 :         {FeeReason::REQUIRED, "Minimum Required Fee"},
      29             :     };
      30        2594 :     auto reason_string = fee_reason_strings.find(reason);
      31             : 
      32        2594 :     if (reason_string == fee_reason_strings.end()) return "Unknown";
      33             : 
      34        2594 :     return reason_string->second;
      35        2594 : }
      36             : 
      37        5690 : const std::vector<std::pair<std::string, FeeEstimateMode>>& FeeModeMap()
      38             : {
      39        7790 :     static const std::vector<std::pair<std::string, FeeEstimateMode>> FEE_MODES = {
      40         525 :         {"unset", FeeEstimateMode::UNSET},
      41         525 :         {"economical", FeeEstimateMode::ECONOMICAL},
      42         525 :         {"conservative", FeeEstimateMode::CONSERVATIVE},
      43         525 :         {(CURRENCY_UNIT + "/kB"), FeeEstimateMode::BTC_KB},
      44         525 :         {(CURRENCY_ATOM + "/B"), FeeEstimateMode::SAT_B},
      45             :     };
      46        5690 :     return FEE_MODES;
      47           0 : }
      48             : 
      49        5662 : std::string FeeModes(const std::string& delimiter)
      50             : {
      51       33972 :     return Join(FeeModeMap(), delimiter, [&](const std::pair<std::string, FeeEstimateMode>& i) { return i.first; });
      52             : }
      53             : 
      54          28 : bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode)
      55             : {
      56          28 :     auto searchkey = ToUpper(mode_string);
      57         149 :     for (const auto& pair : FeeModeMap()) {
      58         121 :         if (ToUpper(pair.first) == searchkey) {
      59          25 :             fee_estimate_mode = pair.second;
      60          25 :             return true;
      61             :         }
      62          96 :     }
      63           3 :     return false;
      64          28 : }

Generated by: LCOV version 1.15