diff options
author | Andrew Chow <achow101-github@achow101.com> | 2022-04-13 16:37:29 -0400 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-06-19 11:38:01 -0400 |
commit | ad779e9ece9829677c1735d8865f14b23459da80 (patch) | |
tree | 06a5c26a874b9e13693b087fdc13852c1aa6c568 /src/wallet/walletdb.cpp | |
parent | 72c2a54ebb99fa3d91d7d15bd8a38a8d16e0ea6c (diff) | |
download | bitcoin-ad779e9ece9829677c1735d8865f14b23459da80.tar.xz |
walletdb: Refactor hd chain loading to its own function
Diffstat (limited to 'src/wallet/walletdb.cpp')
-rw-r--r-- | src/wallet/walletdb.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 6af7501924..0099741258 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -452,6 +452,22 @@ bool LoadEncryptionKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, return true; } +bool LoadHDChain(CWallet* pwallet, DataStream& ssValue, std::string& strErr) +{ + LOCK(pwallet->cs_wallet); + try { + CHDChain chain; + ssValue >> chain; + pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadHDChain(chain); + } catch (const std::exception& e) { + if (strErr.empty()) { + strErr = e.what(); + } + return false; + } + return true; +} + static bool ReadKeyValue(CWallet* pwallet, DataStream& ssKey, CDataStream& ssValue, CWalletScanState &wss, std::string& strType, std::string& strErr, const KeyFilterFn& filter_fn = nullptr) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) @@ -672,9 +688,7 @@ ReadKeyValue(CWallet* pwallet, DataStream& ssKey, CDataStream& ssValue, pwallet->LoadAddressReceiveRequest(dest, strKey.substr(2), strValue); } } else if (strType == DBKeys::HDCHAIN) { - CHDChain chain; - ssValue >> chain; - pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadHDChain(chain); + if (!LoadHDChain(pwallet, ssValue, strErr)) return false; } else if (strType == DBKeys::OLD_KEY) { strErr = "Found unsupported 'wkey' record, try loading with version 0.18"; return false; |