Bitcoin Core 32.99.0
P2P Digital Currency
Loading...
Searching...
No Matches
wallet_loading.cpp
Go to the documentation of this file.
1// Copyright (c) 2022-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <addresstype.h>
6#include <bench/bench.h>
7#include <consensus/amount.h>
8#include <outputtype.h>
10#include <script/script.h>
12#include <util/check.h>
13#include <util/translation.h>
14#include <wallet/context.h>
15#include <wallet/db.h>
16#include <wallet/test/util.h>
17#include <wallet/transaction.h>
18#include <wallet/wallet.h>
19#include <wallet/walletutil.h>
20
21#include <algorithm>
22#include <cstddef>
23#include <cstdint>
24#include <memory>
25#include <optional>
26#include <string>
27#include <utility>
28#include <vector>
29
30namespace wallet{
31static void AddTx(CWallet& wallet)
32{
34 mtx.vout.emplace_back(COIN, GetScriptForDestination(*Assert(wallet.GetNewDestination(OutputType::BECH32, ""))));
35 mtx.vin.emplace_back();
36
38}
39
41{
43
45 context.args = &test_setup->m_args;
46 context.chain = test_setup->m_node.chain.get();
47
48 // Setup the wallet
49 // Loading the wallet will also create it
50 uint64_t create_flags = WALLET_FLAG_DESCRIPTORS;
51 DatabaseStatus status;
52 DatabaseOptions options;
54 options.require_create = true;
55 bilingual_str error;
56 auto database = MakeWalletDatabase("", options, status, error);
57 auto wallet = TestCreateWallet(std::move(database), context, create_flags);
58
59 // Generate a bunch of transactions and addresses to put into the wallet
60 for (int i = 0; i < 1000; ++i) {
61 AddTx(*wallet);
62 }
63
64 options.require_create = false;
65 options.require_existing = true;
66
67 bench.epochs(std::min(bench.epochs(), size_t{5}))
68 .setup([&] {
69 TestUnloadWallet(std::move(wallet));
70 database = MakeWalletDatabase("", options, status, error);
71 })
72 .run([&] {
74 });
75
76 // Cleanup
77 TestUnloadWallet(std::move(wallet));
78}
79
81} // namespace wallet
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition amount.h:15
#define BENCHMARK(n)
Definition bench.h:69
#define Assert(val)
Identity function.
Definition check.h:119
Main entry point to nanobench's benchmarking facility.
Definition nanobench.h:649
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition wallet.h:318
void TestUnloadWallet(std::shared_ptr< CWallet > &&wallet)
Definition util.cpp:103
static void AddTx(CWallet &wallet)
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error_string)
Definition wallet.cpp:2777
std::shared_ptr< CWallet > TestLoadWallet(std::unique_ptr< WalletDatabase > database, WalletContext &context)
Definition util.cpp:81
std::shared_ptr< CWallet > TestCreateWallet(std::unique_ptr< WalletDatabase > database, WalletContext &context, uint64_t create_flags)
Definition util.cpp:57
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition walletutil.h:53
static void WalletLoadingDescriptors(benchmark::Bench &bench)
DatabaseStatus
Definition db.h:180
static CTransactionRef MakeTransactionRef(Tx &&txIn)
A mutable version of CTransaction.
std::vector< CTxOut > vout
Bilingual messages:
Definition translation.h:24
std::optional< DatabaseFormat > require_format
Definition db.h:171
State of transaction not confirmed or conflicting with a known block and not in the mempool.
Definition transaction.h:61
WalletContext struct containing references to state shared between CWallet instances,...
Definition context.h:36
interfaces::Chain * chain
Definition context.h:37
ArgsManager * args
Definition context.h:39
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:82
WalletContext context