Inside Bitcoin
Opening the selected file…
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) 2020-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#ifndef BITCOIN_WALLET_CONTEXT_H6#define BITCOIN_WALLET_CONTEXT_H8#include <sync.h>10#include <functional>11#include <list>12#include <memory>13#include <vector>15class ArgsManager;16class CScheduler;17namespace interfaces {18class Chain;19class Wallet;20} // namespace interfaces22namespace wallet {23class CWallet;24using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;26//! WalletContext struct containing references to state shared between CWallet27//! instances, like the reference to the chain interface, and the list of opened28//! wallets.29//!30//! Future shared state can be added here as an alternative to adding global31//! variables.32//!33//! The struct isn't intended to have any member functions. It should just be a34//! collection of state pointers that doesn't pull in dependencies or implement35//! behavior.36struct WalletContext {37interfaces::Chain* chain{nullptr};38CScheduler* scheduler{nullptr};39ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct40// It is unsafe to lock this after locking a CWallet::cs_wallet mutex because41// this could introduce inconsistent lock ordering and cause deadlocks.42Mutex wallets_mutex;43std::vector<std::shared_ptr<CWallet>> wallets GUARDED_BY(wallets_mutex);44std::list<LoadWalletFn> wallet_load_fns GUARDED_BY(wallets_mutex);46//! Declare default constructor and destructor that are not inline, so code47//! instantiating the WalletContext struct doesn't need to #include class48//! definitions for smart pointer and container members.49WalletContext();50~WalletContext();51};52} // namespace wallet54#endif // BITCOIN_WALLET_CONTEXT_H