From 3665f69a483f8dac27ae1cf5aca6a547b374954a Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Tue, 1 Mar 2022 10:15:06 -0700 Subject: [PATCH] wallet: restore orchard address to IVK mappings during wallet loading --- src/wallet/wallet.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index cc69f26bd..8457de96c 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -881,6 +881,13 @@ bool CWallet::LoadUnifiedCaches() { auto orchardSk = usk.value().GetOrchardKey(); orchardWallet.AddSpendingKey(orchardSk); + + // Associate the Orchard default change address with its IVK + auto orchardInternalIvk = orchardSk.ToFullViewingKey().ToInternalIncomingViewingKey(); + if (!AddOrchardRawAddress(orchardInternalIvk, orchardInternalIvk.Address(0))) { + // Unable to generate a default internal address + return false; + } } // restore unified addresses that have been previously generated to the @@ -891,6 +898,19 @@ bool CWallet::LoadUnifiedCaches() return false; }, [&](const std::pair& addr) { + // Associate the orchard address with our IVK, if there's + // an orchard receiver present in this address. + auto orchardFvk = ufvk.value().GetOrchardKey(); + auto orchardReceiver = addr.first.GetOrchardReceiver(); + assert (orchardFvk.has_value() == orchardReceiver.has_value()); + + if (orchardFvk.has_value()) { + if (!AddOrchardRawAddress(orchardFvk.value().ToIncomingViewingKey(), orchardReceiver.value())) { + // Unable to add an orchard address -> IVK mapping to the wallet + return false; + } + } + return CCryptoKeyStore::AddTransparentReceiverForUnifiedAddress( ufvkId, addr.second, addr.first); }