Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/walletdb.h
Show First 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | |||||
* will be committed when the object goes out of scope. Optionally (on by | * will be committed when the object goes out of scope. Optionally (on by | ||||
* default) it will flush to disk on close. Every 1000 writes will automatically | * default) it will flush to disk on close. Every 1000 writes will automatically | ||||
* trigger a flush to disk. | * trigger a flush to disk. | ||||
*/ | */ | ||||
class WalletBatch { | class WalletBatch { | ||||
private: | private: | ||||
template <typename K, typename T> | template <typename K, typename T> | ||||
bool WriteIC(const K &key, const T &value, bool fOverwrite = true) { | bool WriteIC(const K &key, const T &value, bool fOverwrite = true) { | ||||
if (!m_batch.Write(key, value, fOverwrite)) { | if (!m_batch->Write(key, value, fOverwrite)) { | ||||
return false; | return false; | ||||
} | } | ||||
m_database.IncrementUpdateCounter(); | m_database.IncrementUpdateCounter(); | ||||
if (m_database.nUpdateCounter % 1000 == 0) { | if (m_database.nUpdateCounter % 1000 == 0) { | ||||
m_batch.Flush(); | m_batch->Flush(); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
template <typename K> bool EraseIC(const K &key) { | template <typename K> bool EraseIC(const K &key) { | ||||
if (!m_batch.Erase(key)) { | if (!m_batch->Erase(key)) { | ||||
return false; | return false; | ||||
} | } | ||||
m_database.IncrementUpdateCounter(); | m_database.IncrementUpdateCounter(); | ||||
if (m_database.nUpdateCounter % 1000 == 0) { | if (m_database.nUpdateCounter % 1000 == 0) { | ||||
m_batch.Flush(); | m_batch->Flush(); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
public: | public: | ||||
explicit WalletBatch(WalletDatabase &database, const char *pszMode = "r+", | explicit WalletBatch(WalletDatabase &database, const char *pszMode = "r+", | ||||
bool _fFlushOnClose = true) | bool _fFlushOnClose = true) | ||||
: m_batch(database, pszMode, _fFlushOnClose), m_database(database) {} | : m_batch(database.MakeBatch(pszMode, _fFlushOnClose)), | ||||
m_database(database) {} | |||||
WalletBatch(const WalletBatch &) = delete; | WalletBatch(const WalletBatch &) = delete; | ||||
WalletBatch &operator=(const WalletBatch &) = delete; | WalletBatch &operator=(const WalletBatch &) = delete; | ||||
bool WriteName(const CTxDestination &address, const std::string &strName); | bool WriteName(const CTxDestination &address, const std::string &strName); | ||||
bool EraseName(const CTxDestination &address); | bool EraseName(const CTxDestination &address); | ||||
bool WritePurpose(const CTxDestination &address, | bool WritePurpose(const CTxDestination &address, | ||||
const std::string &purpose); | const std::string &purpose); | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | public: | ||||
//! Begin a new transaction | //! Begin a new transaction | ||||
bool TxnBegin(); | bool TxnBegin(); | ||||
//! Commit current transaction | //! Commit current transaction | ||||
bool TxnCommit(); | bool TxnCommit(); | ||||
//! Abort current transaction | //! Abort current transaction | ||||
bool TxnAbort(); | bool TxnAbort(); | ||||
private: | private: | ||||
BerkeleyBatch m_batch; | std::unique_ptr<BerkeleyBatch> m_batch; | ||||
WalletDatabase &m_database; | WalletDatabase &m_database; | ||||
}; | }; | ||||
//! Compacts BDB state so that wallet.dat is self-contained (if there are | //! Compacts BDB state so that wallet.dat is self-contained (if there are | ||||
//! changes) | //! changes) | ||||
void MaybeCompactWalletDB(); | void MaybeCompactWalletDB(); | ||||
//! Unserialize a given Key-Value pair and load it into the wallet | //! Unserialize a given Key-Value pair and load it into the wallet | ||||
Show All 18 Lines |