Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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",
]
2 changes: 1 addition & 1 deletion cli/browser-demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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"}',
Expand Down
34 changes: 19 additions & 15 deletions cli/src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}