bitcoin.h raw
1 // Copyright (c) 2011-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 #ifndef BITCOIN_QT_BITCOIN_H
6 #define BITCOIN_QT_BITCOIN_H
7
8 #include <bitcoin-build-config.h> // IWYU pragma: keep
9
10 #include <interfaces/node.h>
11 #include <qt/initexecutor.h>
12
13 #include <cassert>
14 #include <memory>
15 #include <optional>
16
17 #include <QApplication>
18
19 class BitcoinGUI;
20 class ClientModel;
21 class NetworkStyle;
22 class OptionsModel;
23 class PaymentServer;
24 class PlatformStyle;
25 class SplashScreen;
26 class WalletController;
27 class WalletModel;
28 namespace interfaces {
29 class Init;
30 } // namespace interfaces
31
32
33 /** Main Bitcoin application object */
34 class BitcoinApplication: public QApplication
35 {
36 Q_OBJECT
37 public:
38 explicit BitcoinApplication();
39 ~BitcoinApplication();
40
41 #ifdef ENABLE_WALLET
42 /// Create payment server
43 void createPaymentServer();
44 #endif
45 /// parameter interaction/setup based on rules
46 void parameterSetup();
47 /// Create options model
48 [[nodiscard]] bool createOptionsModel(bool resetSettings);
49 /// Initialize prune setting
50 void InitPruneSetting(int64_t prune_MiB);
51 /// Create main window
52 void createWindow(const NetworkStyle *networkStyle);
53 /// Create splash screen
54 void createSplashScreen(const NetworkStyle *networkStyle);
55 /// Create or spawn node
56 void createNode(interfaces::Init& init);
57 /// Basic initialization, before starting initialization/shutdown thread. Return true on success.
58 bool baseInitialize();
59
60 /// Request core initialization
61 void requestInitialize();
62
63 /// Get window identifier of QMainWindow (BitcoinGUI)
64 WId getMainWinId() const;
65
66 /// Setup platform style
67 void setupPlatformStyle();
68
69 interfaces::Node& node() const { assert(m_node); return *m_node; }
70
71 public Q_SLOTS:
72 void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info);
73 /// Request core shutdown
74 void requestShutdown();
75 /// Handle runaway exceptions. Shows a message box with the problem and quits the program.
76 void handleRunawayException(const QString &message);
77
78 /**
79 * A helper function that shows a message box
80 * with details about a non-fatal exception.
81 */
82 void handleNonFatalException(const QString& message);
83
84 Q_SIGNALS:
85 void requestedInitialize();
86 void requestedShutdown();
87 void windowShown(BitcoinGUI* window);
88
89 protected:
90 bool event(QEvent* e) override;
91
92 private:
93 std::optional<InitExecutor> m_executor;
94 OptionsModel* optionsModel{nullptr};
95 ClientModel* clientModel{nullptr};
96 BitcoinGUI* window{nullptr};
97 QTimer* pollShutdownTimer{nullptr};
98 #ifdef ENABLE_WALLET
99 PaymentServer* paymentServer{nullptr};
100 WalletController* m_wallet_controller{nullptr};
101 #endif
102 const PlatformStyle* platformStyle{nullptr};
103 std::unique_ptr<QWidget> shutdownWindow;
104 SplashScreen* m_splash = nullptr;
105 std::unique_ptr<interfaces::Node> m_node;
106
107 void startThread();
108 };
109
110 int GuiMain(int argc, char* argv[]);
111
112 #endif // BITCOIN_QT_BITCOIN_H
113