wallet: Have cursor users use DatabaseCursor directly

Instead of having the DatabaseBatch manage the cursor, having the
consumer handle it directly
This commit is contained in:
Andrew Chow
2022-04-11 16:07:58 -04:00
committed by Andrew Chow
parent 7a198bba0a
commit d79e8dcf29
7 changed files with 29 additions and 43 deletions

View File

@@ -399,7 +399,6 @@ void BerkeleyBatch::Close()
activeTxn->abort();
activeTxn = nullptr;
pdb = nullptr;
CloseCursor();
if (fFlushOnClose)
Flush();
@@ -477,12 +476,13 @@ bool BerkeleyDatabase::Rewrite(const char* pszSkip)
fSuccess = false;
}
if (db.StartCursor()) {
std::unique_ptr<DatabaseCursor> cursor = db.GetNewCursor();
if (cursor) {
while (fSuccess) {
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
bool complete;
bool ret1 = db.ReadAtCursor(ssKey, ssValue, complete);
bool ret1 = cursor->Next(ssKey, ssValue, complete);
if (complete) {
break;
} else if (!ret1) {
@@ -503,7 +503,7 @@ bool BerkeleyDatabase::Rewrite(const char* pszSkip)
if (ret2 > 0)
fSuccess = false;
}
db.CloseCursor();
cursor.reset();
}
if (fSuccess) {
db.Close();