Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/bdb.h
Show First 20 Lines • Show All 226 Lines • ▼ Show 20 Lines | public: | ||||
BerkeleyBatch(const BerkeleyBatch &) = delete; | BerkeleyBatch(const BerkeleyBatch &) = delete; | ||||
BerkeleyBatch &operator=(const BerkeleyBatch &) = delete; | BerkeleyBatch &operator=(const BerkeleyBatch &) = delete; | ||||
void Flush(); | void Flush(); | ||||
void Close(); | void Close(); | ||||
template <typename K, typename T> bool Read(const K &key, T &value) { | template <typename K, typename T> 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)) { | ||||
bool ret = ReadKey(ssKey, ssValue); | return false; | ||||
if (ret) { | } | ||||
// Unserialize value | |||||
try { | try { | ||||
ssValue >> value; | ssValue >> value; | ||||
success = true; | return true; | ||||
} catch (const std::exception &) { | } catch (const std::exception &) { | ||||
// In this case success remains 'false' | return 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> bool Erase(const K &key) { | template <typename K> 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> bool Exists(const K &key) { | template <typename K> 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); | ||||
} | } | ||||
bool StartCursor(); | bool StartCursor(); | ||||
bool ReadAtCursor(CDataStream &ssKey, CDataStream &ssValue, bool &complete); | bool ReadAtCursor(CDataStream &ssKey, CDataStream &ssValue, bool &complete); | ||||
void CloseCursor(); | void CloseCursor(); | ||||
bool TxnBegin(); | bool TxnBegin(); | ||||
bool TxnCommit(); | bool TxnCommit(); | ||||
bool TxnAbort(); | bool TxnAbort(); | ||||
}; | }; | ||||
#endif // BITCOIN_WALLET_BDB_H | #endif // BITCOIN_WALLET_BDB_H |