Skip to content

Commit

Permalink
Make billing details editable from ops tools
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ch-iara committed Aug 30, 2022
1 parent 8d8a6c0 commit c95107d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions althea_types/src/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ pub struct OperatorUpdateMessage {
deserialize_with = "data_deserialize"
)]
pub contact_info: Option<ContactType>,
/// Billing details from ops tools, so that we may sync changes
pub billing_details: Option<BillingDetails>,
}

/// Serializes a ContactType as a string
Expand Down
2 changes: 2 additions & 0 deletions althea_types/src/user_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions rita_client/src/dashboard/installation_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ pub async fn set_installation_details(req: Json<InstallationDetailsPost>) -> Htt
city: input.city,
street: input.street,
},
// initialize sequence with 1
sequence_number: 1,
};

let mut rita_client = settings::get_rita_client();
Expand Down
25 changes: 24 additions & 1 deletion rita_client/src/operator_update/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -400,6 +407,22 @@ fn check_contacts_update(current: Option<ContactStorage>, incoming: Option<Conta
false
}

fn check_billing_update(current: Option<BillingDetails>, incoming: Option<BillingDetails>) -> 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) {
Expand Down

0 comments on commit c95107d

Please sign in to comment.