Skip to content

Commit

Permalink
Support multiple threads for vanity address
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapk00 committed Jun 26, 2019
1 parent a96b825 commit d63ac70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -94,7 +99,6 @@ fn main() {
// Number of z addresses to generate
let z_addresses = matches.value_of("z_addresses").unwrap().parse::<u32>().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);
Expand All @@ -106,9 +110,11 @@ fn main() {
return;
}

let num_threads = matches.value_of("threads").unwrap().parse::<u32>().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
Expand Down
6 changes: 3 additions & 3 deletions lib/src/paper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit d63ac70

Please sign in to comment.