27
27
#include < qt/walletmodel.h>
28
28
#endif // ENABLE_WALLET
29
29
30
+ #include < init.h>
30
31
#include < interfaces/handler.h>
31
32
#include < interfaces/node.h>
32
33
#include < node/context.h>
34
+ #include < node/ui_interface.h>
33
35
#include < noui.h>
34
36
#include < uint256.h>
35
37
#include < util/system.h>
36
38
#include < util/threadnames.h>
37
39
#include < util/translation.h>
38
40
#include < validation.h>
39
41
42
+ #include < boost/signals2/connection.hpp>
40
43
#include < memory>
41
44
42
45
#include < QApplication>
@@ -193,10 +196,9 @@ void BitcoinCore::shutdown()
193
196
static int qt_argc = 1 ;
194
197
static const char * qt_argv = " bitcoin-qt" ;
195
198
196
- BitcoinApplication::BitcoinApplication (interfaces::Node& node ):
199
+ BitcoinApplication::BitcoinApplication ():
197
200
QApplication(qt_argc, const_cast <char **>(&qt_argv)),
198
201
coreThread(nullptr ),
199
- m_node(node),
200
202
optionsModel(nullptr ),
201
203
clientModel(nullptr ),
202
204
window(nullptr ),
@@ -246,38 +248,47 @@ void BitcoinApplication::createPaymentServer()
246
248
247
249
void BitcoinApplication::createOptionsModel (bool resetSettings)
248
250
{
249
- optionsModel = new OptionsModel (m_node, this , resetSettings);
251
+ optionsModel = new OptionsModel (this , resetSettings);
250
252
}
251
253
252
254
void BitcoinApplication::createWindow (const NetworkStyle *networkStyle)
253
255
{
254
- window = new BitcoinGUI (m_node , platformStyle, networkStyle, nullptr );
256
+ window = new BitcoinGUI (node () , platformStyle, networkStyle, nullptr );
255
257
256
258
pollShutdownTimer = new QTimer (window);
257
259
connect (pollShutdownTimer, &QTimer::timeout, window, &BitcoinGUI::detectShutdown);
258
260
}
259
261
260
262
void BitcoinApplication::createSplashScreen (const NetworkStyle *networkStyle)
261
263
{
262
- SplashScreen *splash = new SplashScreen (m_node, nullptr , networkStyle);
264
+ assert (!m_splash);
265
+ m_splash = new SplashScreen (nullptr , networkStyle);
263
266
// We don't hold a direct pointer to the splash screen after creation, but the splash
264
267
// screen will take care of deleting itself when finish() happens.
265
- splash->show ();
266
- connect (this , &BitcoinApplication::splashFinished, splash, &SplashScreen::finish);
267
- connect (this , &BitcoinApplication::requestedShutdown, splash, &QWidget::close );
268
+ m_splash->show ();
269
+ connect (this , &BitcoinApplication::splashFinished, m_splash, &SplashScreen::finish);
270
+ connect (this , &BitcoinApplication::requestedShutdown, m_splash, &QWidget::close );
271
+ }
272
+
273
+ void BitcoinApplication::setNode (interfaces::Node& node)
274
+ {
275
+ assert (!m_node);
276
+ m_node = &node;
277
+ if (optionsModel) optionsModel->setNode (*m_node);
278
+ if (m_splash) m_splash->setNode (*m_node);
268
279
}
269
280
270
281
bool BitcoinApplication::baseInitialize ()
271
282
{
272
- return m_node .baseInitialize ();
283
+ return node () .baseInitialize ();
273
284
}
274
285
275
286
void BitcoinApplication::startThread ()
276
287
{
277
288
if (coreThread)
278
289
return ;
279
290
coreThread = new QThread (this );
280
- BitcoinCore *executor = new BitcoinCore (m_node );
291
+ BitcoinCore *executor = new BitcoinCore (node () );
281
292
executor->moveToThread (coreThread);
282
293
283
294
/* communication to and from thread */
@@ -298,8 +309,8 @@ void BitcoinApplication::parameterSetup()
298
309
// print to the console unnecessarily.
299
310
gArgs .SoftSetBoolArg (" -printtoconsole" , false );
300
311
301
- m_node. initLogging ( );
302
- m_node. initParameterInteraction ( );
312
+ InitLogging ( gArgs );
313
+ InitParameterInteraction ( gArgs );
303
314
}
304
315
305
316
void BitcoinApplication::InitializePruneSetting (bool prune)
@@ -331,7 +342,7 @@ void BitcoinApplication::requestShutdown()
331
342
window->unsubscribeFromCoreSignals ();
332
343
// Request node shutdown, which can interrupt long operations, like
333
344
// rescanning a wallet.
334
- m_node .startShutdown ();
345
+ node () .startShutdown ();
335
346
// Unsetting the client model can cause the current thread to wait for node
336
347
// to complete an operation, like wait for a RPC execution to complete.
337
348
window->setClientModel (nullptr );
@@ -353,7 +364,7 @@ void BitcoinApplication::initializeResult(bool success, interfaces::BlockAndHead
353
364
{
354
365
// Log this only after AppInitMain finishes, as then logging setup is guaranteed complete
355
366
qInfo () << " Platform customization:" << platformStyle->getName ();
356
- clientModel = new ClientModel (m_node , optionsModel);
367
+ clientModel = new ClientModel (node () , optionsModel);
357
368
window->setClientModel (clientModel, &tip_info);
358
369
#ifdef ENABLE_WALLET
359
370
if (WalletModel::isWalletEnabled ()) {
@@ -437,9 +448,9 @@ int GuiMain(int argc, char* argv[])
437
448
std::unique_ptr<interfaces::Node> node = interfaces::MakeNode (&node_context);
438
449
439
450
// Subscribe to global signals from core
440
- std::unique_ptr<interfaces::Handler> handler_message_box = node-> handleMessageBox (noui_ThreadSafeMessageBox);
441
- std::unique_ptr<interfaces::Handler> handler_question = node-> handleQuestion (noui_ThreadSafeQuestion);
442
- std::unique_ptr<interfaces::Handler> handler_init_message = node-> handleInitMessage (noui_InitMessage);
451
+ boost::signals2::scoped_connection handler_message_box = ::uiInterface. ThreadSafeMessageBox_connect (noui_ThreadSafeMessageBox);
452
+ boost::signals2::scoped_connection handler_question = ::uiInterface. ThreadSafeQuestion_connect (noui_ThreadSafeQuestion);
453
+ boost::signals2::scoped_connection handler_init_message = ::uiInterface. InitMessage_connect (noui_InitMessage);
443
454
444
455
// Do not refer to data directory yet, this can be overridden by Intro::pickDataDirectory
445
456
@@ -453,15 +464,15 @@ int GuiMain(int argc, char* argv[])
453
464
QCoreApplication::setAttribute (Qt::AA_EnableHighDpiScaling);
454
465
#endif
455
466
456
- BitcoinApplication app (*node) ;
467
+ BitcoinApplication app;
457
468
458
469
// / 2. Parse command-line options. We do this after qt in order to show an error if there are problems parsing these
459
470
// Command-line options take precedence:
460
- node-> setupServerArgs ( );
471
+ SetupServerArgs (node_context );
461
472
SetupUIArgs (gArgs );
462
473
std::string error;
463
- if (!node-> parseParameters (argc, argv, error)) {
464
- node-> initError (strprintf (Untranslated (" Error parsing command line arguments: %s\n " ), error));
474
+ if (!gArgs . ParseParameters (argc, argv, error)) {
475
+ InitError (strprintf (Untranslated (" Error parsing command line arguments: %s\n " ), error));
465
476
// Create a message box, because the gui has neither been created nor has subscribed to core signals
466
477
QMessageBox::critical (nullptr , PACKAGE_NAME,
467
478
// message can not be translated because translations have not been initialized
@@ -487,7 +498,7 @@ int GuiMain(int argc, char* argv[])
487
498
// Show help message immediately after parsing command-line options (for "-lang") and setting locale,
488
499
// but before showing splash screen.
489
500
if (HelpRequested (gArgs ) || gArgs .IsArgSet (" -version" )) {
490
- HelpMessageDialog help (*node, nullptr , gArgs .IsArgSet (" -version" ));
501
+ HelpMessageDialog help (nullptr , gArgs .IsArgSet (" -version" ));
491
502
help.showOrPrint ();
492
503
return EXIT_SUCCESS;
493
504
}
@@ -497,18 +508,18 @@ int GuiMain(int argc, char* argv[])
497
508
bool did_show_intro = false ;
498
509
bool prune = false ; // Intro dialog prune check box
499
510
// Gracefully exit if the user cancels
500
- if (!Intro::showIfNeeded (*node, did_show_intro, prune)) return EXIT_SUCCESS;
511
+ if (!Intro::showIfNeeded (did_show_intro, prune)) return EXIT_SUCCESS;
501
512
502
513
// / 6. Determine availability of data directory and parse bitcoin.conf
503
514
// / - Do not call GetDataDir(true) before this step finishes
504
515
if (!CheckDataDirOption ()) {
505
- node-> initError (strprintf (Untranslated (" Specified data directory \" %s\" does not exist.\n " ), gArgs .GetArg (" -datadir" , " " )));
516
+ InitError (strprintf (Untranslated (" Specified data directory \" %s\" does not exist.\n " ), gArgs .GetArg (" -datadir" , " " )));
506
517
QMessageBox::critical (nullptr , PACKAGE_NAME,
507
518
QObject::tr (" Error: Specified data directory \" %1\" does not exist." ).arg (QString::fromStdString (gArgs .GetArg (" -datadir" , " " ))));
508
519
return EXIT_FAILURE;
509
520
}
510
- if (!node-> readConfigFiles (error)) {
511
- node-> initError (strprintf (Untranslated (" Error reading configuration file: %s\n " ), error));
521
+ if (!gArgs . ReadConfigFiles (error, true )) {
522
+ InitError (strprintf (Untranslated (" Error reading configuration file: %s\n " ), error));
512
523
QMessageBox::critical (nullptr , PACKAGE_NAME,
513
524
QObject::tr (" Error: Cannot parse configuration file: %1." ).arg (QString::fromStdString (error)));
514
525
return EXIT_FAILURE;
@@ -522,18 +533,18 @@ int GuiMain(int argc, char* argv[])
522
533
523
534
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
524
535
try {
525
- node-> selectParams (gArgs .GetChainName ());
536
+ SelectParams (gArgs .GetChainName ());
526
537
} catch (std::exception &e) {
527
- node-> initError (Untranslated (strprintf (" %s\n " , e.what ())));
538
+ InitError (Untranslated (strprintf (" %s\n " , e.what ())));
528
539
QMessageBox::critical (nullptr , PACKAGE_NAME, QObject::tr (" Error: %1" ).arg (e.what ()));
529
540
return EXIT_FAILURE;
530
541
}
531
542
#ifdef ENABLE_WALLET
532
543
// Parse URIs on command line -- this can affect Params()
533
- PaymentServer::ipcParseCommandLine (*node, argc, argv);
544
+ PaymentServer::ipcParseCommandLine (argc, argv);
534
545
#endif
535
- if (!node-> initSettings (error)) {
536
- node-> initError (Untranslated (error));
546
+ if (!gArgs . InitSettings (error)) {
547
+ InitError (Untranslated (error));
537
548
QMessageBox::critical (nullptr , PACKAGE_NAME, QObject::tr (" Error initializing settings: %1" ).arg (QString::fromStdString (error)));
538
549
return EXIT_FAILURE;
539
550
}
@@ -587,6 +598,8 @@ int GuiMain(int argc, char* argv[])
587
598
if (gArgs .GetBoolArg (" -splash" , DEFAULT_SPLASHSCREEN) && !gArgs .GetBoolArg (" -min" , false ))
588
599
app.createSplashScreen (networkStyle.data ());
589
600
601
+ app.setNode (*node);
602
+
590
603
int rv = EXIT_SUCCESS;
591
604
try
592
605
{
@@ -609,10 +622,10 @@ int GuiMain(int argc, char* argv[])
609
622
}
610
623
} catch (const std::exception & e) {
611
624
PrintExceptionContinue (&e, " Runaway exception" );
612
- app.handleRunawayException (QString::fromStdString (node-> getWarnings ().translated ));
625
+ app.handleRunawayException (QString::fromStdString (app. node (). getWarnings ().translated ));
613
626
} catch (...) {
614
627
PrintExceptionContinue (nullptr , " Runaway exception" );
615
- app.handleRunawayException (QString::fromStdString (node-> getWarnings ().translated ));
628
+ app.handleRunawayException (QString::fromStdString (app. node (). getWarnings ().translated ));
616
629
}
617
630
return rv;
618
631
}
0 commit comments