summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralpaylan2021-04-16 01:09:38 +0300
committeralpaylan2021-04-16 01:09:38 +0300
commit6952da3ace3adde1c987f5f2a0ea9464d3e93b4e (patch)
tree0df3ce5520c39abd538795926e66362126e6625c
parentb4212a90caa899785402c06d57216e75de0f1c88 (diff)
downloadgradecoin-6952da3ace3adde1c987f5f2a0ea9464d3e93b4e.tar.gz
gradecoin-6952da3ace3adde1c987f5f2a0ea9464d3e93b4e.tar.bz2
gradecoin-6952da3ace3adde1c987f5f2a0ea9464d3e93b4e.zip
change last block reading method.
-rw-r--r--src/schema.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/schema.rs b/src/schema.rs
index cb353e4..b63b0c1 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -31,11 +31,11 @@ fn block_parser(path: String) -> u64 {
31 block_u64 31 block_u64
32} 32}
33 33
34fn last_block_content() -> (bool, String) { 34fn last_block_content() -> Option<String> {
35 let blocks = read_block_name().unwrap(); 35 let blocks = read_block_name().unwrap();
36 36
37 if blocks.len() == 0 { 37 if blocks.len() == 0 {
38 return (false, "".to_string()); 38 return None;
39 } 39 }
40 40
41 let last_block = blocks[0].to_str().unwrap(); 41 let last_block = blocks[0].to_str().unwrap();
@@ -50,7 +50,7 @@ fn last_block_content() -> (bool, String) {
50 last_block_index = index; 50 last_block_index = index;
51 } 51 }
52 } 52 }
53 return (true, blocks[last_block_index].to_str().unwrap().parse().unwrap()); 53 return Some(blocks[last_block_index].to_str().unwrap().parse().unwrap());
54 54
55} 55}
56 56
@@ -108,11 +108,9 @@ fn populate_db_with_users(db: &mut Db, files: Vec<PathBuf>) -> &mut Db {
108pub fn create_database() -> Db { 108pub fn create_database() -> Db {
109 fs::create_dir_all("blocks").unwrap(); 109 fs::create_dir_all("blocks").unwrap();
110 fs::create_dir_all("users").unwrap(); 110 fs::create_dir_all("users").unwrap();
111 let (res, path) = last_block_content(); 111 let mut db = Db::new();
112 if res { 112 if let Some(block_path) = last_block_content() {
113 return create_db_with_last_block(path); 113 populate_db_with_last_block(&mut db, block_path);
114 } else {
115 return Db::new();
116 } 114 }
117 115
118 if let Ok(users_path) = read_users() { 116 if let Ok(users_path) = read_users() {