Skip to content

Commit a1e1ef8

Browse files
committed
bitcoin.cpp: rebase node initialization for upstream master
"legacy GUI" comments added to indicate which helper functions execute the corresponding code in legacy qt/bitcoin.cpp common::InitConfig was created in bitcoin/bitcoin#27150 to de-duplicate a lot of this code. gArgs.GetChainTypeString() was added in bitcoin/bitcoin#27491
1 parent ee7928a commit a1e1ef8

File tree

1 file changed

+26
-39
lines changed

1 file changed

+26
-39
lines changed

qml/bitcoin.cpp

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
#include <qml/bitcoin.h>
66

7+
#include <common/args.h>
8+
#include <common/init.h>
9+
#include <common/system.h>
710
#include <chainparams.h>
811
#include <common/args.h>
912
#include <common/system.h>
@@ -12,6 +15,7 @@
1215
#include <interfaces/init.h>
1316
#include <interfaces/node.h>
1417
#include <logging.h>
18+
#include <node/context.h>
1519
#include <node/interface_ui.h>
1620
#include <noui.h>
1721
#include <qml/appmode.h>
@@ -181,60 +185,48 @@ int QmlGuiMain(int argc, char* argv[])
181185
Q_INIT_RESOURCE(bitcoin_qml);
182186
qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>("interfaces::BlockAndHeaderTipInfo");
183187

184-
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
185188
QGuiApplication::styleHints()->setTabFocusBehavior(Qt::TabFocusAllControls);
186189
QGuiApplication app(argc, argv);
187190

188-
auto handler_message_box = ::uiInterface.ThreadSafeMessageBox_connect(InitErrorMessageBox);
189-
190191
std::unique_ptr<interfaces::Init> init = interfaces::MakeGuiInit(argc, argv);
192+
auto handler_message_box = ::uiInterface.ThreadSafeMessageBox_connect(InitErrorMessageBox);
191193

192194
SetupEnvironment();
193195
util::ThreadSetInternalName("main");
194196

195197
// must be set before parsing command-line options; otherwise,
196198
// if invalid parameters were passed, QSetting initialization would fail
197-
// and the error will be displayed on terminal
199+
// and the error will be displayed on terminal.
200+
// must be set before OptionsModel is initialized or translations are loaded,
201+
// as it is used to locate QSettings
198202
app.setOrganizationName(QAPP_ORG_NAME);
199203
app.setOrganizationDomain(QAPP_ORG_DOMAIN);
200204
app.setApplicationName(QAPP_APP_NAME_DEFAULT);
201205

202-
/// Parse command-line options. We do this after qt in order to show an error if there are problems parsing these.
203-
SetupServerArgs(gArgs);
206+
// Parse command-line options. We do this after qt in order to show an error if there are problems parsing these.
207+
SetupServerArgs(gArgs, init->canListenIpc());
208+
204209
SetupUIArgs(gArgs);
205210
std::string error;
206211
if (!gArgs.ParseParameters(argc, argv, error)) {
207212
InitError(Untranslated(strprintf("Cannot parse command line arguments: %s\n", error)));
208213
return EXIT_FAILURE;
209214
}
210215

211-
/// Determine availability of data directory.
212-
if (!CheckDataDirOption(gArgs)) {
213-
InitError(Untranslated(strprintf("Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", ""))));
214-
return EXIT_FAILURE;
215-
}
216-
217-
/// Read and parse bitcoin.conf file.
218-
if (!gArgs.ReadConfigFiles(error, true)) {
219-
InitError(Untranslated(strprintf("Cannot parse configuration file: %s\n", error)));
216+
if (auto error = common::InitConfig(
217+
gArgs,
218+
[](const bilingual_str& msg, const std::vector<std::string>& details) {
219+
return InitError(msg, details);
220+
})) {
220221
return EXIT_FAILURE;
221222
}
222223

223-
/// Check for chain settings (Params() calls are only valid after this clause).
224-
try {
225-
SelectParams(gArgs.GetChainType());
226-
} catch(std::exception &e) {
227-
InitError(Untranslated(strprintf("%s\n", e.what())));
228-
return EXIT_FAILURE;
229-
}
230-
231-
/// Read and parse settings.json file.
232-
std::vector<std::string> errors;
233-
if (!gArgs.ReadSettingsFile(&errors)) {
234-
error = strprintf("Failed loading settings file:\n%s\n", MakeUnorderedList(errors));
235-
InitError(Untranslated(error));
236-
return EXIT_FAILURE;
237-
}
224+
// legacy GUI: parameterSetup()
225+
// Default printtoconsole to false for the GUI. GUI programs should not
226+
// print to the console unnecessarily.
227+
gArgs.SoftSetBoolArg("-printtoconsole", false);
228+
InitLogging(gArgs);
229+
InitParameterInteraction(gArgs);
238230

239231
QVariant need_onboarding(true);
240232
if (gArgs.IsArgSet("-datadir") && !gArgs.GetPathArg("-datadir").empty()) {
@@ -247,16 +239,11 @@ int QmlGuiMain(int argc, char* argv[])
247239
need_onboarding.setValue(true);
248240
}
249241

250-
// Default printtoconsole to false for the GUI. GUI programs should not
251-
// print to the console unnecessarily.
252-
gArgs.SoftSetBoolArg("-printtoconsole", false);
253-
InitLogging(gArgs);
254-
InitParameterInteraction(gArgs);
255-
256-
GUIUtil::LogQtInfo();
257-
242+
// legacy GUI: createNode()
258243
std::unique_ptr<interfaces::Node> node = init->makeNode();
259244
std::unique_ptr<interfaces::Chain> chain = init->makeChain();
245+
246+
// legacy GUI: baseInitialize()
260247
if (!node->baseInitialize()) {
261248
// A dialog with detailed error will have been shown by InitError().
262249
return EXIT_FAILURE;
@@ -287,7 +274,7 @@ int QmlGuiMain(int argc, char* argv[])
287274
#endif
288275

289276
ChainModel chain_model{*chain};
290-
chain_model.setCurrentNetworkName(QString::fromStdString(ChainTypeToString(gArgs.GetChainType())));
277+
chain_model.setCurrentNetworkName(QString::fromStdString(gArgs.GetChainTypeString()));
291278
setupChainQSettings(&app, chain_model.currentNetworkName());
292279

293280
QObject::connect(&node_model, &NodeModel::setTimeRatioList, &chain_model, &ChainModel::setTimeRatioList);

0 commit comments

Comments
 (0)