From f12685e32689b620d6096ec91ba3a3f495342925 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Fri, 15 Apr 2022 19:01:40 +0300 Subject: [WIP] first part of lazy users overhaul --- src/db.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/db.rs') diff --git a/src/db.rs b/src/db.rs index bf094ab..fd5c1be 100644 --- a/src/db.rs +++ b/src/db.rs @@ -19,6 +19,7 @@ pub struct Db { pub blockchain: Arc>, pub pending_transactions: Arc>>, pub users: Arc>>, + approved_users: Vec, // TODO: metu_ids or approved_users or something, metu_id struct <11-04-22, yigit> // } @@ -36,11 +37,13 @@ impl Db { } let users: HashMap = get_friendly_users(); + let approved_users = read_approved_users(); Db { blockchain: Arc::new(RwLock::new(Block::default())), pending_transactions: Arc::new(RwLock::new(HashMap::new())), users: Arc::new(RwLock::new(users)), + approved_users, } } @@ -157,3 +160,14 @@ fn get_friendly_users() -> HashMap { ); users } + +fn read_approved_users() -> Vec { + let mut approved_students: Vec = Vec::new(); + let contents = fs::read_to_string("students.csv").unwrap(); + let mut reader = csv::Reader::from_reader(contents.as_bytes()); + for student in reader.records() { + let student = student.unwrap(); + approved_students.push(MetuId::_new(student[0].to_owned(), student[1].to_owned())); + } + approved_students +} -- cgit v1.2.3-70-g09d2