kaspa_consensus_core/api/
stats.rs1use serde::{Deserialize, Serialize};
2use workflow_serializer::prelude::*;
3
4#[derive(Clone, Debug, Serialize, Deserialize, Default)]
5#[serde(rename_all = "camelCase")]
6pub struct BlockCount {
7 pub header_count: u64,
8 pub block_count: u64,
9}
10
11impl BlockCount {
12 pub fn new(block_count: u64, header_count: u64) -> Self {
13 Self { block_count, header_count }
14 }
15}
16
17impl Serializer for BlockCount {
18 fn serialize<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
19 store!(u16, &1, writer)?;
20 store!(u64, &self.header_count, writer)?;
21 store!(u64, &self.block_count, writer)?;
22
23 Ok(())
24 }
25}
26
27impl Deserializer for BlockCount {
28 fn deserialize<R: std::io::Read>(reader: &mut R) -> std::io::Result<Self> {
29 let _version = load!(u16, reader)?;
30 let header_count = load!(u64, reader)?;
31 let block_count = load!(u64, reader)?;
32
33 Ok(Self { header_count, block_count })
34 }
35}
36
37#[derive(Clone, Default)]
38pub struct VirtualStateStats {
39 pub num_parents: u32,
41 pub daa_score: u64,
42 pub bits: u32,
43 pub past_median_time: u64,
44}
45
46pub struct ConsensusStats {
47 pub block_counts: BlockCount,
49
50 pub num_tips: u64,
52
53 pub virtual_stats: VirtualStateStats,
55}