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

Commit

Permalink
cli: set default ss58 address format for each chain (#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
andresilva authored May 21, 2020
1 parent cee1a93 commit 18d6d3f
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,35 @@ impl SubstrateCli for Cli {
pub fn run() -> Result<()> {
let cli = Cli::from_args();

fn set_default_ss58_version(spec: &Box<dyn service::ChainSpec>) {
use sp_core::crypto::Ss58AddressFormat;

let ss58_version = if spec.is_kusama() {
Ss58AddressFormat::KusamaAccount
} else if spec.is_westend() {
Ss58AddressFormat::SubstrateAccount
} else {
Ss58AddressFormat::PolkadotAccount
};

sp_core::crypto::set_default_ss58_version(ss58_version);
};

match &cli.subcommand {
None => {
let runtime = cli.create_runner(&cli.run.base)?;
let config = runtime.config();
let chain_spec = &runtime.config().chain_spec;

set_default_ss58_version(chain_spec);

let authority_discovery_enabled = cli.run.authority_discovery_enabled;
let grandpa_pause = if cli.run.grandpa_pause.is_empty() {
None
} else {
Some((cli.run.grandpa_pause[0], cli.run.grandpa_pause[1]))
};

if config.chain_spec.is_kusama() {
if chain_spec.is_kusama() {
info!("----------------------------");
info!("This chain is not in any way");
info!(" endorsed by the ");
Expand All @@ -97,7 +114,7 @@ pub fn run() -> Result<()> {
},
service::KusamaExecutor::native_version().runtime_version
)
} else if config.chain_spec.is_westend() {
} else if chain_spec.is_westend() {
runtime.run_node(
|config| {
service::westend_new_light(config)
Expand Down Expand Up @@ -135,16 +152,19 @@ pub fn run() -> Result<()> {
},
Some(Subcommand::Base(subcommand)) => {
let runtime = cli.create_runner(subcommand)?;
let chain_spec = &runtime.config().chain_spec;

set_default_ss58_version(chain_spec);

if runtime.config().chain_spec.is_kusama() {
if chain_spec.is_kusama() {
runtime.run_subcommand(subcommand, |config|
service::new_chain_ops::<
service::kusama_runtime::RuntimeApi,
service::KusamaExecutor,
service::kusama_runtime::UncheckedExtrinsic,
>(config)
)
} else if runtime.config().chain_spec.is_westend() {
} else if chain_spec.is_westend() {
runtime.run_subcommand(subcommand, |config|
service::new_chain_ops::<
service::westend_runtime::RuntimeApi,
Expand Down Expand Up @@ -175,12 +195,15 @@ pub fn run() -> Result<()> {
},
Some(Subcommand::Benchmark(cmd)) => {
let runtime = cli.create_runner(cmd)?;
let chain_spec = &runtime.config().chain_spec;

set_default_ss58_version(chain_spec);

if runtime.config().chain_spec.is_kusama() {
if chain_spec.is_kusama() {
runtime.sync_run(|config| {
cmd.run::<service::kusama_runtime::Block, service::KusamaExecutor>(config)
})
} else if runtime.config().chain_spec.is_westend() {
} else if chain_spec.is_westend() {
runtime.sync_run(|config| {
cmd.run::<service::westend_runtime::Block, service::WestendExecutor>(config)
})
Expand Down

0 comments on commit 18d6d3f

Please sign in to comment.