miden_node_store/
config.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::{
    fmt::{Display, Formatter},
    path::PathBuf,
};

use miden_node_utils::config::{Endpoint, DEFAULT_STORE_PORT};
use serde::{Deserialize, Serialize};

// Main config
// ================================================================================================

#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct StoreConfig {
    /// Defines the listening socket.
    pub endpoint: Endpoint,
    /// `SQLite` database file
    pub database_filepath: PathBuf,
    /// Genesis file
    pub genesis_filepath: PathBuf,
    /// Block store directory
    pub blockstore_dir: PathBuf,
}

impl StoreConfig {
    pub fn endpoint_url(&self) -> String {
        self.endpoint.to_string()
    }
}

impl Display for StoreConfig {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_fmt(format_args!(
            "{{ endpoint: \"{}\",  database_filepath: {:?}, genesis_filepath: {:?}, blockstore_dir: {:?} }}",
            self.endpoint, self.database_filepath, self.genesis_filepath, self.blockstore_dir
        ))
    }
}

impl Default for StoreConfig {
    fn default() -> Self {
        const NODE_STORE_DIR: &str = "./";
        Self {
            endpoint: Endpoint::localhost(DEFAULT_STORE_PORT),
            database_filepath: PathBuf::from(NODE_STORE_DIR.to_string() + "miden-store.sqlite3"),
            genesis_filepath: PathBuf::from(NODE_STORE_DIR.to_string() + "genesis.dat"),
            blockstore_dir: PathBuf::from(NODE_STORE_DIR.to_string() + "blocks"),
        }
    }
}