Browse Source

Merge pull request #4931

93f84d0 cleanup class private and public areas in walletdb (Philip Kaufmann)
22d7e70 prefer const string& over char* in CDB and CWalletDB constructor (Philip Kaufmann)
0.10
Wladimir J. van der Laan 10 years ago
parent
commit
e9870c5ed4
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 16
      src/db.cpp
  2. 6
      src/db.h
  3. 4
      src/walletdb.cpp
  4. 19
      src/walletdb.h

16
src/db.cpp

@ -215,7 +215,7 @@ bool CDBEnv::Salvage(std::string strFile, bool fAggressive,
} }
void CDBEnv::CheckpointLSN(std::string strFile) void CDBEnv::CheckpointLSN(const std::string& strFile)
{ {
dbenv.txn_checkpoint(0, 0, 0); dbenv.txn_checkpoint(0, 0, 0);
if (fMockDb) if (fMockDb)
@ -224,12 +224,12 @@ void CDBEnv::CheckpointLSN(std::string strFile)
} }
CDB::CDB(const char *pszFile, const char* pszMode) : CDB::CDB(const std::string& strFilename, const char* pszMode) :
pdb(NULL), activeTxn(NULL) pdb(NULL), activeTxn(NULL)
{ {
int ret; int ret;
fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w')); fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w'));
if (pszFile == NULL) if (strFilename.empty())
return; return;
bool fCreate = strchr(pszMode, 'c') != NULL; bool fCreate = strchr(pszMode, 'c') != NULL;
@ -242,7 +242,7 @@ CDB::CDB(const char *pszFile, const char* pszMode) :
if (!bitdb.Open(GetDataDir())) if (!bitdb.Open(GetDataDir()))
throw runtime_error("CDB : Failed to open database environment."); throw runtime_error("CDB : Failed to open database environment.");
strFile = pszFile; strFile = strFilename;
++bitdb.mapFileUseCount[strFile]; ++bitdb.mapFileUseCount[strFile];
pdb = bitdb.mapDb[strFile]; pdb = bitdb.mapDb[strFile];
if (pdb == NULL) if (pdb == NULL)
@ -255,12 +255,12 @@ CDB::CDB(const char *pszFile, const char* pszMode) :
DbMpoolFile*mpf = pdb->get_mpf(); DbMpoolFile*mpf = pdb->get_mpf();
ret = mpf->set_flags(DB_MPOOL_NOFILE, 1); ret = mpf->set_flags(DB_MPOOL_NOFILE, 1);
if (ret != 0) if (ret != 0)
throw runtime_error(strprintf("CDB : Failed to configure for no temp file backing for database %s", pszFile)); throw runtime_error(strprintf("CDB : Failed to configure for no temp file backing for database %s", strFile));
} }
ret = pdb->open(NULL, // Txn pointer ret = pdb->open(NULL, // Txn pointer
fMockDb ? NULL : pszFile, // Filename fMockDb ? NULL : strFile.c_str(), // Filename
fMockDb ? pszFile : "main", // Logical db name fMockDb ? strFile.c_str() : "main", // Logical db name
DB_BTREE, // Database type DB_BTREE, // Database type
nFlags, // Flags nFlags, // Flags
0); 0);
@ -271,7 +271,7 @@ CDB::CDB(const char *pszFile, const char* pszMode) :
pdb = NULL; pdb = NULL;
--bitdb.mapFileUseCount[strFile]; --bitdb.mapFileUseCount[strFile];
strFile = ""; strFile = "";
throw runtime_error(strprintf("CDB : Error %d, can't open database %s", ret, pszFile)); throw runtime_error(strprintf("CDB : Error %d, can't open database %s", ret, strFile));
} }
if (fCreate && !Exists(string("version"))) if (fCreate && !Exists(string("version")))

6
src/db.h

