mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
wallet: Remove confusing double return value ret+success
Also, remove redundant comments
This commit is contained in:
parent
d4f9ae0025
commit
fa021e9a5b
2 changed files with 6 additions and 28 deletions
|
@ -809,10 +809,8 @@ bool BerkeleyBatch::ReadKey(CDataStream& key, CDataStream& value)
|
||||||
if (!pdb)
|
if (!pdb)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Key
|
|
||||||
SafeDbt datKey(key.data(), key.size());
|
SafeDbt datKey(key.data(), key.size());
|
||||||
|
|
||||||
// Read
|
|
||||||
SafeDbt datValue;
|
SafeDbt datValue;
|
||||||
int ret = pdb->get(activeTxn, datKey, datValue, 0);
|
int ret = pdb->get(activeTxn, datKey, datValue, 0);
|
||||||
if (ret == 0 && datValue.get_data() != nullptr) {
|
if (ret == 0 && datValue.get_data() != nullptr) {
|
||||||
|
@ -829,13 +827,10 @@ bool BerkeleyBatch::WriteKey(CDataStream& key, CDataStream& value, bool overwrit
|
||||||
if (fReadOnly)
|
if (fReadOnly)
|
||||||
assert(!"Write called on database in read-only mode");
|
assert(!"Write called on database in read-only mode");
|
||||||
|
|
||||||
// Key
|
|
||||||
SafeDbt datKey(key.data(), key.size());
|
SafeDbt datKey(key.data(), key.size());
|
||||||
|
|
||||||
// Value
|
|
||||||
SafeDbt datValue(value.data(), value.size());
|
SafeDbt datValue(value.data(), value.size());
|
||||||
|
|
||||||
// Write
|
|
||||||
int ret = pdb->put(activeTxn, datKey, datValue, (overwrite ? 0 : DB_NOOVERWRITE));
|
int ret = pdb->put(activeTxn, datKey, datValue, (overwrite ? 0 : DB_NOOVERWRITE));
|
||||||
return (ret == 0);
|
return (ret == 0);
|
||||||
}
|
}
|
||||||
|
@ -847,10 +842,8 @@ bool BerkeleyBatch::EraseKey(CDataStream& key)
|
||||||
if (fReadOnly)
|
if (fReadOnly)
|
||||||
assert(!"Erase called on database in read-only mode");
|
assert(!"Erase called on database in read-only mode");
|
||||||
|
|
||||||
// Key
|
|
||||||
SafeDbt datKey(key.data(), key.size());
|
SafeDbt datKey(key.data(), key.size());
|
||||||
|
|
||||||
// Erase
|
|
||||||
int ret = pdb->del(activeTxn, datKey, 0);
|
int ret = pdb->del(activeTxn, datKey, 0);
|
||||||
return (ret == 0 || ret == DB_NOTFOUND);
|
return (ret == 0 || ret == DB_NOTFOUND);
|
||||||
}
|
}
|
||||||
|
@ -860,10 +853,8 @@ bool BerkeleyBatch::HasKey(CDataStream& key)
|
||||||
if (!pdb)
|
if (!pdb)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Key
|
|
||||||
SafeDbt datKey(key.data(), key.size());
|
SafeDbt datKey(key.data(), key.size());
|
||||||
|
|
||||||
// Exists
|
|
||||||
int ret = pdb->exists(activeTxn, datKey, 0);
|
int ret = pdb->exists(activeTxn, datKey, 0);
|
||||||
return ret == 0;
|
return ret == 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,64 +223,51 @@ public:
|
||||||
template <typename K, typename T>
|
template <typename K, typename T>
|
||||||
bool Read(const K& key, T& value)
|
bool Read(const K& key, T& value)
|
||||||
{
|
{
|
||||||
// Key
|
|
||||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||||
ssKey.reserve(1000);
|
ssKey.reserve(1000);
|
||||||
ssKey << key;
|
ssKey << key;
|
||||||
|
|
||||||
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
|
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
|
||||||
bool success = false;
|
if (!ReadKey(ssKey, ssValue)) return false;
|
||||||
bool ret = ReadKey(ssKey, ssValue);
|
try {
|
||||||
if (ret) {
|
ssValue >> value;
|
||||||
// Unserialize value
|
return true;
|
||||||
try {
|
} catch (const std::exception&) {
|
||||||
ssValue >> value;
|
return false;
|
||||||
success = true;
|
|
||||||
} catch (const std::exception&) {
|
|
||||||
// In this case success remains 'false'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ret && success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename K, typename T>
|
template <typename K, typename T>
|
||||||
bool Write(const K& key, const T& value, bool fOverwrite = true)
|
bool Write(const K& key, const T& value, bool fOverwrite = true)
|
||||||
{
|
{
|
||||||
// Key
|
|
||||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||||
ssKey.reserve(1000);
|
ssKey.reserve(1000);
|
||||||
ssKey << key;
|
ssKey << key;
|
||||||
|
|
||||||
// Value
|
|
||||||
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
|
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
|
||||||
ssValue.reserve(10000);
|
ssValue.reserve(10000);
|
||||||
ssValue << value;
|
ssValue << value;
|
||||||
|
|
||||||
// Write
|
|
||||||
return WriteKey(ssKey, ssValue, fOverwrite);
|
return WriteKey(ssKey, ssValue, fOverwrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename K>
|
template <typename K>
|
||||||
bool Erase(const K& key)
|
bool Erase(const K& key)
|
||||||
{
|
{
|
||||||
// Key
|
|
||||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||||
ssKey.reserve(1000);
|
ssKey.reserve(1000);
|
||||||
ssKey << key;
|
ssKey << key;
|
||||||
|
|
||||||
// Erase
|
|
||||||
return EraseKey(ssKey);
|
return EraseKey(ssKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename K>
|
template <typename K>
|
||||||
bool Exists(const K& key)
|
bool Exists(const K& key)
|
||||||
{
|
{
|
||||||
// Key
|
|
||||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||||
ssKey.reserve(1000);
|
ssKey.reserve(1000);
|
||||||
ssKey << key;
|
ssKey << key;
|
||||||
|
|
||||||
// Exists
|
|
||||||
return HasKey(ssKey);
|
return HasKey(ssKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue