Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
common
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
8
#include <
common/types.h
>
9
#include <
node/types.h
>
10
#include <
tinyformat.h
>
11
#include <
util/check.h
>
12
#include <
util/fees.h
>
13
#include <
util/strencodings.h
>
14
#include <
util/string.h
>
15
#include <
util/translation.h
>
16
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
std::string
StringForFeeReason
(
FeeReason
reason)
28
{
29
static
const
std::map<FeeReason, std::string> fee_reason_strings = {
30
{
FeeReason::FEE_RATE_ESTIMATOR
,
"Fee Rate Estimator"
},
31
{
FeeReason::MEMPOOL_MIN
,
"Mempool Min Fee"
},
32
{
FeeReason::USER_SPECIFIED
,
"User Specified Fee"
},
33
{
FeeReason::FALLBACK
,
"Fallback fee"
},
34
{
FeeReason::REQUIRED
,
"Minimum Required Fee"
},
35
};
36
auto
reason_string = fee_reason_strings.find(reason);
37
38
if
(reason_string == fee_reason_strings.end())
return
"Unknown"
;
39
40
return
reason_string->second;
41
}
42
43
const
std::vector<std::pair<std::string, FeeEstimateMode>>&
FeeModeMap
()
44
{
45
static
const
std::vector<std::pair<std::string, FeeEstimateMode>> FEE_MODES = {
46
{
"unset"
,
FeeEstimateMode::UNSET
},
47
{
"economical"
,
FeeEstimateMode::ECONOMICAL
},
48
{
"conservative"
,
FeeEstimateMode::CONSERVATIVE
},
49
};
50
return
FEE_MODES;
51
}
52
53
std::string
FeeModeInfo
(
const
std::pair<std::string, FeeEstimateMode>& mode, std::string& default_info)
54
{
55
switch
(mode.second) {
56
case
FeeEstimateMode::UNSET
:
57
return
strprintf
(
"%s means no mode set (%s). \n"
, mode.first, default_info);
58
case
FeeEstimateMode::ECONOMICAL
:
59
return
strprintf
(
"%s mode potentially returns a lower fee rate estimate.\n"
, mode.first);
60
case
FeeEstimateMode::CONSERVATIVE
:
61
return
strprintf
(
"%s potentially returns a higher fee rate estimate.\n"
, mode.first);
62
}
// no default case, so the compiler can warn about missing cases
63
assert
(
false
);
64
}
65
66
std::string
FeeModesDetail
(std::string default_info)
67
{
68
std::string info;
69
for
(
const
auto
& fee_mode :
FeeModeMap
()) {
70
info +=
FeeModeInfo
(fee_mode, default_info);
71
}
72
return
strprintf
(
"%s \n%s"
,
FeeModes
(
", "
), info);
73
}
74
75
std::string
FeeModes
(
const
std::string& delimiter)
76
{
77
return
Join
(
FeeModeMap
(), delimiter, [&](
const
std::pair<std::string, FeeEstimateMode>& i) {
return
i.first; });
78
}
79
80
std::string
InvalidEstimateModeErrorMessage
()
81
{
82
return
"Invalid estimate_mode parameter, must be one of: \""
+
FeeModes
(
"\", \""
) +
"\""
;
83
}
84
85
bool
FeeModeFromString
(std::string_view mode_string,
FeeEstimateMode
& fee_estimate_mode)
86
{
87
auto
searchkey =
ToUpper
(mode_string);
88
for
(
const
auto
& pair :
FeeModeMap
()) {
89
if
(
ToUpper
(pair.first) == searchkey) {
90
fee_estimate_mode = pair.second;
91
return
true
;
92
}
93
}
94
return
false
;
95
}
96
97
bilingual_str
PSBTErrorString
(
PSBTError
err)
98
{
99
switch
(err) {
100
case
PSBTError::MISSING_INPUTS
:
101
return
Untranslated
(
"Inputs missing or spent"
);
102
case
PSBTError::SIGHASH_MISMATCH
:
103
return
Untranslated
(
"Specified sighash value does not match value stored in PSBT"
);
104
case
PSBTError::EXTERNAL_SIGNER_NOT_FOUND
:
105
return
Untranslated
(
"External signer not found"
);
106
case
PSBTError::EXTERNAL_SIGNER_FAILED
:
107
return
Untranslated
(
"External signer failed to sign"
);
108
case
PSBTError::UNSUPPORTED
:
109
return
Untranslated
(
"Signer does not support PSBT"
);
110
case
PSBTError::INCOMPLETE
:
111
return
Untranslated
(
"Input needs additional signatures or other data"
);
112
case
PSBTError::INVALID_TX
:
113
return
Untranslated
(
"The transaction cannot be valid"
);
114
}
// no default case, so the compiler can warn about missing cases
115
assert
(
false
);
116
}
117
118
bilingual_str
TransactionErrorString
(
const
TransactionError
err)
119
{
120
switch
(err) {
121
case
TransactionError::OK
:
122
return
Untranslated
(
"No error"
);
123
case
TransactionError::MISSING_INPUTS
:
124
return
Untranslated
(
"Inputs missing or spent"
);
125
case
TransactionError::ALREADY_IN_UTXO_SET
:
126
return
Untranslated
(
"Transaction outputs already in utxo set"
);
127
case
TransactionError::MEMPOOL_REJECTED
:
128
return
Untranslated
(
"Transaction rejected by mempool"
);
129
case
TransactionError::MEMPOOL_ERROR
:
130
return
Untranslated
(
"Mempool internal error"
);
131
case
TransactionError::MAX_FEE_EXCEEDED
:
132
return
Untranslated
(
"Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)"
);
133
case
TransactionError::MAX_BURN_EXCEEDED
:
134
return
Untranslated
(
"Unspendable output exceeds maximum configured by user (maxburnamount)"
);
135
case
TransactionError::INVALID_PACKAGE
:
136
return
Untranslated
(
"Transaction rejected due to invalid package"
);
137
case
TransactionError::PRIVATE_BROADCAST_FULL
:
138
return
Untranslated
(
"Private broadcast queue is full"
);
139
}
// no default case, so the compiler can warn about missing cases
140
assert
(
false
);
141
}
142
143
bilingual_str
ResolveErrMsg
(
const
std::string& optname,
const
std::string& strBind)
144
{
145
return
strprintf
(
_
(
"Cannot resolve -%s address: '%s'"
), optname, strBind);
146
}
147
148
bilingual_str
InvalidPortErrMsg
(
const
std::string& optname,
const
std::string& invalid_value)
149
{
150
return
strprintf
(
_
(
"Invalid port specified in %s: '%s'"
), optname, invalid_value);
151
}
152
153
bilingual_str
AmountHighWarn
(
const
std::string& optname)
154
{
155
return
strprintf
(
_
(
"%s is set very high!"
), optname);
156
}
157
158
bilingual_str
AmountErrMsg
(
const
std::string& optname,
const
std::string& strValue)
159
{
160
return
strprintf
(
_
(
"Invalid amount for -%s=<amount>: '%s'"
), optname, strValue);
161
}
162
}
// namespace common
Join
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
Definition
string.h:209
check.h
types.h
messages.h
common
Definition
init.cpp:17
common::PSBTError
PSBTError
Definition
types.h:19
common::PSBTError::MISSING_INPUTS
@ MISSING_INPUTS
Definition
types.h:20
common::PSBTError::INCOMPLETE
@ INCOMPLETE
Definition
types.h:25
common::PSBTError::UNSUPPORTED
@ UNSUPPORTED
Definition
types.h:24
common::PSBTError::INVALID_TX
@ INVALID_TX
Definition
types.h:26
common::PSBTError::EXTERNAL_SIGNER_FAILED
@ EXTERNAL_SIGNER_FAILED
Definition
types.h:23
common::PSBTError::EXTERNAL_SIGNER_NOT_FOUND
@ EXTERNAL_SIGNER_NOT_FOUND
Definition
types.h:22
common::PSBTError::SIGHASH_MISMATCH
@ SIGHASH_MISMATCH
Definition
types.h:21
common::PSBTErrorString
bilingual_str PSBTErrorString(PSBTError err)
Definition
messages.cpp:97
common::FeeModesDetail
std::string FeeModesDetail(std::string default_info)
Definition
messages.cpp:66
common::FeeModeInfo
std::string FeeModeInfo(const std::pair< std::string, FeeEstimateMode > &mode, std::string &default_info)
Definition
messages.cpp:53
common::TransactionErrorString
bilingual_str TransactionErrorString(const TransactionError err)
Definition
messages.cpp:118
common::FeeModes
std::string FeeModes(const std::string &delimiter)
Definition
messages.cpp:75
common::AmountErrMsg
bilingual_str AmountErrMsg(const std::string &optname, const std::string &strValue)
Definition
messages.cpp:158
common::FeeModeFromString
bool FeeModeFromString(std::string_view mode_string, FeeEstimateMode &fee_estimate_mode)
Definition
messages.cpp:85
common::InvalidEstimateModeErrorMessage
std::string InvalidEstimateModeErrorMessage()
Definition
messages.cpp:80
common::ResolveErrMsg
bilingual_str ResolveErrMsg(const std::string &optname, const std::string &strBind)
Definition
messages.cpp:143
common::FeeModeMap
const std::vector< std::pair< std::string, FeeEstimateMode > > & FeeModeMap()
Definition
messages.cpp:43
common::StringForFeeReason
std::string StringForFeeReason(FeeReason reason)
Definition
messages.cpp:27
common::AmountHighWarn
bilingual_str AmountHighWarn(const std::string &optname)
Definition
messages.cpp:153
common::InvalidPortErrMsg
bilingual_str InvalidPortErrMsg(const std::string &optname, const std::string &invalid_value)
Definition
messages.cpp:148
node::TransactionError
TransactionError
Definition
types.h:19
node::TransactionError::MISSING_INPUTS
@ MISSING_INPUTS
Definition
types.h:21
node::TransactionError::MEMPOOL_REJECTED
@ MEMPOOL_REJECTED
Definition
types.h:23
node::TransactionError::MAX_FEE_EXCEEDED
@ MAX_FEE_EXCEEDED
Definition
types.h:25
node::TransactionError::MAX_BURN_EXCEEDED
@ MAX_BURN_EXCEEDED
Definition
types.h:26
node::TransactionError::MEMPOOL_ERROR
@ MEMPOOL_ERROR
Definition
types.h:24
node::TransactionError::ALREADY_IN_UTXO_SET
@ ALREADY_IN_UTXO_SET
Definition
types.h:22
node::TransactionError::PRIVATE_BROADCAST_FULL
@ PRIVATE_BROADCAST_FULL
Definition
types.h:28
node::TransactionError::INVALID_PACKAGE
@ INVALID_PACKAGE
Definition
types.h:27
node::TransactionError::OK
@ OK
No error.
Definition
types.h:20
util::Join
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
Definition
string.h:209
types.h
strencodings.h
string.h
bilingual_str
Bilingual messages:
Definition
translation.h:24
tinyformat.h
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition
tinyformat.h:1172
translation.h
_
consteval auto _(util::TranslatedLiteral str)
Definition
translation.h:79
Untranslated
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition
translation.h:82
fees.h
FeeReason
FeeReason
Definition
fees.h:25
FeeReason::USER_SPECIFIED
@ USER_SPECIFIED
Definition
fees.h:28
FeeReason::FEE_RATE_ESTIMATOR
@ FEE_RATE_ESTIMATOR
Definition
fees.h:26
FeeReason::REQUIRED
@ REQUIRED
Definition
fees.h:30
FeeReason::FALLBACK
@ FALLBACK
Definition
fees.h:29
FeeReason::MEMPOOL_MIN
@ MEMPOOL_MIN
Definition
fees.h:27
FeeEstimateMode
FeeEstimateMode
Definition
fees.h:18
FeeEstimateMode::CONSERVATIVE
@ CONSERVATIVE
Force Fee rate estimator to return conservative estimates.
Definition
fees.h:21
FeeEstimateMode::UNSET
@ UNSET
Use default settings based on other criteria.
Definition
fees.h:19
FeeEstimateMode::ECONOMICAL
@ ECONOMICAL
Force Fee rate estimator to return non-conservative estimates.
Definition
fees.h:20
ToUpper
std::string ToUpper(std::string_view str)
Returns the uppercase equivalent of the given string.
Definition
strencodings.cpp:370
assert
assert(!tx.IsCoinBase())
Generated on
for Bitcoin Core by
1.18.0