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 = | if (CashAddrContent content( | ||||
DecodeCashAddrContent(addr, params.CashAddrPrefix()); | DecodeCashAddrContent(addr, params.CashAddrPrefix())); | ||||
if (content.hash.size() == 0) { | content.hash.size() != 0) { | ||||
return CNoDestination{}; | |||||
} | |||||
return DecodeCashAddrDestination(content); | return DecodeCashAddrDestination(content); | ||||
} else if (content = DecodeCashAddrContent( | |||||
addr, params.BackwardsCompatibleCashAddrPrefix()); | |||||
content.hash.size() != 0) { | |||||
return DecodeCashAddrDestination(content); | |||||
} else { | |||||
return CTxDestination{}; | |||||
} | |||||
} | } | ||||
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); | ||||
▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines |