Skip to content

Commit ad779e9

Browse files
committed
walletdb: Refactor hd chain loading to its own function
1 parent 72c2a54 commit ad779e9

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/wallet/walletdb.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,22 @@ bool LoadEncryptionKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue,
452452
return true;
453453
}
454454

455+
bool LoadHDChain(CWallet* pwallet, DataStream& ssValue, std::string& strErr)
456+
{
457+
LOCK(pwallet->cs_wallet);
458+
try {
459+
CHDChain chain;
460+
ssValue >> chain;
461+
pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadHDChain(chain);
462+
} catch (const std::exception& e) {
463+
if (strErr.empty()) {
464+
strErr = e.what();
465+
}
466+
return false;
467+
}
468+
return true;
469+
}
470+
455471
static bool
456472
ReadKeyValue(CWallet* pwallet, DataStream& ssKey, CDataStream& ssValue,
457473
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,
672688
pwallet->LoadAddressReceiveRequest(dest, strKey.substr(2), strValue);
673689
}
674690
} else if (strType == DBKeys::HDCHAIN) {
675-
CHDChain chain;
676-
ssValue >> chain;
677-
pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadHDChain(chain);
691+
if (!LoadHDChain(pwallet, ssValue, strErr)) return false;
678692
} else if (strType == DBKeys::OLD_KEY) {
679693
strErr = "Found unsupported 'wkey' record, try loading with version 0.18";
680694
return false;

src/wallet/walletdb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ bool ReadKeyValue(CWallet* pwallet, DataStream& ssKey, CDataStream& ssValue, std
309309
bool LoadKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr);
310310
bool LoadCryptedKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr);
311311
bool LoadEncryptionKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr);
312+
bool LoadHDChain(CWallet* pwallet, DataStream& ssValue, std::string& strErr);
312313
} // namespace wallet
313314

314315
#endif // BITCOIN_WALLET_WALLETDB_H

0 commit comments

Comments
 (0)