aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/test/util.cpp
diff options
context:
space:
mode:
authorfurszy <matiasfurszyfer@protonmail.com>2022-08-19 11:29:44 -0300
committerfurszy <matiasfurszyfer@protonmail.com>2022-11-21 17:30:00 -0300
commit373c99633ec7f20557db2734c49116ee4ad15423 (patch)
treeff3c63324d02ba445349c8095eac3d0a31212f65 /src/wallet/test/util.cpp
parentee7a984f85015b610be4929b7c35cb501c1fbf7c (diff)
refactor: move DuplicateMockDatabase to wallet/test/util.h
Diffstat (limited to 'src/wallet/test/util.cpp')
-rw-r--r--src/wallet/test/util.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/wallet/test/util.cpp b/src/wallet/test/util.cpp
index fb15c1a451..f6c7ecb598 100644
--- a/src/wallet/test/util.cpp
+++ b/src/wallet/test/util.cpp
@@ -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;