aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
index 80d2def..10c054c 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -2,6 +2,7 @@
2//! 2//!
3//! This module holds the data structures for network configuration. 3//! This module holds the data structures for network configuration.
4use serde::{Deserialize, Serialize}; 4use serde::{Deserialize, Serialize};
5use log::{error, info};
5 6
6/// Configuration for a single network 7/// Configuration for a single network
7#[derive(Debug, Serialize, Deserialize, Clone, Default)] 8#[derive(Debug, Serialize, Deserialize, Clone, Default)]
@@ -18,3 +19,27 @@ pub struct Config {
18 // Transaction traffic reward 19 // Transaction traffic reward
19 pub tx_traffic_reward: u16, 20 pub tx_traffic_reward: u16,
20} 21}
22
23impl Config {
24 pub fn read(filename: &str) -> Option<Self> {
25 let file = match std::fs::File::open(filename) {
26 Ok(f) => f,
27 Err(e) => {
28 error!("Cannot read config file: {}", filename);
29 error!("Error: {:?}", e);
30 return None;
31 },
32 };
33 let config : Config = match serde_yaml::from_reader(file) {
34 Ok(c) => c,
35 Err(e) => {
36 error!("Cannot parse config file: {}", filename);
37 error!("Error: {:?}", e);
38 return None;
39 },
40 };
41 // File closes automatically when it goes out of scope.
42 info!("Config file read successfully: {}", filename);
43 Some(config)
44 }
45}