use std::error::Error;
use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct Metrics {
pub transactions_per_second: f64,
pub block_time: f64,
pub active_validators: u32,
pub network_usage: HashMap<String, f64>,
}
impl Default for Metrics {
fn default() -> Self {
Self::new()
}
}
impl Metrics {
pub fn new() -> Self {
Self {
transactions_per_second: 0.0,
block_time: 0.0,
active_validators: 0,
network_usage: HashMap::new(),
}
}
pub fn add_network_usage(&mut self, key: &str, value: f64) -> Result<(), Box<dyn Error>> {
self.network_usage.insert(key.to_string(), value);
Ok(())
}
}