Skip to content

Commit 8be8184

Browse files
committed
Create SignedEntityType entity
1 parent 235552d commit 8be8184

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

mithril-common/src/entities/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod epoch_settings;
1010
mod http_server_error;
1111
mod protocol_message;
1212
mod protocol_parameters;
13+
mod signed_entity_type;
1314
mod signer;
1415
mod single_signatures;
1516
mod snapshot;
@@ -25,6 +26,7 @@ pub use epoch_settings::EpochSettings;
2526
pub use http_server_error::{ClientError, InternalServerError};
2627
pub use protocol_message::{ProtocolMessage, ProtocolMessagePartKey, ProtocolMessagePartValue};
2728
pub use protocol_parameters::ProtocolParameters;
29+
pub use signed_entity_type::SignedEntityType;
2830
pub use signer::{Signer, SignerWithStake};
2931
pub use single_signatures::SingleSignatures;
3032
pub use snapshot::Snapshot;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

Comments
 (0)