Merge bitcoin/bitcoin#15936: interfaces: Expose settings.json methods to GUI

f9fdcec7e9 settings: Add resetSettings() method (Ryan Ofsky)
77fabffef4 init: Remove Shutdown() node.args reset (Ryan Ofsky)
0e55bc6e7f settings: Add update/getPersistent/isIgnored methods (Ryan Ofsky)

Pull request description:

  Add `interfaces::Node` `updateSetting`, `forceSetting`, `resetSettings`, `isSettingIgnored`, and `getPersistentSetting` methods so GUI is able to manipulate `settings.json` file and use and modify node settings.

  (Originally this PR also contained GUI changes to unify bitcoin-qt and bitcoind persistent settings and call these methods, but the GUI commits have been dropped from this PR and moved to bitcoin-core/gui/pull/602)

ACKs for top commit:
  vasild:
    ACK f9fdcec7e9
  hebasto:
    re-ACK f9fdcec7e9, only a function renamed since my recent [review](https://github.com/bitcoin/bitcoin/pull/15936#pullrequestreview-979324357).

Tree-SHA512: 4cac853ee29be96d2ff38404165b9dfb7c622b2a9c99a15979596f3484ffde0da3d9c9c372677dff5119ca7cffa6383d81037fd9889a29cc9285882a8dc0c268
This commit is contained in:
MacroFake
2022-05-26 17:05:01 +02:00
8 changed files with 123 additions and 17 deletions

View File

@@ -112,6 +112,46 @@ public:
}
}
bool shutdownRequested() override { return ShutdownRequested(); }
bool isSettingIgnored(const std::string& name) override
{
bool ignored = false;
gArgs.LockSettings([&](util::Settings& settings) {
if (auto* options = util::FindKey(settings.command_line_options, name)) {
ignored = !options->empty();
}
});
return ignored;
}
util::SettingsValue getPersistentSetting(const std::string& name) override { return gArgs.GetPersistentSetting(name); }
void updateRwSetting(const std::string& name, const util::SettingsValue& value) override
{
gArgs.LockSettings([&](util::Settings& settings) {
if (value.isNull()) {
settings.rw_settings.erase(name);
} else {
settings.rw_settings[name] = value;
}
});
gArgs.WriteSettingsFile();
}
void forceSetting(const std::string& name, const util::SettingsValue& value) override
{
gArgs.LockSettings([&](util::Settings& settings) {
if (value.isNull()) {
settings.forced_settings.erase(name);
} else {
settings.forced_settings[name] = value;
}
});
}
void resetSettings() override
{
gArgs.WriteSettingsFile(/*errors=*/nullptr, /*backup=*/true);
gArgs.LockSettings([&](util::Settings& settings) {
settings.rw_settings.clear();
});
gArgs.WriteSettingsFile();
}
void mapPort(bool use_upnp, bool use_natpmp) override { StartMapPort(use_upnp, use_natpmp); }
bool getProxy(Network net, Proxy& proxy_info) override { return GetProxy(net, proxy_info); }
size_t getNodeCount(ConnectionDirection flags) override