@ -637,12 +637,9 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
// if we are using HD, replace the HD master key (seed) with a new one
// if we are using HD, replace the HD master key (seed) with a new one
if ( IsHDEnabled ( ) ) {
if ( IsHDEnabled ( ) ) {
CKey key ;
if ( ! SetHDMasterKey ( GenerateNewHDMasterKey ( ) ) ) {
CPubKey masterPubKey = GenerateNewHDMasterKey ( ) ;
// preserve the old chains version to not break backward compatibility
CHDChain oldChain = GetHDChain ( ) ;
if ( ! SetHDMasterKey ( masterPubKey , & oldChain ) )
return false ;
return false ;
}
}
}
NewKeyPool ( ) ;
NewKeyPool ( ) ;
@ -1308,17 +1305,14 @@ CPubKey CWallet::GenerateNewHDMasterKey()
return pubkey ;
return pubkey ;
}
}
bool CWallet : : SetHDMasterKey ( const CPubKey & pubkey , CHDChain * possibleOldChain )
bool CWallet : : SetHDMasterKey ( const CPubKey & pubkey )
{
{
LOCK ( cs_wallet ) ;
LOCK ( cs_wallet ) ;
// store the keyid (hash160) together with
// store the keyid (hash160) together with
// the child index counter in the database
// the child index counter in the database
// as a hdchain object
// as a hdchain object
CHDChain newHdChain ;
CHDChain newHdChain ;
if ( possibleOldChain ) {
newHdChain . nVersion = CanSupportFeature ( FEATURE_HD_SPLIT ) ? CHDChain : : VERSION_HD_CHAIN_SPLIT : CHDChain : : VERSION_HD_BASE ;
// preserve the old chains version
newHdChain . nVersion = possibleOldChain - > nVersion ;
}
newHdChain . masterKeyID = pubkey . GetID ( ) ;
newHdChain . masterKeyID = pubkey . GetID ( ) ;
SetHDChain ( newHdChain , false ) ;
SetHDChain ( newHdChain , false ) ;