MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / Encode

Function Encode

src/bech32.cpp:358–371  ·  view source on GitHub ↗

Encode a Bech32 or Bech32m string. */

Source from the content-addressed store, hash-verified

356
357/** Encode a Bech32 or Bech32m string. */
358std::string Encode(Encoding encoding, const std::string& hrp, const data& values) {
359 // First ensure that the HRP is all lowercase. BIP-173 and BIP350 require an encoder
360 // to return a lowercase Bech32/Bech32m string, but if given an uppercase HRP, the
361 // result will always be invalid.
362 for (const char& c : hrp) assert(c < 'A' || c > 'Z');
363
364 std::string ret;
365 ret.reserve(hrp.size() + 1 + values.size() + CHECKSUM_SIZE);
366 ret += hrp;
367 ret += SEPARATOR;
368 for (const uint8_t& i : values) ret += CHARSET[i];
369 for (const uint8_t& i : CreateChecksum(encoding, hrp, values)) ret += CHARSET[i];
370 return ret;
371}
372
373/** Decode a Bech32 or Bech32m string. */
374DecodeResult Decode(const std::string& str, CharLimit limit) {

Callers 5

EncodeWithVersionMethod · 0.85
operator()Method · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
FUZZ_TARGETFunction · 0.85
Bech32EncodeFunction · 0.85

Calls 3

CreateChecksumFunction · 0.85
reserveMethod · 0.45
sizeMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.68
FUZZ_TARGETFunction · 0.68