LCOV - code coverage report
Current view: top level - src/interfaces - init.h (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 33.3 % 12 4
Test Date: 2026-04-01 04:53:46 Functions: 33.3 % 12 4
Branches: 25.0 % 4 1

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2021-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                 :             : #ifndef BITCOIN_INTERFACES_INIT_H
       6                 :             : #define BITCOIN_INTERFACES_INIT_H
       7                 :             : 
       8                 :             : #include <interfaces/chain.h>
       9                 :             : #include <interfaces/echo.h>
      10                 :             : #include <interfaces/mining.h>
      11                 :             : #include <interfaces/node.h>
      12                 :             : #include <interfaces/rpc.h>
      13                 :             : #include <interfaces/wallet.h>
      14                 :             : 
      15                 :             : #include <memory>
      16                 :             : 
      17                 :             : namespace node {
      18                 :             : struct NodeContext;
      19                 :             : } // namespace node
      20                 :             : 
      21                 :             : namespace interfaces {
      22                 :             : class Ipc;
      23                 :             : 
      24                 :             : //! Initial interface created when a process is first started, and used to give
      25                 :             : //! and get access to other interfaces (Node, Chain, Wallet, etc).
      26                 :             : //!
      27                 :             : //! There is a different Init interface implementation for each process
      28                 :             : //! (bitcoin-gui, bitcoin-node, bitcoin-wallet, bitcoind, bitcoin-qt) and each
      29                 :             : //! implementation can implement the make methods for interfaces it supports.
      30                 :             : //! The default make methods all return null.
      31         [ +  - ]:        2361 : class Init
      32                 :             : {
      33                 :             : public:
      34                 :          48 :     virtual ~Init() = default;
      35                 :           0 :     virtual std::unique_ptr<Node> makeNode() { return nullptr; }
      36                 :           0 :     virtual std::unique_ptr<Chain> makeChain() { return nullptr; }
      37                 :           0 :     virtual std::unique_ptr<Mining> makeMining() { return nullptr; }
      38                 :           0 :     virtual std::unique_ptr<WalletLoader> makeWalletLoader(Chain& chain) { return nullptr; }
      39                 :           0 :     virtual std::unique_ptr<Echo> makeEcho() { return nullptr; }
      40                 :           0 :     virtual std::unique_ptr<Rpc> makeRpc() { return nullptr; }
      41                 :        2323 :     virtual Ipc* ipc() { return nullptr; }
      42                 :        1212 :     virtual bool canListenIpc() { return false; }
      43                 :           0 :     virtual const char* exeName() { return nullptr; }
      44         [ #  # ]:           0 :     virtual void makeMiningOld2() { throw std::runtime_error("Old mining interface (@2) not supported. Please update your client!"); }
      45                 :             : };
      46                 :             : 
      47                 :             : //! Return implementation of Init interface for the node process. If the argv
      48                 :             : //! indicates that this is a child process spawned to handle requests from a
      49                 :             : //! parent process, this blocks and handles requests, then returns null and a
      50                 :             : //! status code to exit with. If this returns non-null, the caller can start up
      51                 :             : //! normally and use the Init object to spawn and connect to other processes
      52                 :             : //! while it is running.
      53                 :             : std::unique_ptr<Init> MakeNodeInit(node::NodeContext& node, int argc, char* argv[], int& exit_status);
      54                 :             : 
      55                 :             : //! Return implementation of Init interface for the wallet process.
      56                 :             : std::unique_ptr<Init> MakeWalletInit(int argc, char* argv[], int& exit_status);
      57                 :             : 
      58                 :             : //! Return implementation of Init interface for the gui process.
      59                 :             : std::unique_ptr<Init> MakeGuiInit(int argc, char* argv[]);
      60                 :             : 
      61                 :             : //! Return implementation of Init interface for a basic IPC client that doesn't
      62                 :             : //! provide any IPC services itself.
      63                 :             : //!
      64                 :             : //! When an IPC client connects to a socket or spawns a process, it gets a pointer
      65                 :             : //! to an Init object allowing it to create objects and threads on the remote
      66                 :             : //! side of the IPC connection. But the client also needs to provide a local Init
      67                 :             : //! object to allow the remote side of the connection to create objects and
      68                 :             : //! threads on this side. This function just returns a basic Init object
      69                 :             : //! allowing remote connections to only create local threads, not other objects
      70                 :             : //! (because its Init::make* methods return null.)
      71                 :             : //!
      72                 :             : //! @param exe_name Current executable name, which is just passed to the IPC
      73                 :             : //!     system and used for logging.
      74                 :             : //!
      75                 :             : //! @param process_argv0 Optional string containing argv[0] value passed to
      76                 :             : //!     main(). This is passed to the IPC system and used to locate binaries by
      77                 :             : //!     relative path if subprocesses are spawned.
      78                 :             : std::unique_ptr<Init> MakeBasicInit(const char* exe_name, const char* process_argv0="");
      79                 :             : } // namespace interfaces
      80                 :             : 
      81                 :             : #endif // BITCOIN_INTERFACES_INIT_H
        

Generated by: LCOV version 2.0-1