13 #include <boost/variant/apply_visitor.hpp>
14 #include <boost/variant/static_visitor.hpp>
21 class DestinationEncoder :
public boost::static_visitor<std::string> {
29 std::string operator()(
const PKHash &
id)
const {
30 std::vector<uint8_t> data =
32 data.insert(data.end(),
id.begin(),
id.end());
36 std::string operator()(
const ScriptHash &
id)
const {
37 std::vector<uint8_t> data =
39 data.insert(data.end(),
id.begin(),
id.end());
43 std::string operator()(
const CNoDestination &no)
const {
return {}; }
48 std::vector<uint8_t> data;
57 const std::vector<uint8_t> &pubkey_prefix =
59 if (data.size() == hash.
size() + pubkey_prefix.size() &&
60 std::equal(pubkey_prefix.begin(), pubkey_prefix.end(), data.begin())) {
61 std::copy(data.begin() + pubkey_prefix.size(), data.end(),
68 const std::vector<uint8_t> &script_prefix =
70 if (data.size() == hash.
size() + script_prefix.size() &&
71 std::equal(script_prefix.begin(), script_prefix.end(), data.begin())) {
72 std::copy(data.begin() + script_prefix.size(), data.end(),
86 std::vector<uint8_t> data;
88 const std::vector<uint8_t> &privkey_prefix =
90 if ((data.size() == 32 + privkey_prefix.size() ||
91 (data.size() == 33 + privkey_prefix.size() && data.back() == 1)) &&
92 std::equal(privkey_prefix.begin(), privkey_prefix.end(),
94 bool compressed = data.size() == 33 + privkey_prefix.size();
95 key.
Set(data.begin() + privkey_prefix.size(),
96 data.begin() + privkey_prefix.size() + 32, compressed);
112 data.insert(data.end(), key.
begin(), key.
end());
123 std::vector<uint8_t> data;
125 const std::vector<uint8_t> &
prefix =
128 std::equal(
prefix.begin(),
prefix.end(), data.begin())) {
136 std::vector<uint8_t> data =
138 size_t size = data.size();
140 key.
Encode(data.data() + size);
147 std::vector<uint8_t> data;
149 const std::vector<uint8_t> &
prefix =
152 std::equal(
prefix.begin(),
prefix.end(), data.begin())) {
160 std::vector<uint8_t> data =
162 size_t size = data.size();
164 key.
Encode(data.data() + size);
193 return boost::apply_visitor(DestinationEncoder(params), dest);
198 return DecodeLegacyDestination(str, params);
bool DecodeBase58Check(const char *psz, std::vector< uint8_t > &vchRet, int max_ret_len)
Decode a base58-encoded string (psz) that includes a checksum into a byte vector (vchRet),...
std::string EncodeBase58Check(Span< const uint8_t > input)
Encode a byte span into a base58-encoded string, including checksum.
std::string EncodeCashAddr(const CTxDestination &dst, const CChainParams ¶ms)
CTxDestination DecodeCashAddr(const std::string &addr, const CChainParams ¶ms)
const CChainParams & Params()
Return the currently selected parameters.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
const std::vector< uint8_t > & Base58Prefix(Base58Type type) const
Return the list of hostnames to look up for DNS seeds.
An encapsulated secp256k1 private key.
const uint8_t * begin() const
bool IsValid() const
Check whether this private key is valid.
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
const uint8_t * end() const
virtual bool UseCashAddrEncoding() const =0
virtual const CChainParams & GetChainParams() const =0
unsigned int size() const
void memory_cleanse(void *ptr, size_t len)
Secure overwrite a buffer (possibly containing secret data) with zero-bytes.
std::string EncodeDestination(const CTxDestination &dest, const Config &config)
bool IsValidDestinationString(const std::string &str, const CChainParams ¶ms)
std::string EncodeExtKey(const CExtKey &key)
CExtPubKey DecodeExtPubKey(const std::string &str)
std::string EncodeSecret(const CKey &key)
CTxDestination DecodeDestination(const std::string &addr, const CChainParams ¶ms)
CKey DecodeSecret(const std::string &str)
std::string EncodeExtPubKey(const CExtPubKey &key)
CTxDestination DecodeLegacyAddr(const std::string &str, const CChainParams ¶ms)
std::string EncodeLegacyAddr(const CTxDestination &dest, const CChainParams ¶ms)
CExtKey DecodeExtKey(const std::string &str)
const CChainParams & m_params
const unsigned int BIP32_EXTKEY_SIZE
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
boost::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
void Encode(uint8_t code[BIP32_EXTKEY_SIZE]) const
void Decode(const uint8_t code[BIP32_EXTKEY_SIZE])
void Encode(uint8_t code[BIP32_EXTKEY_SIZE]) const
void Decode(const uint8_t code[BIP32_EXTKEY_SIZE])