Skip to content

Commit

Permalink
Merge pull request #16 from diegogurpegui/main
Browse files Browse the repository at this point in the history
Disallow both hexa and bech32 vanity at the same time
  • Loading branch information
grunch authored Jan 9, 2023
2 parents 35d6130 + 1f65534 commit 3a27f68
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ pub struct CLIArgs {
required = false,
default_value = "",
help = "Enter the prefix your public key should have when expressed
as hexadecimal. This can be combined with --vanity-n,
but beware of extra calculations required."
as hexadecimal."
)]
pub vanity_prefix: String,
#[arg(
Expand All @@ -42,17 +41,27 @@ but beware of extra calculations required."
default_value = "",
help = "Enter the prefix your public key should have when expressed
in npub format (Bech32 encoding). Specify multiple vanity
targets as a comma-separated list.
This can be combined with --vanity, but beware of extra
calculations required."
targets as a comma-separated list."
)]
pub vanity_npub_prefixes_raw_input: String,
}

pub fn check_args(difficulty: u8, vanity_prefix: &str, vanity_npub_prefixes: &Vec<String>) {
if difficulty > 0 && (!vanity_prefix.is_empty() || !vanity_npub_prefixes.is_empty()) {
panic!("You can cannot specify difficulty and vanity at the same time.");
// Check the public key requirements
let mut requirements_count: u8 = 0;
if difficulty > 0 {
requirements_count += 1;
}
if !vanity_prefix.is_empty() {
requirements_count += 1;
}
if !vanity_npub_prefixes.is_empty() {
requirements_count += 1;
}
if requirements_count > 1 {
panic!("You can cannot specify more than one requirement. You should choose between difficulty or any of the vanity formats.");
}

if vanity_prefix.len() > 64 {
panic!("The vanity prefix cannot be longer than 64 characters.");
}
Expand Down

0 comments on commit 3a27f68

Please sign in to comment.