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) {
104 return errors.empty();
108 const std::map<std::string, SettingsValue>&
values,
109 std::vector<std::string>& errors)
112 for (
const auto& value :
values) {
113 out.
__pushKV(value.first, value.second);
121 file << out.
write( 4, 1) << std::endl;
127 const std::string& section,
128 const std::string&
name,
129 bool ignore_default_section_config,
130 bool ignore_nonpersistent,
140 const bool never_ignore_negated_setting = span.
last_negated();
147 const bool reverse_precedence =
148 (
source == Source::CONFIG_FILE_NETWORK_SECTION ||
source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
156 const bool skip_negated_command_line = get_chain_name;
161 if (ignore_default_section_config &&
source == Source::CONFIG_FILE_DEFAULT_SECTION &&
162 !never_ignore_negated_setting) {
167 if (ignore_nonpersistent && (
source == Source::COMMAND_LINE ||
source == Source::FORCED))
return;
170 if (skip_negated_command_line && span.
last_negated())
return;
173 result = reverse_precedence ? span.
begin()[0] : span.
end()[-1];
184 const std::string& section,
185 const std::string&
name,
186 bool ignore_default_section_config)
188 std::vector<SettingsValue> result;
190 bool prev_negated_empty =
false;
199 const bool add_zombie_config_values =
200 (
source == Source::CONFIG_FILE_NETWORK_SECTION ||
source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
204 if (ignore_default_section_config &&
source == Source::CONFIG_FILE_DEFAULT_SECTION)
return;
208 if (!done || add_zombie_config_values) {
209 for (
const auto& value : span) {
210 if (value.isArray()) {
211 result.insert(result.end(), value.getValues().begin(), value.getValues().end());
213 result.push_back(value);
223 prev_negated_empty |= span.
last_negated() && result.empty();
230 bool has_default_section_setting =
false;
231 bool has_other_setting =
false;
233 if (span.
empty())
return;
234 else if (
source == Source::CONFIG_FILE_DEFAULT_SECTION) has_default_section_setting =
true;
235 else has_other_setting =
true;
240 return has_default_section_setting && !has_other_setting;
250 for (
size_t i =
size; i > 0; --i) {
251 if (
data[i - 1].isFalse())
return i;
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
void __pushKV(std::string key, UniValue val)
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,...
SettingsValue GetSetting(const Settings &settings, const std::string §ion, const std::string &name, bool ignore_default_section_config, bool ignore_nonpersistent, bool get_chain_name)
Get settings value from combined sources: forced settings, command line arguments,...
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.
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.