diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index 830c04c4cf5..88eb7e4aace 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -313,6 +313,21 @@ std::optional CDBWrapper::ReadImpl(Span ssKey) con return strValue; } +bool CDBWrapper::ExistsImpl(Span 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 it(NewIterator()); diff --git a/src/dbwrapper.h b/src/dbwrapper.h index 7e5ffe10620..5b9ff6ea91c 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -6,7 +6,6 @@ #define BITCOIN_DBWRAPPER_H #include -#include #include #include #include @@ -18,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -26,6 +24,7 @@ #include namespace leveldb { class Env; +class Status; } static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64; @@ -236,6 +235,7 @@ private: bool m_is_memory; std::optional ReadImpl(Span ssKey) const; + bool ExistsImpl(Span ssKey) const; public: CDBWrapper(const DBParams& params); @@ -286,17 +286,7 @@ 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); - } - return true; + return ExistsImpl(ssKey); } template