Move serialized Zcash address length constants into zcash/Address.hpp

This commit is contained in:
Jack Grigg 2016-08-16 22:55:06 +12:00
parent 6ae516f10b
commit 3a15b1637e
3 changed files with 10 additions and 11 deletions

View File

@ -313,21 +313,19 @@ bool CBitcoinSecret::SetString(const std::string& strSecret)
return SetString(strSecret.c_str()); return SetString(strSecret.c_str());
} }
const size_t serializedPaymentAddressSize = 64;
bool CZCPaymentAddress::Set(const libzcash::PaymentAddress& addr) bool CZCPaymentAddress::Set(const libzcash::PaymentAddress& addr)
{ {
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << addr; ss << addr;
std::vector<unsigned char> addrSerialized(ss.begin(), ss.end()); std::vector<unsigned char> addrSerialized(ss.begin(), ss.end());
assert(addrSerialized.size() == serializedPaymentAddressSize); assert(addrSerialized.size() == libzcash::SerializedPaymentAddressSize);
SetData(Params().Base58Prefix(CChainParams::ZCPAYMENT_ADDRRESS), &addrSerialized[0], serializedPaymentAddressSize); SetData(Params().Base58Prefix(CChainParams::ZCPAYMENT_ADDRRESS), &addrSerialized[0], libzcash::SerializedPaymentAddressSize);
return true; return true;
} }
libzcash::PaymentAddress CZCPaymentAddress::Get() const libzcash::PaymentAddress CZCPaymentAddress::Get() const
{ {
if (vchData.size() != serializedPaymentAddressSize) { if (vchData.size() != libzcash::SerializedPaymentAddressSize) {
throw std::runtime_error( throw std::runtime_error(
"payment address is invalid" "payment address is invalid"
); );
@ -347,21 +345,19 @@ libzcash::PaymentAddress CZCPaymentAddress::Get() const
return ret; return ret;
} }
const size_t serializedSpendingKeySize = 32;
bool CZCSpendingKey::Set(const libzcash::SpendingKey& addr) bool CZCSpendingKey::Set(const libzcash::SpendingKey& addr)
{ {
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << addr; ss << addr;
std::vector<unsigned char> addrSerialized(ss.begin(), ss.end()); std::vector<unsigned char> addrSerialized(ss.begin(), ss.end());
assert(addrSerialized.size() == serializedSpendingKeySize); assert(addrSerialized.size() == libzcash::SerializedSpendingKeySize);
SetData(Params().Base58Prefix(CChainParams::ZCSPENDING_KEY), &addrSerialized[0], serializedSpendingKeySize); SetData(Params().Base58Prefix(CChainParams::ZCSPENDING_KEY), &addrSerialized[0], libzcash::SerializedSpendingKeySize);
return true; return true;
} }
libzcash::SpendingKey CZCSpendingKey::Get() const libzcash::SpendingKey CZCSpendingKey::Get() const
{ {
if (vchData.size() != serializedSpendingKeySize) { if (vchData.size() != libzcash::SerializedSpendingKeySize) {
throw std::runtime_error( throw std::runtime_error(
"spending key is invalid" "spending key is invalid"
); );

View File

@ -145,7 +145,7 @@ static bool DecryptSpendingKey(const CKeyingMaterial& vMasterKey,
if(!DecryptSecret(vMasterKey, vchCryptedSecret, address.GetHash(), vchSecret)) if(!DecryptSecret(vMasterKey, vchCryptedSecret, address.GetHash(), vchSecret))
return false; return false;
if (vchSecret.size() != 32) if (vchSecret.size() != libzcash::SerializedSpendingKeySize)
return false; return false;
// TODO does this undo the benefits of using CKeyingMaterial? // TODO does this undo the benefits of using CKeyingMaterial?

View File

@ -7,6 +7,9 @@
namespace libzcash { namespace libzcash {
const size_t SerializedPaymentAddressSize = 64;
const size_t SerializedSpendingKeySize = 32;
class PaymentAddress { class PaymentAddress {
public: public:
uint256 a_pk; uint256 a_pk;