mithril_common/messages/
snapshot_download.rs

1use serde::{Deserialize, Serialize};
2
3use crate::entities::{CardanoDbBeacon, CompressionAlgorithm};
4
5/// Message structure of a snapshot
6#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
7pub struct SnapshotDownloadMessage {
8    /// Digest that is signed by the signer participants
9    pub digest: String,
10
11    /// Cardano network
12    pub network: String,
13
14    /// Mithril beacon on the Cardano chain
15    pub beacon: CardanoDbBeacon,
16
17    /// Size of the immutables snapshot file in Bytes
18    pub size: u64,
19
20    /// Size of the ancillary files in Bytes
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub ancillary_size: Option<u64>,
23
24    /// Locations where the snapshot of the immutable files can be retrieved
25    pub locations: Vec<String>,
26
27    /// Locations where the snapshot of the ancillary files can be retrieved
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub ancillary_locations: Option<Vec<String>>,
30
31    /// Compression algorithm of the snapshot archive
32    pub compression_algorithm: CompressionAlgorithm,
33
34    /// Cardano node version
35    pub cardano_node_version: String,
36}
37
38#[cfg(test)]
39mod tests {
40    use crate::entities::Epoch;
41
42    use super::*;
43
44    #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
45    pub struct SnapshotDownloadMessageUntilV0_1_47 {
46        pub digest: String,
47        pub network: String,
48        pub beacon: CardanoDbBeacon,
49        pub size: u64,
50        pub locations: Vec<String>,
51        pub compression_algorithm: CompressionAlgorithm,
52        pub cardano_node_version: String,
53    }
54
55    const CURRENT_JSON: &str = r#"{
56        "digest": "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6",
57        "network": "preview",
58        "beacon": {
59            "epoch": 86,
60            "immutable_file_number": 1728
61        },
62        "size": 807803196,
63        "ancillary_size": 123456789,
64        "locations": [
65            "https://host/certificate.tar.gz"
66        ],
67        "ancillary_locations": [
68            "https://host/ancillary.tar.gz"
69        ],
70        "compression_algorithm": "gzip",
71        "cardano_node_version": "0.0.1"
72    }"#;
73
74    fn golden_message_until_open_api_0_1_47() -> SnapshotDownloadMessageUntilV0_1_47 {
75        SnapshotDownloadMessageUntilV0_1_47 {
76            digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6".to_string(),
77            network: "preview".to_string(),
78            beacon: CardanoDbBeacon {
79                epoch: Epoch(86),
80                immutable_file_number: 1728,
81            },
82            size: 807803196,
83            locations: vec!["https://host/certificate.tar.gz".to_string()],
84            compression_algorithm: CompressionAlgorithm::Gzip,
85            cardano_node_version: "0.0.1".to_string(),
86        }
87    }
88
89    fn golden_message_current() -> SnapshotDownloadMessage {
90        SnapshotDownloadMessage {
91            digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6".to_string(),
92            network: "preview".to_string(),
93            beacon: CardanoDbBeacon {
94                epoch: Epoch(86),
95                immutable_file_number: 1728,
96            },
97            size: 807803196,
98            ancillary_size: Some(123456789),
99            locations: vec!["https://host/certificate.tar.gz".to_string()],
100            ancillary_locations: Some(vec!["https://host/ancillary.tar.gz".to_string()]),
101            compression_algorithm: CompressionAlgorithm::Gzip,
102            cardano_node_version: "0.0.1".to_string(),
103        }
104    }
105
106    #[test]
107    fn test_current_json_deserialized_into_message_supported_until_open_api_0_1_47() {
108        let json = CURRENT_JSON;
109        let message: SnapshotDownloadMessageUntilV0_1_47 = serde_json::from_str(json).unwrap();
110
111        assert_eq!(golden_message_until_open_api_0_1_47(), message);
112    }
113
114    #[test]
115    fn test_current_json_deserialized_into_current_message() {
116        let json = CURRENT_JSON;
117        let message: SnapshotDownloadMessage = serde_json::from_str(json).unwrap();
118
119        assert_eq!(golden_message_current(), message);
120    }
121}