evmlib/
quoting_metrics.rs1use crate::common::U256;
10use serde::{Deserialize, Serialize};
11use std::fmt::{Debug, Formatter, Result as FmtResult};
12
13#[derive(Clone, Eq, PartialEq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
15pub struct QuotingMetrics {
16 pub data_type: u32,
18 pub data_size: usize,
20 pub close_records_stored: usize,
22 pub records_per_type: Vec<(u32, u32)>,
24 pub max_records: usize,
26 pub received_payment_count: usize,
28 pub live_time: u64,
30 pub network_density: Option<[u8; 32]>,
33 pub network_size: Option<u64>,
35}
36
37impl Debug for QuotingMetrics {
38 fn fmt(&self, formatter: &mut Formatter) -> FmtResult {
39 let density_u256 = self.network_density.map(U256::from_be_bytes);
40
41 write!(
42 formatter,
43 "QuotingMetrics {{ data_type: {}, data_size: {}, close_records_stored: {}, records_per_type {:?}, max_records: {}, received_payment_count: {}, live_time: {}, network_density: {density_u256:?}, network_size: {:?} }}",
44 self.data_type,
45 self.data_size,
46 self.close_records_stored,
47 self.records_per_type,
48 self.max_records,
49 self.received_payment_count,
50 self.live_time,
51 self.network_size
52 )
53 }
54}
55
56impl QuotingMetrics {
57 pub fn to_bytes(&self) -> Vec<u8> {
62 let mut bytes = Vec::new();
63
64 bytes.extend_from_slice(&self.data_type.to_le_bytes());
65 bytes.extend_from_slice(&(self.data_size as u64).to_le_bytes());
66 bytes.extend_from_slice(&(self.close_records_stored as u64).to_le_bytes());
67 bytes.extend_from_slice(&(self.records_per_type.len() as u32).to_le_bytes());
68 for (dtype, count) in &self.records_per_type {
69 bytes.extend_from_slice(&dtype.to_le_bytes());
70 bytes.extend_from_slice(&count.to_le_bytes());
71 }
72 bytes.extend_from_slice(&(self.max_records as u64).to_le_bytes());
73 bytes.extend_from_slice(&(self.received_payment_count as u64).to_le_bytes());
74 bytes.extend_from_slice(&self.live_time.to_le_bytes());
75 if let Some(density) = &self.network_density {
76 bytes.push(1); bytes.extend_from_slice(density);
78 } else {
79 bytes.push(0); }
81 if let Some(size) = self.network_size {
82 bytes.push(1); bytes.extend_from_slice(&size.to_le_bytes());
84 } else {
85 bytes.push(0); }
87
88 bytes
89 }
90}