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) 2021-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_INTERFACES_INIT_H6#define BITCOIN_INTERFACES_INIT_H8// This header is associated with several source files, and IWYU9// reaches different conclusions across them about whether these10// headers should be included or their classes forward-declared.11// Keep the includes so the result is the same for every file.12// IWYU pragma: begin_keep13#include <interfaces/chain.h>14#include <interfaces/echo.h>15#include <interfaces/mining.h>16#include <interfaces/node.h>17#include <interfaces/rpc.h>18#include <interfaces/wallet.h>19// IWYU pragma: end_keep21#include <memory>22#include <stdexcept>24namespace node {25struct NodeContext;26} // namespace node28namespace interfaces {29class Ipc;31//! Initial interface created when a process is first started, and used to give32//! and get access to other interfaces (Node, Chain, Wallet, etc).33//!34//! There is a different Init interface implementation for each process35//! (bitcoin-gui, bitcoin-node, bitcoin-wallet, bitcoind, bitcoin-qt) and each36//! implementation can implement the make methods for interfaces it supports.37//! The default make methods all return null.38class Init39{40public:41virtual ~Init() = default;42virtual std::unique_ptr<Node> makeNode() { return nullptr; }43virtual std::unique_ptr<Chain> makeChain() { return nullptr; }44virtual std::unique_ptr<Mining> makeMining() { return nullptr; }45virtual std::unique_ptr<WalletLoader> makeWalletLoader(Chain& chain) { return nullptr; }46virtual std::unique_ptr<Echo> makeEcho() { return nullptr; }47virtual std::unique_ptr<Rpc> makeRpc() { return nullptr; }48virtual Ipc* ipc() { return nullptr; }49virtual bool canListenIpc() { return false; }50virtual const char* exeName() { return nullptr; }51virtual void makeMiningOld2() { throw std::runtime_error("Old mining interface (@2) not supported. Please update your client!"); }52};54//! Return implementation of Init interface for the node process. If the argv55//! indicates that this is a child process spawned to handle requests from a56//! parent process, this blocks and handles requests, then returns null and a57//! status code to exit with. If this returns non-null, the caller can start up58//! normally and use the Init object to spawn and connect to other processes59//! while it is running.60std::unique_ptr<Init> MakeNodeInit(node::NodeContext& node, int argc, char* argv[], int& exit_status);62//! Return implementation of Init interface for the wallet process.63std::unique_ptr<Init> MakeWalletInit(int argc, char* argv[], int& exit_status);65//! Return implementation of Init interface for the gui process.66std::unique_ptr<Init> MakeGuiInit(int argc, char* argv[]);68//! Return implementation of Init interface for a basic IPC client that doesn't69//! provide any IPC services itself.70//!71//! When an IPC client connects to a socket or spawns a process, it gets a pointer72//! to an Init object allowing it to create objects and threads on the remote73//! side of the IPC connection. But the client also needs to provide a local Init74//! object to allow the remote side of the connection to create objects and75//! threads on this side. This function just returns a basic Init object76//! allowing remote connections to only create local threads, not other objects77//! (because its Init::make* methods return null.)78//!79//! @param exe_name Current executable name, which is just passed to the IPC80//! system and used for logging.81//!82//! @param process_argv0 Optional string containing argv[0] value passed to83//! main(). This is passed to the IPC system and used to locate binaries by84//! relative path if subprocesses are spawned.85std::unique_ptr<Init> MakeBasicInit(const char* exe_name, const char* process_argv0="");86} // namespace interfaces88#endif // BITCOIN_INTERFACES_INIT_H
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.