// Copyright (c) 2014 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// file COPYING or https://www.opensource.org/licenses/mit-license.php .
#include "base58.h"
-#include "hash.h"
-#include "uint256.h"
-
-#include "version.h"
-#include "streams.h"
+#include <hash.h>
+#include <uint256.h>
#include <assert.h>
-#include <stdint.h>
#include <string.h>
+#include <stdint.h>
#include <vector>
#include <string>
#include <boost/variant/apply_visitor.hpp>
std::string EncodeBase58(const std::vector<unsigned char>& vch)
{
- return EncodeBase58(&vch[0], &vch[0] + vch.size());
+ return EncodeBase58(vch.data(), vch.data() + vch.size());
}
bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet)
return DecodeBase58Check(str.c_str(), vchRet);
}
+
CBase58Data::CBase58Data()
{
vchVersion.clear();
CBitcoinAddressVisitor(CBitcoinAddress* addrIn) : addr(addrIn) {}
bool operator()(const CKeyID& id) const { return addr->Set(id); }
+ bool operator()(const CPubKey& key) const { return addr->Set(key); }
bool operator()(const CScriptID& id) const { return addr->Set(id); }
bool operator()(const CNoDestination& no) const { return false; }
};
return true;
}
+bool CBitcoinAddress::Set(const CPubKey& key)
+{
+ CKeyID id = key.GetID();
+ SetData(Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS), &id, 20);
+ return true;
+}
+
bool CBitcoinAddress::Set(const CScriptID& id)
{
SetData(Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS), &id, 20);
return CNoDestination();
}
+bool CBitcoinAddress::GetIndexKey(uint160& hashBytes, int& type) const
+{
+ if (!IsValid()) {
+ return false;
+ } else if (vchVersion == Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS)) {
+ memcpy(&hashBytes, &vchData[0], 20);
+ type = 1;
+ return true;
+ } else if (vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS)) {
+ memcpy(&hashBytes, &vchData[0], 20);
+ type = 2;
+ return true;
+ }
+
+ return false;
+}
+
bool CBitcoinAddress::GetKeyID(CKeyID& keyID) const
{
if (!IsValid() || vchVersion != Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS))
return true;
}
+bool CBitcoinAddress::GetKeyID_NoCheck(CKeyID& keyID) const
+{
+ uint160 id;
+ memcpy(&id, &vchData[0], 20);
+ keyID = CKeyID(id);
+ return true;
+}
+
bool CBitcoinAddress::IsScript() const
{
return IsValid() && vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS);
ss >> ret;
return ret;
}
-
-// Explicit instantiations for libzcash::PaymentAddress
-template bool CZCEncoding<libzcash::PaymentAddress,
- CChainParams::ZCPAYMENT_ADDRRESS,
- libzcash::SerializedPaymentAddressSize>::Set(const libzcash::PaymentAddress& addr);
-template libzcash::PaymentAddress CZCEncoding<libzcash::PaymentAddress,
- CChainParams::ZCPAYMENT_ADDRRESS,
- libzcash::SerializedPaymentAddressSize>::Get() const;
-
-// Explicit instantiations for libzcash::ViewingKey
-template bool CZCEncoding<libzcash::ViewingKey,
- CChainParams::ZCVIEWING_KEY,
- libzcash::SerializedViewingKeySize>::Set(const libzcash::ViewingKey& vk);
-template libzcash::ViewingKey CZCEncoding<libzcash::ViewingKey,
- CChainParams::ZCVIEWING_KEY,
- libzcash::SerializedViewingKeySize>::Get() const;
-
-// Explicit instantiations for libzcash::SpendingKey
-template bool CZCEncoding<libzcash::SpendingKey,
- CChainParams::ZCSPENDING_KEY,
- libzcash::SerializedSpendingKeySize>::Set(const libzcash::SpendingKey& sk);
-template libzcash::SpendingKey CZCEncoding<libzcash::SpendingKey,
- CChainParams::ZCSPENDING_KEY,
- libzcash::SerializedSpendingKeySize>::Get() const;