aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/db.rs14
-rw-r--r--src/handlers.rs9
-rw-r--r--src/student.rs7
3 files changed, 25 insertions, 5 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}
diff --git a/src/handlers.rs b/src/handlers.rs
index a64c012..96001ce 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -27,13 +27,13 @@ use warp::{http::StatusCode, reply};
27use crate::PRIVATE_KEY; 27use crate::PRIVATE_KEY;
28 28
29// Valid blocks should have this many transactions 29// Valid blocks should have this many transactions
30const BLOCK_TRANSACTION_COUNT: u8 = 8; 30const BLOCK_TRANSACTION_COUNT: u8 = 4;
31// Inital registration bonus 31// Inital registration bonus
32const REGISTER_BONUS: u16 = 40; 32const REGISTER_BONUS: u16 = 20;
33// Coinbase reward 33// Coinbase reward
34const BLOCK_REWARD: u16 = 3; 34const BLOCK_REWARD: u16 = 2;
35// Transaction amount limit 35// Transaction amount limit
36const TX_UPPER_LIMIT: u16 = 10; 36const TX_UPPER_LIMIT: u16 = 4;
37const TX_LOWER_LIMIT: u16 = 1; 37const TX_LOWER_LIMIT: u16 = 1;
38// Transaction traffic reward 38// Transaction traffic reward
39const TX_TRAFFIC_REWARD: u16 = 1; 39const TX_TRAFFIC_REWARD: u16 = 1;
@@ -278,6 +278,7 @@ pub async fn authenticate_user(
278 }; 278 };
279 279
280 // is the student in AuthRequest privileged? 280 // is the student in AuthRequest privileged?
281 // TODO: this is the only check for 'if metuid is approved' <15-04-22, yigit> //
281 let privileged_student_id = 282 let privileged_student_id =
282 if let Some(id) = MetuId::new(request.student_id.clone(), request.passwd.clone()) { 283 if let Some(id) = MetuId::new(request.student_id.clone(), request.passwd.clone()) {
283 id 284 id
diff --git a/src/student.rs b/src/student.rs
index 4b7acf1..711eeeb 100644
--- a/src/student.rs
+++ b/src/student.rs
@@ -26,6 +26,7 @@ pub struct User {
26} 26}
27 27
28/// The values are hard coded in [`static@OUR_STUDENTS`] so `MetuId::new`() can accept/reject values based on that 28/// The values are hard coded in [`static@OUR_STUDENTS`] so `MetuId::new`() can accept/reject values based on that
29/// TODO update the statement above
29#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] 30#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
30pub struct MetuId { 31pub struct MetuId {
31 id: String, 32 id: String,
@@ -46,10 +47,14 @@ impl MetuId {
46 None 47 None
47 } 48 }
48 } 49 }
50
51 // TODO: replace the function above with this <15-04-22, yigit> //
52 pub fn _new(id: String, passwd: String) -> Self {
53 MetuId { id, passwd }
54 }
49} 55}
50 56
51// TODO: remove this, read from a yaml or something, then MetuId::new gets a self <11-04-22, yigit> // 57// TODO: remove this, read from a yaml or something, then MetuId::new gets a self <11-04-22, yigit> //
52
53// Students who are authorized to have Gradecoin accounts 58// Students who are authorized to have Gradecoin accounts
54lazy_static! { 59lazy_static! {
55 static ref OUR_STUDENTS: HashSet<(&'static str, &'static str)> = { 60 static ref OUR_STUDENTS: HashSet<(&'static str, &'static str)> = {