暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

main.rs 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. extern crate clap;
  2. extern crate time;
  3. use time::get_time;
  4. use clap::{Arg, App, SubCommand};
  5. use std::process;
  6. mod hasher_sha256;
  7. mod hash256;
  8. /// Hauptfunktion zum Starten des Hashers.
  9. pub fn main() {
  10. let matches = create_app().get_matches();
  11. let base = matches.value_of("base").unwrap_or("1");
  12. let diff = matches.value_of("difficulty").unwrap_or("1");
  13. let mut time_measurement = false;
  14. if diff.chars().any( |c| !c.is_digit(16)) {
  15. println!("Difficulty is not hexadecimal.");
  16. process::exit(1)
  17. }
  18. if let Some(ref sub_command) = matches.subcommand {
  19. if sub_command.name.eq("timings") {
  20. time_measurement = true;
  21. }
  22. }
  23. match base.parse::<usize>() {
  24. Ok(b) => {
  25. println!("Using base: {}", base);
  26. println!("Using difficulty: {}", diff);
  27. println!("Please wait...");
  28. let start = get_time();
  29. let max = <usize>::max_value();
  30. for n in 0..max {
  31. if let Some(x) = hash256::verify_product(b, n, &diff.to_string()) {
  32. let end = get_time();
  33. println!("Number: {} --> hash: {}", x.number, x.hash);
  34. if time_measurement{
  35. let diff = end - start;
  36. let s = diff.num_seconds();
  37. let ms = diff.num_milliseconds();
  38. let us = diff.num_microseconds().unwrap_or(ms * 1000);
  39. println!("(Duration {}s / {}ms / {}us)", s, ms, us);
  40. }
  41. process::exit(0)
  42. }
  43. }
  44. }
  45. Err(_) => {
  46. println!("Base is not integer.");
  47. process::exit(1)
  48. }
  49. };
  50. }
  51. /// Diese Funktion dient der Konfiguration der App mit dem Paket **Clap**.
  52. fn create_app<'a, 'b>() -> App<'a, 'b> {
  53. App::new("Hash256")
  54. .version("1.0")
  55. .author("Lorenz Bung & Joshua Rutschmann")
  56. .about("Calculates the Hashvalue of the given base, number and difficulty.")
  57. .arg(Arg::with_name("base")
  58. .value_name("base")
  59. .help("The base of the hash to be calculated on.")
  60. .takes_value(true)
  61. .required(true))
  62. .arg(Arg::with_name("difficulty")
  63. .value_name("difficulty")
  64. .help("The difficulty of the calculated hash.")
  65. .takes_value(true)
  66. .required(true))
  67. .subcommand(SubCommand::with_name("timings")
  68. .about("controls timing features")
  69. .version("1.0")
  70. .author("Lorenz Bung & Joshua Rutschmann"))
  71. }