|
|
@@ -1,20 +1,35 @@
|
|
1
|
1
|
extern crate clap;
|
|
2
|
2
|
extern crate time;
|
|
3
|
3
|
use clap::{Arg, App, SubCommand};
|
|
|
4
|
+use std::process;
|
|
4
|
5
|
mod hasher_sha256;
|
|
5
|
6
|
mod hash256;
|
|
6
|
7
|
|
|
7
|
|
-pub fn main(/*base: usize, */number: usize, diff: String) {
|
|
|
8
|
+pub fn main() {
|
|
8
|
9
|
let matches = create_app().get_matches();
|
|
9
|
|
- let base;
|
|
10
|
|
- match matches.value_of("base") {
|
|
11
|
|
- Some(x) => {base = u64::from(x)}
|
|
12
|
|
- None => {panic!()}
|
|
13
|
|
- };
|
|
14
|
|
- match hash256::verify_product(base, number, diff) {
|
|
15
|
|
- Some(x) => { println!("{}", diff); }
|
|
16
|
|
- None => { println!("None"); }
|
|
|
10
|
+ let base = matches.value_of("base").unwrap_or("1");
|
|
|
11
|
+ let diff = matches.value_of("difficulty").unwrap_or("1");
|
|
|
12
|
+
|
|
|
13
|
+ println!("Using base: {}", base);
|
|
|
14
|
+ println!("Using difficulty: {}", diff);
|
|
|
15
|
+
|
|
|
16
|
+ if diff.chars().any( |c| !c.is_digit(16)) {
|
|
|
17
|
+ println!("Difficulty is not hexadecimal.");
|
|
|
18
|
+ process::exit(1)
|
|
17
|
19
|
}
|
|
|
20
|
+
|
|
|
21
|
+ match base.parse::<usize>() {
|
|
|
22
|
+ Ok(b) => {
|
|
|
23
|
+ println!("Please wait...");
|
|
|
24
|
+ for n in 0..<usize>::max_value() {
|
|
|
25
|
+ if let Some(x) = hash256::verify_product(b, n, &diff.to_string()) {
|
|
|
26
|
+ println!("Number: {} --> hash: {}", x.number, x.hash);
|
|
|
27
|
+ process::exit(0)
|
|
|
28
|
+ }
|
|
|
29
|
+ }
|
|
|
30
|
+ }
|
|
|
31
|
+ Err(_) => {}
|
|
|
32
|
+ };
|
|
18
|
33
|
}
|
|
19
|
34
|
|
|
20
|
35
|
fn create_app<'a, 'b>() -> App<'a, 'b> {
|
|
|
@@ -23,23 +38,12 @@ fn create_app<'a, 'b>() -> App<'a, 'b> {
|
|
23
|
38
|
.author("Lorenz Bung & Joshua Rutschmann")
|
|
24
|
39
|
.about("Calculates the Hashvalue of the given base, number and difficulty.")
|
|
25
|
40
|
.arg(Arg::with_name("base")
|
|
26
|
|
- .short("b")
|
|
27
|
|
- .long("base")
|
|
28
|
|
- .value_name("VALUE")
|
|
|
41
|
+ .value_name("base")
|
|
29
|
42
|
.help("The base of the hash to be calculated on.")
|
|
30
|
43
|
.takes_value(true)
|
|
31
|
44
|
.required(true))
|
|
32
|
|
- .arg(Arg::with_name("number")
|
|
33
|
|
- .short("n")
|
|
34
|
|
- .long("number")
|
|
35
|
|
- .value_name("VALUE")
|
|
36
|
|
- .help("The number of the hash to be calculated on.")
|
|
37
|
|
- .takes_value(true)
|
|
38
|
|
- .required(true))
|
|
39
|
45
|
.arg(Arg::with_name("difficulty")
|
|
40
|
|
- .short("d")
|
|
41
|
|
- .long("difficulty")
|
|
42
|
|
- .value_name("VALUE")
|
|
|
46
|
+ .value_name("difficulty")
|
|
43
|
47
|
.help("The difficulty of the calculated hash.")
|
|
44
|
48
|
.takes_value(true)
|
|
45
|
49
|
.required(true))
|