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)) {
39 const char*
ch = strchr(pszBase58, *psz);
43 int carry = ch - pszBase58;
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())
107 str += pszBase58[*(it++)];
113 return EncodeBase58(vch.data(), vch.data() + vch.size());
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 CFabcoinAddressVisitor :
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(CFabcoinAddressVisitor(
this), dest);
254 bool fCorrectSize =
vchData.size() == 20;
257 return fCorrectSize && fKnownVersion;
314 return fExpectedFormat && fCorrectVersion;
bool DecodeBase58(const char *psz, std::vector< unsigned char > &vch)
Decode a base58-encoded string (psz) into a byte vector (vchRet).
bool SetString(const char *pszSecret)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
const unsigned char * begin() const
bool IsPubKeyHash() const
base58-encoded Fabcoin addresses.
std::string EncodeBase58(const unsigned char *pbegin, const unsigned char *pend)
Why base-58 instead of standard base-64 encoding?
assert(len-trim+(2 *lenIndices)<=WIDTH)
CChainParams defines various tweakable parameters of a given instance of the Fabcoin system...
void SetData(const std::vector< unsigned char > &vchVersionIn, const void *pdata, size_t nSize)
const std::vector< unsigned char > & Base58Prefix(Base58Type type) const
bool IsValid() const
Check whether this private key is valid.
Base class for all base58-encoded data.
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
void memory_cleanse(void *ptr, size_t len)
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)
Compute the 256-bit hash of an object.
CTxDestination Get() const
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)
bool GetKeyID(CKeyID &keyID) const
uint8_t const size_t const size
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
Simple read-only vector-like interface.
uint32_t ch(uint32_t x, uint32_t y, uint32_t z)
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 Set(const CKeyID &id)
void SetKey(const CKey &vchSecret)
int CompareTo(const CBase58Data &b58) const