mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
CSecret/CKey -> CKey/CPubKey split/refactor
This commit is contained in:
committed by
Pieter Wuille
parent
5d891489ab
commit
dfa23b94c2
@@ -32,26 +32,28 @@ CPubKey CWallet::GenerateNewKey()
|
||||
bool fCompressed = CanSupportFeature(FEATURE_COMPRPUBKEY); // default to compressed public keys if we want 0.6.0 wallets
|
||||
|
||||
RandAddSeedPerfmon();
|
||||
CKey key;
|
||||
key.MakeNewKey(fCompressed);
|
||||
CKey secret;
|
||||
secret.MakeNewKey(fCompressed);
|
||||
|
||||
// Compressed public keys were introduced in version 0.6.0
|
||||
if (fCompressed)
|
||||
SetMinVersion(FEATURE_COMPRPUBKEY);
|
||||
|
||||
if (!AddKey(key))
|
||||
CPubKey pubkey = secret.GetPubKey();
|
||||
if (!AddKeyPubKey(secret, pubkey))
|
||||
throw std::runtime_error("CWallet::GenerateNewKey() : AddKey failed");
|
||||
return key.GetPubKey();
|
||||
return pubkey;
|
||||
}
|
||||
|
||||
bool CWallet::AddKey(const CKey& key)
|
||||
bool CWallet::AddKeyPubKey(const CKey& secret, const CPubKey &pubkey)
|
||||
{
|
||||
if (!CCryptoKeyStore::AddKey(key))
|
||||
if (!CCryptoKeyStore::AddKeyPubKey(secret, pubkey))
|
||||
return false;
|
||||
if (!fFileBacked)
|
||||
return true;
|
||||
if (!IsCrypted())
|
||||
return CWalletDB(strWalletFile).WriteKey(key.GetPubKey(), key.GetPrivKey());
|
||||
if (!IsCrypted()) {
|
||||
return CWalletDB(strWalletFile).WriteKey(pubkey, secret.GetPrivKey());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user