library_utils/
stringtou128.rs

1pub fn string_to_u128(difficulty_str: &String) -> u128 {
2    //std::process::exit(
3        match is_run_app_stringtou128(&difficulty_str) {
4        Some(str) => {
5            let diff_str = str.trim().to_lowercase().to_string();
6            let diff_digits = diff_str.strip_prefix("0x").unwrap();
7            let difficulty = u128::from_str_radix(diff_digits, 16).unwrap();
8            let diff_bytes = difficulty.to_le_bytes();
9
10            let de_diff_bytes = diff_bytes;
11            let de_diff = u128::from_le_bytes(de_diff_bytes);
12            let de_diff_str = format!("0x{de_diff:032x}");
13            assert_eq!(diff_str, de_diff_str);
14            return difficulty;
15        }
16        None => {
17            println!("Error string_to_u128");
18            1
19        }
20    }
21//);
22}
23
24fn is_run_app_stringtou128(difficulty_str: &String) -> Option<String> {
25    // let l = (&difficulty_str).as_str().len();
26    // match l {
27    //     34 => Ok(&(difficulty_str).as_str()),
28    //     _ => Err("difficulty length must be 34 char"),
29    // };
30    Some((&(difficulty_str).as_str()).to_string())
31    
32}