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 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 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 bool Erase(const K& key) { - // Key CDataStream ssKey(SER_DISK, CLIENT_VERSION); ssKey.reserve(1000); ssKey << key; - // Erase return EraseKey(ssKey); } template bool Exists(const K& key) { - // Key CDataStream ssKey(SER_DISK, CLIENT_VERSION); ssKey.reserve(1000); ssKey << key; - // Exists return HasKey(ssKey); }