diff options
author | Russell Yanofsky <russ@yanofsky.org> | 2017-12-05 15:57:12 -0500 |
---|---|---|
committer | Russell Yanofsky <russ@yanofsky.org> | 2021-08-17 03:05:15 -0500 |
commit | e4709c7b56612553fb7cbf16ef2d5099c5b732d0 (patch) | |
tree | 3184f2fcce535f256d986e94b8d5b359223db150 /src/qt | |
parent | fdd80b0a53b4af0b29cb6e03118e2456d053a757 (diff) |
Start using init makeNode, makeChain, etc methods
Use interfaces::Init::make* methods instead of interfaces::Make*
functions, so interfaces can be constructed differently in different
executables without having to change any code. (So for example
bitcoin-gui can make an interfaces::Node pointer that communicates with
a bitcoin-node subprocess, while bitcoin-qt can make an interfaces::Node
pointer that starts node code in the same process.)
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/bitcoin.cpp | 16 | ||||
-rw-r--r-- | src/qt/bitcoin.h | 8 | ||||
-rw-r--r-- | src/qt/test/test_main.cpp | 7 | ||||
-rw-r--r-- | src/qt/test/wallettests.cpp | 2 |
4 files changed, 21 insertions, 12 deletions
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index f6ea147ddb..d4895ea6ff 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -11,6 +11,7 @@ #include <chainparams.h> #include <init.h> #include <interfaces/handler.h> +#include <interfaces/init.h> #include <interfaces/node.h> #include <node/context.h> #include <node/ui_interface.h> @@ -275,10 +276,10 @@ void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle) connect(this, &BitcoinApplication::requestedShutdown, m_splash, &QWidget::close); } -void BitcoinApplication::setNode(interfaces::Node& node) +void BitcoinApplication::createNode(interfaces::Init& init) { assert(!m_node); - m_node = &node; + m_node = init.makeNode(); if (optionsModel) optionsModel->setNode(*m_node); if (m_splash) m_splash->setNode(*m_node); } @@ -460,11 +461,13 @@ int GuiMain(int argc, char* argv[]) util::WinCmdLineArgs winArgs; std::tie(argc, argv) = winArgs.get(); #endif - SetupEnvironment(); - util::ThreadSetInternalName("main"); NodeContext node_context; - std::unique_ptr<interfaces::Node> node = interfaces::MakeNode(&node_context); + int unused_exit_status; + std::unique_ptr<interfaces::Init> init = interfaces::MakeNodeInit(node_context, argc, argv, unused_exit_status); + + SetupEnvironment(); + util::ThreadSetInternalName("main"); // Subscribe to global signals from core boost::signals2::scoped_connection handler_message_box = ::uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox); @@ -492,7 +495,6 @@ int GuiMain(int argc, char* argv[]) /// 2. Parse command-line options. We do this after qt in order to show an error if there are problems parsing these // Command-line options take precedence: - node_context.args = &gArgs; SetupServerArgs(gArgs); SetupUIArgs(gArgs); std::string error; @@ -623,7 +625,7 @@ int GuiMain(int argc, char* argv[]) if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false)) app.createSplashScreen(networkStyle.data()); - app.setNode(*node); + app.createNode(*init); int rv = EXIT_SUCCESS; try diff --git a/src/qt/bitcoin.h b/src/qt/bitcoin.h index ed2f26b7f3..602b76052c 100644 --- a/src/qt/bitcoin.h +++ b/src/qt/bitcoin.h @@ -27,6 +27,9 @@ class PlatformStyle; class SplashScreen; class WalletController; class WalletModel; +namespace interfaces { +class Init; +} // namespace interfaces /** Main Bitcoin application object */ @@ -51,6 +54,8 @@ public: void createWindow(const NetworkStyle *networkStyle); /// Create splash screen void createSplashScreen(const NetworkStyle *networkStyle); + /// Create or spawn node + void createNode(interfaces::Init& init); /// Basic initialization, before starting initialization/shutdown thread. Return true on success. bool baseInitialize(); @@ -69,7 +74,6 @@ public: void setupPlatformStyle(); interfaces::Node& node() const { assert(m_node); return *m_node; } - void setNode(interfaces::Node& node); public Q_SLOTS: void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info); @@ -103,7 +107,7 @@ private: const PlatformStyle *platformStyle; std::unique_ptr<QWidget> shutdownWindow; SplashScreen* m_splash = nullptr; - interfaces::Node* m_node = nullptr; + std::unique_ptr<interfaces::Node> m_node; void startThread(); }; diff --git a/src/qt/test/test_main.cpp b/src/qt/test/test_main.cpp index 7d66f67f8a..884ed25637 100644 --- a/src/qt/test/test_main.cpp +++ b/src/qt/test/test_main.cpp @@ -6,6 +6,7 @@ #include <config/bitcoin-config.h> #endif +#include <interfaces/init.h> #include <interfaces/node.h> #include <qt/bitcoin.h> #include <qt/initexecutor.h> @@ -53,7 +54,8 @@ int main(int argc, char* argv[]) } NodeContext node_context; - std::unique_ptr<interfaces::Node> node = interfaces::MakeNode(&node_context); + int unused_exit_status; + std::unique_ptr<interfaces::Init> init = interfaces::MakeNodeInit(node_context, argc, argv, unused_exit_status); gArgs.ForceSetArg("-listen", "0"); gArgs.ForceSetArg("-listenonion", "0"); gArgs.ForceSetArg("-discover", "0"); @@ -76,10 +78,9 @@ int main(int argc, char* argv[]) // Don't remove this, it's needed to access // QApplication:: and QCoreApplication:: in the tests BitcoinApplication app; - app.setNode(*node); app.setApplicationName("Bitcoin-Qt-test"); + app.createNode(*init); - app.node().context()->args = &gArgs; // Make gArgs available in the NodeContext AppTests app_tests(app); if (QTest::qExec(&app_tests) != 0) { fInvalid = true; diff --git a/src/qt/test/wallettests.cpp b/src/qt/test/wallettests.cpp index e883337fb5..1b80193d4f 100644 --- a/src/qt/test/wallettests.cpp +++ b/src/qt/test/wallettests.cpp @@ -138,6 +138,8 @@ void TestGUI(interfaces::Node& node) for (int i = 0; i < 5; ++i) { test.CreateAndProcessBlock({}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey())); } + auto wallet_client = interfaces::MakeWalletClient(*test.m_node.chain, *Assert(test.m_node.args)); + test.m_node.wallet_client = wallet_client.get(); node.setContext(&test.m_node); std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockWalletDatabase()); wallet->LoadWallet(); |