aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/mining.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/mining.rs b/examples/mining.rs
new file mode 100644
index 0000000..56e33f3
--- /dev/null
+++ b/examples/mining.rs
@@ -0,0 +1,35 @@
1use chrono::NaiveDate;
2use gradecoin::schema::NakedBlock;
3use serde_json;
4use std::time::Instant;
5
6use blake2::{Blake2s, Digest};
7
8pub fn main() {
9 let mut b = NakedBlock {
10 transaction_list: vec![
11 "hash_value".to_owned(),
12 ],
13 nonce: 0,
14 timestamp: NaiveDate::from_ymd(2021, 04, 08).and_hms(12, 30, 30),
15 };
16
17 let now = Instant::now();
18
19 for nonce in 0..u32::MAX {
20 b.nonce = nonce;
21
22 let j = serde_json::to_vec(&b).unwrap();
23
24 let result = Blake2s::digest(&j);
25
26 let first_five = result[31] as i32 + result[30] as i32 + (result[29] << 4) as i32;
27
28 if first_five == 0 {
29 println!("{} - {:x}\n{:?}", nonce, result, b);
30 break;
31 }
32 }
33
34 println!("it took {} seconds", now.elapsed().as_secs());
35}