MCPcopy Create free account
hub / github.com/ElementsProject/elements / Encode

Function Encode

src/bech32.cpp:352–365  ·  view source on GitHub ↗

Encode a Bech32 or Bech32m string. */

Source from the content-addressed store, hash-verified

350
351/** Encode a Bech32 or Bech32m string. */
352std::string Encode(Encoding encoding, const std::string& hrp, const data& values) {
353 // First ensure that the HRP is all lowercase. BIP-173 and BIP350 require an encoder
354 // to return a lowercase Bech32/Bech32m string, but if given an uppercase HRP, the
355 // result will always be invalid.
356 for (const char& c : hrp) assert(c < 'A' || c > 'Z');
357 data checksum = CreateChecksum(encoding, hrp, values);
358 data combined = Cat(values, checksum);
359 std::string ret = hrp + '1';
360 ret.reserve(ret.size() + combined.size());
361 for (const auto c : combined) {
362 ret += CHARSET[c];
363 }
364 return ret;
365}
366
367/** Decode a Bech32 or Bech32m string. */
368DecodeResult Decode(const std::string& str) {

Callers 6

EncodeWithVersionMethod · 0.70
operator()Method · 0.70
BOOST_AUTO_TEST_CASEFunction · 0.50
BOOST_AUTO_TEST_CASEFunction · 0.50
FUZZ_TARGETFunction · 0.50
Bech32EncodeFunction · 0.50

Calls 4

CreateChecksumFunction · 0.70
CatFunction · 0.70
reserveMethod · 0.45
sizeMethod · 0.45

Tested by 3

BOOST_AUTO_TEST_CASEFunction · 0.40
BOOST_AUTO_TEST_CASEFunction · 0.40
FUZZ_TARGETFunction · 0.40