aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2022-04-11 14:49:46 -0400
committerAndrew Chow <github@achow101.com>2022-12-12 14:52:04 -0500
commit69efbc011bb74fcd8dd9ed2a8a5d31bc9e323c10 (patch)
treea56f54ad0ca2186bcb5bfef6f3d0beabe28b43c2 /src
parent6061eb6564105ad54703a7cf3282590d0e1a7f28 (diff)
downloadbitcoin-69efbc011bb74fcd8dd9ed2a8a5d31bc9e323c10.tar.xz
Move SafeDbt out of BerkeleyBatch
Diffstat (limited to 'src')
-rw-r--r--src/wallet/bdb.cpp12
-rw-r--r--src/wallet/bdb.h40
2 files changed, 26 insertions, 26 deletions
diff --git a/src/wallet/bdb.cpp b/src/wallet/bdb.cpp
index 3a9d277f65..d45e8679ac 100644
--- a/src/wallet/bdb.cpp
+++ b/src/wallet/bdb.cpp
@@ -220,17 +220,17 @@ BerkeleyEnvironment::BerkeleyEnvironment() : m_use_shared_memory(false)
fMockDb = true;
}
-BerkeleyBatch::SafeDbt::SafeDbt()
+SafeDbt::SafeDbt()
{
m_dbt.set_flags(DB_DBT_MALLOC);
}
-BerkeleyBatch::SafeDbt::SafeDbt(void* data, size_t size)
+SafeDbt::SafeDbt(void* data, size_t size)
: m_dbt(data, size)
{
}
-BerkeleyBatch::SafeDbt::~SafeDbt()
+SafeDbt::~SafeDbt()
{
if (m_dbt.get_data() != nullptr) {
// Clear memory, e.g. in case it was a private key
@@ -244,17 +244,17 @@ BerkeleyBatch::SafeDbt::~SafeDbt()
}
}
-const void* BerkeleyBatch::SafeDbt::get_data() const
+const void* SafeDbt::get_data() const
{
return m_dbt.get_data();
}
-uint32_t BerkeleyBatch::SafeDbt::get_size() const
+uint32_t SafeDbt::get_size() const
{
return m_dbt.get_size();
}
-BerkeleyBatch::SafeDbt::operator Dbt*()
+SafeDbt::operator Dbt*()
{
return &m_dbt;
}
diff --git a/src/wallet/bdb.h b/src/wallet/bdb.h
index ddab85521b..35cc823876 100644
--- a/src/wallet/bdb.h
+++ b/src/wallet/bdb.h
@@ -165,29 +165,29 @@ public:
std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) override;
};
-/** RAII class that provides access to a Berkeley database */
-class BerkeleyBatch : public DatabaseBatch
+/** RAII class that automatically cleanses its data on destruction */
+class SafeDbt final
{
- /** RAII class that automatically cleanses its data on destruction */
- class SafeDbt final
- {
- Dbt m_dbt;
-
- public:
- // construct Dbt with internally-managed data
- SafeDbt();
- // construct Dbt with provided data
- SafeDbt(void* data, size_t size);
- ~SafeDbt();
-
- // delegate to Dbt
- const void* get_data() const;
- uint32_t get_size() const;
+ Dbt m_dbt;
- // conversion operator to access the underlying Dbt
- operator Dbt*();
- };
+public:
+ // construct Dbt with internally-managed data
+ SafeDbt();
+ // construct Dbt with provided data
+ SafeDbt(void* data, size_t size);
+ ~SafeDbt();
+
+ // delegate to Dbt
+ const void* get_data() const;
+ uint32_t get_size() const;
+
+ // conversion operator to access the underlying Dbt
+ operator Dbt*();
+};
+/** RAII class that provides access to a Berkeley database */
+class BerkeleyBatch : public DatabaseBatch
+{
private:
bool ReadKey(CDataStream&& key, CDataStream& value) override;
bool WriteKey(CDataStream&& key, CDataStream&& value, bool overwrite = true) override;