Return UFVK from `CWallet::GenerateNewUnifiedSpendingKey`

The only place we were using the returned Unified Spending Key was in a
test, where we immediately converted it to a UFVK.

Co-authored-by: Kris Nuttycombe <kris@nutty.land>
This commit is contained in:
Jack Grigg 2022-02-21 14:24:13 +00:00
parent 3c84ed604e
commit c2a47b8d97
4 changed files with 11 additions and 10 deletions

View File

@ -2200,14 +2200,15 @@ TEST(WalletTests, GenerateUnifiedAddress) {
EXPECT_EQ(uaResult, expected);
// Create an account, then generate an address for that account.
auto skpair = wallet.GenerateNewUnifiedSpendingKey();
uaResult = wallet.GenerateUnifiedAddress(skpair.second, {ReceiverType::P2PKH, ReceiverType::Sapling});
auto ufvkpair = wallet.GenerateNewUnifiedSpendingKey();
auto ufvk = ufvkpair.first;
auto account = ufvkpair.second;
uaResult = wallet.GenerateUnifiedAddress(account, {ReceiverType::P2PKH, ReceiverType::Sapling});
auto ua = std::get_if<std::pair<libzcash::UnifiedAddress, libzcash::diversifier_index_t>>(&uaResult);
EXPECT_NE(ua, nullptr);
auto uaSaplingReceiver = ua->first.GetSaplingReceiver();
EXPECT_TRUE(uaSaplingReceiver.has_value());
auto ufvk = skpair.first.ToFullViewingKey();
EXPECT_EQ(uaSaplingReceiver.value(), ufvk.GetSaplingKey().value().Address(ua->second));
auto u4r = wallet.FindUnifiedAddressByReceiver(uaSaplingReceiver.value());

View File

@ -3057,8 +3057,8 @@ UniValue z_getnewaccount(const UniValue& params, bool fHelp)
EnsureWalletIsUnlocked();
// Generate the new account.
auto skNew = pwalletMain->GenerateNewUnifiedSpendingKey();
const auto& account = skNew.second;
auto ufvkNew = pwalletMain->GenerateNewUnifiedSpendingKey();
const auto& account = ufvkNew.second;
UniValue result(UniValue::VOBJ);
result.pushKV("account", (uint64_t)account);

View File

@ -477,7 +477,7 @@ libzcash::transparent::AccountKey CWallet::GetLegacyAccountKey() const {
}
std::pair<ZcashdUnifiedSpendingKey, libzcash::AccountId> CWallet::GenerateNewUnifiedSpendingKey() {
std::pair<UnifiedFullViewingKey, libzcash::AccountId> CWallet::GenerateNewUnifiedSpendingKey() {
AssertLockHeld(cs_wallet);
if (!mnemonicHDChain.has_value()) {
@ -488,17 +488,17 @@ std::pair<ZcashdUnifiedSpendingKey, libzcash::AccountId> CWallet::GenerateNewUni
CHDChain& hdChain = mnemonicHDChain.value();
while (true) {
auto accountId = hdChain.GetAccountCounter();
auto usk = GenerateUnifiedSpendingKeyForAccount(accountId);
auto generated = GenerateUnifiedSpendingKeyForAccount(accountId);
hdChain.IncrementAccountCounter();
if (usk.has_value()) {
if (generated.has_value()) {
// Update the persisted chain information
if (fFileBacked && !CWalletDB(strWalletFile).WriteMnemonicHDChain(hdChain)) {
throw std::runtime_error(
"CWallet::GenerateNewUnifiedSpendingKey(): Writing HD chain model failed");
}
return std::make_pair(usk.value(), accountId);
return std::make_pair(generated.value().ToFullViewingKey(), accountId);
}
}
}

View File

@ -1480,7 +1480,7 @@ public:
//! Generate the unified spending key from the wallet's mnemonic seed
//! for the next unused account identifier.
std::pair<libzcash::ZcashdUnifiedSpendingKey, libzcash::AccountId>
std::pair<libzcash::UnifiedFullViewingKey, libzcash::AccountId>
GenerateNewUnifiedSpendingKey();
//! Generate the unified spending key for the specified ZIP-32/BIP-44