Changeset View
Changeset View
Standalone View
Standalone View
src/cashaddrenc.cpp
Show First 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | |||||
std::string EncodeCashAddr(const std::string &prefix, | std::string EncodeCashAddr(const std::string &prefix, | ||||
const CashAddrContent &content) { | const CashAddrContent &content) { | ||||
std::vector<uint8_t> data = PackAddrData(content.hash, content.type); | std::vector<uint8_t> data = PackAddrData(content.hash, content.type); | ||||
return cashaddr::Encode(prefix, data); | return cashaddr::Encode(prefix, data); | ||||
} | } | ||||
CTxDestination DecodeCashAddr(const std::string &addr, | CTxDestination DecodeCashAddr(const std::string &addr, | ||||
const CChainParams ¶ms) { | const CChainParams ¶ms) { | ||||
CashAddrContent content = | const std::array<std::string, 2> prefixes{ | ||||
DecodeCashAddrContent(addr, params.CashAddrPrefix()); | {params.CashAddrPrefix(), params.CashAddrLegacyPrefix()}}; | ||||
if (content.hash.size() == 0) { | |||||
return CNoDestination{}; | |||||
} | |||||
for (const auto &prefix : prefixes) { | |||||
CashAddrContent content = DecodeCashAddrContent(addr, prefix); | |||||
if (content.hash.size() != 0) { | |||||
return DecodeCashAddrDestination(content); | return DecodeCashAddrDestination(content); | ||||
} | } | ||||
} | |||||
return CNoDestination{}; | |||||
} | |||||
CashAddrContent DecodeCashAddrContent(const std::string &addr, | CashAddrContent DecodeCashAddrContent(const std::string &addr, | ||||
const std::string &expectedPrefix) { | const std::string &expectedPrefix) { | ||||
std::string prefix; | std::string prefix; | ||||
std::vector<uint8_t> payload; | std::vector<uint8_t> payload; | ||||
std::tie(prefix, payload) = cashaddr::Decode(addr, expectedPrefix); | std::tie(prefix, payload) = cashaddr::Decode(addr, expectedPrefix); | ||||
if (prefix != expectedPrefix) { | if (prefix != expectedPrefix) { | ||||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |