From c95107d7279e5a1a5370d118dd0e79065d1309ee Mon Sep 17 00:00:00 2001 From: Chiara Seim Date: Tue, 30 Aug 2022 15:15:52 -0700 Subject: [PATCH] Make billing details editable from ops tools Billing details now includes a sequence number which keeps track of updates sent by ops, which now sends back billing details as part of the router checkin process. --- althea_types/src/interop.rs | 2 ++ althea_types/src/user_info.rs | 2 ++ .../src/dashboard/installation_details.rs | 2 ++ rita_client/src/operator_update/mod.rs | 25 ++++++++++++++++++- 4 files changed, 30 insertions(+), 1 deletion(-) 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) {