17 CONFIG_FILE_NETWORK_SECTION,
18 CONFIG_FILE_DEFAULT_SECTION
27static void MergeSettings(
const Settings& settings,
const std::string& section,
const std::string&
name, Fn&& fn)
42 if (!section.empty()) {
68 if (!file.is_open()) {
74 if (!in.
read(std::string{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()})) {
90 const std::vector<std::string>& in_keys = in.
getKeys();
91 const std::vector<SettingsValue>& in_values = in.
getValues();
92 for (
size_t i = 0; i < in_keys.size(); ++i) {
93 auto inserted =
values.emplace(in_keys[i], in_values[i]);
94 if (!inserted.second) {
98 return errors.empty();
102 const std::map<std::string, SettingsValue>&
values,
103 std::vector<std::string>& errors)
106 for (
const auto& value :
values) {
107 out.
__pushKV(value.first, value.second);
115 file << out.
write( 1, 4) << std::endl;
121 const std::string& section,
122 const std::string&
name,
123 bool ignore_default_section_config,
133 const bool never_ignore_negated_setting = span.
last_negated();
140 const bool reverse_precedence =
141 (
source == Source::CONFIG_FILE_NETWORK_SECTION ||
source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
149 const bool skip_negated_command_line = get_chain_name;
154 if (ignore_default_section_config &&
source == Source::CONFIG_FILE_DEFAULT_SECTION &&
155 !never_ignore_negated_setting) {
160 if (skip_negated_command_line && span.
last_negated())
return;
163 result = reverse_precedence ? span.
begin()[0] : span.
end()[-1];
174 const std::string& section,
175 const std::string&
name,
176 bool ignore_default_section_config)
178 std::vector<SettingsValue> result;
180 bool prev_negated_empty =
false;
189 const bool add_zombie_config_values =
190 (
source == Source::CONFIG_FILE_NETWORK_SECTION ||
source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
194 if (ignore_default_section_config &&
source == Source::CONFIG_FILE_DEFAULT_SECTION)
return;
198 if (!done || add_zombie_config_values) {
199 for (
const auto& value : span) {
200 if (value.isArray()) {
201 result.insert(result.end(), value.getValues().begin(), value.getValues().end());
203 result.push_back(value);
213 prev_negated_empty |= span.
last_negated() && result.empty();
220 bool has_default_section_setting =
false;
221 bool has_other_setting =
false;
223 if (span.
empty())
return;
224 else if (
source == Source::CONFIG_FILE_DEFAULT_SECTION) has_default_section_setting =
true;
225 else has_other_setting =
true;
230 return has_default_section_setting && !has_other_setting;
240 for (
size_t i =
size; i > 0; --i) {
241 if (
data[i - 1].isFalse())
return i;
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
void __pushKV(const std::string &key, const 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 prepare application code for transition from boost::filesystem library to std::...
if(na.IsAddrV1Compatible())
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to 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.
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.
SettingsValue GetSetting(const Settings &settings, const std::string §ion, const std::string &name, bool ignore_default_section_config, bool get_chain_name)
Get settings value from combined sources: forced settings, command line arguments,...
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
std::map< std::string, SettingsValue > rw_settings
Map of setting name to read-write file setting value.
std::map< std::string, SettingsValue > forced_settings
Map of setting name to forced setting value.
std::map< std::string, std::map< std::string, std::vector< SettingsValue > > > ro_config
Map of config section name and setting name to list of config file values.
std::map< std::string, std::vector< SettingsValue > > command_line_options
Map of setting name to list of command line values.
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.