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
16namespace init {
17namespace {
18const char* EXE_NAME = "bitcoin-node";
19
20class BitcoinNodeInit : public interfaces::Init
21{
22public:
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
44namespace interfaces {
45std::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
NodeContext & m_node
std::unique_ptr< interfaces::Ipc > m_ipc
#define Assert(val)
Identity function.
Definition: check.h:57
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:93
Initial interface created when a process is first started, and used to give and get access to other i...
Definition: init.h:27
Interface providing access to interprocess-communication (IPC) functionality.
Definition: ipc.h:45
std::unique_ptr< Chain > MakeChain(NodeContext &node)
Return implementation of Chain interface.
Definition: interfaces.cpp:714
std::unique_ptr< Echo > MakeEcho()
Return implementation of Echo interface.
Definition: echo.cpp:17
std::unique_ptr< Ipc > MakeIpc(const char *exe_name, const char *process_argv0, Init &init)
Return implementation of Ipc interface.
Definition: interfaces.cpp:74
std::unique_ptr< WalletClient > MakeWalletClient(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet client.
Definition: dummywallet.cpp:67
std::unique_ptr< Node > MakeNode(NodeContext &context)
Return implementation of Node interface.
Definition: interfaces.cpp:713
std::unique_ptr< Init > MakeNodeInit(NodeContext &node, int argc, char *argv[], int &exit_status)
Return implementation of Init interface for the node process.
Definition: ipc.h:12
NodeContext struct containing references to chain state and connection state.
Definition: context.h:39
interfaces::Init * init
Init interface for initializing current process and connecting to other processes.
Definition: context.h:41
ArgsManager * args
Definition: context.h:49
ArgsManager gArgs
Definition: system.cpp:85