summaryrefslogtreecommitdiffstats
path: root/examples/mining.rs
blob: c95c2142f210221dfe5751ccc7dba2d85b310f2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use chrono::NaiveDate;
use gradecoin::schema::NakedBlock;
use serde_json;
use std::time::Instant;

use blake2::{Blake2s, Digest};

pub fn main() {
    let mut b = NakedBlock {
        transaction_list: vec![
            "hash_value".to_owned(),
        ],
        nonce: 0,
        timestamp: NaiveDate::from_ymd(2021, 04, 08).and_hms(12, 30, 30),
    };

    let now = Instant::now();

    for nonce in 0..u32::MAX {
        b.nonce = nonce;

        let j = serde_json::to_vec(&b).unwrap();

        let result = Blake2s::digest(&j);

        let first_six = result[31] as i32 + result[30] as i32 + result[29] as i32;

        if first_six == 0 {
            println!("{} - {:x}\n{:?}", nonce, result, b);
            break;
        }
    }

    println!("it took {} seconds", now.elapsed().as_secs());
}