Browse Source

Implement CKeyStore::GetSaplingPaymentAddresses()

pull/4/head
Jack Grigg 6 years ago
parent
commit
4715b31c76
No known key found for this signature in database GPG Key ID: 1B8D649257DB0829
  1. 14
      src/keystore.h
  2. 18
      src/wallet/gtest/test_wallet_zkeys.cpp

14
src/keystore.h

@ -75,6 +75,7 @@ public:
virtual bool GetSaplingIncomingViewingKey(
const libzcash::SaplingPaymentAddress &addr,
libzcash::SaplingIncomingViewingKey& ivkOut) const =0;
virtual void GetSaplingPaymentAddresses(std::set<libzcash::SaplingPaymentAddress> &setAddress) const =0;
//! Support for viewing keys
virtual bool AddViewingKey(const libzcash::SproutViewingKey &vk) =0;
@ -251,6 +252,19 @@ public:
virtual bool GetSaplingIncomingViewingKey(
const libzcash::SaplingPaymentAddress &addr,
libzcash::SaplingIncomingViewingKey& ivkOut) const;
void GetSaplingPaymentAddresses(std::set<libzcash::SaplingPaymentAddress> &setAddress) const
{
setAddress.clear();
{
LOCK(cs_SpendingKeyStore);
auto mi = mapSaplingIncomingViewingKeys.begin();
while (mi != mapSaplingIncomingViewingKeys.end())
{
setAddress.insert((*mi).first);
mi++;
}
}
}
virtual bool AddViewingKey(const libzcash::SproutViewingKey &vk);
virtual bool RemoveViewingKey(const libzcash::SproutViewingKey &vk);

18
src/wallet/gtest/test_wallet_zkeys.cpp

@ -16,7 +16,15 @@ TEST(wallet_zkeys_tests, store_and_load_sapling_zkeys) {
CWallet wallet;
// wallet should be empty
std::set<libzcash::SaplingPaymentAddress> addrs;
wallet.GetSaplingPaymentAddresses(addrs);
ASSERT_EQ(0, addrs.size());
// wallet should have one key
auto address = wallet.GenerateNewSaplingZKey();
wallet.GetSaplingPaymentAddresses(addrs);
ASSERT_EQ(1, addrs.size());
// verify wallet has incoming viewing key for the address
ASSERT_TRUE(wallet.HaveSaplingIncomingViewingKey(address));
@ -28,6 +36,16 @@ TEST(wallet_zkeys_tests, store_and_load_sapling_zkeys) {
// verify wallet did add it
auto fvk = sk.full_viewing_key();
ASSERT_TRUE(wallet.HaveSaplingSpendingKey(fvk));
// verify spending key stored correctly
libzcash::SaplingSpendingKey keyOut;
wallet.GetSaplingSpendingKey(fvk, keyOut);
ASSERT_EQ(sk, keyOut);
// verify there are two keys
wallet.GetSaplingPaymentAddresses(addrs);
ASSERT_EQ(2, addrs.size());
ASSERT_EQ(1, addrs.count(address));
}
/**

Loading…
Cancel
Save