Browse Source

Do not break backward compatibility during wallet encryption

0.15
Jonas Schnelli 8 years ago
parent
commit
9382f0425e
No known key found for this signature in database
GPG Key ID: 1EB776BB03C7922D
  1. 10
      src/wallet/wallet.cpp
  2. 6
      src/wallet/wallet.h

10
src/wallet/wallet.cpp

@ -639,7 +639,9 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
if (IsHDEnabled()) { if (IsHDEnabled()) {
CKey key; CKey key;
CPubKey masterPubKey = GenerateNewHDMasterKey(); 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; return false;
} }
@ -1306,13 +1308,17 @@ CPubKey CWallet::GenerateNewHDMasterKey()
return pubkey; return pubkey;
} }
bool CWallet::SetHDMasterKey(const CPubKey& pubkey) bool CWallet::SetHDMasterKey(const CPubKey& pubkey, CHDChain *possibleOldChain)
{ {
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) {
// preserve the old chains version
newHdChain.nVersion = possibleOldChain->nVersion;
}
newHdChain.masterKeyID = pubkey.GetID(); newHdChain.masterKeyID = pubkey.GetID();
SetHDChain(newHdChain, false); SetHDChain(newHdChain, false);

6
src/wallet/wallet.h

@ -1055,8 +1055,10 @@ public:
/* Generates a new HD master key (will not be activated) */ /* Generates a new HD master key (will not be activated) */
CPubKey GenerateNewHDMasterKey(); CPubKey GenerateNewHDMasterKey();
/* Set the current HD master key (will reset the chain child index counters) */ /* Set the current HD master key (will reset the chain child index counters)
bool SetHDMasterKey(const CPubKey& key); If possibleOldChain is provided, the parameters from the old chain (version)
will be preserved. */
bool SetHDMasterKey(const CPubKey& key, CHDChain *possibleOldChain = nullptr);
}; };
/** A key allocated from the key pool. */ /** A key allocated from the key pool. */

Loading…
Cancel
Save