refactor: move DuplicateMockDatabase to wallet/test/util.h

This commit is contained in:
furszy
2022-08-19 11:29:44 -03:00
parent ee7a984f85
commit 373c99633e
3 changed files with 29 additions and 24 deletions

View File

@@ -44,6 +44,30 @@ std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cc
return wallet;
}
std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options)
{
auto new_database = CreateMockWalletDatabase(options);
// Get a cursor to the original database
auto batch = database.MakeBatch();
batch->StartCursor();
// Get a batch for the new database
auto new_batch = new_database->MakeBatch();
// Read all records from the original database and write them to the new one
while (true) {
CDataStream key(SER_DISK, CLIENT_VERSION);
CDataStream value(SER_DISK, CLIENT_VERSION);
bool complete;
batch->ReadAtCursor(key, value, complete);
if (complete) break;
new_batch->Write(key, value);
}
return new_database;
}
std::string getnewaddress(CWallet& w)
{
constexpr auto output_type = OutputType::BECH32;