aboutsummaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
authornecrashter2022-04-23 13:55:48 +0300
committerYigit Sever2022-04-23 18:10:12 +0300
commit0d2611a08449c8596faccf5f8e385980f571bf2d (patch)
tree89a7ee9d66b16594b42b99d2ea405973312f3225 /src/config.rs
parent052d0a0fd2c6cf6b5cdc965a812ad22238d402e8 (diff)
downloadgradecoin-0d2611a08449c8596faccf5f8e385980f571bf2d.tar.gz
gradecoin-0d2611a08449c8596faccf5f8e385980f571bf2d.tar.bz2
gradecoin-0d2611a08449c8596faccf5f8e385980f571bf2d.zip
Implement the ability to read config from yaml
Diffstat (limited to 'src/config.rs')
-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}