diff --git a/Cargo.lock b/Cargo.lock index e99226fb1fff..db27baf9f731 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3753,7 +3753,6 @@ dependencies = [ "sc-client-api 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", "sc-client-db 0.8.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", "sc-executor 0.8.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", - "sc-service 0.8.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", "sp-api 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", "sp-core 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", "sp-runtime 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 9369917d6ab4..725af3bc250e 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["cdylib", "rlib"] log = "0.4.8" futures = { version = "0.3.1", features = ["compat"] } structopt = "0.3.8" -sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } +sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true } sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } @@ -27,16 +27,17 @@ tokio = { version = "0.2.10", features = ["rt-threaded"], optional = true } wasm-bindgen = { version = "0.2.57", optional = true } wasm-bindgen-futures = { version = "0.4.7", optional = true } browser-utils = { package = "browser-utils", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true } -substrate-service = { package = "sc-service", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true, default-features = false } [features] default = [ "wasmtime", "rocksdb", "cli" ] wasmtime = [ "sc-cli/wasmtime" ] rocksdb = [ "service/rocksdb" ] -cli = [ "tokio" ] +cli = [ + "tokio", + "sc-cli", +] browser = [ "wasm-bindgen", "wasm-bindgen-futures", "browser-utils", - "substrate-service", ] diff --git a/cli/browser-demo/index.html b/cli/browser-demo/index.html index 234fc3d9b92d..b039b0e957a1 100644 --- a/cli/browser-demo/index.html +++ b/cli/browser-demo/index.html @@ -19,7 +19,7 @@ // Build our client. log('Starting client'); - let client = await start_client(ws()); + let client = await start_client('westend', ws()); log('Client started'); client.rpcSubscribe('{"method":"chain_subscribeNewHead","params":[],"id":1,"jsonrpc":"2.0"}', diff --git a/cli/src/browser.rs b/cli/src/browser.rs index 32b03fcc8842..0564bb9edab1 100644 --- a/cli/src/browser.rs +++ b/cli/src/browser.rs @@ -16,44 +16,48 @@ use crate::ChainSpec; use log::info; -use substrate_service::Configuration; use wasm_bindgen::prelude::*; -use service::CustomConfiguration; +use service::IsKusama; /// Starts the client. /// /// You must pass a libp2p transport that supports . #[wasm_bindgen] -pub async fn start_client(wasm_ext: browser_utils::Transport) -> Result { - start_inner(wasm_ext) +pub async fn start_client(chain_spec: String, wasm_ext: browser_utils::Transport) -> Result { + start_inner(chain_spec, wasm_ext) .await .map_err(|err| JsValue::from_str(&err.to_string())) } -async fn start_inner(wasm_ext: browser_utils::Transport) -> Result> { +async fn start_inner(chain_spec: String, wasm_ext: browser_utils::Transport) -> Result> { browser_utils::set_console_error_panic_hook(); browser_utils::init_console_log(log::Level::Info)?; - let chain_spec = ChainSpec::Kusama.load().map_err(|e| format!("{:?}", e))?; - let config: Configuration = browser_utils::browser_configuration(wasm_ext, chain_spec) + let chain_spec = ChainSpec::from(&chain_spec) + .ok_or_else(|| format!("Chain spec: {:?} doesn't exist.", chain_spec))? + .load() + .map_err(|e| format!("{:?}", e))?; + let config = browser_utils::browser_configuration(wasm_ext, chain_spec) .await?; info!("Polkadot browser node"); info!(" version {}", config.full_version()); info!(" by Parity Technologies, 2017-2019"); - info!("Chain specification: {}", config.chain_spec.name()); - if config.chain_spec.name().starts_with("Kusama") { - info!("----------------------------"); - info!("This chain is not in any way"); - info!(" endorsed by the "); - info!(" KUSAMA FOUNDATION "); - info!("----------------------------"); + if let Some(chain_spec) = &config.chain_spec { + info!("Chain specification: {}", chain_spec.name()); + if chain_spec.is_kusama() { + info!("----------------------------"); + info!("This chain is not in any way"); + info!(" endorsed by the "); + info!(" KUSAMA FOUNDATION "); + info!("----------------------------"); + } } info!("Node name: {}", config.name); info!("Roles: {:?}", config.roles); // Create the service. This is the most heavy initialization step. - let service = service::kusama_new_light(config).map_err(|e| format!("{:?}", e))?; + let service = service::kusama_new_light(config, None).map_err(|e| format!("{:?}", e))?; Ok(browser_utils::start_client(service)) }