aboutsummaryrefslogtreecommitdiff
path: root/src/dbwrapper.h
diff options
context:
space:
mode:
authorTheCharlatan <seb.kung@gmail.com>2023-07-14 11:46:13 +0200
committerTheCharlatan <seb.kung@gmail.com>2023-08-05 10:42:55 +0200
commit84058e0eed9c05bc30984b39131e88ad1425628f (patch)
tree67fee8661ebfc5369a09b78e17640fa499389b42 /src/dbwrapper.h
parente4af2408f2ac59788567b6fc8cb3a68fc43da9fe (diff)
refactor: Split dbwrapper CDBWrapper::Read implementation
Keep the generic serialization in the header, while moving leveldb-specifics to the implementation file. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
Diffstat (limited to 'src/dbwrapper.h')
-rw-r--r--src/dbwrapper.h16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/dbwrapper.h b/src/dbwrapper.h
index 9bcb79c169..7e5ffe1062 100644
--- a/src/dbwrapper.h
+++ b/src/dbwrapper.h
@@ -235,6 +235,8 @@ private:
//! whether or not the database resides in memory
bool m_is_memory;
+ std::optional<std::string> ReadImpl(Span<const std::byte> ssKey) const;
+
public:
CDBWrapper(const DBParams& params);
~CDBWrapper();
@@ -248,18 +250,12 @@ public:
DataStream ssKey{};
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
ssKey << key;
- leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
-
- std::string strValue;
- leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);
- if (!status.ok()) {
- if (status.IsNotFound())
- return false;
- LogPrintf("LevelDB read failure: %s\n", status.ToString());
- dbwrapper_private::HandleError(status);
+ std::optional<std::string> strValue{ReadImpl(ssKey)};
+ if (!strValue) {
+ return false;
}
try {
- CDataStream ssValue{MakeByteSpan(strValue), SER_DISK, CLIENT_VERSION};
+ CDataStream ssValue{MakeByteSpan(*strValue), SER_DISK, CLIENT_VERSION};
ssValue.Xor(obfuscate_key);
ssValue >> value;
} catch (const std::exception&) {