mithril_common/messages/
aggregator_status.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    entities::{CardanoEra, Epoch, ProtocolParameters, Stake, TotalSPOs},
5    era::SupportedEra,
6};
7
8/// Message advertised by an aggregator to inform about its status
9#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
10pub struct AggregatorStatusMessage {
11    /// Current epoch
12    pub epoch: Epoch,
13
14    /// Current Cardano era
15    pub cardano_era: CardanoEra,
16
17    /// Cardano network
18    pub cardano_network: String,
19
20    /// Current Mithril era
21    pub mithril_era: SupportedEra,
22
23    /// Cardano node version
24    pub cardano_node_version: String,
25
26    /// Aggregator node version
27    pub aggregator_node_version: String,
28
29    /// Current Protocol parameters
30    #[serde(rename = "protocol")]
31    pub protocol_parameters: ProtocolParameters,
32
33    /// Next Protocol parameters
34    #[serde(rename = "next_protocol")]
35    pub next_protocol_parameters: ProtocolParameters,
36
37    /// The number of signers for the current epoch
38    pub total_signers: usize,
39
40    /// The number of signers that will be able to sign on the next epoch
41    pub total_next_signers: usize,
42
43    /// The total stakes of the signers for the current epoch
44    pub total_stakes_signers: Stake,
45
46    /// The total stakes of the signers that will be able to sign on the next epoch
47    pub total_next_stakes_signers: Stake,
48
49    /// The number of Cardano SPOs
50    pub total_cardano_spo: TotalSPOs,
51
52    /// The total stake in Cardano
53    pub total_cardano_stake: Stake,
54}
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59
60    const CURRENT_JSON: &str = r#"{
61        "epoch": 48,
62        "cardano_era": "conway",
63        "cardano_network": "mainnet",
64        "mithril_era": "pythagoras",
65        "cardano_node_version": "1.2.3",
66        "aggregator_node_version": "4.5.6",
67        "protocol": { "k": 5, "m": 100, "phi_f": 0.65 },
68        "next_protocol": { "k": 50, "m": 1000, "phi_f": 0.65 },
69        "total_signers": 1234,
70        "total_next_signers": 56789,
71        "total_stakes_signers": 123456789,
72        "total_next_stakes_signers": 987654321,
73        "total_cardano_spo": 7777,
74        "total_cardano_stake": 888888888
75        }"#;
76
77    fn golden_current_message() -> AggregatorStatusMessage {
78        AggregatorStatusMessage {
79            epoch: Epoch(48),
80            cardano_era: "conway".to_string(),
81            cardano_network: "mainnet".to_string(),
82            mithril_era: SupportedEra::Pythagoras,
83            cardano_node_version: "1.2.3".to_string(),
84            aggregator_node_version: "4.5.6".to_string(),
85            protocol_parameters: ProtocolParameters {
86                k: 5,
87                m: 100,
88                phi_f: 0.65,
89            },
90            next_protocol_parameters: ProtocolParameters {
91                k: 50,
92                m: 1000,
93                phi_f: 0.65,
94            },
95            total_signers: 1234,
96            total_next_signers: 56789,
97            total_stakes_signers: 123456789,
98            total_next_stakes_signers: 987654321,
99            total_cardano_spo: 7777,
100            total_cardano_stake: 888888888,
101        }
102    }
103
104    #[test]
105    fn test_current_json_deserialized_into_current_message() {
106        let json = CURRENT_JSON;
107        let message: AggregatorStatusMessage = serde_json::from_str(json).expect(
108            "This JSON is expected to be successfully parsed into a AggregatorStatusMessage instance.",
109        );
110
111        assert_eq!(golden_current_message(), message);
112    }
113}