diff --git a/mithril-signer/src/dependency_injection/builder.rs b/mithril-signer/src/dependency_injection/builder.rs index 110bbc2e7fa..d806df4b1c5 100644 --- a/mithril-signer/src/dependency_injection/builder.rs +++ b/mithril-signer/src/dependency_injection/builder.rs @@ -3,7 +3,6 @@ use std::sync::Arc; use std::time::Duration; use anyhow::{anyhow, Context}; -use async_trait::async_trait; use tokio::sync::Mutex; use mithril_common::api_version::APIVersionProvider; @@ -50,22 +49,15 @@ use crate::{ /// The `DependenciesBuilder` is intended to manage Services instance creation. /// /// The goal of this is to put all this code out of the way of business code. -#[async_trait] -pub trait DependenciesBuilder { - /// Create a SignerService instance. - async fn build(&self) -> StdResult; -} - -/// A `DependenciesBuilder` for Production environment. -pub struct ProductionDependenciesBuilder<'a> { +pub struct DependenciesBuilder<'a> { config: &'a Configuration, chain_observer_builder: fn(&Configuration) -> StdResult>, immutable_file_observer_builder: fn(&Configuration) -> StdResult>, } -impl<'a> ProductionDependenciesBuilder<'a> { - /// Create a new `ProductionDependenciesBuilder`. +impl<'a> DependenciesBuilder<'a> { + /// Create a new `DependenciesBuilder`. pub fn new(config: &'a Configuration) -> Self { let chain_observer_builder: fn(&Configuration) -> StdResult> = |config: &Configuration| { @@ -73,7 +65,7 @@ impl<'a> ProductionDependenciesBuilder<'a> { let cardano_cli_path = &config.cardano_cli_path; let cardano_node_socket_path = &config.cardano_node_socket_path; let cardano_network = &config.get_network().with_context(|| { - "Production Dependencies Builder can not get Cardano network while building the chain observer" + "Dependencies Builder can not get Cardano network while building the chain observer" })?; let cardano_cli_runner = &CardanoCliRunner::new( cardano_cli_path.to_owned(), @@ -183,12 +175,9 @@ impl<'a> ProductionDependenciesBuilder<'a> { Ok(connection) } -} -#[async_trait] -impl<'a> DependenciesBuilder for ProductionDependenciesBuilder<'a> { /// Build dependencies for the Production environment. - async fn build(&self) -> StdResult { + pub async fn build(&self) -> StdResult { if !self.config.data_stores_directory.exists() { fs::create_dir_all(self.config.data_stores_directory.clone()).with_context(|| { format!( @@ -404,7 +393,7 @@ mod tests { -> StdResult> = |_config: &Configuration| Ok(Arc::new(DumbImmutableFileObserver::default())); - let mut dependencies_builder = ProductionDependenciesBuilder::new(&config); + let mut dependencies_builder = DependenciesBuilder::new(&config); dependencies_builder .override_chain_observer_builder(chain_observer_builder) .override_immutable_file_observer_builder(immutable_file_observer_builder) diff --git a/mithril-signer/src/main.rs b/mithril-signer/src/main.rs index 9652b5efe55..cdd0b151ba4 100644 --- a/mithril-signer/src/main.rs +++ b/mithril-signer/src/main.rs @@ -15,7 +15,7 @@ use tokio::{ use mithril_common::StdResult; use mithril_doc::{Documenter, DocumenterDefault, GenerateDocCommands, StructDoc}; -use mithril_signer::dependency_injection::{DependenciesBuilder, ProductionDependenciesBuilder}; +use mithril_signer::dependency_injection::DependenciesBuilder; use mithril_signer::{ Configuration, DefaultConfiguration, MetricsServer, SignerRunner, SignerState, StateMachine, }; @@ -158,7 +158,7 @@ async fn main() -> StdResult<()> { .try_deserialize() .with_context(|| "configuration deserialize error")?; - let services = ProductionDependenciesBuilder::new(&config) + let services = DependenciesBuilder::new(&config) .build() .await .with_context(|| "services initialization error")?; diff --git a/mithril-signer/tests/test_extensions/state_machine_tester.rs b/mithril-signer/tests/test_extensions/state_machine_tester.rs index b52bf0eb96d..80475ab9186 100644 --- a/mithril-signer/tests/test_extensions/state_machine_tester.rs +++ b/mithril-signer/tests/test_extensions/state_machine_tester.rs @@ -34,7 +34,7 @@ use mithril_persistence::{ store::{StakeStore, StakeStorer}, }; use mithril_signer::{ - dependency_injection::{ProductionDependenciesBuilder, SignerDependencyContainer}, + dependency_injection::{DependenciesBuilder, SignerDependencyContainer}, metrics::*, services::{ AggregatorClient, CardanoTransactionsImporter, MithrilSingleSigner, SignerUpkeepService, @@ -97,7 +97,7 @@ impl StateMachineTester { let selected_signer_party_id = selected_signer_with_stake.party_id.clone(); let config = Configuration::new_sample(&selected_signer_party_id); - let production_dependencies_builder = ProductionDependenciesBuilder::new(&config); + let production_dependencies_builder = DependenciesBuilder::new(&config); let sqlite_connection = Arc::new( production_dependencies_builder .build_sqlite_connection(