Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
grunch committed Feb 1, 2023
1 parent cec1c59 commit 627cf1e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rana"
version = "0.4.1"
version = "0.5.0"
edition = "2021"
license = "MIT"
authors = ["Francisco Calderón <[email protected]>"]
Expand Down
7 changes: 1 addition & 6 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,21 @@ targets as a comma-separated list."
)]
pub num_cores: usize,


#[arg(
short = 'r',
long = "restore",
help = "Restore from mnemonic to public private key",
default_value_t = String::from(""),
required = false
)]
pub mnemonic: String,


#[arg(
short = 'g',
long = "generate",
help = "Generate mnemonic using wordcount. Should be 12,18 or 24",
default_value_t = 0,
required = false
)]
pub word_count: usize,

Expand All @@ -90,10 +86,9 @@ targets as a comma-separated list."
help = "Passphrase used for restoring mnemonic to keypair",
default_value_t = String::from(""),
required = false
)]
pub mnemonic_passphrase: String,

#[arg(
short,
long = "qr",
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod cli;
pub mod tests;
pub mod mnemonic;
pub mod utils;
pub mod tests;
pub mod utils;
11 changes: 4 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let parsed_args = CLIArgs::parse();

// Handle mnemonic part if arguments is set
if parsed_args.mnemonic.len() > 0 {
if !parsed_args.mnemonic.is_empty() {
handle_mnemonic(&parsed_args);
}

Expand Down Expand Up @@ -155,7 +155,7 @@ fn main() -> Result<(), Box<dyn Error>> {
uses_mnemonic = Some(mnemonic.clone());
keys = Keys::from_mnemonic(
mnemonic.to_string(),
Some(format!("{}", passphrase.as_str())),
Some(passphrase.as_str().to_string()),
)
.expect("Error generating keys from mnemonic");
hexa_key = keys.public_key().to_hex();
Expand Down Expand Up @@ -254,11 +254,8 @@ fn main() -> Result<(), Box<dyn Error>> {
}

let mut mnemonic_str = None;
match uses_mnemonic {
Some(mnemonic_obj) => {
mnemonic_str = Some(mnemonic_obj.to_string());
}
None => {}
if let Some(mnemonic_obj) = uses_mnemonic {
mnemonic_str = Some(mnemonic_obj.to_string());
}

// if one of the required conditions is satisfied
Expand Down
4 changes: 2 additions & 2 deletions src/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use nostr_sdk::prelude::{FromMnemonic, GenerateMnemonic, Keys, ToBech32};
pub fn handle_mnemonic(parsed_args: &CLIArgs) {
if parsed_args.word_count > 0 {
let mut word_count = parsed_args.word_count;
if parsed_args.word_count <= 0 || parsed_args.word_count > 24 {
if parsed_args.word_count == 0 || parsed_args.word_count > 24 {
word_count = 12;
}
let mnemonic = Keys::generate_mnemonic(word_count).expect("Couldn't not generate mnemonic");
Expand All @@ -31,7 +31,7 @@ pub fn handle_mnemonic(parsed_args: &CLIArgs) {
exit(0)
}

if parsed_args.mnemonic.len() > 0 {
if !parsed_args.mnemonic.is_empty() {
let keys = Keys::from_mnemonic(
parsed_args.mnemonic.to_string(),
Some(parsed_args.mnemonic_passphrase.to_string()),
Expand Down
12 changes: 4 additions & 8 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ pub fn print_keys(

println!("Found matching public key: {xonly_public_key}");

let private_hex = secret_key.clone();
println!("Nostr private key: {private_hex:>72}");
println!("Nostr private key: {secret_key:>72}");

println!(
"Nostr public key (npub): {:>65}",
Expand All @@ -62,15 +61,12 @@ pub fn print_keys(
"Nostr private key (nsec): {:>64}",
bech32::encode(
"nsec",
hex::decode(private_hex)?.to_base32(),
hex::decode(secret_key)?.to_base32(),
Variant::Bech32
)?
);
match mnemonic {
Some(mnemonic_value) => {
println!("Mnemonic: {}", mnemonic_value);
}
None => {}
if let Some(mnemonic_value) = mnemonic {
println!("Mnemonic: {}", mnemonic_value);
}

Ok(())
Expand Down

0 comments on commit 627cf1e

Please sign in to comment.