Skip to content

Commit

Permalink
[cli/wallet] nicer output when for empty wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Oct 6, 2021
1 parent af722ba commit 7437dc2
Showing 1 changed file with 47 additions and 30 deletions.
77 changes: 47 additions & 30 deletions apps/src/bin/anoma-wallet/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,32 +109,41 @@ fn key_list(
}: args::KeyList,
) {
let wallet = ctx.wallet;
let stdout = io::stdout();
let mut w = stdout.lock();
writeln!(w, "Known keys:").unwrap();
for (alias, (stored_keypair, pkh)) in wallet.get_keys() {
let encrypted = if stored_keypair.is_encrypted() {
"encrypted"
} else {
"not encrypted"
};
writeln!(w, " Alias \"{}\" ({}):", alias, encrypted).unwrap();
if let Some(pkh) = pkh {
writeln!(w, " Public key hash: {}", pkh).unwrap();
}
match stored_keypair.get(decrypt) {
Ok(keypair) => {
writeln!(w, " Public key: {}", keypair.public).unwrap();
if unsafe_show_secret {
writeln!(w, " Secret key: {}", keypair.secret).unwrap();
}
}
Err(DecryptionError::NotDecrypting) if !decrypt => {
continue;
let known_keys = wallet.get_keys();
if known_keys.is_empty() {
println!(
"No known keys. Try `key gen --alias my-key` to generate a new \
key."
);
} else {
let stdout = io::stdout();
let mut w = stdout.lock();
writeln!(w, "Known keys:").unwrap();
for (alias, (stored_keypair, pkh)) in known_keys {
let encrypted = if stored_keypair.is_encrypted() {
"encrypted"
} else {
"not encrypted"
};
writeln!(w, " Alias \"{}\" ({}):", alias, encrypted).unwrap();
if let Some(pkh) = pkh {
writeln!(w, " Public key hash: {}", pkh).unwrap();
}
Err(err) => {
writeln!(w, " Couldn't decrypt the keypair: {}", err)
.unwrap();
match stored_keypair.get(decrypt) {
Ok(keypair) => {
writeln!(w, " Public key: {}", keypair.public).unwrap();
if unsafe_show_secret {
writeln!(w, " Secret key: {}", keypair.secret)
.unwrap();
}
}
Err(DecryptionError::NotDecrypting) if !decrypt => {
continue;
}
Err(err) => {
writeln!(w, " Couldn't decrypt the keypair: {}", err)
.unwrap();
}
}
}
}
Expand Down Expand Up @@ -164,11 +173,19 @@ fn key_export(ctx: Context, args::KeyExport { alias }: args::KeyExport) {
/// List all known addresses.
fn address_list(ctx: Context) {
let wallet = ctx.wallet;
let stdout = io::stdout();
let mut w = stdout.lock();
writeln!(w, "Known addresses:").unwrap();
for (alias, address) in sorted(wallet.get_addresses()) {
writeln!(w, " \"{}\": {}", alias, address).unwrap();
let known_addresses = wallet.get_addresses();
if known_addresses.is_empty() {
println!(
"No known addresses. Try `address gen --alias my-addr` to \
generate a new implicit address."
);
} else {
let stdout = io::stdout();
let mut w = stdout.lock();
writeln!(w, "Known addresses:").unwrap();
for (alias, address) in sorted(known_addresses) {
writeln!(w, " \"{}\": {}", alias, address).unwrap();
}
}
}

Expand Down

0 comments on commit 7437dc2

Please sign in to comment.