Branch data Line data Source code
1 : : // Copyright (c) 2009-2010 Satoshi Nakamoto
2 : : // Copyright (c) 2009-2022 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 <common/messages.h>
7 : :
8 : : #include <common/types.h>
9 : : #include <policy/fees/block_policy_estimator.h>
10 : : #include <node/types.h>
11 : : #include <tinyformat.h>
12 : : #include <util/strencodings.h>
13 : : #include <util/string.h>
14 : : #include <util/translation.h>
15 : :
16 : : #include <cassert>
17 : : #include <map>
18 : : #include <string>
19 : : #include <string_view>
20 : : #include <utility>
21 : : #include <vector>
22 : :
23 : : using node::TransactionError;
24 : : using util::Join;
25 : :
26 : : namespace common {
27 : 3442 : std::string StringForFeeReason(FeeReason reason)
28 : : {
29 : 3442 : static const std::map<FeeReason, std::string> fee_reason_strings = {
30 [ + - ]: 114 : {FeeReason::NONE, "None"},
31 : 114 : {FeeReason::HALF_ESTIMATE, "Half Target 60% Threshold"},
32 : 114 : {FeeReason::FULL_ESTIMATE, "Target 85% Threshold"},
33 : 114 : {FeeReason::DOUBLE_ESTIMATE, "Double Target 95% Threshold"},
34 : 114 : {FeeReason::CONSERVATIVE, "Conservative Double Target longer horizon"},
35 : 114 : {FeeReason::MEMPOOL_MIN, "Mempool Min Fee"},
36 : 114 : {FeeReason::PAYTXFEE, "PayTxFee set"},
37 : 114 : {FeeReason::FALLBACK, "Fallback fee"},
38 : 114 : {FeeReason::REQUIRED, "Minimum Required Fee"},
39 [ + + + - : 5749 : };
+ + - - ]
40 : 3442 : auto reason_string = fee_reason_strings.find(reason);
41 : :
42 [ - + ]: 3442 : if (reason_string == fee_reason_strings.end()) return "Unknown";
43 : :
44 [ - + ]: 3442 : return reason_string->second;
45 [ + - + - : 1026 : }
+ - + - +
- + - + -
+ - - + -
- ]
46 : :
47 : 26897 : const std::vector<std::pair<std::string, FeeEstimateMode>>& FeeModeMap()
48 : : {
49 : 26897 : static const std::vector<std::pair<std::string, FeeEstimateMode>> FEE_MODES = {
50 [ + - ]: 1167 : {"unset", FeeEstimateMode::UNSET},
51 : 1167 : {"economical", FeeEstimateMode::ECONOMICAL},
52 : 1167 : {"conservative", FeeEstimateMode::CONSERVATIVE},
53 [ + + + - : 31565 : };
+ + - - ]
54 : 26897 : return FEE_MODES;
55 [ + - + - : 1167 : }
- + - - ]
56 : :
57 : 39960 : std::string FeeModeInfo(const std::pair<std::string, FeeEstimateMode>& mode, std::string& default_info)
58 : : {
59 [ + + + - ]: 39960 : switch (mode.second) {
60 : 13320 : case FeeEstimateMode::UNSET:
61 : 13320 : return strprintf("%s means no mode set (%s). \n", mode.first, default_info);
62 : 13320 : case FeeEstimateMode::ECONOMICAL:
63 : 13320 : return strprintf("%s estimates use a shorter time horizon, making them more\n"
64 : : "responsive to short-term drops in the prevailing fee market. This mode\n"
65 : 13320 : "potentially returns a lower fee rate estimate.\n", mode.first);
66 : 13320 : case FeeEstimateMode::CONSERVATIVE:
67 : 13320 : return strprintf("%s estimates use a longer time horizon, making them\n"
68 : : "less responsive to short-term drops in the prevailing fee market. This mode\n"
69 : 13320 : "potentially returns a higher fee rate estimate.\n", mode.first);
70 : 0 : default:
71 : : // Other modes apart from the ones handled are fee rate units; they should not be clarified.
72 : 0 : assert(false);
73 : : }
74 : : }
75 : :
76 : 13320 : std::string FeeModesDetail(std::string default_info)
77 : : {
78 [ + - ]: 13320 : std::string info;
79 [ + - + + ]: 53280 : for (const auto& fee_mode : FeeModeMap()) {
80 [ + - ]: 79920 : info += FeeModeInfo(fee_mode, default_info);
81 : : }
82 [ + - + - : 26640 : return strprintf("%s \n%s", FeeModes(", "), info);
+ - ]
83 : 13320 : }
84 : :
85 : 13348 : std::string FeeModes(const std::string& delimiter)
86 : : {
87 [ - + - + ]: 93436 : return Join(FeeModeMap(), delimiter, [&](const std::pair<std::string, FeeEstimateMode>& i) { return i.first; });
88 : : }
89 : :
90 : 28 : std::string InvalidEstimateModeErrorMessage()
91 : : {
92 [ + - + - ]: 56 : return "Invalid estimate_mode parameter, must be one of: \"" + FeeModes("\", \"") + "\"";
93 : : }
94 : :
95 : 229 : bool FeeModeFromString(std::string_view mode_string, FeeEstimateMode& fee_estimate_mode)
96 : : {
97 : 229 : auto searchkey = ToUpper(mode_string);
98 [ + - + + ]: 522 : for (const auto& pair : FeeModeMap()) {
99 [ - + + - : 494 : if (ToUpper(pair.first) == searchkey) {
+ + ]
100 : 201 : fee_estimate_mode = pair.second;
101 : 201 : return true;
102 : : }
103 : : }
104 : : return false;
105 : 229 : }
106 : :
107 : 15 : bilingual_str PSBTErrorString(PSBTError err)
108 : : {
109 [ - + + - : 15 : switch (err) {
- - - - ]
110 : 0 : case PSBTError::MISSING_INPUTS:
111 [ # # ]: 0 : return Untranslated("Inputs missing or spent");
112 : 14 : case PSBTError::SIGHASH_MISMATCH:
113 [ + - ]: 28 : return Untranslated("Specified sighash value does not match value stored in PSBT");
114 : 1 : case PSBTError::EXTERNAL_SIGNER_NOT_FOUND:
115 [ + - ]: 2 : return Untranslated("External signer not found");
116 : 0 : case PSBTError::EXTERNAL_SIGNER_FAILED:
117 [ # # ]: 0 : return Untranslated("External signer failed to sign");
118 : 0 : case PSBTError::UNSUPPORTED:
119 [ # # ]: 0 : return Untranslated("Signer does not support PSBT");
120 : 0 : case PSBTError::INCOMPLETE:
121 [ # # ]: 0 : return Untranslated("Input needs additional signatures or other data");
122 : 0 : case PSBTError::OK:
123 [ # # ]: 0 : return Untranslated("No errors");
124 : : // no default case, so the compiler can warn about missing cases
125 : : }
126 : 0 : assert(false);
127 : : }
128 : :
129 : 30 : bilingual_str TransactionErrorString(const TransactionError err)
130 : : {
131 [ - - + - : 30 : switch (err) {
- + + -
- ]
132 : 0 : case TransactionError::OK:
133 [ # # ]: 0 : return Untranslated("No error");
134 : 0 : case TransactionError::MISSING_INPUTS:
135 [ # # ]: 0 : return Untranslated("Inputs missing or spent");
136 : 3 : case TransactionError::ALREADY_IN_UTXO_SET:
137 [ + - ]: 6 : return Untranslated("Transaction outputs already in utxo set");
138 : 0 : case TransactionError::MEMPOOL_REJECTED:
139 [ # # ]: 0 : return Untranslated("Transaction rejected by mempool");
140 : 0 : case TransactionError::MEMPOOL_ERROR:
141 [ # # ]: 0 : return Untranslated("Mempool internal error");
142 : 22 : case TransactionError::MAX_FEE_EXCEEDED:
143 [ + - ]: 44 : return Untranslated("Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)");
144 : 5 : case TransactionError::MAX_BURN_EXCEEDED:
145 [ + - ]: 10 : return Untranslated("Unspendable output exceeds maximum configured by user (maxburnamount)");
146 : 0 : case TransactionError::INVALID_PACKAGE:
147 [ # # ]: 0 : return Untranslated("Transaction rejected due to invalid package");
148 : : // no default case, so the compiler can warn about missing cases
149 : : }
150 : 0 : assert(false);
151 : : }
152 : :
153 : 3 : bilingual_str ResolveErrMsg(const std::string& optname, const std::string& strBind)
154 : : {
155 : 3 : return strprintf(_("Cannot resolve -%s address: '%s'"), optname, strBind);
156 : : }
157 : :
158 : 9 : bilingual_str InvalidPortErrMsg(const std::string& optname, const std::string& invalid_value)
159 : : {
160 : 9 : return strprintf(_("Invalid port specified in %s: '%s'"), optname, invalid_value);
161 : : }
162 : :
163 : 6 : bilingual_str AmountHighWarn(const std::string& optname)
164 : : {
165 : 6 : return strprintf(_("%s is set very high!"), optname);
166 : : }
167 : :
168 : 0 : bilingual_str AmountErrMsg(const std::string& optname, const std::string& strValue)
169 : : {
170 : 0 : return strprintf(_("Invalid amount for -%s=<amount>: '%s'"), optname, strValue);
171 : : }
172 : : } // namespace common
|