21 size_t size =
id.size();
49 throw std::runtime_error(
50 "Error packing cashaddr: invalid address length");
54 data.insert(data.end(), std::begin(
id), std::end(
id));
60 converted.reserve(((size + 1) * 8 + 4) / 5);
62 std::begin(data), std::end(data));
68class CashAddrEncoder {
72 std::string operator()(
const PKHash &
id)
const {
77 std::string operator()(
const ScriptHash &
id)
const {
82 std::string operator()(
const CNoDestination &)
const {
return ""; }
92 return std::visit(CashAddrEncoder(params),
dst);
105 if (
content.hash.size() == 0) {
124 std::vector<uint8_t> data;
125 data.reserve(
payload.size() * 5 / 8);
133 if (version & 0x80) {
140 if (version & 0x04) {
150 data.erase(data.begin());
151 return {type, std::move(data)};
155 if (
content.hash.size() != 20) {
std::string EncodeCashAddr(const CTxDestination &dst, const CChainParams ¶ms)
CashAddrContent DecodeCashAddrContent(const std::string &addr, const std::string &expectedPrefix)
CTxDestination DecodeCashAddrDestination(const CashAddrContent &content)
CTxDestination DecodeCashAddr(const std::string &addr, const CChainParams ¶ms)
std::vector< uint8_t > PackCashAddrContent(const CashAddrContent &content)
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
const std::string & CashAddrPrefix() const
std::pair< std::string, data > Decode(const std::string &str, const std::string &default_prefix)
Decode a cashaddr string.
std::string Encode(const std::string &prefix, const data &payload)
Encode a cashaddr string.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.