Browse Source

GenerateNewSproutZKey can return a SproutPaymentAddress

pull/4/head
Eirik Ogilvie-Wigley 6 years ago
parent
commit
d6ad8cef2c
  1. 6
      src/test/rpc_wallet_tests.cpp
  2. 12
      src/wallet/gtest/test_wallet_zkeys.cpp
  3. 4
      src/wallet/wallet.cpp
  4. 6
      src/wallet/wallet.h

6
src/test/rpc_wallet_tests.cpp

@ -404,10 +404,8 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_exportwallet)
BOOST_CHECK(addrs.size()==0); BOOST_CHECK(addrs.size()==0);
// wallet should have one key // wallet should have one key
auto address = pwalletMain->GenerateNewSproutZKey(); auto addr = pwalletMain->GenerateNewSproutZKey();
BOOST_CHECK(IsValidPaymentAddress(address)); BOOST_CHECK(IsValidPaymentAddress(addr));
BOOST_ASSERT(boost::get<libzcash::SproutPaymentAddress>(&address) != nullptr);
auto addr = boost::get<libzcash::SproutPaymentAddress>(address);
pwalletMain->GetSproutPaymentAddresses(addrs); pwalletMain->GetSproutPaymentAddresses(addrs);
BOOST_CHECK(addrs.size()==1); BOOST_CHECK(addrs.size()==1);

12
src/wallet/gtest/test_wallet_zkeys.cpp

@ -121,9 +121,7 @@ TEST(wallet_zkeys_tests, store_and_load_zkeys) {
ASSERT_EQ(0, addrs.size()); ASSERT_EQ(0, addrs.size());
// wallet should have one key // wallet should have one key
auto address = wallet.GenerateNewSproutZKey(); auto addr = wallet.GenerateNewSproutZKey();
ASSERT_NE(boost::get<libzcash::SproutPaymentAddress>(&address), nullptr);
auto addr = boost::get<libzcash::SproutPaymentAddress>(address);
wallet.GetSproutPaymentAddresses(addrs); wallet.GetSproutPaymentAddresses(addrs);
ASSERT_EQ(1, addrs.size()); ASSERT_EQ(1, addrs.size());
@ -353,9 +351,7 @@ TEST(wallet_zkeys_tests, write_cryptedzkey_direct_to_db) {
ASSERT_EQ(0, addrs.size()); ASSERT_EQ(0, addrs.size());
// Add random key to the wallet // Add random key to the wallet
auto address = wallet.GenerateNewSproutZKey(); auto paymentAddress = wallet.GenerateNewSproutZKey();
ASSERT_NE(boost::get<libzcash::SproutPaymentAddress>(&address), nullptr);
auto paymentAddress = boost::get<libzcash::SproutPaymentAddress>(address);
// wallet should have one key // wallet should have one key
wallet.GetSproutPaymentAddresses(addrs); wallet.GetSproutPaymentAddresses(addrs);
@ -372,9 +368,7 @@ TEST(wallet_zkeys_tests, write_cryptedzkey_direct_to_db) {
// unlock wallet and then add // unlock wallet and then add
wallet.Unlock(strWalletPass); wallet.Unlock(strWalletPass);
auto address2 = wallet.GenerateNewSproutZKey(); auto paymentAddress2 = wallet.GenerateNewSproutZKey();
ASSERT_NE(boost::get<libzcash::SproutPaymentAddress>(&address2), nullptr);
auto paymentAddress2 = boost::get<libzcash::SproutPaymentAddress>(address2);
// Create a new wallet from the existing wallet path // Create a new wallet from the existing wallet path
CWallet wallet2("wallet_crypted.dat"); CWallet wallet2("wallet_crypted.dat");

4
src/wallet/wallet.cpp

@ -82,10 +82,10 @@ const CWalletTx* CWallet::GetWalletTx(const uint256& hash) const
} }
// Generate a new spending key and return its public payment address // Generate a new spending key and return its public payment address
libzcash::PaymentAddress CWallet::GenerateNewSproutZKey() libzcash::SproutPaymentAddress CWallet::GenerateNewSproutZKey()
{ {
AssertLockHeld(cs_wallet); // mapSproutZKeyMetadata AssertLockHeld(cs_wallet); // mapSproutZKeyMetadata
// TODO: Add Sapling support
auto k = SproutSpendingKey::random(); auto k = SproutSpendingKey::random();
auto addr = k.address(); auto addr = k.address();

6
src/wallet/wallet.h

@ -1042,10 +1042,10 @@ public:
void GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const; void GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const;
/** /**
* ZKeys * Sprout ZKeys
*/ */
//! Generates a new zaddr //! Generates a new Sprout zaddr
libzcash::PaymentAddress GenerateNewSproutZKey(); libzcash::SproutPaymentAddress GenerateNewSproutZKey();
//! Adds spending key to the store, and saves it to disk //! Adds spending key to the store, and saves it to disk
bool AddSproutZKey(const libzcash::SproutSpendingKey &key); bool AddSproutZKey(const libzcash::SproutSpendingKey &key);
//! Adds spending key to the store, without saving it to disk (used by LoadWallet) //! Adds spending key to the store, without saving it to disk (used by LoadWallet)

Loading…
Cancel
Save