Skip to content

Commit

Permalink
Create SignedEntityType entity
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraynaud committed Mar 27, 2023
1 parent c85758d commit 84ae67c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mithril-common/src/entities/mod.rs
Expand Up @@ -10,6 +10,7 @@ mod epoch_settings;
mod http_server_error;
mod protocol_message;
mod protocol_parameters;
mod signed_entity_type;
mod signer;
mod single_signatures;
mod snapshot;
Expand All @@ -25,6 +26,7 @@ pub use epoch_settings::EpochSettings;
pub use http_server_error::{ClientError, InternalServerError};
pub use protocol_message::{ProtocolMessage, ProtocolMessagePartKey, ProtocolMessagePartValue};
pub use protocol_parameters::ProtocolParameters;
pub use signed_entity_type::SignedEntityType;
pub use signer::{Signer, SignerWithStake};
pub use single_signatures::SingleSignatures;
pub use snapshot::Snapshot;
Expand Down
44 changes: 44 additions & 0 deletions mithril-common/src/entities/signed_entity_type.rs
@@ -0,0 +1,44 @@
use strum::IntoEnumIterator;
use strum_macros::{Display, EnumIter, EnumString, FromRepr};

/// The signed entity type that represents a type of data signed by the Mithril protocol
/// Note: Each variant of this enum must be associated to an entry in the `signed_entity_type` tables of the signer/aggregator nodes.
/// The variant are identified by their discriminant (i.e. index in the enum), thus the modification of this type should only ever consist of appending new variants.
#[derive(Display, FromRepr, EnumString, EnumIter, Debug, Clone, Copy, PartialEq, Eq)]
#[strum(serialize_all = "PascalCase")]
pub enum SignedEntityType {
/// Mithril stake distribution
MithrilStakeDistribution,

/// Cardano Stake Distribution
CardanoStakeDistribution,

/// Full Cardano Immutable Files
CardanoImmutableFilesFull,
}

impl SignedEntityType {
/// Retrieve the list of entity types
pub fn entity_types() -> Vec<Self> {
Self::iter().collect()
}

/// Retrieve a dummy enty (for test only)
#[cfg(any(test, feature = "test_only"))]
pub fn dummy() -> Self {
Self::entity_types().first().unwrap().to_owned()
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn from_repr() {
let supported_entity_type = SignedEntityType::from_repr(SignedEntityType::dummy() as usize)
.expect("This signed entity type should support conversion from representation.");

assert_eq!(SignedEntityType::dummy(), supported_entity_type);
}
}

0 comments on commit 84ae67c

Please sign in to comment.