]> Git Repo - VerusCoin.git/blobdiff - src/base58.cpp
test
[VerusCoin.git] / src / base58.cpp
index 980d3cbf429807a83e0a70a2a0a9ad195c03e6c6..d095446822fbe6650a60289a57e949464d82919b 100644 (file)
@@ -7,6 +7,9 @@
 #include "hash.h"
 #include "uint256.h"
 
+#include "version.h"
+#include "streams.h"
+
 #include <assert.h>
 #include <stdint.h>
 #include <string.h>
@@ -172,13 +175,13 @@ bool CBase58Data::SetString(const char* psz, unsigned int nVersionBytes)
     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
@@ -248,6 +251,16 @@ bool CBitcoinAddress::IsValid(const CChainParams& params) 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())
@@ -302,10 +315,75 @@ bool CBitcoinSecret::IsValid() const
 
 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;
+}
+
This page took 0.022881 seconds and 4 git commands to generate.