diff --git a/__crypto/btc-address/src/main.rs b/__crypto/btc-address/src/main.rs index 160bfd0..dbcc646 100644 --- a/__crypto/btc-address/src/main.rs +++ b/__crypto/btc-address/src/main.rs @@ -1,14 +1,34 @@ -use std::{ thread, sync::{ Arc, Mutex } }; -use rand::rngs::OsRng; -use secp256k1::{ Secp256k1, key::PublicKey }; -use sha2::Sha256; -use ripemd160::Ripemd160; -use digest::{ Input, FixedOutput }; +use std::{sync::{Arc, Mutex}, thread}; -const PREFIX: &[&str] = &["1Hatter"]; +use digest::{FixedOutput, Input}; +use rand::rngs::OsRng; +use ripemd160::Ripemd160; +use secp256k1::{key::PublicKey, Secp256k1}; +use sha2::Sha256; fn main() { - println!("Prefix: {:?}", PREFIX); + let args = std::env::args(); + if args.len() <= 1 { + println!("[ERROR] Need at least one argument, e.g. 1Hatter 1UTF8 ..."); + return; + } + let continue_on_found = std::env::var("CONTINUE_ON_FOUND") + .map(|c| c.to_lowercase()) + .map(|c| c == "1" || c == "true" || c == "yes" || c == "on") + .unwrap_or_else(|_| false); + + let prefixes: Vec = args.skip(1).collect(); + println!("Prefixes: {:?}", prefixes); + if continue_on_found { + println!("CONTINUE_ON_FOUND is ON"); + } else { + println!("CONTINUE_ON_FOUND is OFF"); + } + let loop_count = std::env::var("LOOP_COUNT") + .map(|c| c.parse::()) + .unwrap_or_else(|_| Ok(10_000_000_u64)) + .unwrap_or_else(|_| 10_000_000_u64); + println!("LOOP_COUNT={}", loop_count); let num_of_vcpus = num_cpus::get(); let num_of_phycpus = num_cpus::get_physical(); @@ -19,8 +39,9 @@ fn main() { for ind in 0..num_of_phycpus { println!("- Running task {} of {}", ind, num_of_phycpus); let the_stop_flag = Arc::clone(&stop_flag); + let prefixes = prefixes.clone(); let child = thread::spawn(move || { - run_one_task(ind, the_stop_flag); + run_one_task(prefixes, continue_on_found, loop_count, ind, the_stop_flag); }); handles.push(child); } @@ -30,11 +51,11 @@ fn main() { println!("Finished!"); } -fn run_one_task(ind: usize, the_stop_flag: Arc>) { +fn run_one_task(prefixes: Vec, continue_on_found: bool, loop_count: u64, ind: usize, the_stop_flag: Arc>) { let secp = Secp256k1::new(); let mut rng = OsRng::new().expect("OsRng"); - for i in 0..10_000_000 { + for i in 0..loop_count { let (secret_key, public_key) = secp.generate_keypair(&mut rng); let s = make_btc_address(&public_key); @@ -47,12 +68,13 @@ fn run_one_task(ind: usize, the_stop_flag: Arc>) { println!("> {} - {}", ind, i); } } - if PREFIX.iter().any(|p| s.starts_with(p)) { - println!("{}", s); - println!("{}", secret_key); + if prefixes.iter().any(|p| s.starts_with(p)) { + println!(">> {}\n{}", s, secret_key); - *the_stop_flag.lock().unwrap() = true; - break; + if !continue_on_found { + *the_stop_flag.lock().unwrap() = true; + break; + } } } }