Coverage Report

Created: 2026-08-14 20:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/tmp/bitcoin/src/common/args.cpp
Line
Count
Source
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-present The Bitcoin Core developers
3
// Distributed under the MIT software license, see the accompanying
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6
#include <common/args.h>
7
8
#include <chainparamsbase.h>
9
#include <common/settings.h>
10
#include <sync.h>
11
#include <tinyformat.h>
12
#include <univalue.h>
13
#include <util/chaintype.h>
14
#include <util/check.h>
15
#include <util/fs.h>
16
#include <util/fs_helpers.h>
17
#include <util/log.h>
18
#include <util/strencodings.h>
19
#include <util/string.h>
20
21
#ifdef WIN32
22
#include <shlobj.h>
23
#endif
24
25
#include <algorithm>
26
#include <cstdlib>
27
#include <cstring>
28
#include <map>
29
#include <optional>
30
#include <stdexcept>
31
#include <string>
32
#include <utility>
33
#include <variant>
34
35
const char * const BITCOIN_CONF_FILENAME = "bitcoin.conf";
36
const char * const BITCOIN_SETTINGS_FILENAME = "settings.json";
37
38
ArgsManager gArgs;
39
40
/**
41
 * Interpret a string argument as a boolean.
42
 *
43
 * The definition of LocaleIndependentAtoi<int>() requires that non-numeric string values
44
 * like "foo", return 0. This means that if a user unintentionally supplies a
45
 * non-integer argument here, the return value is always false. This means that
46
 * -foo=false does what the user probably expects, but -foo=true is well defined
47
 * but does not do what they probably expected.
48
 *
49
 * The return value of LocaleIndependentAtoi<int>(...) is zero when given input not
50
 * representable as an int.
51
 *
52
 * For a more extensive discussion of this topic (and a wide range of opinions
53
 * on the Right Way to change this code), see PR12713.
54
 */
55
static bool InterpretBool(const std::string& strValue)
56
343k
{
57
343k
    if (strValue.empty())
58
18.7k
        return true;
59
324k
    return (LocaleIndependentAtoi<int>(strValue) != 0);
60
343k
}
61
62
static std::string SettingName(const std::string& arg)
63
1.18M
{
64
1.18M
    return arg.size() > 0 && arg[0] == '-' ? arg.substr(1) : arg;
65
1.18M
}
66
67
/**
68
 * Parse "name", "section.name", "noname", "section.noname" settings keys.
69
 *
70
 * @note Where an option was negated can be later checked using the
71
 * IsArgNegated() method. One use case for this is to have a way to disable
72
 * options that are not normally boolean (e.g. using -nodebuglogfile to request
73
 * that debug log output is not sent to any file at all).
74
 */
75
KeyInfo InterpretKey(std::string key)
76
391k
{
77
391k
    KeyInfo result;
78
    // Split section name from key name for keys like "testnet.foo" or "regtest.bar"
79
391k
    size_t option_index = key.find('.');
80
391k
    if (option_index != std::string::npos) {
81
142k
        result.section = key.substr(0, option_index);
82
142k
        key.erase(0, option_index + 1);
83
142k
    }
84
391k
    if (key.starts_with("no")) {
85
105k
        key.erase(0, 2);
86
105k
        result.negated = true;
87
105k
    }
88
391k
    result.name = key;
89
391k
    return result;
90
391k
}
91
92
/**
93
 * Interpret settings value based on registered flags.
94
 *
95
 * @param[in]   key      key information to know if key was negated
96
 * @param[in]   value    string value of setting to be parsed
97
 * @param[in]   flags    ArgsManager registered argument flags
98
 * @param[out]  error    Error description if settings value is not valid
99
 *
100
 * @return parsed settings value if it is valid, otherwise nullopt accompanied
101
 * by a descriptive error string
102
 */
103
std::optional<common::SettingsValue> InterpretValue(const KeyInfo& key, const std::string* value,
104
                                                  unsigned int flags, std::string& error)
