Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/walletdb.cpp
Show First 20 Lines • Show All 769 Lines • ▼ Show 20 Lines | try { | ||||
if (m_batch.Read(DBKeys::MINVERSION, nMinVersion)) { | if (m_batch.Read(DBKeys::MINVERSION, nMinVersion)) { | ||||
if (nMinVersion > FEATURE_LATEST) { | if (nMinVersion > FEATURE_LATEST) { | ||||
return DBErrors::TOO_NEW; | return DBErrors::TOO_NEW; | ||||
} | } | ||||
pwallet->LoadMinVersion(nMinVersion); | pwallet->LoadMinVersion(nMinVersion); | ||||
} | } | ||||
// Get cursor | // Get cursor | ||||
Dbc *pcursor = m_batch.GetCursor(); | if (!m_batch.StartCursor()) { | ||||
if (!pcursor) { | |||||
pwallet->WalletLogPrintf("Error getting wallet database cursor\n"); | pwallet->WalletLogPrintf("Error getting wallet database cursor\n"); | ||||
return DBErrors::CORRUPT; | return DBErrors::CORRUPT; | ||||
} | } | ||||
while (true) { | while (true) { | ||||
// Read next record | // Read next record | ||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION); | CDataStream ssKey(SER_DISK, CLIENT_VERSION); | ||||
CDataStream ssValue(SER_DISK, CLIENT_VERSION); | CDataStream ssValue(SER_DISK, CLIENT_VERSION); | ||||
int ret = m_batch.ReadAtCursor(pcursor, ssKey, ssValue); | bool complete; | ||||
if (ret == DB_NOTFOUND) { | bool ret = m_batch.ReadAtCursor(ssKey, ssValue, complete); | ||||
if (complete) { | |||||
break; | break; | ||||
} | } | ||||
if (!ret) { | |||||
if (ret != 0) { | m_batch.CloseCursor(); | ||||
pwallet->WalletLogPrintf( | pwallet->WalletLogPrintf( | ||||
"Error reading next record from wallet database\n"); | "Error reading next record from wallet database\n"); | ||||
return DBErrors::CORRUPT; | return DBErrors::CORRUPT; | ||||
} | } | ||||
// Try to be tolerant of single corrupt records: | // Try to be tolerant of single corrupt records: | ||||
std::string strType, strErr; | std::string strType, strErr; | ||||
if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr)) { | if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr)) { | ||||
Show All 15 Lines | try { | ||||
gArgs.SoftSetBoolArg("-rescan", true); | gArgs.SoftSetBoolArg("-rescan", true); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (!strErr.empty()) { | if (!strErr.empty()) { | ||||
pwallet->WalletLogPrintf("%s\n", strErr); | pwallet->WalletLogPrintf("%s\n", strErr); | ||||
} | } | ||||
} | } | ||||
pcursor->close(); | |||||
} catch (...) { | } catch (...) { | ||||
result = DBErrors::CORRUPT; | result = DBErrors::CORRUPT; | ||||
} | } | ||||
m_batch.CloseCursor(); | |||||
// Set the active ScriptPubKeyMans | // Set the active ScriptPubKeyMans | ||||
for (auto spk_man_pair : wss.m_active_external_spks) { | for (auto spk_man_pair : wss.m_active_external_spks) { | ||||
pwallet->LoadActiveScriptPubKeyMan( | pwallet->LoadActiveScriptPubKeyMan( | ||||
spk_man_pair.second, spk_man_pair.first, /* internal */ false); | spk_man_pair.second, spk_man_pair.first, /* internal */ false); | ||||
} | } | ||||
for (auto spk_man_pair : wss.m_active_internal_spks) { | for (auto spk_man_pair : wss.m_active_internal_spks) { | ||||
pwallet->LoadActiveScriptPubKeyMan( | pwallet->LoadActiveScriptPubKeyMan( | ||||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | try { | ||||
int nMinVersion = 0; | int nMinVersion = 0; | ||||
if (m_batch.Read(DBKeys::MINVERSION, nMinVersion)) { | if (m_batch.Read(DBKeys::MINVERSION, nMinVersion)) { | ||||
if (nMinVersion > FEATURE_LATEST) { | if (nMinVersion > FEATURE_LATEST) { | ||||
return DBErrors::TOO_NEW; | return DBErrors::TOO_NEW; | ||||
} | } | ||||
} | } | ||||
// Get cursor | // Get cursor | ||||
Dbc *pcursor = m_batch.GetCursor(); | if (!m_batch.StartCursor()) { | ||||
if (!pcursor) { | |||||
LogPrintf("Error getting wallet database cursor\n"); | LogPrintf("Error getting wallet database cursor\n"); | ||||
return DBErrors::CORRUPT; | return DBErrors::CORRUPT; | ||||
} | } | ||||
while (true) { | while (true) { | ||||
// Read next record | // Read next record | ||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION); | CDataStream ssKey(SER_DISK, CLIENT_VERSION); | ||||
CDataStream ssValue(SER_DISK, CLIENT_VERSION); | CDataStream ssValue(SER_DISK, CLIENT_VERSION); | ||||
int ret = m_batch.ReadAtCursor(pcursor, ssKey, ssValue); | bool complete; | ||||
if (ret == DB_NOTFOUND) { | bool ret = m_batch.ReadAtCursor(ssKey, ssValue, complete); | ||||
if (complete) { | |||||
break; | break; | ||||
} | } | ||||
if (ret != 0) { | if (!ret) { | ||||
m_batch.CloseCursor(); | |||||
LogPrintf("Error reading next record from wallet database\n"); | LogPrintf("Error reading next record from wallet database\n"); | ||||
return DBErrors::CORRUPT; | return DBErrors::CORRUPT; | ||||
} | } | ||||
std::string strType; | std::string strType; | ||||
ssKey >> strType; | ssKey >> strType; | ||||
if (strType == DBKeys::TX) { | if (strType == DBKeys::TX) { | ||||
TxId txid; | TxId txid; | ||||
ssKey >> txid; | ssKey >> txid; | ||||
txIds.push_back(txid); | txIds.push_back(txid); | ||||
vWtx.emplace_back(nullptr /* wallet */, nullptr /* tx */); | vWtx.emplace_back(nullptr /* wallet */, nullptr /* tx */); | ||||
ssValue >> vWtx.back(); | ssValue >> vWtx.back(); | ||||
} | } | ||||
} | } | ||||
pcursor->close(); | |||||
} catch (...) { | } catch (...) { | ||||
result = DBErrors::CORRUPT; | result = DBErrors::CORRUPT; | ||||
} | } | ||||
m_batch.CloseCursor(); | |||||
return result; | return result; | ||||
} | } | ||||
DBErrors WalletBatch::ZapSelectTx(std::vector<TxId> &txIdsIn, | DBErrors WalletBatch::ZapSelectTx(std::vector<TxId> &txIdsIn, | ||||
std::vector<TxId> &txIdsOut) { | std::vector<TxId> &txIdsOut) { | ||||
// Build list of wallet TXs and hashes. | // Build list of wallet TXs and hashes. | ||||
std::vector<TxId> txIds; | std::vector<TxId> txIds; | ||||
▲ Show 20 Lines • Show All 149 Lines • Show Last 20 Lines |