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 13880 : std::string StringForFeeReason(FeeReason reason) 18 : { 19 13880 : static const std::map<FeeReason, std::string> fee_reason_strings = { 20 508 : {FeeReason::NONE, "None"}, 21 508 : {FeeReason::HALF_ESTIMATE, "Half Target 60% Threshold"}, 22 508 : {FeeReason::FULL_ESTIMATE, "Target 85% Threshold"}, 23 508 : {FeeReason::DOUBLE_ESTIMATE, "Double Target 95% Threshold"}, 24 508 : {FeeReason::CONSERVATIVE, "Conservative Double Target longer horizon"}, 25 508 : {FeeReason::MEMPOOL_MIN, "Mempool Min Fee"}, 26 508 : {FeeReason::PAYTXFEE, "PayTxFee set"}, 27 508 : {FeeReason::FALLBACK, "Fallback fee"}, 28 508 : {FeeReason::REQUIRED, "Minimum Required Fee"}, 29 : }; 30 13880 : auto reason_string = fee_reason_strings.find(reason); 31 : 32 13880 : if (reason_string == fee_reason_strings.end()) return "Unknown"; 33 : 34 13880 : return reason_string->second; 35 13880 : } 36 : 37 38737 : const std::vector<std::pair<std::string, FeeEstimateMode>>& FeeModeMap() 38 : { 39 38737 : static const std::vector<std::pair<std::string, FeeEstimateMode>> FEE_MODES = { 40 3069 : {"unset", FeeEstimateMode::UNSET}, 41 3069 : {"economical", FeeEstimateMode::ECONOMICAL}, 42 3069 : {"conservative", FeeEstimateMode::CONSERVATIVE}, 43 : }; 44 38737 : return FEE_MODES; 45 0 : } 46 : 47 38399 : std::string FeeModes(const std::string& delimiter) 48 : { 49 153596 : return Join(FeeModeMap(), delimiter, [&](const std::pair<std::string, FeeEstimateMode>& i) { return i.first; }); 50 : } 51 : 52 129 : std::string InvalidEstimateModeErrorMessage() 53 : { 54 129 : return "Invalid estimate_mode parameter, must be one of: \"" + FeeModes("\", \"") + "\""; 55 0 : } 56 : 57 338 : bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode) 58 : { 59 338 : auto searchkey = ToUpper(mode_string); 60 973 : for (const auto& pair : FeeModeMap()) { 61 844 : if (ToUpper(pair.first) == searchkey) { 62 209 : fee_estimate_mode = pair.second; 63 209 : return true; 64 : } 65 : } 66 129 : return false; 67 338 : }