Skip to main content

miden_validator/
data_directory.rs

1use std::ops::Not;
2use std::path::PathBuf;
3
4/// Represents the validator's data directory and its content paths.
5///
6/// Used to keep our filepath assumptions in one location.
7#[derive(Clone)]
8pub struct DataDirectory {
9    data: PathBuf,
10}
11
12impl DataDirectory {
13    /// Loads the data directory, verifying that it exists.
14    pub fn load(data: PathBuf) -> std::io::Result<Self> {
15        if fs_err::metadata(&data)?.is_dir().not() {
16            return Err(std::io::ErrorKind::NotConnected.into());
17        }
18        Ok(Self { data })
19    }
20
21    pub fn database_path(&self) -> PathBuf {
22        self.data.join("validator.sqlite3")
23    }
24
25    pub fn block_store_dir(&self) -> PathBuf {
26        self.data.join("blocks")
27    }
28
29    pub fn display(&self) -> std::path::Display<'_> {
30        self.data.display()
31    }
32}