5#include <blockfilter.h>
39bool LegacyParsePrechecks(
const std::string& str)
43 if (str.size() >= 1 && (
IsSpace(str[0]) ||
IsSpace(str[str.size() - 1])))
50bool LegacyParseInt32(
const std::string& str, int32_t* out)
52 if (!LegacyParsePrechecks(str))
56 long int n = strtol(str.c_str(), &endp, 10);
57 if (out) *out = (int32_t)n;
61 return endp && *endp == 0 && !errno &&
62 n >= std::numeric_limits<int32_t>::min() &&
63 n <= std::numeric_limits<int32_t>::max();
66bool LegacyParseInt64(
const std::string& str, int64_t* out)
68 if (!LegacyParsePrechecks(str))
72 long long int n = strtoll(str.c_str(), &endp, 10);
73 if (out) *out = (int64_t)n;
76 return endp && *endp == 0 && !errno &&
77 n >= std::numeric_limits<int64_t>::min() &&
78 n <= std::numeric_limits<int64_t>::max();
81bool LegacyParseUInt32(
const std::string& str, uint32_t* out)
83 if (!LegacyParsePrechecks(str))
85 if (str.size() >= 1 && str[0] ==
'-')
89 unsigned long int n = strtoul(str.c_str(), &endp, 10);
90 if (out) *out = (uint32_t)n;
94 return endp && *endp == 0 && !errno &&
95 n <= std::numeric_limits<uint32_t>::max();
98bool LegacyParseUInt8(
const std::string& str, uint8_t* out)
101 if (!LegacyParseUInt32(str, &u32) || u32 > std::numeric_limits<uint8_t>::max()) {
104 if (out !=
nullptr) {
105 *out =
static_cast<uint8_t
>(u32);
110bool LegacyParseUInt64(
const std::string& str, uint64_t* out)
112 if (!LegacyParsePrechecks(str))
114 if (str.size() >= 1 && str[0] ==
'-')
116 char* endp =
nullptr;
118 unsigned long long int n = strtoull(str.c_str(), &endp, 10);
119 if (out) *out = (uint64_t)n;
122 return endp && *endp == 0 && !errno &&
123 n <= std::numeric_limits<uint64_t>::max();
127int64_t atoi64_legacy(
const std::string& str)
129 return strtoll(str.c_str(),
nullptr, 10);
156 (void)
Join(random_string_vector, random_string_1);
163 }
catch (
const std::runtime_error&) {
170 }
catch (
const std::runtime_error&) {
174 }
catch (
const std::runtime_error&) {
182 std::string host_out;
185 (void)
ToLower(random_string_1);
186 (void)
ToUpper(random_string_1);
188 (void)
TrimString(random_string_1, random_string_2);
191 (void)
_(random_string_1.c_str());
194 }
catch (
const std::runtime_error&) {
201 data_stream << random_string_1;
203 data_stream >> limited_string;
204 assert(data_stream.empty());
205 assert(s.size() <= random_string_1.size());
207 if (!random_string_1.empty()) {
210 }
catch (
const std::ios_base::failure&) {
216 data_stream << limited_string;
217 std::string deserialized_string;
218 data_stream >> deserialized_string;
219 assert(data_stream.empty());
220 assert(deserialized_string == random_string_1);
238 const bool ok_i32 =
ParseInt32(random_string_1, &i32);
239 const bool ok_i64 =
ParseInt64(random_string_1, &i64);
240 const bool ok_u32 =
ParseUInt32(random_string_1, &u32);
241 const bool ok_u64 =
ParseUInt64(random_string_1, &u64);
242 const bool ok_u8 =
ParseUInt8(random_string_1, &u8);
249 const bool ok_i32_legacy = LegacyParseInt32(random_string_1, &i32_legacy);
250 const bool ok_i64_legacy = LegacyParseInt64(random_string_1, &i64_legacy);
251 const bool ok_u32_legacy = LegacyParseUInt32(random_string_1, &u32_legacy);
252 const bool ok_u64_legacy = LegacyParseUInt64(random_string_1, &u64_legacy);
253 const bool ok_u8_legacy = LegacyParseUInt8(random_string_1, &u8_legacy);
255 assert(ok_i32 == ok_i32_legacy);
256 assert(ok_i64 == ok_i64_legacy);
257 assert(ok_u32 == ok_u32_legacy);
258 assert(ok_u64 == ok_u64_legacy);
259 assert(ok_u8 == ok_u8_legacy);
262 assert(i32 == i32_legacy);
265 assert(i64 == i64_legacy);
268 assert(u32 == u32_legacy);
271 assert(u64 == u64_legacy);
279 const int atoi_result = atoi(random_string_1.c_str());
280 const int locale_independent_atoi_result = LocaleIndependentAtoi<int>(random_string_1);
281 const int64_t atoi64_result = atoi64_legacy(random_string_1);
282 const bool out_of_range = atoi64_result < std::numeric_limits<int>::min() || atoi64_result > std::numeric_limits<int>::max();
284 assert(locale_independent_atoi_result == 0);
286 assert(atoi_result == locale_independent_atoi_result);
291 const int64_t atoi64_result = atoi64_legacy(random_string_1);
292 const int64_t locale_independent_atoi_result = LocaleIndependentAtoi<int64_t>(random_string_1);
293 assert(atoi64_result == locale_independent_atoi_result || locale_independent_atoi_result == 0);
bool BlockFilterTypeByName(const std::string &name, BlockFilterType &filter_type)
Find a filter type by its human-readable name.
Double ended buffer combining vector and stream-like interfaces.
std::string ConsumeRandomLengthString(size_t max_length)
T ConsumeIntegralInRange(T min, T max)
UniValue ParseNonRFCJSONValue(const std::string &strVal)
Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null) as well as obje...
UniValue RPCConvertValues(const std::string &strMethod, const std::vector< std::string > &strParams)
Convert positional arguments to command-specific RPC representation.
UniValue RPCConvertNamedValues(const std::string &strMethod, const std::vector< std::string > &strParams)
Convert named arguments to command-specific RPC representation.
std::string FormatSubVersion(const std::string &name, int nClientVersion, const std::vector< std::string > &comments)
Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip...
std::string GetDescriptorChecksum(const std::string &descriptor)
Get the checksum for a descriptor.
bilingual_str AmountHighWarn(const std::string &optname)
bilingual_str AmountErrMsg(const std::string &optname, const std::string &strValue)
bilingual_str ResolveErrMsg(const std::string &optname, const std::string &strBind)
bool OnlyHasDefaultSectionSetting(const Settings &settings, const std::string §ion, const std::string &name)
Return true if a setting is set in the default config file section, and not overridden by a higher pr...
enum Network ParseNetwork(const std::string &net_in)
std::optional< OutputType > ParseOutputType(const std::string &type)
UniValue JSONRPCError(int code, const std::string &message)
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
#define LIMITED_STRING(obj, n)
bool IsDeprecatedRPCEnabled(const std::string &method)
std::string Capitalize(std::string str)
Capitalizes the first character of the given string.
std::string FormatParagraph(const std::string &in, size_t width, size_t indent)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line.
std::string ToLower(const std::string &str)
Returns the lowercase equivalent of the given string.
bool ParseUInt64(const std::string &str, uint64_t *out)
Convert decimal string to unsigned 64-bit integer with strict parse error feedback.
bool ParseUInt32(const std::string &str, uint32_t *out)
Convert decimal string to unsigned 32-bit integer with strict parse error feedback.
bool ParseInt32(const std::string &str, int32_t *out)
Convert string to signed 32-bit integer with strict parse error feedback.
bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out)
Parse number as fixed point according to JSON number syntax.
std::string SanitizeString(const std::string &str, int rule)
Remove unsafe chars.
bool ParseInt64(const std::string &str, int64_t *out)
Convert string to signed 64-bit integer with strict parse error feedback.
std::string ToUpper(const std::string &str)
Returns the uppercase equivalent of the given string.
void SplitHostPort(std::string in, uint16_t &portOut, std::string &hostOut)
bool ParseUInt8(const std::string &str, uint8_t *out)
Convert decimal string to unsigned 8-bit integer with strict parse error feedback.
bool TimingResistantEqual(const T &a, const T &b)
Timing-attack-resistant comparison.
constexpr bool IsSpace(char c) noexcept
Tests if the given character is a whitespace character.
auto Join(const std::vector< T > &list, const BaseType &separator, UnaryOp unary_op) -> decltype(unary_op(list.at(0)))
Join a list of items.
bool ValidAsCString(const std::string &str) noexcept
Check if a string does not contain any embedded NUL (\0) characters.
std::string RemovePrefix(const std::string &str, const std::string &prefix)
std::string TrimString(const std::string &str, const std::string &pattern=" \f\n\r\t\v")
std::vector< std::string > ConsumeRandomLengthStringVector(FuzzedDataProvider &fuzzed_data_provider, const size_t max_vector_size=16, const size_t max_string_length=16) noexcept
bilingual_str _(const char *psz)
Translation function.
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
bool FeeModeFromString(const std::string &mode_string, FeeEstimateMode &fee_estimate_mode)
std::string CopyrightHolders(const std::string &strPrefix)
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
std::string ShellEscape(const std::string &arg)
static const int INIT_PROTO_VERSION
initial proto version, to be increased after version/verack negotiation