mithril_common/entities/
snapshot.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use crate::{
    entities::{CardanoDbBeacon, CompressionAlgorithm},
    signable_builder::Artifact,
};
use semver::Version;
use serde::{Deserialize, Serialize};

/// Snapshot represents a snapshot file and its metadata
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct Snapshot {
    /// Digest that is signed by the signer participants
    pub digest: String,

    /// Cardano network
    pub network: String,

    /// Mithril beacon on the Cardano chain
    pub beacon: CardanoDbBeacon,

    /// Size of the snapshot file in Bytes
    pub size: u64,

    /// Locations where the binary content of the snapshot can be retrieved
    pub locations: Vec<String>,

    /// Compression algorithm of the snapshot archive
    pub compression_algorithm: CompressionAlgorithm,

    /// Version of the Cardano node used to create snapshot archive.
    pub cardano_node_version: String,
}

impl Snapshot {
    /// Snapshot factory
    pub fn new<N: Into<String>>(
        digest: String,
        network: N,
        beacon: CardanoDbBeacon,
        size: u64,
        locations: Vec<String>,
        compression_algorithm: CompressionAlgorithm,
        cardano_node_version: &Version,
    ) -> Snapshot {
        let cardano_node_version = format!("{cardano_node_version}");

        Snapshot {
            digest,
            network: network.into(),
            beacon,
            size,
            locations,
            compression_algorithm,
            cardano_node_version,
        }
    }
}

#[typetag::serde]
impl Artifact for Snapshot {
    fn get_id(&self) -> String {
        self.digest.clone()
    }
}