limenka-gui.cpp raw

   1  // Copyright (c) 2021-2022 The Limenka 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 = "limenka-gui";
  20  
  21  class LimenkaGuiInit : public interfaces::Init
  22  {
  23  public:
  24      LimenkaGuiInit(const char* arg0) : m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this))
  25      {
  26          InitContext(m_node);
  27          m_node.init = this;
  28      }
  29      std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
  30      std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }
  31      std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain) override
  32      {
  33          return MakeWalletLoader(chain, *Assert(m_node.args));
  34      }
  35      std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
  36      interfaces::Ipc* ipc() override { return m_ipc.get(); }
  37      // limenka-gui accepts -ipcbind option even though it does not use it
  38      // directly. It just returns true here to accept the option because
  39      // limenka-node accepts the option, and limenka-gui accepts all limenka-node
  40      // options and will start the node with those options.
  41      bool canListenIpc() override { return true; }
  42      node::NodeContext m_node;
  43      std::unique_ptr<interfaces::Ipc> m_ipc;
  44  };
  45  } // namespace
  46  } // namespace init
  47  
  48  namespace interfaces {
  49  std::unique_ptr<Init> MakeGuiInit(int argc, char* argv[])
  50  {
  51      return std::make_unique<init::LimenkaGuiInit>(argc > 0 ? argv[0] : "");
  52  }
  53  } // namespace interfaces
  54