-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse params directly instead of through node (partial revert #10244) #35
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e133631
gui: Partially revert #10244 gArgs and Params changes
ryanofsky 91aced7
gui: Remove unused interfaces::Node references
ryanofsky 102abff
gui: Replace interface::Node references with pointers
ryanofsky 519cae8
gui: Delay interfaces::Node initialization
ryanofsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -27,16 +27,19 @@ | |||||
#include <qt/walletmodel.h> | ||||||
#endif // ENABLE_WALLET | ||||||
|
||||||
#include <init.h> | ||||||
#include <interfaces/handler.h> | ||||||
#include <interfaces/node.h> | ||||||
#include <node/context.h> | ||||||
#include <node/ui_interface.h> | ||||||
#include <noui.h> | ||||||
#include <uint256.h> | ||||||
#include <util/system.h> | ||||||
#include <util/threadnames.h> | ||||||
#include <util/translation.h> | ||||||
#include <validation.h> | ||||||
|
||||||
#include <boost/signals2/connection.hpp> | ||||||
#include <memory> | ||||||
|
||||||
#include <QApplication> | ||||||
|
@@ -193,10 +196,9 @@ void BitcoinCore::shutdown() | |||||
static int qt_argc = 1; | ||||||
static const char* qt_argv = "bitcoin-qt"; | ||||||
|
||||||
BitcoinApplication::BitcoinApplication(interfaces::Node& node): | ||||||
BitcoinApplication::BitcoinApplication(): | ||||||
QApplication(qt_argc, const_cast<char **>(&qt_argv)), | ||||||
coreThread(nullptr), | ||||||
m_node(node), | ||||||
optionsModel(nullptr), | ||||||
clientModel(nullptr), | ||||||
window(nullptr), | ||||||
|
@@ -246,38 +248,47 @@ void BitcoinApplication::createPaymentServer() | |||||
|
||||||
void BitcoinApplication::createOptionsModel(bool resetSettings) | ||||||
{ | ||||||
optionsModel = new OptionsModel(m_node, this, resetSettings); | ||||||
optionsModel = new OptionsModel(this, resetSettings); | ||||||
} | ||||||
|
||||||
void BitcoinApplication::createWindow(const NetworkStyle *networkStyle) | ||||||
{ | ||||||
window = new BitcoinGUI(m_node, platformStyle, networkStyle, nullptr); | ||||||
window = new BitcoinGUI(node(), platformStyle, networkStyle, nullptr); | ||||||
|
||||||
pollShutdownTimer = new QTimer(window); | ||||||
connect(pollShutdownTimer, &QTimer::timeout, window, &BitcoinGUI::detectShutdown); | ||||||
} | ||||||
|
||||||
void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle) | ||||||
{ | ||||||
SplashScreen *splash = new SplashScreen(m_node, nullptr, networkStyle); | ||||||
assert(!m_splash); | ||||||
m_splash = new SplashScreen(nullptr, networkStyle); | ||||||
// We don't hold a direct pointer to the splash screen after creation, but the splash | ||||||
// screen will take care of deleting itself when finish() happens. | ||||||
splash->show(); | ||||||
connect(this, &BitcoinApplication::splashFinished, splash, &SplashScreen::finish); | ||||||
connect(this, &BitcoinApplication::requestedShutdown, splash, &QWidget::close); | ||||||
m_splash->show(); | ||||||
connect(this, &BitcoinApplication::splashFinished, m_splash, &SplashScreen::finish); | ||||||
connect(this, &BitcoinApplication::requestedShutdown, m_splash, &QWidget::close); | ||||||
} | ||||||
|
||||||
void BitcoinApplication::setNode(interfaces::Node& node) | ||||||
{ | ||||||
assert(!m_node); | ||||||
m_node = &node; | ||||||
if (optionsModel) optionsModel->setNode(*m_node); | ||||||
if (m_splash) m_splash->setNode(*m_node); | ||||||
} | ||||||
|
||||||
bool BitcoinApplication::baseInitialize() | ||||||
{ | ||||||
return m_node.baseInitialize(); | ||||||
return node().baseInitialize(); | ||||||
} | ||||||
|
||||||
void BitcoinApplication::startThread() | ||||||
{ | ||||||
if(coreThread) | ||||||
return; | ||||||
coreThread = new QThread(this); | ||||||
BitcoinCore *executor = new BitcoinCore(m_node); | ||||||
BitcoinCore *executor = new BitcoinCore(node()); | ||||||
executor->moveToThread(coreThread); | ||||||
|
||||||
/* communication to and from thread */ | ||||||
|
@@ -298,8 +309,8 @@ void BitcoinApplication::parameterSetup() | |||||
// print to the console unnecessarily. | ||||||
gArgs.SoftSetBoolArg("-printtoconsole", false); | ||||||
|
||||||
m_node.initLogging(); | ||||||
m_node.initParameterInteraction(); | ||||||
InitLogging(gArgs); | ||||||
InitParameterInteraction(gArgs); | ||||||
} | ||||||
|
||||||
void BitcoinApplication::InitializePruneSetting(bool prune) | ||||||
|
@@ -331,7 +342,7 @@ void BitcoinApplication::requestShutdown() | |||||
window->unsubscribeFromCoreSignals(); | ||||||
// Request node shutdown, which can interrupt long operations, like | ||||||
// rescanning a wallet. | ||||||
m_node.startShutdown(); | ||||||
node().startShutdown(); | ||||||
// Unsetting the client model can cause the current thread to wait for node | ||||||
// to complete an operation, like wait for a RPC execution to complete. | ||||||
window->setClientModel(nullptr); | ||||||
|
@@ -353,7 +364,7 @@ void BitcoinApplication::initializeResult(bool success, interfaces::BlockAndHead | |||||
{ | ||||||
// Log this only after AppInitMain finishes, as then logging setup is guaranteed complete | ||||||
qInfo() << "Platform customization:" << platformStyle->getName(); | ||||||
clientModel = new ClientModel(m_node, optionsModel); | ||||||
clientModel = new ClientModel(node(), optionsModel); | ||||||
window->setClientModel(clientModel, &tip_info); | ||||||
#ifdef ENABLE_WALLET | ||||||
if (WalletModel::isWalletEnabled()) { | ||||||
|
@@ -437,9 +448,9 @@ int GuiMain(int argc, char* argv[]) | |||||
std::unique_ptr<interfaces::Node> node = interfaces::MakeNode(&node_context); | ||||||
|
||||||
// Subscribe to global signals from core | ||||||
std::unique_ptr<interfaces::Handler> handler_message_box = node->handleMessageBox(noui_ThreadSafeMessageBox); | ||||||
std::unique_ptr<interfaces::Handler> handler_question = node->handleQuestion(noui_ThreadSafeQuestion); | ||||||
std::unique_ptr<interfaces::Handler> handler_init_message = node->handleInitMessage(noui_InitMessage); | ||||||
boost::signals2::scoped_connection handler_message_box = ::uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox); | ||||||
boost::signals2::scoped_connection handler_question = ::uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion); | ||||||
boost::signals2::scoped_connection handler_init_message = ::uiInterface.InitMessage_connect(noui_InitMessage); | ||||||
|
||||||
// Do not refer to data directory yet, this can be overridden by Intro::pickDataDirectory | ||||||
|
||||||
|
@@ -453,15 +464,15 @@ int GuiMain(int argc, char* argv[]) | |||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); | ||||||
#endif | ||||||
|
||||||
BitcoinApplication app(*node); | ||||||
BitcoinApplication app; | ||||||
|
||||||
/// 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->setupServerArgs(); | ||||||
SetupServerArgs(node_context); | ||||||
SetupUIArgs(gArgs); | ||||||
std::string error; | ||||||
if (!node->parseParameters(argc, argv, error)) { | ||||||
node->initError(strprintf(Untranslated("Error parsing command line arguments: %s\n"), error)); | ||||||
if (!gArgs.ParseParameters(argc, argv, error)) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: (if feedback is addressed) Could use
Suggested change
here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
InitError(strprintf(Untranslated("Error parsing command line arguments: %s\n"), error)); | ||||||
// Create a message box, because the gui has neither been created nor has subscribed to core signals | ||||||
QMessageBox::critical(nullptr, PACKAGE_NAME, | ||||||
// message can not be translated because translations have not been initialized | ||||||
|
@@ -487,7 +498,7 @@ int GuiMain(int argc, char* argv[]) | |||||
// Show help message immediately after parsing command-line options (for "-lang") and setting locale, | ||||||
// but before showing splash screen. | ||||||
if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) { | ||||||
HelpMessageDialog help(*node, nullptr, gArgs.IsArgSet("-version")); | ||||||
HelpMessageDialog help(nullptr, gArgs.IsArgSet("-version")); | ||||||
help.showOrPrint(); | ||||||
return EXIT_SUCCESS; | ||||||
} | ||||||
|
@@ -497,18 +508,18 @@ int GuiMain(int argc, char* argv[]) | |||||
bool did_show_intro = false; | ||||||
bool prune = false; // Intro dialog prune check box | ||||||
// Gracefully exit if the user cancels | ||||||
if (!Intro::showIfNeeded(*node, did_show_intro, prune)) return EXIT_SUCCESS; | ||||||
if (!Intro::showIfNeeded(did_show_intro, prune)) return EXIT_SUCCESS; | ||||||
|
||||||
/// 6. Determine availability of data directory and parse bitcoin.conf | ||||||
/// - Do not call GetDataDir(true) before this step finishes | ||||||
if (!CheckDataDirOption()) { | ||||||
node->initError(strprintf(Untranslated("Specified data directory \"%s\" does not exist.\n"), gArgs.GetArg("-datadir", ""))); | ||||||
InitError(strprintf(Untranslated("Specified data directory \"%s\" does not exist.\n"), gArgs.GetArg("-datadir", ""))); | ||||||
QMessageBox::critical(nullptr, PACKAGE_NAME, | ||||||
QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(gArgs.GetArg("-datadir", "")))); | ||||||
return EXIT_FAILURE; | ||||||
} | ||||||
if (!node->readConfigFiles(error)) { | ||||||
node->initError(strprintf(Untranslated("Error reading configuration file: %s\n"), error)); | ||||||
if (!gArgs.ReadConfigFiles(error, true)) { | ||||||
InitError(strprintf(Untranslated("Error reading configuration file: %s\n"), error)); | ||||||
QMessageBox::critical(nullptr, PACKAGE_NAME, | ||||||
QObject::tr("Error: Cannot parse configuration file: %1.").arg(QString::fromStdString(error))); | ||||||
return EXIT_FAILURE; | ||||||
|
@@ -522,18 +533,18 @@ int GuiMain(int argc, char* argv[]) | |||||
|
||||||
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause) | ||||||
try { | ||||||
node->selectParams(gArgs.GetChainName()); | ||||||
SelectParams(gArgs.GetChainName()); | ||||||
} catch(std::exception &e) { | ||||||
node->initError(Untranslated(strprintf("%s\n", e.what()))); | ||||||
InitError(Untranslated(strprintf("%s\n", e.what()))); | ||||||
QMessageBox::critical(nullptr, PACKAGE_NAME, QObject::tr("Error: %1").arg(e.what())); | ||||||
return EXIT_FAILURE; | ||||||
} | ||||||
#ifdef ENABLE_WALLET | ||||||
// Parse URIs on command line -- this can affect Params() | ||||||
PaymentServer::ipcParseCommandLine(*node, argc, argv); | ||||||
PaymentServer::ipcParseCommandLine(argc, argv); | ||||||
#endif | ||||||
if (!node->initSettings(error)) { | ||||||
node->initError(Untranslated(error)); | ||||||
if (!gArgs.InitSettings(error)) { | ||||||
InitError(Untranslated(error)); | ||||||
QMessageBox::critical(nullptr, PACKAGE_NAME, QObject::tr("Error initializing settings: %1").arg(QString::fromStdString(error))); | ||||||
return EXIT_FAILURE; | ||||||
} | ||||||
|
@@ -587,6 +598,8 @@ int GuiMain(int argc, char* argv[]) | |||||
if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false)) | ||||||
app.createSplashScreen(networkStyle.data()); | ||||||
|
||||||
app.setNode(*node); | ||||||
|
||||||
int rv = EXIT_SUCCESS; | ||||||
try | ||||||
{ | ||||||
|
@@ -609,10 +622,10 @@ int GuiMain(int argc, char* argv[]) | |||||
} | ||||||
} catch (const std::exception& e) { | ||||||
PrintExceptionContinue(&e, "Runaway exception"); | ||||||
app.handleRunawayException(QString::fromStdString(node->getWarnings().translated)); | ||||||
app.handleRunawayException(QString::fromStdString(app.node().getWarnings().translated)); | ||||||
} catch (...) { | ||||||
PrintExceptionContinue(nullptr, "Runaway exception"); | ||||||
app.handleRunawayException(QString::fromStdString(node->getWarnings().translated)); | ||||||
app.handleRunawayException(QString::fromStdString(app.node().getWarnings().translated)); | ||||||
} | ||||||
return rv; | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Could add an unused reference to the argsmanager that is supposed to be used by gui code (instead of the global).
Would either be
const ArgsManager& args = *node_context.args
or= gArgs
?Feel free to ingore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: #35 (comment)
I started implementing this but stopped because there are a number of other uses of gArgs in this function that I thought it would be better not to change here to avoid increasing the size of the PR.
Bigger picture, gArgs is used pretty widely in many parts of qt code and I think that if it's going to be removed, it'd be best to do it in a focused PR updating all the references at the same time.