Unverified Commit 06921c52 authored by Ashley's avatar Ashley Committed by GitHub
Browse files

Fix cli/browser.rs and allow selecting a chainspec on wasm. (#815)



* Fix browser.rs

* Apply suggestions from code review
Co-authored-by: default avatarBastian Köcher <bkchr@users.noreply.github.com>
parent ab1fa78e
Pipeline #76874 passed with stages
in 21 minutes and 50 seconds
......@@ -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)",
......
......@@ -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",
]
......@@ -19,7 +19,7 @@ async function start() {
// 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"}',
......
......@@ -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<browser_utils::Client, JsValue> {
start_inner(wasm_ext)
pub async fn start_client(chain_spec: String, wasm_ext: browser_utils::Transport) -> Result<browser_utils::Client, JsValue> {
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<browser_utils::Client, Box<dyn std::error::Error>> {
async fn start_inner(chain_spec: String, wasm_ext: browser_utils::Transport) -> Result<browser_utils::Client, Box<dyn std::error::Error>> {
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<CustomConfiguration, _, _> = 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))
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment