chain: uniformly use SettingsAction enum in settings methods

This commit is contained in:
ismaelsadeeq 2024-09-05 21:25:06 +01:00
parent 1e9e735670
commit c8e2eeeffb
No known key found for this signature in database
GPG key ID: 0E3908F364989888
3 changed files with 9 additions and 9 deletions

View file

@ -361,10 +361,10 @@ public:
virtual bool updateRwSetting(const std::string& name, const SettingsUpdate& update_function) = 0;
//! Replace a setting in <datadir>/settings.json with a new value.
virtual bool overwriteRwSetting(const std::string& name, common::SettingsValue value, bool write = true) = 0;
virtual bool overwriteRwSetting(const std::string& name, common::SettingsValue value, SettingsAction action = SettingsAction::WRITE) = 0;
//! Delete a given setting in <datadir>/settings.json.
virtual bool deleteRwSettings(const std::string& name, bool write = true) = 0;
virtual bool deleteRwSettings(const std::string& name, SettingsAction action = SettingsAction::WRITE) = 0;
//! Synchronously send transactionAddedToMempool notifications about all
//! current mempool transactions to the specified handler and return after

View file

@ -826,22 +826,22 @@ public:
});
if (!action) return false;
// Now dump value to disk if requested
return *action == interfaces::SettingsAction::SKIP_WRITE || args().WriteSettingsFile();
return *action != interfaces::SettingsAction::WRITE || args().WriteSettingsFile();
}
bool overwriteRwSetting(const std::string& name, common::SettingsValue value, bool write) override
bool overwriteRwSetting(const std::string& name, common::SettingsValue value, interfaces::SettingsAction action) override
{
if (value.isNull()) return deleteRwSettings(name, write);
if (value.isNull()) return deleteRwSettings(name, action);
return updateRwSetting(name, [&](common::SettingsValue& settings) {
settings = std::move(value);
return write ? interfaces::SettingsAction::WRITE : interfaces::SettingsAction::SKIP_WRITE;
return action;
});
}
bool deleteRwSettings(const std::string& name, bool write) override
bool deleteRwSettings(const std::string& name, interfaces::SettingsAction action) override
{
args().LockSettings([&](common::Settings& settings) {
settings.rw_settings.erase(name);
});
return !write || args().WriteSettingsFile();
return action != interfaces::SettingsAction::WRITE || args().WriteSettingsFile();
}
void requestMempoolTransactions(Notifications& notifications) override
{

View file

@ -69,7 +69,7 @@ bool VerifyWallets(WalletContext& context)
// Pass write=false because no need to write file and probably
// better not to. If unnamed wallet needs to be added next startup
// and the setting is empty, this code will just run again.
chain.overwriteRwSetting("wallet", std::move(wallets), /*write=*/false);
chain.overwriteRwSetting("wallet", std::move(wallets), interfaces::SettingsAction::SKIP_WRITE);
}
}