mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
Deduplicate bitcoind and bitcoin-qt init code
Add common InitConfig function to deduplicate bitcoind and bitcoin-qt code reading config files and creating the datadir. There are a few minor changes in behavior: - In bitcoin-qt, when there is a problem reading the configuration file, the GUI error text has changed from "Error: Cannot parse configuration file:" to "Error reading configuration file:" to be consistent with bitcoind. - In bitcoind, when there is a problem reading the settings.json file, the error text has changed from "Failed loading settings file" to "Settings file could not be read" to be consistent with bitcoin-qt. - In bitcoind, when there is a problem writing the settings.json file, the error text has changed from "Failed saving settings file" to "Settings file could not be written" to be consistent with bitcoin-qt. - In bitcoin-qt, if there datadir is not accessible (e.g. no permission to read), there is an normal error dialog showing "Error: filesystem error: status: Permission denied [.../settings.json]", instead of an uncaught exception
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <chainparams.h>
|
||||
#include <clientversion.h>
|
||||
#include <common/init.h>
|
||||
#include <common/url.h>
|
||||
#include <compat/compat.h>
|
||||
#include <init.h>
|
||||
@@ -150,17 +151,8 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
|
||||
std::any context{&node};
|
||||
try
|
||||
{
|
||||
if (!CheckDataDirOption(args)) {
|
||||
return InitError(Untranslated(strprintf("Specified data directory \"%s\" does not exist.", args.GetArg("-datadir", ""))));
|
||||
}
|
||||
if (!args.ReadConfigFiles(error, true)) {
|
||||
return InitError(Untranslated(strprintf("Error reading configuration file: %s", error)));
|
||||
}
|
||||
// Check for chain settings (Params() calls are only valid after this clause)
|
||||
try {
|
||||
SelectParams(args.GetChainName());
|
||||
} catch (const std::exception& e) {
|
||||
return InitError(Untranslated(strprintf("%s", e.what())));
|
||||
if (auto error = common::InitConfig(args)) {
|
||||
return InitError(error->message, error->details);
|
||||
}
|
||||
|
||||
// Error out when loose non-argument tokens are encountered on command line
|
||||
@@ -170,11 +162,6 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (!args.InitSettings(error)) {
|
||||
InitError(Untranslated(error));
|
||||
return false;
|
||||
}
|
||||
|
||||
// -server defaults to true for bitcoind but not for the GUI so do this here
|
||||
args.SoftSetBoolArg("-server", true);
|
||||
// Set this early so that parameter interactions go to console
|
||||
|
||||
Reference in New Issue
Block a user