diff options
| -rw-r--r-- | config.yaml | 4 | ||||
| -rw-r--r-- | src/config.rs | 2 | ||||
| -rw-r--r-- | src/db.rs | 10 | 
3 files changed, 10 insertions, 6 deletions
diff --git a/config.yaml b/config.yaml index b60691a..caac122 100644 --- a/config.yaml +++ b/config.yaml  | |||
| @@ -3,6 +3,10 @@ name: mainnet | |||
| 3 | # URL Prefix for this network | 3 | # URL Prefix for this network | 
| 4 | # For example, url_prefix is "example", register at "gradecoin.xyz/example/register" | 4 | # For example, url_prefix is "example", register at "gradecoin.xyz/example/register" | 
| 5 | url_prefix: "" | 5 | url_prefix: "" | 
| 6 | # List of users who can register | ||
| 7 | # CSV file: userID,password | ||
| 8 | # First line is ignored | ||
| 9 | preapproved_users: "students.csv" | ||
| 6 | # Valid blocks should have this many transactions | 10 | # Valid blocks should have this many transactions | 
| 7 | block_transaction_count: 4 | 11 | block_transaction_count: 4 | 
| 8 | # Bonus awarded after registration | 12 | # Bonus awarded after registration | 
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 | 
| @@ -15,8 +15,6 @@ use log::debug; | |||
| 15 | use parking_lot::RwLock; | 15 | use parking_lot::RwLock; | 
| 16 | use std::{collections::HashMap, fs, io, path::PathBuf, sync::Arc}; | 16 | use std::{collections::HashMap, fs, io, path::PathBuf, sync::Arc}; | 
| 17 | 17 | ||
| 18 | const PREAPPROVED_STU_FILENAME: &str = "students.csv"; | ||
| 19 | |||
| 20 | #[derive(Debug, Clone, Default)] | 18 | #[derive(Debug, Clone, Default)] | 
| 21 | pub struct Db { | 19 | pub 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 | ||
| 187 | fn read_approved_users() -> Vec<MetuId> { | 185 | fn 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 | }); | 
