|
| 1 | +use strum::IntoEnumIterator; |
| 2 | +use strum_macros::{Display, EnumIter, EnumString, FromRepr}; |
| 3 | + |
| 4 | +/// The signed entity type that represents a type of data signed by the Mithril protocol |
| 5 | +/// Note: Each variant of this enum must be associated to an entry in the `signed_entity_type` tables of the signer/aggregator nodes. |
| 6 | +/// 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. |
| 7 | +#[derive(Display, FromRepr, EnumString, EnumIter, Debug, Clone, Copy, PartialEq, Eq)] |
| 8 | +#[strum(serialize_all = "PascalCase")] |
| 9 | +pub enum SignedEntityType { |
| 10 | + /// Mithril stake distribution |
| 11 | + MithrilStakeDistribution, |
| 12 | + |
| 13 | + /// Cardano Stake Distribution |
| 14 | + CardanoStakeDistribution, |
| 15 | + |
| 16 | + /// Full Cardano Immutable Files |
| 17 | + CardanoImmutableFilesFull, |
| 18 | +} |
| 19 | + |
| 20 | +impl SignedEntityType { |
| 21 | + /// Retrieve the list of entity types |
| 22 | + pub fn entity_types() -> Vec<Self> { |
| 23 | + Self::iter().collect() |
| 24 | + } |
| 25 | + |
| 26 | + /// Retrieve a dummy enty (for test only) |
| 27 | + pub fn dummy() -> Self { |
| 28 | + Self::entity_types().first().unwrap().to_owned() |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +#[cfg(test)] |
| 33 | +mod tests { |
| 34 | + use super::*; |
| 35 | + |
| 36 | + #[test] |
| 37 | + fn from_repr() { |
| 38 | + let supported_entity_type = SignedEntityType::from_repr(SignedEntityType::dummy() as usize) |
| 39 | + .expect("This signed entity type should support conversion from representation."); |
| 40 | + |
| 41 | + assert_eq!(SignedEntityType::dummy(), supported_entity_type); |
| 42 | + } |
| 43 | +} |
0 commit comments