Skip to content

Commit

Permalink
Add solana_address to JSON output.
Browse files Browse the repository at this point in the history
Co-authored-by: thiery <thiery.louis@gmail.com>
  • Loading branch information
ke6jjj and lthiery committed Mar 10, 2023
1 parent b446163 commit 619c70b
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/cmd/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,20 @@ fn print_wallet(wallet: &Wallet, account: &Account, format: OutputFormat) -> Res
print_table(&table, None)
}
OutputFormat::Json => {
let mut value = json!({});
let table = value.as_object_mut().unwrap();
table.insert(String::from("sharded"), json!(wallet.is_sharded()));
table.insert(String::from("network"), json!(wallet.public_key.key_tag().network.to_string()));
table.insert(String::from("type"), json!(wallet.public_key.key_tag().key_type.to_string()));
table.insert(String::from("pwhash"), json!(wallet.pwhash().to_string()));
table.insert(String::from("account"), json!(account));
// if this is an ED25519 key type, result will be the Solana address
if let Ok(solana_key) = solana_sdk::pubkey::Pubkey::try_from(wallet.public_key.clone())
{
table.insert(String::from("solana_address"), json!(solana_key.to_string()));
}
print_json(&table)
let json = json!({
"sharded": wallet.is_sharded(),
"network": wallet.public_key.key_tag().network.to_string(),
"type": wallet.public_key.key_tag().key_type.to_string(),
"pwhash": wallet.pwhash().to_string(),
"account": account,
"solana_address": if let Ok(solana_key) = solana_sdk::pubkey::Pubkey::try_from(wallet.public_key.clone())
{
Some(solana_key.to_string())
} else {
None
}
});
print_json(&json)
}
}
}

0 comments on commit 619c70b

Please sign in to comment.