Restore legacy default Sapling addresses to the keystore.
Prior to zcash/zcash@90e59c3be0 Sapling default payment addresses were added to the in-memory keystore whenever a full viewing key was added, or loaded from disk. After that change, the Sapling address was no longer being restored to the in-memory keystore on wallet load; instead, z_getnewaddress and z_getnewaddressforaccount both persist the address to the keystore directly. This commit adds handling to `LoadCaches` to correctly persist the default address to the wallet database, and add it to the in-memory keystore, when this condition is detected.
This commit is contained in:
parent
d17c981013
commit
dd578cb290
|
@ -1136,6 +1136,32 @@ bool CWallet::LoadCaches()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sapling legacy addresses were not directly added to the keystore; instead,
|
||||||
|
// the default address for each key was automatically added to the in-memory
|
||||||
|
// keystore, but not persisted. Following the addition of unified addresses,
|
||||||
|
// all addresses must be written to the wallet database explicitly.
|
||||||
|
auto legacySeed = GetLegacyHDSeed();
|
||||||
|
if (legacySeed.has_value()) {
|
||||||
|
for (const auto& [saplingIvk, keyMeta] : mapSaplingZKeyMetadata) {
|
||||||
|
// This condition only applies for keys derived from the legacy seed
|
||||||
|
if (keyMeta.seedFp == legacySeed.value().Fingerprint()) {
|
||||||
|
SaplingExtendedFullViewingKey extfvk;
|
||||||
|
if (GetSaplingFullViewingKey(saplingIvk, extfvk)) {
|
||||||
|
auto defaultAddress = extfvk.DefaultAddress();
|
||||||
|
if (!HaveSaplingIncomingViewingKey(defaultAddress)) {
|
||||||
|
// restore the address to the keystore and persist it so that
|
||||||
|
// the database state is consistent.
|
||||||
|
if (!AddSaplingPaymentAddress(saplingIvk, defaultAddress)) {
|
||||||
|
LogPrintf("%s: Error: Failed to write legacy Sapling payment address to the wallet database.\n",
|
||||||
|
__func__);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Restore decrypted Orchard notes.
|
// Restore decrypted Orchard notes.
|
||||||
for (const auto& [_, walletTx] : mapWallet) {
|
for (const auto& [_, walletTx] : mapWallet) {
|
||||||
if (!walletTx.orchardTxMeta.empty()) {
|
if (!walletTx.orchardTxMeta.empty()) {
|
||||||
|
|
Loading…
Reference in New Issue