diff options
author | necrashter | 2022-04-23 13:56:31 +0300 |
---|---|---|
committer | Yigit Sever | 2022-04-23 18:10:12 +0300 |
commit | 4364de59a2d73798410b3779b7e973a54e45f288 (patch) | |
tree | 853ef7a1731581151143db7476e00dfc65b91365 /src | |
parent | 0d2611a08449c8596faccf5f8e385980f571bf2d (diff) | |
download | gradecoin-4364de59a2d73798410b3779b7e973a54e45f288.tar.gz gradecoin-4364de59a2d73798410b3779b7e973a54e45f288.tar.bz2 gradecoin-4364de59a2d73798410b3779b7e973a54e45f288.zip |
Read from config file at start-up
Diffstat (limited to 'src')
-rw-r--r-- | src/db.rs | 11 | ||||
-rw-r--r-- | src/main.rs | 11 |
2 files changed, 12 insertions, 10 deletions
@@ -27,7 +27,7 @@ pub struct Db { | |||
27 | } | 27 | } |
28 | 28 | ||
29 | impl Db { | 29 | impl Db { |
30 | pub fn new() -> Self { | 30 | pub fn new(config: Config) -> Self { |
31 | fs::create_dir_all("blocks").unwrap(); | 31 | fs::create_dir_all("blocks").unwrap(); |
32 | fs::create_dir_all("users").unwrap(); | 32 | fs::create_dir_all("users").unwrap(); |
33 | let mut db = Db::default(); | 33 | let mut db = Db::default(); |
@@ -46,14 +46,7 @@ impl Db { | |||
46 | blockchain: Arc::new(RwLock::new(Block::default())), | 46 | blockchain: Arc::new(RwLock::new(Block::default())), |
47 | pending_transactions: Arc::new(RwLock::new(HashMap::new())), | 47 | pending_transactions: Arc::new(RwLock::new(HashMap::new())), |
48 | users: Arc::new(RwLock::new(users)), | 48 | users: Arc::new(RwLock::new(users)), |
49 | config: Config { | 49 | config, |
50 | block_transaction_count: 4, | ||
51 | register_bonus: 100, | ||
52 | block_reward: 4, | ||
53 | tx_upper_limit: 4, | ||
54 | tx_lower_limit: 1, | ||
55 | tx_traffic_reward: 1, | ||
56 | }, | ||
57 | preapproved_users, | 50 | preapproved_users, |
58 | } | 51 | } |
59 | } | 52 | } |
diff --git a/src/main.rs b/src/main.rs index 57ee526..6edd67c 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -35,12 +35,21 @@ pub use block::{Fingerprint, Id}; | |||
35 | use db::Db; | 35 | use db::Db; |
36 | use lazy_static::lazy_static; | 36 | use lazy_static::lazy_static; |
37 | use std::fs; | 37 | use std::fs; |
38 | use crate::config::Config; | ||
38 | 39 | ||
39 | #[tokio::main] | 40 | #[tokio::main] |
40 | async fn main() { | 41 | async fn main() { |
41 | log4rs::init_file("log.conf.yml", log4rs::config::Deserializers::default()).unwrap(); | 42 | log4rs::init_file("log.conf.yml", log4rs::config::Deserializers::default()).unwrap(); |
42 | 43 | ||
43 | let api = routes::application(Db::new()); | 44 | let config = match Config::read("config.yaml") { |
45 | Some(c) => c, | ||
46 | None => { | ||
47 | println!("Could not read config file, exiting."); | ||
48 | return; | ||
49 | }, | ||
50 | }; | ||
51 | |||
52 | let api = routes::application(Db::new(config)); | ||
44 | 53 | ||
45 | // Start the server | 54 | // Start the server |
46 | let point = ([127, 0, 0, 1], 8080); | 55 | let point = ([127, 0, 0, 1], 8080); |