File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -639,7 +639,9 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
639
639
if (IsHDEnabled ()) {
640
640
CKey key;
641
641
CPubKey masterPubKey = GenerateNewHDMasterKey ();
642
- if (!SetHDMasterKey (masterPubKey))
642
+ // preserve the old chains version to not break backward compatibility
643
+ CHDChain oldChain = GetHDChain ();
644
+ if (!SetHDMasterKey (masterPubKey, &oldChain))
643
645
return false ;
644
646
}
645
647
@@ -1306,13 +1308,17 @@ CPubKey CWallet::GenerateNewHDMasterKey()
1306
1308
return pubkey;
1307
1309
}
1308
1310
1309
- bool CWallet::SetHDMasterKey (const CPubKey& pubkey)
1311
+ bool CWallet::SetHDMasterKey (const CPubKey& pubkey, CHDChain *possibleOldChain )
1310
1312
{
1311
1313
LOCK (cs_wallet);
1312
1314
// store the keyid (hash160) together with
1313
1315
// the child index counter in the database
1314
1316
// as a hdchain object
1315
1317
CHDChain newHdChain;
1318
+ if (possibleOldChain) {
1319
+ // preserve the old chains version
1320
+ newHdChain.nVersion = possibleOldChain->nVersion ;
1321
+ }
1316
1322
newHdChain.masterKeyID = pubkey.GetID ();
1317
1323
SetHDChain (newHdChain, false );
1318
1324
Original file line number Diff line number Diff line change @@ -1055,8 +1055,10 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
1055
1055
/* Generates a new HD master key (will not be activated) */
1056
1056
CPubKey GenerateNewHDMasterKey ();
1057
1057
1058
- /* Set the current HD master key (will reset the chain child index counters) */
1059
- bool SetHDMasterKey (const CPubKey& key);
1058
+ /* Set the current HD master key (will reset the chain child index counters)
1059
+ If possibleOldChain is provided, the parameters from the old chain (version)
1060
+ will be preserved. */
1061
+ bool SetHDMasterKey (const CPubKey& key, CHDChain *possibleOldChain = nullptr );
1060
1062
};
1061
1063
1062
1064
/* * A key allocated from the key pool. */
You can’t perform that action at this time.
0 commit comments