105
368k
{
106
    // Return negated settings as false values.
107
368k
    if (key.negated) {
108
105k
        if (flags & ArgsManager::DISALLOW_NEGATION) {
109
0
            error = strprintf("Negating of -%s is meaningless and therefore forbidden", key.name);
110
0
            return std::nullopt;
111
0
        }
112
        // Double negatives like -nofoo=0 are supported (but discouraged)
113
105k
        if (value && !InterpretBool(*value)) {
114
12
            LogWarning("Parsed potentially confusing double-negative -%s=%s", key.name, *value);
115
12
            return true;
116
12
        }
117
105k
        return false;
118
105k
    }
119
262k
    if (!value && (flags & ArgsManager::DISALLOW_ELISION)) {
120
1
        error = strprintf("Can not set -%s with no value. Please specify value with -%s=value.", key.name, key.name);
121
1
        return std::nullopt;
122
1
    }
123
262k
    return value ? *value : "";
124
262k
}
125
126
// Define default constructor and destructor that are not inline, so code instantiating this class doesn't need to
127
// #include class definitions for all members.
128
// For example, m_settings has an internal dependency on univalue.
129
52.2k
ArgsManager::ArgsManager() = default;
130
49.6k
ArgsManager::~ArgsManager() = default;
131
132
std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs() const
133
49.3k
{
134
49.3k
    std::set<std::string> unsuitables;
135
136
49.3k
    LOCK(cs_args);
137
138
    // if there's no section selected, don't worry
139
49.3k
    if (m_network.empty()) return std::set<std::string> {};
140
141
    // if it's okay to use the default section for this network, don't worry
142
49.3k
    if (m_network == ChainTypeToString(ChainType::MAIN)) return std::set<std::string> {};
143
144
36.8k
    for (const auto& arg : m_network_only_args) {
145
28.0k
        if (OnlyHasDefaultSectionSetting(m_settings, m_network, SettingName(arg))) {
146
1.75k
            unsuitables.insert(arg);
147
1.75k
        }
148
28.0k
    }
149
36.8k
    return unsuitables;
150
49.3k
}
151
152
std::list<SectionInfo> ArgsManager::GetUnrecognizedSections() const
153
1.88k
{
154
    // Section names to be recognized in the config file.
155
1.88k
    static const std::set<std::string> available_sections{
156
1.88k
        ChainTypeToString(ChainType::REGTEST),
157
1.88k
        ChainTypeToString(ChainType::SIGNET),
158
1.88k
        ChainTypeToString(ChainType::TESTNET),
159
1.88k
        ChainTypeToString(ChainType::TESTNET4),
160
1.88k
        ChainTypeToString(ChainType::MAIN),
161
1.88k
    };
162
163
1.88k
    LOCK(cs_args);
164
1.88k
    std::list<SectionInfo> unrecognized = m_config_sections;
165
1.88k
    unrecognized.remove_if([](const SectionInfo& appeared){ return available_sections.contains(appeared.m_name); });
166
1.88k
    return unrecognized;
167
1.88k
}
168
169
void ArgsManager::SelectConfigNetwork(const std::string& network)
170
51.0k
{
171
51.0k
    LOCK(cs_args);
172
51.0k
    m_network = network;
173
51.0k
}
174
175
bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::string& error)
176
52.2k
{
177
52.2k
    LOCK(cs_args);
178
52.2k
    m_settings.command_line_options.clear();
179
180
205k
    for (int i = 1; i < argc; i++) {
181
154k
        std::string key(argv[i]);
182
183
#ifdef __APPLE__
184
        // At the first time when a user gets the "App downloaded from the
185
        // internet" warning, and clicks the Open button, macOS passes
186
        // a unique process serial number (PSN) as -psn_... command-line
187
        // argument, which we filter out.
188
        if (key.starts_with("-psn_")) continue;
189
#endif
190
191
154k
        if (key == "-") break; //bitcoin-tx using stdin
192
154k
        std::optional<std::string> val;
193
154k
        size_t is_index = key.find('=');
194
154k
        if (is_index != std::string::npos) {
195
141k
            val = key.substr(is_index + 1);
196
141k
            key.erase(is_index);
197
141k
        }
198
#ifdef WIN32
199
        key = ToLower(key);
200
        if (key[0] == '/')
201
            key[0] = '-';
202
#endif
203
204
154k
        if (key[0] != '-') {
205
946
            if (!m_accept_any_command && m_command.empty()) {
206
                // The first non-dash arg is a registered command
207
65
                std::optional<unsigned int> flags = GetArgFlags_(key);
208
65
                if (!flags || !(*flags & ArgsManager::COMMAND)) {
209
5
                    error = strprintf("Invalid command '%s'", argv[i]);
210
5
                    return false;
211
5
                }
212
65
            }
213
941
            m_command.push_back(key);
214
2.04k
            while (++i < argc) {
215
                // The remaining args are command args
216
1.10k
                m_command.emplace_back(argv[i]);
217
1.10k
            }
218
941
            break;
219
946
        }
220
221
        // Transform --foo to -foo
222
153k
        if (key.length() > 1 && key[1] == '-')
223
6
            key.erase(0, 1);
224
225
        // Transform -foo to foo
226
153k
        key.erase(0, 1);
227
153k
        KeyInfo keyinfo = InterpretKey(key);
228
153k
        std::optional<unsigned int> flags = GetArgFlags_('-' + keyinfo.name);
229
230
        // Unknown command line options and command line options with dot
231
        // characters (which are returned from InterpretKey with nonempty
232
        // section strings) are not valid.
233
153k
        if (!flags || !keyinfo.section.empty()) {
234
11
            error = strprintf("Invalid parameter %s", argv[i]);
235
11
            return false;
236
11
        }
237
238
153k
        std::optional<common::SettingsValue> value = InterpretValue(keyinfo, val ? &*val : nullptr, *flags, error);
239
153k
        if (!value) return false;
240
241
153k
        m_settings.command_line_options[keyinfo.name].push_back(*value);
242
153k
    }
243
244
    // we do not allow -includeconf from command line, only -noincludeconf
245
52.2k
    if (auto* includes = common::FindKey(m_settings.command_line_options, "includeconf")) {
246
5
        const common::SettingsSpan values{*includes};
247
        // Range may be empty if -noincludeconf was passed
248
5
        if (!values.empty()) {
249
4
            error = "-includeconf cannot be used from commandline; -includeconf=" + values.begin()->write();
250
4
            return false; // pick first value as example
251
4
        }
252
5
    }
253
52.2k
    return true;
254
52.2k
}
255
256
std::optional<unsigned int> ArgsManager::GetArgFlags_(const std::string& name) const
257
433k
{
258
433k
    AssertLockHeld(cs_args);
259
839k
    for (const auto& arg_map : m_available_args) {
260
839k
        const auto search = arg_map.second.find(name);
261
839k
        if (search != arg_map.second.end()) {
262
410k
            return search->second.m_flags;
263
410k
        }
264
839k
    }
265
23.3k
    return m_default_flags;
266
433k
}
267
268
std::optional<unsigned int> ArgsManager::GetArgFlags(const std::string& name) const
269
0
{
270
0
    LOCK(cs_args);
271
0
    return GetArgFlags_(name);
272
0
}
273
274
void ArgsManager::SetDefaultFlags(std::optional<unsigned int> flags)
275
0
{
276
0
    LOCK(cs_args);
277
0
    m_default_flags = flags;
278
0
}
279
280
fs::path ArgsManager::GetPathArg_(std::string arg, const fs::path& default_value) const
281
30.8k
{
282
30.8k
    AssertLockHeld(cs_args);
283
30.8k
    const auto value = GetSetting_(arg);
284
30.8k
    if (value.isFalse()) return {};
285
30.8k
    std::string path_str = SettingToString(value, "");
286
30.8k
    if (path_str.empty()) return default_value;
287
13.5k
    fs::path result = fs::PathFromString(path_str).lexically_normal();
288
    // Remove trailing slash, if present.
289
13.5k
    return result.has_filename() ? result : result.parent_path();
290
30.8k
}
291
292
fs::path ArgsManager::GetPathArg(std::string arg, const fs::path& default_value) const
293
20.9k
{
294
20.9k
    LOCK(cs_args);
295
20.9k
    return GetPathArg_(std::move(arg), default_value);
296
20.9k
}
297
298
fs::path ArgsManager::GetBlocksDirPath() const
299
8.80k
{
300
8.80k
    LOCK(cs_args);
301
8.80k
    fs::path& path = m_cached_blocks_path;
302
303
    // Cache the path to avoid calling fs::create_directories on every call of
304
    // this function
305
8.80k
    if (!path.empty()) return path;
306
307
2.05k
    if (!GetSetting_("-blocksdir").isNull()) {
308
3
        path = fs::absolute(GetPathArg_("-blocksdir"));
309
3
        if (!fs::is_directory(path)) {
310
1
            path = "";
311
1
            return path;
312
1
        }
313
2.05k
    } else {
314
2.05k
        path = GetDataDir(/*net_specific=*/false);
315
2.05k
    }
316
317
2.05k
    path /= fs::PathFromString(BaseParams().DataDir());
318
2.05k
    path /= "blocks";
319
2.05k
    fs::create_directories(path);
320
2.05k
    return path;
321
2.05k
}
322
323
3.81k
fs::path ArgsManager::GetDataDirBase() const {
324
3.81k
    LOCK(cs_args);
325
3.81k
    return GetDataDir(/*net_specific=*/false);
326
3.81k
}
327
328
35.5k
fs::path ArgsManager::GetDataDirNet() const {
329
35.5k
    LOCK(cs_args);
330
35.5k
    return GetDataDir(/*net_specific=*/true);
331
35.5k
}
332
333
fs::path ArgsManager::GetDataDir(bool net_specific) const
334
43.6k
{
335
43.6k
    AssertLockHeld(cs_args);
336
43.6k
    fs::path& path = net_specific ? m_cached_network_datadir_path : m_cached_datadir_path;
337
338
    // Used cached path if available
339
43.6k
    if (!path.empty()) return path;
340
341
7.62k
    const fs::path datadir{GetPathArg_("-datadir")};
342
7.62k
    if (!datadir.empty()) {
343
7.61k
        path = fs::absolute(datadir);
344
7.61k
        if (!fs::is_directory(path)) {
345
0
            path = "";
346
0
            return path;
347
0
        }
348
7.61k
    } else {
349
5
        path = GetDefaultDataDir();
350
5
    }
351
352
7.62k
    if (net_specific && !BaseParams().DataDir().empty()) {
353
2.50k
        path /= fs::PathFromString(BaseParams().DataDir());
354
2.50k
    }
355
356
7.62k
    return path;
357
7.62k
}
358
359
void ArgsManager::ClearPathCache()
360
3.02k
{
361
3.02k
    LOCK(cs_args);
362
363
3.02k
    m_cached_datadir_path = fs::path();
364
3.02k
    m_cached_network_datadir_path = fs::path();
365
3.02k
    m_cached_blocks_path = fs::path();
366
3.02k
}
367
368
std::optional<const ArgsManager::Command> ArgsManager::GetCommand() const
369
62
{
370
62
    Command ret;
371
62
    LOCK(cs_args);
372
62
    auto it = m_command.begin();
373
62
    if (it == m_command.end()) {
374
        // No command was passed
375
2
        return std::nullopt;
376
2
    }
377
60
    if (!m_accept_any_command) {
378
        // The registered command
379
60
        ret.command = *(it++);
380
60
    }
381
72
    while (it != m_command.end()) {
382
        // The unregistered command and args (if any)
383
12
        ret.args.push_back(*(it++));
384
12
    }
385
60
    return ret;
386
62
}
387
388
bool ArgsManager::CheckCommandOptions(const std::string& command, std::vector<std::string>* errors) const
389
44
{
390
44
    LOCK(cs_args);
391
392
44
    auto command_options = m_available_args.find(OptionsCategory::COMMAND_OPTIONS);
393
44
    if (command_options == m_available_args.end()) {
394
        // There are no command-specific options at all, so everything is fine
395
0
        return true;
396
0
    }
397
398
44
    const auto command_args = m_command_args.find(command);
399
44
    auto is_valid_opt = [&](const auto& opt) EXCLUSIVE_LOCKS_REQUIRED(cs_args) -> bool {
400
32
        if (command_args == m_command_args.end()) {
401
            // Caller may not have checked that command actually exists
402
            // before calling this function.  In that case, treat it as
403
            // having no valid command-specific options.
404
5
            return false;
405
27
        } else {
406
27
            return command_args->second.contains(opt);
407
27
        }
408
32
    };
409
410
44
    bool ok = true;
411
57
    for (const auto& [arg, _] : command_options->second) {
412
57
        if (!GetSetting_(arg).isNull() && !is_valid_opt(arg)) {
413
7
            ok = false;
414
7
            if (errors != nullptr) {
415
7
                errors->emplace_back(strprintf("The %s option cannot be used with the '%s' command.", arg, command));
416
7
            }
417
7
        }
418
57
    }
419
44
    return ok;
420
44
}
421
422
std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const
423
224k
{
424
224k
    std::vector<std::string> result;
425
224k
    for (const common::SettingsValue& value : GetSettingsList(strArg)) {
426
95.6k
        result.push_back(value.isFalse() ? "0" : value.isTrue() ? "1" : value.get_str());
427
95.6k
    }
428
224k
    return result;
429
224k
}
430
431
bool ArgsManager::IsArgSet(const std::string& strArg) const
432
78.3k
{
433
78.3k
    return !GetSetting(strArg).isNull();
434
78.3k
}
435
436
bool ArgsManager::GetSettingsPath(fs::path* filepath, bool temp, bool backup) const
437
5.13k
{
438
5.13k
    fs::path settings = GetPathArg("-settings", BITCOIN_SETTINGS_FILENAME);
439
5.13k
    if (settings.empty()) {
440
3
        return false;
441
3
    }
442
5.12k
    if (backup) {
443
0
        settings += ".bak";
444
0
    }
445
5.12k
    if (filepath) {
446
3.94k
        *filepath = fsbridge::AbsPathJoin(GetDataDirNet(), temp ? settings + ".tmp" : settings);
447
3.94k
    }
448
5.12k
    return true;
449
5.13k
}
450
451
static void SaveErrors(const std::vector<std::string> errors, std::vector<std::string>* error_out)
452
4
{
453
4
    for (const auto& error : errors) {
454
4
        if (error_out) {
455
3
            error_out->emplace_back(error);
456
3
        } else {
457
1
            LogWarning("%s", error);
458
1
        }
459
4
    }
460
4
}
461
462
bool ArgsManager::ReadSettingsFile(std::vector<std::string>* errors)
463
1.18k
{
464
1.18k
    fs::path path;
465
1.18k
    if (!GetSettingsPath(&path, /* temp= */ false)) {
466
0
        return true; // Do nothing if settings file disabled.
467
0
    }
468
469
1.18k
    LOCK(cs_args);
470
1.18k
    m_settings.rw_settings.clear();
471
1.18k
    std::vector<std::string> read_errors;
472
1.18k
    if (!common::ReadSettings(path, m_settings.rw_settings, read_errors)) {
473
3
        SaveErrors(read_errors, errors);
474
3
        return false;
475
3
    }
476
1.18k
    for (const auto& setting : m_settings.rw_settings) {
477
126
        KeyInfo key = InterpretKey(setting.first); // Split setting key into section and argname
478
126
        if (!GetArgFlags_('-' + key.name)) {
479
7
            LogWarning("Ignoring unknown rw_settings value %s", setting.first);
480
7
        }
481
126
    }
482
1.18k
    return true;
483
1.18k
}
484
485
bool ArgsManager::WriteSettingsFile(std::vector<std::string>* errors, bool backup) const
486
1.37k
{
487
1.37k
    fs::path path, path_tmp;
488
1.37k
    if (!GetSettingsPath(&path, /*temp=*/false, backup) || !GetSettingsPath(&path_tmp, /*temp=*/true, backup)) {
489
0
        throw std::logic_error("Attempt to write settings file when dynamic settings are disabled.");
490
0
    }
491
492
1.37k
    LOCK(cs_args);
493
1.37k
    std::vector<std::string> write_errors;
494
1.37k
    if (!common::WriteSettings(path_tmp, m_settings.rw_settings, write_errors)) {
495
0
        SaveErrors(write_errors, errors);
496
0
        return false;
497
0
    }
498
1.37k
    if (!RenameOver(path_tmp, path)) {
499
1
        SaveErrors({strprintf("Failed renaming settings file %s to %s\n", fs::PathToString(path_tmp), fs::PathToString(path))}, errors);
500
1
        return false;
501
1
    }
502
1.37k
    return true;
503
1.37k
}
504
505
common::SettingsValue ArgsManager::GetPersistentSetting(const std::string& name) const
506
0
{
507
0
    LOCK(cs_args);
508
0
    return common::GetSetting(m_settings, m_network, name, !UseDefaultSection("-" + name),
509
0
        /*ignore_nonpersistent=*/true, /*get_chain_type=*/false);
510
0
}
511
512
bool ArgsManager::IsArgNegated(const std::string& strArg) const
513
54.0k
{
514
54.0k
    return GetSetting(strArg).isFalse();
515
54.0k
}
516
517
std::string ArgsManager::GetArg(const std::string& strArg, const std::string& strDefault) const
518
65.9k
{
519
65.9k
    return GetArg(strArg).value_or(strDefault);
520
65.9k
}
521
522
std::optional<std::string> ArgsManager::GetArg(const std::string& strArg) const
523
106k
{
524
106k
    const common::SettingsValue value = GetSetting(strArg);
525
106k
    return SettingToString(value);
526
106k
}
527
528
std::optional<std::string> SettingToString(const common::SettingsValue& value)
529
137k
{
530
137k
    if (value.isNull()) return std::nullopt;
531
67.1k
    if (value.isFalse()) return "0";
532
55.4k
    if (value.isTrue()) return "1";
533
55.4k
    if (value.isNum()) return value.getValStr();
534
55.4k
    return value.get_str();
535
55.4k
}
536
537
std::string SettingToString(const common::SettingsValue& value, const std::string& strDefault)
538
30.8k
{
539
30.8k
    return SettingToString(value).value_or(strDefault);
540
30.8k
}
541
542
template <std::integral Int>
543
Int ArgsManager::GetArg(const std::string& strArg, Int nDefault) const
544
98.4k
{
545
98.4k
    return GetArg<Int>(strArg).value_or(nDefault);
546
98.4k
}
Unexecuted instantiation: signed char ArgsManager::GetArg<signed char>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, signed char) const
unsigned char ArgsManager::GetArg<unsigned char>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned char) const
Line
Count
Source
544
7
{
545
7
    return GetArg<Int>(strArg).value_or(nDefault);
546
7
}
Unexecuted instantiation: short ArgsManager::GetArg<short>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, short) const
Unexecuted instantiation: unsigned short ArgsManager::GetArg<unsigned short>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned short) const
int ArgsManager::GetArg<int>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int) const
Line
Count
Source
544
2.25k
{
545
2.25k
    return GetArg<Int>(strArg).value_or(nDefault);
546
2.25k
}
Unexecuted instantiation: unsigned int ArgsManager::GetArg<unsigned int>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned int) const
long ArgsManager::GetArg<long>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, long) const
Line
Count
Source
544
96.2k
{
545
96.2k
    return GetArg<Int>(strArg).value_or(nDefault);
546
96.2k
}
Unexecuted instantiation: unsigned long ArgsManager::GetArg<unsigned long>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned long) const
547
548
template <std::integral Int>
549
std::optional<Int> ArgsManager::GetArg(const std::string& strArg) const
550
139k
{
551
139k
    const common::SettingsValue value = GetSetting(strArg);
552
139k
    return SettingTo<Int>(value);
553
139k
}
Unexecuted instantiation: std::optional<signed char> ArgsManager::GetArg<signed char>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
std::optional<unsigned char> ArgsManager::GetArg<unsigned char>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
Line
Count
Source
550
12
{
551
12
    const common::SettingsValue value = GetSetting(strArg);
552
12
    return SettingTo<Int>(value);
553
12
}
Unexecuted instantiation: std::optional<short> ArgsManager::GetArg<short>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
Unexecuted instantiation: std::optional<unsigned short> ArgsManager::GetArg<unsigned short>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
std::optional<int> ArgsManager::GetArg<int>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
Line
Count
Source
550
5.21k
{
551
5.21k
    const common::SettingsValue value = GetSetting(strArg);
552
5.21k
    return SettingTo<Int>(value);
553
5.21k
}
Unexecuted instantiation: std::optional<unsigned int> ArgsManager::GetArg<unsigned int>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
std::optional<long> ArgsManager::GetArg<long>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
Line
Count
Source
550
128k
{
551
128k
    const common::SettingsValue value = GetSetting(strArg);
552
128k
    return SettingTo<Int>(value);
553
128k
}
std::optional<unsigned long> ArgsManager::GetArg<unsigned long>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
Line
Count
Source
550
6.20k
{
551
6.20k
    const common::SettingsValue value = GetSetting(strArg);
552
6.20k
    return SettingTo<Int>(value);
553
6.20k
}
554
555
template <std::integral Int>
556
std::optional<Int> SettingTo(const common::SettingsValue& value)
557
139k
{
558
139k
    if (value.isNull()) return std::nullopt;
559
15.5k
    if (value.isFalse()) return 0;
560
15.5k
    if (value.isTrue()) return 1;
561
15.5k
    if (value.isNum()) return value.getInt<Int>();
562
15.5k
    return LocaleIndependentAtoi<Int>(value.get_str());
563
15.5k
}
Unexecuted instantiation: std::optional<signed char> SettingTo<signed char>(UniValue const&)
std::optional<unsigned char> SettingTo<unsigned char>(UniValue const&)
Line
Count
Source
557
12
{
558
12
    if (value.isNull()) return std::nullopt;
559
9
    if (value.isFalse()) return 0;
560
9
    if (value.isTrue()) return 1;
561
9
    if (value.isNum()) return value.getInt<Int>();
562
9
    return LocaleIndependentAtoi<Int>(value.get_str());
563
9
}
Unexecuted instantiation: std::optional<short> SettingTo<short>(UniValue const&)
Unexecuted instantiation: std::optional<unsigned short> SettingTo<unsigned short>(UniValue const&)
std::optional<int> SettingTo<int>(UniValue const&)
Line
Count
Source
557
5.21k
{
558
5.21k
    if (value.isNull()) return std::nullopt;
559
3.35k
    if (value.isFalse()) return 0;
560
3.35k
    if (value.isTrue()) return 1;
561
3.35k
    if (value.isNum()) return value.getInt<Int>();
562
3.35k
    return LocaleIndependentAtoi<Int>(value.get_str());
563
3.35k
}
Unexecuted instantiation: std::optional<unsigned int> SettingTo<unsigned int>(UniValue const&)
std::optional<long> SettingTo<long>(UniValue const&)
Line
Count
Source
557
128k
{
558
128k
    if (value.isNull()) return std::nullopt;
559
12.1k
    if (value.isFalse()) return 0;
560
12.1k
    if (value.isTrue()) return 1;
561
12.1k
    if (value.isNum()) return value.getInt<Int>();
562
12.1k
    return LocaleIndependentAtoi<Int>(value.get_str());
563
12.1k
}
std::optional<unsigned long> SettingTo<unsigned long>(UniValue const&)
Line
Count
Source
557
6.20k
{
558
6.20k
    if (value.isNull()) return std::nullopt;
559
16
    if (value.isFalse()) return 0;
560
16
    if (value.isTrue()) return 1;
561
16
    if (value.isNum()) return value.getInt<Int>();
562
16
    return LocaleIndependentAtoi<Int>(value.get_str());
563
16
}
564
565
template <std::integral Int>
566
Int SettingTo(const common::SettingsValue& value, Int nDefault)
567
0
{
568
0
    return SettingTo<Int>(value).value_or(nDefault);
569
0
}
Unexecuted instantiation: signed char SettingTo<signed char>(UniValue const&, signed char)
Unexecuted instantiation: unsigned char SettingTo<unsigned char>(UniValue const&, unsigned char)
Unexecuted instantiation: short SettingTo<short>(UniValue const&, short)
Unexecuted instantiation: unsigned short SettingTo<unsigned short>(UniValue const&, unsigned short)
Unexecuted instantiation: int SettingTo<int>(UniValue const&, int)
Unexecuted instantiation: unsigned int SettingTo<unsigned int>(UniValue const&, unsigned int)
Unexecuted instantiation: long SettingTo<long>(UniValue const&, long)
Unexecuted instantiation: unsigned long SettingTo<unsigned long>(UniValue const&, unsigned long)
570
571
bool ArgsManager::GetBoolArg(const std::string& strArg, bool fDefault) const
572
341k
{
573
341k
    return GetBoolArg(strArg).value_or(fDefault);
574
341k
}
575
576
std::optional<bool> ArgsManager::GetBoolArg(const std::string& strArg) const
577
366k
{
578
366k
    const common::SettingsValue value = GetSetting(strArg);
579
366k
    return SettingToBool(value);
580
366k
}
581
582
std::optional<bool> SettingToBool(const common::SettingsValue& value)
583
366k
{
584
366k
    if (value.isNull()) return std::nullopt;
585
231k
    if (value.isBool()) return value.get_bool();
586
230k
    return InterpretBool(value.get_str());
587
231k
}
588
589
bool SettingToBool(const common::SettingsValue& value, bool fDefault)
590
0
{
591
0
    return SettingToBool(value).value_or(fDefault);
592
0
}
593
594
#define INSTANTIATE_INT_TYPE(Type)                                                    \
595
    template Type ArgsManager::GetArg<Type>(const std::string&, Type) const;          \
