Bitcoin Core 31.99.0
P2P Digital Currency
messages.cpp
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-present 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#include <common/types.h>
8#include <node/types.h>
10#include <tinyformat.h>
11#include <util/fees.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
24using util::Join;
25
26namespace common {
27std::string StringForFeeReason(FeeReason reason)
28{
29 static const std::map<FeeReason, std::string> fee_reason_strings = {
30 {FeeReason::NONE, "None"},
31 {FeeReason::HALF_ESTIMATE, "Half Target 60% Threshold"},
32 {FeeReason::FULL_ESTIMATE, "Target 85% Threshold"},
33 {FeeReason::DOUBLE_ESTIMATE, "Double Target 95% Threshold"},
34 {FeeReason::CONSERVATIVE, "Conservative Double Target longer horizon"},
35 {FeeReason::MEMPOOL_MIN, "Mempool Min Fee"},
36 {FeeReason::FALLBACK, "Fallback fee"},
37 {FeeReason::REQUIRED, "Minimum Required Fee"},
38 };
39 auto reason_string = fee_reason_strings.find(reason);
40
41 if (reason_string == fee_reason_strings.end()) return "Unknown";
42
43 return reason_string->second;
44}
45
46const std::vector<std::pair<std::string, FeeEstimateMode>>& FeeModeMap()
47{
48 static const std::vector<std::pair<std::string, FeeEstimateMode>> FEE_MODES = {
49 {"unset", FeeEstimateMode::UNSET},
50 {"economical", FeeEstimateMode::ECONOMICAL},
51 {"conservative", FeeEstimateMode::CONSERVATIVE},
52 };
53 return FEE_MODES;
54}
55
56std::string FeeModeInfo(const std::pair<std::string, FeeEstimateMode>& mode, std::string& default_info)
57{
58 switch (mode.second) {
60 return strprintf("%s means no mode set (%s). \n", mode.first, default_info);
62 return strprintf("%s estimates use a shorter time horizon, making them more\n"
63 "responsive to short-term drops in the prevailing fee market. This mode\n"
64 "potentially returns a lower fee rate estimate.\n", mode.first);
66 return strprintf("%s estimates use a longer time horizon, making them\n"
67 "less responsive to short-term drops in the prevailing fee market. This mode\n"
68 "potentially returns a higher fee rate estimate.\n", mode.first);
69 } // no default case, so the compiler can warn about missing cases
70 assert(false);
71}
72
73std::string FeeModesDetail(std::string default_info)
74{
75 std::string info;
76 for (const auto& fee_mode : FeeModeMap()) {
77 info += FeeModeInfo(fee_mode, default_info);
78 }
79 return strprintf("%s \n%s", FeeModes(", "), info);
80}
81
82std::string FeeModes(const std::string& delimiter)
83{
84 return Join(FeeModeMap(), delimiter, [&](const std::pair<std::string, FeeEstimateMode>& i) { return i.first; });
85}
86
88{
89 return "Invalid estimate_mode parameter, must be one of: \"" + FeeModes("\", \"") + "\"";
90}
91
92bool FeeModeFromString(std::string_view mode_string, FeeEstimateMode& fee_estimate_mode)
93{
94 auto searchkey = ToUpper(mode_string);
95 for (const auto& pair : FeeModeMap()) {
96 if (ToUpper(pair.first) == searchkey) {
97 fee_estimate_mode = pair.second;
98 return true;
99 }
100 }
101 return false;
102}
103
105{
106 switch (err) {
108 return Untranslated("Inputs missing or spent");
110 return Untranslated("Specified sighash value does not match value stored in PSBT");
112 return Untranslated("External signer not found");
114 return Untranslated("External signer failed to sign");
116 return Untranslated("Signer does not support PSBT");
118 return Untranslated("Input needs additional signatures or other data");
119 case PSBTError::OK:
120 return Untranslated("No errors");
121 } // no default case, so the compiler can warn about missing cases
122 assert(false);
123}
124
126{
127 switch (err) {
128 case TransactionError::OK:
129 return Untranslated("No error");
130 case TransactionError::MISSING_INPUTS:
131 return Untranslated("Inputs missing or spent");
132 case TransactionError::ALREADY_IN_UTXO_SET:
133 return Untranslated("Transaction outputs already in utxo set");
134 case TransactionError::MEMPOOL_REJECTED:
135 return Untranslated("Transaction rejected by mempool");
136 case TransactionError::MEMPOOL_ERROR:
137 return Untranslated("Mempool internal error");
138 case TransactionError::MAX_FEE_EXCEEDED:
139 return Untranslated("Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)");
140 case TransactionError::MAX_BURN_EXCEEDED:
141 return Untranslated("Unspendable output exceeds maximum configured by user (maxburnamount)");
142 case TransactionError::INVALID_PACKAGE:
143 return Untranslated("Transaction rejected due to invalid package");
144 } // no default case, so the compiler can warn about missing cases
145 assert(false);
146}
147
148bilingual_str ResolveErrMsg(const std::string& optname, const std::string& strBind)
149{
150 return strprintf(_("Cannot resolve -%s address: '%s'"), optname, strBind);
151}
152
153bilingual_str InvalidPortErrMsg(const std::string& optname, const std::string& invalid_value)
154{
155 return strprintf(_("Invalid port specified in %s: '%s'"), optname, invalid_value);
156}
157
158bilingual_str AmountHighWarn(const std::string& optname)
159{
160 return strprintf(_("%s is set very high!"), optname);
161}
162
163bilingual_str AmountErrMsg(const std::string& optname, const std::string& strValue)
164{
165 return strprintf(_("Invalid amount for -%s=<amount>: '%s'"), optname, strValue);
166}
167} // namespace common
is a home for simple enum and struct type definitions that can be used internally by functions in the...
is a home for simple string functions returning descriptive messages that are used in RPC and GUI int...
Definition: init.cpp:17
PSBTError
Definition: types.h:17
bilingual_str PSBTErrorString(PSBTError err)
Definition: messages.cpp:104
std::string FeeModesDetail(std::string default_info)
Definition: messages.cpp:73
std::string FeeModeInfo(const std::pair< std::string, FeeEstimateMode > &mode, std::string &default_info)
Definition: messages.cpp:56
bilingual_str TransactionErrorString(const TransactionError err)
Definition: messages.cpp:125
std::string FeeModes(const std::string &delimiter)
Definition: messages.cpp:82
bilingual_str AmountErrMsg(const std::string &optname, const std::string &strValue)
Definition: messages.cpp:163
bool FeeModeFromString(std::string_view mode_string, FeeEstimateMode &fee_estimate_mode)
Definition: messages.cpp:92
std::string InvalidEstimateModeErrorMessage()
Definition: messages.cpp:87
bilingual_str ResolveErrMsg(const std::string &optname, const std::string &strBind)
Definition: messages.cpp:148
const std::vector< std::pair< std::string, FeeEstimateMode > > & FeeModeMap()
Definition: messages.cpp:46
std::string StringForFeeReason(FeeReason reason)
Definition: messages.cpp:27
bilingual_str AmountHighWarn(const std::string &optname)
Definition: messages.cpp:158
bilingual_str InvalidPortErrMsg(const std::string &optname, const std::string &invalid_value)
Definition: messages.cpp:153
TransactionError
Definition: types.h:28
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
Definition: string.h:206
is a home for public enum and struct type definitions that are used internally by node code,...
Bilingual messages:
Definition: translation.h:24
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1172
consteval auto _(util::TranslatedLiteral str)
Definition: translation.h:79
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:82
FeeEstimateMode
Definition: fees.h:9
@ CONSERVATIVE
Force estimateSmartFee to use conservative estimates.
@ UNSET
Use default settings based on other criteria.
@ ECONOMICAL
Force estimateSmartFee to use non-conservative estimates.
std::string ToUpper(std::string_view str)
Returns the uppercase equivalent of the given string.
assert(!tx.IsCoinBase())