Branch data Line data Source code
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 : :
17 : : namespace init {
18 : : namespace {
19 : : const char* EXE_NAME = "bitcoin-node";
20 : :
21 : : class BitcoinNodeInit : public interfaces::Init
22 : : {
23 : : public:
24 : 0 : BitcoinNodeInit(node::NodeContext& node, const char* arg0)
25 : 0 : : m_node(node),
26 [ # # ]: 0 : m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this))
27 : : {
28 [ # # ]: 0 : InitContext(m_node);
29 : 0 : m_node.init = this;
30 : 0 : }
31 : 0 : std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
32 : 0 : std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }
33 : 0 : std::unique_ptr<interfaces::Mining> makeMining() override { return interfaces::MakeMining(m_node); }
34 : 0 : std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain) override
35 : : {
36 : 0 : return MakeWalletLoader(chain, *Assert(m_node.args));
37 : : }
38 : 0 : std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
39 : 0 : interfaces::Ipc* ipc() override { return m_ipc.get(); }
40 : 0 : bool canListenIpc() override { return true; }
41 : : node::NodeContext& m_node;
42 : : std::unique_ptr<interfaces::Ipc> m_ipc;
43 : : };
44 : : } // namespace
45 : : } // namespace init
46 : :
47 : : namespace interfaces {
48 : 0 : std::unique_ptr<Init> MakeNodeInit(node::NodeContext& node, int argc, char* argv[], int& exit_status)
49 : : {
50 [ # # ]: 0 : auto init = std::make_unique<init::BitcoinNodeInit>(node, argc > 0 ? argv[0] : "");
51 : : // Check if bitcoin-node is being invoked as an IPC server. If so, then
52 : : // bypass normal execution and just respond to requests over the IPC
53 : : // channel and return null.
54 [ # # # # ]: 0 : if (init->m_ipc->startSpawnedProcess(argc, argv, exit_status)) {
55 : 0 : return nullptr;
56 : : }
57 : 0 : return init;
58 : 0 : }
59 : : } // namespace interfaces
|