@ -69,7 +69,7 @@ public:
bool Open(const boost::filesystem::path &path); bool Open(const boost::filesystem::path &path);
void Close(); void Close();
void Flush(bool fShutdown); void Flush(bool fShutdown);
void CheckpointLSN(std::string strFile); void CheckpointLSN(const std::string& strFile);
void CloseDb(const std::string& strFile); void CloseDb(const std::string& strFile);
bool RemoveDb(const std::string& strFile); bool RemoveDb(const std::string& strFile);
@ -96,11 +96,13 @@ protected:
DbTxn *activeTxn; DbTxn *activeTxn;
bool fReadOnly; bool fReadOnly;
explicit CDB(const char* pszFile, const char* pszMode="r+"); explicit CDB(const std::string& strFilename, const char* pszMode="r+");
~CDB() { Close(); } ~CDB() { Close(); }
public: public:
void Flush(); void Flush();
void Close(); void Close();
private: private:
CDB(const CDB&); CDB(const CDB&);
void operator=(const CDB&); void operator=(const CDB&);

4
src/walletdb.cpp

@ -242,9 +242,7 @@ void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountin
pcursor->close(); pcursor->close();
} }
DBErrors CWalletDB::ReorderTransactions(CWallet* pwallet)
DBErrors
CWalletDB::ReorderTransactions(CWallet* pwallet)
{ {
LOCK(pwallet->cs_wallet); LOCK(pwallet->cs_wallet);
// Old wallets didn't have any defined order for transactions // Old wallets didn't have any defined order for transactions

19
src/walletdb.h

@ -75,13 +75,10 @@ public:
class CWalletDB : public CDB class CWalletDB : public CDB
{ {
public: public:
CWalletDB(std::string strFilename, const char* pszMode="r+") : CDB(strFilename.c_str(), pszMode) CWalletDB(const std::string& strFilename, const char* pszMode = "r+") : CDB(strFilename, pszMode)
{ {
} }
private:
CWalletDB(const CWalletDB&);
void operator=(const CWalletDB&);
public:
bool WriteName(const std::string& strAddress, const std::string& strName); bool WriteName(const std::string& strAddress, const std::string& strName);
bool EraseName(const std::string& strAddress); bool EraseName(const std::string& strAddress);
@ -119,19 +116,23 @@ public:
bool WriteDestData(const std::string &address, const std::string &key, const std::string &value); bool WriteDestData(const std::string &address, const std::string &key, const std::string &value);
/// Erase destination data tuple from wallet database /// Erase destination data tuple from wallet database
bool EraseDestData(const std::string &address, const std::string &key); bool EraseDestData(const std::string &address, const std::string &key);
private:
bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry);
public:
bool WriteAccountingEntry(const CAccountingEntry& acentry); bool WriteAccountingEntry(const CAccountingEntry& acentry);
int64_t GetAccountCreditDebit(const std::string& strAccount); int64_t GetAccountCreditDebit(const std::string& strAccount);
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries); void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
DBErrors ReorderTransactions(CWallet*); DBErrors ReorderTransactions(CWallet* pwallet);
DBErrors LoadWallet(CWallet* pwallet); DBErrors LoadWallet(CWallet* pwallet);
DBErrors FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash, std::vector<CWalletTx>& vWtx); DBErrors FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash, std::vector<CWalletTx>& vWtx);
DBErrors ZapWalletTx(CWallet* pwallet, std::vector<CWalletTx>& vWtx); DBErrors ZapWalletTx(CWallet* pwallet, std::vector<CWalletTx>& vWtx);
static bool Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys); static bool Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys);
static bool Recover(CDBEnv& dbenv, std::string filename); static bool Recover(CDBEnv& dbenv, std::string filename);
private:
CWalletDB(const CWalletDB&);
void operator=(const CWalletDB&);
bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry);
}; };
bool BackupWallet(const CWallet& wallet, const std::string& strDest); bool BackupWallet(const CWallet& wallet, const std::string& strDest);

Loading…
Cancel
Save