solana_oasis_node/
config.rs

1use libp2p::identity::Keypair;
2use std::fmt;
3
4#[derive(Clone)]
5pub struct NetworkConfig {
6    pub identity: Keypair,
7    pub listen_addresses: Vec<String>,
8    pub bootstrap_peers: Vec<String>,
9    pub state_db_path: String,
10}
11
12impl fmt::Debug for NetworkConfig {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        f.debug_struct("NetworkConfig")
15            .field("listen_addresses", &self.listen_addresses)
16            .field("bootstrap_peers", &self.bootstrap_peers)
17            .field("state_db_path", &self.state_db_path)
18            .field("identity", &"<keypair>")
19            .finish()
20    }
21}
22
23impl NetworkConfig {
24    pub fn new(
25        identity: Keypair,
26        listen_addresses: Vec<String>,
27        bootstrap_peers: Vec<String>,
28        state_db_path: String,
29    ) -> Self {
30        Self {
31            identity,
32            listen_addresses,
33            bootstrap_peers,
34            state_db_path,
35        }
36    }
37}
38
39#[cfg(test)]
40mod tests {
41    use super::*;
42    use libp2p::identity;
43
44    #[test]
45    fn test_network_config() {
46        let config = NetworkConfig::new(
47            identity::Keypair::generate_ed25519(),
48            vec!["/ip4/127.0.0.1/tcp/0".to_string()],
49            vec![],
50            "test_db".to_string(),
51        );
52
53        assert_eq!(config.listen_addresses.len(), 1);
54        assert_eq!(config.bootstrap_peers.len(), 0);
55        assert_eq!(config.state_db_path, "test_db");
56    }
57}