Changeset View
Changeset View
Standalone View
Standalone View
src/dbwrapper.h
Show First 20 Lines • Show All 225 Lines • ▼ Show 20 Lines | template <typename K, typename V> bool Read(const K &key, V &value) const { | ||||
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | ||||
ssKey << key; | ssKey << key; | ||||
leveldb::Slice slKey(ssKey.data(), ssKey.size()); | leveldb::Slice slKey(ssKey.data(), ssKey.size()); | ||||
std::string strValue; | std::string strValue; | ||||
leveldb::Status status = pdb->Get(readoptions, slKey, &strValue); | leveldb::Status status = pdb->Get(readoptions, slKey, &strValue); | ||||
if (!status.ok()) { | if (!status.ok()) { | ||||
if (status.IsNotFound()) return false; | if (status.IsNotFound()) return false; | ||||
LogPrintf("LevelDB read failure: %s\n", status.ToString()); | LogPrint(BCLog::LEVELDB, "LevelDB read failure: %s\n", | ||||
status.ToString()); | |||||
dbwrapper_private::HandleError(status); | dbwrapper_private::HandleError(status); | ||||
} | } | ||||
try { | try { | ||||
CDataStream ssValue(strValue.data(), | CDataStream ssValue(strValue.data(), | ||||
strValue.data() + strValue.size(), SER_DISK, | strValue.data() + strValue.size(), SER_DISK, | ||||
CLIENT_VERSION); | CLIENT_VERSION); | ||||
ssValue.Xor(obfuscate_key); | ssValue.Xor(obfuscate_key); | ||||
ssValue >> value; | ssValue >> value; | ||||
Show All 15 Lines | template <typename K> bool Exists(const K &key) const { | ||||
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); | ||||
ssKey << key; | ssKey << key; | ||||
leveldb::Slice slKey(ssKey.data(), ssKey.size()); | leveldb::Slice slKey(ssKey.data(), ssKey.size()); | ||||
std::string strValue; | std::string strValue; | ||||
leveldb::Status status = pdb->Get(readoptions, slKey, &strValue); | leveldb::Status status = pdb->Get(readoptions, slKey, &strValue); | ||||
if (!status.ok()) { | if (!status.ok()) { | ||||
if (status.IsNotFound()) return false; | if (status.IsNotFound()) return false; | ||||
LogPrintf("LevelDB read failure: %s\n", status.ToString()); | LogPrint(BCLog::LEVELDB, "LevelDB read failure: %s\n", | ||||
status.ToString()); | |||||
dbwrapper_private::HandleError(status); | dbwrapper_private::HandleError(status); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
template <typename K> bool Erase(const K &key, bool fSync = false) { | template <typename K> bool Erase(const K &key, bool fSync = false) { | ||||
CDBBatch batch(*this); | CDBBatch batch(*this); | ||||
batch.Erase(key); | batch.Erase(key); | ||||
▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines |