Skip to content

Commit

Permalink
Add ReadDataStream to CDBWrapper to allow manual deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Jan 18, 2019
1 parent b6346a2 commit 56ee83a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/dbwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ class CDBWrapper
CDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false, bool obfuscate = false);
~CDBWrapper();

template <typename K, typename V>
bool Read(const K& key, V& value) const
template <typename K>
bool ReadDataStream(const K& key, CDataStream& ssValue) const
{
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
Expand All @@ -241,9 +241,21 @@ class CDBWrapper
LogPrintf("LevelDB read failure: %s\n", status.ToString());
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 {
CDataStream ssValue(strValue.data(), strValue.data() + strValue.size(), SER_DISK, CLIENT_VERSION);
ssValue.Xor(obfuscate_key);
ssValue >> value;
} catch (const std::exception&) {
return false;
Expand Down

0 comments on commit 56ee83a

Please sign in to comment.