From d6ad8cef2ca578a176c93d4a9c88bd19cb6cd191 Mon Sep 17 00:00:00 2001 From: Eirik Ogilvie-Wigley Date: Mon, 8 Oct 2018 14:52:58 -0600 Subject: [PATCH] GenerateNewSproutZKey can return a SproutPaymentAddress --- src/test/rpc_wallet_tests.cpp | 6 ++---- src/wallet/gtest/test_wallet_zkeys.cpp | 12 +++--------- src/wallet/wallet.cpp | 4 ++-- src/wallet/wallet.h | 6 +++--- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/test/rpc_wallet_tests.cpp b/src/test/rpc_wallet_tests.cpp index 38da9814f..31540d7d0 100644 --- a/src/test/rpc_wallet_tests.cpp +++ b/src/test/rpc_wallet_tests.cpp @@ -404,10 +404,8 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_exportwallet) BOOST_CHECK(addrs.size()==0); // wallet should have one key - auto address = pwalletMain->GenerateNewSproutZKey(); - BOOST_CHECK(IsValidPaymentAddress(address)); - BOOST_ASSERT(boost::get(&address) != nullptr); - auto addr = boost::get(address); + auto addr = pwalletMain->GenerateNewSproutZKey(); + BOOST_CHECK(IsValidPaymentAddress(addr)); pwalletMain->GetSproutPaymentAddresses(addrs); BOOST_CHECK(addrs.size()==1); diff --git a/src/wallet/gtest/test_wallet_zkeys.cpp b/src/wallet/gtest/test_wallet_zkeys.cpp index fb819ec49..5f022c5d5 100644 --- a/src/wallet/gtest/test_wallet_zkeys.cpp +++ b/src/wallet/gtest/test_wallet_zkeys.cpp @@ -121,9 +121,7 @@ TEST(wallet_zkeys_tests, store_and_load_zkeys) { ASSERT_EQ(0, addrs.size()); // wallet should have one key - auto address = wallet.GenerateNewSproutZKey(); - ASSERT_NE(boost::get(&address), nullptr); - auto addr = boost::get(address); + auto addr = wallet.GenerateNewSproutZKey(); wallet.GetSproutPaymentAddresses(addrs); ASSERT_EQ(1, addrs.size()); @@ -353,9 +351,7 @@ TEST(wallet_zkeys_tests, write_cryptedzkey_direct_to_db) { ASSERT_EQ(0, addrs.size()); // Add random key to the wallet - auto address = wallet.GenerateNewSproutZKey(); - ASSERT_NE(boost::get(&address), nullptr); - auto paymentAddress = boost::get(address); + auto paymentAddress = wallet.GenerateNewSproutZKey(); // wallet should have one key wallet.GetSproutPaymentAddresses(addrs); @@ -372,9 +368,7 @@ TEST(wallet_zkeys_tests, write_cryptedzkey_direct_to_db) { // unlock wallet and then add wallet.Unlock(strWalletPass); - auto address2 = wallet.GenerateNewSproutZKey(); - ASSERT_NE(boost::get(&address2), nullptr); - auto paymentAddress2 = boost::get(address2); + auto paymentAddress2 = wallet.GenerateNewSproutZKey(); // Create a new wallet from the existing wallet path CWallet wallet2("wallet_crypted.dat"); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 05a6cb086..e8cfdc44c 100644 --- a/src/wallet/wallet.cpp +++ b/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 -libzcash::PaymentAddress CWallet::GenerateNewSproutZKey() +libzcash::SproutPaymentAddress CWallet::GenerateNewSproutZKey() { AssertLockHeld(cs_wallet); // mapSproutZKeyMetadata - // TODO: Add Sapling support + auto k = SproutSpendingKey::random(); auto addr = k.address(); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 0ff61771e..31f2b0aee 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1042,10 +1042,10 @@ public: void GetKeyBirthTimes(std::map &mapKeyBirth) const; /** - * ZKeys + * Sprout ZKeys */ - //! Generates a new zaddr - libzcash::PaymentAddress GenerateNewSproutZKey(); + //! Generates a new Sprout zaddr + libzcash::SproutPaymentAddress GenerateNewSproutZKey(); //! Adds spending key to the store, and saves it to disk bool AddSproutZKey(const libzcash::SproutSpendingKey &key); //! Adds spending key to the store, without saving it to disk (used by LoadWallet)