My immediate goal with this is to make it easier to use a different key/value store instead of BerkeleyDB, for a sandboxing project. However, it is an improvement also for BerkeleyDB.
Steps:
-
Abstract database handle from explicit strFilename into CWalletDBWrapper. For many databases, a usable handle involves more than just a filename. Also make the field private.
-
Get rid of fFileBacked - it is only used by the tests, and used inconsistly - for example CWallet::AddToWallet doesn’t check it at all, and that’s not quite the only place (see AbandonWallet). Fixing would be a lot of work and lead to disjointed code.
But it is not necessary. Instead move the concern to ignoring operations with a dummy database to CDB. There were very few changes necessary for this.
-
Reduce references to global bitdb. CWalletDBWrapper carries this environment information around so there is less need to refer to global scope. Besides being cleaner, this could allow use of multiple database environments at some point.
-
CWalletDB now contains a CDB instead of inheriting from it. This makes it easier to replace the internal transaction with a different database, without leaking through internals.
Future:
-
The eventual goal of “CWalletDBWrapper” is like “CDBWrapper”, to move further database functionality there from “CDB” (which is really a “CDBBatch”, a database transaction object). Not renaming it nor CWalletDB here to not interfere unduly much with other open wallet pulls.
-
Two maps inside bitdb that refer to wallet files by name could be removed, and converted to fields on CWalletDBWrapper:
std::map<std::string, int> mapFileUseCount; std::map<std::string, Db*> mapDb;