diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/mining.rs | 66 | ||||
-rw-r--r-- | examples/serdeser.rs | 16 |
2 files changed, 0 insertions, 82 deletions
diff --git a/examples/mining.rs b/examples/mining.rs deleted file mode 100644 index e3d1487..0000000 --- a/examples/mining.rs +++ /dev/null | |||
@@ -1,66 +0,0 @@ | |||
1 | use chrono::NaiveDate; | ||
2 | use gradecoin::schema::NakedBlock; | ||
3 | use serde_json; | ||
4 | use std::sync::{Arc, Mutex}; | ||
5 | use std::thread; | ||
6 | use std::time::Instant; | ||
7 | |||
8 | use blake2::{Blake2s, Digest}; | ||
9 | |||
10 | const N: usize = 4; | ||
11 | |||
12 | pub fn main() { | ||
13 | let counter = Arc::new(Mutex::new(0)); | ||
14 | |||
15 | let now = Instant::now(); | ||
16 | |||
17 | let mut threads = Vec::with_capacity(N); | ||
18 | |||
19 | (0..N).for_each(|_| { | ||
20 | let counter = Arc::clone(&counter); | ||
21 | threads.push(thread::spawn(move || { | ||
22 | let mut b = NakedBlock { | ||
23 | transaction_list: vec!["fingerprint_of_some_guy".to_owned()], | ||
24 | nonce: 0, | ||
25 | timestamp: NaiveDate::from_ymd(2021, 04, 13).and_hms(23, 38, 00), | ||
26 | }; | ||
27 | |||
28 | let start: u32; | ||
29 | let end: u32; | ||
30 | { | ||
31 | let mut num = counter.lock().unwrap(); | ||
32 | |||
33 | println!("Starting with 2 over {}", num); | ||
34 | |||
35 | start = 0 + (1073741824 * *num); | ||
36 | end = 1073741820 * (*num + 1); | ||
37 | *num += 1; | ||
38 | } | ||
39 | |||
40 | println!("here {} - {}", start, end); | ||
41 | |||
42 | for nonce in start..end { | ||
43 | b.nonce = nonce; | ||
44 | |||
45 | let j = serde_json::to_vec(&b).unwrap(); | ||
46 | |||
47 | let result = Blake2s::digest(&j); | ||
48 | |||
49 | let first_six = result[0] as i32 + result[1] as i32 + (result[2]) as i32; | ||
50 | |||
51 | if first_six == 0 { | ||
52 | println!("{} - {:x}\n{:?}", nonce, result, b); | ||
53 | break; | ||
54 | } | ||
55 | } | ||
56 | })); | ||
57 | }); | ||
58 | |||
59 | threads.into_iter().for_each(|thread| { | ||
60 | thread | ||
61 | .join() | ||
62 | .expect("The thread creating or execution failed !") | ||
63 | }); | ||
64 | |||
65 | println!("it took {} seconds", now.elapsed().as_secs()); | ||
66 | } | ||
diff --git a/examples/serdeser.rs b/examples/serdeser.rs deleted file mode 100644 index 4fdfdc2..0000000 --- a/examples/serdeser.rs +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | use gradecoin::schema::Transaction; | ||
2 | use serde_json; | ||
3 | |||
4 | pub fn main() { | ||
5 | |||
6 | let tx = Transaction { | ||
7 | source: "fingerprint_of_some_guy".to_owned(), | ||
8 | target: "31415926535897932384626433832795028841971693993751058209749445923".to_owned(), | ||
9 | amount: 2, | ||
10 | timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 30), | ||
11 | }; | ||
12 | |||
13 | let tx_string = serde_json::to_string(&tx).unwrap(); | ||
14 | |||
15 | println!("{}", &tx_string); | ||
16 | } | ||