From e0fb91039f34204b2a5c588a95cb3f1789ad2fa7 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Mon, 12 Apr 2021 05:32:53 +0300 Subject: 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 --- src/schema.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/schema.rs') 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 { // somewhere // I want to keep this as a String vector because it makes things easier elsewhere pub transaction_list: Vec, // hashes of the transactions (or just "source" for now) - pub nonce: String, + pub nonce: u32, pub timestamp: NaiveDateTime, pub hash: String, // future proof'd baby } +/// For prototyping and letting serde handle everything json +#[derive(Serialize, Deserialize, Debug)] +pub struct NakedBlock { + pub transaction_list: Vec, + pub nonce: u32, + pub timestamp: NaiveDateTime, +} + impl Block { /// Genesis block pub fn new() -> Block { Block { transaction_list: vec![], - nonce: String::from(""), + nonce: 0, timestamp: NaiveDate::from_ymd(2021, 04, 11).and_hms(20, 45, 00), hash: String::from(""), } -- cgit v1.2.3-70-g09d2