|
| 1 | +use semver::Version; |
| 2 | +use serde::{Deserialize, Serialize}; |
| 3 | + |
| 4 | +use crate::{ |
| 5 | + entities::{CardanoDbBeacon, CompressionAlgorithm}, |
| 6 | + signable_builder::Artifact, |
| 7 | +}; |
| 8 | + |
| 9 | +/// Cardano database incremental. |
| 10 | +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
| 11 | +pub struct CardanoDatabase { |
| 12 | + /// Merkle root of the Cardano database. |
| 13 | + pub merkle_root: String, |
| 14 | + |
| 15 | + /// Mithril beacon on the Cardano chain. |
| 16 | + pub beacon: CardanoDbBeacon, |
| 17 | + |
| 18 | + /// Size of the uncompressed Cardano database (including the ledger and volatile) in Bytes. |
| 19 | + pub total_db_size_uncompressed: u64, |
| 20 | + |
| 21 | + /// Locations of the Cardano database artifacts. |
| 22 | + pub locations: ArtifactsLocations, |
| 23 | + |
| 24 | + /// Compression algorithm of the Cardano database archives |
| 25 | + pub compression_algorithm: CompressionAlgorithm, |
| 26 | + |
| 27 | + /// Version of the Cardano node used to create the archives. |
| 28 | + pub cardano_node_version: String, |
| 29 | +} |
| 30 | + |
| 31 | +impl CardanoDatabase { |
| 32 | + /// [CardanoDatabase] factory |
| 33 | + pub fn new( |
| 34 | + merkle_root: String, |
| 35 | + beacon: CardanoDbBeacon, |
| 36 | + total_db_size_uncompressed: u64, |
| 37 | + locations: ArtifactsLocations, |
| 38 | + compression_algorithm: CompressionAlgorithm, |
| 39 | + cardano_node_version: &Version, |
| 40 | + ) -> Self { |
| 41 | + let cardano_node_version = format!("{cardano_node_version}"); |
| 42 | + |
| 43 | + Self { |
| 44 | + merkle_root, |
| 45 | + beacon, |
| 46 | + locations, |
| 47 | + total_db_size_uncompressed, |
| 48 | + compression_algorithm, |
| 49 | + cardano_node_version, |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
| 55 | +#[serde(rename_all = "snake_case")] |
| 56 | +pub enum ArtifactLocationType { |
| 57 | + Aggregator, |
| 58 | +} |
| 59 | + |
| 60 | +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
| 61 | +pub struct ArtifactLocationEntry { |
| 62 | + #[serde(rename = "type")] |
| 63 | + pub location_type: ArtifactLocationType, |
| 64 | + pub uri: String, |
| 65 | +} |
| 66 | + |
| 67 | +/// Locations of the Cardano database related files. |
| 68 | +#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] |
| 69 | +pub struct ArtifactsLocations { |
| 70 | + /// Locations of the file containing the digests of the immutable files. |
| 71 | + pub digests: Vec<ArtifactLocationEntry>, |
| 72 | + /// Locations of the immutable files. |
| 73 | + pub immutables: Vec<ArtifactLocationEntry>, |
| 74 | + /// Locations of the ancillary files (ledger and volatile). |
| 75 | + pub ancillary: Vec<ArtifactLocationEntry>, |
| 76 | +} |
| 77 | + |
| 78 | +#[typetag::serde] |
| 79 | +impl Artifact for CardanoDatabase { |
| 80 | + fn get_id(&self) -> String { |
| 81 | + self.merkle_root.clone() |
| 82 | + } |
| 83 | +} |
0 commit comments