2
2
// Distributed under the MIT software license, see the accompanying
3
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
4
5
- #ifndef BITCOIN_LEVELDBWRAPPER_H
6
- #define BITCOIN_LEVELDBWRAPPER_H
5
+ #ifndef BITCOIN_DBWRAPPER_H
6
+ #define BITCOIN_DBWRAPPER_H
7
7
8
8
#include " clientversion.h"
9
9
#include " serialize.h"
17
17
#include < leveldb/db.h>
18
18
#include < leveldb/write_batch.h>
19
19
20
- class leveldb_error : public std ::runtime_error
20
+ class dbwrapper_error : public std ::runtime_error
21
21
{
22
22
public:
23
- leveldb_error (const std::string& msg) : std::runtime_error(msg) {}
23
+ dbwrapper_error (const std::string& msg) : std::runtime_error(msg) {}
24
24
};
25
25
26
- void HandleError (const leveldb::Status& status) throw(leveldb_error );
26
+ void HandleError (const leveldb::Status& status) throw(dbwrapper_error );
27
27
28
- /* * Batch of changes queued to be written to a CLevelDBWrapper */
29
- class CLevelDBBatch
28
+ /* * Batch of changes queued to be written to a CDBWrapper */
29
+ class CDBBatch
30
30
{
31
- friend class CLevelDBWrapper ;
31
+ friend class CDBWrapper ;
32
32
33
33
private:
34
34
leveldb::WriteBatch batch;
@@ -38,7 +38,7 @@ class CLevelDBBatch
38
38
/* *
39
39
* @param[in] obfuscate_key If passed, XOR data with this key.
40
40
*/
41
- CLevelDBBatch (const std::vector<unsigned char > *obfuscate_key) : obfuscate_key(obfuscate_key) { };
41
+ CDBBatch (const std::vector<unsigned char > *obfuscate_key) : obfuscate_key(obfuscate_key) { };
42
42
43
43
template <typename K, typename V>
44
44
void Write (const K& key, const V& value)
@@ -68,8 +68,8 @@ class CLevelDBBatch
68
68
batch.Delete (slKey);
69
69
}
70
70
};
71
-
72
- class CLevelDBIterator
71
+
72
+ class CDBIterator
73
73
{
74
74
private:
75
75
leveldb::Iterator *piter;
@@ -81,14 +81,13 @@ class CLevelDBIterator
81
81
* @param[in] piterIn The original leveldb iterator.
82
82
* @param[in] obfuscate_key If passed, XOR data with this key.
83
83
*/
84
- CLevelDBIterator (leveldb::Iterator *piterIn, const std::vector<unsigned char >* obfuscate_key) :
84
+ CDBIterator (leveldb::Iterator *piterIn, const std::vector<unsigned char >* obfuscate_key) :
85
85
piter (piterIn), obfuscate_key(obfuscate_key) { };
86
- ~CLevelDBIterator ();
86
+ ~CDBIterator ();
87
87
88
88
bool Valid ();
89
89
90
90
void SeekToFirst ();
91
- void SeekToLast ();
92
91
93
92
template <typename K> void Seek (const K& key) {
94
93
CDataStream ssKey (SER_DISK, CLIENT_VERSION);
@@ -99,7 +98,6 @@ class CLevelDBIterator
99
98
}
100
99
101
100
void Next ();
102
- void Prev ();
103
101
104
102
template <typename K> bool GetKey (K& key) {
105
103
leveldb::Slice slKey = piter->key ();
@@ -133,8 +131,8 @@ class CLevelDBIterator
133
131
}
134
132
135
133
};
136
-
137
- class CLevelDBWrapper
134
+
135
+ class CDBWrapper
138
136
{
139
137
private:
140
138
// ! custom environment this database is using (may be NULL in case of default environment)
@@ -163,10 +161,10 @@ class CLevelDBWrapper
163
161
164
162
// ! the key under which the obfuscation key is stored
165
163
static const std::string OBFUSCATE_KEY_KEY;
166
-
164
+
167
165
// ! the length of the obfuscate key in number of bytes
168
166
static const unsigned int OBFUSCATE_KEY_NUM_BYTES;
169
-
167
+
170
168
std::vector<unsigned char > CreateObfuscateKey () const ;
171
169
172
170
public:
@@ -178,11 +176,11 @@ class CLevelDBWrapper
178
176
* @param[in] obfuscate If true, store data obfuscated via simple XOR. If false, XOR
179
177
* with a zero'd byte array.
180
178
*/
181
- CLevelDBWrapper (const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false , bool fWipe = false , bool obfuscate = false );
182
- ~CLevelDBWrapper ();
179
+ CDBWrapper (const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false , bool fWipe = false , bool obfuscate = false );
180
+ ~CDBWrapper ();
183
181
184
182
template <typename K, typename V>
185
- bool Read (const K& key, V& value) const throw(leveldb_error )
183
+ bool Read (const K& key, V& value) const throw(dbwrapper_error )
186
184
{
187
185
CDataStream ssKey (SER_DISK, CLIENT_VERSION);
188
186
ssKey.reserve (ssKey.GetSerializeSize (key));
@@ -208,15 +206,15 @@ class CLevelDBWrapper
208
206
}
209
207
210
208
template <typename K, typename V>
211
- bool Write (const K& key, const V& value, bool fSync = false ) throw(leveldb_error )
209
+ bool Write (const K& key, const V& value, bool fSync = false ) throw(dbwrapper_error )
212
210
{
213
- CLevelDBBatch batch (&obfuscate_key);
211
+ CDBBatch batch (&obfuscate_key);
214
212
batch.Write (key, value);
215
213
return WriteBatch (batch, fSync );
216
214
}
217
215
218
216
template <typename K>
219
- bool Exists (const K& key) const throw(leveldb_error )
217
+ bool Exists (const K& key) const throw(dbwrapper_error )
220
218
{
221
219
CDataStream ssKey (SER_DISK, CLIENT_VERSION);
222
220
ssKey.reserve (ssKey.GetSerializeSize (key));
@@ -235,30 +233,30 @@ class CLevelDBWrapper
235
233
}
236
234
237
235
template <typename K>
238
- bool Erase (const K& key, bool fSync = false ) throw(leveldb_error )
236
+ bool Erase (const K& key, bool fSync = false ) throw(dbwrapper_error )
239
237
{
240
- CLevelDBBatch batch (&obfuscate_key);
238
+ CDBBatch batch (&obfuscate_key);
241
239
batch.Erase (key);
242
240
return WriteBatch (batch, fSync );
243
241
}
244
242
245
- bool WriteBatch (CLevelDBBatch & batch, bool fSync = false ) throw(leveldb_error );
243
+ bool WriteBatch (CDBBatch & batch, bool fSync = false ) throw(dbwrapper_error );
246
244
247
245
// not available for LevelDB; provide for compatibility with BDB
248
246
bool Flush ()
249
247
{
250
248
return true ;
251
249
}
252
250
253
- bool Sync () throw(leveldb_error )
251
+ bool Sync () throw(dbwrapper_error )
254
252
{
255
- CLevelDBBatch batch (&obfuscate_key);
253
+ CDBBatch batch (&obfuscate_key);
256
254
return WriteBatch (batch, true );
257
255
}
258
256
259
- CLevelDBIterator *NewIterator ()
257
+ CDBIterator *NewIterator ()
260
258
{
261
- return new CLevelDBIterator (pdb->NewIterator (iteroptions), &obfuscate_key);
259
+ return new CDBIterator (pdb->NewIterator (iteroptions), &obfuscate_key);
262
260
}
263
261
264
262
/* *
@@ -278,5 +276,5 @@ class CLevelDBWrapper
278
276
279
277
};
280
278
281
- #endif // BITCOIN_LEVELDBWRAPPER_H
279
+ #endif // BITCOIN_DBWRAPPER_H
282
280
0 commit comments