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

@@ -47,7 +47,8 @@ bool DumpWallet(const ArgsManager& args, CWallet& wallet, bilingual_str& error)
std::unique_ptr<DatabaseBatch> batch = db.MakeBatch();
bool ret = true;
if (!batch->StartCursor()) {
std::unique_ptr<DatabaseCursor> cursor = batch->GetNewCursor();
if (!cursor) {
error = _("Error: Couldn't create cursor into database");
ret = false;
}
@@ -69,7 +70,7 @@ bool DumpWallet(const ArgsManager& args, CWallet& wallet, bilingual_str& error)
CDataStream ss_key(SER_DISK, CLIENT_VERSION);
CDataStream ss_value(SER_DISK, CLIENT_VERSION);
bool complete;
ret = batch->ReadAtCursor(ss_key, ss_value, complete);
ret = cursor->Next(ss_key, ss_value, complete);
if (complete) {
ret = true;
break;
@@ -85,7 +86,7 @@ bool DumpWallet(const ArgsManager& args, CWallet& wallet, bilingual_str& error)
}
}
batch->CloseCursor();
cursor.reset();
batch.reset();
// Close the wallet after we're done with it. The caller won't be doing this