16 #include <boost/variant/apply_visitor.hpp>
17 #include <boost/variant/static_visitor.hpp>
20 static const char* pszBase58 =
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
22 bool DecodeBase58(
const char *psz, std::vector<unsigned char>& vch) {
24 while (*psz && isspace(*psz))
33 std::vector<unsigned char> b256(strlen(psz) * 733 / 1000 + 1);
35 while (*psz && !isspace(*psz)) {
37 const char *ch = strchr(pszBase58, *psz);
41 int carry = ch - pszBase58;
42 for (std::vector<unsigned char>::reverse_iterator it = b256.rbegin(); it != b256.rend(); it++) {
56 std::vector<unsigned char>::iterator it = b256.begin();
57 while (it != b256.end() && *it == 0)
60 vch.reserve(zeroes + (b256.end() - it));
61 vch.assign(zeroes, 0x00);
62 while (it != b256.end())
63 vch.push_back(*(it++));
67 std::string
EncodeBase58(
const unsigned char* pbegin,
const unsigned char* pend) {
70 while (pbegin != pend && *pbegin == 0) {
75 std::vector<unsigned char> b58((pend - pbegin) * 138 / 100 + 1);
77 while (pbegin != pend) {
80 for (std::vector<unsigned char>::reverse_iterator it = b58.rbegin(); it != b58.rend(); it++) {
89 std::vector<unsigned char>::iterator it = b58.begin();
90 while (it != b58.end() && *it == 0)
94 str.reserve(zeroes + (b58.end() - it));
95 str.assign(zeroes,
'1');
96 while (it != b58.end())
97 str += pszBase58[*(it++)];
105 bool DecodeBase58(
const std::string& str, std::vector<unsigned char>& vchRet) {
111 std::vector<unsigned char> vch(vchIn);
113 vch.insert(vch.end(), (
unsigned char*)&hash, (
unsigned char*)&hash + 4);
125 uint256 hash =
Hash(vchRet.begin(), vchRet.end()-4);
126 if (memcmp(&hash, &vchRet.
end()[-4], 4) != 0)
131 vchRet.resize(vchRet.size()-4);
151 void CBase58Data::SetData(
const std::vector<unsigned char> &vchVersionIn,
const unsigned char *pbegin,
const unsigned char *pend) {
152 SetData(vchVersionIn, (
void*)pbegin, pend - pbegin);
156 std::vector<unsigned char> vchTemp;
158 if ((!rc58) || (vchTemp.size() < nVersionBytes)) {
163 vchVersion.assign(vchTemp.begin(), vchTemp.begin() + nVersionBytes);
164 vchData.resize(vchTemp.size() - nVersionBytes);
167 OPENSSL_cleanse(&vchTemp[0],
vchData.size());
190 class CAnoncoinAddressVisitor :
public boost::static_visitor<bool> {
196 bool operator()(
const CKeyID &
id)
const {
return addr->
Set(
id); }
197 bool operator()(
const CScriptID &
id)
const {
return addr->
Set(
id); }
213 return boost::apply_visitor(CAnoncoinAddressVisitor(
this), dest);
217 bool fCorrectSize =
vchData.size() == 20;
220 return fCorrectSize && fKnownVersion;
265 return fExpectedFormat && fCorrectVersion;
bool DecodeBase58(const char *psz, std::vector< unsigned char > &vch)
Decode a base58-encoded string (psz) into a byte vector (vchRet).
const unsigned char * begin() const
bool Set(const CKeyID &id)
CTxDestination Get() const
std::string EncodeBase58(const unsigned char *pbegin, const unsigned char *pend)
Encode a byte sequence as a base58-encoded string.
bool GetKeyID(CKeyID &keyID) const
void SetData(const std::vector< unsigned char > &vchVersionIn, const void *pdata, size_t nSize)
void SetKey(const CKey &vchSecret)
const std::vector< unsigned char > & Base58Prefix(Base58Type type) const
Base class for all base58-encoded data.
bool IsCompressed() const
base58-encoded Anoncoin addresses.
bool DecodeBase58Check(const char *psz, std::vector< unsigned char > &vchRet)
Decode a base58-encoded string (psz) that includes a checksum into a byte vector (vchRet), return true if decoding is successful.
bool SetString(const char *pszSecret)
std::string ToString() const
uint256 Hash(const T1 pbegin, const T1 pend)
void Set(const T pbegin, const T pend, bool fCompressedIn)
bool SetString(const char *psz, unsigned int nVersionBytes=1)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
const CChainParams & Params()
Return the currently selected parameters.
void * memcpy(void *a, const void *b, size_t c)
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)
An encapsulated private key.
unsigned int size() const
std::string EncodeBase58Check(const std::vector< unsigned char > &vchIn)
Encode a byte vector into a base58-encoded string, including checksum.
std::vector< unsigned char > vchVersion
int CompareTo(const CBase58Data &b58) const