Browse Source

Merge #8564: [Wallet] remove unused code/conditions in ReadAtCursor

beef966 [Wallet] remove unused code/conditions in ReadAtCursor (Jonas Schnelli)
0.14
Pieter Wuille 8 years ago
parent
commit
01680195f8
No known key found for this signature in database
GPG Key ID: DBA1A67379A1A931
  1. 2
      src/wallet/db.cpp
  2. 10
      src/wallet/db.h
  3. 8
      src/wallet/walletdb.cpp

2
src/wallet/db.cpp

@ -387,7 +387,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
while (fSuccess) { while (fSuccess) {
CDataStream ssKey(SER_DISK, CLIENT_VERSION); CDataStream ssKey(SER_DISK, CLIENT_VERSION);
CDataStream ssValue(SER_DISK, CLIENT_VERSION); CDataStream ssValue(SER_DISK, CLIENT_VERSION);
int ret = db.ReadAtCursor(pcursor, ssKey, ssValue, DB_NEXT); int ret = db.ReadAtCursor(pcursor, ssKey, ssValue);
if (ret == DB_NOTFOUND) { if (ret == DB_NOTFOUND) {
pcursor->close(); pcursor->close();
break; break;

10
src/wallet/db.h

@ -228,19 +228,17 @@ protected:
return pcursor; return pcursor;
} }
int ReadAtCursor(Dbc* pcursor, CDataStream& ssKey, CDataStream& ssValue, unsigned int fFlags = DB_NEXT) int ReadAtCursor(Dbc* pcursor, CDataStream& ssKey, CDataStream& ssValue, bool setRange = false)
{ {
// Read at cursor // Read at cursor
Dbt datKey; Dbt datKey;
if (fFlags == DB_SET || fFlags == DB_SET_RANGE || fFlags == DB_GET_BOTH || fFlags == DB_GET_BOTH_RANGE) { unsigned int fFlags = DB_NEXT;
if (setRange) {
datKey.set_data(&ssKey[0]); datKey.set_data(&ssKey[0]);
datKey.set_size(ssKey.size()); datKey.set_size(ssKey.size());
fFlags = DB_SET_RANGE;
} }
Dbt datValue; Dbt datValue;
if (fFlags == DB_GET_BOTH || fFlags == DB_GET_BOTH_RANGE) {
datValue.set_data(&ssValue[0]);
datValue.set_size(ssValue.size());
}
datKey.set_flags(DB_DBT_MALLOC); datKey.set_flags(DB_DBT_MALLOC);
datValue.set_flags(DB_DBT_MALLOC); datValue.set_flags(DB_DBT_MALLOC);
int ret = pcursor->get(&datKey, &datValue, fFlags); int ret = pcursor->get(&datKey, &datValue, fFlags);

8
src/wallet/walletdb.cpp

@ -216,16 +216,16 @@ void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountin
Dbc* pcursor = GetCursor(); Dbc* pcursor = GetCursor();
if (!pcursor) if (!pcursor)
throw runtime_error(std::string(__func__) + ": cannot create DB cursor"); throw runtime_error(std::string(__func__) + ": cannot create DB cursor");
unsigned int fFlags = DB_SET_RANGE; bool setRange = true;
while (true) while (true)
{ {
// Read next record // Read next record
CDataStream ssKey(SER_DISK, CLIENT_VERSION); CDataStream ssKey(SER_DISK, CLIENT_VERSION);
if (fFlags == DB_SET_RANGE) if (setRange)
ssKey << std::make_pair(std::string("acentry"), std::make_pair((fAllAccounts ? string("") : strAccount), uint64_t(0))); ssKey << std::make_pair(std::string("acentry"), std::make_pair((fAllAccounts ? string("") : strAccount), uint64_t(0)));
CDataStream ssValue(SER_DISK, CLIENT_VERSION); CDataStream ssValue(SER_DISK, CLIENT_VERSION);
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags); int ret = ReadAtCursor(pcursor, ssKey, ssValue, setRange);
fFlags = DB_NEXT; setRange = false;
if (ret == DB_NOTFOUND) if (ret == DB_NOTFOUND)
break; break;
else if (ret != 0) else if (ret != 0)

Loading…
Cancel
Save