diff options
author | Yigit Sever | 2021-04-12 05:32:53 +0300 |
---|---|---|
committer | Yigit Sever | 2021-04-12 05:32:53 +0300 |
commit | 44d21b676f90a2fc8b255eb9c1393e53f40c9daa (patch) | |
tree | edfadfd279dc9fcfaa6c27f819c7f0e69d14599c /src/schema.rs | |
parent | 6c0345ecda5e46da88bc6ca513a28c648c29833c (diff) | |
download | gradecoin-44d21b676f90a2fc8b255eb9c1393e53f40c9daa.tar.gz gradecoin-44d21b676f90a2fc8b255eb9c1393e53f40c9daa.tar.bz2 gradecoin-44d21b676f90a2fc8b255eb9c1393e53f40c9daa.zip |
Implement proof-of-work
Using blacke2s: https://docs.rs/blake2/0.9.1/blake2/
Using this guy's hash checker https://gist.github.com/gkbrk/2e4835e3a17b3fb6e1e7
blacke2s with 5 bits 0 can mine a block between 20 seconds to 359 during
my tests, hope it'll be fun
Diffstat (limited to 'src/schema.rs')
-rw-r--r-- | src/schema.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/schema.rs b/src/schema.rs index 909b5cd..98291d7 100644 --- a/src/schema.rs +++ b/src/schema.rs | |||
@@ -62,17 +62,25 @@ pub struct Block { | |||
62 | // somewhere | 62 | // somewhere |
63 | // I want to keep this as a String vector because it makes things easier elsewhere | 63 | // I want to keep this as a String vector because it makes things easier elsewhere |
64 | pub transaction_list: Vec<String>, // hashes of the transactions (or just "source" for now) | 64 | pub transaction_list: Vec<String>, // hashes of the transactions (or just "source" for now) |
65 | pub nonce: String, | 65 | pub nonce: u32, |
66 | pub timestamp: NaiveDateTime, | 66 | pub timestamp: NaiveDateTime, |
67 | pub hash: String, // future proof'd baby | 67 | pub hash: String, // future proof'd baby |
68 | } | 68 | } |
69 | 69 | ||
70 | /// For prototyping and letting serde handle everything json | ||
71 | #[derive(Serialize, Deserialize, Debug)] | ||
72 | pub struct NakedBlock { | ||
73 | pub transaction_list: Vec<String>, | ||
74 | pub nonce: u32, | ||
75 | pub timestamp: NaiveDateTime, | ||
76 | } | ||
77 | |||
70 | impl Block { | 78 | impl Block { |
71 | /// Genesis block | 79 | /// Genesis block |
72 | pub fn new() -> Block { | 80 | pub fn new() -> Block { |
73 | Block { | 81 | Block { |
74 | transaction_list: vec![], | 82 | transaction_list: vec![], |
75 | nonce: String::from(""), | 83 | nonce: 0, |
76 | timestamp: NaiveDate::from_ymd(2021, 04, 11).and_hms(20, 45, 00), | 84 | timestamp: NaiveDate::from_ymd(2021, 04, 11).and_hms(20, 45, 00), |
77 | hash: String::from(""), | 85 | hash: String::from(""), |
78 | } | 86 | } |