Bitcoin Core  0.20.99
P2P Digital Currency
fees.cpp
Go to the documentation of this file.
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 std::string StringForFeeReason(FeeReason reason)
18 {
19  static const std::map<FeeReason, std::string> fee_reason_strings = {
20  {FeeReason::NONE, "None"},
21  {FeeReason::HALF_ESTIMATE, "Half Target 60% Threshold"},
22  {FeeReason::FULL_ESTIMATE, "Target 85% Threshold"},
23  {FeeReason::DOUBLE_ESTIMATE, "Double Target 95% Threshold"},
24  {FeeReason::CONSERVATIVE, "Conservative Double Target longer horizon"},
25  {FeeReason::MEMPOOL_MIN, "Mempool Min Fee"},
26  {FeeReason::PAYTXFEE, "PayTxFee set"},
27  {FeeReason::FALLBACK, "Fallback fee"},
28  {FeeReason::REQUIRED, "Minimum Required Fee"},
29  };
30  auto reason_string = fee_reason_strings.find(reason);
31 
32  if (reason_string == fee_reason_strings.end()) return "Unknown";
33 
34  return reason_string->second;
35 }
36 
37 const std::vector<std::pair<std::string, FeeEstimateMode>>& FeeModeMap()
38 {
39  static const std::vector<std::pair<std::string, FeeEstimateMode>> FEE_MODES = {
40  {"unset", FeeEstimateMode::UNSET},
41  {"economical", FeeEstimateMode::ECONOMICAL},
42  {"conservative", FeeEstimateMode::CONSERVATIVE},
45  };
46  return FEE_MODES;
47 }
48 
49 std::string FeeModes(const std::string& delimiter)
50 {
51  return Join(FeeModeMap(), delimiter, [&](const std::pair<std::string, FeeEstimateMode>& i) { return i.first; });
52 }
53 
54 bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode)
55 {
56  auto searchkey = ToUpper(mode_string);
57  for (const auto& pair : FeeModeMap()) {
58  if (ToUpper(pair.first) == searchkey) {
59  fee_estimate_mode = pair.second;
60  return true;
61  }
62  }
63  return false;
64 }
std::string ToUpper(const std::string &str)
Returns the uppercase equivalent of the given string.
auto Join(const std::vector< T > &list, const BaseType &separator, UnaryOp unary_op) -> decltype(unary_op(list.at(0)))
Join a list of items.
Definition: string.h:34
const std::vector< std::pair< std::string, FeeEstimateMode > > & FeeModeMap()
Definition: fees.cpp:37
Force estimateSmartFee to use non-conservative estimates.
Force estimateSmartFee to use conservative estimates.
const std::string CURRENCY_ATOM
Definition: feerate.h:15
FeeEstimateMode
Definition: feerate.h:18
const std::string CURRENCY_UNIT
Definition: feerate.h:14
FeeReason
Definition: fees.h:36
Use explicit BTC/kB fee given in coin control.
std::string FeeModes(const std::string &delimiter)
Definition: fees.cpp:49
Use default settings based on other criteria.
Use explicit sat/B fee given in coin control.
bool FeeModeFromString(const std::string &mode_string, FeeEstimateMode &fee_estimate_mode)
Definition: fees.cpp:54
std::string StringForFeeReason(FeeReason reason)
Definition: fees.cpp:17