aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornecrashter2022-04-23 15:59:29 +0300
committerYigit Sever2022-04-23 18:10:12 +0300
commit435cda893bd74bd8e597876f4b5f515c8347f9de (patch)
treec3939c359d934e78548ad49bbb3290ab8a53530e /src
parentbcf7a379620ca433215ad9617ad9417b4f39e87d (diff)
downloadgradecoin-435cda893bd74bd8e597876f4b5f515c8347f9de.tar.gz
gradecoin-435cda893bd74bd8e597876f4b5f515c8347f9de.tar.bz2
gradecoin-435cda893bd74bd8e597876f4b5f515c8347f9de.zip
Read preapproved users CSV file from config
Diffstat (limited to 'src')
-rw-r--r--src/config.rs2
-rw-r--r--src/db.rs10
2 files changed, 6 insertions, 6 deletions
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 {
11 pub name: String, 11 pub name: String,
12 // URL prefix for this network, can be empty 12 // URL prefix for this network, can be empty
13 pub url_prefix: String, 13 pub url_prefix: String,
14 // CSV file that contains the list of users who can register
15 pub preapproved_users: String,
14 // Valid blocks should have this many transactions 16 // Valid blocks should have this many transactions
15 pub block_transaction_count: u8, 17 pub block_transaction_count: u8,
16 // Inital registration bonus 18 // 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;
15use parking_lot::RwLock; 15use parking_lot::RwLock;
16use std::{collections::HashMap, fs, io, path::PathBuf, sync::Arc}; 16use std::{collections::HashMap, fs, io, path::PathBuf, sync::Arc};
17 17
18const PREAPPROVED_STU_FILENAME: &str = "students.csv";
19
20#[derive(Debug, Clone, Default)] 18#[derive(Debug, Clone, Default)]
21pub struct Db { 19pub struct Db {
22 pub blockchain: Arc<RwLock<Block>>, 20 pub blockchain: Arc<RwLock<Block>>,
@@ -35,7 +33,7 @@ impl Db {
35 let users: HashMap<Fingerprint, User> = get_friendly_users(); 33 let users: HashMap<Fingerprint, User> = get_friendly_users();
36 34
37 // Read the list of users who can register 35 // Read the list of users who can register
38 let preapproved_users = read_approved_users(); 36 let preapproved_users = read_approved_users(&config.preapproved_users);
39 37
40 let mut db = Db { 38 let mut db = Db {
41 blockchain: Arc::new(RwLock::new(Block::default())), 39 blockchain: Arc::new(RwLock::new(Block::default())),
@@ -184,14 +182,14 @@ fn get_friendly_users() -> HashMap<Fingerprint, User> {
184 users 182 users
185} 183}
186 184
187fn read_approved_users() -> Vec<MetuId> { 185fn read_approved_users(filename: &str) -> Vec<MetuId> {
188 let mut approved_students: Vec<MetuId> = Vec::new(); 186 let mut approved_students: Vec<MetuId> = Vec::new();
189 let contents = fs::read_to_string(PREAPPROVED_STU_FILENAME).unwrap_or_else(|_| { 187 let contents = fs::read_to_string(filename).unwrap_or_else(|_| {
190 panic!( 188 panic!(
191 "{}", 189 "{}",
192 format!( 190 format!(
193 "Expected {} in place to load preapproved students", 191 "Expected {} in place to load preapproved students",
194 PREAPPROVED_STU_FILENAME 192 filename
195 ) 193 )
196 ) 194 )
197 }); 195 });