Skip to content

Commit

Permalink
Inspection extension to node CLI (paritytech#4697)
Browse files Browse the repository at this point in the history
* Initial inspect.

* WiP

* Add parsing tests.

* Finalize CLI.

* Update to latest substrate.

* Remove unused imports.

* Support ImportParams as well, to get the right pruning setting.

* Mention in docs that hash is no 0x.

* Move bytes above extrinsics.

* Switch to fill helper from sc_cli.

* Remove overwrite.

* Fix error.

* Fix error message.

* Remove extra allow.

* init_config
  • Loading branch information
tomusdrw authored Feb 18, 2020
1 parent c1a03a6 commit d9952dd
Show file tree
Hide file tree
Showing 11 changed files with 517 additions and 11 deletions.
19 changes: 18 additions & 1 deletion Cargo.lock

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

9 changes: 6 additions & 3 deletions bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ node-executor = { version = "2.0.0", path = "../executor" }
# CLI-specific dependencies
sc-cli = { version = "0.8.0", optional = true, path = "../../../client/cli" }
node-transaction-factory = { version = "0.8.0", optional = true, path = "../transaction-factory" }
node-inspect = { version = "0.8.0", optional = true, path = "../inspect" }

# WASM-specific dependencies
wasm-bindgen = { version = "0.2.57", optional = true }
Expand All @@ -110,6 +111,7 @@ nix = "0.17"
build-script-utils = { version = "2.0.0", package = "substrate-build-script-utils", path = "../../../utils/build-script-utils" }
structopt = { version = "0.3.8", optional = true }
node-transaction-factory = { version = "0.8.0", optional = true, path = "../transaction-factory" }
node-inspect = { version = "0.8.0", optional = true, path = "../inspect" }

[build-dependencies.sc-cli]
version = "0.8.0"
Expand All @@ -129,12 +131,13 @@ browser = [
"wasm-bindgen-futures",
]
cli = [
"sc-cli",
"node-executor/wasmi-errno",
"node-inspect",
"node-transaction-factory",
"sc-cli",
"sc-service/rocksdb",
"node-executor/wasmi-errno",
"vergen",
"structopt",
"vergen",
]
wasmtime = [
"cli",
Expand Down
15 changes: 11 additions & 4 deletions bin/node/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@
use sc_cli::{SharedParams, ImportParams, RunCmd};
use structopt::StructOpt;

#[allow(missing_docs)]
/// An overarching CLI command definition.
#[derive(Clone, Debug, StructOpt)]
#[structopt(settings = &[
structopt::clap::AppSettings::GlobalVersion,
structopt::clap::AppSettings::ArgsNegateSubcommands,
structopt::clap::AppSettings::SubcommandsNegateReqs,
])]
pub struct Cli {
#[allow(missing_docs)]
/// Possible subcommand with parameters.
#[structopt(subcommand)]
pub subcommand: Option<Subcommand>,
#[allow(missing_docs)]
#[structopt(flatten)]
pub run: RunCmd,
}

#[allow(missing_docs)]
/// Possible subcommands of the main binary.
#[derive(Clone, Debug, StructOpt)]
pub enum Subcommand {
#[allow(missing_docs)]
/// A set of base subcommands handled by `sc_cli`.
#[structopt(flatten)]
Base(sc_cli::Subcommand),
/// The custom factory subcommmand for manufacturing transactions.
Expand All @@ -46,6 +46,13 @@ pub enum Subcommand {
Only supported for development or local testnet."
)]
Factory(FactoryCmd),

/// The custom inspect subcommmand for decoding blocks and extrinsics.
#[structopt(
name = "inspect",
about = "Decode given block or extrinsic using current native runtime."
)]
Inspect(node_inspect::cli::InspectCmd),
}

/// The `factory` command used to generate transactions.
Expand Down
10 changes: 10 additions & 0 deletions bin/node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ where
load_spec,
&version,
),
Some(Subcommand::Inspect(cmd)) => {
cmd.init(&mut config, load_spec, &version)?;

let client = sc_service::new_full_client::<
node_runtime::Block,node_runtime::RuntimeApi, node_executor::Executor, _, _,
>(&config)?;
let inspect = node_inspect::Inspector::<node_runtime::Block>::new(client);

cmd.run(inspect)
},
Some(Subcommand::Factory(cli_args)) => {
sc_cli::init(&cli_args.shared_params, &version)?;
sc_cli::init_config(&mut config, &cli_args.shared_params, &version, load_spec)?;
Expand Down
1 change: 0 additions & 1 deletion bin/node/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
//! hasn't been tested.
#![warn(missing_docs)]
#![warn(unused_extern_crates)]

pub mod chain_spec;

Expand Down
17 changes: 17 additions & 0 deletions bin/node/inspect/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "node-inspect"
version = "0.8.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"

[dependencies]
codec = { package = "parity-scale-codec", version = "1.0.0" }
derive_more = "0.99"
log = "0.4.8"
sc-cli = { version = "0.8.0", path = "../../../client/cli" }
sc-client-api = { version = "2.0.0", path = "../../../client/api" }
sc-service = { version = "0.8", default-features = false, path = "../../../client/service" }
sp-blockchain = { version = "2.0.0", path = "../../../primitives/blockchain" }
sp-core = { version = "2.0.0", path = "../../../primitives/core" }
sp-runtime = { version = "2.0.0", path = "../../../primitives/runtime" }
structopt = "0.3.8"
Loading

0 comments on commit d9952dd

Please sign in to comment.