diff --git a/src/bench/wallet_loading.cpp b/src/bench/wallet_loading.cpp index 6c9936ccd9d..2f7dc53b0c7 100644 --- a/src/bench/wallet_loading.cpp +++ b/src/bench/wallet_loading.cpp @@ -52,30 +52,6 @@ static void AddTx(CWallet& wallet) wallet.AddToWallet(MakeTransactionRef(mtx), TxStateInactive{}); } -static std::unique_ptr 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; -} - static void WalletLoading(benchmark::Bench& bench, bool legacy_wallet) { const auto test_setup = MakeNoLogFileContext(); diff --git a/src/wallet/test/util.cpp b/src/wallet/test/util.cpp index fb15c1a451c..f6c7ecb598b 100644 --- a/src/wallet/test/util.cpp +++ b/src/wallet/test/util.cpp @@ -44,6 +44,30 @@ std::unique_ptr CreateSyncedWallet(interfaces::Chain& chain, CChain& cc return wallet; } +std::unique_ptr 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; diff --git a/src/wallet/test/util.h b/src/wallet/test/util.h index 7fb496c82a7..a2e361ddca0 100644 --- a/src/wallet/test/util.h +++ b/src/wallet/test/util.h @@ -18,9 +18,14 @@ class Chain; namespace wallet { class CWallet; +struct DatabaseOptions; +class WalletDatabase; std::unique_ptr CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, ArgsManager& args, const CKey& key); +// Creates a copy of the provided database +std::unique_ptr DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options); + /** Returns a new encoded destination from the wallet (hardcoded to BECH32) */ std::string getnewaddress(CWallet& w); /** Returns a new destination, of an specific type, from the wallet */