From 956db6bb240596c6b8eb16d2e62f99a7179033c0 Mon Sep 17 00:00:00 2001 From: Alexander Cyon Date: Tue, 27 Aug 2024 14:14:35 +0200 Subject: [PATCH] remove KeysCollectingClient --- src/derivation/collector/keys_collector.rs | 39 ++++++++++++++-- .../interactors/keys_collecting_client.rs | 46 ------------------- src/derivation/interactors/mod.rs | 2 - 3 files changed, 36 insertions(+), 51 deletions(-) delete mode 100644 src/derivation/interactors/keys_collecting_client.rs diff --git a/src/derivation/collector/keys_collector.rs b/src/derivation/collector/keys_collector.rs index f7c9ad8f..89456fc4 100644 --- a/src/derivation/collector/keys_collector.rs +++ b/src/derivation/collector/keys_collector.rs @@ -50,13 +50,46 @@ impl KeysCollector { self.dependencies.interactors.interactor_for(kind) } + async fn use_factor_sources( + &self, + interactor: KeyDerivationInteractor, + factor_sources: IndexSet, + ) -> Result<()> { + match interactor { + KeyDerivationInteractor::Parallel(interactor) => { + // Prepare the request for the interactor + let request = self.request_for_parallel_interactor( + factor_sources + .into_iter() + .map(|f| f.factor_source_id()) + .collect(), + )?; + let response = interactor.derive(request).await?; + self.process_batch_response(response)?; + } + + KeyDerivationInteractor::Serial(interactor) => { + for factor_source in factor_sources { + // Prepare the request for the interactor + let request = + self.request_for_serial_interactor(&factor_source.factor_source_id())?; + + // Produce the results from the interactor + let response = interactor.derive(request).await?; + + // Report the results back to the collector + self.process_batch_response(response)?; + } + } + } + Ok(()) + } + /// In decreasing "friction order" async fn derive_with_factors(&self) -> Result<()> { for factors_of_kind in self.dependencies.factors_of_kind.iter() { let interactor = self.get_interactor(factors_of_kind.kind); - let client = KeysCollectingClient::new(interactor); - client - .use_factor_sources(factors_of_kind.factor_sources(), self) + self.use_factor_sources(interactor, factors_of_kind.factor_sources()) .await?; } Ok(()) diff --git a/src/derivation/interactors/keys_collecting_client.rs b/src/derivation/interactors/keys_collecting_client.rs deleted file mode 100644 index 120114f2..00000000 --- a/src/derivation/interactors/keys_collecting_client.rs +++ /dev/null @@ -1,46 +0,0 @@ -use crate::prelude::*; - -pub struct KeysCollectingClient { - interactor: KeyDerivationInteractor, -} - -impl KeysCollectingClient { - pub fn new(interactor: KeyDerivationInteractor) -> Self { - Self { interactor } - } - - pub async fn use_factor_sources( - &self, - factor_sources: IndexSet, - collector: &KeysCollector, - ) -> Result<()> { - match &self.interactor { - KeyDerivationInteractor::Parallel(interactor) => { - // Prepare the request for the interactor - let request = collector.request_for_parallel_interactor( - factor_sources - .into_iter() - .map(|f| f.factor_source_id()) - .collect(), - )?; - let response = interactor.derive(request).await?; - collector.process_batch_response(response)?; - } - - KeyDerivationInteractor::Serial(interactor) => { - for factor_source in factor_sources { - // Prepare the request for the interactor - let request = collector - .request_for_serial_interactor(&factor_source.factor_source_id())?; - - // Produce the results from the interactor - let response = interactor.derive(request).await?; - - // Report the results back to the collector - collector.process_batch_response(response)?; - } - } - } - Ok(()) - } -} diff --git a/src/derivation/interactors/mod.rs b/src/derivation/interactors/mod.rs index b3ed387c..ad4aefa9 100644 --- a/src/derivation/interactors/mod.rs +++ b/src/derivation/interactors/mod.rs @@ -1,5 +1,3 @@ -mod keys_collecting_client; mod keys_collecting_interactors; -pub use keys_collecting_client::*; pub use keys_collecting_interactors::*;