Skip to content

Commit 3a59088

Browse files
committed
fix: refactor impl
1 parent 21a67b7 commit 3a59088

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

sentry/src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -444,16 +444,6 @@ pub fn epoch() -> f64 {
444444
}
445445

446446
// @TODO: Make pub(crate)
447-
// #[derive(Debug, Clone)]
448-
// pub struct Session {
449-
// pub era: i64,
450-
// pub uid: ValidatorId,
451-
// pub ip: Option<String>,
452-
// pub country: Option<String>,
453-
// pub referrer_header: Option<String>,
454-
// pub os: Option<String>,
455-
// }
456-
457447
#[derive(Debug, Clone)]
458448
pub struct Session {
459449
pub ip: Option<String>,

sentry/src/payout.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,21 @@ fn payout(
4242
.iter()
4343
.find(|&rule| rule.amount.is_some())
4444
.map(|&rule| rule.amount.as_ref().expect("should have value"));
45-
let price_by_rules = if let Some(amount) = fixed_amount_rule {
46-
amount.clone()
47-
} else {
48-
let exponent: f64 = 10.0;
49-
let multiplier = rules
50-
.iter()
51-
.filter(|&rule| rule.multiplier.is_some())
52-
.map(|rule| rule.multiplier.expect("should have value"))
53-
.fold(1.0, |result, i| result * i);
54-
let value: u64 = (multiplier * exponent.powi(18)) as u64;
55-
let result = min_price * BigNum::from(value);
56-
57-
result / BigNum::from(10u64.pow(18))
45+
46+
let price_by_rules = match fixed_amount_rule {
47+
Some(amount) => amount.clone(),
48+
None => {
49+
let exponent: f64 = 10.0;
50+
let multiplier = rules
51+
.iter()
52+
.filter(|&rule| rule.multiplier.is_some())
53+
.map(|rule| rule.multiplier.expect("should have value"))
54+
.fold(1.0, |result, i| result * i);
55+
let value: u64 = (multiplier * exponent.powi(18)) as u64;
56+
let result = min_price * BigNum::from(value);
57+
58+
result / BigNum::from(10u64.pow(18))
59+
}
5860
};
5961

6062
max_price.min(price_by_rules)
@@ -66,14 +68,12 @@ fn match_rule(
6668
session: &Session,
6769
uid: &ValidatorId,
6870
) -> bool {
69-
let ev_type = match &rule.ev_type {
70-
Some(event_types) => event_types.contains(&ev_type.to_string()),
71-
None => true,
72-
};
73-
74-
let publisher = match &rule.publisher {
75-
Some(publishers) => publishers.contains(&uid),
76-
None => true,
71+
let (ev_type, publisher) = match (&rule.ev_type, &rule.publisher) {
72+
(Some(event_types), Some(publishers)) => (
73+
event_types.contains(&ev_type.to_string()),
74+
publishers.contains(&uid),
75+
),
76+
_ => (true, true),
7777
};
7878

7979
let os_type = match (&rule.os_type, &session.os) {
@@ -394,7 +394,7 @@ mod tests {
394394
channel.spec.pricing_bounds = Some(PricingBounds {
395395
click: Some(Pricing {
396396
min: BigNum::from(100),
397-
max: BigNum::from(1000)
397+
max: BigNum::from(1000),
398398
}),
399399
impression: None,
400400
});

0 commit comments

Comments
 (0)