Skip to main content

miden_node_store/
data_directory.rs

1use std::ops::Not;
2use std::path::PathBuf;
3
4use miden_node_tracing::RecordAttribute;
5
6/// Represents the store's data-directory and its content paths.
7///
8/// Used to keep our filepath assumptions in one location.
9#[derive(Clone)]
10pub struct DataDirectory(PathBuf);
11
12impl DataDirectory {
13    /// Creates a new [`DataDirectory`], ensuring that the directory exists and is accessible
14    /// insofar as is possible.
15    pub fn load(path: PathBuf) -> std::io::Result<Self> {
16        let meta = fs_err::metadata(&path)?;
17        if meta.is_dir().not() {
18            return Err(std::io::ErrorKind::NotConnected.into());
19        }
20
21        Ok(Self(path))
22    }
23
24    pub fn block_store_dir(&self) -> PathBuf {
25        self.0.join("blocks")
26    }
27
28    pub fn database_path(&self) -> PathBuf {
29        self.0.join("miden-store.sqlite3")
30    }
31
32    pub fn allowlist_database_path(&self) -> PathBuf {
33        self.0.join("miden-allowlist.sqlite3")
34    }
35
36    pub fn fee_collector_account_path(&self) -> PathBuf {
37        self.0.join("fee-collector.mac")
38    }
39
40    pub fn display(&self) -> std::path::Display<'_> {
41        self.0.display()
42    }
43}
44
45impl RecordAttribute for DataDirectory {
46    const FIELD_NAMES: &'static [&'static str] = &["data.directory", "path"];
47
48    fn record_attribute(&self) -> impl miden_node_tracing::Value + '_ {
49        miden_node_tracing::field::display(self.display())
50    }
51}