Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 745 Lines • ▼ Show 20 Lines | if (!crypter.Encrypt(_vMasterKey, kMasterKey.vchCryptedKey)) { | ||||
delete pwalletdbEncryption; | delete pwalletdbEncryption; | ||||
pwalletdbEncryption = nullptr; | pwalletdbEncryption = nullptr; | ||||
Lock(); | Lock(); | ||||
Unlock(strWalletPassphrase); | Unlock(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(); | ||||
Lock(); | Lock(); | ||||
// Need to completely rewrite the wallet file; if we don't, bdb might | // Need to completely rewrite the wallet file; if we don't, bdb might | ||||
▲ Show 20 Lines • Show All 772 Lines • ▼ Show 20 Lines | CPubKey CWallet::GenerateNewHDMasterKey() { | ||||
if (!AddKeyPubKey(key, pubkey)) { | if (!AddKeyPubKey(key, pubkey)) { | ||||
throw std::runtime_error(std::string(__func__) + | throw std::runtime_error(std::string(__func__) + | ||||
": AddKeyPubKey failed"); | ": AddKeyPubKey failed"); | ||||
} | } | ||||
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 the child index counter in the | // Store the keyid (hash160) together with the child index counter in the | ||||
// database as a hdchain object. | // database as a hdchain object. | ||||
CHDChain newHdChain; | CHDChain newHdChain; | ||||
if (possibleOldChain) { | newHdChain.nVersion = CanSupportFeature(FEATURE_HD_SPLIT) | ||||
// preserve the old chains version | ? CHDChain::VERSION_HD_CHAIN_SPLIT | ||||
newHdChain.nVersion = possibleOldChain->nVersion; | : CHDChain::VERSION_HD_BASE; | ||||
} | |||||
newHdChain.masterKeyID = pubkey.GetID(); | newHdChain.masterKeyID = pubkey.GetID(); | ||||
SetHDChain(newHdChain, false); | SetHDChain(newHdChain, false); | ||||
return true; | return true; | ||||
} | } | ||||
bool CWallet::SetHDChain(const CHDChain &chain, bool memonly) { | bool CWallet::SetHDChain(const CHDChain &chain, bool memonly) { | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
▲ Show 20 Lines • Show All 2,910 Lines • Show Last 20 Lines |