|
6 | 6 | #include "base58.h" |
7 | 7 |
|
8 | 8 | #include "hash.h" |
9 | | -#include "script/script.h" |
10 | | -#include "uint256.h" |
11 | 9 |
|
12 | | -#include <boost/variant/apply_visitor.hpp> |
13 | | -#include <boost/variant/static_visitor.hpp> |
| 10 | +#include "uint256.h" |
14 | 11 |
|
15 | 12 | #include <algorithm> |
16 | 13 | #include <assert.h> |
@@ -167,96 +164,3 @@ bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRe |
167 | 164 | { |
168 | 165 | return DecodeBase58Check(str.c_str(), vchRet, max_ret); |
169 | 166 | } |
170 | | - |
171 | | -namespace |
172 | | -{ |
173 | | -class DestinationEncoder : public boost::static_visitor<std::string> |
174 | | -{ |
175 | | -private: |
176 | | - const CChainParams& m_params; |
177 | | - const CChainParams::Base58Type m_addrType; |
178 | | - |
179 | | -public: |
180 | | - DestinationEncoder(const CChainParams& params, const CChainParams::Base58Type _addrType = CChainParams::PUBKEY_ADDRESS) : m_params(params), m_addrType(_addrType) {} |
181 | | - |
182 | | - std::string operator()(const CKeyID& id) const |
183 | | - { |
184 | | - std::vector<unsigned char> data = m_params.Base58Prefix(m_addrType); |
185 | | - data.insert(data.end(), id.begin(), id.end()); |
186 | | - return EncodeBase58Check(data); |
187 | | - } |
188 | | - |
189 | | - std::string operator()(const CScriptID& id) const |
190 | | - { |
191 | | - std::vector<unsigned char> data = m_params.Base58Prefix(CChainParams::SCRIPT_ADDRESS); |
192 | | - data.insert(data.end(), id.begin(), id.end()); |
193 | | - return EncodeBase58Check(data); |
194 | | - } |
195 | | - |
196 | | - std::string operator()(const CNoDestination& no) const { return ""; } |
197 | | -}; |
198 | | - |
199 | | -CTxDestination DecodeDestination(const std::string& str, const CChainParams& params, bool& isStaking) |
200 | | -{ |
201 | | - std::vector<unsigned char> data; |
202 | | - uint160 hash; |
203 | | - if (DecodeBase58Check(str, data)) { |
204 | | - // base58-encoded PIVX addresses. |
205 | | - // Public-key-hash-addresses have version 30 (or 139 testnet). |
206 | | - // The data vector contains RIPEMD160(SHA256(pubkey)), where pubkey is the serialized public key. |
207 | | - const std::vector<unsigned char>& pubkey_prefix = params.Base58Prefix(CChainParams::PUBKEY_ADDRESS); |
208 | | - if (data.size() == hash.size() + pubkey_prefix.size() && std::equal(pubkey_prefix.begin(), pubkey_prefix.end(), data.begin())) { |
209 | | - std::copy(data.begin() + pubkey_prefix.size(), data.end(), hash.begin()); |
210 | | - return CKeyID(hash); |
211 | | - } |
212 | | - // Public-key-hash-coldstaking-addresses have version 63 (or 73 testnet). |
213 | | - const std::vector<unsigned char>& staking_prefix = params.Base58Prefix(CChainParams::STAKING_ADDRESS); |
214 | | - if (data.size() == hash.size() + staking_prefix.size() && std::equal(staking_prefix.begin(), staking_prefix.end(), data.begin())) { |
215 | | - isStaking = true; |
216 | | - std::copy(data.begin() + staking_prefix.size(), data.end(), hash.begin()); |
217 | | - return CKeyID(hash); |
218 | | - } |
219 | | - // Script-hash-addresses have version 13 (or 19 testnet). |
220 | | - // The data vector contains RIPEMD160(SHA256(cscript)), where cscript is the serialized redemption script. |
221 | | - const std::vector<unsigned char>& script_prefix = params.Base58Prefix(CChainParams::SCRIPT_ADDRESS); |
222 | | - if (data.size() == hash.size() + script_prefix.size() && std::equal(script_prefix.begin(), script_prefix.end(), data.begin())) { |
223 | | - std::copy(data.begin() + script_prefix.size(), data.end(), hash.begin()); |
224 | | - return CScriptID(hash); |
225 | | - } |
226 | | - } |
227 | | - return CNoDestination(); |
228 | | -} |
229 | | - |
230 | | -} // anon namespace |
231 | | - |
232 | | -std::string EncodeDestination(const CTxDestination& dest, bool isStaking) |
233 | | -{ |
234 | | - return EncodeDestination(dest, isStaking ? CChainParams::STAKING_ADDRESS : CChainParams::PUBKEY_ADDRESS); |
235 | | -} |
236 | | - |
237 | | -std::string EncodeDestination(const CTxDestination& dest, const CChainParams::Base58Type addrType) |
238 | | -{ |
239 | | - return boost::apply_visitor(DestinationEncoder(Params(), addrType), dest); |
240 | | -} |
241 | | - |
242 | | -CTxDestination DecodeDestination(const std::string& str) |
243 | | -{ |
244 | | - bool isStaking; |
245 | | - return DecodeDestination(str, Params(), isStaking); |
246 | | -} |
247 | | - |
248 | | -CTxDestination DecodeDestination(const std::string& str, bool& isStaking) |
249 | | -{ |
250 | | - return DecodeDestination(str, Params(), isStaking); |
251 | | -} |
252 | | - |
253 | | -bool IsValidDestinationString(const std::string& str, bool fStaking, const CChainParams& params) |
254 | | -{ |
255 | | - bool isStaking = false; |
256 | | - return IsValidDestination(DecodeDestination(str, params, isStaking)) && (isStaking == fStaking); |
257 | | -} |
258 | | - |
259 | | -bool IsValidDestinationString(const std::string& str, bool isStaking) |
260 | | -{ |
261 | | - return IsValidDestinationString(str, isStaking, Params()); |
262 | | -} |
0 commit comments