Skip to content

Commit

Permalink
Rename ProductionDependenciesBuilder to DependenciesBuilder
Browse files Browse the repository at this point in the history
And remove the trait of the same name.

The idea behind the `DependenciesBuilder` trait was to define a common
api to build dependencies, but two years after its introduction it only
have one implementor.
  • Loading branch information
Alenar committed Aug 29, 2024
1 parent a96b950 commit c9abaa5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
23 changes: 6 additions & 17 deletions mithril-signer/src/dependency_injection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,30 +49,23 @@ 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<SignerDependencyContainer>;
}

/// A `DependenciesBuilder` for Production environment.
pub struct ProductionDependenciesBuilder<'a> {
pub struct DependenciesBuilder<'a> {
config: &'a Configuration,
chain_observer_builder: fn(&Configuration) -> StdResult<Arc<dyn ChainObserver>>,
immutable_file_observer_builder:
fn(&Configuration) -> StdResult<Arc<dyn ImmutableFileObserver>>,
}

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<Arc<dyn ChainObserver>> =
|config: &Configuration| {
let chain_observer_type = ChainObserverType::Pallas;
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(),
Expand Down Expand Up @@ -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<SignerDependencyContainer> {
pub async fn build(&self) -> StdResult<SignerDependencyContainer> {
if !self.config.data_stores_directory.exists() {
fs::create_dir_all(self.config.data_stores_directory.clone()).with_context(|| {
format!(
Expand Down Expand Up @@ -404,7 +393,7 @@ mod tests {
-> StdResult<Arc<dyn ImmutableFileObserver>> =
|_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)
Expand Down
4 changes: 2 additions & 2 deletions mithril-signer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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")?;
Expand Down
4 changes: 2 additions & 2 deletions mithril-signer/tests/test_extensions/state_machine_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit c9abaa5

Please sign in to comment.