diff options
author | TheCharlatan <seb.kung@gmail.com> | 2023-07-14 11:46:13 +0200 |
---|---|---|
committer | TheCharlatan <seb.kung@gmail.com> | 2023-08-05 10:42:55 +0200 |
commit | 84058e0eed9c05bc30984b39131e88ad1425628f (patch) | |
tree | 67fee8661ebfc5369a09b78e17640fa499389b42 /src/dbwrapper.cpp | |
parent | e4af2408f2ac59788567b6fc8cb3a68fc43da9fe (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.cpp')
-rw-r--r-- | src/dbwrapper.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index c0a2895a58..830c04c4cf 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -10,7 +10,6 @@ #include <serialize.h> #include <span.h> #include <streams.h> -#include <tinyformat.h> #include <util/fs.h> #include <util/fs_helpers.h> #include <util/strencodings.h> @@ -300,6 +299,20 @@ std::vector<unsigned char> CDBWrapper::CreateObfuscateKey() const return ret; } +std::optional<std::string> CDBWrapper::ReadImpl(Span<const std::byte> ssKey) const +{ + 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 std::nullopt; + LogPrintf("LevelDB read failure: %s\n", status.ToString()); + dbwrapper_private::HandleError(status); + } + return strValue; +} + bool CDBWrapper::IsEmpty() { std::unique_ptr<CDBIterator> it(NewIterator()); |