diff --git a/rita_bin/src/client.rs b/rita_bin/src/client.rs index 5fcdf0df6..a1d29cbd6 100644 --- a/rita_bin/src/client.rs +++ b/rita_bin/src/client.rs @@ -144,10 +144,9 @@ fn main() { start_rita_common_loops(); start_rita_client_loops(); - save_to_disk_loop( - SettingsOnDisk::RitaClientSettings(settings::get_rita_client()), - &args.flag_config, - ); + save_to_disk_loop(SettingsOnDisk::RitaClientSettings( + settings::get_rita_client(), + )); start_core_rita_endpoints(4); start_rita_client_endpoints(1); start_client_dashboard(settings.network.rita_dashboard_port); diff --git a/rita_bin/src/exit.rs b/rita_bin/src/exit.rs index 9d6522d4c..930979dc2 100644 --- a/rita_bin/src/exit.rs +++ b/rita_bin/src/exit.rs @@ -70,7 +70,7 @@ fn main() { // load the settings file, setup a thread to save it out every so often // and populate the memory cache of settings used throughout the program let settings = { - let settings_file = args.flag_config.clone(); + let settings_file = args.flag_config; let settings = RitaExitSettingsStruct::new_watched(&settings_file).unwrap(); settings::set_git_hash(env!("GIT_HASH").to_string()); @@ -132,10 +132,9 @@ fn main() { start_rita_common_loops(); start_rita_exit_loop(); - save_to_disk_loop( - SettingsOnDisk::RitaExitSettingsStruct(settings::get_rita_exit()), - &args.flag_config, - ); + save_to_disk_loop(SettingsOnDisk::RitaExitSettingsStruct( + settings::get_rita_exit(), + )); let workers = settings.workers; start_core_rita_endpoints(workers as usize); diff --git a/rita_client/src/dashboard/exits.rs b/rita_client/src/dashboard/exits.rs index d00289b30..c236cbe6c 100644 --- a/rita_client/src/dashboard/exits.rs +++ b/rita_client/src/dashboard/exits.rs @@ -12,6 +12,7 @@ use babel_monitor::parse_routes; use rita_common::RitaCommonError; use rita_common::KI; use settings::client::ExitServer; +use settings::write_config; use std::collections::HashMap; use std::time::Duration; @@ -149,6 +150,10 @@ pub async fn reset_exit(path: Path) -> HttpResponse { }; rita_client.exit_client.exits = exits; settings::set_rita_client(rita_client); + let res = write_config(); + if let Err(e) = res { + error!("Failed to save exit reset! {:?}", e); + } HttpResponse::Ok().json(ret) } else { error!("Requested a reset on unknown exit {:?}", exit_name); diff --git a/rita_client/src/dashboard/operator.rs b/rita_client/src/dashboard/operator.rs index d7a9b0f97..2fec66a1b 100644 --- a/rita_client/src/dashboard/operator.rs +++ b/rita_client/src/dashboard/operator.rs @@ -3,6 +3,7 @@ use actix_web_async::web::Path; use actix_web_async::{HttpRequest, HttpResponse}; use clarity::Address; use num256::Uint256; +use settings::write_config; use std::collections::HashMap; /// TODO remove after beta 12, provided for backwards compat @@ -28,6 +29,10 @@ pub async fn add_to_dao_list(path: Path
) -> HttpResponse { rita_client.operator = operator; settings::set_rita_client(rita_client); + let res = write_config(); + if let Err(e) = res { + error!("Failed to save operator address! {:?}", e); + } HttpResponse::Ok().finish() } @@ -41,6 +46,10 @@ pub async fn remove_from_dao_list(_path: Path
) -> HttpResponse { rita_client.operator = operator; settings::set_rita_client(rita_client); + let res = write_config(); + if let Err(e) = res { + error!("Failed to save operator remove! {:?}", e); + } HttpResponse::Ok().finish() } @@ -65,6 +74,10 @@ pub async fn set_dao_fee(path: Path) -> HttpResponse { rita_client.operator = operator; settings::set_rita_client(rita_client); + let res = write_config(); + if let Err(e) = res { + error!("Failed to save operator fee! {:?}", e); + } HttpResponse::Ok().finish() } diff --git a/rita_common/src/rita_loop/write_to_disk.rs b/rita_common/src/rita_loop/write_to_disk.rs index 63a4f7656..af4a9006a 100644 --- a/rita_common/src/rita_loop/write_to_disk.rs +++ b/rita_common/src/rita_loop/write_to_disk.rs @@ -1,7 +1,7 @@ use crate::{debt_keeper::save_debt_to_disk, usage_tracker::save_usage_to_disk}; use settings::{ check_if_exit, client::RitaClientSettings, exit::RitaExitSettingsStruct, get_rita_client, - get_rita_exit, save_client_settings, save_exit_settings, + get_rita_exit, write_config, }; use std::{ thread, @@ -26,8 +26,7 @@ pub enum SettingsOnDisk { /// is. There is also a consideration for the amount of storage the device /// has on disk since we don't want to save too often if the disk doesn't /// contain a lot of storage. -pub fn save_to_disk_loop(mut old_settings: SettingsOnDisk, file_path: &str) { - let file_path = file_path.to_string(); +pub fn save_to_disk_loop(mut old_settings: SettingsOnDisk) { let router_storage_small; let saving_to_disk_frequency: Duration; @@ -67,7 +66,10 @@ pub fn save_to_disk_loop(mut old_settings: SettingsOnDisk, file_path: &str) { let new_settings = get_rita_client(); if old_settings_client != new_settings { - save_client_settings(old_settings_client, file_path.clone()); + let res = write_config(); + if let Err(e) = res { + error!("Error saving client settings! {:?}", e); + } } old_settings = SettingsOnDisk::RitaClientSettings(new_settings); @@ -76,7 +78,10 @@ pub fn save_to_disk_loop(mut old_settings: SettingsOnDisk, file_path: &str) { let new_settings = get_rita_exit(); if old_settings_exit != new_settings { - save_exit_settings(new_settings.clone(), file_path.clone()); + let res = write_config(); + if let Err(e) = res { + error!("Error saving exit settings! {:?}", e); + } } old_settings = SettingsOnDisk::RitaExitSettingsStruct(new_settings); diff --git a/settings/src/lib.rs b/settings/src/lib.rs index d00cb75af..3f4c5db70 100644 --- a/settings/src/lib.rs +++ b/settings/src/lib.rs @@ -156,20 +156,6 @@ pub fn save_settings_on_shutdown() { info!("Shutdown: saving settings"); } -pub fn save_exit_settings(new_settings: RitaExitSettingsStruct, file_path: String) { - if let Err(e) = new_settings.write(&file_path) { - warn!("writing updated exit config failed {:?}", e); - } - log::info!("Exit Config/settings is being saved to"); -} - -pub fn save_client_settings(new_settings: RitaClientSettings, file_path: String) { - if let Err(e) = new_settings.write(&file_path) { - warn!("writing updated client config failed {:?}", e); - } - log::info!("Client Config/settings is being saved to"); -} - /// get a JSON value of all settings pub fn get_config_json() -> Result { match &*SETTINGS.read().unwrap() {