From 435cda893bd74bd8e597876f4b5f515c8347f9de Mon Sep 17 00:00:00 2001 From: necrashter Date: Sat, 23 Apr 2022 15:59:29 +0300 Subject: Read preapproved users CSV file from config --- src/config.rs | 2 ++ src/db.rs | 10 ++++------ 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index e6f5e0e..9fb268b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,6 +11,8 @@ pub struct Config { pub name: String, // URL prefix for this network, can be empty pub url_prefix: String, + // CSV file that contains the list of users who can register + pub preapproved_users: String, // Valid blocks should have this many transactions pub block_transaction_count: u8, // Inital registration bonus diff --git a/src/db.rs b/src/db.rs index e7fb137..2187010 100644 --- a/src/db.rs +++ b/src/db.rs @@ -15,8 +15,6 @@ use log::debug; use parking_lot::RwLock; use std::{collections::HashMap, fs, io, path::PathBuf, sync::Arc}; -const PREAPPROVED_STU_FILENAME: &str = "students.csv"; - #[derive(Debug, Clone, Default)] pub struct Db { pub blockchain: Arc>, @@ -35,7 +33,7 @@ impl Db { let users: HashMap = get_friendly_users(); // Read the list of users who can register - let preapproved_users = read_approved_users(); + let preapproved_users = read_approved_users(&config.preapproved_users); let mut db = Db { blockchain: Arc::new(RwLock::new(Block::default())), @@ -184,14 +182,14 @@ fn get_friendly_users() -> HashMap { users } -fn read_approved_users() -> Vec { +fn read_approved_users(filename: &str) -> Vec { let mut approved_students: Vec = Vec::new(); - let contents = fs::read_to_string(PREAPPROVED_STU_FILENAME).unwrap_or_else(|_| { + let contents = fs::read_to_string(filename).unwrap_or_else(|_| { panic!( "{}", format!( "Expected {} in place to load preapproved students", - PREAPPROVED_STU_FILENAME + filename ) ) }); -- cgit v1.2.3-70-g09d2