Skip to content

Commit 69efbc0

Browse files
committed
Move SafeDbt out of BerkeleyBatch
1 parent 6061eb6 commit 69efbc0

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

src/wallet/bdb.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,17 @@ BerkeleyEnvironment::BerkeleyEnvironment() : m_use_shared_memory(false)
220220
fMockDb = true;
221221
}
222222

223-
BerkeleyBatch::SafeDbt::SafeDbt()
223+
SafeDbt::SafeDbt()
224224
{
225225
m_dbt.set_flags(DB_DBT_MALLOC);
226226
}
227227

228-
BerkeleyBatch::SafeDbt::SafeDbt(void* data, size_t size)
228+
SafeDbt::SafeDbt(void* data, size_t size)
229229
: m_dbt(data, size)
230230
{
231231
}
232232

233-
BerkeleyBatch::SafeDbt::~SafeDbt()
233+
SafeDbt::~SafeDbt()
234234
{
235235
if (m_dbt.get_data() != nullptr) {
236236
// Clear memory, e.g. in case it was a private key
@@ -244,17 +244,17 @@ BerkeleyBatch::SafeDbt::~SafeDbt()
244244
}
245245
}
246246

247-
const void* BerkeleyBatch::SafeDbt::get_data() const
247+
const void* SafeDbt::get_data() const
248248
{
249249
return m_dbt.get_data();
250250
}
251251

252-
uint32_t BerkeleyBatch::SafeDbt::get_size() const
252+
uint32_t SafeDbt::get_size() const
253253
{
254254
return m_dbt.get_size();
255255
}
256256

257-
BerkeleyBatch::SafeDbt::operator Dbt*()
257+
SafeDbt::operator Dbt*()
258258
{
259259
return &m_dbt;
260260
}

src/wallet/bdb.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -165,29 +165,29 @@ class BerkeleyDatabase : public WalletDatabase
165165
std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) override;
166166
};
167167

168-
/** RAII class that provides access to a Berkeley database */
169-
class BerkeleyBatch : public DatabaseBatch
168+
/** RAII class that automatically cleanses its data on destruction */
169+
class SafeDbt final
170170
{
171-
/** RAII class that automatically cleanses its data on destruction */
172-
class SafeDbt final
173-
{
174-
Dbt m_dbt;
175-
176-
public:
177-
// construct Dbt with internally-managed data
178-
SafeDbt();
179-
// construct Dbt with provided data
180-
SafeDbt(void* data, size_t size);
181-
~SafeDbt();
182-
183-
// delegate to Dbt
184-
const void* get_data() const;
185-
uint32_t get_size() const;
171+
Dbt m_dbt;
186172

187-
// conversion operator to access the underlying Dbt
188-
operator Dbt*();
189-
};
173+
public:
174+
// construct Dbt with internally-managed data
175+
SafeDbt();
176+
// construct Dbt with provided data
177+
SafeDbt(void* data, size_t size);
178+
~SafeDbt();
179+
180+
// delegate to Dbt
181+
const void* get_data() const;
182+
uint32_t get_size() const;
183+
184+
// conversion operator to access the underlying Dbt
185+
operator Dbt*();
186+
};
190187

188+
/** RAII class that provides access to a Berkeley database */
189+
class BerkeleyBatch : public DatabaseBatch
190+
{
191191
private:
192192
bool ReadKey(CDataStream&& key, CDataStream& value) override;
193193
bool WriteKey(CDataStream&& key, CDataStream&& value, bool overwrite = true) override;

0 commit comments

Comments
 (0)