Changeset View
Changeset View
Standalone View
Standalone View
src/cashaddrenc.cpp
Show First 20 Lines • Show All 93 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); | ||||
} | } | ||||
// Convert a CTxDestination to a CashAddrContent | |||||
class CashAddrContentEncoder : public boost::static_visitor<CashAddrContent> { | |||||
public: | |||||
CashAddrContent operator()(const PKHash &id) const { | |||||
return CashAddrContent{CashAddrType::PUBKEY_TYPE, id}; | |||||
} | |||||
CashAddrContent operator()(const ScriptHash &id) const { | |||||
return CashAddrContent{CashAddrType::SCRIPT_TYPE, id}; | |||||
} | |||||
CashAddrContent operator()(const CNoDestination &) const { return {}; } | |||||
}; | |||||
CashAddrContent EncodeCashAddrContent(const CTxDestination &dest) { | |||||
return boost::apply_visitor(CashAddrContentEncoder(), dest); | |||||
} | |||||
CTxDestination DecodeCashAddr(const std::string &addr, | CTxDestination DecodeCashAddr(const std::string &addr, | ||||
const CChainParams ¶ms) { | const CChainParams ¶ms) { | ||||
CashAddrContent content = | CashAddrContent content = | ||||
DecodeCashAddrContent(addr, params.CashAddrPrefix()); | DecodeCashAddrContent(addr, params.CashAddrPrefix()); | ||||
if (content.hash.size() == 0) { | if (content.hash.size() == 0) { | ||||
return CNoDestination{}; | return CNoDestination{}; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |