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

Function Encode

src/blech32.cpp:170–183  ·  view source on GitHub ↗

Encode a Blech32 or Blech32m string. */

Source from the content-addressed store, hash-verified

168
169/** Encode a Blech32 or Blech32m string. */
170std::string Encode(Encoding encoding, const std::string& hrp, const data& values) {
171 // First ensure that the HRP is all lowercase. BIP-173 and BIP350 require an encoder
172 // to return a lowercase Blech32/Blech32m string, but if given an uppercase HRP, the
173 // result will always be invalid.
174 for (const char& c : hrp) assert(c < 'A' || c > 'Z');
175 data checksum = CreateChecksum(encoding, hrp, values);
176 data combined = Cat(values, checksum);
177 std::string ret = hrp + '1';
178 ret.reserve(ret.size() + combined.size());
179 for (const auto c : combined) {
180 ret += CHARSET[c];
181 }
182 return ret;
183}
184
185/** Decode a Blech32 or Blech32m string. */
186DecodeResult Decode(const std::string& str) {

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected