aboutsummaryrefslogtreecommitdiff
path: root/src/walletdb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/walletdb.cpp')
-rw-r--r--src/walletdb.cpp59
1 files changed, 20 insertions, 39 deletions
diff --git a/src/walletdb.cpp b/src/walletdb.cpp
index 81a21443a1..4a73413d26 100644
--- a/src/walletdb.cpp
+++ b/src/walletdb.cpp
@@ -262,52 +262,33 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
}
else if (strType == "key" || strType == "wkey")
{
- vector<unsigned char> vchPubKey;
+ CPubKey vchPubKey;
ssKey >> vchPubKey;
+ if (!vchPubKey.IsValid())
+ {
+ strErr = "Error reading wallet database: CPubKey corrupt";
+ return false;
+ }
CKey key;
+ CPrivKey pkey;
if (strType == "key")
- {
- CPrivKey pkey;
ssValue >> pkey;
- key.SetPubKey(vchPubKey);
- if (!key.SetPrivKey(pkey))
- {
- strErr = "Error reading wallet database: CPrivKey corrupt";
- return false;
- }
- if (key.GetPubKey() != vchPubKey)
- {
- strErr = "Error reading wallet database: CPrivKey pubkey inconsistency";
- return false;
- }
- if (!key.IsValid())
- {
- strErr = "Error reading wallet database: invalid CPrivKey";
- return false;
- }
- }
- else
- {
+ else {
CWalletKey wkey;
ssValue >> wkey;
- key.SetPubKey(vchPubKey);
- if (!key.SetPrivKey(wkey.vchPrivKey))
- {
- strErr = "Error reading wallet database: CPrivKey corrupt";
- return false;
- }
- if (key.GetPubKey() != vchPubKey)
- {
- strErr = "Error reading wallet database: CWalletKey pubkey inconsistency";
- return false;
- }
- if (!key.IsValid())
- {
- strErr = "Error reading wallet database: invalid CWalletKey";
- return false;
- }
+ pkey = wkey.vchPrivKey;
+ }
+ if (!key.SetPrivKey(pkey, vchPubKey.IsCompressed()))
+ {
+ strErr = "Error reading wallet database: CPrivKey corrupt";
+ return false;
+ }
+ if (key.GetPubKey() != vchPubKey)
+ {
+ strErr = "Error reading wallet database: CPrivKey pubkey inconsistency";
+ return false;
}
- if (!pwallet->LoadKey(key))
+ if (!pwallet->LoadKey(key, vchPubKey))
{
strErr = "Error reading wallet database: LoadKey failed";
return false;