|
|
@ -40,18 +40,20 @@ CPubKey CWallet::GenerateNewKey() |
|
|
|
SetMinVersion(FEATURE_COMPRPUBKEY); |
|
|
|
SetMinVersion(FEATURE_COMPRPUBKEY); |
|
|
|
|
|
|
|
|
|
|
|
CPubKey pubkey = secret.GetPubKey(); |
|
|
|
CPubKey pubkey = secret.GetPubKey(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create new metadata
|
|
|
|
|
|
|
|
int64 nCreationTime = GetTime(); |
|
|
|
|
|
|
|
mapKeyMetadata[pubkey.GetID()] = CKeyMetadata(nCreationTime); |
|
|
|
|
|
|
|
if (!nTimeFirstKey || nCreationTime < nTimeFirstKey) |
|
|
|
|
|
|
|
nTimeFirstKey = nCreationTime; |
|
|
|
|
|
|
|
|
|
|
|
if (!AddKeyPubKey(secret, pubkey)) |
|
|
|
if (!AddKeyPubKey(secret, pubkey)) |
|
|
|
throw std::runtime_error("CWallet::GenerateNewKey() : AddKey failed"); |
|
|
|
throw std::runtime_error("CWallet::GenerateNewKey() : AddKey failed"); |
|
|
|
return pubkey; |
|
|
|
return pubkey; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool CWallet::AddKeyPubKey(const CKey& secret, const CPubKey &pubkey, |
|
|
|
bool CWallet::AddKeyPubKey(const CKey& secret, const CPubKey &pubkey) |
|
|
|
int64 nCreateTime) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!nCreateTime) |
|
|
|
|
|
|
|
nCreateTime = GetTime(); |
|
|
|
|
|
|
|
if (!nTimeFirstKey || (nCreateTime < nTimeFirstKey)) |
|
|
|
|
|
|
|
nTimeFirstKey = nCreateTime; |
|
|
|
|
|
|
|
if (!CCryptoKeyStore::AddKeyPubKey(secret, pubkey)) |
|
|
|
if (!CCryptoKeyStore::AddKeyPubKey(secret, pubkey)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
if (!fFileBacked) |
|
|
|
if (!fFileBacked) |
|
|
@ -59,19 +61,14 @@ bool CWallet::AddKeyPubKey(const CKey& secret, const CPubKey &pubkey, |
|
|
|
if (!IsCrypted()) { |
|
|
|
if (!IsCrypted()) { |
|
|
|
return CWalletDB(strWalletFile).WriteKey(pubkey, |
|
|
|
return CWalletDB(strWalletFile).WriteKey(pubkey, |
|
|
|
secret.GetPrivKey(), |
|
|
|
secret.GetPrivKey(), |
|
|
|
nCreateTime); |
|
|
|
mapKeyMetadata[pubkey.GetID()]); |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, |
|
|
|
bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, |
|
|
|
const vector<unsigned char> &vchCryptedSecret, |
|
|
|
const vector<unsigned char> &vchCryptedSecret) |
|
|
|
int64 nCreateTime) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!nCreateTime) |
|
|
|
|
|
|
|
nCreateTime = GetTime(); |
|
|
|
|
|
|
|
if (!nTimeFirstKey || (nCreateTime < nTimeFirstKey)) |
|
|
|
|
|
|
|
nTimeFirstKey = nCreateTime; |
|
|
|
|
|
|
|
if (!CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret)) |
|
|
|
if (!CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
if (!fFileBacked) |
|
|
|
if (!fFileBacked) |
|
|
@ -81,15 +78,24 @@ bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, |
|
|
|
if (pwalletdbEncryption) |
|
|
|
if (pwalletdbEncryption) |
|
|
|
return pwalletdbEncryption->WriteCryptedKey(vchPubKey, |
|
|
|
return pwalletdbEncryption->WriteCryptedKey(vchPubKey, |
|
|
|
vchCryptedSecret, |
|
|
|
vchCryptedSecret, |
|
|
|
nCreateTime); |
|
|
|
mapKeyMetadata[vchPubKey.GetID()]); |
|
|
|
else |
|
|
|
else |
|
|
|
return CWalletDB(strWalletFile).WriteCryptedKey(vchPubKey, |
|
|
|
return CWalletDB(strWalletFile).WriteCryptedKey(vchPubKey, |
|
|
|
vchCryptedSecret, |
|
|
|
vchCryptedSecret, |
|
|
|
nCreateTime); |
|
|
|
mapKeyMetadata[vchPubKey.GetID()]); |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CWallet::LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &meta) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (meta.nCreateTime && (!nTimeFirstKey || meta.nCreateTime < nTimeFirstKey)) |
|
|
|
|
|
|
|
nTimeFirstKey = meta.nCreateTime; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapKeyMetadata[pubkey.GetID()] = meta; |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool CWallet::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) |
|
|
|
bool CWallet::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret); |
|
|
|
return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret); |
|
|
|