Skip to content

Commit

Permalink
Fix syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
grunch committed Jan 29, 2023
1 parent c8428e5 commit 3e8f8ff
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
15 changes: 12 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ targets as a comma-separated list."
pub qr: bool,
}

pub fn check_args(difficulty: u8, vanity_prefix: &str, vanity_npub_prefixes: &Vec<String>, vanity_npub_suffixes: &Vec<String>, num_cores: usize) {
pub fn check_args(
difficulty: u8,
vanity_prefix: &str,
vanity_npub_prefixes: &Vec<String>,
vanity_npub_suffixes: &Vec<String>,
num_cores: usize,
) {
// Check the public key requirements
let mut requirements_count: u8 = 0;
if difficulty > 0 {
Expand Down Expand Up @@ -127,7 +133,10 @@ pub fn check_args(difficulty: u8, vanity_prefix: &str, vanity_npub_prefixes: &Ve
if num_cores == 0 {
panic!("There can be no proof of work if one does not do work (-c, --cores must be greater than 0)");
} else if num_cores > num_cpus::get() {
panic!("Your processor has {} cores; cannot set -c, --cores to {}", num_cpus::get(), num_cores);
panic!(
"Your processor has {} cores; cannot set -c, --cores to {}",
num_cpus::get(),
num_cores
);
}

}
34 changes: 19 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ fn main() -> Result<(), Box<dyn Error>> {
}
}

check_args(difficulty, vanity_prefix.as_str(), &vanity_npub_prefixes, &vanity_npub_suffixes, num_cores);
check_args(
difficulty,
vanity_prefix.as_str(),
&vanity_npub_prefixes,
&vanity_npub_suffixes,
num_cores,
);

//-- Calculate pow difficulty and initialize

Expand All @@ -52,31 +58,28 @@ fn main() -> Result<(), Box<dyn Error>> {
"Started mining process for vanity hex prefix: '{}' (estimated pow: {})",
vanity_prefix, pow_difficulty
);

} else if !vanity_npub_prefixes.is_empty() && !vanity_npub_suffixes.is_empty() {
// set pow difficulty as the length of the first prefix + first suffix translated to bits
pow_difficulty = ((vanity_npub_prefixes[0].len() * 4) + (vanity_npub_suffixes[0].len() * 4)) as u8;
pow_difficulty =
((vanity_npub_prefixes[0].len() * 4) + (vanity_npub_suffixes[0].len() * 4)) as u8;
println!(
"Started mining process for vanity bech32 prefix[es]: 'npub1{:?}' and suffix[es]: '...{:?}' (estimated pow: {})",
vanity_npub_prefixes, vanity_npub_suffixes, pow_difficulty
);

} else if !vanity_npub_prefixes.is_empty() {
// set pow difficulty as the length of the first prefix translated to bits
pow_difficulty = (vanity_npub_prefixes[0].len() * 4) as u8;
println!(
"Started mining process for vanity bech32 prefix[es]: 'npub1{:?}' (estimated pow: {})",
vanity_npub_prefixes, pow_difficulty
);

} else if !vanity_npub_suffixes.is_empty() {
// set pow difficulty as the length of the first suffix translated to bits
pow_difficulty = (vanity_npub_suffixes[0].len() * 4) as u8;
println!(
"Started mining process for vanity bech32 suffix[es]: '...{:?}' (estimated pow: {})",
vanity_npub_suffixes, pow_difficulty
);

} else {
// Defaults to using difficulty

Expand Down Expand Up @@ -137,7 +140,6 @@ fn main() -> Result<(), Box<dyn Error>> {
if vanity_ts.as_str() != "" {
// hex vanity search
is_valid_pubkey = hexa_key.starts_with(vanity_ts.as_str());

} else if !vanity_npubs_pre_ts.is_empty() || !vanity_npubs_post_ts.is_empty() {
// bech32 vanity search
let bech_key: String = bech32::encode(
Expand All @@ -152,17 +154,21 @@ fn main() -> Result<(), Box<dyn Error>> {
for cur_vanity_npub_post in vanity_npubs_post_ts.iter() {
is_valid_pubkey = bech_key.starts_with(
(String::from("npub1") + cur_vanity_npub_pre.as_str()).as_str(),
) && bech_key.ends_with(cur_vanity_npub_post.as_str());
) && bech_key
.ends_with(cur_vanity_npub_post.as_str());

if is_valid_pubkey {
vanity_npub = cur_vanity_npub_pre.clone() + "..." + cur_vanity_npub_post.clone().as_str();
vanity_npub = cur_vanity_npub_pre.clone()
+ "..."
+ cur_vanity_npub_post.clone().as_str();
break;
}
}
if is_valid_pubkey {break;}
if is_valid_pubkey {
break;
}
}
}
else if !vanity_npubs_pre_ts.is_empty() {
} else if !vanity_npubs_pre_ts.is_empty() {
for cur_vanity_npub in vanity_npubs_pre_ts.iter() {
is_valid_pubkey = bech_key.starts_with(
(String::from("npub1") + cur_vanity_npub.as_str()).as_str(),
Expand All @@ -173,8 +179,7 @@ fn main() -> Result<(), Box<dyn Error>> {
break;
}
}
}
else {
} else {
for cur_vanity_npub in vanity_npubs_post_ts.iter() {
is_valid_pubkey = bech_key.ends_with(cur_vanity_npub.as_str());

Expand All @@ -184,7 +189,6 @@ fn main() -> Result<(), Box<dyn Error>> {
}
}
}

} else {
// difficulty search
leading_zeroes = get_leading_zero_bits(&xonly_public_key.serialize());
Expand Down

0 comments on commit 3e8f8ff

Please sign in to comment.