Show network id/version in subkey (#5457)

* Show network id/version in subkey

- show network id/version when creating
- show network id/version when inspecting

* Update bin/utils/subkey/src/main.rs

use `unwrap_or_default` for more clean syntax

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
yanganto
2020-03-31 06:13:39 +08:00
committed by GitHub
parent 0bc0d4bebb
commit 77b9771bfd
+15 -8
View File
@@ -79,6 +79,7 @@ trait Crypto: Sized {
) where
<Self::Pair as Pair>::Public: PublicT,
{
let v = network_override.unwrap_or_default();
if let Ok((pair, seed)) = Self::Pair::from_phrase(uri, password) {
let public_key = Self::public_from_pair(&pair);
@@ -86,6 +87,7 @@ trait Crypto: Sized {
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),
@@ -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),
@@ -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),
@@ -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),