Skip to content

Commit 4bddc11

Browse files
committed
feat: add CardanoDatabase entity
1 parent 74c6e61 commit 4bddc11

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
}

mithril-common/src/entities/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub(crate) mod arithmetic_operation_wrapper;
44
mod block_number;
55
mod block_range;
66
mod cardano_chain_point;
7+
mod cardano_database;
78
mod cardano_db_beacon;
89
mod cardano_network;
910
mod cardano_stake_distribution;
@@ -32,6 +33,7 @@ mod type_alias;
3233
pub use block_number::BlockNumber;
3334
pub use block_range::{BlockRange, BlockRangeLength, BlockRangesSequence};
3435
pub use cardano_chain_point::{BlockHash, ChainPoint};
36+
pub use cardano_database::{ArtifactsLocations, CardanoDatabase};
3537
pub use cardano_db_beacon::CardanoDbBeacon;
3638
pub use cardano_network::CardanoNetwork;
3739
pub use cardano_stake_distribution::CardanoStakeDistribution;

0 commit comments

Comments
 (0)