596
    template std::optional<Type> ArgsManager::GetArg<Type>(const std::string&) const; \
597
    template Type SettingTo<Type>(const common::SettingsValue&, Type);                \
598
    template std::optional<Type> SettingTo<Type>(const common::SettingsValue&)
599
600
INSTANTIATE_INT_TYPE(int8_t);
601
INSTANTIATE_INT_TYPE(uint8_t);
602
INSTANTIATE_INT_TYPE(int16_t);
603
INSTANTIATE_INT_TYPE(uint16_t);
604
INSTANTIATE_INT_TYPE(int32_t);
605
INSTANTIATE_INT_TYPE(uint32_t);
606
INSTANTIATE_INT_TYPE(int64_t);
607
INSTANTIATE_INT_TYPE(uint64_t);
608
609
#undef INSTANTIATE_INT_TYPE
610
611
bool ArgsManager::SoftSetArg(const std::string& strArg, const std::string& strValue)
612
52.4k
{
613
52.4k
    LOCK(cs_args);
614
52.4k
    if (!GetSetting_(strArg).isNull()) return false;
615
1.97k
    m_settings.forced_settings[SettingName(strArg)] = strValue;
616
1.97k
    return true;
617
52.4k
}
618
619
bool ArgsManager::SoftSetBoolArg(const std::string& strArg, bool fValue)
620
4.90k
{
621
4.90k
    if (fValue)
622
2.32k
        return SoftSetArg(strArg, std::string("1"));
623
2.58k
    else
624
2.58k
        return SoftSetArg(strArg, std::string("0"));
625
4.90k
}
626
627
void ArgsManager::ForceSetArg(const std::string& strArg, const std::string& strValue)
628
51.0k
{
629
51.0k
    LOCK(cs_args);
630
51.0k
    m_settings.forced_settings[SettingName(strArg)] = strValue;
631
51.0k
}
632
633
void ArgsManager::AddCommand(const std::string& cmd, const std::string& help, std::set<std::string> options)
634
238
{
635
238
    Assert(cmd.find('=') == std::string::npos);
636
238
    Assert(cmd.at(0) != '-');
637
638
238
    LOCK(cs_args);
639
238
    m_accept_any_command = false; // latch to false
640
238
    std::map<std::string, Arg>& arg_map = m_available_args[OptionsCategory::COMMANDS];
641
238
    auto ret = arg_map.emplace(cmd, Arg{"", help, ArgsManager::COMMAND});
642
238
    if (!options.empty()) {
643
110
        auto& cmdopts = m_available_args[OptionsCategory::COMMAND_OPTIONS];
644
110
        bool command_has_all_options_defined = true;
645
126
        for (const auto& opt : options) {
646
126
            if (!cmdopts.contains(opt)) {
647
0
                command_has_all_options_defined = false;
648
0
            }
649
126
        }
650
110
        Assert(command_has_all_options_defined);
651
652
110
        m_command_args.try_emplace(cmd, std::move(options));
653
110
    }
654
238
    Assert(ret.second); // Fail on duplicate commands
655
238
}
656
657
void ArgsManager::AddArg(const std::string& name, const std::string& help, unsigned int flags, const OptionsCategory& cat)
658
471k
{
659
471k
    Assert((flags & ArgsManager::COMMAND) == 0); // use AddCommand
660
661
    // Split arg name from its help param
662
471k
    size_t eq_index = name.find('=');
663
471k
    if (eq_index == std::string::npos) {
664
243k
        eq_index = name.size();
665
243k
    }
666
471k
    std::string arg_name = name.substr(0, eq_index);
667
668
471k
    LOCK(cs_args);
669
670
    // Allow duplicates involving HIDDEN — it is used as a placeholder for args
671
    // unavailable in this binary but tolerated for shared config files (see #13441).
672
2.30M
    for (const auto& arg_map : m_available_args) {
673
2.30M
        if (arg_map.first == OptionsCategory::HIDDEN || cat == OptionsCategory::HIDDEN) continue;
674
1.54M
        Assert(!arg_map.second.contains(arg_name));
675
1.54M
    }
676
677
471k
    std::map<std::string, Arg>& arg_map = m_available_args[cat];
678
471k
    auto ret = arg_map.emplace(arg_name, Arg{name.substr(eq_index, name.size() - eq_index), help, flags});
679
471k
    assert(ret.second); // Make sure an insertion actually happened
680
681
471k
    if (flags & ArgsManager::NETWORK_ONLY) {
682
40.3k
        m_network_only_args.emplace(arg_name);
683
40.3k
    }
684
471k
}
685
686
void ArgsManager::AddHiddenArgs(const std::vector<std::string>& names)
687
5.12k
{
688
41.1k
    for (const std::string& name : names) {
689
41.1k
        AddArg(name, "", ArgsManager::ALLOW_ANY, OptionsCategory::HIDDEN);
690
41.1k
    }
691
5.12k
}
692
693
void ArgsManager::ClearArgs()
694
710
{
695
710
    LOCK(cs_args);
696
710
    m_settings = {};
697
710
    m_available_args.clear();
698
710
    m_command_args.clear();
699
710
    m_network_only_args.clear();
700
710
    m_config_sections.clear();
701
710
}
702
703
void ArgsManager::CheckMultipleCLIArgs() const
704
1.11k
{
705
1.11k
    LOCK(cs_args);
706
1.11k
    std::vector<std::string> found{};
707
1.11k
    auto cmds = m_available_args.find(OptionsCategory::CLI_COMMANDS);
708
1.11k
    if (cmds != m_available_args.end()) {
709
4.44k
        for (const auto& [cmd, argspec] : cmds->second) {
710
4.44k
            if (!GetSetting_(cmd).isNull()) {
711
42
                found.push_back(cmd);
712
42
            }
713
4.44k
        }
714
1.11k
        if (found.size() > 1) {
715
1
            throw std::runtime_error(strprintf("Only one of %s may be specified.", util::Join(found, ", ")));
716
1
        }
717
1.11k
    }
718
1.11k
}
719
720
std::string ArgsManager::GetHelpMessage() const
721
2
{
722
2
    const bool show_debug = GetBoolArg("-help-debug", false);
723
724
2
    std::string usage;
725
2
    LOCK(cs_args);
726
727
2
    const auto command_options = m_available_args.find(OptionsCategory::COMMAND_OPTIONS);
728
2
    const auto for_matching_cmd_opts = [&](const std::set<std::string>& select, auto&& fn) EXCLUSIVE_LOCKS_REQUIRED(cs_args) {
729
1
        if (select.empty()) return;
730
1
        if (command_options == m_available_args.end()) return;
731
1
        for (const auto& [name, info] : command_options->second) {
732
1
            if (!show_debug && (info.m_flags & ArgsManager::DEBUG_ONLY)) continue;
733
1
            if (!select.contains(name)) continue;
734
1
            fn(name, info);
735
1
        }
736
1
    };
737
738
12
    for (const auto& [category, category_args] : m_available_args) {
739
12
        switch(category) {
740
1
            case OptionsCategory::OPTIONS:
741
1
                usage += HelpMessageGroup("Options:");
742
1
                break;
743
1
            case OptionsCategory::CONNECTION:
744
1
                usage += HelpMessageGroup("Connection options:");
745
1
                break;
746
0
            case OptionsCategory::ZMQ:
747
0
                usage += HelpMessageGroup("ZeroMQ notification options:");
748
0
                break;
749
1
            case OptionsCategory::DEBUG_TEST:
750
1
                usage += HelpMessageGroup("Debugging/Testing options:");
751
1
                break;
752
1
            case OptionsCategory::NODE_RELAY:
753
1
                usage += HelpMessageGroup("Node relay options:");
754
1
                break;
755
1
            case OptionsCategory::BLOCK_CREATION:
756
1
                usage += HelpMessageGroup("Block creation options:");
757
1
                break;
758
1
            case OptionsCategory::RPC:
759
1
                usage += HelpMessageGroup("RPC server options:");
760
1
                break;
761
0
            case OptionsCategory::IPC:
762
0
                usage += HelpMessageGroup("IPC interprocess connection options:");
763
0
                break;
764
1
            case OptionsCategory::WALLET:
765
1
                usage += HelpMessageGroup("Wallet options:");
766
1
                break;
767
1
            case OptionsCategory::WALLET_DEBUG_TEST:
768
1
                if (show_debug) usage += HelpMessageGroup("Wallet debugging/testing options:");
769
1
                break;
770
1
            case OptionsCategory::CHAINPARAMS:
771
1
                usage += HelpMessageGroup("Chain selection options:");
772
1
                break;
773
0
            case OptionsCategory::GUI:
774
0
                usage += HelpMessageGroup("UI Options:");
775
0
                break;
776
1
            case OptionsCategory::COMMANDS:
777
1
                usage += HelpMessageGroup("Commands:");
778
1
                break;
779
0
            case OptionsCategory::REGISTER_COMMANDS:
780
0
                usage += HelpMessageGroup("Register Commands:");
781
0
                break;
782
0
            case OptionsCategory::CLI_COMMANDS:
783
0
                usage += HelpMessageGroup("CLI Commands:");
784
0
                break;
785
1
            case OptionsCategory::COMMAND_OPTIONS:
786
2
            case OptionsCategory::HIDDEN:
787
2
                break;
788
12
        } // no default case, so the compiler can warn about missing cases
789
790
12
        if (category == OptionsCategory::COMMAND_OPTIONS) continue;
791
792
        // When we get to the hidden options, stop
793
11
        if (category == OptionsCategory::HIDDEN) break;
794
795
174
        for (const auto& [arg_name, arg_info] : category_args) {
796
174
            if (show_debug || !(arg_info.m_flags & ArgsManager::DEBUG_ONLY)) {
797
133
                usage += HelpMessageOpt(arg_name, arg_info.m_help_param, arg_info.m_help_text);
798
799
133
                if (category == OptionsCategory::COMMANDS) {
800
1
                    const auto cmd_args = m_command_args.find(arg_name);
801
1
                    if (cmd_args == m_command_args.end()) continue;
802
1
                    for_matching_cmd_opts(cmd_args->second, [&](const auto& cmdopt_name, const auto& cmdopt_info) {
803
1
                        usage += HelpMessageOpt(cmdopt_name, cmdopt_info.m_help_param, cmdopt_info.m_help_text, /*subopt=*/true);
804
1
                    });
805
1
                }
806
133
            }
807
174
        }
808
10
    }
809
2
    return usage;
810
2
}
811
812
bool HelpRequested(const ArgsManager& args)
813
2.44k
{
814
2.44k
    return args.IsArgSet("-?") || args.IsArgSet("-h") || args.IsArgSet("-help") || args.IsArgSet("-help-debug");
815
2.44k
}
816
817
void SetupHelpOptions(ArgsManager& args)
818
3.19k
{
819
3.19k
    args.AddArg("-help", "Print this help message and exit (also -h or -?)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
820
3.19k
    args.AddHiddenArgs({"-h", "-?"});
821
3.19k
}
822
823
9
std::string HelpMessageGroup(const std::string &message) {
824
9
    return std::string(message) + std::string("\n\n");
825
9
}
826
827
std::string HelpMessageOpt(std::string_view option, std::string_view help_param, std::string_view message, bool subopt)
828
134
{
829
134
    constexpr int screen_width = 79;
830
134
    int opt_indent = 2;
831
134
    int msg_indent = 7;
832
833
134
    if (subopt) {
834
1
        int bump = msg_indent - opt_indent;
835
1
        opt_indent += bump; // opt_indent now at the old msg_indent level
836
1
        msg_indent += bump; // indent by the same amount
837
1
    }
838
134
    int msg_width = screen_width - msg_indent;
839
840
134
    return strprintf("%*s%s%s\n%*s%s\n\n",
841
134
                     opt_indent, "", option, help_param,
842
134
                     msg_indent, "", FormatParagraph(message, msg_width, msg_indent));
843
134
}
844
845
const std::vector<std::string> TEST_OPTIONS_DOC{
846
    "addrman (use deterministic addrman)",
847
    "reindex_after_failure_noninteractive_yes (When asked for a reindex after failure interactively, simulate as-if answered with 'yes')",
848
    "bip94 (enforce BIP94 consensus rules)",
849
};
850
851
bool HasTestOption(const ArgsManager& args, const std::string& test_option)
852
4.45k
{
853
4.45k
    const auto options = args.GetArgs("-test");
854
4.45k
    return std::any_of(options.begin(), options.end(), [test_option](const auto& option) {
855
31
        return option == test_option;
856
31
    });
857
4.45k
}
858
859
fs::path GetDefaultDataDir()
860
1.15k
{
861
    // Windows:
862
    //   old: C:\Users\Username\AppData\Roaming\Bitcoin
863
    //   new: C:\Users\Username\AppData\Local\Bitcoin
864
    // macOS: ~/Library/Application Support/Bitcoin
865
    // Unix-like: ~/.bitcoin
866
#ifdef WIN32
867
    // Windows
868
    // Check for existence of datadir in old location and keep it there
869
    fs::path legacy_path = GetSpecialFolderPath(CSIDL_APPDATA) / "Bitcoin";
870
    if (fs::exists(legacy_path)) return legacy_path;
871
872
    // Otherwise, fresh installs can start in the new, "proper" location
873
    return GetSpecialFolderPath(CSIDL_LOCAL_APPDATA) / "Bitcoin";
874
#else
875
1.15k
    fs::path pathRet;
876
1.15k
    char* pszHome = getenv("HOME");
877
1.15k
    if (pszHome == nullptr || strlen(pszHome) == 0)
878
0
        pathRet = fs::path("/");
879
1.15k
    else
880
1.15k
        pathRet = fs::path(pszHome);
881
#ifdef __APPLE__
882
    // macOS
883
    return pathRet / "Library/Application Support/Bitcoin";
884
#else
885
    // Unix-like
886
1.15k
    return pathRet / ".bitcoin";
887
1.15k
#endif
888
1.15k
#endif
889
1.15k
}
890
891
bool CheckDataDirOption(const ArgsManager& args)
892
4.66k
{
893
4.66k
    const fs::path datadir{args.GetPathArg("-datadir")};
894
4.66k
    return datadir.empty() || fs::is_directory(fs::absolute(datadir));
895
4.66k
}
896
897
fs::path ArgsManager::GetConfigFilePath() const
898
3.48k
{
899
3.48k
    LOCK(cs_args);
900
3.48k
    return *Assert(m_config_path);
901
3.48k
}
902
903
void ArgsManager::SetConfigFilePath(fs::path path)
904
1
{
905
1
    LOCK(cs_args);
906
1
    assert(!m_config_path);
907
1
    m_config_path = path;
908
1
}
909
910
ChainType ArgsManager::GetChainType() const
911
4.34k
{
912
4.34k
    std::variant<ChainType, std::string> arg = GetChainArg();
913
4.34k
    if (auto* parsed = std::get_if<ChainType>(&arg)) return *parsed;
914
0
    throw std::runtime_error(strprintf("Unknown chain %s.", std::get<std::string>(arg)));
915
4.34k
}
916
917
std::string ArgsManager::GetChainTypeString() const
918
6.02k
{
919
6.02k
    auto arg = GetChainArg();
920
6.02k
    if (auto* parsed = std::get_if<ChainType>(&arg)) return ChainTypeToString(*parsed);
921
187
    return std::get<std::string>(arg);
922
6.02k
}
923
924
std::variant<ChainType, std::string> ArgsManager::GetChainArg() const
925
10.3k
{
926
41.4k
    auto get_net = [&](const std::string& arg) {
927
41.4k
        LOCK(cs_args);
928
41.4k
        common::SettingsValue value = common::GetSetting(m_settings, /* section= */ "", SettingName(arg),
929
41.4k
            /* ignore_default_section_config= */ false,
930
41.4k
            /*ignore_nonpersistent=*/false,
931
41.4k
            /* get_chain_type= */ true);
932
41.4k
        return value.isNull() ? false : value.isBool() ? value.get_bool() : InterpretBool(value.get_str());
933
41.4k
    };
934
935
10.3k
    const bool fRegTest = get_net("-regtest");
936
10.3k
    const bool fSigNet  = get_net("-signet");
937
10.3k
    const bool fTestNet = get_net("-testnet");
938
10.3k
    const bool fTestNet4 = get_net("-testnet4");
939
10.3k
    const auto chain_arg = GetArg("-chain");
940
941
10.3k
    if ((int)chain_arg.has_value() + (int)fRegTest + (int)fSigNet + (int)fTestNet + (int)fTestNet4 > 1) {
942
187
        throw std::runtime_error("Invalid combination of -regtest, -signet, -testnet, -testnet4 and -chain. Can use at most one.");
943
187
    }
944
10.1k
    if (chain_arg) {
945
32
        if (auto parsed = ChainTypeFromString(*chain_arg)) return *parsed;
946
        // Not a known string, so return original string
947
0
        return *chain_arg;
948
32
    }
949
10.1k
    if (fRegTest) return ChainType::REGTEST;
950
1.86k
    if (fSigNet) return ChainType::SIGNET;
951
1.73k
    if (fTestNet) return ChainType::TESTNET;
952
1.72k
    if (fTestNet4) return ChainType::TESTNET4;
953
1.38k
    return ChainType::MAIN;
954
1.72k
}
955
956
bool ArgsManager::UseDefaultSection(const std::string& arg) const
957
1.06M
{
958
1.06M
    AssertLockHeld(cs_args);
959
1.06M
    return m_network == ChainTypeToString(ChainType::MAIN) || !m_network_only_args.contains(arg);
960
1.06M
}
961
962
common::SettingsValue ArgsManager::GetSetting_(const std::string& arg) const
963
835k
{
964
835k
    AssertLockHeld(cs_args);
965
835k
    return common::GetSetting(
966
835k
        m_settings, m_network, SettingName(arg), !UseDefaultSection(arg),
967
835k
        /*ignore_nonpersistent=*/false, /*get_chain_type=*/false);
968
835k
}
969
970
common::SettingsValue ArgsManager::GetSetting(const std::string& arg) const
971
745k
{
972
745k
    LOCK(cs_args);
973
745k
    return GetSetting_(arg);
974
745k
}
975
976
std::vector<common::SettingsValue> ArgsManager::GetSettingsList(const std::string& arg) const
977
225k
{
978
225k
    LOCK(cs_args);
979
225k
    return common::GetSettingsList(m_settings, m_network, SettingName(arg), !UseDefaultSection(arg));
980
225k
}
981
982
void ArgsManager::logArgsPrefix(
983
    const std::string& prefix,
984
    const std::string& section,
985
    const std::map<std::string, std::vector<common::SettingsValue>>& args) const
986
3.45k
{
987
3.45k
    AssertLockHeld(cs_args);
988
3.45k
    std::string section_str = section.empty() ? "" : "[" + section + "] ";
989
40.0k
    for (const auto& arg : args) {
990
41.4k
        for (const auto& value : arg.second) {
991
41.4k
            std::optional<unsigned int> flags = GetArgFlags_('-' + arg.first);
992
41.4k
            if (flags) {
993
41.4k
                std::string value_str = (*flags & SENSITIVE) ? "****" : value.write();
994
41.4k
                LogInfo("%s %s%s=%s\n", prefix, section_str, arg.first, value_str);
995
41.4k
            }
996
41.4k
        }
997
40.0k
    }
998
3.45k
}
999
1000
void ArgsManager::LogArgs() const
1001
1.15k
{
1002
1.15k
    LOCK(cs_args);
1003
2.29k
    for (const auto& section : m_settings.ro_config) {
1004
2.29k
        logArgsPrefix("Config file arg:", section.first, section.second);
1005
2.29k
    }
1006
1.15k
    for (const auto& setting : m_settings.rw_settings) {
1007
125
        LogInfo("Setting file arg: %s = %s\n", setting.first, setting.second.write());
1008
125
    }
1009
1.15k
    logArgsPrefix("Command-line arg:", "", m_settings.command_line_options);
1010
1.15k
}