aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-06-20 08:44:42 -0400
committerMarcoFalke <falke.marco@gmail.com>2020-06-20 08:41:19 -0400
commitfa021e9a5b7e930a3db0febb416942dea3a90a8f (patch)
tree87be616951b6bbad4ef1edf0ed2d93880f6715d4 /src
parentd4f9ae00252ba44909a61db0f606be6fddf904c1 (diff)
wallet: Remove confusing double return value ret+success
Also, remove redundant comments
Diffstat (limited to 'src')
-rw-r--r--src/wallet/bdb.cpp9
-rw-r--r--src/wallet/bdb.h25
2 files changed, 6 insertions, 28 deletions
diff --git a/src/wallet/bdb.cpp b/src/wallet/bdb.cpp
index 125bf004e4..a3a56aa51c 100644
--- a/src/wallet/bdb.cpp
+++ b/src/wallet/bdb.cpp
@@ -809,10 +809,8 @@ bool BerkeleyBatch::ReadKey(CDataStream& key, CDataStream& value)
if (!pdb)
return false;
- // Key
SafeDbt datKey(key.data(), key.size());
- // Read
SafeDbt datValue;
int ret = pdb->get(activeTxn, datKey, datValue, 0);
if (ret == 0 && datValue.get_data() != nullptr) {
@@ -829,13 +827,10 @@ bool BerkeleyBatch::WriteKey(CDataStream& key, CDataStream& value, bool overwrit
if (fReadOnly)
assert(!"Write called on database in read-only mode");
- // Key
SafeDbt datKey(key.data(), key.size());
- // Value
SafeDbt datValue(value.data(), value.size());
- // Write
int ret = pdb->put(activeTxn, datKey, datValue, (overwrite ? 0 : DB_NOOVERWRITE));
return (ret == 0);
}
@@ -847,10 +842,8 @@ bool BerkeleyBatch::EraseKey(CDataStream& key)
if (fReadOnly)
assert(!"Erase called on database in read-only mode");
- // Key
SafeDbt datKey(key.data(), key.size());
- // Erase
int ret = pdb->del(activeTxn, datKey, 0);
return (ret == 0 || ret == DB_NOTFOUND);
}
@@ -860,10 +853,8 @@ bool BerkeleyBatch::HasKey(CDataStream& key)
if (!pdb)
return false;
- // Key
SafeDbt datKey(key.data(), key.size());
- // Exists
int ret = pdb->exists(activeTxn, datKey, 0);
return ret == 0;
}
diff --git a/src/wallet/bdb.h b/src/wallet/bdb.h
index c121bb4228..a2eaf95001 100644
--- a/src/wallet/bdb.h
+++ b/src/wallet/bdb.h
@@ -223,64 +223,51 @@ public:
template <typename K, typename T>
bool Read(const K& key, T& value)
{
- // Key
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
ssKey.reserve(1000);
ssKey << key;
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
- bool success = false;
- bool ret = ReadKey(ssKey, ssValue);
- if (ret) {
- // Unserialize value
- try {
- ssValue >> value;
- success = true;
- } catch (const std::exception&) {
- // In this case success remains 'false'
- }
+ if (!ReadKey(ssKey, ssValue)) return false;
+ try {
+ ssValue >> value;
+ return true;
+ } catch (const std::exception&) {
+ return false;
}
- return ret && success;
}
template <typename K, typename T>
bool Write(const K& key, const T& value, bool fOverwrite = true)
{
- // Key
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
ssKey.reserve(1000);
ssKey << key;
- // Value
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
ssValue.reserve(10000);
ssValue << value;
- // Write
return WriteKey(ssKey, ssValue, fOverwrite);
}
template <typename K>
bool Erase(const K& key)
{
- // Key
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
ssKey.reserve(1000);
ssKey << key;
- // Erase
return EraseKey(ssKey);
}
template <typename K>
bool Exists(const K& key)
{
- // Key
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
ssKey.reserve(1000);
ssKey << key;
- // Exists
return HasKey(ssKey);
}