BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
bitcoin.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2018 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/bitcoingui.h>
10 
11 #include <chainparams.h>
12 #include <qt/clientmodel.h>
13 #include <fs.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/walletmodel.h>
27 #endif
28 
29 #include <interfaces/handler.h>
30 #include <interfaces/node.h>
31 #include <noui.h>
32 #include <rpc/server.h>
33 #include <ui_interface.h>
34 #include <uint256.h>
35 #include <util.h>
36 #include <warnings.h>
37 
38 #include <walletinitinterface.h>
39 
40 #include <memory>
41 #include <stdint.h>
42 
43 #include <boost/thread.hpp>
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 
55 #if defined(QT_STATICPLUGIN)
56 #include <QtPlugin>
57 #if QT_VERSION < 0x050400
58 Q_IMPORT_PLUGIN(AccessibleFactory)
59 #endif
60 #if defined(QT_QPA_PLATFORM_XCB)
61 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
62 #elif defined(QT_QPA_PLATFORM_WINDOWS)
63 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
64 #elif defined(QT_QPA_PLATFORM_COCOA)
65 Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
66 #endif
67 #endif
68 
69 // Declare meta types used for QMetaObject::invokeMethod
70 Q_DECLARE_METATYPE(bool*)
71 Q_DECLARE_METATYPE(CAmount)
72 Q_DECLARE_METATYPE(uint256)
73 
74 static void InitMessage(const std::string& message)
75 {
76  noui_InitMessage(message);
77 }
78 
80 const std::function<std::string(const char*)> G_TRANSLATION_FUN = [](const char* psz) {
81  return QCoreApplication::translate("bitcoin-core", psz).toStdString();
82 };
83 
84 static QString GetLangTerritory()
85 {
86  QSettings settings;
87  // Get desired locale (e.g. "de_DE")
88  // 1) System default language
89  QString lang_territory = QLocale::system().name();
90  // 2) Language from QSettings
91  QString lang_territory_qsettings = settings.value("language", "").toString();
92  if(!lang_territory_qsettings.isEmpty())
93  lang_territory = lang_territory_qsettings;
94  // 3) -lang command line argument
95  lang_territory = QString::fromStdString(gArgs.GetArg("-lang", lang_territory.toStdString()));
96  return lang_territory;
97 }
98 
100 static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
101 {
102  // Remove old translators
103  QApplication::removeTranslator(&qtTranslatorBase);
104  QApplication::removeTranslator(&qtTranslator);
105  QApplication::removeTranslator(&translatorBase);
106  QApplication::removeTranslator(&translator);
107 
108  // Get desired locale (e.g. "de_DE")
109  // 1) System default language
110  QString lang_territory = GetLangTerritory();
111 
112  // Convert to "de" only by truncating "_DE"
113  QString lang = lang_territory;
114  lang.truncate(lang_territory.lastIndexOf('_'));
115 
116  // Load language files for configured locale:
117  // - First load the translator for the base language, without territory
118  // - Then load the more specific locale translator
119 
120  // Load e.g. qt_de.qm
121  if (qtTranslatorBase.load("qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
122  QApplication::installTranslator(&qtTranslatorBase);
123 
124  // Load e.g. qt_de_DE.qm
125  if (qtTranslator.load("qt_" + lang_territory, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
126  QApplication::installTranslator(&qtTranslator);
127 
128  // Load e.g. bitcoin_de.qm (shortcut "de" needs to be defined in bitcoin.qrc)
129  if (translatorBase.load(lang, ":/translations/"))
130  QApplication::installTranslator(&translatorBase);
131 
132  // Load e.g. bitcoin_de_DE.qm (shortcut "de_DE" needs to be defined in bitcoin.qrc)
133  if (translator.load(lang_territory, ":/translations/"))
134  QApplication::installTranslator(&translator);
135 }
136 
137 /* qDebug() message handler --> debug.log */
138 void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString &msg)
139 {
140  Q_UNUSED(context);
141  if (type == QtDebugMsg) {
142  LogPrint(BCLog::QT, "GUI: %s\n", msg.toStdString());
143  } else {
144  LogPrintf("GUI: %s\n", msg.toStdString());
145  }
146 }
147 
151 class BitcoinCore: public QObject
152 {
153  Q_OBJECT
154 public:
155  explicit BitcoinCore(interfaces::Node& node);
156 
157 public Q_SLOTS:
158  void initialize();
159  void shutdown();
160 
161 Q_SIGNALS:
162  void initializeResult(bool success);
163  void shutdownResult();
164  void runawayException(const QString &message);
165 
166 private:
168  void handleRunawayException(const std::exception *e);
169 
171 };
172 
174 class BitcoinApplication: public QApplication
175 {
176  Q_OBJECT
177 public:
178  explicit BitcoinApplication(interfaces::Node& node, int &argc, char **argv);
180 
181 #ifdef ENABLE_WALLET
182  void createPaymentServer();
184 #endif
185  void parameterSetup();
188  void createOptionsModel(bool resetSettings);
190  void createWindow(const NetworkStyle *networkStyle);
192  void createSplashScreen(const NetworkStyle *networkStyle);
193 
195  void requestInitialize();
197  void requestShutdown();
198 
200  int getReturnValue() const { return returnValue; }
201 
203  WId getMainWinId() const;
204 
206  void setupPlatformStyle();
207 
208 public Q_SLOTS:
209  void initializeResult(bool success);
210  void shutdownResult();
212  void handleRunawayException(const QString &message);
213  void addWallet(WalletModel* walletModel);
214  void removeWallet();
215 
216 Q_SIGNALS:
217  void requestedInitialize();
218  void requestedShutdown();
219  void stopThread();
220  void splashFinished(QWidget *window);
221 
222 private:
223  QThread *coreThread;
229 #ifdef ENABLE_WALLET
230  PaymentServer* paymentServer;
231  std::vector<WalletModel*> m_wallet_models;
232  std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
233 #endif
236  std::unique_ptr<QWidget> shutdownWindow;
237 
238  void startThread();
239 };
240 
241 #include <qt/bitcoin.moc>
242 
244  QObject(), m_node(node)
245 {
246 }
247 
248 void BitcoinCore::handleRunawayException(const std::exception *e)
249 {
250  PrintExceptionContinue(e, "Runaway exception");
251  Q_EMIT runawayException(QString::fromStdString(m_node.getWarnings("gui")));
252 }
253 
255 {
256  try
257  {
258  qDebug() << __func__ << ": Running initialization in thread";
259  bool rv = m_node.appInitMain();
260  Q_EMIT initializeResult(rv);
261  } catch (const std::exception& e) {
263  } catch (...) {
264  handleRunawayException(nullptr);
265  }
266 }
267 
269 {
270  try
271  {
272  qDebug() << __func__ << ": Running Shutdown in thread";
274  qDebug() << __func__ << ": Shutdown finished";
275  Q_EMIT shutdownResult();
276  } catch (const std::exception& e) {
278  } catch (...) {
279  handleRunawayException(nullptr);
280  }
281 }
282 
284  QApplication(argc, argv),
285  coreThread(0),
286  m_node(node),
287  optionsModel(0),
288  clientModel(0),
289  window(0),
290  pollShutdownTimer(0),
291 #ifdef ENABLE_WALLET
292  paymentServer(0),
293  m_wallet_models(),
294 #endif
295  returnValue(0),
296  platformStyle(0)
297 {
298  setQuitOnLastWindowClosed(false);
299 }
300 
302 {
303  // UI per-platform customization
304  // This must be done inside the BitcoinApplication constructor, or after it, because
305  // PlatformStyle::instantiate requires a QApplication
306  std::string platformName;
307  platformName = gArgs.GetArg("-uiplatform", BitcoinGUI::DEFAULT_UIPLATFORM);
308  platformStyle = PlatformStyle::instantiate(QString::fromStdString(platformName));
309  if (!platformStyle) // Fall back to "other" if specified name not found
311  assert(platformStyle);
312 }
313 
315 {
316  if(coreThread)
317  {
318  qDebug() << __func__ << ": Stopping thread";
319  Q_EMIT stopThread();
320  coreThread->wait();
321  qDebug() << __func__ << ": Stopped thread";
322  }
323 
324  delete window;
325  window = 0;
326 #ifdef ENABLE_WALLET
327  delete paymentServer;
328  paymentServer = 0;
329 #endif
330  delete optionsModel;
331  optionsModel = 0;
332  delete platformStyle;
333  platformStyle = 0;
334 }
335 
336 #ifdef ENABLE_WALLET
337 void BitcoinApplication::createPaymentServer()
338 {
339  paymentServer = new PaymentServer(this);
340 }
341 #endif
342 
344 {
345  optionsModel = new OptionsModel(m_node, nullptr, resetSettings);
346 }
347 
349 {
350  window = new BitcoinGUI(m_node, platformStyle, networkStyle, 0);
351 
352  pollShutdownTimer = new QTimer(window);
353  connect(pollShutdownTimer, &QTimer::timeout, window, &BitcoinGUI::detectShutdown);
354 }
355 
357 {
358  SplashScreen *splash = new SplashScreen(m_node, 0, networkStyle);
359  // We don't hold a direct pointer to the splash screen after creation, but the splash
360  // screen will take care of deleting itself when slotFinish happens.
361  splash->show();
363  connect(this, &BitcoinApplication::requestedShutdown, splash, &QWidget::close);
364 }
365 
367 {
368  if(coreThread)
369  return;
370  coreThread = new QThread(this);
371  BitcoinCore *executor = new BitcoinCore(m_node);
372  executor->moveToThread(coreThread);
373 
374  /* communication to and from thread */
380  /* make sure executor object is deleted in its own thread */
381  connect(this, &BitcoinApplication::stopThread, executor, &QObject::deleteLater);
382  connect(this, &BitcoinApplication::stopThread, coreThread, &QThread::quit);
383 
384  coreThread->start();
385 }
386 
388 {
389  // Default printtoconsole to false for the GUI. GUI programs should not
390  // print to the console unnecessarily.
391  gArgs.SoftSetBoolArg("-printtoconsole", false);
392 
395 }
396 
398 {
399  qDebug() << __func__ << ": Requesting initialize";
400  startThread();
401  Q_EMIT requestedInitialize();
402 }
403 
405 {
406  // Show a simple window indicating shutdown status
407  // Do this first as some of the steps may take some time below,
408  // for example the RPC console may still be executing a command.
410 
411  qDebug() << __func__ << ": Requesting shutdown";
412  startThread();
413  window->hide();
415  pollShutdownTimer->stop();
416 
417 #ifdef ENABLE_WALLET
418  window->removeAllWallets();
419  for (const WalletModel* walletModel : m_wallet_models) {
420  delete walletModel;
421  }
422  m_wallet_models.clear();
423 #endif
424  delete clientModel;
425  clientModel = 0;
426 
428 
429  // Request shutdown from core thread
430  Q_EMIT requestedShutdown();
431 }
432 
434 {
435 #ifdef ENABLE_WALLET
436  window->addWallet(walletModel);
437 
438  if (m_wallet_models.empty()) {
439  window->setCurrentWallet(walletModel->getWalletName());
440  }
441 
442 #ifdef ENABLE_BIP70
443  connect(walletModel, &WalletModel::coinsSent,
444  paymentServer, &PaymentServer::fetchPaymentACK);
445 #endif
446  connect(walletModel, &WalletModel::unload, this, &BitcoinApplication::removeWallet);
447 
448  m_wallet_models.push_back(walletModel);
449 #endif
450 }
451 
453 {
454 #ifdef ENABLE_WALLET
455  WalletModel* walletModel = static_cast<WalletModel*>(sender());
456  m_wallet_models.erase(std::find(m_wallet_models.begin(), m_wallet_models.end(), walletModel));
457  window->removeWallet(walletModel);
458  walletModel->deleteLater();
459 #endif
460 }
461 
463 {
464  qDebug() << __func__ << ": Initialization result: " << success;
465  // Set exit result.
466  returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE;
467  if(success)
468  {
469  // Log this only after AppInitMain finishes, as then logging setup is guaranteed complete
470  qWarning() << "Platform customization:" << platformStyle->getName();
471 #ifdef ENABLE_WALLET
472 #ifdef ENABLE_BIP70
473  PaymentServer::LoadRootCAs();
474 #endif
475  paymentServer->setOptionsModel(optionsModel);
476 #endif
477 
480 
481 #ifdef ENABLE_WALLET
482  m_handler_load_wallet = m_node.handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) {
483  WalletModel* wallet_model = new WalletModel(std::move(wallet), m_node, platformStyle, optionsModel, nullptr);
484  // Fix wallet model thread affinity.
485  wallet_model->moveToThread(thread());
486  QMetaObject::invokeMethod(this, "addWallet", Qt::QueuedConnection, Q_ARG(WalletModel*, wallet_model));
487  });
488 
489  for (auto& wallet : m_node.getWallets()) {
490  addWallet(new WalletModel(std::move(wallet), m_node, platformStyle, optionsModel));
491  }
492 #endif
493 
494  // If -min option passed, start window minimized.
495  if(gArgs.GetBoolArg("-min", false))
496  {
497  window->showMinimized();
498  }
499  else
500  {
501  window->show();
502  }
503  Q_EMIT splashFinished(window);
504 
505 #ifdef ENABLE_WALLET
506  // Now that initialization/startup is done, process any command-line
507  // bitcoin: URIs or payment requests:
508  connect(paymentServer, &PaymentServer::receivedPaymentRequest, window, &BitcoinGUI::handlePaymentRequest);
510  connect(paymentServer, &PaymentServer::message, [this](const QString& title, const QString& message, unsigned int style) {
511  window->message(title, message, style);
512  });
513  QTimer::singleShot(100, paymentServer, &PaymentServer::uiReady);
514 #endif
515  pollShutdownTimer->start(200);
516  } else {
517  Q_EMIT splashFinished(window); // Make sure splash screen doesn't stick around during shutdown
518  quit(); // Exit first main loop invocation
519  }
520 }
521 
523 {
524  quit(); // Exit second main loop invocation after shutdown finished
525 }
526 
527 void BitcoinApplication::handleRunawayException(const QString &message)
528 {
529  QMessageBox::critical(0, "Runaway exception", BitcoinGUI::tr("A fatal error occurred. BSHA3 can no longer continue safely and will quit.") + QString("\n\n") + message);
530  ::exit(EXIT_FAILURE);
531 }
532 
534 {
535  if (!window)
536  return 0;
537 
538  return window->winId();
539 }
540 
541 static void SetupUIArgs()
542 {
543 #if defined(ENABLE_WALLET) && defined(ENABLE_BIP70)
544  gArgs.AddArg("-allowselfsignedrootcertificates", strprintf("Allow self signed root certificates (default: %u)", DEFAULT_SELFSIGNED_ROOTCERTS), true, OptionsCategory::GUI);
545 #endif
546  gArgs.AddArg("-choosedatadir", strprintf("Choose data directory on startup (default: %u)", DEFAULT_CHOOSE_DATADIR), false, OptionsCategory::GUI);
547  gArgs.AddArg("-lang=<lang>", "Set language, for example \"de_DE\" (default: system locale)", false, OptionsCategory::GUI);
548  gArgs.AddArg("-min", "Start minimized", false, OptionsCategory::GUI);
549  gArgs.AddArg("-resetguisettings", "Reset all settings changed in the GUI", false, OptionsCategory::GUI);
550  gArgs.AddArg("-rootcertificates=<file>", "Set SSL root certificates for payment request (default: -system-)", false, OptionsCategory::GUI);
551  gArgs.AddArg("-splash", strprintf("Show splash screen on startup (default: %u)", DEFAULT_SPLASHSCREEN), false, OptionsCategory::GUI);
552  gArgs.AddArg("-uiplatform", strprintf("Select platform to customize UI for (one of windows, macosx, other; default: %s)", BitcoinGUI::DEFAULT_UIPLATFORM), true, OptionsCategory::GUI);
553 }
554 
555 #ifndef BITCOIN_QT_TEST
556 int main(int argc, char *argv[])
557 {
558 #ifdef WIN32
559  util::WinCmdLineArgs winArgs;
560  std::tie(argc, argv) = winArgs.get();
561 #endif
563 
564  std::unique_ptr<interfaces::Node> node = interfaces::MakeNode();
565 
566  // Do not refer to data directory yet, this can be overridden by Intro::pickDataDirectory
567 
569  Q_INIT_RESOURCE(bitcoin);
570  Q_INIT_RESOURCE(bitcoin_locale);
571 
572  BitcoinApplication app(*node, argc, argv);
573 #if QT_VERSION > 0x050100
574  // Generate high-dpi pixmaps
575  QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
576 #endif
577 #if QT_VERSION >= 0x050600
578  QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
579 #endif
580 #ifdef Q_OS_MAC
581  QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
582 #endif
583 
584  // Register meta types used for QMetaObject::invokeMethod
585  qRegisterMetaType< bool* >();
586  // Need to pass name here as CAmount is a typedef (see http://qt-project.org/doc/qt-5/qmetatype.html#qRegisterMetaType)
587  // IMPORTANT if it is no longer a typedef use the normal variant above
588  qRegisterMetaType< CAmount >("CAmount");
589  qRegisterMetaType< std::function<void()> >("std::function<void()>");
590 #ifdef ENABLE_WALLET
591  qRegisterMetaType<WalletModel*>("WalletModel*");
592 #endif
593 
595  // Command-line options take precedence:
596  node->setupServerArgs();
597  SetupUIArgs();
598  std::string error;
599  if (!node->parseParameters(argc, argv, error)) {
600  QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
601  QObject::tr("Error parsing command line arguments: %1.").arg(QString::fromStdString(error)));
602  return EXIT_FAILURE;
603  }
604 
605  // Now that the QApplication is setup and we have parsed our parameters, we can set the platform style
606  app.setupPlatformStyle();
607 
609  // must be set before OptionsModel is initialized or translations are loaded,
610  // as it is used to locate QSettings
611  QApplication::setOrganizationName(QAPP_ORG_NAME);
612  QApplication::setOrganizationDomain(QAPP_ORG_DOMAIN);
613  QApplication::setApplicationName(QAPP_APP_NAME_DEFAULT);
614 
616  // Now that QSettings are accessible, initialize translations
617  QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
618  initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
619 
620  // Show help message immediately after parsing command-line options (for "-lang") and setting locale,
621  // but before showing splash screen.
622  if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
623  HelpMessageDialog help(*node, nullptr, gArgs.IsArgSet("-version"));
624  help.showOrPrint();
625  return EXIT_SUCCESS;
626  }
627 
629  // User language is set up: pick a data directory
630  if (!Intro::pickDataDirectory(*node))
631  return EXIT_SUCCESS;
632 
635  if (!fs::is_directory(GetDataDir(false)))
636  {
637  QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
638  QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(gArgs.GetArg("-datadir", ""))));
639  return EXIT_FAILURE;
640  }
641  if (!node->readConfigFiles(error)) {
642  QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
643  QObject::tr("Error: Cannot parse configuration file: %1.").arg(QString::fromStdString(error)));
644  return EXIT_FAILURE;
645  }
646 
648  // - Do not call Params() before this step
649  // - Do this after parsing the configuration file, as the network can be switched there
650  // - QSettings() will use the new application name after this, resulting in network-specific settings
651  // - Needs to be done before createOptionsModel
652 
653  // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
654  try {
655  node->selectParams(gArgs.GetChainName());
656  } catch(std::exception &e) {
657  QMessageBox::critical(0, QObject::tr(PACKAGE_NAME), QObject::tr("Error: %1").arg(e.what()));
658  return EXIT_FAILURE;
659  }
660 #ifdef ENABLE_WALLET
661  // Parse URIs on command line -- this can affect Params()
662  PaymentServer::ipcParseCommandLine(*node, argc, argv);
663 #endif
664 
665  QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(QString::fromStdString(Params().NetworkIDString())));
666  assert(!networkStyle.isNull());
667  // Allow for separate UI settings for testnets
668  QApplication::setApplicationName(networkStyle->getAppName());
669  // Re-initialize translations after changing application name (language in network-specific settings can be different)
670  initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
671 
672 #ifdef ENABLE_WALLET
673  // - Do this early as we don't want to bother initializing if we are just calling IPC
675  // - Do this *after* setting up the data directory, as the data directory hash is used in the name
676  // of the server.
677  // - Do this after creating app and setting up translations, so errors are
678  // translated properly.
680  exit(EXIT_SUCCESS);
681 
682  // Start up the payment server early, too, so impatient users that click on
683  // bitcoin: links repeatedly have their payment requests routed to this process:
684  app.createPaymentServer();
685 #endif
686 
688  // Install global event filter that makes sure that long tooltips can be word-wrapped
689  app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app));
690 #if defined(Q_OS_WIN)
691  // Install global event filter for processing Windows session related Windows messages (WM_QUERYENDSESSION and WM_ENDSESSION)
692  qApp->installNativeEventFilter(new WinShutdownMonitor());
693 #endif
694  // Install qDebug() message handler to route to debug.log
695  qInstallMessageHandler(DebugMessageHandler);
696  // Allow parameter interaction before we create the options model
697  app.parameterSetup();
698  // Load GUI settings from QSettings
699  app.createOptionsModel(gArgs.GetBoolArg("-resetguisettings", false));
700 
701  // Subscribe to global signals from core
702  std::unique_ptr<interfaces::Handler> handler = node->handleInitMessage(InitMessage);
703 
704  if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false))
705  app.createSplashScreen(networkStyle.data());
706 
707  int rv = EXIT_SUCCESS;
708  try
709  {
710  app.createWindow(networkStyle.data());
711  // Perform base initialization before spinning up initialization/shutdown thread
712  // This is acceptable because this function only contains steps that are quick to execute,
713  // so the GUI thread won't be held up.
714  if (node->baseInitialize()) {
715  app.requestInitialize();
716 #if defined(Q_OS_WIN)
717  WinShutdownMonitor::registerShutdownBlockReason(QObject::tr("%1 didn't yet exit safely...").arg(QObject::tr(PACKAGE_NAME)), (HWND)app.getMainWinId());
718 #endif
719  app.exec();
720  app.requestShutdown();
721  app.exec();
722  rv = app.getReturnValue();
723  } else {
724  // A dialog with detailed error will have been shown by InitError()
725  rv = EXIT_FAILURE;
726  }
727  } catch (const std::exception& e) {
728  PrintExceptionContinue(&e, "Runaway exception");
729  app.handleRunawayException(QString::fromStdString(node->getWarnings("gui")));
730  } catch (...) {
731  PrintExceptionContinue(nullptr, "Runaway exception");
732  app.handleRunawayException(QString::fromStdString(node->getWarnings("gui")));
733  }
734  return rv;
735 }
736 #endif // BITCOIN_QT_TEST
OptionsModel * optionsModel
Definition: bitcoin.cpp:225
bool HelpRequested(const ArgsManager &args)
Definition: util.cpp:662
virtual bool appInitMain()=0
Start node.
bool(* handler)(HTTPRequest *req, const std::string &strReq)
Definition: rest.cpp:582
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: util.cpp:502
virtual std::string getWarnings(const std::string &type)=0
Get warnings.
void message(const QString &title, const QString &message, unsigned int style, bool *ret=nullptr)
Notify the user of an event from the core network or transaction handling code.
Definition: bitcoingui.cpp:897
void setupPlatformStyle()
Setup platform style.
Definition: bitcoin.cpp:301
void coinsSent(WalletModel *wallet, SendCoinsRecipient recipient, QByteArray transaction)
void receivedURI(const QString &uri)
Signal raised when a URI was entered or dragged to the GUI.
void message(const QString &title, const QString &message, unsigned int style)
virtual void initLogging()=0
Init logging.
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn&#39;t already have a value.
Definition: util.cpp:558
Class for the splashscreen with information of the running client.
Definition: splashscreen.h:27
Class encapsulating Bitcoin Core startup and shutdown.
Definition: bitcoin.cpp:151
#define strprintf
Definition: tinyformat.h:1066
void parameterSetup()
parameter interaction/setup based on rules
Definition: bitcoin.cpp:387
static void ipcParseCommandLine(interfaces::Node &node, int argc, char *argv[])
void handleRunawayException(const std::exception *e)
Pass fatal exception message to UI thread.
Definition: bitcoin.cpp:248
virtual void startShutdown()=0
Start shutdown.
void handleRunawayException(const QString &message)
Handle runaway exceptions. Shows a message box with the problem and quits the program.
Definition: bitcoin.cpp:527
void unload()
int main(int argc, char *argv[])
Definition: bitcoin.cpp:556
void requestInitialize()
Request core initialization.
Definition: bitcoin.cpp:397
#define PACKAGE_NAME
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
Definition: util.cpp:698
void receivedPaymentRequest(SendCoinsRecipient)
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
Definition: guiutil.h:128
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: util.cpp:542
Bitcoin GUI main class.
Definition: bitcoingui.h:59
interfaces::Node & m_node
Definition: bitcoin.cpp:170
virtual std::vector< std::unique_ptr< Wallet > > getWallets()=0
Return interfaces for accessing wallets (if any).
void createOptionsModel(bool resetSettings)
Create options model.
Definition: bitcoin.cpp:343
void noui_InitMessage(const std::string &message)
Non-GUI handler, which only logs a message.
Definition: noui.cpp:49
void requestedInitialize()
void initializeResult(bool success)
void handleURIOrFile(const QString &s)
const std::function< std::string(const char *)> G_TRANSLATION_FUN
Translate string to current locale using Qt.
Definition: bitcoin.cpp:80
static bool ipcSendCommandLine()
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
BitcoinApplication(interfaces::Node &node, int &argc, char **argv)
Definition: bitcoin.cpp:283
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: bitcoingui.cpp:446
void shutdown()
Definition: bitcoin.cpp:268
BitcoinCore(interfaces::Node &node)
Definition: bitcoin.cpp:243
static bool pickDataDirectory(interfaces::Node &node)
Determine data directory.
Definition: intro.cpp:190
#define QAPP_ORG_NAME
Definition: guiconstants.h:49
void createSplashScreen(const NetworkStyle *networkStyle)
Create splash screen.
Definition: bitcoin.cpp:356
Main Bitcoin application object.
Definition: bitcoin.cpp:174
interfaces::Node & m_node
Definition: bitcoin.cpp:224
void splashFinished(QWidget *window)
void detectShutdown()
called by a timer to check if ShutdownRequested() has been set
std::unique_ptr< QWidget > shutdownWindow
Definition: bitcoin.cpp:236
UniValue help(const JSONRPCRequest &jsonRequest)
Definition: server.cpp:202
QString getWalletName() const
void initialize()
Definition: bitcoin.cpp:254
Model for Bitcoin network client.
Definition: clientmodel.h:44
void shutdownResult()
Definition: bitcoin.cpp:522
BitcoinGUI * window
Definition: bitcoin.cpp:227
void requestShutdown()
Request core shutdown.
Definition: bitcoin.cpp:404
QThread * coreThread
Definition: bitcoin.cpp:223
virtual void initParameterInteraction()=0
Init parameter interaction.
virtual std::unique_ptr< Handler > handleLoadWallet(LoadWalletFn fn)=0
void DebugMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
Definition: bitcoin.cpp:138
256-bit opaque blob.
Definition: uint256.h:122
#define QAPP_APP_NAME_DEFAULT
Definition: guiconstants.h:51
ArgsManager gArgs
Definition: util.cpp:88
#define ENABLE_WALLET
virtual void appShutdown()=0
Stop node.
void createWindow(const NetworkStyle *networkStyle)
Create main window.
Definition: bitcoin.cpp:348
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:29
#define QAPP_ORG_DOMAIN
Definition: guiconstants.h:50
void initializeResult(bool success)
Definition: bitcoin.cpp:462
void slotFinish(QWidget *mainWin)
Slot to call finish() method as it&#39;s not defined as slot.
std::unique_ptr< Node > MakeNode()
Return implementation of Node interface.
Definition: node.cpp:298
const CChainParams & Params()
Return the currently selected parameters.
const QString & getName() const
Definition: platformstyle.h:19
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:125
void addWallet(WalletModel *walletModel)
Definition: bitcoin.cpp:433
void AddArg(const std::string &name, const std::string &help, const bool debug_only, const OptionsCategory &cat)
Add argument.
Definition: util.cpp:572
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: util.cpp:526
static QWidget * showShutdownWindow(BitcoinGUI *window)
bool error(const char *fmt, const Args &... args)
Definition: util.h:59
"Help message" dialog box
Definition: utilitydialog.h:22
std::string GetChainName() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
Definition: util.cpp:967
const fs::path & GetDataDir(bool fNetSpecific)
Definition: util.cpp:766
void SetupEnvironment()
Definition: util.cpp:1184
void shutdownResult()
static const std::string DEFAULT_UIPLATFORM
Definition: bitcoingui.h:64
void runawayException(const QString &message)
WId getMainWinId() const
Get window identifier of QMainWindow (BitcoinGUI)
Definition: bitcoin.cpp:533
Top-level interface for a bitcoin node (bsha3d process).
Definition: node.h:35
ClientModel * clientModel
Definition: bitcoin.cpp:226
static const NetworkStyle * instantiate(const QString &networkId)
Get style associated with provided BIP70 network id, or 0 if not known.
int getReturnValue() const
Get process return value.
Definition: bitcoin.cpp:200
QTimer * pollShutdownTimer
Definition: bitcoin.cpp:228
const PlatformStyle * platformStyle
Definition: bitcoin.cpp:235