GenerateLegacySaplingZKey only needs to return an address, not an extfvk.

This commit is contained in:
Kris Nuttycombe 2022-01-30 11:26:49 -07:00
parent ae2213dcdc
commit b80349d246
3 changed files with 12 additions and 12 deletions

View File

@ -205,8 +205,8 @@ libzcash::SaplingPaymentAddress AsyncRPCOperation_saplingmigration::getMigration
} }
// TODO: move off of legacy addresses. // TODO: move off of legacy addresses.
auto generatedKey = pwalletMain->GenerateLegacySaplingZKey(0); auto generated = pwalletMain->GenerateLegacySaplingZKey(0);
return generatedKey.first.ToXFVK().DefaultAddress(); return generated.first;
} }
void AsyncRPCOperation_saplingmigration::cancel() { void AsyncRPCOperation_saplingmigration::cancel() {

View File

@ -129,13 +129,12 @@ SaplingPaymentAddress CWallet::GenerateNewLegacySaplingZKey() {
// loop until we find an unused address index // loop until we find an unused address index
while (true) { while (true) {
auto generatedKey = GenerateLegacySaplingZKey(hdChain.GetLegacySaplingKeyCounter()); auto generated = GenerateLegacySaplingZKey(hdChain.GetLegacySaplingKeyCounter());
auto xfvk = generatedKey.first.ToXFVK();
// advance the address index counter so that the next time we need to generate // advance the address index counter so that the next time we need to generate
// a key we're pointing at a free index. // a key we're pointing at a free index.
hdChain.IncrementLegacySaplingKeyCounter(); hdChain.IncrementLegacySaplingKeyCounter();
if (!generatedKey.second) { if (!generated.second) {
// the key already existed, so try the next one // the key already existed, so try the next one
continue; continue;
} else { } else {
@ -145,12 +144,12 @@ SaplingPaymentAddress CWallet::GenerateNewLegacySaplingZKey() {
"CWallet::GenerateNewLegacySaplingZKey(): Writing HD chain model failed"); "CWallet::GenerateNewLegacySaplingZKey(): Writing HD chain model failed");
} }
return xfvk.DefaultAddress(); return generated.first;
} }
} }
} }
std::pair<SaplingExtendedSpendingKey, bool> CWallet::GenerateLegacySaplingZKey(uint32_t addrIndex) { std::pair<SaplingPaymentAddress, bool> CWallet::GenerateLegacySaplingZKey(uint32_t addrIndex) {
auto seedOpt = GetMnemonicSeed(); auto seedOpt = GetMnemonicSeed();
if (!seedOpt.has_value()) { if (!seedOpt.has_value()) {
throw std::runtime_error( throw std::runtime_error(
@ -159,8 +158,9 @@ std::pair<SaplingExtendedSpendingKey, bool> CWallet::GenerateLegacySaplingZKey(u
auto seed = seedOpt.value(); auto seed = seedOpt.value();
auto xsk = libzcash::SaplingExtendedSpendingKey::Legacy(seed, BIP44CoinType(), addrIndex); auto xsk = libzcash::SaplingExtendedSpendingKey::Legacy(seed, BIP44CoinType(), addrIndex);
if (!HaveSaplingSpendingKey(xsk.first.ToXFVK())) { auto extfvk = xsk.first.ToXFVK();
auto ivk = xsk.first.expsk.full_viewing_key().in_viewing_key(); if (!HaveSaplingSpendingKey(extfvk)) {
auto ivk = extfvk.fvk.in_viewing_key();
CKeyMetadata keyMeta(GetTime()); CKeyMetadata keyMeta(GetTime());
keyMeta.hdKeypath = xsk.second; keyMeta.hdKeypath = xsk.second;
keyMeta.seedFp = seed.Fingerprint(); keyMeta.seedFp = seed.Fingerprint();
@ -169,9 +169,9 @@ std::pair<SaplingExtendedSpendingKey, bool> CWallet::GenerateLegacySaplingZKey(u
if (!AddSaplingZKey(xsk.first)) { if (!AddSaplingZKey(xsk.first)) {
throw std::runtime_error("CWallet::GenerateLegacySaplingZKey(): AddSaplingZKey failed."); throw std::runtime_error("CWallet::GenerateLegacySaplingZKey(): AddSaplingZKey failed.");
} }
return std::make_pair(xsk.first, true) ; return std::make_pair(extfvk.DefaultAddress(), true) ;
} else { } else {
return std::make_pair(xsk.first, false); return std::make_pair(extfvk.DefaultAddress(), false);
} }
} }

View File

@ -1372,7 +1372,7 @@ public:
//! spending key to the wallet if it has not alreay been persisted. //! spending key to the wallet if it has not alreay been persisted.
//! Returns the newly created key, and a flag distinguishing //! Returns the newly created key, and a flag distinguishing
//! whether or not the key was already known by the wallet. //! whether or not the key was already known by the wallet.
std::pair<libzcash::SaplingExtendedSpendingKey, bool> GenerateLegacySaplingZKey(uint32_t addrIndex); std::pair<libzcash::SaplingPaymentAddress, bool> GenerateLegacySaplingZKey(uint32_t addrIndex);
//! Adds Sapling spending key to the store, and saves it to disk //! Adds Sapling spending key to the store, and saves it to disk
bool AddSaplingZKey(const libzcash::SaplingExtendedSpendingKey &key); bool AddSaplingZKey(const libzcash::SaplingExtendedSpendingKey &key);
//! Add Sapling full viewing key to the wallet. //! Add Sapling full viewing key to the wallet.