mithril_common/messages/
aggregator_status.rs

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