Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

base58.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
14 #ifndef BITCOIN_BASE58_H
15 #define BITCOIN_BASE58_H
16 
17 #include <chainparams.h>
18 #include <key.h>
19 #include <pubkey.h>
20 #include <script/script.h>
21 #include <script/standard.h>
23 
24 #include <string>
25 #include <vector>
26 
31 std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend);
32 
36 std::string EncodeBase58(const std::vector<unsigned char>& vch);
37 
43 bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet);
44 
49 bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet);
50 
54 std::string EncodeBase58Check(const std::vector<unsigned char>& vchIn);
55 
60 inline bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRet);
61 
66 inline bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet);
67 
72 {
73 protected:
75  std::vector<unsigned char> vchVersion;
76 
78  typedef std::vector<unsigned char, zero_after_free_allocator<unsigned char> > vector_uchar;
80 
81  CBase58Data();
82  void SetData(const std::vector<unsigned char> &vchVersionIn, const void* pdata, size_t nSize);
83  void SetData(const std::vector<unsigned char> &vchVersionIn, const unsigned char *pbegin, const unsigned char *pend);
84 
85 public:
86  bool SetString(const char* psz, unsigned int nVersionBytes = 1);
87  bool SetString(const std::string& str);
88  std::string ToString() const;
89  int CompareTo(const CBase58Data& b58) const;
90 
91  bool operator==(const CBase58Data& b58) const { return CompareTo(b58) == 0; }
92  bool operator<=(const CBase58Data& b58) const { return CompareTo(b58) <= 0; }
93  bool operator>=(const CBase58Data& b58) const { return CompareTo(b58) >= 0; }
94  bool operator< (const CBase58Data& b58) const { return CompareTo(b58) < 0; }
95  bool operator> (const CBase58Data& b58) const { return CompareTo(b58) > 0; }
96 };
97 
102 {
103 public:
104  void SetKey(const CKey& vchSecret);
105  CKey GetKey();
106  bool IsValid() const;
107  bool SetString(const char* pszSecret);
108  bool SetString(const std::string& strSecret);
109 
110  CBitcoinSecret(const CKey& vchSecret) { SetKey(vchSecret); }
112 };
113 
114 template<typename K, int Size, CChainParams::Base58Type Type> class CBitcoinExtKeyBase : public CBase58Data
115 {
116 public:
117  void SetKey(const K &key) {
118  unsigned char vch[Size];
119  key.Encode(vch);
120  SetData(Params().Base58Prefix(Type), vch, vch+Size);
121  }
122 
123  K GetKey() {
124  K ret;
125  if (vchData.size() == Size) {
126  // If base58 encoded data does not hold an ext key, return a !IsValid() key
127  ret.Decode(vchData.data());
128  }
129  return ret;
130  }
131 
132  CBitcoinExtKeyBase(const K &key) {
133  SetKey(key);
134  }
135 
136  CBitcoinExtKeyBase(const std::string& strBase58c) {
137  SetString(strBase58c.c_str(), Params().Base58Prefix(Type).size());
138  }
139 
141 };
142 
145 
146 std::string EncodeDestination(const CTxDestination& dest);
147 CTxDestination DecodeDestination(const std::string& str);
148 bool IsValidDestinationString(const std::string& str);
149 bool IsValidDestinationString(const std::string& str, const CChainParams& params);
150 
151 #endif // BITCOIN_BASE58_H
CBitcoinSecret()
Definition: base58.h:111
void SetKey(const CKey &vchSecret)
Definition: base58.cpp:296
bool IsValidDestinationString(const std::string &str)
Definition: base58.cpp:346
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:80
CBitcoinExtKeyBase< CExtPubKey, BIP32_EXTKEY_SIZE, CChainParams::EXT_PUBLIC_KEY > CBitcoinExtPubKey
Definition: base58.h:144
CKey GetKey()
Definition: base58.cpp:304
bool DecodeBase58(const char *psz, std::vector< unsigned char > &vchRet)
Decode a base58-encoded string (psz) into a byte vector (vchRet).
Definition: base58.cpp:21
vector_uchar vchData
Definition: base58.h:79
int CompareTo(const CBase58Data &b58) const
Definition: base58.cpp:200
CChainParams defines various tweakable parameters of a given instance of the Dash system...
Definition: chainparams.h:41
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.
Definition: base58.cpp:130
void SetData(const std::vector< unsigned char > &vchVersionIn, const void *pdata, size_t nSize)
Definition: base58.cpp:158
void SetKey(const K &key)
Definition: base58.h:117
bool SetString(const char *pszSecret)
Definition: base58.cpp:319
std::string ToString() const
Definition: base58.cpp:193
std::vector< unsigned char, zero_after_free_allocator< unsigned char > > vector_uchar
the actually encoded data
Definition: base58.h:78
Base class for all base58-encoded data.
Definition: base58.h:71
CBitcoinExtKeyBase< CExtKey, BIP32_EXTKEY_SIZE, CChainParams::EXT_SECRET_KEY > CBitcoinExtKey
Definition: base58.h:143
bool operator<=(const CBase58Data &b58) const
Definition: base58.h:92
bool operator==(const CBase58Data &b58) const
Definition: base58.h:91
A base58-encoded secret key.
Definition: base58.h:101
bool operator>=(const CBase58Data &b58) const
Definition: base58.h:93
bool SetString(const char *psz, unsigned int nVersionBytes=1)
Definition: base58.cpp:171
std::string EncodeBase58Check(const std::vector< unsigned char > &vchIn)
Encode a byte vector into a base58-encoded string, including checksum.
Definition: base58.cpp:121
std::string EncodeDestination(const CTxDestination &dest)
Definition: base58.cpp:329
bool IsValid() const
Definition: base58.cpp:312
CBitcoinSecret(const CKey &vchSecret)
Definition: base58.h:110
const CChainParams & Params()
Return the currently selected parameters.
CTxDestination DecodeDestination(const std::string &str)
Definition: base58.cpp:336
CBitcoinExtKeyBase(const std::string &strBase58c)
Definition: base58.h:136
std::string EncodeBase58(const unsigned char *pbegin, const unsigned char *pend)
Why base-58 instead of standard base-64 encoding?
Definition: base58.cpp:71
CBitcoinExtKeyBase(const K &key)
Definition: base58.h:132
bool operator>(const CBase58Data &b58) const
Definition: base58.h:95
An encapsulated private key.
Definition: key.h:27
bool operator<(const CBase58Data &b58) const
Definition: base58.h:94
std::vector< unsigned char > vchVersion
the version byte(s)
Definition: base58.h:75
const std::vector< unsigned char > & Base58Prefix(Base58Type type) const
Definition: chainparams.h:79
Released under the MIT license