Skip to content

Commit 373c996

Browse files
committed
refactor: move DuplicateMockDatabase to wallet/test/util.h
1 parent ee7a984 commit 373c996

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

src/bench/wallet_loading.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,30 +52,6 @@ static void AddTx(CWallet& wallet)
5252
wallet.AddToWallet(MakeTransactionRef(mtx), TxStateInactive{});
5353
}
5454

55-
static std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options)
56-
{
57-
auto new_database = CreateMockWalletDatabase(options);
58-
59-
// Get a cursor to the original database
60-
auto batch = database.MakeBatch();
61-
batch->StartCursor();
62-
63-
// Get a batch for the new database
64-
auto new_batch = new_database->MakeBatch();
65-
66-
// Read all records from the original database and write them to the new one
67-
while (true) {
68-
CDataStream key(SER_DISK, CLIENT_VERSION);
69-
CDataStream value(SER_DISK, CLIENT_VERSION);
70-
bool complete;
71-
batch->ReadAtCursor(key, value, complete);
72-
if (complete) break;
73-
new_batch->Write(key, value);
74-
}
75-
76-
return new_database;
77-
}
78-
7955
static void WalletLoading(benchmark::Bench& bench, bool legacy_wallet)
8056
{
8157
const auto test_setup = MakeNoLogFileContext<TestingSetup>();

src/wallet/test/util.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,30 @@ std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cc
4444
return wallet;
4545
}
4646

47+
std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options)
48+
{
49+
auto new_database = CreateMockWalletDatabase(options);
50+
51+
// Get a cursor to the original database
52+
auto batch = database.MakeBatch();
53+
batch->StartCursor();
54+
55+
// Get a batch for the new database
56+
auto new_batch = new_database->MakeBatch();
57+
58+
// Read all records from the original database and write them to the new one
59+
while (true) {
60+
CDataStream key(SER_DISK, CLIENT_VERSION);
61+
CDataStream value(SER_DISK, CLIENT_VERSION);
62+
bool complete;
63+
batch->ReadAtCursor(key, value, complete);
64+
if (complete) break;
65+
new_batch->Write(key, value);
66+
}
67+
68+
return new_database;
69+
}
70+
4771
std::string getnewaddress(CWallet& w)
4872
{
4973
constexpr auto output_type = OutputType::BECH32;

src/wallet/test/util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ class Chain;
1818

1919
namespace wallet {
2020
class CWallet;
21+
struct DatabaseOptions;
22+
class WalletDatabase;
2123

2224
std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, ArgsManager& args, const CKey& key);
2325

26+
// Creates a copy of the provided database
27+
std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options);
28+
2429
/** Returns a new encoded destination from the wallet (hardcoded to BECH32) */
2530
std::string getnewaddress(CWallet& w);
2631
/** Returns a new destination, of an specific type, from the wallet */

0 commit comments

Comments
 (0)