GenerateNewSproutZKey can return a SproutPaymentAddress

This commit is contained in:
Eirik Ogilvie-Wigley
2018-10-08 14:52:58 -06:00
parent 92fc29a3f4
commit d6ad8cef2c
4 changed files with 10 additions and 18 deletions

View File

@@ -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);

View File

@@ -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");

View File

@@ -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();

View File

@@ -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)