bitcoin-gui.cpp raw
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 #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/mining.h>
11 #include <interfaces/node.h>
12 #include <interfaces/rpc.h>
13 #include <interfaces/wallet.h>
14 #include <node/context.h>
15 #include <util/check.h>
16
17 #include <memory>
18
19 namespace init {
20 namespace {
21 const char* EXE_NAME = "bitcoin-gui";
22
23 class BitcoinGuiInit : public interfaces::Init
24 {
25 public:
26 BitcoinGuiInit(const char* arg0) : 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 std::unique_ptr<interfaces::Rpc> makeRpc() override { return interfaces::MakeRpc(m_node); }
40 interfaces::Ipc* ipc() override { return m_ipc.get(); }
41 // bitcoin-gui accepts -ipcbind option even though it does not use it
42 // directly. It just returns true here to accept the option because
43 // bitcoin-node accepts the option, and bitcoin-gui accepts all bitcoin-node
44 // options and will start the node with those options.
45 bool canListenIpc() override { return true; }
46 const char* exeName() override { return EXE_NAME; }
47 node::NodeContext m_node;
48 std::unique_ptr<interfaces::Ipc> m_ipc;
49 };
50 } // namespace
51 } // namespace init
52
53 namespace interfaces {
54 std::unique_ptr<Init> MakeGuiInit(int argc, char* argv[])
55 {
56 return std::make_unique<init::BitcoinGuiInit>(argc > 0 ? argv[0] : "");
57 }
58 } // namespace interfaces
59