mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 12:51:02 +00:00
Fix cli/browser.rs and allow selecting a chainspec on wasm. (#815)
* Fix browser.rs * Apply suggestions from code review Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Generated
-1
@@ -3753,7 +3753,6 @@ dependencies = [
|
|||||||
"sc-client-api 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
|
"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-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-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-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-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)",
|
"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"
|
log = "0.4.8"
|
||||||
futures = { version = "0.3.1", features = ["compat"] }
|
futures = { version = "0.3.1", features = ["compat"] }
|
||||||
structopt = "0.3.8"
|
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-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||||
sp-core = { 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" }
|
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 = { version = "0.2.57", optional = true }
|
||||||
wasm-bindgen-futures = { version = "0.4.7", 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 }
|
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]
|
[features]
|
||||||
default = [ "wasmtime", "rocksdb", "cli" ]
|
default = [ "wasmtime", "rocksdb", "cli" ]
|
||||||
wasmtime = [ "sc-cli/wasmtime" ]
|
wasmtime = [ "sc-cli/wasmtime" ]
|
||||||
rocksdb = [ "service/rocksdb" ]
|
rocksdb = [ "service/rocksdb" ]
|
||||||
cli = [ "tokio" ]
|
cli = [
|
||||||
|
"tokio",
|
||||||
|
"sc-cli",
|
||||||
|
]
|
||||||
browser = [
|
browser = [
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-futures",
|
"wasm-bindgen-futures",
|
||||||
"browser-utils",
|
"browser-utils",
|
||||||
"substrate-service",
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ async function start() {
|
|||||||
|
|
||||||
// Build our client.
|
// Build our client.
|
||||||
log('Starting client');
|
log('Starting client');
|
||||||
let client = await start_client(ws());
|
let client = await start_client('westend', ws());
|
||||||
log('Client started');
|
log('Client started');
|
||||||
|
|
||||||
client.rpcSubscribe('{"method":"chain_subscribeNewHead","params":[],"id":1,"jsonrpc":"2.0"}',
|
client.rpcSubscribe('{"method":"chain_subscribeNewHead","params":[],"id":1,"jsonrpc":"2.0"}',
|
||||||
|
|||||||
+14
-10
@@ -16,44 +16,48 @@
|
|||||||
|
|
||||||
use crate::ChainSpec;
|
use crate::ChainSpec;
|
||||||
use log::info;
|
use log::info;
|
||||||
use substrate_service::Configuration;
|
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
use service::CustomConfiguration;
|
use service::IsKusama;
|
||||||
|
|
||||||
/// Starts the client.
|
/// Starts the client.
|
||||||
///
|
///
|
||||||
/// You must pass a libp2p transport that supports .
|
/// You must pass a libp2p transport that supports .
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub async fn start_client(wasm_ext: browser_utils::Transport) -> Result<browser_utils::Client, JsValue> {
|
pub async fn start_client(chain_spec: String, wasm_ext: browser_utils::Transport) -> Result<browser_utils::Client, JsValue> {
|
||||||
start_inner(wasm_ext)
|
start_inner(chain_spec, wasm_ext)
|
||||||
.await
|
.await
|
||||||
.map_err(|err| JsValue::from_str(&err.to_string()))
|
.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::set_console_error_panic_hook();
|
||||||
browser_utils::init_console_log(log::Level::Info)?;
|
browser_utils::init_console_log(log::Level::Info)?;
|
||||||
|
|
||||||
let chain_spec = ChainSpec::Kusama.load().map_err(|e| format!("{:?}", e))?;
|
let chain_spec = ChainSpec::from(&chain_spec)
|
||||||
let config: Configuration<CustomConfiguration, _, _> = browser_utils::browser_configuration(wasm_ext, 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?;
|
.await?;
|
||||||
|
|
||||||
info!("Polkadot browser node");
|
info!("Polkadot browser node");
|
||||||
info!(" version {}", config.full_version());
|
info!(" version {}", config.full_version());
|
||||||
info!(" by Parity Technologies, 2017-2019");
|
info!(" by Parity Technologies, 2017-2019");
|
||||||
info!("Chain specification: {}", config.chain_spec.name());
|
if let Some(chain_spec) = &config.chain_spec {
|
||||||
if config.chain_spec.name().starts_with("Kusama") {
|
info!("Chain specification: {}", chain_spec.name());
|
||||||
|
if chain_spec.is_kusama() {
|
||||||
info!("----------------------------");
|
info!("----------------------------");
|
||||||
info!("This chain is not in any way");
|
info!("This chain is not in any way");
|
||||||
info!(" endorsed by the ");
|
info!(" endorsed by the ");
|
||||||
info!(" KUSAMA FOUNDATION ");
|
info!(" KUSAMA FOUNDATION ");
|
||||||
info!("----------------------------");
|
info!("----------------------------");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
info!("Node name: {}", config.name);
|
info!("Node name: {}", config.name);
|
||||||
info!("Roles: {:?}", config.roles);
|
info!("Roles: {:?}", config.roles);
|
||||||
|
|
||||||
// Create the service. This is the most heavy initialization step.
|
// 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))
|
Ok(browser_utils::start_client(service))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user