Use boost::variant to represent shielded addresses and keys
libzcash::PaymentAddress has been renamed to libzcash::SproutPaymentAddress, and a new typedef boost::variant is now libzcash::PaymentAddress. Similarly for ViewingKey and SpendingKey. A new class InvalidEncoding is introduced as the default boost::variant option for each address and key type; it is used during decoding instead of boost::optional. All address and key storage functions in the wallet have been modified to refer specifically to the Sprout types, as they are used very precisely. In most other cases, the more general type is leveraged as much as possible, and we convert to the Sprout type when necessary. This will be subsequently wrapped in, or replaced with, context-specific functions once Sapling types are implemented.
This commit is contained in:
@@ -49,26 +49,26 @@ public:
|
||||
virtual bool HaveWatchOnly() const =0;
|
||||
|
||||
//! Add a spending key to the store.
|
||||
virtual bool AddSpendingKey(const libzcash::SpendingKey &sk) =0;
|
||||
virtual bool AddSpendingKey(const libzcash::SproutSpendingKey &sk) =0;
|
||||
|
||||
//! Check whether a spending key corresponding to a given payment address is present in the store.
|
||||
virtual bool HaveSpendingKey(const libzcash::PaymentAddress &address) const =0;
|
||||
virtual bool GetSpendingKey(const libzcash::PaymentAddress &address, libzcash::SpendingKey& skOut) const =0;
|
||||
virtual void GetPaymentAddresses(std::set<libzcash::PaymentAddress> &setAddress) const =0;
|
||||
virtual bool HaveSpendingKey(const libzcash::SproutPaymentAddress &address) const =0;
|
||||
virtual bool GetSpendingKey(const libzcash::SproutPaymentAddress &address, libzcash::SproutSpendingKey& skOut) const =0;
|
||||
virtual void GetPaymentAddresses(std::set<libzcash::SproutPaymentAddress> &setAddress) const =0;
|
||||
|
||||
//! Support for viewing keys
|
||||
virtual bool AddViewingKey(const libzcash::ViewingKey &vk) =0;
|
||||
virtual bool RemoveViewingKey(const libzcash::ViewingKey &vk) =0;
|
||||
virtual bool HaveViewingKey(const libzcash::PaymentAddress &address) const =0;
|
||||
virtual bool GetViewingKey(const libzcash::PaymentAddress &address, libzcash::ViewingKey& vkOut) const =0;
|
||||
virtual bool AddViewingKey(const libzcash::SproutViewingKey &vk) =0;
|
||||
virtual bool RemoveViewingKey(const libzcash::SproutViewingKey &vk) =0;
|
||||
virtual bool HaveViewingKey(const libzcash::SproutPaymentAddress &address) const =0;
|
||||
virtual bool GetViewingKey(const libzcash::SproutPaymentAddress &address, libzcash::SproutViewingKey& vkOut) const =0;
|
||||
};
|
||||
|
||||
typedef std::map<CKeyID, CKey> KeyMap;
|
||||
typedef std::map<CScriptID, CScript > ScriptMap;
|
||||
typedef std::set<CScript> WatchOnlySet;
|
||||
typedef std::map<libzcash::PaymentAddress, libzcash::SpendingKey> SpendingKeyMap;
|
||||
typedef std::map<libzcash::PaymentAddress, libzcash::ViewingKey> ViewingKeyMap;
|
||||
typedef std::map<libzcash::PaymentAddress, ZCNoteDecryption> NoteDecryptorMap;
|
||||
typedef std::map<libzcash::SproutPaymentAddress, libzcash::SproutSpendingKey> SpendingKeyMap;
|
||||
typedef std::map<libzcash::SproutPaymentAddress, libzcash::SproutViewingKey> ViewingKeyMap;
|
||||
typedef std::map<libzcash::SproutPaymentAddress, ZCNoteDecryption> NoteDecryptorMap;
|
||||
|
||||
/** Basic key store, that keeps keys in an address->secret map */
|
||||
class CBasicKeyStore : public CKeyStore
|
||||
@@ -127,8 +127,8 @@ public:
|
||||
virtual bool HaveWatchOnly(const CScript &dest) const;
|
||||
virtual bool HaveWatchOnly() const;
|
||||
|
||||
bool AddSpendingKey(const libzcash::SpendingKey &sk);
|
||||
bool HaveSpendingKey(const libzcash::PaymentAddress &address) const
|
||||
bool AddSpendingKey(const libzcash::SproutSpendingKey &sk);
|
||||
bool HaveSpendingKey(const libzcash::SproutPaymentAddress &address) const
|
||||
{
|
||||
bool result;
|
||||
{
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
}
|
||||
return result;
|
||||
}
|
||||
bool GetSpendingKey(const libzcash::PaymentAddress &address, libzcash::SpendingKey &skOut) const
|
||||
bool GetSpendingKey(const libzcash::SproutPaymentAddress &address, libzcash::SproutSpendingKey &skOut) const
|
||||
{
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
@@ -150,7 +150,7 @@ public:
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool GetNoteDecryptor(const libzcash::PaymentAddress &address, ZCNoteDecryption &decOut) const
|
||||
bool GetNoteDecryptor(const libzcash::SproutPaymentAddress &address, ZCNoteDecryption &decOut) const
|
||||
{
|
||||
{
|
||||
LOCK(cs_SpendingKeyStore);
|
||||
@@ -163,7 +163,7 @@ public:
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void GetPaymentAddresses(std::set<libzcash::PaymentAddress> &setAddress) const
|
||||
void GetPaymentAddresses(std::set<libzcash::SproutPaymentAddress> &setAddress) const
|
||||
{
|
||||
setAddress.clear();
|
||||
{
|
||||
@@ -183,14 +183,14 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool AddViewingKey(const libzcash::ViewingKey &vk);
|
||||
virtual bool RemoveViewingKey(const libzcash::ViewingKey &vk);
|
||||
virtual bool HaveViewingKey(const libzcash::PaymentAddress &address) const;
|
||||
virtual bool GetViewingKey(const libzcash::PaymentAddress &address, libzcash::ViewingKey& vkOut) const;
|
||||
virtual bool AddViewingKey(const libzcash::SproutViewingKey &vk);
|
||||
virtual bool RemoveViewingKey(const libzcash::SproutViewingKey &vk);
|
||||
virtual bool HaveViewingKey(const libzcash::SproutPaymentAddress &address) const;
|
||||
virtual bool GetViewingKey(const libzcash::SproutPaymentAddress &address, libzcash::SproutViewingKey& vkOut) const;
|
||||
};
|
||||
|
||||
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CKeyingMaterial;
|
||||
typedef std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char> > > CryptedKeyMap;
|
||||
typedef std::map<libzcash::PaymentAddress, std::vector<unsigned char> > CryptedSpendingKeyMap;
|
||||
typedef std::map<libzcash::SproutPaymentAddress, std::vector<unsigned char> > CryptedSpendingKeyMap;
|
||||
|
||||
#endif // BITCOIN_KEYSTORE_H
|
||||
|
||||
Reference in New Issue
Block a user