5#include <bitcoin-build-config.h>
27 CONFIG_FILE_NETWORK_SECTION,
28 CONFIG_FILE_DEFAULT_SECTION
44 fn(SettingsSpan(*value), Source::FORCED);
48 fn(SettingsSpan(*
values), Source::COMMAND_LINE);
52 fn(SettingsSpan(*value), Source::RW_SETTINGS);
55 if (!section.empty()) {
58 fn(SettingsSpan(*
values), Source::CONFIG_FILE_NETWORK_SECTION);
65 fn(SettingsSpan(*
values), Source::CONFIG_FILE_DEFAULT_SECTION);
80 file.open(path.std_path());
81 if (!file.is_open()) {
87 if (!in.
read(std::string{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()})) {
88 errors.emplace_back(
strprintf(
"Settings file %s does not contain valid JSON. This may be caused by a crash, power loss, full disk, or storage error, "
89 "and can be fixed by removing the file, which will reset settings to default values.",
107 for (
size_t i = 0; i <
in_keys.size(); ++i) {
123 const std::map<std::string, SettingsValue>&
values,
124 std::vector<std::string>&
errors)
128 out.pushKV(
SETTINGS_WARN_MSG_KEY,
strprintf(
"This file is automatically generated and updated by %s. Please do not edit this file while the node "
129 "is running, as any changes might be ignored or overwritten.",
CLIENT_NAME));
131 for (
const auto& value :
values) {
132 out.pushKVEnd(value.first, value.second);
135 file.open(path.std_path());
140 file << out.write( 4, 1) << std::endl;
154 const std::string& section,
155 const std::string&
name,
175 (
source == Source::CONFIG_FILE_NETWORK_SECTION ||
source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
211 const std::string& section,
212 const std::string&
name,
215 std::vector<SettingsValue> result;
227 (
source == Source::CONFIG_FILE_NETWORK_SECTION ||
source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
236 for (
const auto& value : span) {
237 if (value.isArray()) {
238 result.insert(result.end(), value.getValues().begin(), value.getValues().end());
240 result.push_back(value);
260 if (span.
empty())
return;
277 for (
size_t i =
size; i > 0; --i) {
278 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 json)
Parse JSON; set value to null on failure.
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to a byte string.
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 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
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.