Bitcoin ABC 0.30.7
P2P Digital Currency
strencodings.cpp
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-2016 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/strencodings.h>
7#include <util/string.h>
8
9#include <tinyformat.h>
10
11#include <array>
12#include <cstdlib>
13#include <cstring>
14#include <optional>
15
16static const std::string CHARS_ALPHA_NUM =
17 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
18
19static const std::string SAFE_CHARS[] = {
20 // SAFE_CHARS_DEFAULT
21 CHARS_ALPHA_NUM + " .,;-_/:?@()",
22 // SAFE_CHARS_UA_COMMENT
23 CHARS_ALPHA_NUM + " .,;-_?@",
24 // SAFE_CHARS_FILENAME
25 CHARS_ALPHA_NUM + ".-_",
26 // SAFE_CHARS_URI
27 CHARS_ALPHA_NUM + "!*'();:@&=+$,/?#[]-_.~%",
28};
29
30std::string SanitizeString(std::string_view str, int rule) {
31 std::string result;
32 for (char c : str) {
33 if (SAFE_CHARS[rule].find(c) != std::string::npos) {
34 result.push_back(c);
35 }
36 }
37 return result;
38}
39
40const signed char p_util_hexdigit[256] = {
41 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
42 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
43 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
44 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
45 -1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1,
46 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
47 -1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1,
48 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
49 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
50 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
51 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
52 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
53 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
54 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
55 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
56 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
57};
58
59signed char HexDigit(char c) {
60 return p_util_hexdigit[(uint8_t)c];
61}
62
63bool IsHex(std::string_view str) {
64 for (char c : str) {
65 if (HexDigit(c) < 0) {
66 return false;
67 }
68 }
69 return (str.size() > 0) && (str.size() % 2 == 0);
70}
71
72bool IsHexNumber(std::string_view str) {
73 if (str.substr(0, 2) == "0x") {
74 str.remove_prefix(2);
75 }
76 for (char c : str) {
77 if (HexDigit(c) < 0) {
78 return false;
79 }
80 }
81 // Return false for empty string or "0x".
82 return str.size() > 0;
83}
84
85template <typename Byte>
86std::optional<std::vector<Byte>> TryParseHex(std::string_view str) {
87 std::vector<Byte> vch;
88 auto it = str.begin();
89 while (it != str.end()) {
90 if (IsSpace(*it)) {
91 ++it;
92 continue;
93 }
94 auto c1 = HexDigit(*(it++));
95 if (it == str.end()) {
96 return std::nullopt;
97 }
98 auto c2 = HexDigit(*(it++));
99 if (c1 < 0 || c2 < 0) {
100 return std::nullopt;
101 }
102 vch.push_back(Byte(c1 << 4) | Byte(c2));
103 }
104 return vch;
105}
106template std::vector<std::byte> ParseHex(std::string_view);
107template std::vector<uint8_t> ParseHex(std::string_view);
108
109void SplitHostPort(std::string_view in, uint16_t &portOut,
110 std::string &hostOut) {
111 size_t colon = in.find_last_of(':');
112 // if a : is found, and it either follows a [...], or no other : is in the
113 // string, treat it as port separator
114 bool fHaveColon = colon != in.npos;
115 // if there is a colon, and in[0]=='[', colon is not 0, so in[colon-1] is
116 // safe
117 bool fBracketed = fHaveColon && (in[0] == '[' && in[colon - 1] == ']');
118 bool fMultiColon =
119 fHaveColon && (in.find_last_of(':', colon - 1) != in.npos);
120 if (fHaveColon && (colon == 0 || fBracketed || !fMultiColon)) {
121 uint16_t n;
122 if (ParseUInt16(in.substr(colon + 1), &n)) {
123 in = in.substr(0, colon);
124 portOut = n;
125 }
126 }
127 if (in.size() > 0 && in[0] == '[' && in[in.size() - 1] == ']') {
128 hostOut = in.substr(1, in.size() - 2);
129 } else {
130 hostOut = in;
131 }
132}
133
135 static const char *pbase64 =
136 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
137
138 std::string str;
139 str.reserve(((input.size() + 2) / 3) * 4);
140 ConvertBits<8, 6, true>([&](int v) { str += pbase64[v]; }, input.begin(),
141 input.end());
142 while (str.size() % 4) {
143 str += '=';
144 }
145 return str;
146}
147
148std::optional<std::vector<uint8_t>> DecodeBase64(std::string_view str) {
149 static const int8_t decode64_table[256] = {
150 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
151 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
152 -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57,
153 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6,
154 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
155 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
156 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1,
157 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
158 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
159 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
160 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
161 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
162 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
163 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
164 -1, -1, -1, -1};
165
166 if (str.size() % 4 != 0) {
167 return {};
168 }
169 /* One or two = characters at the end are permitted. */
170 if (str.size() >= 1 && str.back() == '=') {
171 str.remove_suffix(1);
172 }
173 if (str.size() >= 1 && str.back() == '=') {
174 str.remove_suffix(1);
175 }
176
177 std::vector<uint8_t> ret;
178 ret.reserve((str.size() * 3) / 4);
179 bool valid = ConvertBits<6, 8, false>(
180 [&](uint8_t c) { ret.push_back(c); }, str.begin(), str.end(),
181 [](char c) { return decode64_table[uint8_t(c)]; });
182 if (!valid) {
183 return {};
184 }
185
186 return ret;
187}
188
189std::string EncodeBase32(Span<const uint8_t> input, bool pad) {
190 static const char *pbase32 = "abcdefghijklmnopqrstuvwxyz234567";
191
192 std::string str;
193 str.reserve(((input.size() + 4) / 5) * 8);
194 ConvertBits<8, 5, true>([&](int v) { str += pbase32[v]; }, input.begin(),
195 input.end());
196 if (pad) {
197 while (str.size() % 8) {
198 str += '=';
199 }
200 }
201 return str;
202}
203
204std::string EncodeBase32(std::string_view str, bool pad) {
205 return EncodeBase32(MakeUCharSpan(str), pad);
206}
207
208std::optional<std::vector<uint8_t>> DecodeBase32(std::string_view str) {
209 static const int8_t decode32_table[256] = {
210 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
211 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
212 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29,
213 30, 31, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6,
214 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
215 25, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
216 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1,
217 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
218 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
219 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
220 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
221 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
222 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
223 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
224 -1, -1, -1, -1};
225
226 if (str.size() % 8 != 0) {
227 return {};
228 }
229 /* 1, 3, 4, or 6 padding '=' suffix characters are permitted. */
230 if (str.size() >= 1 && str.back() == '=') {
231 str.remove_suffix(1);
232 }
233 if (str.size() >= 2 && str.substr(str.size() - 2) == "==") {
234 str.remove_suffix(2);
235 }
236 if (str.size() >= 1 && str.back() == '=') {
237 str.remove_suffix(1);
238 }
239 if (str.size() >= 2 && str.substr(str.size() - 2) == "==") {
240 str.remove_suffix(2);
241 }
242
243 std::vector<uint8_t> ret;
244 ret.reserve((str.size() * 5) / 8);
245 bool valid = ConvertBits<5, 8, false>(
246 [&](uint8_t c) { ret.push_back(c); }, str.begin(), str.end(),
247 [](char c) { return decode32_table[uint8_t(c)]; });
248
249 if (!valid) {
250 return {};
251 }
252
253 return ret;
254}
255
256namespace {
257template <typename T> bool ParseIntegral(std::string_view str, T *out) {
258 static_assert(std::is_integral<T>::value);
259 // Replicate the exact behavior of strtol/strtoll/strtoul/strtoull when
260 // handling leading +/- for backwards compatibility.
261 if (str.length() >= 2 && str[0] == '+' && str[1] == '-') {
262 return false;
263 }
264 const std::optional<T> opt_int =
265 ToIntegral<T>((!str.empty() && str[0] == '+') ? str.substr(1) : str);
266 if (!opt_int) {
267 return false;
268 }
269 if (out != nullptr) {
270 *out = *opt_int;
271 }
272 return true;
273}
274}; // namespace
275
276bool ParseInt32(std::string_view str, int32_t *out) {
277 return ParseIntegral<int32_t>(str, out);
278}
279
280bool ParseInt64(std::string_view str, int64_t *out) {
281 return ParseIntegral<int64_t>(str, out);
282}
283
284bool ParseUInt8(std::string_view str, uint8_t *out) {
285 return ParseIntegral<uint8_t>(str, out);
286}
287
288bool ParseUInt16(std::string_view str, uint16_t *out) {
289 return ParseIntegral<uint16_t>(str, out);
290}
291
292bool ParseUInt32(std::string_view str, uint32_t *out) {
293 return ParseIntegral<uint32_t>(str, out);
294}
295
296bool ParseUInt64(std::string_view str, uint64_t *out) {
297 return ParseIntegral<uint64_t>(str, out);
298}
299
300std::string FormatParagraph(std::string_view in, size_t width, size_t indent) {
301 std::stringstream out;
302 size_t ptr = 0;
303 size_t indented = 0;
304 while (ptr < in.size()) {
305 size_t lineend = in.find_first_of('\n', ptr);
306 if (lineend == std::string::npos) {
307 lineend = in.size();
308 }
309 const size_t linelen = lineend - ptr;
310 const size_t rem_width = width - indented;
311 if (linelen <= rem_width) {
312 out << in.substr(ptr, linelen + 1);
313 ptr = lineend + 1;
314 indented = 0;
315 } else {
316 size_t finalspace = in.find_last_of(" \n", ptr + rem_width);
317 if (finalspace == std::string::npos || finalspace < ptr) {
318 // No place to break; just include the entire word and move on
319 finalspace = in.find_first_of("\n ", ptr);
320 if (finalspace == std::string::npos) {
321 // End of the string, just add it and break
322 out << in.substr(ptr);
323 break;
324 }
325 }
326 out << in.substr(ptr, finalspace - ptr) << "\n";
327 if (in[finalspace] == '\n') {
328 indented = 0;
329 } else if (indent) {
330 out << std::string(indent, ' ');
331 indented = indent;
332 }
333 ptr = finalspace + 1;
334 }
335 }
336 return out.str();
337}
338
339int64_t atoi64(const std::string &str) {
340#ifdef _MSC_VER
341 return _atoi64(str.c_str());
342#else
343 return strtoll(str.c_str(), nullptr, 10);
344#endif
345}
346
347int atoi(const std::string &str) {
348 return atoi(str.c_str());
349}
350
360static const int64_t UPPER_BOUND = 1000000000000000000LL - 1LL;
361
363static inline bool ProcessMantissaDigit(char ch, int64_t &mantissa,
364 int &mantissa_tzeros) {
365 if (ch == '0') {
366 ++mantissa_tzeros;
367 } else {
368 for (int i = 0; i <= mantissa_tzeros; ++i) {
369 // overflow
370 if (mantissa > (UPPER_BOUND / 10LL)) {
371 return false;
372 }
373 mantissa *= 10;
374 }
375 mantissa += ch - '0';
376 mantissa_tzeros = 0;
377 }
378 return true;
379}
380
381bool ParseFixedPoint(std::string_view val, int decimals, int64_t *amount_out) {
382 int64_t mantissa = 0;
383 int64_t exponent = 0;
384 int mantissa_tzeros = 0;
385 bool mantissa_sign = false;
386 bool exponent_sign = false;
387 int ptr = 0;
388 int end = val.size();
389 int point_ofs = 0;
390
391 if (ptr < end && val[ptr] == '-') {
392 mantissa_sign = true;
393 ++ptr;
394 }
395 if (ptr < end) {
396 if (val[ptr] == '0') {
397 // pass single 0
398 ++ptr;
399 } else if (val[ptr] >= '1' && val[ptr] <= '9') {
400 while (ptr < end && IsDigit(val[ptr])) {
401 if (!ProcessMantissaDigit(val[ptr], mantissa,
402 mantissa_tzeros)) {
403 // overflow
404 return false;
405 }
406 ++ptr;
407 }
408 } else {
409 // missing expected digit
410 return false;
411 }
412 } else {
413 // empty string or loose '-'
414 return false;
415 }
416 if (ptr < end && val[ptr] == '.') {
417 ++ptr;
418 if (ptr < end && IsDigit(val[ptr])) {
419 while (ptr < end && IsDigit(val[ptr])) {
420 if (!ProcessMantissaDigit(val[ptr], mantissa,
421 mantissa_tzeros)) {
422 // overflow
423 return false;
424 }
425 ++ptr;
426 ++point_ofs;
427 }
428 } else {
429 // missing expected digit
430 return false;
431 }
432 }
433 if (ptr < end && (val[ptr] == 'e' || val[ptr] == 'E')) {
434 ++ptr;
435 if (ptr < end && val[ptr] == '+') {
436 ++ptr;
437 } else if (ptr < end && val[ptr] == '-') {
438 exponent_sign = true;
439 ++ptr;
440 }
441 if (ptr < end && IsDigit(val[ptr])) {
442 while (ptr < end && IsDigit(val[ptr])) {
443 if (exponent > (UPPER_BOUND / 10LL)) {
444 // overflow
445 return false;
446 }
447 exponent = exponent * 10 + val[ptr] - '0';
448 ++ptr;
449 }
450 } else {
451 // missing expected digit
452 return false;
453 }
454 }
455 if (ptr != end) {
456 // trailing garbage
457 return false;
458 }
459 // finalize exponent
460 if (exponent_sign) {
461 exponent = -exponent;
462 }
463 exponent = exponent - point_ofs + mantissa_tzeros;
464
465 // finalize mantissa
466 if (mantissa_sign) {
467 mantissa = -mantissa;
468 }
469
470 // convert to one 64-bit fixed-point value
471 exponent += decimals;
472 if (exponent < 0) {
473 // cannot represent values smaller than 10^-decimals
474 return false;
475 }
476 if (exponent >= 18) {
477 // cannot represent values larger than or equal to 10^(18-decimals)
478 return false;
479 }
480
481 for (int i = 0; i < exponent; ++i) {
482 if (mantissa > (UPPER_BOUND / 10LL) ||
483 mantissa < -(UPPER_BOUND / 10LL)) {
484 // overflow
485 return false;
486 }
487 mantissa *= 10;
488 }
489 if (mantissa > UPPER_BOUND || mantissa < -UPPER_BOUND) {
490 // overflow
491 return false;
492 }
493
494 if (amount_out) {
495 *amount_out = mantissa;
496 }
497
498 return true;
499}
500
501std::string ToLower(std::string_view str) {
502 std::string r;
503 for (auto ch : str) {
504 r += ToLower(ch);
505 }
506 return r;
507}
508
509std::string ToUpper(std::string_view str) {
510 std::string r;
511 for (auto ch : str) {
512 r += ToUpper(ch);
513 }
514 return r;
515}
516
517std::string Capitalize(std::string str) {
518 if (str.empty()) {
519 return str;
520 }
521 str[0] = ToUpper(str.front());
522 return str;
523}
524
525namespace {
526
527using ByteAsHex = std::array<char, 2>;
528
529constexpr std::array<ByteAsHex, 256> CreateByteToHexMap() {
530 constexpr char hexmap[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
531 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
532
533 std::array<ByteAsHex, 256> byte_to_hex{};
534 for (size_t i = 0; i < byte_to_hex.size(); ++i) {
535 byte_to_hex[i][0] = hexmap[i >> 4];
536 byte_to_hex[i][1] = hexmap[i & 15];
537 }
538 return byte_to_hex;
539}
540
541} // namespace
542
543std::string HexStr(const Span<const uint8_t> s) {
544 std::string rv(s.size() * 2, '\0');
545 static constexpr auto byte_to_hex = CreateByteToHexMap();
546 static_assert(sizeof(byte_to_hex) == 512);
547
548 char *it = rv.data();
549 for (uint8_t v : s) {
550 std::memcpy(it, byte_to_hex[v].data(), 2);
551 it += 2;
552 }
553
554 assert(it == rv.data() + rv.size());
555 return rv;
556}
constexpr std::size_t size() const noexcept
Definition: span.h:209
constexpr C * begin() const noexcept
Definition: span.h:199
constexpr C * end() const noexcept
Definition: span.h:200
constexpr auto MakeUCharSpan(V &&v) -> decltype(UCharSpanCast(Span{std::forward< V >(v)}))
Like the Span constructor, but for (const) uint8_t member types only.
Definition: span.h:337
constexpr bool IsDigit(char c)
Tests if the given character is a decimal digit.
Definition: strencodings.h:98
constexpr bool IsSpace(char c) noexcept
Tests if the given character is a whitespace character.
Definition: strencodings.h:114
std::string Capitalize(std::string str)
Capitalizes the first character of the given string.
static const std::string SAFE_CHARS[]
bool IsHexNumber(std::string_view str)
Return true if the string is a hex number, optionally prefixed with "0x".
bool ParseInt32(std::string_view str, int32_t *out)
Convert string to signed 32-bit integer with strict parse error feedback.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
std::string EncodeBase64(Span< const uint8_t > input)
bool ParseUInt16(std::string_view str, uint16_t *out)
Convert decimal string to unsigned 16-bit integer with strict parse error feedback.
std::string ToUpper(std::string_view str)
Returns the uppercase equivalent of the given string.
const signed char p_util_hexdigit[256]
template std::vector< std::byte > ParseHex(std::string_view)
std::string EncodeBase32(Span< const uint8_t > input, bool pad)
Base32 encode.
bool ParseFixedPoint(std::string_view val, int decimals, int64_t *amount_out)
Parse number as fixed point according to JSON number syntax.
bool ParseInt64(std::string_view str, int64_t *out)
Convert string to signed 64-bit integer with strict parse error feedback.
bool ParseUInt8(std::string_view str, uint8_t *out)
Convert decimal string to unsigned 8-bit integer with strict parse error feedback.
bool ParseUInt64(std::string_view str, uint64_t *out)
Convert decimal string to unsigned 64-bit integer with strict parse error feedback.
signed char HexDigit(char c)
int atoi(const std::string &str)
static bool ProcessMantissaDigit(char ch, int64_t &mantissa, int &mantissa_tzeros)
Helper function for ParseFixedPoint.
bool IsHex(std::string_view str)
Returns true if each character in str is a hex character, and has an even number of hex digits.
std::string FormatParagraph(std::string_view in, size_t width, size_t indent)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line.
static const int64_t UPPER_BOUND
Upper bound for mantissa.
int64_t atoi64(const std::string &str)
std::optional< std::vector< uint8_t > > DecodeBase64(std::string_view str)
bool ParseUInt32(std::string_view str, uint32_t *out)
Convert decimal string to unsigned 32-bit integer with strict parse error feedback.
void SplitHostPort(std::string_view in, uint16_t &portOut, std::string &hostOut)
std::optional< std::vector< Byte > > TryParseHex(std::string_view str)
Parse the hex string into bytes (uint8_t or std::byte).
std::string ToLower(std::string_view str)
Returns the lowercase equivalent of the given string.
std::optional< std::vector< uint8_t > > DecodeBase32(std::string_view str)
std::string SanitizeString(std::string_view str, int rule)
Remove unsafe chars.
static const std::string CHARS_ALPHA_NUM
assert(!tx.IsCoinBase())