Skip to content

Commit dede0ee

Browse files
committed
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.
1 parent a5c2eb5 commit dede0ee

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/dbwrapper.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,21 @@ std::optional<std::string> CDBWrapper::ReadImpl(Span<const std::byte> ssKey) con
313313
return strValue;
314314
}
315315

316+
bool CDBWrapper::ExistsImpl(Span<const std::byte> ssKey) const
317+
{
318+
leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
319+
320+
std::string strValue;
321+
leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);
322+
if (!status.ok()) {
323+
if (status.IsNotFound())
324+
return false;
325+
LogPrintf("LevelDB read failure: %s\n", status.ToString());
326+
dbwrapper_private::HandleError(status);
327+
}
328+
return true;
329+
}
330+
316331
bool CDBWrapper::IsEmpty()
317332
{
318333
std::unique_ptr<CDBIterator> it(NewIterator());

src/dbwrapper.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#define BITCOIN_DBWRAPPER_H
77

88
#include <clientversion.h>
9-
#include <logging.h>
109
#include <serialize.h>
1110
#include <span.h>
1211
#include <streams.h>
@@ -18,14 +17,14 @@
1817
#include <leveldb/db.h>
1918
#include <leveldb/options.h>
2019
#include <leveldb/slice.h>
21-
#include <leveldb/status.h>
2220
#include <memory>
2321
#include <optional>
2422
#include <stdexcept>
2523
#include <string>
2624
#include <vector>
2725
namespace leveldb {
2826
class Env;
27+
class Status;
2928
}
3029

3130
static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64;
@@ -236,6 +235,7 @@ class CDBWrapper
236235
bool m_is_memory;
237236

238237
std::optional<std::string> ReadImpl(Span<const std::byte> ssKey) const;
238+
bool ExistsImpl(Span<const std::byte> ssKey) const;
239239

240240
public:
241241
CDBWrapper(const DBParams& params);
@@ -286,17 +286,7 @@ class CDBWrapper
286286
DataStream ssKey{};
287287
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
288288
ssKey << key;
289-
leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
290-
291-
std::string strValue;
292-
leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);
293-
if (!status.ok()) {
294-
if (status.IsNotFound())
295-
return false;
296-
LogPrintf("LevelDB read failure: %s\n", status.ToString());
297-
dbwrapper_private::HandleError(status);
298-
}
299-
return true;
289+
return ExistsImpl(ssKey);
300290
}
301291

302292
template <typename K>

0 commit comments

Comments
 (0)