sequencer/api/
fs.rs

1use std::path::Path;
2
3use async_trait::async_trait;
4use hotshot_query_service::data_source::FileSystemDataSource;
5
6use super::data_source::{Provider, SequencerDataSource};
7use crate::{catchup::CatchupStorage, persistence::fs::Options, SeqTypes};
8
9pub type DataSource = FileSystemDataSource<SeqTypes, Provider>;
10
11#[async_trait]
12impl SequencerDataSource for DataSource {
13    type Options = Options;
14
15    async fn create(opt: Self::Options, provider: Provider, reset: bool) -> anyhow::Result<Self> {
16        let path = Path::new(opt.path());
17        let data_source = {
18            if reset {
19                FileSystemDataSource::create(path, provider).await?
20            } else {
21                FileSystemDataSource::open(path, provider).await?
22            }
23        };
24
25        Ok(data_source)
26    }
27}
28
29impl CatchupStorage for DataSource {}
30
31#[cfg(test)]
32mod impl_testable_data_source {
33    use tempfile::TempDir;
34
35    use super::*;
36    use crate::api::{self, data_source::testing::TestableSequencerDataSource};
37
38    #[async_trait]
39    impl TestableSequencerDataSource for DataSource {
40        type Storage = TempDir;
41
42        async fn create_storage() -> Self::Storage {
43            TempDir::new().unwrap()
44        }
45
46        fn persistence_options(storage: &Self::Storage) -> Self::Options {
47            Options::new(storage.path().into())
48        }
49
50        fn options(storage: &Self::Storage, opt: api::Options) -> api::Options {
51            opt.query_fs(Default::default(), Options::new(storage.path().into()))
52        }
53    }
54}