Bitcoin Core 28.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
bitcoin-node.cpp
Go to the documentation of this file.
1// Copyright (c) 2021-2022 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 <init.h>
6#include <interfaces/chain.h>
7#include <interfaces/echo.h>
8#include <interfaces/init.h>
9#include <interfaces/ipc.h>
10#include <interfaces/node.h>
11#include <interfaces/wallet.h>
12#include <node/context.h>
13#include <util/check.h>
14
15#include <memory>
16
17namespace init {
18namespace {
19const char* EXE_NAME = "bitcoin-node";
20
21class BitcoinNodeInit : public interfaces::Init
22{
23public:
24 BitcoinNodeInit(node::NodeContext& node, const char* arg0)
25 : m_node(node),
26 m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this))
27 {
28 InitContext(m_node);
29 m_node.init = this;
30 }
31 std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
32 std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }
33 std::unique_ptr<interfaces::Mining> makeMining() override { return interfaces::MakeMining(m_node); }
34 std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain) override
35 {
36 return MakeWalletLoader(chain, *Assert(m_node.args));
37 }
38 std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
39 interfaces::Ipc* ipc() override { return m_ipc.get(); }
41 std::unique_ptr<interfaces::Ipc> m_ipc;
42};
43} // namespace
44} // namespace init
45
46namespace interfaces {
47std::unique_ptr<Init> MakeNodeInit(node::NodeContext& node, int argc, char* argv[], int& exit_status)
48{
49 auto init = std::make_unique<init::BitcoinNodeInit>(node, argc > 0 ? argv[0] : "");
50 // Check if bitcoin-node is being invoked as an IPC server. If so, then
51 // bypass normal execution and just respond to requests over the IPC
52 // channel and return null.
53 if (init->m_ipc->startSpawnedProcess(argc, argv, exit_status)) {
54 return nullptr;
55 }
56 return init;
57}
58} // namespace interfaces
std::unique_ptr< interfaces::Ipc > m_ipc
node::NodeContext m_node
int exit_status
#define Assert(val)
Identity function.
Definition check.h:77
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition chain.h:135
Initial interface created when a process is first started, and used to give and get access to other i...
Definition init.h:31
Interface providing access to interprocess-communication (IPC) functionality.
Definition ipc.h:45
void InitContext(NodeContext &node)
Initialize node context shutdown and args variables.
Definition init.cpp:200
std::unique_ptr< Node > MakeNode(node::NodeContext &context)
Return implementation of Node interface.
std::unique_ptr< Mining > MakeMining(node::NodeContext &node)
Return implementation of Mining interface.
std::unique_ptr< Echo > MakeEcho()
Return implementation of Echo interface.
std::unique_ptr< WalletLoader > MakeWalletLoader(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet loader.
std::unique_ptr< Ipc > MakeIpc(const char *exe_name, const char *process_argv0, Init &init)
Return implementation of Ipc interface.
std::unique_ptr< Init > MakeNodeInit(node::NodeContext &node, int argc, char *argv[], int &exit_status)
Return implementation of Init interface for the node process.
std::unique_ptr< Chain > MakeChain(node::NodeContext &node)
Return implementation of Chain interface.
Definition ipc.h:12
NodeContext struct containing references to chain state and connection state.
Definition context.h:55
ArgsManager * args
Definition context.h:71
interfaces::Init * init
Init interface for initializing current process and connecting to other processes.
Definition context.h:60