#include "hash.h"
#include "uint256.h"
+#include "version.h"
+#include "streams.h"
+
#include <assert.h>
#include <stdint.h>
#include <string.h>
vchData.resize(vchTemp.size() - nVersionBytes);
if (!vchData.empty())
memcpy(&vchData[0], &vchTemp[nVersionBytes], vchData.size());
- OPENSSL_cleanse(&vchTemp[0], vchData.size());
+ memory_cleanse(&vchTemp[0], vchData.size());
return true;
}
-bool CBase58Data::SetString(const std::string& str)
+bool CBase58Data::SetString(const std::string& str, unsigned int nVersionBytes)
{
- return SetString(str.c_str());
+ return SetString(str.c_str(), nVersionBytes);
}
std::string CBase58Data::ToString() const
return fCorrectSize && fKnownVersion;
}
+bool CBitcoinAddress::SetString(const char* pszAddress)
+{
+ return CBase58Data::SetString(pszAddress, 1);//2);
+}
+
+bool CBitcoinAddress::SetString(const std::string& strAddress)
+{
+ return SetString(strAddress.c_str());
+}
+
CTxDestination CBitcoinAddress::Get() const
{
if (!IsValid())
bool CBitcoinSecret::SetString(const char* pszSecret)
{
- return CBase58Data::SetString(pszSecret) && IsValid();
+ return CBase58Data::SetString(pszSecret, 1) && IsValid();
}
bool CBitcoinSecret::SetString(const std::string& strSecret)
{
return SetString(strSecret.c_str());
}
+
+bool CZCPaymentAddress::Set(const libzcash::PaymentAddress& addr)
+{
+ CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
+ ss << addr;
+ std::vector<unsigned char> addrSerialized(ss.begin(), ss.end());
+ assert(addrSerialized.size() == libzcash::SerializedPaymentAddressSize);
+ SetData(Params().Base58Prefix(CChainParams::ZCPAYMENT_ADDRRESS), &addrSerialized[0], libzcash::SerializedPaymentAddressSize);
+ return true;
+}
+
+libzcash::PaymentAddress CZCPaymentAddress::Get() const
+{
+ if (vchData.size() != libzcash::SerializedPaymentAddressSize) {
+ throw std::runtime_error(
+ "payment address is invalid"
+ );
+ }
+
+ if (vchVersion != Params().Base58Prefix(CChainParams::ZCPAYMENT_ADDRRESS)) {
+ throw std::runtime_error(
+ "payment address is for wrong network type"
+ );
+ }
+
+ std::vector<unsigned char> serialized(vchData.begin(), vchData.end());
+
+ CDataStream ss(serialized, SER_NETWORK, PROTOCOL_VERSION);
+ libzcash::PaymentAddress ret;
+ ss >> ret;
+ return ret;
+}
+
+bool CZCSpendingKey::Set(const libzcash::SpendingKey& addr)
+{
+ CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
+ ss << addr;
+ std::vector<unsigned char> addrSerialized(ss.begin(), ss.end());
+ assert(addrSerialized.size() == libzcash::SerializedSpendingKeySize);
+ SetData(Params().Base58Prefix(CChainParams::ZCSPENDING_KEY), &addrSerialized[0], libzcash::SerializedSpendingKeySize);
+ return true;
+}
+
+libzcash::SpendingKey CZCSpendingKey::Get() const
+{
+ if (vchData.size() != libzcash::SerializedSpendingKeySize) {
+ throw std::runtime_error(
+ "spending key is invalid"
+ );
+ }
+
+ if (vchVersion != Params().Base58Prefix(CChainParams::ZCSPENDING_KEY)) {
+ throw std::runtime_error(
+ "spending key is for wrong network type"
+ );
+ }
+
+ std::vector<unsigned char> serialized(vchData.begin(), vchData.end());
+
+ CDataStream ss(serialized, SER_NETWORK, PROTOCOL_VERSION);
+ libzcash::SpendingKey ret;
+ ss >> ret;
+ return ret;
+}
+