Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/walletdb.cpp
Show First 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | if (!WriteKeyMetadata(keyMeta, vchPubKey, true)) { | ||||
return false; | return false; | ||||
} | } | ||||
if (!WriteIC(std::make_pair(DBKeys::CRYPTED_KEY, vchPubKey), | if (!WriteIC(std::make_pair(DBKeys::CRYPTED_KEY, vchPubKey), | ||||
vchCryptedSecret, false)) { | vchCryptedSecret, false)) { | ||||
return false; | return false; | ||||
} | } | ||||
EraseIC(std::make_pair(DBKeys::KEY, vchPubKey)); | EraseIC(std::make_pair(DBKeys::KEY, vchPubKey)); | ||||
EraseIC(std::make_pair(DBKeys::OLD_KEY, vchPubKey)); | |||||
return true; | return true; | ||||
} | } | ||||
bool WalletBatch::WriteMasterKey(unsigned int nID, | bool WalletBatch::WriteMasterKey(unsigned int nID, | ||||
const CMasterKey &kMasterKey) { | const CMasterKey &kMasterKey) { | ||||
return WriteIC(std::make_pair(DBKeys::MASTER_KEY, nID), kMasterKey, true); | return WriteIC(std::make_pair(DBKeys::MASTER_KEY, nID), kMasterKey, true); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | try { | ||||
wss.nWatchKeys++; | wss.nWatchKeys++; | ||||
CScript script; | CScript script; | ||||
ssKey >> script; | ssKey >> script; | ||||
char fYes; | char fYes; | ||||
ssValue >> fYes; | ssValue >> fYes; | ||||
if (fYes == '1') { | if (fYes == '1') { | ||||
pwallet->LoadWatchOnly(script); | pwallet->LoadWatchOnly(script); | ||||
} | } | ||||
} else if (strType == DBKeys::KEY || strType == DBKeys::OLD_KEY) { | } else if (strType == DBKeys::KEY) { | ||||
CPubKey vchPubKey; | CPubKey vchPubKey; | ||||
ssKey >> vchPubKey; | ssKey >> vchPubKey; | ||||
if (!vchPubKey.IsValid()) { | if (!vchPubKey.IsValid()) { | ||||
strErr = "Error reading wallet database: CPubKey corrupt"; | strErr = "Error reading wallet database: CPubKey corrupt"; | ||||
return false; | return false; | ||||
} | } | ||||
CKey key; | CKey key; | ||||
CPrivKey pkey; | CPrivKey pkey; | ||||
uint256 hash; | uint256 hash; | ||||
if (strType == DBKeys::KEY) { | |||||
wss.nKeys++; | wss.nKeys++; | ||||
ssValue >> pkey; | ssValue >> pkey; | ||||
} else { | |||||
OldKey wkey; | |||||
ssValue >> wkey; | |||||
pkey = wkey.vchPrivKey; | |||||
} | |||||
// Old wallets store keys as DBKeys::KEY [pubkey] => [privkey] ... | // Old wallets store keys as DBKeys::KEY [pubkey] => [privkey] ... | ||||
// which was slow for wallets with lots of keys, because the public | // which was slow for wallets with lots of keys, because the public | ||||
// key is re-derived from the private key using EC operations as a | // key is re-derived from the private key using EC operations as a | ||||
// checksum. Newer wallets store keys as DBKeys::KEY [pubkey] => | // checksum. Newer wallets store keys as DBKeys::KEY [pubkey] => | ||||
// [privkey][hash(pubkey,privkey)], which is much faster while | // [privkey][hash(pubkey,privkey)], which is much faster while | ||||
// remaining backwards-compatible. | // remaining backwards-compatible. | ||||
try { | try { | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | try { | ||||
} else if (strType == DBKeys::FLAGS) { | } else if (strType == DBKeys::FLAGS) { | ||||
uint64_t flags; | uint64_t flags; | ||||
ssValue >> flags; | ssValue >> flags; | ||||
if (!pwallet->SetWalletFlags(flags, true)) { | if (!pwallet->SetWalletFlags(flags, true)) { | ||||
strErr = "Error reading wallet database: Unknown non-tolerable " | strErr = "Error reading wallet database: Unknown non-tolerable " | ||||
"wallet flags found"; | "wallet flags found"; | ||||
return false; | return false; | ||||
} | } | ||||
} else if (strType == DBKeys::OLD_KEY) { | |||||
strErr = "Found unsupported 'wkey' record, try loading with " | |||||
"version 0.20"; | |||||
return false; | |||||
} else if (strType != DBKeys::BESTBLOCK && | } else if (strType != DBKeys::BESTBLOCK && | ||||
strType != DBKeys::BESTBLOCK_NOMERKLE && | strType != DBKeys::BESTBLOCK_NOMERKLE && | ||||
strType != DBKeys::MINVERSION && | strType != DBKeys::MINVERSION && | ||||
strType != DBKeys::ACENTRY && strType != DBKeys::VERSION && | strType != DBKeys::ACENTRY && strType != DBKeys::VERSION && | ||||
strType != DBKeys::SETTINGS) { | strType != DBKeys::SETTINGS) { | ||||
wss.m_unknown_records++; | wss.m_unknown_records++; | ||||
} | } | ||||
} catch (...) { | } catch (...) { | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool WalletBatch::IsKeyType(const std::string &strType) { | bool WalletBatch::IsKeyType(const std::string &strType) { | ||||
return (strType == DBKeys::KEY || strType == DBKeys::OLD_KEY || | return (strType == DBKeys::KEY || strType == DBKeys::MASTER_KEY || | ||||
strType == DBKeys::MASTER_KEY || strType == DBKeys::CRYPTED_KEY); | strType == DBKeys::CRYPTED_KEY); | ||||
} | } | ||||
DBErrors WalletBatch::LoadWallet(CWallet *pwallet) { | DBErrors WalletBatch::LoadWallet(CWallet *pwallet) { | ||||
CWalletScanState wss; | CWalletScanState wss; | ||||
bool fNoncriticalErrors = false; | bool fNoncriticalErrors = false; | ||||
DBErrors result = DBErrors::LOAD_OK; | DBErrors result = DBErrors::LOAD_OK; | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
▲ Show 20 Lines • Show All 367 Lines • Show Last 20 Lines |