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