5 #ifndef BITCOIN_DBWRAPPER_H 6 #define BITCOIN_DBWRAPPER_H 69 bool DestroyDB(
const std::string& path_str);
98 template <
typename K,
typename V>
99 void Write(
const K& key,
const V& value)
110 template <
typename K>
148 template<
typename K>
void Seek(
const K& key) {
161 }
catch (
const std::exception&) {
172 }
catch (
const std::exception&) {
220 template <
typename K,
typename V>
221 bool Read(
const K& key, V& value)
const 226 std::optional<std::string> strValue{
ReadImpl(ssKey)};
234 }
catch (
const std::exception&) {
240 template <
typename K,
typename V>
241 bool Write(
const K& key,
const V& value,
bool fSync =
false)
244 batch.
Write(key, value);
256 template <
typename K>
265 template <
typename K>
266 bool Erase(
const K& key,
bool fSync =
false)
297 #endif // BITCOIN_DBWRAPPER_H bool Exists(const K &key) const
dbwrapper_error(const std::string &msg)
fs::path path
Location in the filesystem where leveldb data will be stored.
These should be considered an implementation detail of the specific database.
void reserve(size_type n)
Batch of changes queued to be written to a CDBWrapper.
auto & DBContext() const LIFETIMEBOUND
Span< const std::byte > GetValueImpl() const
static const size_t DBWRAPPER_PREALLOC_KEY_SIZE
Span< const std::byte > GetKeyImpl() const
bool DestroyDB(const std::string &path_str)
const std::unique_ptr< IteratorImpl > m_impl_iter
DBOptions options
Passed-through options.
User-controlled performance and debug options.
CDBIterator(const CDBWrapper &_parent, std::unique_ptr< IteratorImpl > _piter)
std::vector< unsigned char > CreateObfuscateKey() const
Returns a string (consisting of 8 random bytes) suitable for use as an obfuscating XOR key...
std::optional< fs::path > StoragePath()
size_t EstimateSizeImpl(Span< const std::byte > key1, Span< const std::byte > key2) const
size_t DynamicMemoryUsage() const
const CDBWrapper & parent
const CDBWrapper & parent
CDBWrapper & operator=(const CDBWrapper &)=delete
bool Erase(const K &key, bool fSync=false)
CDBWrapper(const DBParams ¶ms)
Double ended buffer combining vector and stream-like interfaces.
CDBIterator * NewIterator()
void Write(const K &key, const V &value)
size_t SizeEstimate() const
void EraseImpl(Span< const std::byte > key)
bool m_is_memory
whether or not the database resides in memory
bool wipe_data
If true, remove all existing data.
bool IsEmpty()
Return true if the database managed by this class contains no entries.
bool Read(const K &key, V &value) const
const fs::path m_path
path to filesystem storage
bool force_compact
Compact database on startup.
bool obfuscate
If true, store data obfuscated via simple XOR.
const std::vector< unsigned char > & GetObfuscateKey(const CDBWrapper &w)
Work around circular dependency, as well as for testing in dbwrapper_tests.
static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE
static const unsigned int OBFUSCATE_KEY_NUM_BYTES
the length of the obfuscate key in number of bytes
bool Write(const K &key, const V &value, bool fSync=false)
void SeekImpl(Span< const std::byte > key)
std::string m_name
the name of this database
std::unique_ptr< LevelDBContext > m_db_context
holds all leveldb-specific fields of this class
static const std::string OBFUSCATE_KEY_KEY
the key under which the obfuscation key is stored
Span< const std::byte > MakeByteSpan(V &&v) noexcept
void WriteImpl(Span< const std::byte > key, DataStream &ssValue)
Application-specific storage settings.
CDBBatch(const CDBWrapper &_parent)
bool WriteBatch(CDBBatch &batch, bool fSync=false)
bool ExistsImpl(Span< const std::byte > key) const
size_t cache_bytes
Configures various leveldb cache settings.
const std::unique_ptr< WriteBatchImpl > m_impl_batch
std::vector< unsigned char > obfuscate_key
a key used for optional XOR-obfuscation of the database
size_t EstimateSize(const K &key_begin, const K &key_end) const
std::optional< std::string > ReadImpl(Span< const std::byte > key) const
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
bool memory_only
If true, use leveldb's memory environment.
#define Assert(val)
Identity function.