MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GetSetting

Function GetSetting

src/common/settings.cpp:154–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152}
153
154SettingsValue GetSetting(const Settings& settings,
155 const std::string& section,
156 const std::string& name,
157 bool ignore_default_section_config,
158 bool ignore_nonpersistent,
159 bool get_chain_type)
160{
161 SettingsValue result;
162 bool done = false; // Done merging any more settings sources.
163 MergeSettings(settings, section, name, [&](SettingsSpan span, Source source) {
164 // Weird behavior preserved for backwards compatibility: Apply negated
165 // setting even if non-negated setting would be ignored. A negated
166 // value in the default section is applied to network specific options,
167 // even though normal non-negated values there would be ignored.
168 const bool never_ignore_negated_setting = span.last_negated();
169
170 // Weird behavior preserved for backwards compatibility: Take first
171 // assigned value instead of last. In general, later settings take
172 // precedence over early settings, but for backwards compatibility in
173 // the config file the precedence is reversed for all settings except
174 // chain type settings.
175 const bool reverse_precedence =
176 (source == Source::CONFIG_FILE_NETWORK_SECTION || source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
177 !get_chain_type;
178
179 // Weird behavior preserved for backwards compatibility: Negated
180 // -regtest and -testnet arguments which you would expect to override
181 // values set in the configuration file are currently accepted but
182 // silently ignored. It would be better to apply these just like other
183 // negated values, or at least warn they are ignored.
184 const bool skip_negated_command_line = get_chain_type;
185
186 if (done) return;
187
188 // Ignore settings in default config section if requested.
189 if (ignore_default_section_config && source == Source::CONFIG_FILE_DEFAULT_SECTION &&
190 !never_ignore_negated_setting) {
191 return;
192 }
193
194 // Ignore nonpersistent settings if requested.
195 if (ignore_nonpersistent && (source == Source::COMMAND_LINE || source == Source::FORCED)) return;
196
197 // Skip negated command line settings.
198 if (skip_negated_command_line && span.last_negated()) return;
199
200 if (!span.empty()) {
201 result = reverse_precedence ? span.begin()[0] : span.end()[-1];
202 done = true;
203 } else if (span.last_negated()) {
204 result = false;
205 done = true;
206 }
207 });
208 return result;
209}
210
211std::vector<SettingsValue> GetSettingsList(const Settings& settings,

Callers 10

CheckValuesFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
BOOST_FIXTURE_TEST_CASEFunction · 0.85
IsArgSetMethod · 0.85
GetPersistentSettingMethod · 0.85
IsArgNegatedMethod · 0.85
GetArgMethod · 0.85
GetBoolArgMethod · 0.85
GetChainArgMethod · 0.85
GetSetting_Method · 0.85

Calls 5

MergeSettingsFunction · 0.85
last_negatedMethod · 0.80
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 3

CheckValuesFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68
BOOST_FIXTURE_TEST_CASEFunction · 0.68