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

@@ -50,7 +50,7 @@ std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database,
// Get a cursor to the original database
auto batch = database.MakeBatch();
batch->StartCursor();
std::unique_ptr<wallet::DatabaseCursor> cursor = batch->GetNewCursor();
// Get a batch for the new database
auto new_batch = new_database->MakeBatch();
@@ -60,7 +60,7 @@ std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database,
CDataStream key(SER_DISK, CLIENT_VERSION);
CDataStream value(SER_DISK, CLIENT_VERSION);
bool complete;
batch->ReadAtCursor(key, value, complete);
cursor->Next(key, value, complete);
if (complete) break;
new_batch->Write(key, value);
}

View File

@@ -54,12 +54,14 @@ BOOST_FIXTURE_TEST_CASE(wallet_load_unknown_descriptor, TestingSetup)
bool HasAnyRecordOfType(WalletDatabase& db, const std::string& key)
{
std::unique_ptr<DatabaseBatch> batch = db.MakeBatch(false);
BOOST_CHECK(batch->StartCursor());
BOOST_CHECK(batch);
std::unique_ptr<DatabaseCursor> cursor = batch->GetNewCursor();
BOOST_CHECK(cursor);
while (true) {
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
bool complete;
BOOST_CHECK(batch->ReadAtCursor(ssKey, ssValue, complete));
BOOST_CHECK(cursor->Next(ssKey, ssValue, complete));
if (complete) break;
std::string type;
ssKey >> type;