mithril_aggregator/dependency_injection/builder/enablers/
epoch.rs1use std::sync::Arc;
2use tokio::sync::RwLock;
3
4use crate::dependency_injection::{DependenciesBuilder, EpochServiceWrapper, Result};
5use crate::services::{EpochServiceDependencies, MithrilEpochService};
6
7impl DependenciesBuilder {
8 async fn build_epoch_service(&mut self) -> Result<EpochServiceWrapper> {
9 let verification_key_store = self.get_verification_key_store().await?;
10 let epoch_settings_storer = self.get_epoch_settings_store().await?;
11 let chain_observer = self.get_chain_observer().await?;
12 let era_checker = self.get_era_checker().await?;
13 let stake_store = self.get_stake_store().await?;
14 let epoch_settings = self.configuration.get_epoch_settings_configuration();
15 let allowed_discriminants = self
16 .configuration
17 .compute_allowed_signed_entity_types_discriminants()?;
18
19 let epoch_service = Arc::new(RwLock::new(MithrilEpochService::new(
20 epoch_settings,
21 EpochServiceDependencies::new(
22 epoch_settings_storer,
23 verification_key_store,
24 chain_observer,
25 era_checker,
26 stake_store,
27 ),
28 allowed_discriminants,
29 self.root_logger(),
30 )));
31
32 Ok(epoch_service)
33 }
34
35 pub async fn get_epoch_service(&mut self) -> Result<EpochServiceWrapper> {
37 if self.epoch_service.is_none() {
38 self.epoch_service = Some(self.build_epoch_service().await?);
39 }
40
41 Ok(self.epoch_service.as_ref().cloned().unwrap())
42 }
43}