aboutsummaryrefslogtreecommitdiffstats
path: root/src/db.rs
diff options
context:
space:
mode:
authorYigit Sever2022-04-15 19:01:40 +0300
committerYigit Sever2022-04-15 19:01:40 +0300
commitf12685e32689b620d6096ec91ba3a3f495342925 (patch)
tree7f7ba75511980e1877a3ffde53fc51399205660c /src/db.rs
parentbacedcecc51d4f8be610c6a1f4c1d0643faf8146 (diff)
downloadgradecoin-f12685e32689b620d6096ec91ba3a3f495342925.tar.gz
gradecoin-f12685e32689b620d6096ec91ba3a3f495342925.tar.bz2
gradecoin-f12685e32689b620d6096ec91ba3a3f495342925.zip
[WIP] first part of lazy users overhaul
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs14
1 files changed, 14 insertions, 0 deletions
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 {
19 pub blockchain: Arc<RwLock<Block>>, 19 pub blockchain: Arc<RwLock<Block>>,
20 pub pending_transactions: Arc<RwLock<HashMap<Id, Transaction>>>, 20 pub pending_transactions: Arc<RwLock<HashMap<Id, Transaction>>>,
21 pub users: Arc<RwLock<HashMap<Fingerprint, User>>>, 21 pub users: Arc<RwLock<HashMap<Fingerprint, User>>>,
22 approved_users: Vec<MetuId>,
22 // TODO: metu_ids or approved_users or something, metu_id struct <11-04-22, yigit> // 23 // TODO: metu_ids or approved_users or something, metu_id struct <11-04-22, yigit> //
23} 24}
24 25
@@ -36,11 +37,13 @@ impl Db {
36 } 37 }
37 38
38 let users: HashMap<Fingerprint, User> = get_friendly_users(); 39 let users: HashMap<Fingerprint, User> = get_friendly_users();
40 let approved_users = read_approved_users();
39 41
40 Db { 42 Db {
41 blockchain: Arc::new(RwLock::new(Block::default())), 43 blockchain: Arc::new(RwLock::new(Block::default())),
42 pending_transactions: Arc::new(RwLock::new(HashMap::new())), 44 pending_transactions: Arc::new(RwLock::new(HashMap::new())),
43 users: Arc::new(RwLock::new(users)), 45 users: Arc::new(RwLock::new(users)),
46 approved_users,
44 } 47 }
45 } 48 }
46 49
@@ -157,3 +160,14 @@ fn get_friendly_users() -> HashMap<Fingerprint, User> {
157 ); 160 );
158 users 161 users
159} 162}
163
164fn read_approved_users() -> Vec<MetuId> {
165 let mut approved_students: Vec<MetuId> = Vec::new();
166 let contents = fs::read_to_string("students.csv").unwrap();
167 let mut reader = csv::Reader::from_reader(contents.as_bytes());
168 for student in reader.records() {
169 let student = student.unwrap();
170 approved_students.push(MetuId::_new(student[0].to_owned(), student[1].to_owned()));
171 }
172 approved_students
173}