Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions mithril-common/src/entities/cardano_database.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
use semver::Version;
use serde::{Deserialize, Serialize};

use crate::{
entities::{CardanoDbBeacon, CompressionAlgorithm},
signable_builder::Artifact,
};

/// Cardano database incremental.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct CardanoDatabase {
/// Merkle root of the Cardano database.
pub merkle_root: String,

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

/// Size of the uncompressed Cardano database (including the ledger and volatile) in Bytes.
pub total_db_size_uncompressed: u64,

/// Locations of the Cardano database artifacts.
pub locations: ArtifactsLocations,

/// Compression algorithm of the Cardano database archives
pub compression_algorithm: CompressionAlgorithm,

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

impl CardanoDatabase {
/// [CardanoDatabase] factory
pub fn new(
merkle_root: String,
beacon: CardanoDbBeacon,
total_db_size_uncompressed: u64,
locations: ArtifactsLocations,
compression_algorithm: CompressionAlgorithm,
cardano_node_version: &Version,
) -> Self {
let cardano_node_version = format!("{cardano_node_version}");

Self {
merkle_root,
beacon,
locations,
total_db_size_uncompressed,
compression_algorithm,
cardano_node_version,
}
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ArtifactLocationType {
Aggregator,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ArtifactLocationEntry {
#[serde(rename = "type")]
pub location_type: ArtifactLocationType,
pub uri: String,
}

/// Locations of the Cardano database related files.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct ArtifactsLocations {
/// Locations of the file containing the digests of the immutable files.
pub digests: Vec<ArtifactLocationEntry>,
/// Locations of the immutable files.
pub immutables: Vec<ArtifactLocationEntry>,
/// Locations of the ancillary files (ledger and volatile).
pub ancillary: Vec<ArtifactLocationEntry>,
}

#[typetag::serde]
impl Artifact for CardanoDatabase {
fn get_id(&self) -> String {
self.merkle_root.clone()
}
}
2 changes: 2 additions & 0 deletions mithril-common/src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub(crate) mod arithmetic_operation_wrapper;
mod block_number;
mod block_range;
mod cardano_chain_point;
mod cardano_database;
mod cardano_db_beacon;
mod cardano_network;
mod cardano_stake_distribution;
Expand Down Expand Up @@ -32,6 +33,7 @@ mod type_alias;
pub use block_number::BlockNumber;
pub use block_range::{BlockRange, BlockRangeLength, BlockRangesSequence};
pub use cardano_chain_point::{BlockHash, ChainPoint};
pub use cardano_database::{ArtifactsLocations, CardanoDatabase};
pub use cardano_db_beacon::CardanoDbBeacon;
pub use cardano_network::CardanoNetwork;
pub use cardano_stake_distribution::CardanoStakeDistribution;
Expand Down