diff --git a/cli/src/main.rs b/cli/src/main.rs index e8185d2..83fe1bb 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -42,6 +42,11 @@ fn main() { .long("vanity") .help("Generate a vanity address with the given prefix") .takes_value(true)) + .arg(Arg::with_name("threads") + .long("threads") + .help("Number of threads to use for the vanity address generator. Set this to the number of CPUs you have") + .takes_value(true) + .default_value("1")) .arg(Arg::with_name("t_addresses") .short("t") .long("taddrs") @@ -94,7 +99,6 @@ fn main() { // Number of z addresses to generate let z_addresses = matches.value_of("z_addresses").unwrap().parse::().unwrap(); - let addresses = if !matches.value_of("vanity").is_none() { if z_addresses != 1 { eprintln!("Can only generate 1 zaddress in vanity mode. You specified {}", z_addresses); @@ -106,9 +110,11 @@ fn main() { return; } + let num_threads = matches.value_of("threads").unwrap().parse::().unwrap(); + let prefix = matches.value_of("vanity").unwrap().to_string(); println!("Generating address starting with \"{}\"", prefix); - let addresses = generate_vanity_wallet(is_testnet, prefix); + let addresses = generate_vanity_wallet(is_testnet, num_threads, prefix); // return addresses diff --git a/lib/src/paper.rs b/lib/src/paper.rs index 6b72b7c..aecc6e4 100644 --- a/lib/src/paper.rs +++ b/lib/src/paper.rs @@ -126,7 +126,7 @@ pub fn vanity_thread(is_testnet: bool, entropy: &[u8], prefix: String, tx: mpsc: } /// Generate a vanity address with the given prefix. -pub fn generate_vanity_wallet(is_testnet: bool, prefix: String) -> String { +pub fn generate_vanity_wallet(is_testnet: bool, num_threads: u32, prefix: String) -> String { // Get 32 bytes of system entropy let mut system_rng = ChaChaRng::from_entropy(); @@ -135,7 +135,7 @@ pub fn generate_vanity_wallet(is_testnet: bool, prefix: String) -> String { let mut handles = Vec::new(); - for _i in 0..8 { + for _i in 0..num_threads { let testnet_local = is_testnet.clone(); let prefix_local = prefix.clone(); let tx_local = mpsc::Sender::clone(&tx); @@ -159,7 +159,7 @@ pub fn generate_vanity_wallet(is_testnet: bool, prefix: String) -> String { let recv = rx.recv().unwrap(); if recv.starts_with(&"Processed") { processed = processed + 1000; - let timeelapsed = now.elapsed().unwrap().as_secs(); + let timeelapsed = now.elapsed().unwrap().as_secs() + 1; // Add one second to prevent any divide by zero problems. print!("Checking addresses at {}/sec \r", (processed / timeelapsed)); io::stdout().flush().ok().unwrap();