Skip to content

Commit ca1a3b0

Browse files
jonasschnellifurszy
authored andcommitted
[Wallet] remove unused code/conditions in ReadAtCursor
1 parent fd259f3 commit ca1a3b0

File tree

3 files changed

+29
-31
lines changed

3 files changed

+29
-31
lines changed

src/wallet/db.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ bool CDB::Rewrite(const std::string& strFile, const char* pszSkip)
368368
while (fSuccess) {
369369
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
370370
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
371-
int ret = db.ReadAtCursor(pcursor, ssKey, ssValue, DB_NEXT);
371+
int ret = db.ReadAtCursor(pcursor, ssKey, ssValue);
372372
if (ret == DB_NOTFOUND) {
373373
pcursor->close();
374374
break;

src/wallet/db.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,19 +229,17 @@ class CDB
229229
return pcursor;
230230
}
231231

232-
int ReadAtCursor(Dbc* pcursor, CDataStream& ssKey, CDataStream& ssValue, unsigned int fFlags = DB_NEXT)
232+
int ReadAtCursor(Dbc* pcursor, CDataStream& ssKey, CDataStream& ssValue, bool setRange = false)
233233
{
234234
// Read at cursor
235235
Dbt datKey;
236-
if (fFlags == DB_SET || fFlags == DB_SET_RANGE || fFlags == DB_GET_BOTH || fFlags == DB_GET_BOTH_RANGE) {
236+
unsigned int fFlags = DB_NEXT;
237+
if (setRange) {
237238
datKey.set_data(&ssKey[0]);
238239
datKey.set_size(ssKey.size());
240+
fFlags = DB_SET_RANGE;
239241
}
240242
Dbt datValue;
241-
if (fFlags == DB_GET_BOTH || fFlags == DB_GET_BOTH_RANGE) {
242-
datValue.set_data(&ssValue[0]);
243-
datValue.set_size(ssValue.size());
244-
}
245243
datKey.set_flags(DB_DBT_MALLOC);
246244
datValue.set_flags(DB_DBT_MALLOC);
247245
int ret = pcursor->get(&datKey, &datValue, fFlags);

src/wallet/walletdb.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,16 +1363,16 @@ std::map<uint256, std::vector<std::pair<uint256, uint32_t> > > CWalletDB::MapMin
13631363
Dbc* pcursor = GetCursor();
13641364
if (!pcursor)
13651365
throw std::runtime_error(std::string(__func__)+" : cannot create DB cursor");
1366-
unsigned int fFlags = DB_SET_RANGE;
1366+
bool setRange = true;
13671367
for (;;)
13681368
{
13691369
// Read next record
13701370
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
1371-
if (fFlags == DB_SET_RANGE)
1371+
if (setRange)
13721372
ssKey << std::make_pair(std::string("mintpool"), UINT256_ZERO);
13731373
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
1374-
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
1375-
fFlags = DB_NEXT;
1374+
int ret = ReadAtCursor(pcursor, ssKey, ssValue, setRange);
1375+
setRange = false;
13761376
if (ret == DB_NOTFOUND)
13771377
break;
13781378
else if (ret != 0)
@@ -1419,16 +1419,16 @@ std::list<CDeterministicMint> CWalletDB::ListDeterministicMints()
14191419
Dbc* pcursor = GetCursor();
14201420
if (!pcursor)
14211421
throw std::runtime_error(std::string(__func__)+" : cannot create DB cursor");
1422-
unsigned int fFlags = DB_SET_RANGE;
1422+
bool setRange = true;
14231423
for (;;)
14241424
{
14251425
// Read next record
14261426
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
1427-
if (fFlags == DB_SET_RANGE)
1427+
if (setRange)
14281428
ssKey << make_pair(std::string("dzpiv"), UINT256_ZERO);
14291429
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
1430-
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
1431-
fFlags = DB_NEXT;
1430+
int ret = ReadAtCursor(pcursor, ssKey, ssValue, setRange);
1431+
setRange = false;
14321432
if (ret == DB_NOTFOUND)
14331433
break;
14341434
else if (ret != 0)
@@ -1462,18 +1462,18 @@ std::list<CZerocoinMint> CWalletDB::ListMintedCoins()
14621462
Dbc* pcursor = GetCursor();
14631463
if (!pcursor)
14641464
throw std::runtime_error(std::string(__func__)+" : cannot create DB cursor");
1465-
unsigned int fFlags = DB_SET_RANGE;
1465+
bool setRange = true;
14661466
std::vector<CZerocoinMint> vOverWrite;
14671467
std::vector<CZerocoinMint> vArchive;
14681468
for (;;)
14691469
{
14701470
// Read next record
14711471
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
1472-
if (fFlags == DB_SET_RANGE)
1472+
if (setRange)
14731473
ssKey << make_pair(std::string("zerocoin"), UINT256_ZERO);
14741474
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
1475-
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
1476-
fFlags = DB_NEXT;
1475+
int ret = ReadAtCursor(pcursor, ssKey, ssValue, setRange);
1476+
setRange = false;
14771477
if (ret == DB_NOTFOUND)
14781478
break;
14791479
else if (ret != 0)
@@ -1507,16 +1507,16 @@ std::list<CZerocoinSpend> CWalletDB::ListSpentCoins()
15071507
Dbc* pcursor = GetCursor();
15081508
if (!pcursor)
15091509
throw std::runtime_error(std::string(__func__)+" : cannot create DB cursor");
1510-
unsigned int fFlags = DB_SET_RANGE;
1510+
bool setRange = true;
15111511
for (;;)
15121512
{
15131513
// Read next record
15141514
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
1515-
if (fFlags == DB_SET_RANGE)
1515+
if (setRange)
15161516
ssKey << make_pair(std::string("zcserial"), BN_ZERO);
15171517
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
1518-
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
1519-
fFlags = DB_NEXT;
1518+
int ret = ReadAtCursor(pcursor, ssKey, ssValue, setRange);
1519+
setRange = false;
15201520
if (ret == DB_NOTFOUND)
15211521
break;
15221522
else if (ret != 0)
@@ -1562,16 +1562,16 @@ std::list<CZerocoinMint> CWalletDB::ListArchivedZerocoins()
15621562
Dbc* pcursor = GetCursor();
15631563
if (!pcursor)
15641564
throw std::runtime_error(std::string(__func__)+" : cannot create DB cursor");
1565-
unsigned int fFlags = DB_SET_RANGE;
1565+
bool setRange = true;
15661566
for (;;)
15671567
{
15681568
// Read next record
15691569
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
1570-
if (fFlags == DB_SET_RANGE)
1570+
if (setRange)
15711571
ssKey << make_pair(std::string("zco"), BN_ZERO);
15721572
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
1573-
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
1574-
fFlags = DB_NEXT;
1573+
int ret = ReadAtCursor(pcursor, ssKey, ssValue, setRange);
1574+
setRange = false;
15751575
if (ret == DB_NOTFOUND)
15761576
break;
15771577
else if (ret != 0)
@@ -1605,16 +1605,16 @@ std::list<CDeterministicMint> CWalletDB::ListArchivedDeterministicMints()
16051605
Dbc* pcursor = GetCursor();
16061606
if (!pcursor)
16071607
throw std::runtime_error(std::string(__func__)+" : cannot create DB cursor");
1608-
unsigned int fFlags = DB_SET_RANGE;
1608+
bool setRange = true;
16091609
for (;;)
16101610
{
16111611
// Read next record
16121612
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
1613-
if (fFlags == DB_SET_RANGE)
1613+
if (setRange)
16141614
ssKey << make_pair(std::string("dzco"), BN_ZERO);
16151615
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
1616-
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
1617-
fFlags = DB_NEXT;
1616+
int ret = ReadAtCursor(pcursor, ssKey, ssValue, setRange);
1617+
setRange = false;
16181618
if (ret == DB_NOTFOUND)
16191619
break;
16201620
else if (ret != 0)

0 commit comments

Comments
 (0)