26 CONFIG_FILE_NETWORK_SECTION,
27 CONFIG_FILE_DEFAULT_SECTION
35 template <
typename Fn>
36 static void MergeSettings(
const Settings& settings,
const std::string& section,
const std::string&
name, Fn&& fn)
39 if (
auto* value =
FindKey(settings.forced_settings,
name)) {
40 fn(SettingsSpan(*value), Source::FORCED);
44 fn(SettingsSpan(*
values), Source::COMMAND_LINE);
48 fn(SettingsSpan(*value), Source::RW_SETTINGS);
51 if (!section.empty()) {
52 if (
auto* map =
FindKey(settings.ro_config, section)) {
54 fn(SettingsSpan(*
values), Source::CONFIG_FILE_NETWORK_SECTION);
59 if (
auto* map =
FindKey(settings.ro_config,
"")) {
61 fn(SettingsSpan(*
values), Source::CONFIG_FILE_DEFAULT_SECTION);
77 if (!file.is_open()) {
83 if (!in.
read(std::string{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()})) {
99 const std::vector<std::string>& in_keys = in.
getKeys();
100 const std::vector<SettingsValue>& in_values = in.
getValues();
101 for (
size_t i = 0; i < in_keys.size(); ++i) {
102 auto inserted =
values.emplace(in_keys[i], in_values[i]);
103 if (!inserted.second) {
109 return errors.empty();
113 const std::map<std::string, SettingsValue>&
values,
114 std::vector<std::string>& errors)
117 for (
const auto& value :
values) {
118 out.pushKVEnd(value.first, value.second);
126 file <<
out.write( 4, 1) << std::endl;
132 const std::string& section,
133 const std::string&
name,
134 bool ignore_default_section_config,
135 bool ignore_nonpersistent,
145 const bool never_ignore_negated_setting = span.
last_negated();
152 const bool reverse_precedence =
153 (
source == Source::CONFIG_FILE_NETWORK_SECTION ||
source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
161 const bool skip_negated_command_line = get_chain_type;
166 if (ignore_default_section_config &&
source == Source::CONFIG_FILE_DEFAULT_SECTION &&
167 !never_ignore_negated_setting) {
172 if (ignore_nonpersistent && (
source == Source::COMMAND_LINE ||
source == Source::FORCED))
return;
175 if (skip_negated_command_line && span.
last_negated())
return;
178 result = reverse_precedence ? span.
begin()[0] : span.
end()[-1];
189 const std::string& section,
190 const std::string&
name,
191 bool ignore_default_section_config)
193 std::vector<SettingsValue> result;
195 bool prev_negated_empty =
false;
204 const bool add_zombie_config_values =
205 (
source == Source::CONFIG_FILE_NETWORK_SECTION ||
source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
209 if (ignore_default_section_config &&
source == Source::CONFIG_FILE_DEFAULT_SECTION)
return;
213 if (!done || add_zombie_config_values) {
214 for (
const auto& value : span) {
215 if (value.isArray()) {
216 result.insert(result.end(), value.getValues().begin(), value.getValues().end());
218 result.push_back(value);
228 prev_negated_empty |= span.
last_negated() && result.empty();
235 bool has_default_section_setting =
false;
236 bool has_other_setting =
false;
238 if (span.
empty())
return;
239 else if (
source == Source::CONFIG_FILE_DEFAULT_SECTION) has_default_section_setting =
true;
240 else has_other_setting =
true;
245 return has_default_section_setting && !has_other_setting;
255 for (
size_t i =
size; i > 0; --i) {
256 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)
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
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...
UniValue SettingsValue
Settings value type (string/integer/boolean/null variant).
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to a byte string.
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