Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/walletdb.cpp
Show First 20 Lines • Show All 267 Lines • ▼ Show 20 Lines | try { | ||||
pwallet->LoadToWallet(wtx); | pwallet->LoadToWallet(wtx); | ||||
} else if (strType == DBKeys::WATCHS) { | } else if (strType == DBKeys::WATCHS) { | ||||
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->GetLegacyScriptPubKeyMan()->LoadWatchOnly(script); | pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadWatchOnly( | ||||
script); | |||||
} | } | ||||
} else if (strType == DBKeys::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; | ||||
} | } | ||||
Show All 32 Lines | try { | ||||
fSkipCheck = true; | fSkipCheck = true; | ||||
} | } | ||||
if (!key.Load(pkey, vchPubKey, fSkipCheck)) { | if (!key.Load(pkey, vchPubKey, fSkipCheck)) { | ||||
strErr = "Error reading wallet database: CPrivKey corrupt"; | strErr = "Error reading wallet database: CPrivKey corrupt"; | ||||
return false; | return false; | ||||
} | } | ||||
if (!pwallet->GetLegacyScriptPubKeyMan()->LoadKey(key, vchPubKey)) { | if (!pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadKey( | ||||
key, vchPubKey)) { | |||||
strErr = "Error reading wallet database: " | strErr = "Error reading wallet database: " | ||||
"LegacyScriptPubKeyMan::LoadKey failed"; | "LegacyScriptPubKeyMan::LoadKey failed"; | ||||
return false; | return false; | ||||
} | } | ||||
} else if (strType == DBKeys::MASTER_KEY) { | } else if (strType == DBKeys::MASTER_KEY) { | ||||
// Master encryption key is loaded into only the wallet and not any | // Master encryption key is loaded into only the wallet and not any | ||||
// of the ScriptPubKeyMans. | // of the ScriptPubKeyMans. | ||||
unsigned int nID; | unsigned int nID; | ||||
Show All 16 Lines | try { | ||||
if (!vchPubKey.IsValid()) { | if (!vchPubKey.IsValid()) { | ||||
strErr = "Error reading wallet database: CPubKey corrupt"; | strErr = "Error reading wallet database: CPubKey corrupt"; | ||||
return false; | return false; | ||||
} | } | ||||
std::vector<uint8_t> vchPrivKey; | std::vector<uint8_t> vchPrivKey; | ||||
ssValue >> vchPrivKey; | ssValue >> vchPrivKey; | ||||
wss.nCKeys++; | wss.nCKeys++; | ||||
if (!pwallet->GetLegacyScriptPubKeyMan()->LoadCryptedKey( | if (!pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadCryptedKey( | ||||
vchPubKey, vchPrivKey)) { | vchPubKey, vchPrivKey)) { | ||||
strErr = "Error reading wallet database: " | strErr = "Error reading wallet database: " | ||||
"LegacyScriptPubKeyMan::LoadCryptedKey failed"; | "LegacyScriptPubKeyMan::LoadCryptedKey failed"; | ||||
return false; | return false; | ||||
} | } | ||||
wss.fIsEncrypted = true; | wss.fIsEncrypted = true; | ||||
} else if (strType == DBKeys::KEYMETA) { | } else if (strType == DBKeys::KEYMETA) { | ||||
CPubKey vchPubKey; | CPubKey vchPubKey; | ||||
ssKey >> vchPubKey; | ssKey >> vchPubKey; | ||||
CKeyMetadata keyMeta; | CKeyMetadata keyMeta; | ||||
ssValue >> keyMeta; | ssValue >> keyMeta; | ||||
wss.nKeyMeta++; | wss.nKeyMeta++; | ||||
pwallet->GetLegacyScriptPubKeyMan()->LoadKeyMetadata( | pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadKeyMetadata( | ||||
vchPubKey.GetID(), keyMeta); | vchPubKey.GetID(), keyMeta); | ||||
} else if (strType == DBKeys::WATCHMETA) { | } else if (strType == DBKeys::WATCHMETA) { | ||||
CScript script; | CScript script; | ||||
ssKey >> script; | ssKey >> script; | ||||
CKeyMetadata keyMeta; | CKeyMetadata keyMeta; | ||||
ssValue >> keyMeta; | ssValue >> keyMeta; | ||||
wss.nKeyMeta++; | wss.nKeyMeta++; | ||||
pwallet->GetLegacyScriptPubKeyMan()->LoadScriptMetadata( | pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadScriptMetadata( | ||||
CScriptID(script), keyMeta); | CScriptID(script), keyMeta); | ||||
} else if (strType == DBKeys::DEFAULTKEY) { | } else if (strType == DBKeys::DEFAULTKEY) { | ||||
// We don't want or need the default key, but if there is one set, | // We don't want or need the default key, but if there is one set, | ||||
// we want to make sure that it is valid so that we can detect | // we want to make sure that it is valid so that we can detect | ||||
// corruption | // corruption | ||||
CPubKey vchPubKey; | CPubKey vchPubKey; | ||||
ssValue >> vchPubKey; | ssValue >> vchPubKey; | ||||
if (!vchPubKey.IsValid()) { | if (!vchPubKey.IsValid()) { | ||||
strErr = "Error reading wallet database: Default Key corrupt"; | strErr = "Error reading wallet database: Default Key corrupt"; | ||||
return false; | return false; | ||||
} | } | ||||
} else if (strType == DBKeys::POOL) { | } else if (strType == DBKeys::POOL) { | ||||
int64_t nIndex; | int64_t nIndex; | ||||
ssKey >> nIndex; | ssKey >> nIndex; | ||||
CKeyPool keypool; | CKeyPool keypool; | ||||
ssValue >> keypool; | ssValue >> keypool; | ||||
pwallet->GetLegacyScriptPubKeyMan()->LoadKeyPool(nIndex, keypool); | pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadKeyPool(nIndex, | ||||
keypool); | |||||
} else if (strType == DBKeys::CSCRIPT) { | } else if (strType == DBKeys::CSCRIPT) { | ||||
uint160 hash; | uint160 hash; | ||||
ssKey >> hash; | ssKey >> hash; | ||||
CScript script; | CScript script; | ||||
ssValue >> script; | ssValue >> script; | ||||
if (!pwallet->GetLegacyScriptPubKeyMan()->LoadCScript(script)) { | if (!pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadCScript( | ||||
script)) { | |||||
strErr = "Error reading wallet database: " | strErr = "Error reading wallet database: " | ||||
"LegacyScriptPubKeyMan::LoadCScript failed"; | "LegacyScriptPubKeyMan::LoadCScript failed"; | ||||
return false; | return false; | ||||
} | } | ||||
} else if (strType == DBKeys::ORDERPOSNEXT) { | } else if (strType == DBKeys::ORDERPOSNEXT) { | ||||
ssValue >> pwallet->nOrderPosNext; | ssValue >> pwallet->nOrderPosNext; | ||||
} else if (strType == DBKeys::DESTDATA) { | } else if (strType == DBKeys::DESTDATA) { | ||||
std::string strAddress, strKey, strValue; | std::string strAddress, strKey, strValue; | ||||
ssKey >> strAddress; | ssKey >> strAddress; | ||||
ssKey >> strKey; | ssKey >> strKey; | ||||
ssValue >> strValue; | ssValue >> strValue; | ||||
pwallet->LoadDestData( | pwallet->LoadDestData( | ||||
DecodeDestination(strAddress, pwallet->chainParams), strKey, | DecodeDestination(strAddress, pwallet->chainParams), strKey, | ||||
strValue); | strValue); | ||||
} else if (strType == DBKeys::HDCHAIN) { | } else if (strType == DBKeys::HDCHAIN) { | ||||
CHDChain chain; | CHDChain chain; | ||||
ssValue >> chain; | ssValue >> chain; | ||||
pwallet->GetLegacyScriptPubKeyMan()->SetHDChain(chain, true); | pwallet->GetOrCreateLegacyScriptPubKeyMan()->SetHDChain(chain, | ||||
true); | |||||
} 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; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | DBErrors WalletBatch::LoadWallet(CWallet *pwallet) { | ||||
pwallet->WalletLogPrintf("Keys: %u plaintext, %u encrypted, %u w/ " | pwallet->WalletLogPrintf("Keys: %u plaintext, %u encrypted, %u w/ " | ||||
"metadata, %u total. Unknown wallet records: %u\n", | "metadata, %u total. Unknown wallet records: %u\n", | ||||
wss.nKeys, wss.nCKeys, wss.nKeyMeta, | wss.nKeys, wss.nCKeys, wss.nKeyMeta, | ||||
wss.nKeys + wss.nCKeys, wss.m_unknown_records); | wss.nKeys + wss.nCKeys, wss.m_unknown_records); | ||||
// nTimeFirstKey is only reliable if all keys have metadata | // nTimeFirstKey is only reliable if all keys have metadata | ||||
if ((wss.nKeys + wss.nCKeys + wss.nWatchKeys) != wss.nKeyMeta) { | if ((wss.nKeys + wss.nCKeys + wss.nWatchKeys) != wss.nKeyMeta) { | ||||
auto spk_man = pwallet->GetLegacyScriptPubKeyMan(); | auto spk_man = pwallet->GetOrCreateLegacyScriptPubKeyMan(); | ||||
if (spk_man) { | if (spk_man) { | ||||
LOCK(spk_man->cs_KeyStore); | LOCK(spk_man->cs_KeyStore); | ||||
spk_man->UpdateTimeFirstKey(1); | spk_man->UpdateTimeFirstKey(1); | ||||
} | } | ||||
} | } | ||||
for (const TxId &txid : wss.vWalletUpgrade) { | for (const TxId &txid : wss.vWalletUpgrade) { | ||||
WriteTx(pwallet->mapWallet.at(txid)); | WriteTx(pwallet->mapWallet.at(txid)); | ||||
▲ Show 20 Lines • Show All 272 Lines • Show Last 20 Lines |