Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Show network id/version in subkey #5457

Merged
merged 2 commits into from
Mar 30, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions bin/utils/subkey/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ trait Crypto: Sized {
) where
<Self::Pair as Pair>::Public: PublicT,
{
let v = network_override.unwrap_or(Ss58AddressFormat::default());
yanganto marked this conversation as resolved.
Show resolved Hide resolved
if let Ok((pair, seed)) = Self::Pair::from_phrase(uri, password) {
let public_key = Self::public_from_pair(&pair);

match output {
OutputType::Json => {
let json = json!({
"secretPhrase": uri,
"networkId": String::from(v),
"secretSeed": format_seed::<Self>(seed),
"publicKey": format_public_key::<Self>(public_key.clone()),
"accountId": format_account_id::<Self>(public_key),
Expand All @@ -95,11 +97,13 @@ trait Crypto: Sized {
},
OutputType::Text => {
println!("Secret phrase `{}` is account:\n \
Secret seed: {}\n \
Public key (hex): {}\n \
Account ID: {}\n \
SS58 Address: {}",
Network ID/version: {}\n \
Secret seed: {}\n \
Public key (hex): {}\n \
Account ID: {}\n \
SS58 Address: {}",
uri,
String::from(v),
format_seed::<Self>(seed),
format_public_key::<Self>(public_key.clone()),
format_account_id::<Self>(public_key),
Expand All @@ -114,6 +118,7 @@ trait Crypto: Sized {
OutputType::Json => {
let json = json!({
"secretKeyUri": uri,
"networkId": String::from(v),
"secretSeed": if let Some(seed) = seed { format_seed::<Self>(seed) } else { "n/a".into() },
"publicKey": format_public_key::<Self>(public_key.clone()),
"accountId": format_account_id::<Self>(public_key),
Expand All @@ -123,11 +128,13 @@ trait Crypto: Sized {
},
OutputType::Text => {
println!("Secret Key URI `{}` is account:\n \
Secret seed: {}\n \
Public key (hex): {}\n \
Account ID: {}\n \
SS58 Address: {}",
Network ID/version: {}\n \
Secret seed: {}\n \
Public key (hex): {}\n \
Account ID: {}\n \
SS58 Address: {}",
uri,
String::from(v),
if let Some(seed) = seed { format_seed::<Self>(seed) } else { "n/a".into() },
format_public_key::<Self>(public_key.clone()),
format_account_id::<Self>(public_key),
Expand Down