diff options
author | alpaylan | 2021-04-16 01:09:38 +0300 |
---|---|---|
committer | alpaylan | 2021-04-16 01:09:38 +0300 |
commit | eab91040254b1b3e7556c29a1ab6a57f139308ee (patch) | |
tree | 4bf4342059cee2732639fd050a08244040ed1a32 /src | |
parent | d248309f8595701a0fddd2462b963bcad55f18c8 (diff) | |
download | gradecoin-eab91040254b1b3e7556c29a1ab6a57f139308ee.tar.gz gradecoin-eab91040254b1b3e7556c29a1ab6a57f139308ee.tar.bz2 gradecoin-eab91040254b1b3e7556c29a1ab6a57f139308ee.zip |
change last block reading method.
Diffstat (limited to 'src')
-rw-r--r-- | src/schema.rs | 14 |
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 | ||
34 | fn last_block_content() -> (bool, String) { | 34 | fn 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 { | |||
108 | pub fn create_database() -> Db { | 108 | pub 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() { |