5#ifndef BITCOIN_DBWRAPPER_H
6#define BITCOIN_DBWRAPPER_H
68bool DestroyDB(
const std::string& path_str);
85 void EraseImpl(std::span<const std::byte> key);
95 template <
typename K,
typename V>
96 void Write(
const K& key,
const V& value)
107 template <
typename K>
128 void SeekImpl(std::span<const std::byte> key);
129 std::span<const std::byte>
GetKeyImpl()
const;
145 template<
typename K>
void Seek(
const K& key) {
158 }
catch (
const std::exception&) {
169 }
catch (
const std::exception&) {
200 std::optional<std::string>
ReadImpl(std::span<const std::byte> key)
const;
201 bool ExistsImpl(std::span<const std::byte> key)
const;
202 size_t EstimateSizeImpl(std::span<const std::byte> key1, std::span<const std::byte> key2)
const;
212 template <
typename K,
typename V>
213 bool Read(
const K& key, V& value)
const
218 std::optional<std::string> strValue{
ReadImpl(ssKey)};
226 }
catch (
const std::exception&) {
232 template <
typename K,
typename V>
233 bool Write(
const K& key,
const V& value,
bool fSync =
false)
236 batch.
Write(key, value);
248 template <
typename K>
257 template <
typename K>
258 bool Erase(
const K& key,
bool fSync =
false)
#define Assert(val)
Identity function.
Batch of changes queued to be written to a CDBWrapper.
void WriteImpl(std::span< const std::byte > key, DataStream &ssValue)
const std::unique_ptr< WriteBatchImpl > m_impl_batch
void Write(const K &key, const V &value)
void EraseImpl(std::span< const std::byte > key)
CDBBatch(const CDBWrapper &_parent)
size_t ApproximateSize() const
const CDBWrapper & parent
CDBIterator(const CDBWrapper &_parent, std::unique_ptr< IteratorImpl > _piter)
const std::unique_ptr< IteratorImpl > m_impl_iter
void SeekImpl(std::span< const std::byte > key)
std::span< const std::byte > GetKeyImpl() const
const CDBWrapper & parent
std::span< const std::byte > GetValueImpl() const
CDBWrapper(const CDBWrapper &)=delete
std::optional< std::string > ReadImpl(std::span< const std::byte > key) const
size_t EstimateSizeImpl(std::span< const std::byte > key1, std::span< const std::byte > key2) const
size_t DynamicMemoryUsage() const
bool WriteBatch(CDBBatch &batch, bool fSync=false)
bool Read(const K &key, V &value) const
CDBIterator * NewIterator()
std::string m_name
the name of this database
bool Erase(const K &key, bool fSync=false)
bool Write(const K &key, const V &value, bool fSync=false)
bool Exists(const K &key) const
CDBWrapper(const DBParams ¶ms)
const fs::path m_path
path to filesystem storage
bool ExistsImpl(std::span< const std::byte > key) const
Obfuscation m_obfuscation
optional XOR-obfuscation of the database
std::unique_ptr< LevelDBContext > m_db_context
holds all leveldb-specific fields of this class
CDBWrapper & operator=(const CDBWrapper &)=delete
bool m_is_memory
whether or not the database resides in memory
static const std::string OBFUSCATION_KEY
obfuscation key storage key, null-prefixed to avoid collisions
auto & DBContext() const LIFETIMEBOUND
bool IsEmpty()
Return true if the database managed by this class contains no entries.
std::optional< fs::path > StoragePath()
size_t EstimateSize(const K &key_begin, const K &key_end) const
Double ended buffer combining vector and stream-like interfaces.
void reserve(size_type n)
dbwrapper_error(const std::string &msg)
static const size_t DBWRAPPER_PREALLOC_KEY_SIZE
bool DestroyDB(const std::string &path_str)
static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE
static const size_t DBWRAPPER_MAX_FILE_SIZE
These should be considered an implementation detail of the specific database.
const Obfuscation & GetObfuscation(const CDBWrapper &w)
Work around circular dependency, as well as for testing in dbwrapper_tests.
auto MakeByteSpan(const V &v) noexcept
User-controlled performance and debug options.
bool force_compact
Compact database on startup.
Application-specific storage settings.
DBOptions options
Passed-through options.
bool obfuscate
If true, store data obfuscated via simple XOR.
bool wipe_data
If true, remove all existing data.
size_t cache_bytes
Configures various leveldb cache settings.
fs::path path
Location in the filesystem where leveldb data will be stored.
bool memory_only
If true, use leveldb's memory environment.