23 CONFIG_FILE_NETWORK_SECTION,
24 CONFIG_FILE_DEFAULT_SECTION
32 template <
typename Fn>
33 static void MergeSettings(
const Settings& settings,
const std::string& section,
const std::string&
name, Fn&& fn)
36 if (
auto* value =
FindKey(settings.forced_settings,
name)) {
37 fn(SettingsSpan(*value), Source::FORCED);
41 fn(SettingsSpan(*
values), Source::COMMAND_LINE);
45 fn(SettingsSpan(*value), Source::RW_SETTINGS);
48 if (!section.empty()) {
49 if (
auto* map =
FindKey(settings.ro_config, section)) {
51 fn(SettingsSpan(*
values), Source::CONFIG_FILE_NETWORK_SECTION);
56 if (
auto* map =
FindKey(settings.ro_config,
"")) {
58 fn(SettingsSpan(*
values), Source::CONFIG_FILE_DEFAULT_SECTION);
74 if (!file.is_open()) {
80 if (!in.
read(std::string{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()})) {
96 const std::vector<std::string>& in_keys = in.
getKeys();
97 const std::vector<SettingsValue>& in_values = in.
getValues();
98 for (
size_t i = 0; i < in_keys.size(); ++i) {
99 auto inserted =
values.emplace(in_keys[i], in_values[i]);
100 if (!inserted.second) {
106 return errors.empty();
110 const std::map<std::string, SettingsValue>&
values,
111 std::vector<std::string>& errors)
114 for (
const auto& value :
values) {
115 out.__pushKV(value.first, value.second);
123 file <<
out.write( 4, 1) << std::endl;
129 const std::string& section,
130 const std::string&
name,
131 bool ignore_default_section_config,
132 bool ignore_nonpersistent,
142 const bool never_ignore_negated_setting = span.
last_negated();
149 const bool reverse_precedence =
150 (
source == Source::CONFIG_FILE_NETWORK_SECTION ||
source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
158 const bool skip_negated_command_line = get_chain_type;
163 if (ignore_default_section_config &&
source == Source::CONFIG_FILE_DEFAULT_SECTION &&
164 !never_ignore_negated_setting) {
169 if (ignore_nonpersistent && (
source == Source::COMMAND_LINE ||
source == Source::FORCED))
return;
172 if (skip_negated_command_line && span.
last_negated())
return;
175 result = reverse_precedence ? span.
begin()[0] : span.
end()[-1];
186 const std::string& section,
187 const std::string&
name,
188 bool ignore_default_section_config)
190 std::vector<SettingsValue> result;
192 bool prev_negated_empty =
false;
201 const bool add_zombie_config_values =
202 (
source == Source::CONFIG_FILE_NETWORK_SECTION ||
source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
206 if (ignore_default_section_config &&
source == Source::CONFIG_FILE_DEFAULT_SECTION)
return;
210 if (!done || add_zombie_config_values) {
211 for (
const auto& value : span) {
212 if (value.isArray()) {
213 result.insert(result.end(), value.getValues().begin(), value.getValues().end());
215 result.push_back(value);
225 prev_negated_empty |= span.
last_negated() && result.empty();
232 bool has_default_section_setting =
false;
233 bool has_other_setting =
false;
235 if (span.
empty())
return;
236 else if (
source == Source::CONFIG_FILE_DEFAULT_SECTION) has_default_section_setting =
true;
237 else has_other_setting =
true;
242 return has_default_section_setting && !has_other_setting;
252 for (
size_t i =
size; i > 0; --i) {
253 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(const char *raw, size_t len)
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to a byte string.
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 ReadSettings(const fs::path &path, std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Read settings file.
UniValue SettingsValue
Settings value type (string/integer/boolean/null variant).
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...
bool WriteSettings(const fs::path &path, const std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Write 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.
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.
size_t negated() const
Number of negated values.
const SettingsValue * end() const
Pointer to end of values.
bool empty() const
True if there are any non-negated values.
const SettingsValue * data
bool last_negated() const
True if the last value is negated.
const SettingsValue * begin() const
Pointer to first non-negated value.