[0.13] Create a new HD seed after encrypting the wallet
https://github.com/bitcoin/bitcoin/pull/8389/commits
This commit is contained in:
@@ -946,6 +946,15 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
||||
|
||||
Lock();
|
||||
Unlock(strWalletPassphrase);
|
||||
|
||||
// if we are using HD, replace the HD master key with a new one
|
||||
if (!hdChain.masterKeyID.IsNull()) {
|
||||
CKey key;
|
||||
key.MakeNewKey(true);
|
||||
if (!SetHDMasterKey(key))
|
||||
return false;
|
||||
}
|
||||
|
||||
NewKeyPool();
|
||||
Lock();
|
||||
|
||||
@@ -1378,19 +1387,42 @@ CAmount CWallet::GetChange(const CTxOut& txout) const
|
||||
return (IsChange(txout) ? txout.nValue : 0);
|
||||
}
|
||||
|
||||
CPubKey CWallet::GenerateNewHDMasterKey()
|
||||
{
|
||||
CKey key;
|
||||
key.MakeNewKey(true);
|
||||
|
||||
int64_t nCreationTime = GetTime();
|
||||
CKeyMetadata metadata(nCreationTime);
|
||||
|
||||
// calculate the pubkey
|
||||
CPubKey pubkey = key.GetPubKey();
|
||||
assert(key.VerifyPubKey(pubkey));
|
||||
|
||||
// set the hd keypath to "m" -> Master, refers the masterkeyid to itself
|
||||
metadata.hdKeypath = "m";
|
||||
metadata.hdMasterKeyID = pubkey.GetID();
|
||||
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
|
||||
// mem store the metadata
|
||||
mapKeyMetadata[pubkey.GetID()] = metadata;
|
||||
|
||||
// write the key&metadata to the database
|
||||
if (!AddKeyPubKey(key, pubkey))
|
||||
throw std::runtime_error("CWallet::GenerateNewKey(): AddKey failed");
|
||||
}
|
||||
|
||||
return pubkey;
|
||||
}
|
||||
|
||||
bool CWallet::SetHDMasterKey(const CKey& key)
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
|
||||
// ensure this wallet.dat can only be opened by clients supporting HD
|
||||
SetMinVersion(FEATURE_HD);
|
||||
|
||||
// store the key as normal "key"/"ckey" object
|
||||
// in the database
|
||||
// key metadata is not required
|
||||
CPubKey pubkey = key.GetPubKey();
|
||||
if (!AddKeyPubKey(key, pubkey))
|
||||
throw std::runtime_error("CWallet::GenerateNewKey(): AddKey failed");
|
||||
|
||||
// store the keyid (hash160) together with
|
||||
// the child index counter in the database
|
||||
|
||||
Reference in New Issue
Block a user