diff --git a/althea_types/src/interop.rs b/althea_types/src/interop.rs index e7cacdb85..afb1f387a 100644 --- a/althea_types/src/interop.rs +++ b/althea_types/src/interop.rs @@ -525,6 +525,8 @@ pub struct OperatorUpdateMessage { deserialize_with = "data_deserialize" )] pub contact_info: Option, + /// Billing details from ops tools, so that we may sync changes + pub billing_details: Option, } /// Serializes a ContactType as a string diff --git a/althea_types/src/user_info.rs b/althea_types/src/user_info.rs index 9d273b618..d4ba26447 100644 --- a/althea_types/src/user_info.rs +++ b/althea_types/src/user_info.rs @@ -30,6 +30,8 @@ pub struct BillingDetails { /// format the local nation has for addresses. Optional as this install /// may not have a formal mailing address pub mailing_address: MailingAddress, + #[serde(default)] + pub sequence_number: u32, } /// Struct for storing details about this user installation. This particular diff --git a/rita_client/src/dashboard/installation_details.rs b/rita_client/src/dashboard/installation_details.rs index 6a997291b..e9d93b93a 100644 --- a/rita_client/src/dashboard/installation_details.rs +++ b/rita_client/src/dashboard/installation_details.rs @@ -117,6 +117,8 @@ pub async fn set_installation_details(req: Json) -> Htt city: input.city, street: input.street, }, + // initialize sequence with 1 + sequence_number: 1, }; let mut rita_client = settings::get_rita_client(); diff --git a/rita_client/src/operator_update/mod.rs b/rita_client/src/operator_update/mod.rs index d1536abb5..a94156bbd 100644 --- a/rita_client/src/operator_update/mod.rs +++ b/rita_client/src/operator_update/mod.rs @@ -8,6 +8,7 @@ use crate::rita_loop::CLIENT_LOOP_TIMEOUT; use crate::set_router_update_instruction; use althea_kernel_interface::hardware_info::get_hardware_info; use althea_types::get_sequence_num; +use althea_types::BillingDetails; use althea_types::ContactStorage; use althea_types::ContactType; use althea_types::HardwareInfo; @@ -228,7 +229,13 @@ async fn checkin() { rita_client.payment = payment; trace!("Done with payment"); - let mut operator = rita_client.operator; + let mut operator = rita_client.operator.clone(); + if check_billing_update( + rita_client.operator.billing_details.clone(), + new_settings.billing_details.clone(), + ) { + operator.billing_details = new_settings.billing_details.clone(); + } let new_operator_fee = Uint256::from(new_settings.operator_fee); operator.operator_fee = new_operator_fee; operator.installation_details = None; @@ -400,6 +407,22 @@ fn check_contacts_update(current: Option, incoming: Option, incoming: Option) -> bool { + let current_sequence = match current { + Some(details) => details.sequence_number, + None => 0, + }; + if let Some(details) = incoming { + let seq = details.sequence_number; + if seq > current_sequence { + return true; + } + // else the existing config is more recent, so do not update + return false; + } + false +} + /// Merges an arbitrary settings string, after first filtering for several /// forbidden values fn merge_settings_safely(new_settings: Value) {