1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use crate::utils::deserialize_u256;
use ethers::core::types::U256;
use serde::Deserialize;

/// Represents stats for a searcher.
#[derive(Deserialize)]
pub struct UserStats {
    /// Whether the searcher is high priority or not.
    pub is_high_priority: bool,
    /// The total amount of payments made to miners.
    #[serde(deserialize_with = "deserialize_u256")]
    pub all_time_miner_payments: U256,
    /// The total amount of gas simulated in bundles.
    #[serde(deserialize_with = "deserialize_u256")]
    pub all_time_gas_simulated: U256,
    /// The total amount of payments made to miners in the last 7 days.
    #[serde(deserialize_with = "deserialize_u256")]
    pub last_7d_miner_payments: U256,
    /// The total amount of gas simulated in bundles the last 7 days.
    #[serde(deserialize_with = "deserialize_u256")]
    pub last_7d_gas_simulated: U256,
    /// The total amount of payments made to miners in the last day.
    #[serde(deserialize_with = "deserialize_u256")]
    pub last_1d_miner_payments: U256,
    /// The total amount of gas simulated in bundles in the last day.
    #[serde(deserialize_with = "deserialize_u256")]
    pub last_1d_gas_simulated: U256,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn user_stats_deserialize() {
        let user_stats: UserStats = serde_json::from_str(
            r#"{
  "is_high_priority": true,
  "all_time_miner_payments": "1280749594841588639",
  "all_time_gas_simulated": "30049470846",
  "last_7d_miner_payments": "1280749594841588639",
  "last_7d_gas_simulated": "30049470846",
  "last_1d_miner_payments": "142305510537954293",
  "last_1d_gas_simulated": "2731770076"
}"#,
        )
        .unwrap();

        assert_eq!(user_stats.is_high_priority, true);
        assert_eq!(
            user_stats.all_time_miner_payments,
            U256::from_dec_str("1280749594841588639").unwrap()
        );
        assert_eq!(
            user_stats.all_time_gas_simulated,
            U256::from_dec_str("30049470846").unwrap()
        );
        assert_eq!(
            user_stats.last_7d_miner_payments,
            U256::from_dec_str("1280749594841588639").unwrap()
        );
        assert_eq!(
            user_stats.last_7d_gas_simulated,
            U256::from_dec_str("30049470846").unwrap()
        );
        assert_eq!(
            user_stats.last_1d_miner_payments,
            U256::from_dec_str("142305510537954293").unwrap()
        );
        assert_eq!(
            user_stats.last_1d_gas_simulated,
            U256::from_dec_str("2731770076").unwrap()
        );
    }
}