mithril_aggregator/message_adapters/
from_epoch_settings.rs

1use anyhow::Context;
2use mithril_common::{
3    messages::{EpochSettingsMessage, SignerMessagePart, TryFromMessageAdapter},
4    StdResult,
5};
6
7use crate::entities::LeaderAggregatorEpochSettings;
8
9/// Adapter to convert [EpochSettingsMessage] to [LeaderAggregatorEpochSettings].
10pub struct FromEpochSettingsAdapter;
11
12impl TryFromMessageAdapter<EpochSettingsMessage, LeaderAggregatorEpochSettings>
13    for FromEpochSettingsAdapter
14{
15    /// Method to convert.
16    fn try_adapt(message: EpochSettingsMessage) -> StdResult<LeaderAggregatorEpochSettings> {
17        let epoch_settings = LeaderAggregatorEpochSettings {
18            epoch: message.epoch,
19            registration_protocol_parameters: message.signer_registration_protocol_parameters,
20            current_signers: SignerMessagePart::try_into_signers(message.current_signers)
21                .with_context(|| "'FromMessageAdapter' can not convert the current signers")?,
22            next_signers: SignerMessagePart::try_into_signers(message.next_signers)
23                .with_context(|| "'FromMessageAdapter' can not convert the next signers")?,
24            cardano_transactions_signing_config: message.cardano_transactions_signing_config,
25            next_cardano_transactions_signing_config: message
26                .next_cardano_transactions_signing_config,
27        };
28
29        Ok(epoch_settings)
30    }
31}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36
37    #[test]
38    fn try_adapt_epoch_settings_message_to_entity() {
39        let message = EpochSettingsMessage::dummy();
40        let epoch = message.epoch;
41        let epoch_settings = FromEpochSettingsAdapter::try_adapt(message).unwrap();
42
43        assert_eq!(epoch, epoch_settings.epoch);
44    }
45}