11 #include <boost/variant/apply_visitor.hpp>
12 #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))
34 std::vector<unsigned char> b256(strlen(psz) * 733 / 1000 + 1);
36 while (*psz && !isspace(*psz)) {
38 const char* ch = strchr(pszBase58, *psz);
42 int carry = ch - pszBase58;
43 for (std::vector<unsigned char>::reverse_iterator it = b256.rbegin(); it != b256.rend(); it++) {
57 std::vector<unsigned char>::iterator it = b256.begin();
58 while (it != b256.end() && *it == 0)
61 vch.reserve(zeroes + (b256.end() - it));
62 vch.assign(zeroes, 0x00);
63 while (it != b256.end())
64 vch.push_back(*(it++));
70 std::vector<unsigned char> vch;
75 for (
unsigned int i = 0; i < vch.size(); i++) {
76 unsigned char* c = &vch[i];
77 ss << std::setw(2) << std::setfill(
'0') << (int)c[0];
83 std::string
EncodeBase58(
const unsigned char* pbegin,
const unsigned char* pend)
87 while (pbegin != pend && *pbegin == 0) {
92 std::vector<unsigned char> b58((pend - pbegin) * 138 / 100 + 1);
94 while (pbegin != pend) {
97 for (std::vector<unsigned char>::reverse_iterator it = b58.rbegin(); it != b58.rend(); it++) {
106 std::vector<unsigned char>::iterator it = b58.begin();
107 while (it != b58.end() && *it == 0)
111 str.reserve(zeroes + (b58.end() - it));
112 str.assign(zeroes,
'1');
113 while (it != b58.end())
114 str += pszBase58[*(it++)];
123 bool DecodeBase58(
const std::string& str, std::vector<unsigned char>& vchRet)
131 std::vector<unsigned char> vch(vchIn);
133 vch.insert(vch.end(), (
unsigned char*)&hash, (
unsigned char*)&hash + 4);
140 (vchRet.size() < 4)) {
145 uint256 hash =
Hash(vchRet.begin(), vchRet.end() - 4);
146 if (memcmp(&hash, &vchRet.
end()[-4], 4) != 0) {
150 vchRet.resize(vchRet.size() - 4);
173 void CBase58Data::SetData(
const std::vector<unsigned char>& vchVersionIn,
const unsigned char* pbegin,
const unsigned char* pend)
175 SetData(vchVersionIn, (
void*)pbegin, pend - pbegin);
180 std::vector<unsigned char> vchTemp;
182 if ((!rc58) || (vchTemp.size() < nVersionBytes)) {
187 vchVersion.assign(vchTemp.begin(), vchTemp.begin() + nVersionBytes);
188 vchData.resize(vchTemp.size() - nVersionBytes);
222 class CBitcoinAddressVisitor :
public boost::static_visitor<bool>
230 bool operator()(
const CKeyID&
id)
const {
return addr->
Set(
id); }
231 bool operator()(
const CScriptID&
id)
const {
return addr->
Set(
id); }
251 return boost::apply_visitor(CBitcoinAddressVisitor(
this), dest);
261 bool fCorrectSize =
vchData.size() == 20;
264 return fCorrectSize && fKnownVersion;
316 return fExpectedFormat && fCorrectVersion;