Add ReadDataStream to CDBWrapper to allow manual deserialization

This commit is contained in:
Alexander Block 2019-01-18 11:54:29 +01:00
parent b6346a2f68
commit 56ee83a766

View File

@ -225,8 +225,8 @@ public:
CDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false, bool obfuscate = false); CDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false, bool obfuscate = false);
~CDBWrapper(); ~CDBWrapper();
template <typename K, typename V> template <typename K>
bool Read(const K& key, V& value) const bool ReadDataStream(const K& key, CDataStream& ssValue) const
{ {
CDataStream ssKey(SER_DISK, CLIENT_VERSION); CDataStream ssKey(SER_DISK, CLIENT_VERSION);
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
@ -241,9 +241,21 @@ public:
LogPrintf("LevelDB read failure: %s\n", status.ToString()); LogPrintf("LevelDB read failure: %s\n", status.ToString());
dbwrapper_private::HandleError(status); dbwrapper_private::HandleError(status);
} }
CDataStream ssValueTmp(strValue.data(), strValue.data() + strValue.size(), SER_DISK, CLIENT_VERSION);
ssValueTmp.Xor(obfuscate_key);
ssValue = std::move(ssValueTmp);
return true;
}
template <typename K, typename V>
bool Read(const K& key, V& value) const
{
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
if (!ReadDataStream(key, ssValue)) {
return false;
}
try { try {
CDataStream ssValue(strValue.data(), strValue.data() + strValue.size(), SER_DISK, CLIENT_VERSION);
ssValue.Xor(obfuscate_key);
ssValue >> value; ssValue >> value;
} catch (const std::exception&) { } catch (const std::exception&) {
return false; return false;