9 #include <boost/variant/apply_visitor.hpp>
10 #include <boost/variant/static_visitor.hpp>
18 class DestinationEncoder :
public boost::static_visitor<std::string>
27 std::string operator()(
const CKeyID&
id)
const
29 std::vector<unsigned char> data = m_params.
Base58Prefix(m_addrType);
30 data.insert(data.end(),
id.begin(),
id.end());
37 data.insert(data.end(),
id.begin(),
id.end());
41 std::string operator()(
const CScriptID&
id)
const
44 data.insert(data.end(),
id.begin(),
id.end());
48 std::string operator()(
const CNoDestination& no)
const {
return ""; }
53 std::vector<unsigned char> data;
60 if (data.size() == hash.
size() + pubkey_prefix.size() && std::equal(pubkey_prefix.begin(), pubkey_prefix.end(), data.begin())) {
61 std::copy(data.begin() + pubkey_prefix.size(), data.end(), hash.
begin());
66 if (data.size() == hash.
size() + exchange_pubkey_prefix.size() && std::equal(exchange_pubkey_prefix.begin(), exchange_pubkey_prefix.end(), data.begin())) {
68 std::copy(data.begin() + exchange_pubkey_prefix.size(), data.end(), hash.
begin());
73 if (data.size() == hash.
size() + staking_prefix.size() && std::equal(staking_prefix.begin(), staking_prefix.end(), data.begin())) {
75 std::copy(data.begin() + staking_prefix.size(), data.end(), hash.
begin());
81 if (data.size() == hash.
size() + script_prefix.size() && std::equal(script_prefix.begin(), script_prefix.end(), data.begin())) {
82 std::copy(data.begin() + script_prefix.size(), data.end(), hash.
begin());
98 return boost::apply_visitor(DestinationEncoder(
Params(), addrType), dest);
115 bool isStaking =
false;
116 bool isExchange =
false;
129 std::vector<unsigned char> data;
132 if ((data.size() == 32 + privkey_prefix.size() ||
133 (data.size() == 33 + privkey_prefix.size() && data.back() == 1)) &&
134 std::equal(privkey_prefix.begin(), privkey_prefix.end(), data.begin())) {
135 bool compressed = data.size() == 33 + privkey_prefix.size();
136 key.
Set(data.begin() + privkey_prefix.size(), data.begin() + privkey_prefix.size() + 32, compressed);
148 data.insert(data.end(), key.
begin(), key.
end());
159 std::vector<unsigned char> data;
163 std::equal(
prefix.begin(),
prefix.end(), data.begin())) {
172 size_t size = data.size();
174 key.
Encode(data.data() + size);
183 std::vector<unsigned char> data;
196 size_t size = data.size();
198 key.
Encode(data.data() + size);
bool DecodeBase58Check(const char *psz, std::vector< unsigned char > &vchRet, int max_ret_len)
Decode a base58-encoded string (psz) that includes a checksum into a byte vector (vchRet),...
std::string EncodeBase58Check(const std::vector< unsigned char > &vchIn)
Encode a byte vector into a base58-encoded string, including checksum.
const CChainParams & Params()
Return the currently selected parameters.
CChainParams defines various tweakable parameters of a given instance of the PIVX system.
const std::vector< unsigned char > & Base58Prefix(Base58Type type) const
A reference to a CKey: the Hash160 of its serialized public key, special case for exchange key.
An encapsulated private key.
const unsigned char * end() 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 unsigned char * begin() const
A reference to a CKey: the Hash160 of its serialized public key.
A reference to a CScript: the Hash160 of its serialization (see script.h)
unsigned int size() const
void memory_cleanse(void *ptr, size_t len)
bool IsValidDestinationString(const std::string &str, bool fStaking, const CChainParams ¶ms)
CTxDestination DecodeDestination(const std::string &str)
std::string EncodeDestination(const CTxDestination &dest, bool isStaking, bool isExchange)
std::string EncodeSecret(const CKey &key)
CKey DecodeSecret(const std::string &str)
std::string EncodeExtPubKey(const CExtPubKey &key)
std::string EncodeExtKey(const CExtKey &key)
CExtPubKey DecodeExtPubKey(const std::string &str)
CExtKey DecodeExtKey(const std::string &str)
bool IsValidDestination(const CWDestination &address)
const unsigned int BIP32_EXTKEY_SIZE
boost::variant< CNoDestination, CKeyID, CScriptID, CExchangeKeyID > CTxDestination
A txout script template with a specific destination.
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE])
void Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const
void Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE])