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)
25 while (*psz && isspace(*psz))
35 int size = strlen(psz) * 733 /1000 + 1;
36 std::vector<unsigned char> b256(size);
38 while (*psz && !isspace(*psz)) {
40 const char* ch = strchr(pszBase58, *psz);
44 int carry = ch - pszBase58;
46 for (std::vector<unsigned char>::reverse_iterator it = b256.rbegin(); (carry != 0 || i < length) && (it != b256.rend()); ++it, ++i) {
61 std::vector<unsigned char>::iterator it = b256.begin() + (size - length);
62 while (it != b256.end() && *it == 0)
65 vch.reserve(zeroes + (b256.end() - it));
66 vch.assign(zeroes, 0x00);
67 while (it != b256.end())
68 vch.push_back(*(it++));
72 std::string
EncodeBase58(
const unsigned char* pbegin,
const unsigned char* pend)
77 while (pbegin != pend && *pbegin == 0) {
82 int size = (pend - pbegin) * 138 / 100 + 1;
83 std::vector<unsigned char> b58(size);
85 while (pbegin != pend) {
89 for (std::vector<unsigned char>::reverse_iterator it = b58.rbegin(); (carry != 0 || i < length) && (it != b58.rend()); it++, i++) {
100 std::vector<unsigned char>::iterator it = b58.begin() + (size - length);
101 while (it != b58.end() && *it == 0)
105 str.reserve(zeroes + (b58.end() - it));
106 str.assign(zeroes,
'1');
107 while (it != b58.end())
108 str += pszBase58[*(it++)];
114 return EncodeBase58(vch.data(), vch.data() + vch.size());
117 bool DecodeBase58(
const std::string& str, std::vector<unsigned char>& vchRet)
125 std::vector<unsigned char> vch(vchIn);
127 vch.insert(vch.end(), (
unsigned char*)&hash, (
unsigned char*)&hash + 4);
134 (vchRet.size() < 4)) {
139 uint256 hash =
Hash(vchRet.begin(), vchRet.end() - 4);
140 if (memcmp(&hash, &vchRet[vchRet.size() - 4], 4) != 0) {
144 vchRet.resize(vchRet.size() - 4);
167 void CBase58Data::SetData(
const std::vector<unsigned char>& vchVersionIn,
const unsigned char* pbegin,
const unsigned char* pend)
169 SetData(vchVersionIn, (
void*)pbegin, pend - pbegin);
174 std::vector<unsigned char> vchTemp;
176 if ((!rc58) || (vchTemp.size() < nVersionBytes)) {
181 vchVersion.assign(vchTemp.begin(), vchTemp.begin() + nVersionBytes);
182 vchData.resize(vchTemp.size() - nVersionBytes);
217 class CRavenAddressVisitor :
public boost::static_visitor<bool>
223 explicit CRavenAddressVisitor(
CRavenAddress* addrIn) : addr(addrIn) {}
225 bool operator()(
const CKeyID&
id)
const {
return addr->
Set(
id); }
226 bool operator()(
const CScriptID&
id)
const {
return addr->
Set(
id); }
246 return boost::apply_visitor(CRavenAddressVisitor(
this), dest);
256 bool fCorrectSize =
vchData.size() == 20;
259 return fCorrectSize && fKnownVersion;
313 return fExpectedFormat && fCorrectVersion;
329 if (!addr.
IsValid())
return "";
bool DecodeBase58(const char *psz, std::vector< unsigned char > &vch)
Decode a base58-encoded string (psz) into a byte vector (vchRet).
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
bool Set(const CKeyID &id)
CTxDestination DecodeDestination(const std::string &str)
std::string EncodeBase58(const unsigned char *pbegin, const unsigned char *pend)
Why base-58 instead of standard base-64 encoding?
int CompareTo(const CBase58Data &b58) const
CChainParams defines various tweakable parameters of a given instance of the Raven system...
void SetData(const std::vector< unsigned char > &vchVersionIn, const void *pdata, size_t nSize)
const unsigned char * begin() const
bool GetIndexKey(uint160 &hashBytes, int &type) const
std::string ToString() const
Base class for all base58-encoded data.
void memory_cleanse(void *ptr, size_t len)
bool IsValidDestinationString(const std::string &str, const CChainParams ¶ms)
base58-encoded Raven addresses.
bool SetString(const char *pszSecret)
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.
unsigned int size() const
Simple read-only vector-like interface.
uint256 Hash(const T1 pbegin, const T1 pend)
Compute the 256-bit hash of an object.
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.
bool SetString(const char *psz, unsigned int nVersionBytes=1)
std::string EncodeDestination(const CTxDestination &dest)
const CChainParams & Params()
Return the currently selected parameters.
void * memcpy(void *a, const void *b, size_t c)
CTxDestination Get() 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)
An encapsulated private key.
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
the version byte(s)
bool IsValid() const
Check whether this private key is valid.
const std::vector< unsigned char > & Base58Prefix(Base58Type type) const
void SetKey(const CKey &vchSecret)