wallet: Introduce DatabaseCursor RAII class for managing cursor

Instead of having DatabaseBatch deal with opening and closing database
cursors, have a separate RAII class that deals with those.

For now, DatabaseBatch manages DatabaseCursor, but this will change
later.
This commit is contained in:
Andrew Chow
2022-04-11 15:14:24 -04:00
committed by Andrew Chow
parent 69efbc011b
commit 7a198bba0a
6 changed files with 108 additions and 44 deletions

View File

@@ -867,6 +867,12 @@ BOOST_FIXTURE_TEST_CASE(ZapSelectTx, TestChain100Setup)
TestUnloadWallet(std::move(wallet));
}
class FailCursor : public DatabaseCursor
{
public:
bool Next(CDataStream& key, CDataStream& value, bool& complete) override { return false; }
};
/** RAII class that provides access to a FailDatabase. Which fails if needed. */
class FailBatch : public DatabaseBatch
{
@@ -882,9 +888,7 @@ public:
void Flush() override {}
void Close() override {}
bool StartCursor() override { return true; }
bool ReadAtCursor(CDataStream& ssKey, CDataStream& ssValue, bool& complete) override { return false; }
void CloseCursor() override {}
std::unique_ptr<DatabaseCursor> GetNewCursor() override { return std::make_unique<FailCursor>(); }
bool TxnBegin() override { return false; }
bool TxnCommit() override { return false; }
bool TxnAbort() override { return false; }