Changeset View
Changeset View
Standalone View
Standalone View
src/cashaddrenc.cpp
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | std::vector<uint8_t> PackAddrData(const T &id, uint8_t type) { | ||||
return converted; | return converted; | ||||
} | } | ||||
// Implements encoding of CTxDestination using cashaddr. | // Implements encoding of CTxDestination using cashaddr. | ||||
class CashAddrEncoder : public boost::static_visitor<std::string> { | class CashAddrEncoder : public boost::static_visitor<std::string> { | ||||
public: | public: | ||||
CashAddrEncoder(const CChainParams &p) : params(p) {} | CashAddrEncoder(const CChainParams &p) : params(p) {} | ||||
std::string operator()(const CKeyID &id) const { | std::string operator()(const PKHash &id) const { | ||||
std::vector<uint8_t> data = PackAddrData(id, PUBKEY_TYPE); | std::vector<uint8_t> data = PackAddrData(id, PUBKEY_TYPE); | ||||
return cashaddr::Encode(params.CashAddrPrefix(), data); | return cashaddr::Encode(params.CashAddrPrefix(), data); | ||||
} | } | ||||
std::string operator()(const CScriptID &id) const { | std::string operator()(const ScriptHash &id) const { | ||||
std::vector<uint8_t> data = PackAddrData(id, SCRIPT_TYPE); | std::vector<uint8_t> data = PackAddrData(id, SCRIPT_TYPE); | ||||
return cashaddr::Encode(params.CashAddrPrefix(), data); | return cashaddr::Encode(params.CashAddrPrefix(), data); | ||||
} | } | ||||
std::string operator()(const CNoDestination &) const { return ""; } | std::string operator()(const CNoDestination &) const { return ""; } | ||||
private: | private: | ||||
const CChainParams ¶ms; | const CChainParams ¶ms; | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | if (content.hash.size() != 20) { | ||||
return CNoDestination{}; | return CNoDestination{}; | ||||
} | } | ||||
uint160 hash; | uint160 hash; | ||||
std::copy(begin(content.hash), end(content.hash), hash.begin()); | std::copy(begin(content.hash), end(content.hash), hash.begin()); | ||||
switch (content.type) { | switch (content.type) { | ||||
case PUBKEY_TYPE: | case PUBKEY_TYPE: | ||||
return CKeyID(hash); | return PKHash(hash); | ||||
case SCRIPT_TYPE: | case SCRIPT_TYPE: | ||||
return CScriptID(hash); | return ScriptHash(hash); | ||||
default: | default: | ||||
return CNoDestination{}; | return CNoDestination{}; | ||||
} | } | ||||
} | } | ||||
// PackCashAddrContent allows for testing PackAddrData in unittests due to | // PackCashAddrContent allows for testing PackAddrData in unittests due to | ||||
// template definitions. | // template definitions. | ||||
std::vector<uint8_t> PackCashAddrContent(const CashAddrContent &content) { | std::vector<uint8_t> PackCashAddrContent(const CashAddrContent &content) { | ||||
return PackAddrData(content.hash, content.type); | return PackAddrData(content.hash, content.type); | ||||
} | } |