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)
24 while (*psz && isspace(*psz))
34 int size = strlen(psz) * 733 /1000 + 1;
35 std::vector<unsigned char> b256(size);
37 while (*psz && !isspace(*psz)) {
45 for (std::vector<unsigned char>::reverse_iterator it = b256.rbegin(); (carry != 0 || i < length) && (it != b256.rend()); ++it, ++i) {
60 std::vector<unsigned char>::iterator it = b256.begin() + (size - length);
61 while (it != b256.end() && *it == 0)
64 vch.reserve(zeroes + (b256.end() - it));
65 vch.assign(zeroes, 0x00);
66 while (it != b256.end())
67 vch.push_back(*(it++));
71 std::string
EncodeBase58(
const unsigned char* pbegin,
const unsigned char* pend)
76 while (pbegin != pend && *pbegin == 0) {
81 int size = (pend - pbegin) * 138 / 100 + 1;
82 std::vector<unsigned char> b58(size);
84 while (pbegin != pend) {
88 for (std::vector<unsigned char>::reverse_iterator it = b58.rbegin(); (carry != 0 || i < length) && (it != b58.rend()); it++, i++) {
99 std::vector<unsigned char>::iterator it = b58.begin() + (size - length);
100 while (it != b58.end() && *it == 0)
104 str.reserve(zeroes + (b58.end() - it));
105 str.assign(zeroes,
'1');
106 while (it != b58.end())
116 bool DecodeBase58(
const std::string& str, std::vector<unsigned char>& vchRet)
124 std::vector<unsigned char> vch(vchIn);
126 vch.insert(vch.end(), (
unsigned char*)&hash, (
unsigned char*)&hash + 4);
133 (vchRet.size() < 4)) {
138 uint256 hash =
Hash(vchRet.begin(), vchRet.end() - 4);
139 if (memcmp(&hash, &vchRet.
end()[-4], 4) != 0) {
143 vchRet.resize(vchRet.size() - 4);
166 void CBase58Data::SetData(
const std::vector<unsigned char>& vchVersionIn,
const unsigned char* pbegin,
const unsigned char* pend)
168 SetData(vchVersionIn, (
void*)pbegin, pend - pbegin);
173 std::vector<unsigned char> vchTemp;
175 if ((!rc58) || (vchTemp.size() < nVersionBytes)) {
180 vchVersion.assign(vchTemp.begin(), vchTemp.begin() + nVersionBytes);
181 vchData.resize(vchTemp.size() - nVersionBytes);
215 class CBitcoinAddressVisitor :
public boost::static_visitor<bool>
223 bool operator()(
const CKeyID&
id)
const {
return addr->
Set(
id); }
224 bool operator()(
const CScriptID&
id)
const {
return addr->
Set(
id); }
244 return boost::apply_visitor(CBitcoinAddressVisitor(
this), dest);
254 bool fCorrectSize =
vchData.size() == 20;
257 return fCorrectSize && fKnownVersion;
326 return fExpectedFormat && fCorrectVersion;
bool SetString(const char *pszSecret)
bool DecodeBase58(const char *psz, std::vector< unsigned char > &vch)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
std::string EncodeBase58(const unsigned char *pbegin, const unsigned char *pend)
std::string ToString() const
void memory_cleanse(void *ptr, size_t len)
std::vector< unsigned char > vchVersion
the version byte(s)
int CompareTo(const CBase58Data &b58) const
bool Set(const CKeyID &id)
bool DecodeBase58Check(const char *psz, std::vector< unsigned char > &vchRet)
uint256 Hash(const T1 pbegin, const T1 pend)
static const char * pszBase58
bool SetString(const char *psz, unsigned int nVersionBytes=1)
const unsigned char * begin() const
CTxDestination Get() const
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
const CChainParams & Params()
void * memcpy(void *a, const void *b, size_t c)
void SetKey(const CKey &vchSecret)
bool GetKeyID(CKeyID &keyID) const
bool GetIndexKey(uint160 &hashBytes, int &type) const
unsigned int size() const
Simple read-only vector-like interface.
void SetData(const std::vector< unsigned char > &vchVersionIn, const void *pdata, size_t nSize)
bool IsValid() const
Check whether this private key is valid.
std::string EncodeBase58Check(const std::vector< unsigned char > &vchIn)
const std::vector< unsigned char > & Base58Prefix(Base58Type type) const