Skip to content

Commit b582cc0

Browse files
committed
refactor(client): wire temporary folder provider in the client builder
1 parent 0aeeb07 commit b582cc0

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

mithril-client/src/cardano_database_client/api.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::feedback::FeedbackSender;
2222
#[cfg(feature = "fs")]
2323
use crate::file_downloader::FileDownloader;
2424
#[cfg(feature = "fs")]
25-
use crate::utils::AncillaryVerifier;
25+
use crate::utils::{AncillaryVerifier, TempDirectoryProvider};
2626
use crate::{CardanoDatabaseSnapshot, CardanoDatabaseSnapshotListItem, MithrilResult};
2727

2828
use super::fetch::InternalArtifactRetriever;
@@ -50,6 +50,7 @@ impl CardanoDatabaseClient {
5050
#[cfg(feature = "fs")] http_file_downloader: Arc<dyn FileDownloader>,
5151
#[cfg(feature = "fs")] ancillary_verifier: Option<Arc<AncillaryVerifier>>,
5252
#[cfg(feature = "fs")] feedback_sender: FeedbackSender,
53+
#[cfg(feature = "fs")] temp_directory_provider: Arc<dyn TempDirectoryProvider>,
5354
#[cfg(feature = "fs")] logger: Logger,
5455
) -> Self {
5556
#[cfg(feature = "fs")]
@@ -67,6 +68,7 @@ impl CardanoDatabaseClient {
6768
#[cfg(feature = "fs")]
6869
artifact_prover: InternalArtifactProver::new(
6970
http_file_downloader.clone(),
71+
temp_directory_provider.clone(),
7072
logger.clone(),
7173
),
7274
statistics_sender: InternalStatisticsSender::new(aggregator_client.clone()),
@@ -172,6 +174,8 @@ pub(crate) mod test_dependency_injector {
172174
#[cfg(feature = "fs")]
173175
use crate::file_downloader::{FileDownloader, MockFileDownloaderBuilder};
174176
#[cfg(feature = "fs")]
177+
use crate::utils::TimestampTempDirectoryProvider;
178+
#[cfg(feature = "fs")]
175179
use crate::{feedback::FeedbackReceiver, test_utils::TestLogger};
176180

177181
/// Dependency injector for `CardanoDatabaseClient` for testing purposes.
@@ -184,6 +188,8 @@ pub(crate) mod test_dependency_injector {
184188
#[cfg(feature = "fs")]
185189
feedback_receivers: Vec<Arc<dyn FeedbackReceiver>>,
186190
#[cfg(feature = "fs")]
191+
temp_directory_provider: Arc<dyn TempDirectoryProvider>,
192+
#[cfg(feature = "fs")]
187193
logger: Logger,
188194
}
189195

@@ -204,6 +210,10 @@ pub(crate) mod test_dependency_injector {
204210
#[cfg(feature = "fs")]
205211
feedback_receivers: vec![],
206212
#[cfg(feature = "fs")]
213+
temp_directory_provider: Arc::new(TimestampTempDirectoryProvider::new(
214+
"cardano_database_client_test",
215+
)),
216+
#[cfg(feature = "fs")]
207217
logger: TestLogger::stdout(),
208218
}
209219
}
@@ -259,13 +269,25 @@ pub(crate) mod test_dependency_injector {
259269
}
260270
}
261271

272+
#[cfg(feature = "fs")]
273+
pub(crate) fn with_temp_directory_provider(
274+
self,
275+
temp_directory_provider: Arc<dyn TempDirectoryProvider>,
276+
) -> Self {
277+
Self {
278+
temp_directory_provider,
279+
..self
280+
}
281+
}
282+
262283
#[cfg(feature = "fs")]
263284
pub(crate) fn build_cardano_database_client(self) -> CardanoDatabaseClient {
264285
CardanoDatabaseClient::new(
265286
Arc::new(self.aggregator_client),
266287
self.http_file_downloader,
267288
self.ancillary_verifier,
268289
FeedbackSender::new(&self.feedback_receivers),
290+
self.temp_directory_provider,
269291
self.logger,
270292
)
271293
}

mithril-client/src/client.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use anyhow::{Context, anyhow};
2+
#[cfg(feature = "fs")]
3+
use chrono::Utc;
24
use reqwest::Url;
35
use serde::{Deserialize, Serialize};
46
use slog::{Logger, o};
@@ -28,6 +30,8 @@ use crate::mithril_stake_distribution_client::MithrilStakeDistributionClient;
2830
use crate::snapshot_client::SnapshotClient;
2931
#[cfg(feature = "fs")]
3032
use crate::utils::AncillaryVerifier;
33+
#[cfg(feature = "fs")]
34+
use crate::utils::TimestampTempDirectoryProvider;
3135

3236
const DEFAULT_CLIENT_TYPE: &str = "LIBRARY";
3337

@@ -312,6 +316,11 @@ impl ClientBuilder {
312316
#[cfg(feature = "fs")]
313317
feedback_sender,
314318
#[cfg(feature = "fs")]
319+
Arc::new(TimestampTempDirectoryProvider::new(&format!(
320+
"{}",
321+
Utc::now().timestamp_micros()
322+
))),
323+
#[cfg(feature = "fs")]
315324
logger,
316325
));
317326

0 commit comments

Comments
 (0)