Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Prev Previous commit
Next Next commit
More clean up
  • Loading branch information
tomaka committed Oct 30, 2019
commit bf9c5ed37f117d1231ea2241fbddeb8154dcda4f
39 changes: 28 additions & 11 deletions node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
log = "0.4.8"
tokio = { version = "0.1.22", optional = true }
futures = "0.1.29"
exit-future = { version = "0.1.4", optional = true }
jsonrpc-core = "13.2.0"
substrate-cli = { path = "../../core/cli", optional = true }
codec = { package = "parity-scale-codec", version = "1.0.0" }
sr-io = { path = "../../core/sr-io" }
client = { package = "substrate-client", path = "../../core/client" }
Expand All @@ -51,7 +48,6 @@ sr-primitives = { path = "../../core/sr-primitives" }
node-executor = { path = "../executor" }
substrate-telemetry = { package = "substrate-telemetry", path = "../../core/telemetry" }
structopt = "0.3.3"
transaction-factory = { path = "../../test-utils/transaction-factory", optional = true }
keyring = { package = "substrate-keyring", path = "../../core/keyring" }
indices = { package = "srml-indices", path = "../../srml/indices" }
timestamp = { package = "srml-timestamp", path = "../../srml/timestamp", default-features = false }
Expand All @@ -66,19 +62,24 @@ im_online = { package = "srml-im-online", path = "../../srml/im-online", default
serde = { version = "1.0.101", features = [ "derive" ] }
client_db = { package = "substrate-client-db", path = "../../core/client/db", default-features = false }
offchain = { package = "substrate-offchain", path = "../../core/offchain" }

# CLI-specific dependencies
tokio = { version = "0.1.22", optional = true }
exit-future = { version = "0.1.4", optional = true }
substrate-cli = { path = "../../core/cli", optional = true }
transaction-factory = { path = "../../test-utils/transaction-factory", optional = true }
ctrlc = { version = "3.1.3", features = ["termination"], optional = true }

# WASM-specific dependencies
libp2p = { version = "0.12.0", default-features = false, optional = true }
clear_on_drop = { version = "0.2.3", features = ["no_cc"], optional = true }
clear_on_drop = { version = "0.2.3", features = ["no_cc"], optional = true } # Imported just for the `no_cc` feature
console_error_panic_hook = { version = "0.1.1", optional = true }
console_log = { version = "0.1.2", optional = true }
js-sys = { version = "0.3.22", optional = true }
wasm-bindgen = { version = "0.2.45", optional = true }
wasm-bindgen-futures = { version = "0.3.22", optional = true }
kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d", optional = true }
# TODO: need the feature
rand6 = { package = "rand", version = "0.6", features = ["wasm-bindgen"] }
rand6 = { package = "rand", version = "0.6", features = ["wasm-bindgen"], optional = true } # Imported just for the `wasm-bindgen` feature

[dev-dependencies]
keystore = { package = "substrate-keystore", path = "../../core/keystore" }
Expand All @@ -95,7 +96,23 @@ vergen = "3.0.4"

[features]
default = ["cli"]
# TODO: docs
browser = ["clear_on_drop", "console_error_panic_hook", "console_log", "js-sys", "libp2p", "wasm-bindgen", "wasm-bindgen-futures", "kvdb-memorydb", "rand/wasm-bindgen"]
# TODO: docs
cli = ["substrate-cli", "transaction-factory", "tokio", "exit-future", "ctrlc", "client_db/kvdb-rocksdb"]
browser = [
"clear_on_drop",
"console_error_panic_hook",
"console_log",
"js-sys",
"libp2p",
"wasm-bindgen",
"wasm-bindgen-futures",
"kvdb-memorydb",
"rand/wasm-bindgen",
"rand6"
]
cli = [
"substrate-cli",
"transaction-factory",
"tokio",
"exit-future",
"ctrlc",
"client_db/kvdb-rocksdb"
]
2 changes: 1 addition & 1 deletion node/cli/browser-demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
```sh
cargo install wasm-pack # If necessary

# From the `node-browser` directory (parent from this README)
# From the `node/cli` directory (parent from this README)
wasm-pack build --target web --out-dir ./demo/pkg --no-typescript --release -- --no-default-features --features "browser"

xdg-open index.html
Expand Down
47 changes: 27 additions & 20 deletions node/cli/src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use substrate_service::{AbstractService, RpcSession, Roles as ServiceRoles, Conf
use wasm_bindgen::prelude::*;

/// Starts the client.
///
/// You must pass a libp2p transport that supports .
#[wasm_bindgen]
pub fn start_client(wasm_ext: wasm_ext::ffi::Transport) -> Result<Client, JsValue> {
start_inner(wasm_ext)
Expand All @@ -35,35 +37,40 @@ fn start_inner(wasm_ext: wasm_ext::ffi::Transport) -> Result<Client, Box<dyn std
console_error_panic_hook::set_once();
console_log::init_with_level(log::Level::Info);

let wasm_ext = wasm_ext::ExtTransport::new(wasm_ext);

let chain_spec = ChainSpec::FlamingFir.load().map_err(|e| format!("{:?}", e))?;
let mut config = Configuration::<(), _, _>::default_with_spec(chain_spec);
config.network.transport = network::config::TransportConfig::Normal {
wasm_external_transport: Some(wasm_ext.clone()),
enable_mdns: false,
};
config.telemetry_external_transport = Some(wasm_ext);
config.roles = ServiceRoles::FULL;
config.name = "Browser node".to_string();
config.database = {
let db = Arc::new(kvdb_memorydb::create(10));
DatabaseConfig::Custom(db)
// Build the configuration to pass to the service.
let config = {
let wasm_ext = wasm_ext::ExtTransport::new(wasm_ext);
let chain_spec = ChainSpec::FlamingFir.load().map_err(|e| format!("{:?}", e))?;
let mut config = Configuration::<(), _, _>::default_with_spec(chain_spec);
config.network.transport = network::config::TransportConfig::Normal {
wasm_external_transport: Some(wasm_ext.clone()),
enable_mdns: false,
};
config.telemetry_external_transport = Some(wasm_ext);
config.roles = ServiceRoles::LIGHT;
config.name = "Browser node".to_string();
config.database = {
let db = Arc::new(kvdb_memorydb::create(10));
DatabaseConfig::Custom(db)
};
config
};

//info!("{}", version.name);
info!("Substrate browser node");
info!(" version {}", config.full_version());
info!(" by Parity Technologies, 2017-2019");
info!("Chain specification: {}", config.chain_spec.name());
info!("Node name: {}", config.name);
info!("Roles: {:?}", config.roles);

let mut service = new_full!(config)
.map_err(|e: String| format!("{:?}", e))?.0;

/*let informant = substrate_cli::informant::build(&service);
wasm_bindgen_futures::spawn_local(informant);*/
// Create the service. This is the most heavy initialization step.
let mut service = crate::service::new_light(config).map_err(|e| format!("{:?}", e))?;

// We now dispatch a background task responsible for processing the service.
//
// The main action performed by the code below consists in polling the service with
// `service.poll()`.
// The rest consists in handling RPC requests.
let (rpc_send_tx, mut rpc_send_rx) = mpsc::unbounded::<RpcMessage>();
wasm_bindgen_futures::spawn_local(futures::future::poll_fn(move || {
loop {
Expand Down
10 changes: 10 additions & 0 deletions node/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Substrate CLI library.
//!
//! This package has two Cargo features:
//!
//! - `cli` (default): exposes functions that parse command-line options, then start and run the
//! node as a CLI application.
//!
//! - `browser`: exposes the content of the `browser` module, which consists of exported symbols
//! that are meant to be passed through the `wasm-bindgen` utility and called from JavaScript.
//! Despite its name the produced WASM can theoretically also be used from NodeJS, although this
//! hasn't been tested.

#![warn(missing_docs)]
#![warn(unused_extern_crates)]
Expand Down