From 4364de59a2d73798410b3779b7e973a54e45f288 Mon Sep 17 00:00:00 2001 From: necrashter Date: Sat, 23 Apr 2022 13:56:31 +0300 Subject: Read from config file at start-up --- src/db.rs | 11 ++--------- src/main.rs | 11 ++++++++++- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/db.rs b/src/db.rs index 85d43a0..98aa984 100644 --- a/src/db.rs +++ b/src/db.rs @@ -27,7 +27,7 @@ pub struct Db { } impl Db { - pub fn new() -> Self { + pub fn new(config: Config) -> Self { fs::create_dir_all("blocks").unwrap(); fs::create_dir_all("users").unwrap(); let mut db = Db::default(); @@ -46,14 +46,7 @@ impl Db { blockchain: Arc::new(RwLock::new(Block::default())), pending_transactions: Arc::new(RwLock::new(HashMap::new())), users: Arc::new(RwLock::new(users)), - config: Config { - block_transaction_count: 4, - register_bonus: 100, - block_reward: 4, - tx_upper_limit: 4, - tx_lower_limit: 1, - tx_traffic_reward: 1, - }, + config, preapproved_users, } } 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}; use db::Db; use lazy_static::lazy_static; use std::fs; +use crate::config::Config; #[tokio::main] async fn main() { log4rs::init_file("log.conf.yml", log4rs::config::Deserializers::default()).unwrap(); - let api = routes::application(Db::new()); + let config = match Config::read("config.yaml") { + Some(c) => c, + None => { + println!("Could not read config file, exiting."); + return; + }, + }; + + let api = routes::application(Db::new(config)); // Start the server let point = ([127, 0, 0, 1], 8080); -- cgit v1.2.3-70-g09d2