Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2022-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <addresstype.h>6#include <bench/bench.h>7#include <consensus/amount.h>8#include <outputtype.h>9#include <primitives/transaction.h>10#include <script/script.h>11#include <test/util/setup_common.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>21#include <cstdint>22#include <memory>23#include <optional>24#include <string>25#include <utility>26#include <vector>28namespace wallet{29static void AddTx(CWallet& wallet)30{31CMutableTransaction mtx;32mtx.vout.emplace_back(COIN, GetScriptForDestination(*Assert(wallet.GetNewDestination(OutputType::BECH32, ""))));33mtx.vin.emplace_back();35wallet.AddToWallet(MakeTransactionRef(mtx), TxStateInactive{});36}38static void WalletLoadingDescriptors(benchmark::Bench& bench)39{40const auto test_setup = MakeNoLogFileContext<TestingSetup>();42WalletContext context;43context.args = &test_setup->m_args;44context.chain = test_setup->m_node.chain.get();46// Setup the wallet47// Loading the wallet will also create it48uint64_t create_flags = WALLET_FLAG_DESCRIPTORS;49DatabaseStatus status;50DatabaseOptions options;51options.require_format = DatabaseFormat::SQLITE;52options.require_create = true;53bilingual_str error;54auto database = MakeWalletDatabase("", options, status, error);55auto wallet = TestCreateWallet(std::move(database), context, create_flags);57// Generate a bunch of transactions and addresses to put into the wallet58for (int i = 0; i < 1000; ++i) {59AddTx(*wallet);60}62options.require_create = false;63options.require_existing = true;65bench.epochs(5)66.setup([&] {67TestUnloadWallet(std::move(wallet));68database = MakeWalletDatabase("", options, status, error);69})70.run([&] {71wallet = TestLoadWallet(std::move(database), context);72});74// Cleanup75TestUnloadWallet(std::move(wallet));76}78BENCHMARK(WalletLoadingDescriptors);79} // namespace wallet
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.