Skip to content

Commit fb6ee10

Browse files
authored
Merge pull request #831 from input-output-hk/jpraynaud/815-create-signed-entity-type-table
Create `signed_entity_type` store
2 parents 1dd289b + 5f997aa commit fb6ee10

File tree

5 files changed

+63
-2
lines changed

5 files changed

+63
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-aggregator/src/database/migration.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ insert into epoch_setting (epoch_setting_id, protocol_parameters)
5050
from protocol_parameters
5151
order by key asc;
5252
drop table protocol_parameters;
53+
"#,
54+
),
55+
// Migration 3
56+
// Add the `signed_entity_type` table and insert first types
57+
SqlMigration::new(
58+
3,
59+
r#"
60+
create table signed_entity_type (
61+
signed_entity_type_id integer not null,
62+
name text not null,
63+
primary key (signed_entity_type_id)
64+
);
65+
insert into signed_entity_type (signed_entity_type_id, name)
66+
values (0, 'Mithril Stake Distribution'),
67+
(1, 'Cardano Stake Distribution'),
68+
(2, 'Full Cardano Immutable Files');
5369
"#,
5470
),
5571
]

mithril-common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-common"
3-
version = "0.2.34"
3+
version = "0.2.35"
44
authors = { workspace = true }
55
edition = { workspace = true }
66
documentation = { workspace = true }

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)