36 boost::filesystem::path
path;
44 std::map<std::string, Db*>
mapDb;
66 typedef std::pair<std::vector<unsigned char>, std::vector<unsigned char> >
KeyValPair;
67 bool Salvage(std::string strFile,
bool fAggressive, std::vector<KeyValPair>& vResult);
69 bool Open(
const boost::filesystem::path &path);
71 void Flush(
bool fShutdown);
74 void CloseDb(
const std::string& strFile);
75 bool RemoveDb(
const std::string& strFile);
80 int ret = dbenv.txn_begin(NULL, &ptxn, flags);
81 if (!ptxn || ret != 0)
99 explicit CDB(
const char* pszFile,
const char* pszMode=
"r+");
109 template<
typename K,
typename T>
119 Dbt datKey(&ssKey[0], ssKey.
size());
123 datValue.set_flags(DB_DBT_MALLOC);
124 int ret = pdb->get(activeTxn, &datKey, &datValue, 0);
125 memset(datKey.get_data(), 0, datKey.get_size());
126 if (datValue.get_data() == NULL)
131 CDataStream ssValue((
char*)datValue.get_data(), (
char*)datValue.get_data() + datValue.get_size(),
SER_DISK, CLIENT_VERSION);
134 catch (std::exception &e) {
139 memset(datValue.get_data(), 0, datValue.get_size());
140 free(datValue.get_data());
144 template<
typename K,
typename T>
145 bool Write(
const K& key,
const T&
value,
bool fOverwrite=
true)
150 assert(!
"Write called on database in read-only mode");
156 Dbt datKey(&ssKey[0], ssKey.
size());
160 ssValue.reserve(10000);
162 Dbt datValue(&ssValue[0], ssValue.size());
165 int ret = pdb->put(activeTxn, &datKey, &datValue, (fOverwrite ? 0 : DB_NOOVERWRITE));
168 memset(datKey.get_data(), 0, datKey.get_size());
169 memset(datValue.get_data(), 0, datValue.get_size());
179 assert(!
"Erase called on database in read-only mode");
185 Dbt datKey(&ssKey[0], ssKey.
size());
188 int ret = pdb->del(activeTxn, &datKey, 0);
191 memset(datKey.get_data(), 0, datKey.get_size());
192 return (ret == 0 || ret == DB_NOTFOUND);
205 Dbt datKey(&ssKey[0], ssKey.
size());
208 int ret = pdb->exists(activeTxn, &datKey, 0);
211 memset(datKey.get_data(), 0, datKey.get_size());
220 int ret = pdb->cursor(NULL, &pcursor, 0);
230 if (fFlags == DB_SET || fFlags == DB_SET_RANGE || fFlags == DB_GET_BOTH || fFlags == DB_GET_BOTH_RANGE)
232 datKey.set_data(&ssKey[0]);
233 datKey.set_size(ssKey.
size());
236 if (fFlags == DB_GET_BOTH || fFlags == DB_GET_BOTH_RANGE)
238 datValue.set_data(&ssValue[0]);
239 datValue.set_size(ssValue.
size());
241 datKey.set_flags(DB_DBT_MALLOC);
242 datValue.set_flags(DB_DBT_MALLOC);
243 int ret = pcursor->get(&datKey, &datValue, fFlags);
246 else if (datKey.get_data() == NULL || datValue.get_data() == NULL)
252 ssKey.
write((
char*)datKey.get_data(), datKey.get_size());
255 ssValue.
write((
char*)datValue.get_data(), datValue.get_size());
258 memset(datKey.get_data(), 0, datKey.get_size());
259 memset(datValue.get_data(), 0, datValue.get_size());
260 free(datKey.get_data());
261 free(datValue.get_data());
268 if (!pdb || activeTxn)
279 if (!pdb || !activeTxn)
281 int ret = activeTxn->commit(0);
288 if (!pdb || !activeTxn)
290 int ret = activeTxn->abort();
298 return Read(std::string(
"version"), nVersion);
303 return Write(std::string(
"version"), nVersion);
306 bool static Rewrite(
const std::string& strFile,
const char* pszSkip = NULL);
327 #endif // BITCOIN_DB_H
Access to the (IP) address database (peers.dat)
std::map< std::string, int > mapFileUseCount
void CheckpointLSN(std::string strFile)
DbTxn * TxnBegin(int flags=DB_TXN_WRITE_NOSYNC)
int ReadAtCursor(Dbc *pcursor, CDataStream &ssKey, CDataStream &ssValue, unsigned int fFlags=DB_NEXT)
static bool Rewrite(const std::string &strFile, const char *pszSkip=NULL)
Master key for wallet encryption.
bool Write(const K &key, const T &value, bool fOverwrite=true)
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
void Flush(bool fShutdown)
bool Exists(const K &key)
Double ended buffer combining vector and stream-like interfaces.
unsigned int nWalletDBUpdated
boost::filesystem::path path
Stochastical (IP) address manager.
bool Write(const CAddrMan &addr)
std::map< std::string, Db * > mapDb
bool ReadVersion(int &nVersion)
A CService with information about it as peer.
RAII class that provides access to a Berkeley database.
Used to marshal pointers into hashes for db storage.
An outpoint - a combination of a transaction hash and an index n into its vout.
bool RemoveDb(const std::string &strFile)
bool Read(const K &key, T &value)
A transaction with a bunch of additional info that only the owner cares about.
void operator=(const CDB &)
bool Salvage(std::string strFile, bool fAggressive, std::vector< KeyValPair > &vResult)
CDataStream & write(const char *pch, int nSize)
void reserve(size_type n)
boost::filesystem::path pathAddr
void CloseDb(const std::string &strFile)
bool WriteVersion(int nVersion)
CDB(const char *pszFile, const char *pszMode="r+")
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
VerifyResult Verify(std::string strFile, bool(*recoverFunc)(CDBEnv &dbenv, std::string strFile))
bool BackupWallet(const CWallet &wallet, const std::string &strDest)
std::pair< std::vector< unsigned char >, std::vector< unsigned char > > KeyValPair
bool Open(const boost::filesystem::path &path)
bool Read(CAddrMan &addr)
void ThreadFlushWalletDB(const std::string &strWalletFile)