aboutsummaryrefslogtreecommitdiffstats
path: root/src/schema.rs
diff options
context:
space:
mode:
authorYigit Sever2021-04-22 20:15:40 +0300
committerYigit Sever2021-04-22 20:15:40 +0300
commite9bf8a1a85d9366e59ec7989772d4e16490f1273 (patch)
tree6ddf0b62381bb054ff85c7f0f4f1369e16553ed1 /src/schema.rs
parent9f17c1391a8bb1651c472fc2ba2c246ed22ee2d4 (diff)
downloadgradecoin-e9bf8a1a85d9366e59ec7989772d4e16490f1273.tar.gz
gradecoin-e9bf8a1a85d9366e59ec7989772d4e16490f1273.tar.bz2
gradecoin-e9bf8a1a85d9366e59ec7989772d4e16490f1273.zip
[WIP] Starting to implement realnet
Diffstat (limited to 'src/schema.rs')
-rw-r--r--src/schema.rs59
1 files changed, 50 insertions, 9 deletions
diff --git a/src/schema.rs b/src/schema.rs
index 40c6329..b855b1c 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -20,9 +20,9 @@ use std::path::PathBuf;
20use std::string::String; 20use std::string::String;
21use std::sync::Arc; 21use std::sync::Arc;
22use std::vec::Vec; 22use std::vec::Vec;
23// use crate::validators;
24 23
25pub type Fingerprint = String; 24pub type Fingerprint = String;
25pub type Id = String;
26 26
27fn block_parser(path: String) -> u64 { 27fn block_parser(path: String) -> u64 {
28 let end_pos = path.find(".block").unwrap(); 28 let end_pos = path.find(".block").unwrap();
@@ -146,7 +146,7 @@ pub struct Claims {
146#[derive(Debug, Clone)] 146#[derive(Debug, Clone)]
147pub struct Db { 147pub struct Db {
148 pub blockchain: Arc<RwLock<Block>>, 148 pub blockchain: Arc<RwLock<Block>>,
149 pub pending_transactions: Arc<RwLock<HashMap<Fingerprint, Transaction>>>, 149 pub pending_transactions: Arc<RwLock<HashMap<Id, Transaction>>>,
150 pub users: Arc<RwLock<HashMap<Fingerprint, User>>>, 150 pub users: Arc<RwLock<HashMap<Fingerprint, User>>>,
151} 151}
152 152
@@ -154,14 +154,51 @@ impl Db {
154 pub fn new() -> Self { 154 pub fn new() -> Self {
155 let mut users: HashMap<Fingerprint, User> = HashMap::new(); 155 let mut users: HashMap<Fingerprint, User> = HashMap::new();
156 156
157 let bank_acc = MetuId::new("bank".to_owned(), "P7oxDm30g1jeIId".to_owned()).unwrap(); 157 let friendly_1 = MetuId::new("friend_1".to_owned(), "not_used".to_owned()).unwrap();
158 158
159 users.insert( 159 users.insert(
160 "31415926535897932384626433832795028841971693993751058209749445923".to_owned(), 160 "cde48537ca2c28084ff560826d0e6388b7c57a51497a6cb56f397289e52ff41b".to_owned(),
161 User { 161 User {
162 user_id: bank_acc, 162 user_id: friendly_1,
163 public_key: "null".to_owned(), 163 public_key: "not_used".to_owned(),
164 balance: 27 * 80, 164 balance: 0,
165 is_bot: true,
166 },
167 );
168
169 let friendly_2 = MetuId::new("friend_2".to_owned(), "not_used".to_owned()).unwrap();
170
171 users.insert(
172 "a1a38b5bae5866d7d998a9834229ec2f9db7a4fc8fb6f58b1115a96a446875ff".to_owned(),
173 User {
174 user_id: friendly_2,
175 public_key: "not_used".to_owned(),
176 balance: 0,
177 is_bot: true,
178 },
179 );
180
181 let friendly_3 = MetuId::new("friend_4".to_owned(), "not_used".to_owned()).unwrap();
182
183 users.insert(
184 "4e048fd2a62f1307866086e803e9be43f78a702d5df10831fbf434e7663ae0e7".to_owned(),
185 User {
186 user_id: friendly_3,
187 public_key: "not_used".to_owned(),
188 balance: 0,
189 is_bot: true,
190 },
191 );
192
193 let friendly_4 = MetuId::new("friend_4".to_owned(), "not_used".to_owned()).unwrap();
194
195 users.insert(
196 "60e77101e76950a9b1830fa107fd2f8fc545255b3e0f14b6a7797cf9ee005f07".to_owned(),
197 User {
198 user_id: friendly_4,
199 public_key: "not_used".to_owned(),
200 balance: 0,
201 is_bot: true,
165 }, 202 },
166 ); 203 );
167 204
@@ -182,7 +219,6 @@ impl Default for Db {
182/// A transaction between `source` and `target` that moves `amount` 219/// A transaction between `source` and `target` that moves `amount`
183#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] 220#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
184pub struct Transaction { 221pub struct Transaction {
185 pub by: Fingerprint,
186 pub source: Fingerprint, 222 pub source: Fingerprint,
187 pub target: Fingerprint, 223 pub target: Fingerprint,
188 pub amount: u16, 224 pub amount: u16,
@@ -244,6 +280,8 @@ pub struct User {
244 pub user_id: MetuId, 280 pub user_id: MetuId,
245 pub public_key: String, 281 pub public_key: String,
246 pub balance: u16, 282 pub balance: u16,
283 #[serde(skip, default = "bool::default")]
284 pub is_bot: bool,
247} 285}
248 286
249/// The values are hard coded in [`OUR_STUDENTS`] so MetuId::new() can accept/reject values based on that 287/// The values are hard coded in [`OUR_STUDENTS`] so MetuId::new() can accept/reject values based on that
@@ -306,7 +344,10 @@ lazy_static! {
306 ("e231060", "VJgziofQQPCoisH"), 344 ("e231060", "VJgziofQQPCoisH"),
307 ("e223795", "pmcTCKox99NFsqp"), 345 ("e223795", "pmcTCKox99NFsqp"),
308 ("e223715", "1H5QuOYI1b2r9ET"), 346 ("e223715", "1H5QuOYI1b2r9ET"),
309 ("bank", "P7oxDm30g1jeIId"), 347 ("friend_1", "not_used"),
348 ("friend_2", "not_used"),
349 ("friend_3", "not_used"),
350 ("friend_4", "not_used"),
310 ] 351 ]
311 .iter() 352 .iter()
312 .cloned() 353 .cloned()