5 #ifndef BITCOIN_DBWRAPPER_H 6 #define BITCOIN_DBWRAPPER_H 15 #include <boost/filesystem/path.hpp> 17 #include <leveldb/db.h> 18 #include <leveldb/write_batch.h> 43 template <
typename K,
typename V>
49 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
52 ssValue.reserve(ssValue.GetSerializeSize(value));
55 leveldb::Slice slValue(&ssValue[0], ssValue.size());
57 batch.Put(slKey, slValue);
66 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
92 template<
typename K>
void Seek(
const K&
key) {
96 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
103 leveldb::Slice slKey =
piter->key();
107 }
catch (
const std::exception&) {
114 return piter->key().size();
118 leveldb::Slice slValue =
piter->value();
123 }
catch (
const std::exception&) {
130 return piter->value().size();
179 CDBWrapper(
const boost::filesystem::path& path,
size_t nCacheSize,
bool fMemory =
false,
bool fWipe =
false,
bool obfuscate =
false);
182 template <
typename K,
typename V>
188 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
190 std::string strValue;
193 if (status.IsNotFound())
195 LogPrintf(
"LevelDB read failure: %s\n", status.ToString());
202 }
catch (
const std::exception&) {
208 template <
typename K,
typename V>
216 template <
typename K>
222 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
224 std::string strValue;
227 if (status.IsNotFound())
229 LogPrintf(
"LevelDB read failure: %s\n", status.ToString());
235 template <
typename K>
279 #endif // BITCOIN_DBWRAPPER_H dbwrapper_error(const std::string &msg)
leveldb::Env * penv
custom environment this database is using (may be NULL in case of default environment) ...
static const unsigned int OBFUSCATE_KEY_NUM_BYTES
the length of the obfuscate key in number of bytes
CDBIterator(leveldb::Iterator *piterIn, const std::vector< unsigned char > *obfuscate_key)
void HandleError(const leveldb::Status &status)
CDBBatch(const std::vector< unsigned char > *obfuscate_key)
const std::vector< unsigned char > * obfuscate_key
static const std::string OBFUSCATE_KEY_KEY
the key under which the obfuscation key is stored
leveldb::WriteBatch batch
void Xor(const std::vector< unsigned char > &key)
const std::vector< unsigned char > * obfuscate_key
leveldb::DB * pdb
the database itself
bool Write(const K &key, const V &value, bool fSync=false)
unsigned int GetSerializeSize(const T &obj)
void reserve(size_type n)
leveldb::Options options
database options used
std::string GetObfuscateKeyHex() const
CDBWrapper(const boost::filesystem::path &path, size_t nCacheSize, bool fMemory=false, bool fWipe=false, bool obfuscate=false)
bool WriteBatch(CDBBatch &batch, bool fSync=false)
void Write(const K &key, const V &value)
leveldb::WriteOptions syncoptions
options used when sync writing to the database
leveldb::WriteOptions writeoptions
options used when writing to the database
leveldb::ReadOptions readoptions
options used when reading from the database
unsigned int GetValueSize()
leveldb::ReadOptions iteroptions
options used when iterating over values of the database
bool Exists(const K &key) const
CDBIterator * NewIterator()
bool Erase(const K &key, bool fSync=false)
const std::vector< unsigned char > & GetObfuscateKey() const
std::vector< unsigned char > CreateObfuscateKey() const
static const int CLIENT_VERSION
bool Read(const K &key, V &value) const
unsigned int GetKeySize()
leveldb::Iterator * piter
std::vector< unsigned char > obfuscate_key
a key used for optional XOR-obfuscation of the database