Skip to content

Commit ae37db6

Browse files
authored
add inspect (#213)
1 parent 210ce20 commit ae37db6

File tree

10 files changed

+530
-6
lines changed

10 files changed

+530
-6
lines changed

Cargo.lock

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ sp-transaction-pool = { version = "2.0.0-alpha.6" }
5858
sp-std = { version = "2.0.0-alpha.6" }
5959
sp-arithmetic = { version = "2.0.0-alpha.6" }
6060
substrate-frame-rpc-system = { version = "2.0.0-alpha.6" }
61+
frame-benchmarking-cli = { version = "2.0.0-alpha.6" }
6162

6263
margin-protocol = { package = "module-margin-protocol", path = "modules/margin-protocol"}
6364
margin-protocol-rpc = { path = "modules/margin-protocol/rpc" }
@@ -67,6 +68,7 @@ orml-oracle-rpc = { path = "orml/oracle/rpc" }
6768
orml-utilities = { path = "orml/utilities" }
6869
module-primitives = { path = "./modules/primitives" }
6970
runtime = { package = "laminar-runtime", path = "runtime" }
71+
inspect = { package = "laminar-inspect", path = "inspect" }
7072

7173
[dev-dependencies]
7274
cucumber = { package = "cucumber_rust", version = "^0.6.0" }
@@ -75,6 +77,11 @@ frame-support = { version = "2.0.0-alpha.6" }
7577
[build-dependencies]
7678
build-script-utils = { package = "substrate-build-script-utils", version = "2.0.0-alpha.6" }
7779

80+
[features]
81+
runtime-benchmarks = [
82+
"runtime/runtime-benchmarks",
83+
]
84+
7885
[workspace]
7986
members = [
8087
"modules/primitives",
@@ -92,6 +99,7 @@ members = [
9299
"orml/utilities",
93100
"orml/vesting",
94101
"runtime",
102+
"inspect",
95103
"orml/schedule-update",
96104
"orml/gradually-update",
97105
]

inspect/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "laminar-inspect"
3+
version = "0.0.1"
4+
authors = ["Laminar Developers <hello@laminar.one>"]
5+
edition = "2018"
6+
7+
[package.metadata.docs.rs]
8+
targets = ["x86_64-unknown-linux-gnu"]
9+
10+
[dependencies]
11+
codec = { package = "parity-scale-codec", version = "1.3.0" }
12+
derive_more = "0.99"
13+
log = "0.4.8"
14+
sc-cli = { version = "0.8.0-alpha.6" }
15+
sc-client-api = { version = "2.0.0-alpha.6" }
16+
sc-service = { version = "0.8.0-alpha.6", default-features = false }
17+
sp-blockchain = { version = "2.0.0-alpha.6" }
18+
sp-core = { version = "2.0.0-alpha.6" }
19+
sp-runtime = { version = "2.0.0-alpha.6" }
20+
structopt = "0.3.8"

inspect/src/cli.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use sc_cli::{ImportParams, SharedParams};
2+
use std::fmt::Debug;
3+
use structopt::StructOpt;
4+
5+
/// The `inspect` command used to print decoded chain data.
6+
#[derive(Debug, StructOpt, Clone)]
7+
pub struct InspectCmd {
8+
#[allow(missing_docs)]
9+
#[structopt(flatten)]
10+
pub command: InspectSubCmd,
11+
12+
#[allow(missing_docs)]
13+
#[structopt(flatten)]
14+
pub shared_params: SharedParams,
15+
16+
#[allow(missing_docs)]
17+
#[structopt(flatten)]
18+
pub import_params: ImportParams,
19+
}
20+
21+
/// A possible inspect sub-commands.
22+
#[derive(Debug, StructOpt, Clone)]
23+
pub enum InspectSubCmd {
24+
/// Decode block with native version of runtime and print out the details.
25+
Block {
26+
/// Address of the block to print out.
27+
///
28+
/// Can be either a block hash (no 0x prefix) or a number to retrieve existing block,
29+
/// or a 0x-prefixed bytes hex string, representing SCALE encoding of
30+
/// a block.
31+
#[structopt(value_name = "HASH or NUMBER or BYTES")]
32+
input: String,
33+
},
34+
/// Decode extrinsic with native version of runtime and print out the details.
35+
Extrinsic {
36+
/// Address of an extrinsic to print out.
37+
///
38+
/// Can be either a block hash (no 0x prefix) or number and the index, in the form
39+
/// of `{block}:{index}` or a 0x-prefixed bytes hex string,
40+
/// representing SCALE encoding of an extrinsic.
41+
#[structopt(value_name = "BLOCK:INDEX or BYTES")]
42+
input: String,
43+
},
44+
}

inspect/src/command.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use crate::cli::{InspectCmd, InspectSubCmd};
2+
use crate::Inspector;
3+
use sc_cli::{CliConfiguration, ImportParams, Result, SharedParams};
4+
use sc_service::{new_full_client, Configuration, NativeExecutionDispatch};
5+
use sp_runtime::traits::Block;
6+
use std::str::FromStr;
7+
8+
impl InspectCmd {
9+
/// Run the inspect command, passing the inspector.
10+
pub fn run<B, RA, EX>(&self, config: Configuration) -> Result<()>
11+
where
12+
B: Block,
13+
B::Hash: FromStr,
14+
RA: Send + Sync + 'static,
15+
EX: NativeExecutionDispatch + 'static,
16+
{
17+
let client = new_full_client::<B, RA, EX>(&config)?;
18+
let inspect = Inspector::<B>::new(client);
19+
20+
match &self.command {
21+
InspectSubCmd::Block { input } => {
22+
let input = input.parse()?;
23+
let res = inspect.block(input).map_err(|e| format!("{}", e))?;
24+
println!("{}", res);
25+
Ok(())
26+
}
27+
InspectSubCmd::Extrinsic { input } => {
28+
let input = input.parse()?;
29+
let res = inspect.extrinsic(input).map_err(|e| format!("{}", e))?;
30+
println!("{}", res);
31+
Ok(())
32+
}
33+
}
34+
}
35+
}
36+
37+
impl CliConfiguration for InspectCmd {
38+
fn shared_params(&self) -> &SharedParams {
39+
&self.shared_params
40+
}
41+
42+
fn import_params(&self) -> Option<&ImportParams> {
43+
Some(&self.import_params)
44+
}
45+
}

0 commit comments

Comments
 (0)