aboutsummaryrefslogtreecommitdiff
path: root/src/dbwrapper.cpp
diff options
context:
space:
mode:
authorTheCharlatan <seb.kung@gmail.com>2023-07-14 11:53:24 +0200
committerTheCharlatan <seb.kung@gmail.com>2023-08-05 10:42:58 +0200
commitdede0eef7adb7413f62f5abd68cac8e01635ba4a (patch)
treea4c26e3a77fa83561881b8d10325ad3f41c28d95 /src/dbwrapper.cpp
parenta5c2eb57484314b04ec94523d14e0ef0c6c46d4f (diff)
downloadbitcoin-dede0eef7adb7413f62f5abd68cac8e01635ba4a.tar.xz
refactor: Split dbwrapper CDBWrapper::Exists 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.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp
index 830c04c4cf..88eb7e4aac 100644
--- a/src/dbwrapper.cpp
+++ b/src/dbwrapper.cpp
@@ -313,6 +313,21 @@ std::optional<std::string> CDBWrapper::ReadImpl(Span<const std::byte> ssKey) con
return strValue;
}
+bool CDBWrapper::ExistsImpl(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 false;
+ LogPrintf("LevelDB read failure: %s\n", status.ToString());
+ dbwrapper_private::HandleError(status);
+ }
+ return true;
+}
+
bool CDBWrapper::IsEmpty()
{
std::unique_ptr<CDBIterator> it(NewIterator());