mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
Do not break backward compatibility during wallet encryption
This commit is contained in:
@@ -639,7 +639,9 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
||||
if (IsHDEnabled()) {
|
||||
CKey key;
|
||||
CPubKey masterPubKey = GenerateNewHDMasterKey();
|
||||
if (!SetHDMasterKey(masterPubKey))
|
||||
// preserve the old chains version to not break backward compatibility
|
||||
CHDChain oldChain = GetHDChain();
|
||||
if (!SetHDMasterKey(masterPubKey, &oldChain))
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1306,13 +1308,17 @@ CPubKey CWallet::GenerateNewHDMasterKey()
|
||||
return pubkey;
|
||||
}
|
||||
|
||||
bool CWallet::SetHDMasterKey(const CPubKey& pubkey)
|
||||
bool CWallet::SetHDMasterKey(const CPubKey& pubkey, CHDChain *possibleOldChain)
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
// store the keyid (hash160) together with
|
||||
// the child index counter in the database
|
||||
// as a hdchain object
|
||||
CHDChain newHdChain;
|
||||
if (possibleOldChain) {
|
||||
// preserve the old chains version
|
||||
newHdChain.nVersion = possibleOldChain->nVersion;
|
||||
}
|
||||
newHdChain.masterKeyID = pubkey.GetID();
|
||||
SetHDChain(newHdChain, false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user