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:
parent
3c84ed604e
commit
c2a47b8d97
|
@ -2200,14 +2200,15 @@ TEST(WalletTests, GenerateUnifiedAddress) {
|
||||||
EXPECT_EQ(uaResult, expected);
|
EXPECT_EQ(uaResult, expected);
|
||||||
|
|
||||||
// Create an account, then generate an address for that account.
|
// Create an account, then generate an address for that account.
|
||||||
auto skpair = wallet.GenerateNewUnifiedSpendingKey();
|
auto ufvkpair = wallet.GenerateNewUnifiedSpendingKey();
|
||||||
uaResult = wallet.GenerateUnifiedAddress(skpair.second, {ReceiverType::P2PKH, ReceiverType::Sapling});
|
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);
|
auto ua = std::get_if<std::pair<libzcash::UnifiedAddress, libzcash::diversifier_index_t>>(&uaResult);
|
||||||
EXPECT_NE(ua, nullptr);
|
EXPECT_NE(ua, nullptr);
|
||||||
|
|
||||||
auto uaSaplingReceiver = ua->first.GetSaplingReceiver();
|
auto uaSaplingReceiver = ua->first.GetSaplingReceiver();
|
||||||
EXPECT_TRUE(uaSaplingReceiver.has_value());
|
EXPECT_TRUE(uaSaplingReceiver.has_value());
|
||||||
auto ufvk = skpair.first.ToFullViewingKey();
|
|
||||||
EXPECT_EQ(uaSaplingReceiver.value(), ufvk.GetSaplingKey().value().Address(ua->second));
|
EXPECT_EQ(uaSaplingReceiver.value(), ufvk.GetSaplingKey().value().Address(ua->second));
|
||||||
|
|
||||||
auto u4r = wallet.FindUnifiedAddressByReceiver(uaSaplingReceiver.value());
|
auto u4r = wallet.FindUnifiedAddressByReceiver(uaSaplingReceiver.value());
|
||||||
|
|
|
@ -3057,8 +3057,8 @@ UniValue z_getnewaccount(const UniValue& params, bool fHelp)
|
||||||
EnsureWalletIsUnlocked();
|
EnsureWalletIsUnlocked();
|
||||||
|
|
||||||
// Generate the new account.
|
// Generate the new account.
|
||||||
auto skNew = pwalletMain->GenerateNewUnifiedSpendingKey();
|
auto ufvkNew = pwalletMain->GenerateNewUnifiedSpendingKey();
|
||||||
const auto& account = skNew.second;
|
const auto& account = ufvkNew.second;
|
||||||
|
|
||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ);
|
||||||
result.pushKV("account", (uint64_t)account);
|
result.pushKV("account", (uint64_t)account);
|
||||||
|
|
|
@ -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);
|
AssertLockHeld(cs_wallet);
|
||||||
|
|
||||||
if (!mnemonicHDChain.has_value()) {
|
if (!mnemonicHDChain.has_value()) {
|
||||||
|
@ -488,17 +488,17 @@ std::pair<ZcashdUnifiedSpendingKey, libzcash::AccountId> CWallet::GenerateNewUni
|
||||||
CHDChain& hdChain = mnemonicHDChain.value();
|
CHDChain& hdChain = mnemonicHDChain.value();
|
||||||
while (true) {
|
while (true) {
|
||||||
auto accountId = hdChain.GetAccountCounter();
|
auto accountId = hdChain.GetAccountCounter();
|
||||||
auto usk = GenerateUnifiedSpendingKeyForAccount(accountId);
|
auto generated = GenerateUnifiedSpendingKeyForAccount(accountId);
|
||||||
hdChain.IncrementAccountCounter();
|
hdChain.IncrementAccountCounter();
|
||||||
|
|
||||||
if (usk.has_value()) {
|
if (generated.has_value()) {
|
||||||
// Update the persisted chain information
|
// Update the persisted chain information
|
||||||
if (fFileBacked && !CWalletDB(strWalletFile).WriteMnemonicHDChain(hdChain)) {
|
if (fFileBacked && !CWalletDB(strWalletFile).WriteMnemonicHDChain(hdChain)) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"CWallet::GenerateNewUnifiedSpendingKey(): Writing HD chain model failed");
|
"CWallet::GenerateNewUnifiedSpendingKey(): Writing HD chain model failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_pair(usk.value(), accountId);
|
return std::make_pair(generated.value().ToFullViewingKey(), accountId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1480,7 +1480,7 @@ public:
|
||||||
|
|
||||||
//! Generate the unified spending key from the wallet's mnemonic seed
|
//! Generate the unified spending key from the wallet's mnemonic seed
|
||||||
//! for the next unused account identifier.
|
//! for the next unused account identifier.
|
||||||
std::pair<libzcash::ZcashdUnifiedSpendingKey, libzcash::AccountId>
|
std::pair<libzcash::UnifiedFullViewingKey, libzcash::AccountId>
|
||||||
GenerateNewUnifiedSpendingKey();
|
GenerateNewUnifiedSpendingKey();
|
||||||
|
|
||||||
//! Generate the unified spending key for the specified ZIP-32/BIP-44
|
//! Generate the unified spending key for the specified ZIP-32/BIP-44
|
||||||
|
|
Loading…
Reference in New Issue