| 124 | } |
| 125 | |
| 126 | SettingsValue GetSetting(const Settings& settings, |
| 127 | const std::string& section, |
| 128 | const std::string& name, |
| 129 | bool ignore_default_section_config, |
| 130 | bool get_chain_name) |
| 131 | { |
| 132 | SettingsValue result; |
| 133 | bool done = false; // Done merging any more settings sources. |
| 134 | MergeSettings(settings, section, name, [&](SettingsSpan span, Source source) { |
| 135 | // Weird behavior preserved for backwards compatibility: Apply negated |
| 136 | // setting even if non-negated setting would be ignored. A negated |
| 137 | // value in the default section is applied to network specific options, |
| 138 | // even though normal non-negated values there would be ignored. |
| 139 | const bool never_ignore_negated_setting = span.last_negated(); |
| 140 | |
| 141 | // Weird behavior preserved for backwards compatibility: Take first |
| 142 | // assigned value instead of last. In general, later settings take |
| 143 | // precedence over early settings, but for backwards compatibility in |
| 144 | // the config file the precedence is reversed for all settings except |
| 145 | // chain name settings. |
| 146 | const bool reverse_precedence = |
| 147 | (source == Source::CONFIG_FILE_NETWORK_SECTION || source == Source::CONFIG_FILE_DEFAULT_SECTION) && |
| 148 | !get_chain_name; |
| 149 | |
| 150 | // Weird behavior preserved for backwards compatibility: Negated |
| 151 | // -regtest and -testnet arguments which you would expect to override |
| 152 | // values set in the configuration file are currently accepted but |
| 153 | // silently ignored. It would be better to apply these just like other |
| 154 | // negated values, or at least warn they are ignored. |
| 155 | const bool skip_negated_command_line = get_chain_name; |
| 156 | |
| 157 | if (done) return; |
| 158 | |
| 159 | // Ignore settings in default config section if requested. |
| 160 | if (ignore_default_section_config && source == Source::CONFIG_FILE_DEFAULT_SECTION && |
| 161 | !never_ignore_negated_setting) { |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | // Skip negated command line settings. |
| 166 | if (skip_negated_command_line && span.last_negated()) return; |
| 167 | |
| 168 | if (!span.empty()) { |
| 169 | result = reverse_precedence ? span.begin()[0] : span.end()[-1]; |
| 170 | done = true; |
| 171 | } else if (span.last_negated()) { |
| 172 | result = false; |
| 173 | done = true; |
| 174 | } |
| 175 | }); |
| 176 | return result; |
| 177 | } |
| 178 | |
| 179 | std::vector<SettingsValue> GetSettingsList(const Settings& settings, |
| 180 | const std::string& section, |