Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/bdb.h
Show First 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | public: | ||||
const void *get_data() const; | const void *get_data() const; | ||||
u_int32_t get_size() const; | u_int32_t get_size() const; | ||||
// conversion operator to access the underlying Dbt | // conversion operator to access the underlying Dbt | ||||
operator Dbt *(); | operator Dbt *(); | ||||
}; | }; | ||||
private: | private: | ||||
bool ReadKey(CDataStream &key, CDataStream &value); | bool ReadKey(CDataStream &&key, CDataStream &value); | ||||
bool WriteKey(CDataStream &key, CDataStream &value, bool overwrite = true); | bool WriteKey(CDataStream &&key, CDataStream &&value, | ||||
bool EraseKey(CDataStream &key); | bool overwrite = true); | ||||
bool HasKey(CDataStream &key); | bool EraseKey(CDataStream &&key); | ||||
bool HasKey(CDataStream &&key); | |||||
protected: | protected: | ||||
Db *pdb; | Db *pdb; | ||||
std::string strFile; | std::string strFile; | ||||
DbTxn *activeTxn; | DbTxn *activeTxn; | ||||
Dbc *m_cursor; | Dbc *m_cursor; | ||||
bool fReadOnly; | bool fReadOnly; | ||||
bool fFlushOnClose; | bool fFlushOnClose; | ||||
Show All 12 Lines | public: | ||||
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) { | ||||
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); | ||||
if (!ReadKey(ssKey, ssValue)) { | if (!ReadKey(std::move(ssKey), ssValue)) { | ||||
return false; | return false; | ||||
} | } | ||||
try { | try { | ||||
ssValue >> value; | ssValue >> value; | ||||
return true; | return true; | ||||
} catch (const std::exception &) { | } catch (const std::exception &) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
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) { | ||||
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); | ||||
ssValue.reserve(10000); | ssValue.reserve(10000); | ||||
ssValue << value; | ssValue << value; | ||||
return WriteKey(ssKey, ssValue, fOverwrite); | return WriteKey(std::move(ssKey), std::move(ssValue), fOverwrite); | ||||
} | } | ||||
template <typename K> bool Erase(const K &key) { | template <typename K> bool Erase(const K &key) { | ||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION); | CDataStream ssKey(SER_DISK, CLIENT_VERSION); | ||||
ssKey.reserve(1000); | ssKey.reserve(1000); | ||||
ssKey << key; | ssKey << key; | ||||
return EraseKey(ssKey); | return EraseKey(std::move(ssKey)); | ||||
} | } | ||||
template <typename K> bool Exists(const K &key) { | template <typename K> bool Exists(const K &key) { | ||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION); | CDataStream ssKey(SER_DISK, CLIENT_VERSION); | ||||
ssKey.reserve(1000); | ssKey.reserve(1000); | ||||
ssKey << key; | ssKey << key; | ||||
return HasKey(ssKey); | return HasKey(std::move(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 |