Browse Source

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

pull/4/head
Jack Grigg 8 years ago
parent
commit
3a15b1637e
  1. 16
      src/base58.cpp
  2. 2
      src/wallet/crypter.cpp
  3. 3
      src/zcash/Address.hpp

16
src/base58.cpp

@ -313,21 +313,19 @@ bool CBitcoinSecret::SetString(const std::string& strSecret)
return SetString(strSecret.c_str());
}
const size_t serializedPaymentAddressSize = 64;
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() == serializedPaymentAddressSize);
SetData(Params().Base58Prefix(CChainParams::ZCPAYMENT_ADDRRESS), &addrSerialized[0], serializedPaymentAddressSize);
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() != serializedPaymentAddressSize) {
if (vchData.size() != libzcash::SerializedPaymentAddressSize) {
throw std::runtime_error(
"payment address is invalid"
);
@ -347,21 +345,19 @@ libzcash::PaymentAddress CZCPaymentAddress::Get() const
return ret;
}
const size_t serializedSpendingKeySize = 32;
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() == serializedSpendingKeySize);
SetData(Params().Base58Prefix(CChainParams::ZCSPENDING_KEY), &addrSerialized[0], serializedSpendingKeySize);
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() != serializedSpendingKeySize) {
if (vchData.size() != libzcash::SerializedSpendingKeySize) {
throw std::runtime_error(
"spending key is invalid"
);

2
src/wallet/crypter.cpp

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

3
src/zcash/Address.hpp

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

Loading…
Cancel
Save