Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/bdb.h
- This file was copied from src/wallet/db.h.
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2020 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_WALLET_DB_H | #ifndef BITCOIN_WALLET_BDB_H | ||||
#define BITCOIN_WALLET_DB_H | #define BITCOIN_WALLET_BDB_H | ||||
#include <clientversion.h> | #include <clientversion.h> | ||||
#include <fs.h> | #include <fs.h> | ||||
#include <serialize.h> | #include <serialize.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <wallet/db.h> | |||||
#include <db_cxx.h> | #include <db_cxx.h> | ||||
#include <atomic> | #include <atomic> | ||||
#include <map> | #include <map> | ||||
#include <memory> | #include <memory> | ||||
#include <string> | #include <string> | ||||
#include <unordered_map> | #include <unordered_map> | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | public: | ||||
void CheckpointLSN(const std::string &strFile); | void CheckpointLSN(const std::string &strFile); | ||||
void CloseDb(const std::string &strFile); | void CloseDb(const std::string &strFile); | ||||
void ReloadDbEnv(); | void ReloadDbEnv(); | ||||
DbTxn *TxnBegin(int flags = DB_TXN_WRITE_NOSYNC) { | DbTxn *TxnBegin(int flags = DB_TXN_WRITE_NOSYNC) { | ||||
DbTxn *ptxn = nullptr; | DbTxn *ptxn = nullptr; | ||||
int ret = dbenv->txn_begin(nullptr, &ptxn, flags); | int ret = dbenv->txn_begin(nullptr, &ptxn, flags); | ||||
if (!ptxn || ret != 0) return nullptr; | if (!ptxn || ret != 0) { | ||||
return nullptr; | |||||
} | |||||
return ptxn; | return ptxn; | ||||
} | } | ||||
}; | }; | ||||
/** Return whether a wallet database is currently loaded. */ | |||||
bool IsBDBWalletLoaded(const fs::path &wallet_path); | |||||
/** | |||||
* Given a wallet directory path or legacy file path, return path to main data | |||||
* file in the wallet database. */ | |||||
fs::path WalletDataFilePath(const fs::path &wallet_path); | |||||
void SplitWalletPath(const fs::path &wallet_path, fs::path &env_directory, | |||||
std::string &database_filename); | |||||
/** Get BerkeleyEnvironment and database filename given a wallet path. */ | /** Get BerkeleyEnvironment and database filename given a wallet path. */ | ||||
std::shared_ptr<BerkeleyEnvironment> | std::shared_ptr<BerkeleyEnvironment> | ||||
GetWalletEnv(const fs::path &wallet_path, std::string &database_filename); | GetWalletEnv(const fs::path &wallet_path, std::string &database_filename); | ||||
/** Return whether a BDB wallet database is currently loaded. */ | |||||
bool IsBDBWalletLoaded(const fs::path &wallet_path); | |||||
/** | /** | ||||
* An instance of this class represents one database. | * An instance of this class represents one database. | ||||
* For BerkeleyDB this is just a (env, strFile) tuple. | * For BerkeleyDB this is just a (env, strFile) tuple. | ||||
*/ | */ | ||||
class BerkeleyDatabase { | class BerkeleyDatabase { | ||||
friend class BerkeleyBatch; | friend class BerkeleyBatch; | ||||
public: | public: | ||||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | public: | ||||
~BerkeleyBatch() { Close(); } | ~BerkeleyBatch() { Close(); } | ||||
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(); | ||||
/* flush the wallet passively (TRY_LOCK) | /* | ||||
ideal to be called periodically */ | * flush the wallet passively (TRY_LOCK)i | ||||
* ideal to be called periodically | |||||
*/ | |||||
static bool PeriodicFlush(BerkeleyDatabase &database); | static bool PeriodicFlush(BerkeleyDatabase &database); | ||||
/* verifies the database environment */ | /* verifies the database environment */ | ||||
static bool VerifyEnvironment(const fs::path &file_path, | static bool VerifyEnvironment(const fs::path &file_path, | ||||
bilingual_str &errorStr); | bilingual_str &errorStr); | ||||
/* verifies the database file */ | /* verifies the database file */ | ||||
static bool VerifyDatabaseFile(const fs::path &file_path, | static bool VerifyDatabaseFile(const fs::path &file_path, | ||||
bilingual_str &errorStr); | bilingual_str &errorStr); | ||||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | public: | ||||
bool TxnBegin(); | bool TxnBegin(); | ||||
bool TxnCommit(); | bool TxnCommit(); | ||||
bool TxnAbort(); | bool TxnAbort(); | ||||
static bool Rewrite(BerkeleyDatabase &database, | static bool Rewrite(BerkeleyDatabase &database, | ||||
const char *pszSkip = nullptr); | const char *pszSkip = nullptr); | ||||
}; | }; | ||||
#endif // BITCOIN_WALLET_DB_H | #endif // BITCOIN_WALLET_BDB_H |