7#include <bitcoin-build-config.h>
28 CONFIG_FILE_NETWORK_SECTION,
29 CONFIG_FILE_DEFAULT_SECTION
45 fn(SettingsSpan(*value), Source::FORCED);
49 fn(SettingsSpan(*
values), Source::COMMAND_LINE);
53 fn(SettingsSpan(*value), Source::RW_SETTINGS);
56 if (!section.empty()) {
59 fn(SettingsSpan(*
values), Source::CONFIG_FILE_NETWORK_SECTION);
66 fn(SettingsSpan(*
values), Source::CONFIG_FILE_DEFAULT_SECTION);
81 file.open(path.std_path());
82 if (!file.is_open()) {
88 if (!in.
read(std::string{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()})) {
89 errors.emplace_back(
strprintf(
"Settings file %s does not contain valid JSON. This is probably caused by disk corruption or a crash, "
90 "and can be fixed by removing the file, which will reset settings to default values.",
108 for (
size_t i = 0; i <
in_keys.size(); ++i) {
124 const std::map<std::string, SettingsValue>&
values,
125 std::vector<std::string>&
errors)
129 out.pushKV(
SETTINGS_WARN_MSG_KEY,
strprintf(
"This file is automatically generated and updated by %s. Please do not edit this file while the node "
130 "is running, as any changes might be ignored or overwritten.",
CLIENT_NAME));
132 for (
const auto& value :
values) {
133 out.pushKVEnd(value.first, value.second);
136 file.open(path.std_path());
141 file << out.write( 4, 1) << std::endl;
147 const std::string& section,
148 const std::string&
name,
168 (
source == Source::CONFIG_FILE_NETWORK_SECTION ||
source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
204 const std::string& section,
205 const std::string&
name,
208 std::vector<SettingsValue> result;
220 (
source == Source::CONFIG_FILE_NETWORK_SECTION ||
source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
229 for (
const auto& value : span) {
230 if (value.isArray()) {
231 result.insert(result.end(), value.getValues().begin(), value.getValues().end());
233 result.push_back(value);
253 if (span.
empty())
return;
270 for (
size_t i =
size; i > 0; --i) {
271 if (
data[i - 1].isFalse())
return i;
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
const std::vector< UniValue > & getValues() const
const std::vector< std::string > & getKeys() const
bool read(std::string_view raw)
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to a byte string.
UniValue SettingsValue
Settings value type (string/integer/boolean/null variant).
bool WriteSettings(const fs::path &path, const std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Write settings file.
bool ReadSettings(const fs::path &path, std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Read settings file.
SettingsValue GetSetting(const Settings &settings, const std::string §ion, const std::string &name, bool ignore_default_section_config, bool ignore_nonpersistent, bool get_chain_type)
Get settings value from combined sources: forced settings, command line arguments,...
auto FindKey(Map &&map, Key &&key) -> decltype(&map.at(key))
Map lookup helper.
std::vector< SettingsValue > GetSettingsList(const Settings &settings, const std::string §ion, const std::string &name, bool ignore_default_section_config)
Get combined setting value similar to GetSetting(), except if setting was specified multiple times,...
bool OnlyHasDefaultSectionSetting(const Settings &settings, const std::string §ion, const std::string &name)
Return true if a setting is set in the default config file section, and not overridden by a higher pr...
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
Accessor for list of settings that skips negated values when iterated over.
bool last_negated() const
True if the last value is negated.
const SettingsValue * begin() const
Pointer to first non-negated value.
const SettingsValue * end() const
Pointer to end of values.
bool empty() const
True if there are any non-negated values.
size_t negated() const
Number of negated values.
const SettingsValue * data
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.