15 #include <boost/variant/apply_visitor.hpp>
16 #include <boost/variant/static_visitor.hpp>
19 static const char*
pszBase58 =
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
21 bool DecodeBase58(
const char *psz, std::vector<unsigned char>& vch) {
23 while (*psz && isspace(*psz))
32 std::vector<unsigned char> b256(strlen(psz) * 733 / 1000 + 1);
34 while (*psz && !isspace(*psz)) {
41 for (std::vector<unsigned char>::reverse_iterator it = b256.rbegin(); it != b256.rend(); it++) {
55 std::vector<unsigned char>::iterator it = b256.begin();
56 while (it != b256.end() && *it == 0)
59 vch.reserve(zeroes + (b256.end() - it));
60 vch.assign(zeroes, 0x00);
61 while (it != b256.end())
62 vch.push_back(*(it++));
66 std::string
EncodeBase58(
const unsigned char* pbegin,
const unsigned char* pend) {
69 while (pbegin != pend && *pbegin == 0) {
74 std::vector<unsigned char> b58((pend - pbegin) * 138 / 100 + 1);
76 while (pbegin != pend) {
79 for (std::vector<unsigned char>::reverse_iterator it = b58.rbegin(); it != b58.rend(); it++) {
88 std::vector<unsigned char>::iterator it = b58.begin();
89 while (it != b58.end() && *it == 0)
93 str.reserve(zeroes + (b58.end() - it));
94 str.assign(zeroes,
'1');
95 while (it != b58.end())
104 bool DecodeBase58(
const std::string& str, std::vector<unsigned char>& vchRet) {
110 std::vector<unsigned char> vch(vchIn);
112 vch.insert(vch.end(), (
unsigned char*)&hash, (
unsigned char*)&hash + 4);
124 uint256 hash =
Hash(vchRet.begin(), vchRet.end()-4);
125 if (memcmp(&hash, &vchRet.end()[-4], 4) != 0)
130 vchRet.resize(vchRet.size()-4);
150 void CBase58Data::SetData(
const std::vector<unsigned char> &vchVersionIn,
const unsigned char *pbegin,
const unsigned char *pend) {
151 SetData(vchVersionIn, (
void*)pbegin, pend - pbegin);
155 std::vector<unsigned char> vchTemp;
157 if ((!rc58) || (vchTemp.size() < nVersionBytes)) {
162 vchVersion.assign(vchTemp.begin(), vchTemp.begin() + nVersionBytes);
163 vchData.resize(vchTemp.size() - nVersionBytes);
166 OPENSSL_cleanse(&vchTemp[0],
vchData.size());
189 class CBitcoinAddressVisitor :
public boost::static_visitor<bool> {
195 bool operator()(
const CKeyID &
id)
const {
return addr->
Set(
id); }
196 bool operator()(
const CScriptID &
id)
const {
return addr->
Set(
id); }
212 return boost::apply_visitor(CBitcoinAddressVisitor(
this), dest);
216 bool fCorrectSize =
vchData.size() == 20;
219 return fCorrectSize && fKnownVersion;
264 return fExpectedFormat && fCorrectVersion;
bool DecodeBase58(const char *psz, std::vector< unsigned char > &vch)
Decode a base58-encoded string (psz) into a byte vector (vchRet).
void SetKey(const CKey &vchSecret)
const unsigned char * begin() const
std::string EncodeBase58(const unsigned char *pbegin, const unsigned char *pend)
Encode a byte sequence as a base58-encoded string.
base58-encoded Bitcoin addresses.
void SetData(const std::vector< unsigned char > &vchVersionIn, const void *pdata, size_t nSize)
CTxDestination Get() const
const std::vector< unsigned char > & Base58Prefix(Base58Type type) const
bool GetKeyID(CKeyID &keyID) const
bool SetString(const char *pszSecret)
Base class for all base58-encoded data.
bool IsCompressed() const
bool Set(const CKeyID &id)
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.
std::string ToString() const
uint256 Hash(const T1 pbegin, const T1 pend)
static const char * pszBase58
void Set(const T pbegin, const T pend, bool fCompressedIn)
bool SetString(const char *psz, unsigned int nVersionBytes=1)
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)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
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