23 CONFIG_FILE_NETWORK_SECTION,
24 CONFIG_FILE_DEFAULT_SECTION
33 template <
typename Fn>
36 const std::string &
name,
Fn &&fn) {
39 fn(SettingsSpan(*value), Source::FORCED);
43 fn(SettingsSpan(*values), Source::COMMAND_LINE);
47 fn(SettingsSpan(*value), Source::RW_SETTINGS);
53 fn(SettingsSpan(*values),
54 Source::CONFIG_FILE_NETWORK_SECTION);
61 fn(SettingsSpan(*values), Source::CONFIG_FILE_DEFAULT_SECTION);
68 std::map<std::string, SettingsValue> &values,
69 std::vector<std::string> &
errors) {
80 if (!file.is_open()) {
87 if (!
in.read(std::string{std::istreambuf_iterator<char>(file),
88 std::istreambuf_iterator<char>()})) {
102 if (!
in.isObject()) {
104 strprintf(
"Found non-object value %s in settings file %s",
110 const std::vector<SettingsValue> &
in_values =
in.getValues();
111 for (
size_t i = 0; i <
in_keys.size(); ++i) {
115 strprintf(
"Found duplicate key %s in settings file %s",
123 const std::map<std::string, SettingsValue> &values,
124 std::vector<std::string> &
errors) {
126 for (
const auto &value : values) {
127 out.
pushKVEnd(value.first, value.second);
133 strprintf(
"Error: Unable to open settings file %s for writing",
137 file << out.
write( 1, 4) << std::endl;
143 const std::string &
name,
164 (
source == Source::CONFIG_FILE_NETWORK_SECTION ||
165 source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
182 source == Source::CONFIG_FILE_DEFAULT_SECTION &&
189 (
source == Source::COMMAND_LINE ||
source == Source::FORCED)) {
201 }
else if (
span.last_negated()) {
211 const std::string &
name,
213 std::vector<SettingsValue> result;
227 (
source == Source::CONFIG_FILE_NETWORK_SECTION ||
228 source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
233 source == Source::CONFIG_FILE_DEFAULT_SECTION) {
240 for (
const auto &value :
span) {
241 if (value.isArray()) {
242 result.insert(result.end(), value.getValues().begin(),
243 value.getValues().end());
245 result.push_back(value);
252 done |=
span.negated() > 0 ||
source == Source::FORCED;
263 const std::string &
name) {
270 }
else if (
source == Source::CONFIG_FILE_DEFAULT_SECTION) {
297 for (
size_t i =
size; i > 0; --i) {
298 if (
data[i - 1].isFalse()) {
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
const std::vector< std::string > & getKeys() const
void pushKVEnd(std::string key, UniValue val)
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 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.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
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.