Bitcoin Core  0.21.1
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules
bitcoin.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2020 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 #if defined(HAVE_CONFIG_H)
7 #endif
8 
9 #include <qt/bitcoin.h>
10 #include <qt/bitcoingui.h>
11 
12 #include <chainparams.h>
13 #include <qt/clientmodel.h>
14 #include <qt/guiconstants.h>
15 #include <qt/guiutil.h>
16 #include <qt/intro.h>
17 #include <qt/networkstyle.h>
18 #include <qt/optionsmodel.h>
19 #include <qt/platformstyle.h>
20 #include <qt/splashscreen.h>
21 #include <qt/utilitydialog.h>
22 #include <qt/winshutdownmonitor.h>
23 
24 #ifdef ENABLE_WALLET
25 #include <qt/paymentserver.h>
26 #include <qt/walletcontroller.h>
27 #include <qt/walletmodel.h>
28 #endif // ENABLE_WALLET
29 
30 #include <init.h>
31 #include <interfaces/handler.h>
32 #include <interfaces/node.h>
33 #include <node/context.h>
34 #include <node/ui_interface.h>
35 #include <noui.h>
36 #include <uint256.h>
37 #include <util/system.h>
38 #include <util/threadnames.h>
39 #include <util/translation.h>
40 #include <validation.h>
41 
42 #include <boost/signals2/connection.hpp>
43 #include <memory>
44 
45 #include <QApplication>
46 #include <QDebug>
47 #include <QLibraryInfo>
48 #include <QLocale>
49 #include <QMessageBox>
50 #include <QSettings>
51 #include <QThread>
52 #include <QTimer>
53 #include <QTranslator>
54 #include <QtGlobal>
55 
56 #if defined(QT_STATICPLUGIN)
57 #include <QtPlugin>
58 #if defined(QT_QPA_PLATFORM_XCB)
59 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
60 #elif defined(QT_QPA_PLATFORM_WINDOWS)
61 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
62 #elif defined(QT_QPA_PLATFORM_COCOA)
63 Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
64 #endif
65 #endif
66 
67 // Declare meta types used for QMetaObject::invokeMethod
68 Q_DECLARE_METATYPE(bool*)
69 Q_DECLARE_METATYPE(CAmount)
70 Q_DECLARE_METATYPE(SynchronizationState)
71 Q_DECLARE_METATYPE(uint256)
72 
73 static void RegisterMetaTypes()
74 {
75  // Register meta types used for QMetaObject::invokeMethod and Qt::QueuedConnection
76  qRegisterMetaType<bool*>();
77  qRegisterMetaType<SynchronizationState>();
78  #ifdef ENABLE_WALLET
79  qRegisterMetaType<WalletModel*>();
80  #endif
81  // Register typedefs (see http://qt-project.org/doc/qt-5/qmetatype.html#qRegisterMetaType)
82  // IMPORTANT: if CAmount is no longer a typedef use the normal variant above (see https://doc.qt.io/qt-5/qmetatype.html#qRegisterMetaType-1)
83  qRegisterMetaType<CAmount>("CAmount");
84  qRegisterMetaType<size_t>("size_t");
85 
86  qRegisterMetaType<std::function<void()>>("std::function<void()>");
87  qRegisterMetaType<QMessageBox::Icon>("QMessageBox::Icon");
88  qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>("interfaces::BlockAndHeaderTipInfo");
89 }
90 
91 static QString GetLangTerritory()
92 {
93  QSettings settings;
94  // Get desired locale (e.g. "de_DE")
95  // 1) System default language
96  QString lang_territory = QLocale::system().name();
97  // 2) Language from QSettings
98  QString lang_territory_qsettings = settings.value("language", "").toString();
99  if(!lang_territory_qsettings.isEmpty())
100  lang_territory = lang_territory_qsettings;
101  // 3) -lang command line argument
102  lang_territory = QString::fromStdString(gArgs.GetArg("-lang", lang_territory.toStdString()));
103  return lang_territory;
104 }
105 
107 static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
108 {
109  // Remove old translators
110  QApplication::removeTranslator(&qtTranslatorBase);
111  QApplication::removeTranslator(&qtTranslator);
112  QApplication::removeTranslator(&translatorBase);
113  QApplication::removeTranslator(&translator);
114 
115  // Get desired locale (e.g. "de_DE")
116  // 1) System default language
117  QString lang_territory = GetLangTerritory();
118 
119  // Convert to "de" only by truncating "_DE"
120  QString lang = lang_territory;
121  lang.truncate(lang_territory.lastIndexOf('_'));
122 
123  // Load language files for configured locale:
124  // - First load the translator for the base language, without territory
125  // - Then load the more specific locale translator
126 
127  // Load e.g. qt_de.qm
128  if (qtTranslatorBase.load("qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
129  QApplication::installTranslator(&qtTranslatorBase);
130 
131  // Load e.g. qt_de_DE.qm
132  if (qtTranslator.load("qt_" + lang_territory, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
133  QApplication::installTranslator(&qtTranslator);
134 
135  // Load e.g. bitcoin_de.qm (shortcut "de" needs to be defined in bitcoin.qrc)
136  if (translatorBase.load(lang, ":/translations/"))
137  QApplication::installTranslator(&translatorBase);
138 
139  // Load e.g. bitcoin_de_DE.qm (shortcut "de_DE" needs to be defined in bitcoin.qrc)
140  if (translator.load(lang_territory, ":/translations/"))
141  QApplication::installTranslator(&translator);
142 }
143 
144 /* qDebug() message handler --> debug.log */
145 void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString &msg)
146 {
147  Q_UNUSED(context);
148  if (type == QtDebugMsg) {
149  LogPrint(BCLog::QT, "GUI: %s\n", msg.toStdString());
150  } else {
151  LogPrintf("GUI: %s\n", msg.toStdString());
152  }
153 }
154 
156  QObject(), m_node(node)
157 {
158 }
159 
160 void BitcoinCore::handleRunawayException(const std::exception *e)
161 {
162  PrintExceptionContinue(e, "Runaway exception");
163  Q_EMIT runawayException(QString::fromStdString(m_node.getWarnings().translated));
164 }
165 
167 {
168  try
169  {
170  util::ThreadRename("qt-init");
171  qDebug() << __func__ << ": Running initialization in thread";
173  bool rv = m_node.appInitMain(&tip_info);
174  Q_EMIT initializeResult(rv, tip_info);
175  } catch (const std::exception& e) {
177  } catch (...) {
178  handleRunawayException(nullptr);
179  }
180 }
181 
183 {
184  try
185  {
186  qDebug() << __func__ << ": Running Shutdown in thread";
188  qDebug() << __func__ << ": Shutdown finished";
189  Q_EMIT shutdownResult();
190  } catch (const std::exception& e) {
192  } catch (...) {
193  handleRunawayException(nullptr);
194  }
195 }
196 
197 static int qt_argc = 1;
198 static const char* qt_argv = "bitcoin-qt";
199 
201  QApplication(qt_argc, const_cast<char **>(&qt_argv)),
202  coreThread(nullptr),
203  optionsModel(nullptr),
204  clientModel(nullptr),
205  window(nullptr),
206  pollShutdownTimer(nullptr),
207  returnValue(0),
208  platformStyle(nullptr)
209 {
210  // Qt runs setlocale(LC_ALL, "") on initialization.
212  setQuitOnLastWindowClosed(false);
213 }
214 
216 {
217  // UI per-platform customization
218  // This must be done inside the BitcoinApplication constructor, or after it, because
219  // PlatformStyle::instantiate requires a QApplication
220  std::string platformName;
221  platformName = gArgs.GetArg("-uiplatform", BitcoinGUI::DEFAULT_UIPLATFORM);
222  platformStyle = PlatformStyle::instantiate(QString::fromStdString(platformName));
223  if (!platformStyle) // Fall back to "other" if specified name not found
225  assert(platformStyle);
226 }
227 
229 {
230  if(coreThread)
231  {
232  qDebug() << __func__ << ": Stopping thread";
233  coreThread->quit();
234  coreThread->wait();
235  qDebug() << __func__ << ": Stopped thread";
236  }
237 
238  delete window;
239  window = nullptr;
240  delete platformStyle;
241  platformStyle = nullptr;
242 }
243 
244 #ifdef ENABLE_WALLET
245 void BitcoinApplication::createPaymentServer()
246 {
247  paymentServer = new PaymentServer(this);
248 }
249 #endif
250 
252 {
253  optionsModel = new OptionsModel(this, resetSettings);
254 }
255 
257 {
258  window = new BitcoinGUI(node(), platformStyle, networkStyle, nullptr);
259 
260  pollShutdownTimer = new QTimer(window);
261  connect(pollShutdownTimer, &QTimer::timeout, window, &BitcoinGUI::detectShutdown);
262 }
263 
265 {
266  assert(!m_splash);
267  m_splash = new SplashScreen(nullptr, networkStyle);
268  // We don't hold a direct pointer to the splash screen after creation, but the splash
269  // screen will take care of deleting itself when finish() happens.
270  m_splash->show();
273  connect(this, &BitcoinApplication::requestedShutdown, m_splash, &QWidget::close);
274 }
275 
277 {
278  assert(!m_node);
279  m_node = &node;
282 }
283 
285 {
286  return node().baseInitialize();
287 }
288 
290 {
291  if(coreThread)
292  return;
293  coreThread = new QThread(this);
294  BitcoinCore *executor = new BitcoinCore(node());
295  executor->moveToThread(coreThread);
296 
297  /* communication to and from thread */
303  /* make sure executor object is deleted in its own thread */
304  connect(coreThread, &QThread::finished, executor, &QObject::deleteLater);
305 
306  coreThread->start();
307 }
308 
310 {
311  // Default printtoconsole to false for the GUI. GUI programs should not
312  // print to the console unnecessarily.
313  gArgs.SoftSetBoolArg("-printtoconsole", false);
314 
317 }
318 
320 {
321  // If prune is set, intentionally override existing prune size with
322  // the default size since this is called when choosing a new datadir.
324 }
325 
327 {
328  qDebug() << __func__ << ": Requesting initialize";
329  startThread();
330  Q_EMIT requestedInitialize();
331 }
332 
334 {
335  // Show a simple window indicating shutdown status
336  // Do this first as some of the steps may take some time below,
337  // for example the RPC console may still be executing a command.
339 
340  qDebug() << __func__ << ": Requesting shutdown";
341  startThread();
342  window->hide();
343  // Must disconnect node signals otherwise current thread can deadlock since
344  // no event loop is running.
346  // Request node shutdown, which can interrupt long operations, like
347  // rescanning a wallet.
348  node().startShutdown();
349  // Unsetting the client model can cause the current thread to wait for node
350  // to complete an operation, like wait for a RPC execution to complete.
351  window->setClientModel(nullptr);
352  pollShutdownTimer->stop();
353 
354  delete clientModel;
355  clientModel = nullptr;
356 
357  // Request shutdown from core thread
358  Q_EMIT requestedShutdown();
359 }
360 
362 {
363  qDebug() << __func__ << ": Initialization result: " << success;
364  // Set exit result.
365  returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE;
366  if(success)
367  {
368  // Log this only after AppInitMain finishes, as then logging setup is guaranteed complete
369  qInfo() << "Platform customization:" << platformStyle->getName();
371  window->setClientModel(clientModel, &tip_info);
372 #ifdef ENABLE_WALLET
374  m_wallet_controller = new WalletController(*clientModel, platformStyle, this);
375  window->setWalletController(m_wallet_controller);
376  if (paymentServer) {
377  paymentServer->setOptionsModel(optionsModel);
378  }
379  }
380 #endif // ENABLE_WALLET
381 
382  // If -min option passed, start window minimized (iconified) or minimized to tray
383  if (!gArgs.GetBoolArg("-min", false)) {
384  window->show();
386  // do nothing as the window is managed by the tray icon
387  } else {
388  window->showMinimized();
389  }
390  Q_EMIT splashFinished();
391  Q_EMIT windowShown(window);
392 
393 #ifdef ENABLE_WALLET
394  // Now that initialization/startup is done, process any command-line
395  // bitcoin: URIs or payment requests:
396  if (paymentServer) {
397  connect(paymentServer, &PaymentServer::receivedPaymentRequest, window, &BitcoinGUI::handlePaymentRequest);
399  connect(paymentServer, &PaymentServer::message, [this](const QString& title, const QString& message, unsigned int style) {
400  window->message(title, message, style);
401  });
402  QTimer::singleShot(100, paymentServer, &PaymentServer::uiReady);
403  }
404 #endif
405  pollShutdownTimer->start(200);
406  } else {
407  Q_EMIT splashFinished(); // Make sure splash screen doesn't stick around during shutdown
408  quit(); // Exit first main loop invocation
409  }
410 }
411 
413 {
414  quit(); // Exit second main loop invocation after shutdown finished
415 }
416 
417 void BitcoinApplication::handleRunawayException(const QString &message)
418 {
419  QMessageBox::critical(nullptr, "Runaway exception", BitcoinGUI::tr("A fatal error occurred. %1 can no longer continue safely and will quit.").arg(PACKAGE_NAME) + QString("<br><br>") + message);
420  ::exit(EXIT_FAILURE);
421 }
422 
424 {
425  if (!window)
426  return 0;
427 
428  return window->winId();
429 }
430 
431 static void SetupUIArgs(ArgsManager& argsman)
432 {
433  argsman.AddArg("-choosedatadir", strprintf("Choose data directory on startup (default: %u)", DEFAULT_CHOOSE_DATADIR), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
434  argsman.AddArg("-lang=<lang>", "Set language, for example \"de_DE\" (default: system locale)", ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
435  argsman.AddArg("-min", "Start minimized", ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
436  argsman.AddArg("-resetguisettings", "Reset all settings changed in the GUI", ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
437  argsman.AddArg("-splash", strprintf("Show splash screen on startup (default: %u)", DEFAULT_SPLASHSCREEN), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
438  argsman.AddArg("-uiplatform", strprintf("Select platform to customize UI for (one of windows, macosx, other; default: %s)", BitcoinGUI::DEFAULT_UIPLATFORM), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::GUI);
439 }
440 
441 int GuiMain(int argc, char* argv[])
442 {
443 #ifdef WIN32
444  util::WinCmdLineArgs winArgs;
445  std::tie(argc, argv) = winArgs.get();
446 #endif
449 
450  NodeContext node_context;
451  std::unique_ptr<interfaces::Node> node = interfaces::MakeNode(&node_context);
452 
453  // Subscribe to global signals from core
454  boost::signals2::scoped_connection handler_message_box = ::uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox);
455  boost::signals2::scoped_connection handler_question = ::uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
456  boost::signals2::scoped_connection handler_init_message = ::uiInterface.InitMessage_connect(noui_InitMessage);
457 
458  // Do not refer to data directory yet, this can be overridden by Intro::pickDataDirectory
459 
461  Q_INIT_RESOURCE(bitcoin);
462  Q_INIT_RESOURCE(bitcoin_locale);
463 
464  // Generate high-dpi pixmaps
465  QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
466 #if QT_VERSION >= 0x050600
467  QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
468 #endif
469 
470 #if (QT_VERSION <= QT_VERSION_CHECK(5, 9, 8)) && defined(Q_OS_MACOS)
471  const auto os_name = QSysInfo::prettyProductName();
472  if (os_name.startsWith("macOS 11") || os_name.startsWith("macOS 10.16")) {
473  QApplication::setStyle("fusion");
474  }
475 #endif
476 
477  BitcoinApplication app;
478 
480  // Command-line options take precedence:
481  SetupServerArgs(node_context);
483  std::string error;
484  if (!gArgs.ParseParameters(argc, argv, error)) {
485  InitError(strprintf(Untranslated("Error parsing command line arguments: %s\n"), error));
486  // Create a message box, because the gui has neither been created nor has subscribed to core signals
487  QMessageBox::critical(nullptr, PACKAGE_NAME,
488  // message can not be translated because translations have not been initialized
489  QString::fromStdString("Error parsing command line arguments: %1.").arg(QString::fromStdString(error)));
490  return EXIT_FAILURE;
491  }
492 
493  // Now that the QApplication is setup and we have parsed our parameters, we can set the platform style
494  app.setupPlatformStyle();
495 
497  // must be set before OptionsModel is initialized or translations are loaded,
498  // as it is used to locate QSettings
499  QApplication::setOrganizationName(QAPP_ORG_NAME);
500  QApplication::setOrganizationDomain(QAPP_ORG_DOMAIN);
501  QApplication::setApplicationName(QAPP_APP_NAME_DEFAULT);
502 
504  // Now that QSettings are accessible, initialize translations
505  QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
506  initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
507 
508  // Show help message immediately after parsing command-line options (for "-lang") and setting locale,
509  // but before showing splash screen.
510  if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
511  HelpMessageDialog help(nullptr, gArgs.IsArgSet("-version"));
512  help.showOrPrint();
513  return EXIT_SUCCESS;
514  }
515 
516  // Install global event filter that makes sure that long tooltips can be word-wrapped
517  app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app));
518 
520  // User language is set up: pick a data directory
521  bool did_show_intro = false;
522  bool prune = false; // Intro dialog prune check box
523  // Gracefully exit if the user cancels
524  if (!Intro::showIfNeeded(did_show_intro, prune)) return EXIT_SUCCESS;
525 
528  if (!CheckDataDirOption()) {
529  InitError(strprintf(Untranslated("Specified data directory \"%s\" does not exist.\n"), gArgs.GetArg("-datadir", "")));
530  QMessageBox::critical(nullptr, PACKAGE_NAME,
531  QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(gArgs.GetArg("-datadir", ""))));
532  return EXIT_FAILURE;
533  }
534  if (!gArgs.ReadConfigFiles(error, true)) {
535  InitError(strprintf(Untranslated("Error reading configuration file: %s\n"), error));
536  QMessageBox::critical(nullptr, PACKAGE_NAME,
537  QObject::tr("Error: Cannot parse configuration file: %1.").arg(QString::fromStdString(error)));
538  return EXIT_FAILURE;
539  }
540 
542  // - Do not call Params() before this step
543  // - Do this after parsing the configuration file, as the network can be switched there
544  // - QSettings() will use the new application name after this, resulting in network-specific settings
545  // - Needs to be done before createOptionsModel
546 
547  // Check for chain settings (Params() calls are only valid after this clause)
548  try {
550  } catch(std::exception &e) {
551  InitError(Untranslated(strprintf("%s\n", e.what())));
552  QMessageBox::critical(nullptr, PACKAGE_NAME, QObject::tr("Error: %1").arg(e.what()));
553  return EXIT_FAILURE;
554  }
555 #ifdef ENABLE_WALLET
556  // Parse URIs on command line -- this can affect Params()
558 #endif
559  if (!gArgs.InitSettings(error)) {
560  InitError(Untranslated(error));
561  QMessageBox::critical(nullptr, PACKAGE_NAME, QObject::tr("Error initializing settings: %1").arg(QString::fromStdString(error)));
562  return EXIT_FAILURE;
563  }
564 
565  QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(Params().NetworkIDString()));
566  assert(!networkStyle.isNull());
567  // Allow for separate UI settings for testnets
568  QApplication::setApplicationName(networkStyle->getAppName());
569  // Re-initialize translations after changing application name (language in network-specific settings can be different)
570  initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
571 
572 #ifdef ENABLE_WALLET
573  // - Do this early as we don't want to bother initializing if we are just calling IPC
575  // - Do this *after* setting up the data directory, as the data directory hash is used in the name
576  // of the server.
577  // - Do this after creating app and setting up translations, so errors are
578  // translated properly.
580  exit(EXIT_SUCCESS);
581 
582  // Start up the payment server early, too, so impatient users that click on
583  // bitcoin: links repeatedly have their payment requests routed to this process:
585  app.createPaymentServer();
586  }
587 #endif // ENABLE_WALLET
588 
590  // Install global event filter that makes sure that out-of-focus labels do not contain text cursor.
591  app.installEventFilter(new GUIUtil::LabelOutOfFocusEventFilter(&app));
592 #if defined(Q_OS_WIN)
593  // Install global event filter for processing Windows session related Windows messages (WM_QUERYENDSESSION and WM_ENDSESSION)
594  qApp->installNativeEventFilter(new WinShutdownMonitor());
595 #endif
596  // Install qDebug() message handler to route to debug.log
597  qInstallMessageHandler(DebugMessageHandler);
598  // Allow parameter interaction before we create the options model
599  app.parameterSetup();
601  // Load GUI settings from QSettings
602  app.createOptionsModel(gArgs.GetBoolArg("-resetguisettings", false));
603 
604  if (did_show_intro) {
605  // Store intro dialog settings other than datadir (network specific)
606  app.InitializePruneSetting(prune);
607  }
608 
609  if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false))
610  app.createSplashScreen(networkStyle.data());
611 
612  app.setNode(*node);
613 
614  int rv = EXIT_SUCCESS;
615  try
616  {
617  app.createWindow(networkStyle.data());
618  // Perform base initialization before spinning up initialization/shutdown thread
619  // This is acceptable because this function only contains steps that are quick to execute,
620  // so the GUI thread won't be held up.
621  if (app.baseInitialize()) {
622  app.requestInitialize();
623 #if defined(Q_OS_WIN)
624  WinShutdownMonitor::registerShutdownBlockReason(QObject::tr("%1 didn't yet exit safely...").arg(PACKAGE_NAME), (HWND)app.getMainWinId());
625 #endif
626  app.exec();
627  app.requestShutdown();
628  app.exec();
629  rv = app.getReturnValue();
630  } else {
631  // A dialog with detailed error will have been shown by InitError()
632  rv = EXIT_FAILURE;
633  }
634  } catch (const std::exception& e) {
635  PrintExceptionContinue(&e, "Runaway exception");
636  app.handleRunawayException(QString::fromStdString(app.node().getWarnings().translated));
637  } catch (...) {
638  PrintExceptionContinue(nullptr, "Runaway exception");
639  app.handleRunawayException(QString::fromStdString(app.node().getWarnings().translated));
640  }
641  return rv;
642 }
NODISCARD bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
Definition: system.cpp:845
OptionsModel * optionsModel
Definition: bitcoin.h:110
void unsubscribeFromCoreSignals()
Disconnect core signals from GUI client.
static const bool DEFAULT_CHOOSE_DATADIR
Definition: intro.h:12
bool noui_ThreadSafeQuestion(const bilingual_str &, const std::string &message, const std::string &caption, unsigned int style)
Non-GUI handler, which logs and prints questions.
Definition: noui.cpp:49
static constexpr int DEFAULT_PRUNE_TARGET_GB
Definition: guiconstants.h:56
void setupPlatformStyle()
Setup platform style.
Definition: bitcoin.cpp:215
void receivedURI(const QString &uri)
Signal raised when a URI was entered or dragged to the GUI.
void InitLogging(const ArgsManager &args)
Initialize global loggers.
Definition: init.cpp:871
void LogQtInfo()
Writes to debug.log short info about the used Qt and the host system.
Definition: guiutil.cpp:897
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:106
void message(const QString &title, const QString &message, unsigned int style)
#define LogPrint(category,...)
Definition: logging.h:182
static int qt_argc
Definition: bitcoin.cpp:197
static bool isWalletEnabled()
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
Definition: system.cpp:493
Class for the splashscreen with information of the running client.
Definition: splashscreen.h:26
static const NetworkStyle * instantiate(const std::string &networkId)
Get style associated with provided network id, or 0 if not known.
Class encapsulating Bitcoin Core startup and shutdown.
Definition: bitcoin.h:32
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:479
void setNode(interfaces::Node &node)
virtual bool baseInitialize()=0
Initialize app dependencies.
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
void parameterSetup()
parameter interaction/setup based on rules
Definition: bitcoin.cpp:309
void handleRunawayException(const std::exception *e)
Pass fatal exception message to UI thread.
Definition: bitcoin.cpp:160
virtual void startShutdown()=0
Start shutdown.
bool noui_ThreadSafeMessageBox(const bilingual_str &message, const std::string &caption, unsigned int style)
Non-GUI handler, which logs and prints messages.
Definition: noui.cpp:22
static void LogPrintf(const char *fmt, const Args &...args)
Definition: logging.h:166
NodeContext & m_node
Definition: chain.cpp:411
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:40
void handleRunawayException(const QString &message)
Handle runaway exceptions. Shows a message box with the problem and quits the program.
Definition: bitcoin.cpp:417
void SetPruneTargetGB(int prune_target_gb, bool force=false)
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name...
Definition: threadnames.cpp:57
void SetupEnvironment()
Definition: system.cpp:1228
void requestInitialize()
Request core initialization.
Definition: bitcoin.cpp:326
int getReturnValue() const
Get process return value.
Definition: bitcoin.h:85
#define PACKAGE_NAME
void setClientModel(ClientModel *clientModel=nullptr, interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)
Set the client model.
Definition: bitcoingui.cpp:577
Controller between interfaces::Node, WalletModel instances and the GUI.
OptionsModel * getOptionsModel()
void receivedPaymentRequest(SendCoinsRecipient)
NODISCARD bool ParseParameters(int argc, const char *const argv[], std::string &error)
Definition: system.cpp:284
std::string translated
Definition: translation.h:18
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
Definition: guiutil.h:150
Bitcoin GUI main class.
Definition: bitcoingui.h:66
static void SetupUIArgs(ArgsManager &argsman)
Definition: bitcoin.cpp:431
interfaces::Node & m_node
Definition: bitcoin.h:51
void createOptionsModel(bool resetSettings)
Create options model.
Definition: bitcoin.cpp:251
void noui_InitMessage(const std::string &message)
Non-GUI handler, which only logs a message.
Definition: noui.cpp:54
void requestedInitialize()
void SetupServerArgs(NodeContext &node)
Register all arguments with the ArgsManager.
Definition: init.cpp:371
Qt event filter that intercepts QEvent::FocusOut events for QLabel objects, and resets their `textInt...
Definition: guiutil.h:170
static const bool DEFAULT_SPLASHSCREEN
Definition: guiconstants.h:19
static void ipcParseCommandLine(int argc, char *argv[])
void setNode(interfaces::Node &node)
Definition: bitcoin.cpp:276
void handleURIOrFile(const QString &s)
static bool ipcSendCommandLine()
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
bool CheckDataDirOption()
Definition: system.cpp:751
void shutdown()
Definition: bitcoin.cpp:182
static QWidget * showShutdownWindow(QMainWindow *window)
BitcoinCore(interfaces::Node &node)
Definition: bitcoin.cpp:155
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: system.cpp:371
void finish()
Hide the splash screen window and schedule the splash screen object for deletion. ...
bool error(const char *fmt, const Args &...args)
Definition: system.h:52
#define QAPP_ORG_NAME
Definition: guiconstants.h:45
NodeContext struct containing references to chain state and connection state.
Definition: context.h:36
static void RegisterMetaTypes()
Definition: bitcoin.cpp:73
void createSplashScreen(const NetworkStyle *networkStyle)
Create splash screen.
Definition: bitcoin.cpp:264
Main Bitcoin application object.
Definition: bitcoin.h:55
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
virtual bilingual_str getWarnings()=0
Get warnings.
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
int GuiMain(int argc, char *argv[])
Definition: bitcoin.cpp:441
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
Definition: system.cpp:507
bool HelpRequested(const ArgsManager &args)
Definition: system.cpp:602
static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
Set up translations.
Definition: bitcoin.cpp:107
WId getMainWinId() const
Get window identifier of QMainWindow (BitcoinGUI)
Definition: bitcoin.cpp:423
void detectShutdown()
called by a timer to check if ShutdownRequested() has been set
SplashScreen * m_splash
Definition: bitcoin.h:121
Block and header tip information.
Definition: node.h:42
bool InitError(const bilingual_str &str)
Show error message.
std::unique_ptr< QWidget > shutdownWindow
Definition: bitcoin.h:120
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
Definition: system.cpp:644
void setNode(interfaces::Node &node)
Definition: optionsmodel.h:98
void initialize()
Definition: bitcoin.cpp:166
void windowShown(BitcoinGUI *window)
Model for Bitcoin network client.
Definition: clientmodel.h:46
const QString & getName() const
Definition: platformstyle.h:19
void shutdownResult()
Definition: bitcoin.cpp:412
void ThreadSetInternalName(std::string &&)
Set the internal (in-memory) name of the current thread only.
Definition: threadnames.cpp:63
bool getMinimizeToTray() const
Definition: optionsmodel.h:82
static const char * qt_argv
Definition: bitcoin.cpp:198
BitcoinGUI * window
Definition: bitcoin.h:112
void message(const QString &title, QString message, unsigned int style, bool *ret=nullptr, const QString &detailed_message=QString())
Notify the user of an event from the core network or transaction handling code.
void requestShutdown()
Request core shutdown.
Definition: bitcoin.cpp:333
QThread * coreThread
Definition: bitcoin.h:109
void DebugMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
Definition: bitcoin.cpp:145
256-bit opaque blob.
Definition: uint256.h:124
#define QAPP_APP_NAME_DEFAULT
Definition: guiconstants.h:47
virtual void appShutdown()=0
Stop node.
void handleLoadWallet()
Handle wallet load notifications.
bool hasTrayIcon() const
Get the tray icon status.
Definition: bitcoingui.h:99
void createWindow(const NetworkStyle *networkStyle)
Create main window.
Definition: bitcoin.cpp:256
static const int TOOLTIP_WRAP_THRESHOLD
Definition: guiconstants.h:40
bool InitSettings(std::string &error)
Read and update settings file with saved settings.
Definition: system.cpp:376
static const PlatformStyle * instantiate(const QString &platformId)
Get style associated with provided platform name, or 0 if not known.
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:39
#define QAPP_ORG_DOMAIN
Definition: guiconstants.h:46
const CChainParams & Params()
Return the currently selected parameters.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:467
static bool showIfNeeded(bool &did_show_intro, bool &prune)
Determine data directory.
Definition: intro.cpp:185
ArgsManager gArgs
Definition: system.cpp:77
interfaces::Node * m_node
Definition: bitcoin.h:122
"Help message" dialog box
Definition: utilitydialog.h:20
std::string GetChainName() const
Returns the appropriate chain name from the program arguments.
Definition: system.cpp:932
CClientUIInterface uiInterface
void shutdownResult()
static QString GetLangTerritory()
Definition: bitcoin.cpp:91
void InitializePruneSetting(bool prune)
Initialize prune setting.
Definition: bitcoin.cpp:319
static const std::string DEFAULT_UIPLATFORM
Definition: bitcoingui.h:71
void runawayException(const QString &message)
std::unique_ptr< Node > MakeNode(NodeContext *context)
Return implementation of Node interface.
Definition: node.cpp:301
static RPCHelpMan help()
Definition: server.cpp:133
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:52
bool baseInitialize()
Basic initialization, before starting initialization/shutdown thread. Return true on success...
Definition: bitcoin.cpp:284
ClientModel * clientModel
Definition: bitcoin.h:111
void InitParameterInteraction(ArgsManager &args)
Parameter interaction: change current parameters depending on various rules.
Definition: init.cpp:802
interfaces::Node & node() const
Definition: bitcoin.h:93
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
Definition: bitcoin.cpp:361
virtual bool appInitMain(interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)=0
Start node.
QTimer * pollShutdownTimer
Definition: bitcoin.h:113
const PlatformStyle * platformStyle
Definition: bitcoin.h:119