From 73b899b3880afe2b2a9db82a08dbf8132601e04f Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 17 Feb 2020 17:22:29 +0100 Subject: [PATCH 01/77] draft --- Cargo.lock | 3 + bin/utils/subkey/src/main.rs | 4 +- client/cli/Cargo.toml | 5 +- client/cli/src/params.rs | 1269 -------------------- client/cli/src/params/benchmark.rs | 107 ++ client/cli/src/params/build_spec.rs | 92 ++ client/cli/src/params/check_block.rs | 95 ++ client/cli/src/params/export_blocks.rs | 98 ++ client/cli/src/params/generate.rs | 66 + client/cli/src/params/generate_node_key.rs | 50 + client/cli/src/params/import_blocks.rs | 235 ++++ client/cli/src/params/inspect.rs | 58 + client/cli/src/params/mod.rs | 495 ++++++++ client/cli/src/params/purge_chain.rs | 90 ++ client/cli/src/params/revert.rs | 64 + client/cli/src/params/run.rs | 493 ++++++++ client/cli/src/params/sign.rs | 57 + client/cli/src/params/sign_transaction.rs | 73 ++ client/cli/src/params/subcommand.rs | 115 ++ primitives/core/src/crypto.rs | 2 +- 20 files changed, 2198 insertions(+), 1273 deletions(-) delete mode 100644 client/cli/src/params.rs create mode 100644 client/cli/src/params/benchmark.rs create mode 100644 client/cli/src/params/build_spec.rs create mode 100644 client/cli/src/params/check_block.rs create mode 100644 client/cli/src/params/export_blocks.rs create mode 100644 client/cli/src/params/generate.rs create mode 100644 client/cli/src/params/generate_node_key.rs create mode 100644 client/cli/src/params/import_blocks.rs create mode 100644 client/cli/src/params/inspect.rs create mode 100644 client/cli/src/params/mod.rs create mode 100644 client/cli/src/params/purge_chain.rs create mode 100644 client/cli/src/params/revert.rs create mode 100644 client/cli/src/params/run.rs create mode 100644 client/cli/src/params/sign.rs create mode 100644 client/cli/src/params/sign_transaction.rs create mode 100644 client/cli/src/params/subcommand.rs diff --git a/Cargo.lock b/Cargo.lock index 7a44b0ed7701a..bfe6be8631dd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5604,7 +5604,9 @@ dependencies = [ "env_logger 0.7.1", "fdlimit", "futures 0.3.4", + "hex-literal", "lazy_static", + "libp2p", "log 0.4.8", "names", "parity-util-mem", @@ -5626,6 +5628,7 @@ dependencies = [ "structopt", "tempfile", "time", + "tiny-bip39", "tokio 0.2.11", ] diff --git a/bin/utils/subkey/src/main.rs b/bin/utils/subkey/src/main.rs index 4d7e220642270..bf26a8de9c211 100644 --- a/bin/utils/subkey/src/main.rs +++ b/bin/utils/subkey/src/main.rs @@ -81,7 +81,7 @@ trait Crypto: Sized { { if let Ok((pair, seed)) = Self::Pair::from_phrase(uri, password) { let public_key = Self::public_from_pair(&pair); - + match output { OutputType::Json => { let json = json!({ @@ -135,7 +135,7 @@ trait Crypto: Sized { ); }, } - + } else if let Ok((public_key, v)) = ::Public::from_string_with_version(uri) { diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index e176894d64c07..ca1bf14105561 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -28,7 +28,7 @@ sp-blockchain = { version = "2.0.0", path = "../../primitives/blockchain" } sc-network = { version = "0.8", path = "../network" } sp-runtime = { version = "2.0.0", path = "../../primitives/runtime" } sp-core = { version = "2.0.0", path = "../../primitives/core" } -sc-service = { version = "0.8", default-features = false, path = "../service" } +sc-service = { version = "0.8", default-features = false, path = "../service", features = ["rocksdb"] } sp-state-machine = { version = "0.8", path = "../../primitives/state-machine" } sc-telemetry = { version = "2.0.0", path = "../telemetry" } sp-keyring = { version = "2.0.0", path = "../../primitives/keyring" } @@ -37,6 +37,9 @@ structopt = "0.3.8" sc-tracing = { version = "2.0.0", path = "../tracing" } chrono = "0.4.10" parity-util-mem = { version = "0.5.1", default-features = false, features = ["primitive-types"] } +tiny-bip39 = "0.6.2" +libp2p = "0.15.0" +hex-literal = "0.2.1" [target.'cfg(not(target_os = "unknown"))'.dependencies] rpassword = "4.0.1" diff --git a/client/cli/src/params.rs b/client/cli/src/params.rs deleted file mode 100644 index 2ffa8bd61b1f7..0000000000000 --- a/client/cli/src/params.rs +++ /dev/null @@ -1,1269 +0,0 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -use std::{str::FromStr, path::PathBuf}; -use structopt::{StructOpt, clap::arg_enum}; -use sc_service::{ - AbstractService, Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand, - config::DatabaseConfig, -}; -use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; -use crate::VersionInfo; -use crate::error; -use std::fmt::Debug; -use log::info; -use sc_network::config::build_multiaddr; -use std::io; -use std::fs; -use std::io::{Read, Write, Seek}; -use sp_runtime::generic::BlockId; -use crate::runtime::run_until_exit; -use crate::node_key::node_key_config; -use crate::execution_strategy::*; - -pub use crate::execution_strategy::ExecutionStrategy; - -impl Into for ExecutionStrategy { - fn into(self) -> sc_client_api::ExecutionStrategy { - match self { - ExecutionStrategy::Native => sc_client_api::ExecutionStrategy::NativeWhenPossible, - ExecutionStrategy::Wasm => sc_client_api::ExecutionStrategy::AlwaysWasm, - ExecutionStrategy::Both => sc_client_api::ExecutionStrategy::Both, - ExecutionStrategy::NativeElseWasm => sc_client_api::ExecutionStrategy::NativeElseWasm, - } - } -} - -arg_enum! { - /// How to execute Wasm runtime code - #[allow(missing_docs)] - #[derive(Debug, Clone, Copy)] - pub enum WasmExecutionMethod { - // Uses an interpreter. - Interpreted, - // Uses a compiled runtime. - Compiled, - } -} - -impl WasmExecutionMethod { - /// Returns list of variants that are not disabled by feature flags. - fn enabled_variants() -> Vec<&'static str> { - Self::variants() - .iter() - .cloned() - .filter(|&name| cfg!(feature = "wasmtime") || name != "Compiled") - .collect() - } -} - -impl Into for WasmExecutionMethod { - fn into(self) -> sc_service::config::WasmExecutionMethod { - match self { - WasmExecutionMethod::Interpreted => sc_service::config::WasmExecutionMethod::Interpreted, - #[cfg(feature = "wasmtime")] - WasmExecutionMethod::Compiled => sc_service::config::WasmExecutionMethod::Compiled, - #[cfg(not(feature = "wasmtime"))] - WasmExecutionMethod::Compiled => panic!( - "Substrate must be compiled with \"wasmtime\" feature for compiled Wasm execution" - ), - } - } -} - -arg_enum! { - /// Whether off-chain workers are enabled. - #[allow(missing_docs)] - #[derive(Debug, Clone)] - pub enum OffchainWorkerEnabled { - Always, - Never, - WhenValidating, - } -} - -/// Shared parameters used by all `CoreParams`. -#[derive(Debug, StructOpt, Clone)] -pub struct SharedParams { - /// Specify the chain specification (one of dev, local or staging). - #[structopt(long = "chain", value_name = "CHAIN_SPEC")] - pub chain: Option, - - /// Specify the development chain. - #[structopt(long = "dev")] - pub dev: bool, - - /// Specify custom base path. - #[structopt(long = "base-path", short = "d", value_name = "PATH", parse(from_os_str))] - pub base_path: Option, - - /// Sets a custom logging filter. - #[structopt(short = "l", long = "log", value_name = "LOG_PATTERN")] - pub log: Option, -} - -/// Parameters for block import. -#[derive(Debug, StructOpt, Clone)] -pub struct ImportParams { - /// Specify the state pruning mode, a number of blocks to keep or 'archive'. - /// - /// Default is to keep all block states if the node is running as a - /// validator (i.e. 'archive'), otherwise state is only kept for the last - /// 256 blocks. - #[structopt(long = "pruning", value_name = "PRUNING_MODE")] - pub pruning: Option, - - /// Force start with unsafe pruning settings. - /// - /// When running as a validator it is highly recommended to disable state - /// pruning (i.e. 'archive') which is the default. The node will refuse to - /// start as a validator if pruning is enabled unless this option is set. - #[structopt(long = "unsafe-pruning")] - pub unsafe_pruning: bool, - - /// Method for executing Wasm runtime code. - #[structopt( - long = "wasm-execution", - value_name = "METHOD", - possible_values = &WasmExecutionMethod::enabled_variants(), - case_insensitive = true, - default_value = "Interpreted" - )] - pub wasm_method: WasmExecutionMethod, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub execution_strategies: ExecutionStrategies, - - /// Limit the memory the database cache can use. - #[structopt(long = "db-cache", value_name = "MiB", default_value = "1024")] - pub database_cache_size: u32, - - /// Specify the state cache size. - #[structopt(long = "state-cache-size", value_name = "Bytes", default_value = "67108864")] - pub state_cache_size: usize, - - /// Comma separated list of targets for tracing - #[structopt(long = "tracing-targets", value_name = "TARGETS")] - pub tracing_targets: Option, - - /// Receiver to process tracing messages - #[structopt( - long = "tracing-receiver", - value_name = "RECEIVER", - possible_values = &TracingReceiver::variants(), - case_insensitive = true, - default_value = "Log" - )] - pub tracing_receiver: TracingReceiver, -} - -/// Parameters used to create the network configuration. -#[derive(Debug, StructOpt, Clone)] -pub struct NetworkConfigurationParams { - /// Specify a list of bootnodes. - #[structopt(long = "bootnodes", value_name = "URL")] - pub bootnodes: Vec, - - /// Specify a list of reserved node addresses. - #[structopt(long = "reserved-nodes", value_name = "URL")] - pub reserved_nodes: Vec, - - /// Whether to only allow connections to/from reserved nodes. - /// - /// If you are a validator your node might still connect to other validator - /// nodes regardless of whether they are defined as reserved nodes. - #[structopt(long = "reserved-only")] - pub reserved_only: bool, - - /// Specify a list of sentry node public addresses. - #[structopt( - long = "sentry-nodes", - value_name = "URL", - conflicts_with_all = &[ "sentry" ] - )] - pub sentry_nodes: Vec, - - /// Listen on this multiaddress. - #[structopt(long = "listen-addr", value_name = "LISTEN_ADDR")] - pub listen_addr: Vec, - - /// Specify p2p protocol TCP port. - /// - /// Only used if --listen-addr is not specified. - #[structopt(long = "port", value_name = "PORT")] - pub port: Option, - - /// Allow connecting to private IPv4 addresses (as specified in - /// [RFC1918](https://tools.ietf.org/html/rfc1918)), unless the address was passed with - /// `--reserved-nodes` or `--bootnodes`. - #[structopt(long = "no-private-ipv4")] - pub no_private_ipv4: bool, - - /// Specify the number of outgoing connections we're trying to maintain. - #[structopt(long = "out-peers", value_name = "COUNT", default_value = "25")] - pub out_peers: u32, - - /// Specify the maximum number of incoming connections we're accepting. - #[structopt(long = "in-peers", value_name = "COUNT", default_value = "25")] - pub in_peers: u32, - - /// Disable mDNS discovery. - /// - /// By default, the network will use mDNS to discover other nodes on the - /// local network. This disables it. Automatically implied when using --dev. - #[structopt(long = "no-mdns")] - pub no_mdns: bool, - - /// Maximum number of peers to ask the same blocks in parallel. - /// - /// This allows downlading announced blocks from multiple peers. Decrease to save - /// traffic and risk increased latency. - #[structopt(long = "max-parallel-downloads", value_name = "COUNT", default_value = "5")] - pub max_parallel_downloads: u32, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub node_key_params: NodeKeyParams, - - /// Experimental feature flag. - #[structopt(long = "use-yamux-flow-control")] - pub use_yamux_flow_control: bool, -} - -arg_enum! { - #[allow(missing_docs)] - #[derive(Debug, Copy, Clone, PartialEq, Eq)] - pub enum NodeKeyType { - Ed25519 - } -} - -/// Parameters used to create the `NodeKeyConfig`, which determines the keypair -/// used for libp2p networking. -#[derive(Debug, StructOpt, Clone)] -pub struct NodeKeyParams { - /// The secret key to use for libp2p networking. - /// - /// The value is a string that is parsed according to the choice of - /// `--node-key-type` as follows: - /// - /// `ed25519`: - /// The value is parsed as a hex-encoded Ed25519 32 bytes secret key, - /// i.e. 64 hex characters. - /// - /// The value of this option takes precedence over `--node-key-file`. - /// - /// WARNING: Secrets provided as command-line arguments are easily exposed. - /// Use of this option should be limited to development and testing. To use - /// an externally managed secret key, use `--node-key-file` instead. - #[structopt(long = "node-key", value_name = "KEY")] - pub node_key: Option, - - /// The type of secret key to use for libp2p networking. - /// - /// The secret key of the node is obtained as follows: - /// - /// * If the `--node-key` option is given, the value is parsed as a secret key - /// according to the type. See the documentation for `--node-key`. - /// - /// * If the `--node-key-file` option is given, the secret key is read from the - /// specified file. See the documentation for `--node-key-file`. - /// - /// * Otherwise, the secret key is read from a file with a predetermined, - /// type-specific name from the chain-specific network config directory - /// inside the base directory specified by `--base-dir`. If this file does - /// not exist, it is created with a newly generated secret key of the - /// chosen type. - /// - /// The node's secret key determines the corresponding public key and hence the - /// node's peer ID in the context of libp2p. - #[structopt( - long = "node-key-type", - value_name = "TYPE", - possible_values = &NodeKeyType::variants(), - case_insensitive = true, - default_value = "Ed25519" - )] - pub node_key_type: NodeKeyType, - - /// The file from which to read the node's secret key to use for libp2p networking. - /// - /// The contents of the file are parsed according to the choice of `--node-key-type` - /// as follows: - /// - /// `ed25519`: - /// The file must contain an unencoded 32 bytes Ed25519 secret key. - /// - /// If the file does not exist, it is created with a newly generated secret key of - /// the chosen type. - #[structopt(long = "node-key-file", value_name = "FILE")] - pub node_key_file: Option, -} - -/// Parameters used to create the pool configuration. -#[derive(Debug, StructOpt, Clone)] -pub struct TransactionPoolParams { - /// Maximum number of transactions in the transaction pool. - #[structopt(long = "pool-limit", value_name = "COUNT", default_value = "8192")] - pub pool_limit: usize, - /// Maximum number of kilobytes of all transactions stored in the pool. - #[structopt(long = "pool-kbytes", value_name = "COUNT", default_value = "20480")] - pub pool_kbytes: usize, -} - -arg_enum! { - #[allow(missing_docs)] - #[derive(Debug, Copy, Clone, PartialEq, Eq)] - pub enum TracingReceiver { - Log, - Telemetry, - Grafana, - } -} - -impl Into for TracingReceiver { - fn into(self) -> sc_tracing::TracingReceiver { - match self { - TracingReceiver::Log => sc_tracing::TracingReceiver::Log, - TracingReceiver::Telemetry => sc_tracing::TracingReceiver::Telemetry, - TracingReceiver::Grafana => sc_tracing::TracingReceiver::Grafana, - } - } -} - -/// Execution strategies parameters. -#[derive(Debug, StructOpt, Clone)] -pub struct ExecutionStrategies { - /// The means of execution used when calling into the runtime while syncing blocks. - #[structopt( - long = "execution-syncing", - value_name = "STRATEGY", - possible_values = &ExecutionStrategy::variants(), - case_insensitive = true, - default_value = DEFAULT_EXECUTION_SYNCING.as_str(), - )] - pub execution_syncing: ExecutionStrategy, - - /// The means of execution used when calling into the runtime while importing blocks. - #[structopt( - long = "execution-import-block", - value_name = "STRATEGY", - possible_values = &ExecutionStrategy::variants(), - case_insensitive = true, - default_value = DEFAULT_EXECUTION_IMPORT_BLOCK.as_str(), - )] - pub execution_import_block: ExecutionStrategy, - - /// The means of execution used when calling into the runtime while constructing blocks. - #[structopt( - long = "execution-block-construction", - value_name = "STRATEGY", - possible_values = &ExecutionStrategy::variants(), - case_insensitive = true, - default_value = DEFAULT_EXECUTION_BLOCK_CONSTRUCTION.as_str(), - )] - pub execution_block_construction: ExecutionStrategy, - - /// The means of execution used when calling into the runtime while using an off-chain worker. - #[structopt( - long = "execution-offchain-worker", - value_name = "STRATEGY", - possible_values = &ExecutionStrategy::variants(), - case_insensitive = true, - default_value = DEFAULT_EXECUTION_OFFCHAIN_WORKER.as_str(), - )] - pub execution_offchain_worker: ExecutionStrategy, - - /// The means of execution used when calling into the runtime while not syncing, importing or constructing blocks. - #[structopt( - long = "execution-other", - value_name = "STRATEGY", - possible_values = &ExecutionStrategy::variants(), - case_insensitive = true, - default_value = DEFAULT_EXECUTION_OTHER.as_str(), - )] - pub execution_other: ExecutionStrategy, - - /// The execution strategy that should be used by all execution contexts. - #[structopt( - long = "execution", - value_name = "STRATEGY", - possible_values = &ExecutionStrategy::variants(), - case_insensitive = true, - conflicts_with_all = &[ - "execution-other", - "execution-offchain-worker", - "execution-block-construction", - "execution-import-block", - "execution-syncing", - ] - )] - pub execution: Option, -} - -/// The `run` command used to run a node. -#[derive(Debug, StructOpt, Clone)] -pub struct RunCmd { - /// Enable validator mode. - /// - /// The node will be started with the authority role and actively - /// participate in any consensus task that it can (e.g. depending on - /// availability of local keys). - #[structopt( - long = "validator", - conflicts_with_all = &[ "sentry" ] - )] - pub validator: bool, - - /// Enable sentry mode. - /// - /// The node will be started with the authority role and participate in - /// consensus tasks as an "observer", it will never actively participate - /// regardless of whether it could (e.g. keys are available locally). This - /// mode is useful as a secure proxy for validators (which would run - /// detached from the network), since we want this node to participate in - /// the full consensus protocols in order to have all needed consensus data - /// available to relay to private nodes. - #[structopt( - long = "sentry", - conflicts_with_all = &[ "validator", "light" ] - )] - pub sentry: bool, - - /// Disable GRANDPA voter when running in validator mode, otherwise disables the GRANDPA observer. - #[structopt(long = "no-grandpa")] - pub no_grandpa: bool, - - /// Experimental: Run in light client mode. - #[structopt(long = "light", conflicts_with = "sentry")] - pub light: bool, - - /// Listen to all RPC interfaces. - /// - /// Default is local. Note: not all RPC methods are safe to be exposed publicly. Use a RPC proxy - /// server to filter out dangerous methods. More details: https://github.com/paritytech/substrate/wiki/Public-RPC. - /// Use `--unsafe-rpc-external` to suppress the warning if you understand the risks. - #[structopt(long = "rpc-external")] - pub rpc_external: bool, - - /// Listen to all RPC interfaces. - /// - /// Same as `--rpc-external`. - #[structopt(long = "unsafe-rpc-external")] - pub unsafe_rpc_external: bool, - - /// Listen to all Websocket interfaces. - /// - /// Default is local. Note: not all RPC methods are safe to be exposed publicly. Use a RPC proxy - /// server to filter out dangerous methods. More details: https://github.com/paritytech/substrate/wiki/Public-RPC. - /// Use `--unsafe-ws-external` to suppress the warning if you understand the risks. - #[structopt(long = "ws-external")] - pub ws_external: bool, - - /// Listen to all Websocket interfaces. - /// - /// Same as `--ws-external`. - #[structopt(long = "unsafe-ws-external")] - pub unsafe_ws_external: bool, - - /// Listen to all Grafana data source interfaces. - /// - /// Default is local. - #[structopt(long = "grafana-external")] - pub grafana_external: bool, - - /// Specify HTTP RPC server TCP port. - #[structopt(long = "rpc-port", value_name = "PORT")] - pub rpc_port: Option, - - /// Specify WebSockets RPC server TCP port. - #[structopt(long = "ws-port", value_name = "PORT")] - pub ws_port: Option, - - /// Maximum number of WS RPC server connections. - #[structopt(long = "ws-max-connections", value_name = "COUNT")] - pub ws_max_connections: Option, - - /// Specify browser Origins allowed to access the HTTP & WS RPC servers. - /// - /// A comma-separated list of origins (protocol://domain or special `null` - /// value). Value of `all` will disable origin validation. Default is to - /// allow localhost, https://polkadot.js.org and - /// https://substrate-ui.parity.io origins. When running in --dev mode the - /// default is to allow all origins. - #[structopt(long = "rpc-cors", value_name = "ORIGINS", parse(try_from_str = parse_cors))] - pub rpc_cors: Option, - - /// Specify Grafana data source server TCP Port. - #[structopt(long = "grafana-port", value_name = "PORT")] - pub grafana_port: Option, - - /// The human-readable name for this node. - /// - /// The node name will be reported to the telemetry server, if enabled. - #[structopt(long = "name", value_name = "NAME")] - pub name: Option, - - /// Disable connecting to the Substrate telemetry server. - /// - /// Telemetry is on by default on global chains. - #[structopt(long = "no-telemetry")] - pub no_telemetry: bool, - - /// The URL of the telemetry server to connect to. - /// - /// This flag can be passed multiple times as a mean to specify multiple - /// telemetry endpoints. Verbosity levels range from 0-9, with 0 denoting - /// the least verbosity. If no verbosity level is specified the default is - /// 0. - #[structopt(long = "telemetry-url", value_name = "URL VERBOSITY", parse(try_from_str = parse_telemetry_endpoints))] - pub telemetry_endpoints: Vec<(String, u8)>, - - /// Should execute offchain workers on every block. - /// - /// By default it's only enabled for nodes that are authoring new blocks. - #[structopt( - long = "offchain-worker", - value_name = "ENABLED", - possible_values = &OffchainWorkerEnabled::variants(), - case_insensitive = true, - default_value = "WhenValidating" - )] - pub offchain_worker: OffchainWorkerEnabled, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub import_params: ImportParams, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub network_config: NetworkConfigurationParams, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub pool_config: TransactionPoolParams, - - /// Shortcut for `--name Alice --validator` with session keys for `Alice` added to keystore. - #[structopt(long, conflicts_with_all = &["bob", "charlie", "dave", "eve", "ferdie", "one", "two"])] - pub alice: bool, - - /// Shortcut for `--name Bob --validator` with session keys for `Bob` added to keystore. - #[structopt(long, conflicts_with_all = &["alice", "charlie", "dave", "eve", "ferdie", "one", "two"])] - pub bob: bool, - - /// Shortcut for `--name Charlie --validator` with session keys for `Charlie` added to keystore. - #[structopt(long, conflicts_with_all = &["alice", "bob", "dave", "eve", "ferdie", "one", "two"])] - pub charlie: bool, - - /// Shortcut for `--name Dave --validator` with session keys for `Dave` added to keystore. - #[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "eve", "ferdie", "one", "two"])] - pub dave: bool, - - /// Shortcut for `--name Eve --validator` with session keys for `Eve` added to keystore. - #[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "ferdie", "one", "two"])] - pub eve: bool, - - /// Shortcut for `--name Ferdie --validator` with session keys for `Ferdie` added to keystore. - #[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "one", "two"])] - pub ferdie: bool, - - /// Shortcut for `--name One --validator` with session keys for `One` added to keystore. - #[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "ferdie", "two"])] - pub one: bool, - - /// Shortcut for `--name Two --validator` with session keys for `Two` added to keystore. - #[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "ferdie", "one"])] - pub two: bool, - - /// Enable authoring even when offline. - #[structopt(long = "force-authoring")] - pub force_authoring: bool, - - /// Specify custom keystore path. - #[structopt(long = "keystore-path", value_name = "PATH", parse(from_os_str))] - pub keystore_path: Option, - - /// Use interactive shell for entering the password used by the keystore. - #[structopt( - long = "password-interactive", - conflicts_with_all = &[ "password", "password-filename" ] - )] - pub password_interactive: bool, - - /// Password used by the keystore. - #[structopt( - long = "password", - conflicts_with_all = &[ "password-interactive", "password-filename" ] - )] - pub password: Option, - - /// File that contains the password used by the keystore. - #[structopt( - long = "password-filename", - value_name = "PATH", - parse(from_os_str), - conflicts_with_all = &[ "password-interactive", "password" ] - )] - pub password_filename: Option -} - -impl RunCmd { - /// Get the `Sr25519Keyring` matching one of the flag - pub fn get_keyring(&self) -> Option { - use sp_keyring::Sr25519Keyring::*; - - if self.alice { Some(Alice) } - else if self.bob { Some(Bob) } - else if self.charlie { Some(Charlie) } - else if self.dave { Some(Dave) } - else if self.eve { Some(Eve) } - else if self.ferdie { Some(Ferdie) } - else if self.one { Some(One) } - else if self.two { Some(Two) } - else { None } - } -} - -/// Default to verbosity level 0, if none is provided. -fn parse_telemetry_endpoints(s: &str) -> Result<(String, u8), Box> { - let pos = s.find(' '); - match pos { - None => { - Ok((s.to_owned(), 0)) - }, - Some(pos_) => { - let verbosity = s[pos_ + 1..].parse()?; - let url = s[..pos_].parse()?; - Ok((url, verbosity)) - } - } -} - -/// CORS setting -/// -/// The type is introduced to overcome `Option>` -/// handling of `structopt`. -#[derive(Clone, Debug)] -pub enum Cors { - /// All hosts allowed - All, - /// Only hosts on the list are allowed. - List(Vec), -} - -impl From for Option> { - fn from(cors: Cors) -> Self { - match cors { - Cors::All => None, - Cors::List(list) => Some(list), - } - } -} - -/// Parse cors origins -fn parse_cors(s: &str) -> Result> { - let mut is_all = false; - let mut origins = Vec::new(); - for part in s.split(',') { - match part { - "all" | "*" => { - is_all = true; - break; - }, - other => origins.push(other.to_owned()), - } - } - - Ok(if is_all { Cors::All } else { Cors::List(origins) }) -} - -/// The `build-spec` command used to build a specification. -#[derive(Debug, StructOpt, Clone)] -pub struct BuildSpecCmd { - /// Force raw genesis storage output. - #[structopt(long = "raw")] - pub raw: bool, - - /// Disable adding the default bootnode to the specification. - /// - /// By default the `/ip4/127.0.0.1/tcp/30333/p2p/NODE_PEER_ID` bootnode is added to the - /// specification when no bootnode exists. - #[structopt(long = "disable-default-bootnode")] - pub disable_default_bootnode: bool, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub node_key_params: NodeKeyParams, -} - -/// Wrapper type of `String` which holds an arbitary sized unsigned integer formatted as decimal. -#[derive(Debug, Clone)] -pub struct BlockNumber(String); - -impl FromStr for BlockNumber { - type Err = String; - - fn from_str(block_number: &str) -> Result { - if block_number.chars().any(|d| !d.is_digit(10)) { - Err(format!( - "Invalid block number: {}, expected decimal formatted unsigned integer", - block_number - )) - } else { - Ok(Self(block_number.to_owned())) - } - } -} - -impl BlockNumber { - /// Wrapper on top of `std::str::parse` but with `Error` as a `String` - /// - /// See `https://doc.rust-lang.org/std/primitive.str.html#method.parse` for more elaborate - /// documentation. - pub fn parse(&self) -> Result - where - N: FromStr, - N::Err: std::fmt::Debug, - { - self.0 - .parse() - .map_err(|e| format!("BlockNumber: {} parsing failed because of {:?}", self.0, e)) - } -} - -/// The `export-blocks` command used to export blocks. -#[derive(Debug, StructOpt, Clone)] -pub struct ExportBlocksCmd { - /// Output file name or stdout if unspecified. - #[structopt(parse(from_os_str))] - pub output: Option, - - /// Specify starting block number. - /// - /// Default is 1. - #[structopt(long = "from", value_name = "BLOCK")] - pub from: Option, - - /// Specify last block number. - /// - /// Default is best block. - #[structopt(long = "to", value_name = "BLOCK")] - pub to: Option, - - /// Use JSON output rather than binary. - #[structopt(long = "json")] - pub json: bool, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, -} - -/// The `import-blocks` command used to import blocks. -#[derive(Debug, StructOpt, Clone)] -pub struct ImportBlocksCmd { - /// Input file or stdin if unspecified. - #[structopt(parse(from_os_str))] - pub input: Option, - - /// The default number of 64KB pages to ever allocate for Wasm execution. - /// - /// Don't alter this unless you know what you're doing. - #[structopt(long = "default-heap-pages", value_name = "COUNT")] - pub default_heap_pages: Option, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub import_params: ImportParams, -} - -/// The `check-block` command used to validate blocks. -#[derive(Debug, StructOpt, Clone)] -pub struct CheckBlockCmd { - /// Block hash or number - #[structopt(value_name = "HASH or NUMBER")] - pub input: String, - - /// The default number of 64KB pages to ever allocate for Wasm execution. - /// - /// Don't alter this unless you know what you're doing. - #[structopt(long = "default-heap-pages", value_name = "COUNT")] - pub default_heap_pages: Option, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub import_params: ImportParams, -} - -/// The `revert` command used revert the chain to a previous state. -#[derive(Debug, StructOpt, Clone)] -pub struct RevertCmd { - /// Number of blocks to revert. - #[structopt(default_value = "256")] - pub num: BlockNumber, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, -} - -/// The `purge-chain` command used to remove the whole chain. -#[derive(Debug, StructOpt, Clone)] -pub struct PurgeChainCmd { - /// Skip interactive prompt by answering yes automatically. - #[structopt(short = "y")] - pub yes: bool, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, -} - -/// The `benchmark` command used to benchmark FRAME Pallets. -#[derive(Debug, StructOpt, Clone)] -pub struct BenchmarkCmd { - /// Select a FRAME Pallet to benchmark. - #[structopt(short, long)] - pub pallet: String, - - /// Select an extrinsic to benchmark. - #[structopt(short, long)] - pub extrinsic: String, - - /// Select how many samples we should take across the variable components. - #[structopt(short, long, default_value = "1")] - pub steps: u32, - - /// Select how many repetitions of this benchmark should run. - #[structopt(short, long, default_value = "1")] - pub repeat: u32, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - - /// The execution strategy that should be used for benchmarks - #[structopt( - long = "execution", - value_name = "STRATEGY", - possible_values = &ExecutionStrategy::variants(), - case_insensitive = true, - )] - pub execution: Option, - - /// Method for executing Wasm runtime code. - #[structopt( - long = "wasm-execution", - value_name = "METHOD", - possible_values = &WasmExecutionMethod::enabled_variants(), - case_insensitive = true, - default_value = "Interpreted" - )] - pub wasm_method: WasmExecutionMethod, -} - -/// All core commands that are provided by default. -/// -/// The core commands are split into multiple subcommands and `Run` is the default subcommand. From -/// the CLI user perspective, it is not visible that `Run` is a subcommand. So, all parameters of -/// `Run` are exported as main executable parameters. -#[derive(Debug, Clone, StructOpt)] -pub enum Subcommand { - /// Build a spec.json file, outputing to stdout. - BuildSpec(BuildSpecCmd), - - /// Export blocks to a file. - ExportBlocks(ExportBlocksCmd), - - /// Import blocks from file. - ImportBlocks(ImportBlocksCmd), - - /// Validte a single block. - CheckBlock(CheckBlockCmd), - - /// Revert chain to the previous state. - Revert(RevertCmd), - - /// Remove the whole chain data. - PurgeChain(PurgeChainCmd), - - /// Run runtime benchmarks. - Benchmark(BenchmarkCmd), -} - -impl Subcommand { - /// Get the shared parameters of a `CoreParams` command - pub fn get_shared_params(&self) -> &SharedParams { - use Subcommand::*; - - match self { - BuildSpec(params) => ¶ms.shared_params, - ExportBlocks(params) => ¶ms.shared_params, - ImportBlocks(params) => ¶ms.shared_params, - CheckBlock(params) => ¶ms.shared_params, - Revert(params) => ¶ms.shared_params, - PurgeChain(params) => ¶ms.shared_params, - Benchmark(params) => ¶ms.shared_params, - } - } - - /// Run any `CoreParams` command - pub fn run( - self, - config: Configuration, - builder: B, - ) -> error::Result<()> - where - B: FnOnce(Configuration) -> Result, - G: RuntimeGenesis, - E: ChainSpecExtension, - BC: ServiceBuilderCommand + Unpin, - BB: sp_runtime::traits::Block + Debug, - <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, - ::Hash: std::str::FromStr, - { - assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); - - match self { - Subcommand::BuildSpec(cmd) => cmd.run(config), - Subcommand::ExportBlocks(cmd) => cmd.run(config, builder), - Subcommand::ImportBlocks(cmd) => cmd.run(config, builder), - Subcommand::CheckBlock(cmd) => cmd.run(config, builder), - Subcommand::PurgeChain(cmd) => cmd.run(config), - Subcommand::Benchmark(cmd) => cmd.run(config, builder), - Subcommand::Revert(cmd) => cmd.run(config, builder), - } - } -} - -impl RunCmd { - /// Run the command that runs the node - pub fn run( - self, - mut config: Configuration, - new_light: FNL, - new_full: FNF, - version: &VersionInfo, - ) -> error::Result<()> - where - G: RuntimeGenesis, - E: ChainSpecExtension, - FNL: FnOnce(Configuration) -> Result, - FNF: FnOnce(Configuration) -> Result, - SL: AbstractService + Unpin, - SF: AbstractService + Unpin, - { - assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); - - crate::update_config_for_running_node(&mut config, self)?; - - crate::run_node(config, new_light, new_full, &version) - } -} - -impl BuildSpecCmd { - /// Run the build-spec command - pub fn run( - self, - config: Configuration, - ) -> error::Result<()> - where - G: RuntimeGenesis, - E: ChainSpecExtension, - { - assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); - - info!("Building chain spec"); - let mut spec = config.expect_chain_spec().clone(); - let raw_output = self.raw; - - if spec.boot_nodes().is_empty() && !self.disable_default_bootnode { - let node_key = node_key_config( - self.node_key_params.clone(), - &Some(config - .in_chain_config_dir(crate::DEFAULT_NETWORK_CONFIG_PATH) - .expect("We provided a base_path")), - )?; - let keys = node_key.into_keypair()?; - let peer_id = keys.public().into_peer_id(); - let addr = build_multiaddr![ - Ip4([127, 0, 0, 1]), - Tcp(30333u16), - P2p(peer_id) - ]; - spec.add_boot_node(addr) - } - - let json = sc_service::chain_ops::build_spec(spec, raw_output)?; - - print!("{}", json); - - Ok(()) - } -} - -impl ExportBlocksCmd { - /// Run the export-blocks command - pub fn run( - self, - mut config: Configuration, - builder: B, - ) -> error::Result<()> - where - B: FnOnce(Configuration) -> Result, - G: RuntimeGenesis, - E: ChainSpecExtension, - BC: ServiceBuilderCommand + Unpin, - BB: sp_runtime::traits::Block + Debug, - <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, - ::Hash: std::str::FromStr, - { - assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); - - crate::fill_config_keystore_in_memory(&mut config)?; - - if let DatabaseConfig::Path { ref path, .. } = config.expect_database() { - info!("DB path: {}", path.display()); - } - let from = self.from.as_ref().and_then(|f| f.parse().ok()).unwrap_or(1); - let to = self.to.as_ref().and_then(|t| t.parse().ok()); - - let json = self.json; - - let file: Box = match &self.output { - Some(filename) => Box::new(fs::File::create(filename)?), - None => Box::new(io::stdout()), - }; - - run_until_exit(config, |config| { - Ok(builder(config)?.export_blocks(file, from.into(), to, json)) - }) - } -} - -/// Internal trait used to cast to a dynamic type that implements Read and Seek. -trait ReadPlusSeek: Read + Seek {} - -impl ReadPlusSeek for T {} - -impl ImportBlocksCmd { - /// Run the import-blocks command - pub fn run( - self, - mut config: Configuration, - builder: B, - ) -> error::Result<()> - where - B: FnOnce(Configuration) -> Result, - G: RuntimeGenesis, - E: ChainSpecExtension, - BC: ServiceBuilderCommand + Unpin, - BB: sp_runtime::traits::Block + Debug, - <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, - ::Hash: std::str::FromStr, - { - crate::fill_import_params( - &mut config, - &self.import_params, - sc_service::Roles::FULL, - self.shared_params.dev, - )?; - - let file: Box = match &self.input { - Some(filename) => Box::new(fs::File::open(filename)?), - None => { - let mut buffer = Vec::new(); - io::stdin().read_to_end(&mut buffer)?; - Box::new(io::Cursor::new(buffer)) - }, - }; - - run_until_exit(config, |config| { - Ok(builder(config)?.import_blocks(file, false)) - }) - } -} - -impl CheckBlockCmd { - /// Run the check-block command - pub fn run( - self, - mut config: Configuration, - builder: B, - ) -> error::Result<()> - where - B: FnOnce(Configuration) -> Result, - G: RuntimeGenesis, - E: ChainSpecExtension, - BC: ServiceBuilderCommand + Unpin, - BB: sp_runtime::traits::Block + Debug, - <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, - ::Hash: std::str::FromStr, - { - assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); - - crate::fill_import_params( - &mut config, - &self.import_params, - sc_service::Roles::FULL, - self.shared_params.dev, - )?; - crate::fill_config_keystore_in_memory(&mut config)?; - - let input = if self.input.starts_with("0x") { &self.input[2..] } else { &self.input[..] }; - let block_id = match FromStr::from_str(input) { - Ok(hash) => BlockId::hash(hash), - Err(_) => match self.input.parse::() { - Ok(n) => BlockId::number((n as u32).into()), - Err(_) => return Err(error::Error::Input("Invalid hash or number specified".into())), - } - }; - - let start = std::time::Instant::now(); - run_until_exit(config, |config| { - Ok(builder(config)?.check_block(block_id)) - })?; - println!("Completed in {} ms.", start.elapsed().as_millis()); - - Ok(()) - } -} - -impl PurgeChainCmd { - /// Run the purge command - pub fn run( - self, - mut config: Configuration, - ) -> error::Result<()> - where - G: RuntimeGenesis, - E: ChainSpecExtension, - { - assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); - - crate::fill_config_keystore_in_memory(&mut config)?; - - let db_path = match config.expect_database() { - DatabaseConfig::Path { path, .. } => path, - _ => { - eprintln!("Cannot purge custom database implementation"); - return Ok(()); - } - }; - - if !self.yes { - print!("Are you sure to remove {:?}? [y/N]: ", &db_path); - io::stdout().flush().expect("failed to flush stdout"); - - let mut input = String::new(); - io::stdin().read_line(&mut input)?; - let input = input.trim(); - - match input.chars().nth(0) { - Some('y') | Some('Y') => {}, - _ => { - println!("Aborted"); - return Ok(()); - }, - } - } - - match fs::remove_dir_all(&db_path) { - Ok(_) => { - println!("{:?} removed.", &db_path); - Ok(()) - }, - Err(ref err) if err.kind() == io::ErrorKind::NotFound => { - eprintln!("{:?} did not exist.", &db_path); - Ok(()) - }, - Err(err) => Result::Err(err.into()) - } - } -} - -impl RevertCmd { - /// Run the revert command - pub fn run( - self, - mut config: Configuration, - builder: B, - ) -> error::Result<()> - where - B: FnOnce(Configuration) -> Result, - G: RuntimeGenesis, - E: ChainSpecExtension, - BC: ServiceBuilderCommand + Unpin, - BB: sp_runtime::traits::Block + Debug, - <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, - ::Hash: std::str::FromStr, - { - assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); - - crate::fill_config_keystore_in_memory(&mut config)?; - - let blocks = self.num.parse()?; - builder(config)?.revert_chain(blocks)?; - - Ok(()) - } -} - -impl BenchmarkCmd { - /// Runs the command and benchmarks the chain. - pub fn run( - self, - config: Configuration, - _builder: B, - ) -> error::Result<()> - where - B: FnOnce(Configuration) -> Result, - G: RuntimeGenesis, - E: ChainSpecExtension, - BC: ServiceBuilderCommand + Unpin, - BB: sp_runtime::traits::Block + Debug, - <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, - ::Hash: std::str::FromStr, - { - let spec = config.chain_spec.expect("chain_spec is always Some"); - let execution_strategy = self.execution.unwrap_or(ExecutionStrategy::Native).into(); - let wasm_method = self.wasm_method.into(); - let pallet = self.pallet; - let extrinsic = self.extrinsic; - let steps = self.steps; - let repeat = self.repeat; - sc_service::chain_ops::benchmark_runtime::(spec, execution_strategy, wasm_method, pallet, extrinsic, steps, repeat)?; - Ok(()) - } -} - diff --git a/client/cli/src/params/benchmark.rs b/client/cli/src/params/benchmark.rs new file mode 100644 index 0000000000000..6eaa4cda18b33 --- /dev/null +++ b/client/cli/src/params/benchmark.rs @@ -0,0 +1,107 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +use structopt::{StructOpt}; +use sc_service::{ + Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand, +}; +use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; +use crate::error; +use std::fmt::Debug; +use crate::execution_strategy::*; +use super::{SharedParams, WasmExecutionMethod}; + + +/// The `benchmark` command used to benchmark FRAME Pallets. +#[derive(Debug, StructOpt, Clone)] +pub struct BenchmarkCmd { + /// Select a FRAME Pallet to benchmark. + #[structopt(short, long)] + pub pallet: String, + + /// Select an extrinsic to benchmark. + #[structopt(short, long)] + pub extrinsic: String, + + /// Select how many samples we should take across the variable components. + #[structopt(short, long, default_value = "1")] + pub steps: u32, + + /// Select how many repetitions of this benchmark should run. + #[structopt(short, long, default_value = "1")] + pub repeat: u32, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, + + /// The execution strategy that should be used for benchmarks + #[structopt( + long = "execution", + value_name = "STRATEGY", + possible_values = &ExecutionStrategy::variants(), + case_insensitive = true, + )] + pub execution: Option, + + /// Method for executing Wasm runtime code. + #[structopt( + long = "wasm-execution", + value_name = "METHOD", + possible_values = &WasmExecutionMethod::enabled_variants(), + case_insensitive = true, + default_value = "Interpreted" + )] + pub wasm_method: WasmExecutionMethod, +} + +impl BenchmarkCmd { + /// Runs the command and benchmarks the chain. + pub fn run( + self, + config: Configuration, + _builder: B, + ) -> error::Result<()> + where + B: FnOnce(Configuration) -> Result, + G: RuntimeGenesis, + E: ChainSpecExtension, + BC: ServiceBuilderCommand + Unpin, + BB: sp_runtime::traits::Block + Debug, + <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, + ::Hash: std::str::FromStr, + { + let spec = config.chain_spec.expect("chain_spec is always Some"); + let execution_strategy = self.execution.unwrap_or(ExecutionStrategy::Native).into(); + let wasm_method = self.wasm_method.into(); + let pallet = self.pallet; + let extrinsic = self.extrinsic; + let steps = self.steps; + let repeat = self.repeat; + sc_service::chain_ops::benchmark_runtime::( + spec, + execution_strategy, + wasm_method, + pallet, + extrinsic, + steps, + repeat + )?; + Ok(()) + } +} + + diff --git a/client/cli/src/params/build_spec.rs b/client/cli/src/params/build_spec.rs new file mode 100644 index 0000000000000..261e1cc411aef --- /dev/null +++ b/client/cli/src/params/build_spec.rs @@ -0,0 +1,92 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +use structopt::{StructOpt}; +use sc_service::{ + Configuration, ChainSpecExtension, RuntimeGenesis, +}; +use crate::error; +use std::fmt::Debug; +use log::info; +use sc_network::config::build_multiaddr; +use crate::node_key::node_key_config; + +use super::{NodeKeyParams, SharedParams}; + +/// The `build-spec` command used to build a specification. +#[derive(Debug, StructOpt, Clone)] +pub struct BuildSpecCmd { + /// Force raw genesis storage output. + #[structopt(long = "raw")] + pub raw: bool, + + /// Disable adding the default bootnode to the specification. + /// + /// By default the `/ip4/127.0.0.1/tcp/30333/p2p/NODE_PEER_ID` bootnode is added to the + /// specification when no bootnode exists. + #[structopt(long = "disable-default-bootnode")] + pub disable_default_bootnode: bool, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub node_key_params: NodeKeyParams, +} + + +impl BuildSpecCmd { + /// Run the build-spec command + pub fn run( + self, + config: Configuration, + ) -> error::Result<()> + where + G: RuntimeGenesis, + E: ChainSpecExtension, + { + assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); + + info!("Building chain spec"); + let mut spec = config.expect_chain_spec().clone(); + let raw_output = self.raw; + + if spec.boot_nodes().is_empty() && !self.disable_default_bootnode { + let node_key = node_key_config( + self.node_key_params.clone(), + &Some(config + .in_chain_config_dir(crate::DEFAULT_NETWORK_CONFIG_PATH) + .expect("We provided a base_path")), + )?; + let keys = node_key.into_keypair()?; + let peer_id = keys.public().into_peer_id(); + let addr = build_multiaddr![ + Ip4([127, 0, 0, 1]), + Tcp(30333u16), + P2p(peer_id) + ]; + spec.add_boot_node(addr) + } + + let json = sc_service::chain_ops::build_spec(spec, raw_output)?; + + print!("{}", json); + + Ok(()) + } +} diff --git a/client/cli/src/params/check_block.rs b/client/cli/src/params/check_block.rs new file mode 100644 index 0000000000000..c95f3cdb46e75 --- /dev/null +++ b/client/cli/src/params/check_block.rs @@ -0,0 +1,95 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +use std::{str::FromStr}; +use structopt::{StructOpt}; +use sc_service::{ + Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand, +}; +use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; +use crate::error; +use std::fmt::Debug; +use sp_runtime::generic::BlockId; +use crate::runtime::run_until_exit; + +use super::{ImportParams, SharedParams}; + +/// The `check-block` command used to validate blocks. +#[derive(Debug, StructOpt, Clone)] +pub struct CheckBlockCmd { + /// Block hash or number + #[structopt(value_name = "HASH or NUMBER")] + pub input: String, + + /// The default number of 64KB pages to ever allocate for Wasm execution. + /// + /// Don't alter this unless you know what you're doing. + #[structopt(long = "default-heap-pages", value_name = "COUNT")] + pub default_heap_pages: Option, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub import_params: ImportParams, +} + +impl CheckBlockCmd { + /// Run the check-block command + pub fn run( + self, + mut config: Configuration, + builder: B, + ) -> error::Result<()> + where + B: FnOnce(Configuration) -> Result, + G: RuntimeGenesis, + E: ChainSpecExtension, + BC: ServiceBuilderCommand + Unpin, + BB: sp_runtime::traits::Block + Debug, + <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, + ::Hash: std::str::FromStr, + { + assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); + + crate::fill_import_params( + &mut config, + &self.import_params, + sc_service::Roles::FULL, + self.shared_params.dev, + )?; + crate::fill_config_keystore_in_memory(&mut config)?; + + let input = if self.input.starts_with("0x") { &self.input[2..] } else { &self.input[..] }; + let block_id = match FromStr::from_str(input) { + Ok(hash) => BlockId::hash(hash), + Err(_) => match self.input.parse::() { + Ok(n) => BlockId::number((n as u32).into()), + Err(_) => return Err(error::Error::Input("Invalid hash or number specified".into())), + } + }; + + let start = std::time::Instant::now(); + run_until_exit(config, |config| { + Ok(builder(config)?.check_block(block_id)) + })?; + println!("Completed in {} ms.", start.elapsed().as_millis()); + + Ok(()) + } +} diff --git a/client/cli/src/params/export_blocks.rs b/client/cli/src/params/export_blocks.rs new file mode 100644 index 0000000000000..3c1891bfc7690 --- /dev/null +++ b/client/cli/src/params/export_blocks.rs @@ -0,0 +1,98 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +use std::{path::PathBuf}; +use structopt::{StructOpt}; +use sc_service::{ + Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand, + config::DatabaseConfig, +}; +use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; +use crate::error; +use std::fmt::Debug; +use log::info; +use std::io; +use std::fs; +use crate::runtime::run_until_exit; + +use super::{SharedParams, BlockNumber}; + +/// The `export-blocks` command used to export blocks. +#[derive(Debug, StructOpt, Clone)] +pub struct ExportBlocksCmd { + /// Output file name or stdout if unspecified. + #[structopt(parse(from_os_str))] + pub output: Option, + + /// Specify starting block number. + /// + /// Default is 1. + #[structopt(long = "from", value_name = "BLOCK")] + pub from: Option, + + /// Specify last block number. + /// + /// Default is best block. + #[structopt(long = "to", value_name = "BLOCK")] + pub to: Option, + + /// Use JSON output rather than binary. + #[structopt(long = "json")] + pub json: bool, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + +impl ExportBlocksCmd { + /// Run the export-blocks command + pub fn run( + self, + mut config: Configuration, + builder: B, + ) -> error::Result<()> + where + B: FnOnce(Configuration) -> Result, + G: RuntimeGenesis, + E: ChainSpecExtension, + BC: ServiceBuilderCommand + Unpin, + BB: sp_runtime::traits::Block + Debug, + <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, + ::Hash: std::str::FromStr, + { + assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); + + crate::fill_config_keystore_in_memory(&mut config)?; + + if let DatabaseConfig::Path { ref path, .. } = config.expect_database() { + info!("DB path: {}", path.display()); + } + let from = self.from.as_ref().and_then(|f| f.parse().ok()).unwrap_or(1); + let to = self.to.as_ref().and_then(|t| t.parse().ok()); + + let json = self.json; + + let file: Box = match &self.output { + Some(filename) => Box::new(fs::File::create(filename)?), + None => Box::new(io::stdout()), + }; + + run_until_exit(config, |config| { + Ok(builder(config)?.export_blocks(file, from.into(), to, json)) + }) + } +} diff --git a/client/cli/src/params/generate.rs b/client/cli/src/params/generate.rs new file mode 100644 index 0000000000000..5843653c2125d --- /dev/null +++ b/client/cli/src/params/generate.rs @@ -0,0 +1,66 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Implementation of the `generate` subcommand + +use super::{SharedParams, RunCmd, Crypto, get_password}; +use crate::error::{self, Error}; +use bip39::{Language, Mnemonic, MnemonicType}; +use structopt::StructOpt; + +/// The `generate` command +#[derive(Debug, StructOpt, Clone)] +#[structopt(name = "generate", about = "Generate a random account")] +pub struct GenerateCmd { + /// The number of words in the phrase to generate. One of 12 default), 15, 18, 21 and 24. + #[structopt(long, short = "w", value_name = "WORDS")] + words: Option, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + +impl GenerateCmd { + /// Run the command + pub fn run( + self, + run_cmd: RunCmd, + ) -> error::Result<()> { + let words = match self.words { + Some(words) => { + MnemonicType::for_word_count(words) + .map_err(|_| { + Error::Input("Invalid number of words given for phrase: must be 12/15/18/21/24".into()) + })? + }, + None => MnemonicType::Words12, + }; + let mnemonic = Mnemonic::new(words, Language::English); + let password = get_password(&run_cmd)?; + let maybe_network = self.shared_params.network; + let output = self.shared_params.output_type; + + C::print_from_uri( + mnemonic.phrase(), + password.as_ref().map(String::as_str), + maybe_network, + output + ); + + Ok(()) + } +} diff --git a/client/cli/src/params/generate_node_key.rs b/client/cli/src/params/generate_node_key.rs new file mode 100644 index 0000000000000..8775b6c19cf5b --- /dev/null +++ b/client/cli/src/params/generate_node_key.rs @@ -0,0 +1,50 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Implementation of the `generate-node-key` subcommand + +use crate::error; +use structopt::StructOpt; +use std::{path::PathBuf, fs}; +use libp2p::identity::{ed25519 as libp2p_ed25519, PublicKey}; + +#[derive(Debug, StructOpt, Clone)] +#[structopt( + name = "generate-node-key", + about = "Generate a random node libp2p key, save it to file and print its peer ID" +)] +pub struct GenerateNodeKeyCmd { + /// Name of file to save secret key to. + #[structopt(long)] + file: PathBuf, +} + +impl GenerateNodeKeyCmd { + /// Run the command + pub fn run(self) -> error::Result<()> { + let file = self.file; + + let keypair = libp2p_ed25519::Keypair::generate(); + let secret = keypair.secret(); + let peer_id = PublicKey::Ed25519(keypair.public()).into_peer_id(); + + fs::write(file, secret.as_ref())?; + + println!("{}", peer_id); + + Ok(()) + } +} diff --git a/client/cli/src/params/import_blocks.rs b/client/cli/src/params/import_blocks.rs new file mode 100644 index 0000000000000..77671fe8f89ff --- /dev/null +++ b/client/cli/src/params/import_blocks.rs @@ -0,0 +1,235 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +use std::path::PathBuf; +use structopt::{StructOpt, clap::arg_enum}; +use sc_service::{Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand}; +use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; +use crate::error; +use std::fmt::Debug; +use std::io; +use std::fs; +use std::io::Read; +use crate::runtime::run_until_exit; +use crate::execution_strategy::*; +use super::{SharedParams, WasmExecutionMethod, ReadPlusSeek}; + +arg_enum! { + #[allow(missing_docs)] + #[derive(Debug, Copy, Clone, PartialEq, Eq)] + pub enum TracingReceiver { + Log, + Telemetry, + Grafana, + } +} + +impl Into for TracingReceiver { + fn into(self) -> sc_tracing::TracingReceiver { + match self { + TracingReceiver::Log => sc_tracing::TracingReceiver::Log, + TracingReceiver::Telemetry => sc_tracing::TracingReceiver::Telemetry, + TracingReceiver::Grafana => sc_tracing::TracingReceiver::Grafana, + } + } +} + +/// Execution strategies parameters. +#[derive(Debug, StructOpt, Clone)] +pub struct ExecutionStrategies { + /// The means of execution used when calling into the runtime while syncing blocks. + #[structopt( + long = "execution-syncing", + value_name = "STRATEGY", + possible_values = &ExecutionStrategy::variants(), + case_insensitive = true, + default_value = DEFAULT_EXECUTION_SYNCING.as_str(), + )] + pub execution_syncing: ExecutionStrategy, + + /// The means of execution used when calling into the runtime while importing blocks. + #[structopt( + long = "execution-import-block", + value_name = "STRATEGY", + possible_values = &ExecutionStrategy::variants(), + case_insensitive = true, + default_value = DEFAULT_EXECUTION_IMPORT_BLOCK.as_str(), + )] + pub execution_import_block: ExecutionStrategy, + + /// The means of execution used when calling into the runtime while constructing blocks. + #[structopt( + long = "execution-block-construction", + value_name = "STRATEGY", + possible_values = &ExecutionStrategy::variants(), + case_insensitive = true, + default_value = DEFAULT_EXECUTION_BLOCK_CONSTRUCTION.as_str(), + )] + pub execution_block_construction: ExecutionStrategy, + + /// The means of execution used when calling into the runtime while using an off-chain worker. + #[structopt( + long = "execution-offchain-worker", + value_name = "STRATEGY", + possible_values = &ExecutionStrategy::variants(), + case_insensitive = true, + default_value = DEFAULT_EXECUTION_OFFCHAIN_WORKER.as_str(), + )] + pub execution_offchain_worker: ExecutionStrategy, + + /// The means of execution used when calling into the runtime while not syncing, importing or constructing blocks. + #[structopt( + long = "execution-other", + value_name = "STRATEGY", + possible_values = &ExecutionStrategy::variants(), + case_insensitive = true, + default_value = DEFAULT_EXECUTION_OTHER.as_str(), + )] + pub execution_other: ExecutionStrategy, + + /// The execution strategy that should be used by all execution contexts. + #[structopt( + long = "execution", + value_name = "STRATEGY", + possible_values = &ExecutionStrategy::variants(), + case_insensitive = true, + conflicts_with_all = &[ + "execution-other", + "execution-offchain-worker", + "execution-block-construction", + "execution-import-block", + "execution-syncing", + ] + )] + pub execution: Option, +} + +/// Parameters for block import. +#[derive(Debug, StructOpt, Clone)] +pub struct ImportParams { + /// Specify the state pruning mode, a number of blocks to keep or 'archive'. + /// + /// Default is to keep all block states if the node is running as a + /// validator (i.e. 'archive'), otherwise state is only kept for the last + /// 256 blocks. + #[structopt(long = "pruning", value_name = "PRUNING_MODE")] + pub pruning: Option, + + /// Force start with unsafe pruning settings. + /// + /// When running as a validator it is highly recommended to disable state + /// pruning (i.e. 'archive') which is the default. The node will refuse to + /// start as a validator if pruning is enabled unless this option is set. + #[structopt(long = "unsafe-pruning")] + pub unsafe_pruning: bool, + + /// Method for executing Wasm runtime code. + #[structopt( + long = "wasm-execution", + value_name = "METHOD", + possible_values = &WasmExecutionMethod::enabled_variants(), + case_insensitive = true, + default_value = "Interpreted" + )] + pub wasm_method: WasmExecutionMethod, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub execution_strategies: ExecutionStrategies, + + /// Limit the memory the database cache can use. + #[structopt(long = "db-cache", value_name = "MiB", default_value = "1024")] + pub database_cache_size: u32, + + /// Specify the state cache size. + #[structopt(long = "state-cache-size", value_name = "Bytes", default_value = "67108864")] + pub state_cache_size: usize, + + /// Comma separated list of targets for tracing + #[structopt(long = "tracing-targets", value_name = "TARGETS")] + pub tracing_targets: Option, + + /// Receiver to process tracing messages + #[structopt( + long = "tracing-receiver", + value_name = "RECEIVER", + possible_values = &TracingReceiver::variants(), + case_insensitive = true, + default_value = "Log" + )] + pub tracing_receiver: TracingReceiver, +} + + +/// The `import-blocks` command used to import blocks. +#[derive(Debug, StructOpt, Clone)] +pub struct ImportBlocksCmd { + /// Input file or stdin if unspecified. + #[structopt(parse(from_os_str))] + pub input: Option, + + /// The default number of 64KB pages to ever allocate for Wasm execution. + /// + /// Don't alter this unless you know what you're doing. + #[structopt(long = "default-heap-pages", value_name = "COUNT")] + pub default_heap_pages: Option, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub import_params: ImportParams, +} + +impl ImportBlocksCmd { + /// Run the import-blocks command + pub fn run( + self, + mut config: Configuration, + builder: B, + ) -> error::Result<()> + where + B: FnOnce(Configuration) -> Result, + G: RuntimeGenesis, + E: ChainSpecExtension, + BC: ServiceBuilderCommand + Unpin, + BB: sp_runtime::traits::Block + Debug, + <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, + ::Hash: std::str::FromStr, + { + crate::fill_import_params( + &mut config, + &self.import_params, + sc_service::Roles::FULL, + self.shared_params.dev, + )?; + + let file: Box = match &self.input { + Some(filename) => Box::new(fs::File::open(filename)?), + None => { + let mut buffer = Vec::new(); + io::stdin().read_to_end(&mut buffer)?; + Box::new(io::Cursor::new(buffer)) + }, + }; + + run_until_exit(config, |config| { + Ok(builder(config)?.import_blocks(file, false)) + }) + } +} diff --git a/client/cli/src/params/inspect.rs b/client/cli/src/params/inspect.rs new file mode 100644 index 0000000000000..747decf672361 --- /dev/null +++ b/client/cli/src/params/inspect.rs @@ -0,0 +1,58 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Implementation of the `inspect` subcommand + +use crate::error; +use super::{SharedParams, RunCmd, get_password, read_uri, Crypto}; +use structopt::StructOpt; +use std::{path::PathBuf, fs}; +use libp2p::identity::{ed25519 as libp2p_ed25519, PublicKey}; + +#[derive(Debug, StructOpt, Clone)] +#[structopt( + name = "inspect", + about = "Gets a public key and a SS58 address from the provided Secret URI" +)] +pub struct InspectCmd { + /// A Key URI to be inspected. May be a secret seed, secret URI (with derivation paths and password), SS58 or + /// public URI. If the value is a file, the file content is used as URI. + /// If not given, you will be prompted for the URI. + #[structopt(long)] + uri: Option, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + +impl InspectCmd { + pub fn run(self, run_cmd: RunCmd) -> error::Result<()> { + let uri = read_uri(self.uri)?; + + let pass = get_password(&run_cmd)?; + + C::print_from_uri( + &uri, + password.as_ref().map(String::as_str), + self.shared_params.network, + self.shared_params.output_type + ); + + Ok(()) + } +} + diff --git a/client/cli/src/params/mod.rs b/client/cli/src/params/mod.rs new file mode 100644 index 0000000000000..3022c6321258e --- /dev/null +++ b/client/cli/src/params/mod.rs @@ -0,0 +1,495 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +use std::{ + str::FromStr, path::PathBuf, convert::TryInto, +}; +use hex_literal::hex; +use structopt::{StructOpt, clap::arg_enum}; +use std::fmt::Debug; +use std::io::{Read, Seek}; +use sp_core::{ + crypto::{Ss58AddressFormat, Ss58Codec}, + Pair, Public, hexdisplay::HexDisplay, +}; +use sp_runtime::traits::{Verify, IdentifyAccount}; +use serde_json::json; +use crate::error::{Error, self}; + +mod import_blocks; +mod export_blocks; +mod check_block; +mod build_spec; +mod benchmark; +mod revert; +mod run; +mod subcommand; +mod purge_chain; +mod generate; +mod generate_node_key; +mod inspect; +mod sign; +mod sign_transaction; + +pub use import_blocks::*; +pub use export_blocks::*; +pub use benchmark::*; +pub use build_spec::*; +pub use check_block::*; +pub use revert::*; +pub use run::*; +pub use subcommand::*; +pub use purge_chain::*; +pub use generate::*; +pub use generate_node_key::*; +pub use inspect::*; +pub use sign::*; +pub use sign_transaction::*; + +pub use crate::execution_strategy::ExecutionStrategy; +use sp_runtime::MultiSignature; + +impl Into for ExecutionStrategy { + fn into(self) -> sc_client_api::ExecutionStrategy { + match self { + ExecutionStrategy::Native => sc_client_api::ExecutionStrategy::NativeWhenPossible, + ExecutionStrategy::Wasm => sc_client_api::ExecutionStrategy::AlwaysWasm, + ExecutionStrategy::Both => sc_client_api::ExecutionStrategy::Both, + ExecutionStrategy::NativeElseWasm => sc_client_api::ExecutionStrategy::NativeElseWasm, + } + } +} + +arg_enum! { + /// How to execute Wasm runtime code + #[allow(missing_docs)] + #[derive(Debug, Clone, Copy)] + pub enum WasmExecutionMethod { + // Uses an interpreter. + Interpreted, + // Uses a compiled runtime. + Compiled, + } +} + +impl WasmExecutionMethod { + /// Returns list of variants that are not disabled by feature flags. + fn enabled_variants() -> Vec<&'static str> { + Self::variants() + .iter() + .cloned() + .filter(|&name| cfg!(feature = "wasmtime") || name != "Compiled") + .collect() + } +} + +impl Into for WasmExecutionMethod { + fn into(self) -> sc_service::config::WasmExecutionMethod { + match self { + WasmExecutionMethod::Interpreted => sc_service::config::WasmExecutionMethod::Interpreted, + #[cfg(feature = "wasmtime")] + WasmExecutionMethod::Compiled => sc_service::config::WasmExecutionMethod::Compiled, + #[cfg(not(feature = "wasmtime"))] + WasmExecutionMethod::Compiled => panic!( + "Substrate must be compiled with \"wasmtime\" feature for compiled Wasm execution" + ), + } + } +} + +/// Shared parameters used by all `CoreParams`. +#[derive(Debug, StructOpt, Clone)] +#[structopt(rename_all = "kebab-case")] +pub struct SharedParams { + /// Specify the chain specification (one of dev, local or staging). + #[structopt(long = "chain", value_name = "CHAIN_SPEC")] + pub chain: Option, + + /// Specify the development chain. + #[structopt(long)] + pub dev: bool, + + /// Specify custom base path. + #[structopt(long, short = "d", value_name = "PATH", parse(from_os_str))] + pub base_path: Option, + + /// Sets a custom logging filter. + #[structopt(short = "l", long = "log", value_name = "LOG_PATTERN")] + pub log: Option, + + /// output type + #[structopt( + long, + value_name = "OUTPUT_TYPE", + possible_values = &OutputType::variants(), + case_insensitive = true, + default_value = "Text" + )] + pub output_type: OutputType, + + /// network format + #[structopt( + long, + value_name = "NETWORK", + parse(try_from_str = parse_network), + )] + pub network: Option, +} + +fn parse_network(network: &str) -> Result { + network.try_into() + .map_err(|_| Error::Input("Invalid network name. See --help for available networks.".into())) +} + +/// Wrapper type of `String` which holds an arbitary sized unsigned integer formatted as decimal. +#[derive(Debug, Clone)] +pub struct BlockNumber(String); + +impl FromStr for BlockNumber { + type Err = String; + + fn from_str(block_number: &str) -> Result { + if block_number.chars().any(|d| !d.is_digit(10)) { + Err(format!( + "Invalid block number: {}, expected decimal formatted unsigned integer", + block_number + )) + } else { + Ok(Self(block_number.to_owned())) + } + } +} + +impl BlockNumber { + /// Wrapper on top of `std::str::parse` but with `Error` as a `String` + /// + /// See `https://doc.rust-lang.org/std/primitive.str.html#method.parse` for more elaborate + /// documentation. + pub fn parse(&self) -> Result + where + N: FromStr, + N::Err: std::fmt::Debug, + { + self.0 + .parse() + .map_err(|e| format!("BlockNumber: {} parsing failed because of {:?}", self.0, e)) + } +} + +#[derive(Debug, StructOpt, Clone)] +pub struct VerifyCmd { + /// ... + #[structopt(long)] + uri: String, + + #[structopt(long)] + hex: bool, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + +#[derive(Debug, StructOpt, Clone)] +pub struct InsertCmd { + /// ... + #[structopt(long)] + node_url: Option, + + /// ... + #[structopt(long)] + suri: Option, + + #[structopt(long)] + key_type: bool, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + +#[derive(Debug, StructOpt, Clone)] +pub struct TransferCmd { + /// ... + #[structopt(long)] + from: Option, + + /// ... + #[structopt(long)] + to: Option, + + /// ... + #[structopt(long)] + index: Option, + + /// ... + #[structopt(long)] + genesis: Option, + + /// ... + #[structopt(long)] + amount: Option, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + +/// Internal trait used to cast to a dynamic type that implements Read and Seek. +pub trait ReadPlusSeek: Read + Seek {} + +impl ReadPlusSeek for T {} + +arg_enum! { + #[derive(Debug, Copy, Clone, PartialEq, Eq)] + pub enum OutputType { + Json, + Text, + } +} + +pub type SignatureOf = <::Pair as Pair>::Signature; +pub type PublicOf = <::Pair as Pair>::Public; +pub type SeedOf = <::Pair as Pair>::Seed; +pub type AccountPublic = ::Signer; + +pub trait IntoRuntimePublic: Sized + AsRef<[u8]> + Ss58Codec { + /// Converts the public key into a runtime account public key, if possible. If not possible, bombs out. + fn into_runtime(self) -> AccountPublic { + panic!("This cryptography isn't supported for this runtime.") + } +} + +pub trait IntoRuntimeSignature: AsRef<[u8]> + AsMut<[u8]> + Default { + /// Converts the signature into a runtime account signature, if possible. If not possible, bombs out. + fn into_runtime(self) -> MultiSignature { + panic!("This cryptography isn't supported for this runtime.") + } +} + +fn format_seed(seed: SeedOf) -> String { + format!("0x{}", HexDisplay::from(&seed.as_ref())) +} + +fn format_public_key(public_key: PublicOf) -> String { + format!("0x{}", HexDisplay::from(&public_key.as_ref())) +} + +fn format_account_id(public_key: PublicOf) -> String where + PublicOf: IntoRuntimePublic, +{ + format!("0x{}", HexDisplay::from(&public_key.into_runtime().into_account().as_ref())) +} + +pub fn read_uri(uri: Option) -> error::Result { + if let Some(uri) = uri { + let file = PathBuf::from(uri); + if file.is_file() { + std::fs::read_to_string(uri)? + .trim_end() + .into() + } else { + uri.into() + } + } else { + rpassword::read_password_from_tty(Some("URI: "))? + } +} + +pub fn decode_hex>(message: T) -> Result, Error> { + hex::decode(message).map_err(|e| Error::Formatted(format!("Invalid hex ({})", e))) +} + +pub fn read_pair( + matched_suri: Option<&str>, + password: Option<&str>, +) -> Result<::Pair, Error> where + SignatureOf: SignatureT, + PublicOf: PublicT, +{ + let suri = matched_suri.ok_or(Error::Static("parameter is required; thus it can't be None; qed"))?; + Ok(C::pair_from_suri(suri, password)) +} + +pub fn read_message_from_stdin(should_decode: bool) -> Result, Error> { + let mut message = vec![]; + std::io::stdin() + .lock() + .read_to_end(&mut message)?; + if should_decode { + message = decode_hex(&message)?; + } + Ok(message) +} + +pub fn get_password(run_cmd: &RunCmd) -> error::Result> { + let password_interactive = run_cmd.password_interactive; + let password = run_cmd.password.as_ref(); + + let pass = if password_interactive { + Some(rpassword::read_password_from_tty(Some("Key password: "))?) + } else { + password.map(Into::into) + }; + + Ok(pass) +} + +pub fn as_str(s: &Option) -> Option<&str> { + s.as_ref().map(String::as_ref) +} + + +pub trait Crypto: Sized { + type Pair: Pair; + type Public: IntoRuntimePublic + Public + Ss58Codec + AsRef<[u8]> + std::hash::Hash; + + fn pair_from_suri(suri: &str, password: Option<&str>) -> Self::Pair { + Self::Pair::from_string(suri, password).expect("Invalid phrase") + } + + fn ss58_from_pair(pair: &Self::Pair) -> String where + ::Public: IntoRuntimePublic, + { + pair.public().into_runtime().into_account().to_ss58check() + } + + fn public_from_pair(pair: &Self::Pair) -> Self::Public { + pair.public() + } + + fn print_from_uri( + uri: &str, + password: Option<&str>, + network_override: Option, + output: OutputType, + ) where + ::Public: IntoRuntimePublic, + { + if let Ok((pair, seed)) = Self::Pair::from_phrase(uri, password) { + let public_key = Self::public_from_pair(&pair); + + match output { + OutputType::Json => { + let json = json!({ + "secretPhrase": uri, + "secretSeed": format_seed::(seed), + "publicKey": format_public_key::(public_key.clone()), + "accountId": format_account_id::(public_key), + "ss58Address": Self::ss58_from_pair(&pair), + }); + println!("{}", serde_json::to_string_pretty(&json).expect("Json pretty print failed")); + }, + OutputType::Text => { + println!("Secret phrase `{}` is account:\n \ + Secret seed: {}\n \ + Public key (hex): {}\n \ + Account ID: {}\n \ + SS58 Address: {}", + uri, + format_seed::(seed), + format_public_key::(public_key.clone()), + format_account_id::(public_key), + Self::ss58_from_pair(&pair), + ); + }, + } + } else if let Ok((pair, seed)) = Self::Pair::from_string_with_seed(uri, password) { + let public_key = Self::public_from_pair(&pair); + + match output { + OutputType::Json => { + let json = json!({ + "secretKeyUri": uri, + "secretSeed": if let Some(seed) = seed { format_seed::(seed) } else { "n/a".into() }, + "publicKey": format_public_key::(public_key.clone()), + "accountId": format_account_id::(public_key), + "ss58Address": Self::ss58_from_pair(&pair), + }); + println!("{}", serde_json::to_string_pretty(&json).expect("Json pretty print failed")); + }, + OutputType::Text => { + println!("Secret Key URI `{}` is account:\n \ + Secret seed: {}\n \ + Public key (hex): {}\n \ + Account ID: {}\n \ + SS58 Address: {}", + uri, + if let Some(seed) = seed { format_seed::(seed) } else { "n/a".into() }, + format_public_key::(public_key.clone()), + format_account_id::(public_key), + Self::ss58_from_pair(&pair), + ); + }, + } + + } else if let Ok((public_key, v)) = + ::Public::from_string_with_version(uri) + { + let v = network_override.unwrap_or(v); + + match output { + OutputType::Json => { + let json = json!({ + "publicKeyUri": uri, + "networkId": String::from(v), + "publicKey": format_public_key::(public_key.clone()), + "accountId": format_account_id::(public_key.clone()), + "ss58Address": public_key.to_ss58check_with_version(v), + }); + println!("{}", serde_json::to_string_pretty(&json).expect("Json pretty print failed")); + }, + OutputType::Text => { + println!("Public Key URI `{}` is account:\n \ + Network ID/version: {}\n \ + Public key (hex): {}\n \ + Account ID: {}\n \ + SS58 Address: {}", + uri, + String::from(v), + format_public_key::(public_key.clone()), + format_account_id::(public_key.clone()), + public_key.to_ss58check_with_version(v), + ); + }, + } + } else { + println!("Invalid phrase/URI given"); + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[derive(Debug, Clone, StructOpt)] + struct Cmd { + #[allow(missing_docs)] + #[structopt(subcommand)] + pub subcommand: Option, + #[allow(missing_docs)] + #[structopt(flatten)] + pub run: RunCmd, + } + + #[test] + fn subcommand() { + let vec = vec!["cmd", "--password", "qwerty", "generate", "--words=12", "--output-type", "Json"]; + let cmd = Cmd::from_iter(vec); + println!("{:#?}", cmd.subcommand) + } +} \ No newline at end of file diff --git a/client/cli/src/params/purge_chain.rs b/client/cli/src/params/purge_chain.rs new file mode 100644 index 0000000000000..591459a7530b3 --- /dev/null +++ b/client/cli/src/params/purge_chain.rs @@ -0,0 +1,90 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +use structopt::{StructOpt}; +use sc_service::{ + Configuration, ChainSpecExtension, RuntimeGenesis, config::DatabaseConfig, +}; +use crate::error; +use std::fmt::Debug; +use std::fs; +use std::io::{self, Write}; +use super::SharedParams; + +/// The `purge-chain` command used to remove the whole chain. +#[derive(Debug, StructOpt, Clone)] +pub struct PurgeChainCmd { + /// Skip interactive prompt by answering yes automatically. + #[structopt(short = "y")] + pub yes: bool, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + +impl PurgeChainCmd { + /// Run the purge command + pub fn run( + self, + mut config: Configuration, + ) -> error::Result<()> + where + G: RuntimeGenesis, + E: ChainSpecExtension, + { + assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); + + crate::fill_config_keystore_in_memory(&mut config)?; + + let db_path = match config.expect_database() { + DatabaseConfig::Path { path, .. } => path, + _ => { + eprintln!("Cannot purge custom database implementation"); + return Ok(()); + } + }; + + if !self.yes { + print!("Are you sure to remove {:?}? [y/N]: ", &db_path); + io::stdout().flush().expect("failed to flush stdout"); + + let mut input = String::new(); + io::stdin().read_line(&mut input)?; + let input = input.trim(); + + match input.chars().nth(0) { + Some('y') | Some('Y') => {}, + _ => { + println!("Aborted"); + return Ok(()); + }, + } + } + + match fs::remove_dir_all(&db_path) { + Ok(_) => { + println!("{:?} removed.", &db_path); + Ok(()) + }, + Err(ref err) if err.kind() == io::ErrorKind::NotFound => { + eprintln!("{:?} did not exist.", &db_path); + Ok(()) + }, + Err(err) => Result::Err(err.into()) + } + } +} diff --git a/client/cli/src/params/revert.rs b/client/cli/src/params/revert.rs new file mode 100644 index 0000000000000..7ef9f00a33e24 --- /dev/null +++ b/client/cli/src/params/revert.rs @@ -0,0 +1,64 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +use structopt::{StructOpt}; +use sc_service::{ + Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand, +}; +use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; +use crate::error; +use std::fmt::Debug; +use super::{BlockNumber, SharedParams}; + + +/// The `revert` command used revert the chain to a previous state. +#[derive(Debug, StructOpt, Clone)] +pub struct RevertCmd { + /// Number of blocks to revert. + #[structopt(default_value = "256")] + pub num: BlockNumber, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + +impl RevertCmd { + /// Run the revert command + pub fn run( + self, + mut config: Configuration, + builder: B, + ) -> error::Result<()> + where + B: FnOnce(Configuration) -> Result, + G: RuntimeGenesis, + E: ChainSpecExtension, + BC: ServiceBuilderCommand + Unpin, + BB: sp_runtime::traits::Block + Debug, + <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, + ::Hash: std::str::FromStr, + { + assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); + + crate::fill_config_keystore_in_memory(&mut config)?; + + let blocks = self.num.parse()?; + builder(config)?.revert_chain(blocks)?; + + Ok(()) + } +} \ No newline at end of file diff --git a/client/cli/src/params/run.rs b/client/cli/src/params/run.rs new file mode 100644 index 0000000000000..ae3d58106bb86 --- /dev/null +++ b/client/cli/src/params/run.rs @@ -0,0 +1,493 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +use std::{path::PathBuf}; +use structopt::{StructOpt, clap::arg_enum}; +use sc_service::{ + AbstractService, Configuration, ChainSpecExtension, RuntimeGenesis, +}; +use crate::VersionInfo; +use crate::error; +use std::fmt::Debug; +use super::{SharedParams, ImportParams}; + +/// CORS setting +/// +/// The type is introduced to overcome `Option>` +/// handling of `structopt`. +#[derive(Clone, Debug)] +pub enum Cors { + /// All hosts allowed + All, + /// Only hosts on the list are allowed. + List(Vec), +} + +impl From for Option> { + fn from(cors: Cors) -> Self { + match cors { + Cors::All => None, + Cors::List(list) => Some(list), + } + } +} + +/// Parse cors origins +fn parse_cors(s: &str) -> Result> { + let mut is_all = false; + let mut origins = Vec::new(); + for part in s.split(',') { + match part { + "all" | "*" => { + is_all = true; + break; + }, + other => origins.push(other.to_owned()), + } + } + + Ok(if is_all { Cors::All } else { Cors::List(origins) }) +} + +/// Default to verbosity level 0, if none is provided. +fn parse_telemetry_endpoints(s: &str) -> Result<(String, u8), Box> { + let pos = s.find(' '); + match pos { + None => { + Ok((s.to_owned(), 0)) + }, + Some(pos_) => { + let verbosity = s[pos_ + 1..].parse()?; + let url = s[..pos_].parse()?; + Ok((url, verbosity)) + } + } +} + +/// Parameters used to create the pool configuration. +#[derive(Debug, StructOpt, Clone)] +pub struct TransactionPoolParams { + /// Maximum number of transactions in the transaction pool. + #[structopt(long = "pool-limit", value_name = "COUNT", default_value = "8192")] + pub pool_limit: usize, + /// Maximum number of kilobytes of all transactions stored in the pool. + #[structopt(long = "pool-kbytes", value_name = "COUNT", default_value = "20480")] + pub pool_kbytes: usize, +} + +arg_enum! { + #[allow(missing_docs)] + #[derive(Debug, Copy, Clone, PartialEq, Eq)] + pub enum NodeKeyType { + Ed25519 + } +} + +arg_enum! { + /// Whether off-chain workers are enabled. + #[allow(missing_docs)] + #[derive(Debug, Clone)] + pub enum OffchainWorkerEnabled { + Always, + Never, + WhenValidating, + } +} + +/// Parameters used to create the `NodeKeyConfig`, which determines the keypair +/// used for libp2p networking. +#[derive(Debug, StructOpt, Clone)] +pub struct NodeKeyParams { + /// The secret key to use for libp2p networking. + /// + /// The value is a string that is parsed according to the choice of + /// `--node-key-type` as follows: + /// + /// `ed25519`: + /// The value is parsed as a hex-encoded Ed25519 32 bytes secret key, + /// i.e. 64 hex characters. + /// + /// The value of this option takes precedence over `--node-key-file`. + /// + /// WARNING: Secrets provided as command-line arguments are easily exposed. + /// Use of this option should be limited to development and testing. To use + /// an externally managed secret key, use `--node-key-file` instead. + #[structopt(long = "node-key", value_name = "KEY")] + pub node_key: Option, + + /// The type of secret key to use for libp2p networking. + /// + /// The secret key of the node is obtained as follows: + /// + /// * If the `--node-key` option is given, the value is parsed as a secret key + /// according to the type. See the documentation for `--node-key`. + /// + /// * If the `--node-key-file` option is given, the secret key is read from the + /// specified file. See the documentation for `--node-key-file`. + /// + /// * Otherwise, the secret key is read from a file with a predetermined, + /// type-specific name from the chain-specific network config directory + /// inside the base directory specified by `--base-dir`. If this file does + /// not exist, it is created with a newly generated secret key of the + /// chosen type. + /// + /// The node's secret key determines the corresponding public key and hence the + /// node's peer ID in the context of libp2p. + #[structopt( + long = "node-key-type", + value_name = "TYPE", + possible_values = &NodeKeyType::variants(), + case_insensitive = true, + default_value = "Ed25519" + )] + pub node_key_type: NodeKeyType, + + /// The file from which to read the node's secret key to use for libp2p networking. + /// + /// The contents of the file are parsed according to the choice of `--node-key-type` + /// as follows: + /// + /// `ed25519`: + /// The file must contain an unencoded 32 bytes Ed25519 secret key. + /// + /// If the file does not exist, it is created with a newly generated secret key of + /// the chosen type. + #[structopt(long = "node-key-file", value_name = "FILE")] + pub node_key_file: Option, +} + +/// Parameters used to create the network configuration. +#[derive(Debug, StructOpt, Clone)] +pub struct NetworkConfigurationParams { + /// Specify a list of bootnodes. + #[structopt(long = "bootnodes", value_name = "URL")] + pub bootnodes: Vec, + + /// Specify a list of reserved node addresses. + #[structopt(long = "reserved-nodes", value_name = "URL")] + pub reserved_nodes: Vec, + + /// Whether to only allow connections to/from reserved nodes. + /// + /// If you are a validator your node might still connect to other validator + /// nodes regardless of whether they are defined as reserved nodes. + #[structopt(long = "reserved-only")] + pub reserved_only: bool, + + /// Specify a list of sentry node public addresses. + #[structopt( + long = "sentry-nodes", + value_name = "URL", + conflicts_with_all = &[ "sentry" ] + )] + pub sentry_nodes: Vec, + + /// Listen on this multiaddress. + #[structopt(long = "listen-addr", value_name = "LISTEN_ADDR")] + pub listen_addr: Vec, + + /// Specify p2p protocol TCP port. + /// + /// Only used if --listen-addr is not specified. + #[structopt(long = "port", value_name = "PORT")] + pub port: Option, + + /// Allow connecting to private IPv4 addresses (as specified in + /// [RFC1918](https://tools.ietf.org/html/rfc1918)), unless the address was passed with + /// `--reserved-nodes` or `--bootnodes`. + #[structopt(long = "no-private-ipv4")] + pub no_private_ipv4: bool, + + /// Specify the number of outgoing connections we're trying to maintain. + #[structopt(long = "out-peers", value_name = "COUNT", default_value = "25")] + pub out_peers: u32, + + /// Specify the maximum number of incoming connections we're accepting. + #[structopt(long = "in-peers", value_name = "COUNT", default_value = "25")] + pub in_peers: u32, + + /// Disable mDNS discovery. + /// + /// By default, the network will use mDNS to discover other nodes on the + /// local network. This disables it. Automatically implied when using --dev. + #[structopt(long = "no-mdns")] + pub no_mdns: bool, + + /// Maximum number of peers to ask the same blocks in parallel. + /// + /// This allows downlading announced blocks from multiple peers. Decrease to save + /// traffic and risk increased latency. + #[structopt(long = "max-parallel-downloads", value_name = "COUNT", default_value = "5")] + pub max_parallel_downloads: u32, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub node_key_params: NodeKeyParams, + + /// Experimental feature flag. + #[structopt(long = "use-yamux-flow-control")] + pub use_yamux_flow_control: bool, +} + +/// The `run` command used to run a node. +#[derive(Debug, StructOpt, Clone)] +pub struct RunCmd { + /// Enable validator mode. + /// + /// The node will be started with the authority role and actively + /// participate in any consensus task that it can (e.g. depending on + /// availability of local keys). + #[structopt( + long = "validator", + conflicts_with_all = &[ "sentry" ] + )] + pub validator: bool, + + /// Enable sentry mode. + /// + /// The node will be started with the authority role and participate in + /// consensus tasks as an "observer", it will never actively participate + /// regardless of whether it could (e.g. keys are available locally). This + /// mode is useful as a secure proxy for validators (which would run + /// detached from the network), since we want this node to participate in + /// the full consensus protocols in order to have all needed consensus data + /// available to relay to private nodes. + #[structopt( + long = "sentry", + conflicts_with_all = &[ "validator", "light" ] + )] + pub sentry: bool, + + /// Disable GRANDPA voter when running in validator mode, otherwise disables the GRANDPA observer. + #[structopt(long = "no-grandpa")] + pub no_grandpa: bool, + + /// Experimental: Run in light client mode. + #[structopt(long = "light", conflicts_with = "sentry")] + pub light: bool, + + /// Listen to all RPC interfaces. + /// + /// Default is local. Note: not all RPC methods are safe to be exposed publicly. Use a RPC proxy + /// server to filter out dangerous methods. More details: https://github.com/paritytech/substrate/wiki/Public-RPC. + /// Use `--unsafe-rpc-external` to suppress the warning if you understand the risks. + #[structopt(long = "rpc-external")] + pub rpc_external: bool, + + /// Listen to all RPC interfaces. + /// + /// Same as `--rpc-external`. + #[structopt(long = "unsafe-rpc-external")] + pub unsafe_rpc_external: bool, + + /// Listen to all Websocket interfaces. + /// + /// Default is local. Note: not all RPC methods are safe to be exposed publicly. Use a RPC proxy + /// server to filter out dangerous methods. More details: https://github.com/paritytech/substrate/wiki/Public-RPC. + /// Use `--unsafe-ws-external` to suppress the warning if you understand the risks. + #[structopt(long = "ws-external")] + pub ws_external: bool, + + /// Listen to all Websocket interfaces. + /// + /// Same as `--ws-external`. + #[structopt(long = "unsafe-ws-external")] + pub unsafe_ws_external: bool, + + /// Listen to all Grafana data source interfaces. + /// + /// Default is local. + #[structopt(long = "grafana-external")] + pub grafana_external: bool, + + /// Specify HTTP RPC server TCP port. + #[structopt(long = "rpc-port", value_name = "PORT")] + pub rpc_port: Option, + + /// Specify WebSockets RPC server TCP port. + #[structopt(long = "ws-port", value_name = "PORT")] + pub ws_port: Option, + + /// Maximum number of WS RPC server connections. + #[structopt(long = "ws-max-connections", value_name = "COUNT")] + pub ws_max_connections: Option, + + /// Specify browser Origins allowed to access the HTTP & WS RPC servers. + /// + /// A comma-separated list of origins (protocol://domain or special `null` + /// value). Value of `all` will disable origin validation. Default is to + /// allow localhost, https://polkadot.js.org and + /// https://substrate-ui.parity.io origins. When running in --dev mode the + /// default is to allow all origins. + #[structopt(long = "rpc-cors", value_name = "ORIGINS", parse(try_from_str = parse_cors))] + pub rpc_cors: Option, + + /// Specify Grafana data source server TCP Port. + #[structopt(long = "grafana-port", value_name = "PORT")] + pub grafana_port: Option, + + /// The human-readable name for this node. + /// + /// The node name will be reported to the telemetry server, if enabled. + #[structopt(long = "name", value_name = "NAME")] + pub name: Option, + + /// Disable connecting to the Substrate telemetry server. + /// + /// Telemetry is on by default on global chains. + #[structopt(long = "no-telemetry")] + pub no_telemetry: bool, + + /// The URL of the telemetry server to connect to. + /// + /// This flag can be passed multiple times as a mean to specify multiple + /// telemetry endpoints. Verbosity levels range from 0-9, with 0 denoting + /// the least verbosity. If no verbosity level is specified the default is + /// 0. + #[structopt(long = "telemetry-url", value_name = "URL VERBOSITY", parse(try_from_str = parse_telemetry_endpoints))] + pub telemetry_endpoints: Vec<(String, u8)>, + + /// Should execute offchain workers on every block. + /// + /// By default it's only enabled for nodes that are authoring new blocks. + #[structopt( + long = "offchain-worker", + value_name = "ENABLED", + possible_values = &OffchainWorkerEnabled::variants(), + case_insensitive = true, + default_value = "WhenValidating" + )] + pub offchain_worker: OffchainWorkerEnabled, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub import_params: ImportParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub network_config: NetworkConfigurationParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub pool_config: TransactionPoolParams, + + /// Shortcut for `--name Alice --validator` with session keys for `Alice` added to keystore. + #[structopt(long, conflicts_with_all = &["bob", "charlie", "dave", "eve", "ferdie", "one", "two"])] + pub alice: bool, + + /// Shortcut for `--name Bob --validator` with session keys for `Bob` added to keystore. + #[structopt(long, conflicts_with_all = &["alice", "charlie", "dave", "eve", "ferdie", "one", "two"])] + pub bob: bool, + + /// Shortcut for `--name Charlie --validator` with session keys for `Charlie` added to keystore. + #[structopt(long, conflicts_with_all = &["alice", "bob", "dave", "eve", "ferdie", "one", "two"])] + pub charlie: bool, + + /// Shortcut for `--name Dave --validator` with session keys for `Dave` added to keystore. + #[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "eve", "ferdie", "one", "two"])] + pub dave: bool, + + /// Shortcut for `--name Eve --validator` with session keys for `Eve` added to keystore. + #[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "ferdie", "one", "two"])] + pub eve: bool, + + /// Shortcut for `--name Ferdie --validator` with session keys for `Ferdie` added to keystore. + #[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "one", "two"])] + pub ferdie: bool, + + /// Shortcut for `--name One --validator` with session keys for `One` added to keystore. + #[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "ferdie", "two"])] + pub one: bool, + + /// Shortcut for `--name Two --validator` with session keys for `Two` added to keystore. + #[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "ferdie", "one"])] + pub two: bool, + + /// Enable authoring even when offline. + #[structopt(long = "force-authoring")] + pub force_authoring: bool, + + /// Specify custom keystore path. + #[structopt(long = "keystore-path", value_name = "PATH", parse(from_os_str))] + pub keystore_path: Option, + + /// Use interactive shell for entering the password used by the keystore. + #[structopt( + long = "password-interactive", + conflicts_with_all = &[ "password", "password-filename" ] + )] + pub password_interactive: bool, + + /// Password used by the keystore. + #[structopt( + long = "password", + conflicts_with_all = &[ "password-interactive", "password-filename" ] + )] + pub password: Option, + + /// File that contains the password used by the keystore. + #[structopt( + long = "password-filename", + value_name = "PATH", + parse(from_os_str), + conflicts_with_all = &[ "password-interactive", "password" ] + )] + pub password_filename: Option +} + +impl RunCmd { + /// Get the `Sr25519Keyring` matching one of the flag + pub fn get_keyring(&self) -> Option { + use sp_keyring::Sr25519Keyring::*; + + if self.alice { Some(Alice) } + else if self.bob { Some(Bob) } + else if self.charlie { Some(Charlie) } + else if self.dave { Some(Dave) } + else if self.eve { Some(Eve) } + else if self.ferdie { Some(Ferdie) } + else if self.one { Some(One) } + else if self.two { Some(Two) } + else { None } + } + + /// Run the command that runs the node + pub fn run( + self, + mut config: Configuration, + new_light: FNL, + new_full: FNF, + version: &VersionInfo, + ) -> error::Result<()> + where + G: RuntimeGenesis, + E: ChainSpecExtension, + FNL: FnOnce(Configuration) -> Result, + FNF: FnOnce(Configuration) -> Result, + SL: AbstractService + Unpin, + SF: AbstractService + Unpin, + { + assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); + + crate::update_config_for_running_node(&mut config, self)?; + + crate::run_node(config, new_light, new_full, &version) + } +} diff --git a/client/cli/src/params/sign.rs b/client/cli/src/params/sign.rs new file mode 100644 index 0000000000000..29393c52d2cb1 --- /dev/null +++ b/client/cli/src/params/sign.rs @@ -0,0 +1,57 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Implementation of the `sign` subcommand +use crate::error; +use super::{SharedParams, RunCmd, get_password, read_message_from_stdin, read_pair, Crypto}; +use structopt::StructOpt; +use std::{path::PathBuf, fs}; +use crate::params::read_uri; + +#[derive(Debug, StructOpt, Clone)] +#[structopt( + name = "sign", + about = "Sign a message, provided on STDIN, with a given (secret) key" +)] +pub struct SignCmd { + /// The secret key URI. + /// If the value is a file, the file content is used as URI. + /// If not given, you will be prompted for the URI. + #[structopt(long)] + suri: Option, + + /// The message on STDIN is hex-encoded data + #[structopt(long)] + hex: bool, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + + +impl SignCmd { + pub fn run(self, run_cmd: RunCmd) -> error::Result<()> { + let suri = read_uri(self.uri)?; + + let message = read_message_from_stdin(self.hex)?; + let password = get_password(&run_cmd)?; + let pair = read_pair::(Some(&suri), password.as_ref().map(String::as_str))?; + let signature = format!("{}", hex::encode(pair.sign(&message))); + println!("{}", signature); + Ok(()) + } +} diff --git a/client/cli/src/params/sign_transaction.rs b/client/cli/src/params/sign_transaction.rs new file mode 100644 index 0000000000000..71cd0fda6af9d --- /dev/null +++ b/client/cli/src/params/sign_transaction.rs @@ -0,0 +1,73 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Implementation of the `sign-transaction` subcommand +use crate::error; +use hex_literal::hex; +use super::{SharedParams, RunCmd, get_password, read_message_from_stdin, read_pair, Crypto}; +use structopt::StructOpt; +use std::{path::PathBuf, fs}; +use crate::params::{read_uri, as_str}; + + +#[derive(Debug, StructOpt, Clone)] +#[structopt( + name = "sign-transaction", + about = "Sign transaction from encoded Call. Returns a signed and encoded UncheckedMortalCompactExtrinsic as hex." +)] +pub struct SignTransactionCmd { + /// The secret key URI. + #[structopt(long)] + suri: Option, + + /// The nonce. + #[structopt(long)] + nonce: Option, + + /// The call, hex-encoded. + #[structopt(long)] + call: String, + + /// The genesis block hash, hex-encoded. + #[structopt(long)] + genesis: Option, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + +impl SignTransactionCmd { + pub fn run(self, run_cmd: RunCmd) -> error::Result<()> { + let signer = read_pair::( + as_str(&self.suri), + as_str(&get_password(&run_cmd)?) + )?; + let genesis_hash = read_genesis_hash(matches)?; + + let call = matches.value_of("call").expect("call is required; qed"); + let function: Call = hex::decode(&call) + .ok() + .and_then(|x| Decode::decode(&mut &x[..]).ok()) + .unwrap(); + + let extrinsic = create_extrinsic::(function, index, signer, genesis_hash); + + print_extrinsic(extrinsic); + + Ok(()) + } +} diff --git a/client/cli/src/params/subcommand.rs b/client/cli/src/params/subcommand.rs new file mode 100644 index 0000000000000..3e303ca0b1bd2 --- /dev/null +++ b/client/cli/src/params/subcommand.rs @@ -0,0 +1,115 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +use structopt::{StructOpt}; +use sc_service::{ + Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand, +}; +use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; +use crate::error; +use std::fmt::Debug; +use super::*; + +/// All core commands that are provided by default. +/// +/// The core commands are split into multiple subcommands and `Run` is the default subcommand. From +/// the CLI user perspective, it is not visible that `Run` is a subcommand. So, all parameters of +/// `Run` are exported as main executable parameters. +#[derive(Debug, Clone, StructOpt)] +pub enum Subcommand { + /// Build a spec.json file, outputing to stdout. + BuildSpec(BuildSpecCmd), + + /// Export blocks to a file. + ExportBlocks(ExportBlocksCmd), + + /// Import blocks from file. + ImportBlocks(ImportBlocksCmd), + + /// Validte a single block. + CheckBlock(CheckBlockCmd), + + /// Revert chain to the previous state. + Revert(RevertCmd), + + /// Remove the whole chain data. + PurgeChain(PurgeChainCmd), + + /// Run runtime benchmarks. + Benchmark(BenchmarkCmd), + + /// Generate mmemonics + Generate(GenerateCmd), + + /// Generate Node Key + GenerateNodeKey(GenerateNodeKeyCmd), + + /// Inspect key. + Inspect(InspectCmd), + + /// Sign extrinsic + Sign(SignCmd), +} + +impl Subcommand { + /// Get the shared parameters of a `CoreParams` command + pub fn get_shared_params(&self) -> &SharedParams { + use Subcommand::*; + + match self { + BuildSpec(params) => ¶ms.shared_params, + ExportBlocks(params) => ¶ms.shared_params, + ImportBlocks(params) => ¶ms.shared_params, + CheckBlock(params) => ¶ms.shared_params, + Revert(params) => ¶ms.shared_params, + PurgeChain(params) => ¶ms.shared_params, + Benchmark(params) => ¶ms.shared_params, + Generate(params) => ¶ms.shared_params, + _ => unimplemented!() + } + } + + /// Run any `CoreParams` command + pub fn run( + self, + config: Configuration, + builder: B, + ) -> error::Result<()> + where + B: FnOnce(Configuration) -> Result, + G: RuntimeGenesis, + E: ChainSpecExtension, + BC: ServiceBuilderCommand + Unpin, + BB: sp_runtime::traits::Block + Debug, + <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, + ::Hash: std::str::FromStr, + { + assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); + + match self { + Subcommand::BuildSpec(cmd) => cmd.run(config), + Subcommand::ExportBlocks(cmd) => cmd.run(config, builder), + Subcommand::ImportBlocks(cmd) => cmd.run(config, builder), + Subcommand::CheckBlock(cmd) => cmd.run(config, builder), + Subcommand::PurgeChain(cmd) => cmd.run(config), + Subcommand::Benchmark(cmd) => cmd.run(config, builder), + Subcommand::Revert(cmd) => cmd.run(config, builder), + _ => { + Ok(()) + }, + } + } +} \ No newline at end of file diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 5ad5e1981379b..4447c7f9d0403 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -352,7 +352,7 @@ lazy_static::lazy_static! { macro_rules! ss58_address_format { ( $( $identifier:tt => ($number:expr, $name:expr, $desc:tt) )* ) => ( /// A known address (sub)format/network ID for SS58. - #[derive(Copy, Clone, PartialEq, Eq)] + #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum Ss58AddressFormat { $(#[doc = $desc] $identifier),*, /// Use a manually provided numeric value. From 742df0029d0b50fd04fbc43a53420eedd0df6f94 Mon Sep 17 00:00:00 2001 From: Seun Date: Wed, 4 Mar 2020 15:12:56 +0100 Subject: [PATCH 02/77] revert --- Cargo.lock | 623 ++++++++++++++++-- .../cli/src/{params => commands}/generate.rs | 0 .../{params => commands}/generate_node_key.rs | 0 .../cli/src/{params => commands}/inspect.rs | 0 client/cli/src/commands/mod.rs | 8 + client/cli/src/commands/runcmd.rs | 14 - client/cli/src/{params => commands}/sign.rs | 0 .../{params => commands}/sign_transaction.rs | 0 client/cli/src/params/benchmark.rs | 107 --- client/cli/src/params/build_spec.rs | 92 --- client/cli/src/params/check_block.rs | 95 --- client/cli/src/params/export_blocks.rs | 98 --- client/cli/src/params/import_blocks.rs | 235 ------- client/cli/src/params/purge_chain.rs | 90 --- client/cli/src/params/revert.rs | 64 -- client/cli/src/params/run.rs | 493 -------------- client/cli/src/params/shared_params.rs | 14 + client/cli/src/params/subcommand.rs | 115 ---- 18 files changed, 577 insertions(+), 1471 deletions(-) rename client/cli/src/{params => commands}/generate.rs (100%) rename client/cli/src/{params => commands}/generate_node_key.rs (100%) rename client/cli/src/{params => commands}/inspect.rs (100%) rename client/cli/src/{params => commands}/sign.rs (100%) rename client/cli/src/{params => commands}/sign_transaction.rs (100%) delete mode 100644 client/cli/src/params/benchmark.rs delete mode 100644 client/cli/src/params/build_spec.rs delete mode 100644 client/cli/src/params/check_block.rs delete mode 100644 client/cli/src/params/export_blocks.rs delete mode 100644 client/cli/src/params/import_blocks.rs delete mode 100644 client/cli/src/params/purge_chain.rs delete mode 100644 client/cli/src/params/revert.rs delete mode 100644 client/cli/src/params/run.rs delete mode 100644 client/cli/src/params/subcommand.rs diff --git a/Cargo.lock b/Cargo.lock index a7fdd2b4c9161..c70a89b379ccd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -189,7 +189,7 @@ dependencies = [ "mio", "mio-uds", "num_cpus", - "once_cell", + "once_cell 1.3.1", "pin-project-lite", "pin-utils", "slab", @@ -917,7 +917,7 @@ dependencies = [ "lazy_static", "maybe-uninit", "memoffset", - "scopeguard", + "scopeguard 1.1.0", ] [[package]] @@ -1519,7 +1519,7 @@ dependencies = [ "frame-system", "impl-trait-for-tuples", "log 0.4.8", - "once_cell", + "once_cell 1.3.1", "parity-scale-codec", "paste", "pretty_assertions", @@ -2010,6 +2010,16 @@ dependencies = [ "crunchy", ] +[[package]] +name = "hashbrown" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" +dependencies = [ + "byteorder 1.3.4", + "scopeguard 0.3.3", +] + [[package]] name = "hashbrown" version = "0.6.3" @@ -2629,6 +2639,43 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "libp2p" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f84847789ab24b3fc5971a68656ac85886df640986d9ce3264c0327694eae471" +dependencies = [ + "bytes 0.5.4", + "futures 0.3.4", + "lazy_static", + "libp2p-core 0.15.0", + "libp2p-core-derive 0.15.0", + "libp2p-deflate 0.7.0", + "libp2p-dns 0.15.0", + "libp2p-floodsub 0.15.0", + "libp2p-gossipsub 0.15.0", + "libp2p-identify 0.15.0", + "libp2p-kad 0.15.0", + "libp2p-mdns 0.15.0", + "libp2p-mplex 0.15.0", + "libp2p-noise 0.13.0", + "libp2p-ping 0.15.0", + "libp2p-plaintext 0.15.0", + "libp2p-secio 0.15.0", + "libp2p-swarm 0.5.0", + "libp2p-tcp 0.15.0", + "libp2p-uds 0.15.0", + "libp2p-wasm-ext 0.8.0", + "libp2p-websocket 0.15.0", + "libp2p-yamux 0.15.0", + "parity-multiaddr 0.7.2", + "parity-multihash 0.2.3", + "parking_lot 0.10.0", + "pin-project", + "smallvec 1.2.0", + "wasm-timer", +] + [[package]] name = "libp2p" version = "0.16.2" @@ -2638,27 +2685,27 @@ dependencies = [ "bytes 0.5.4", "futures 0.3.4", "lazy_static", - "libp2p-core", - "libp2p-core-derive", - "libp2p-deflate", - "libp2p-dns", - "libp2p-floodsub", - "libp2p-gossipsub", - "libp2p-identify", - "libp2p-kad", - "libp2p-mdns", - "libp2p-mplex", - "libp2p-noise", - "libp2p-ping", - "libp2p-plaintext", + "libp2p-core 0.16.0", + "libp2p-core-derive 0.16.0", + "libp2p-deflate 0.16.0", + "libp2p-dns 0.16.0", + "libp2p-floodsub 0.16.0", + "libp2p-gossipsub 0.16.0", + "libp2p-identify 0.16.0", + "libp2p-kad 0.16.2", + "libp2p-mdns 0.16.0", + "libp2p-mplex 0.16.0", + "libp2p-noise 0.16.2", + "libp2p-ping 0.16.0", + "libp2p-plaintext 0.16.0", "libp2p-pnet", - "libp2p-secio", - "libp2p-swarm", - "libp2p-tcp", - "libp2p-uds", - "libp2p-wasm-ext", - "libp2p-websocket", - "libp2p-yamux", + "libp2p-secio 0.16.1", + "libp2p-swarm 0.16.1", + "libp2p-tcp 0.16.0", + "libp2p-uds 0.16.0", + "libp2p-wasm-ext 0.16.2", + "libp2p-websocket 0.16.0", + "libp2p-yamux 0.16.2", "parity-multiaddr 0.7.2", "parity-multihash 0.2.3", "parking_lot 0.10.0", @@ -2667,6 +2714,40 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-core" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbafb2706b8082233f66dc13e196f9cf9b4c229f2cd7c96b2b16617ad6ee330b" +dependencies = [ + "asn1_der", + "bs58 0.3.0", + "ed25519-dalek", + "fnv", + "futures 0.3.4", + "futures-timer 2.0.2", + "lazy_static", + "libsecp256k1", + "log 0.4.8", + "multistream-select", + "parity-multiaddr 0.7.2", + "parity-multihash 0.2.3", + "parking_lot 0.10.0", + "pin-project", + "prost", + "prost-build", + "rand 0.7.3", + "ring", + "rw-stream-sink", + "sha2", + "smallvec 1.2.0", + "thiserror", + "unsigned-varint 0.3.1", + "untrusted", + "void", + "zeroize 1.1.0", +] + [[package]] name = "libp2p-core" version = "0.16.0" @@ -2700,6 +2781,16 @@ dependencies = [ "zeroize 1.1.0", ] +[[package]] +name = "libp2p-core-derive" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c320266be0a7760e23484d635acdb83844b2d74d3612d93b41c393c9bcf004e" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "libp2p-core-derive" version = "0.16.0" @@ -2710,6 +2801,17 @@ dependencies = [ "syn", ] +[[package]] +name = "libp2p-deflate" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be32697b42d040b325c3737f827ea04ede569ec956b7807700dd8d89d8210f9" +dependencies = [ + "flate2", + "futures 0.3.4", + "libp2p-core 0.15.0", +] + [[package]] name = "libp2p-deflate" version = "0.16.0" @@ -2718,7 +2820,18 @@ checksum = "2e25004d4d9837b44b22c5f1a69be1724a5168fef6cff1716b5176a972c3aa62" dependencies = [ "flate2", "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", +] + +[[package]] +name = "libp2p-dns" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f11c979b882f25d85726b15637d5bbc722dfa1be576605c54e99b8cf56906be3" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "log 0.4.8", ] [[package]] @@ -2728,10 +2841,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b99e552f9939b606eb4b59f7f64d9b01e3f96752f47e350fc3c5fc646ed3f649" dependencies = [ "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", ] +[[package]] +name = "libp2p-floodsub" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bdf6fba9272ad47dde94bade89540fdb16e24ae9ff7fb714c1c80a035165f28" +dependencies = [ + "bs58 0.3.0", + "cuckoofilter", + "fnv", + "futures 0.3.4", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "prost", + "prost-build", + "rand 0.7.3", + "smallvec 1.2.0", +] + [[package]] name = "libp2p-floodsub" version = "0.16.0" @@ -2741,12 +2872,38 @@ dependencies = [ "cuckoofilter", "fnv", "futures 0.3.4", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", + "prost", + "prost-build", + "rand 0.7.3", + "smallvec 1.2.0", +] + +[[package]] +name = "libp2p-gossipsub" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e6ecd058bf769d27ebec530544b081e08b0a1088e3186da8cc58d59915784d0" +dependencies = [ + "base64 0.11.0", + "bs58 0.3.0", + "byteorder 1.3.4", + "bytes 0.5.4", + "fnv", + "futures 0.3.4", + "futures_codec", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "lru", "prost", "prost-build", "rand 0.7.3", + "sha2", "smallvec 1.2.0", + "unsigned-varint 0.3.1", + "wasm-timer", ] [[package]] @@ -2761,8 +2918,8 @@ dependencies = [ "fnv", "futures 0.3.4", "futures_codec", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "lru", "prost", @@ -2774,6 +2931,22 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-identify" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1a6261b804111c2dbf53f8ca03f66edc5ad1c29b78a61cf0cc5354052e28e9" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "prost", + "prost-build", + "smallvec 1.2.0", + "wasm-timer", +] + [[package]] name = "libp2p-identify" version = "0.16.0" @@ -2781,8 +2954,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfeb935a9bd41263e4f3a24b988e9f4a044f3ae89ac284e83c17fe2f84e0d66b" dependencies = [ "futures 0.3.4", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "prost", "prost-build", @@ -2790,6 +2963,33 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-kad" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c6ea6fece0d99599afb1b2082ca8937944cdd6b0946a88d54cb3ae7a38d1253" +dependencies = [ + "arrayvec 0.5.1", + "bytes 0.5.4", + "either", + "fnv", + "futures 0.3.4", + "futures_codec", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "parity-multihash 0.2.3", + "prost", + "prost-build", + "rand 0.7.3", + "sha2", + "smallvec 1.2.0", + "uint", + "unsigned-varint 0.3.1", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-kad" version = "0.16.2" @@ -2802,8 +3002,8 @@ dependencies = [ "fnv", "futures 0.3.4", "futures_codec", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "parity-multihash 0.2.3", "prost", @@ -2817,6 +3017,28 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-mdns" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "074312353355df310affa105ec71b16fd7e52f5c6ae61d3dcbb3e79e8fdc9e5f" +dependencies = [ + "async-std", + "data-encoding", + "dns-parser", + "either", + "futures 0.3.4", + "lazy_static", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "net2", + "rand 0.7.3", + "smallvec 1.2.0", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-mdns" version = "0.16.0" @@ -2829,8 +3051,8 @@ dependencies = [ "either", "futures 0.3.4", "lazy_static", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "net2", "rand 0.7.3", @@ -2839,6 +3061,22 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-mplex" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89d0b44dfdef80cc2be4b42d127de1c793905eca2459415a5c57d6b4fbd8ec30" +dependencies = [ + "bytes 0.5.4", + "fnv", + "futures 0.3.4", + "futures_codec", + "libp2p-core 0.15.0", + "log 0.4.8", + "parking_lot 0.10.0", + "unsigned-varint 0.3.1", +] + [[package]] name = "libp2p-mplex" version = "0.16.0" @@ -2849,12 +3087,32 @@ dependencies = [ "fnv", "futures 0.3.4", "futures_codec", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "parking_lot 0.10.0", "unsigned-varint 0.3.1", ] +[[package]] +name = "libp2p-noise" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0845e8208d814cd41c26c90a6a2f2b720c31b588209cecc49a44c881a09f417f" +dependencies = [ + "curve25519-dalek 1.2.3", + "futures 0.3.4", + "lazy_static", + "libp2p-core 0.15.0", + "log 0.4.8", + "prost", + "prost-build", + "rand 0.7.3", + "ring", + "snow", + "x25519-dalek 0.5.2", + "zeroize 1.1.0", +] + [[package]] name = "libp2p-noise" version = "0.16.2" @@ -2864,7 +3122,7 @@ dependencies = [ "curve25519-dalek 2.0.0", "futures 0.3.4", "lazy_static", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "prost", "prost-build", @@ -2872,10 +3130,25 @@ dependencies = [ "sha2", "snow", "static_assertions", - "x25519-dalek", + "x25519-dalek 0.6.0", "zeroize 1.1.0", ] +[[package]] +name = "libp2p-ping" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ecced2949ae93b6ff29565303ecd1bef15c4e4efb689033ee744922561a36b" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "rand 0.7.3", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-ping" version = "0.16.0" @@ -2883,14 +3156,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d22f2f228b3a828dca1cb8aa9fa331e0bc9c36510cb2c1916956e20dc85e8c" dependencies = [ "futures 0.3.4", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "rand 0.7.3", "void", "wasm-timer", ] +[[package]] +name = "libp2p-plaintext" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "195fda6b6a948a242fd30570e0e3418ae8e0a20055ea75d45458e1079a8efb05" +dependencies = [ + "bytes 0.5.4", + "futures 0.3.4", + "futures_codec", + "libp2p-core 0.15.0", + "log 0.4.8", + "prost", + "prost-build", + "rw-stream-sink", + "unsigned-varint 0.3.1", + "void", +] + [[package]] name = "libp2p-plaintext" version = "0.16.0" @@ -2900,7 +3191,7 @@ dependencies = [ "bytes 0.5.4", "futures 0.3.4", "futures_codec", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "prost", "prost-build", @@ -2923,6 +3214,36 @@ dependencies = [ "sha3", ] +[[package]] +name = "libp2p-secio" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ceef68ca377b264f84d64c88739a8fa118b5db1e8f18297351dff75314504a5f" +dependencies = [ + "aes-ctr", + "ctr", + "futures 0.3.4", + "hmac", + "js-sys", + "lazy_static", + "libp2p-core 0.15.0", + "log 0.4.8", + "parity-send-wrapper", + "pin-project", + "prost", + "prost-build", + "quicksink", + "rand 0.7.3", + "ring", + "rw-stream-sink", + "sha2", + "static_assertions", + "twofish", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "libp2p-secio" version = "0.16.1" @@ -2935,7 +3256,7 @@ dependencies = [ "hmac", "js-sys", "lazy_static", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "parity-send-wrapper", "pin-project", @@ -2953,6 +3274,20 @@ dependencies = [ "web-sys", ] +[[package]] +name = "libp2p-swarm" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14ea00be81bc3985e36abad263ce2ad1b6aeb862aa743563eb70ad42880c05ae" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "log 0.4.8", + "smallvec 1.2.0", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-swarm" version = "0.16.1" @@ -2960,13 +3295,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "275471e7c0e88ae004660866cd54f603bd8bd1f4caef541a27f50dd8640c4d4c" dependencies = [ "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "smallvec 1.2.0", "void", "wasm-timer", ] +[[package]] +name = "libp2p-tcp" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e65ef381570df31cb047dfbc11483ab0fe7e6abbdcf2bdc2c60b5d11133d241" +dependencies = [ + "async-std", + "futures 0.3.4", + "futures-timer 2.0.2", + "get_if_addrs", + "ipnet", + "libp2p-core 0.15.0", + "log 0.4.8", +] + [[package]] name = "libp2p-tcp" version = "0.16.0" @@ -2978,7 +3328,19 @@ dependencies = [ "futures-timer 3.0.2", "get_if_addrs", "ipnet", - "libp2p-core", + "libp2p-core 0.16.0", + "log 0.4.8", +] + +[[package]] +name = "libp2p-uds" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e4f4f7989b35f33d4b9738aab2f031310eb20fec513cab44d12b1bc985a8074" +dependencies = [ + "async-std", + "futures 0.3.4", + "libp2p-core 0.15.0", "log 0.4.8", ] @@ -2990,10 +3352,24 @@ checksum = "76d329564a43da9d0e055a5b938633c4a8ceab1f59cec133fbc4647917c07341" dependencies = [ "async-std", "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", ] +[[package]] +name = "libp2p-wasm-ext" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b4d457adb91a5e2212343218a554394cd8ced64a79fb8e36e7aed2a16d49495" +dependencies = [ + "futures 0.3.4", + "js-sys", + "libp2p-core 0.15.0", + "parity-send-wrapper", + "wasm-bindgen", + "wasm-bindgen-futures", +] + [[package]] name = "libp2p-wasm-ext" version = "0.16.2" @@ -3002,12 +3378,33 @@ checksum = "923581c055bc4b8c5f42d4ce5ef43e52fe5216f1ea4bc26476cb8a966ce6220b" dependencies = [ "futures 0.3.4", "js-sys", - "libp2p-core", + "libp2p-core 0.16.0", "parity-send-wrapper", "wasm-bindgen", "wasm-bindgen-futures", ] +[[package]] +name = "libp2p-websocket" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bba425f2af1fdb7dece88b9ae05ca9430dfb0b72b2c078e73ded6f1556084509" +dependencies = [ + "async-tls", + "bytes 0.5.4", + "either", + "futures 0.3.4", + "libp2p-core 0.15.0", + "log 0.4.8", + "quicksink", + "rustls", + "rw-stream-sink", + "soketto", + "url 2.1.1", + "webpki", + "webpki-roots 0.18.0", +] + [[package]] name = "libp2p-websocket" version = "0.16.0" @@ -3018,7 +3415,7 @@ dependencies = [ "bytes 0.5.4", "either", "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "quicksink", "rustls", @@ -3029,6 +3426,20 @@ dependencies = [ "webpki-roots 0.18.0", ] +[[package]] +name = "libp2p-yamux" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca25b3aac78a3c93c2a567622abd3cfc16f96f26ae1bf6134f0056203d62d86" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "log 0.4.8", + "parking_lot 0.10.0", + "thiserror", + "yamux", +] + [[package]] name = "libp2p-yamux" version = "0.16.2" @@ -3036,7 +3447,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dac30de24ccde0e67f363d71a125c587bbe6589503f664947e9b084b68a34f1" dependencies = [ "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "parking_lot 0.10.0", "thiserror", "yamux", @@ -3097,13 +3508,22 @@ dependencies = [ "linked-hash-map", ] +[[package]] +name = "lock_api" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" +dependencies = [ + "scopeguard 0.3.3", +] + [[package]] name = "lock_api" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79b2de95ecb4691949fea4716ca53cdbcfccb2c612e19644a8bad05edcf9f47b" dependencies = [ - "scopeguard", + "scopeguard 1.1.0", ] [[package]] @@ -3130,7 +3550,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0609345ddee5badacf857d4f547e0e5a2e987db77085c24cd887f73573a04237" dependencies = [ - "hashbrown", + "hashbrown 0.6.3", ] [[package]] @@ -3177,7 +3597,7 @@ checksum = "198831fe8722331a395bc199a5d08efbc197497ef354cb4c77b969c02ffc0fc4" dependencies = [ "ahash", "hash-db", - "hashbrown", + "hashbrown 0.6.3", "parity-util-mem", ] @@ -3783,6 +4203,15 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "once_cell" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "532c29a261168a45ce28948f9537ddd7a5dd272cc513b3017b1e82a88f962c37" +dependencies = [ + "parking_lot 0.7.1", +] + [[package]] name = "once_cell" version = "1.3.1" @@ -4657,7 +5086,7 @@ checksum = "ef1476e40bf8f5c6776e9600983435821ca86eb9819d74a6207cca69d091406a" dependencies = [ "cfg-if", "ethereum-types", - "hashbrown", + "hashbrown 0.6.3", "impl-trait-for-tuples", "lru", "parity-util-mem-derive", @@ -4693,13 +5122,23 @@ version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" +[[package]] +name = "parking_lot" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" +dependencies = [ + "lock_api 0.1.5", + "parking_lot_core 0.4.0", +] + [[package]] name = "parking_lot" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" dependencies = [ - "lock_api", + "lock_api 0.3.3", "parking_lot_core 0.6.2", "rustc_version", ] @@ -4710,10 +5149,23 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92e98c49ab0b7ce5b222f2cc9193fc4efe11c6d0bd4f648e374684a6857b1cfc" dependencies = [ - "lock_api", + "lock_api 0.3.3", "parking_lot_core 0.7.0", ] +[[package]] +name = "parking_lot_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" +dependencies = [ + "libc", + "rand 0.6.5", + "rustc_version", + "smallvec 0.6.13", + "winapi 0.3.8", +] + [[package]] name = "parking_lot_core" version = "0.6.2" @@ -5582,7 +6034,7 @@ dependencies = [ "env_logger 0.7.1", "futures 0.3.4", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "parity-scale-codec", "prost", @@ -5677,7 +6129,9 @@ dependencies = [ "env_logger 0.7.1", "fdlimit", "futures 0.3.4", + "hex-literal", "lazy_static", + "libp2p 0.15.0", "log 0.4.8", "names", "parity-util-mem", @@ -5700,6 +6154,7 @@ dependencies = [ "substrate-prometheus-endpoint", "tempfile", "time", + "tiny-bip39 0.6.2", "tokio 0.2.12", ] @@ -6177,7 +6632,7 @@ dependencies = [ "futures 0.3.4", "futures-timer 3.0.2", "futures_codec", - "libp2p", + "libp2p 0.16.2", "linked-hash-map", "linked_hash_set", "log 0.4.8", @@ -6225,7 +6680,7 @@ version = "0.8.0-alpha.3" dependencies = [ "futures 0.3.4", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "lru", "parking_lot 0.10.0", @@ -6241,7 +6696,7 @@ dependencies = [ "env_logger 0.7.1", "futures 0.3.4", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "parking_lot 0.10.0", "rand 0.7.3", @@ -6295,7 +6750,7 @@ name = "sc-peerset" version = "2.0.0-alpha.3" dependencies = [ "futures 0.3.4", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "rand 0.7.3", "serde_json", @@ -6481,7 +6936,7 @@ dependencies = [ "bytes 0.5.4", "futures 0.3.4", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "parking_lot 0.10.0", "pin-project", @@ -6584,6 +7039,12 @@ dependencies = [ "zeroize 0.9.3", ] +[[package]] +name = "scopeguard" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" + [[package]] name = "scopeguard" version = "1.1.0" @@ -6864,7 +7325,7 @@ dependencies = [ "rustc_version", "sha2", "subtle 2.2.2", - "x25519-dalek", + "x25519-dalek 0.6.0", ] [[package]] @@ -7040,7 +7501,7 @@ dependencies = [ "futures 0.3.4", "futures-diagnose", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "parity-scale-codec", "parking_lot 0.10.0", @@ -7130,7 +7591,7 @@ dependencies = [ "sp-std", "sp-storage", "substrate-bip39", - "tiny-bip39", + "tiny-bip39 0.7.1", "tiny-keccak 2.0.1", "twox-hash", "wasmi", @@ -7583,7 +8044,7 @@ dependencies = [ "hyper 0.12.35", "itertools", "jsonrpc-core-client", - "libp2p", + "libp2p 0.16.2", "node-primitives", "node-runtime", "pallet-balances", @@ -7597,7 +8058,7 @@ dependencies = [ "sp-core", "sp-runtime", "substrate-bip39", - "tiny-bip39", + "tiny-bip39 0.7.1", ] [[package]] @@ -7625,7 +8086,7 @@ dependencies = [ "futures-timer 3.0.2", "js-sys", "kvdb-web", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "rand 0.6.5", "rand 0.7.3", @@ -7978,6 +8439,21 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "tiny-bip39" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1c5676413eaeb1ea35300a0224416f57abc3bd251657e0fafc12c47ff98c060" +dependencies = [ + "failure", + "hashbrown 0.1.8", + "hmac", + "once_cell 0.1.8", + "pbkdf2", + "rand 0.6.5", + "sha2", +] + [[package]] name = "tiny-bip39" version = "0.7.1" @@ -7986,7 +8462,7 @@ checksum = "a6848cd8f566953ce1e8faeba12ee23cbdbb0437754792cd857d44628b5685e3" dependencies = [ "failure", "hmac", - "once_cell", + "once_cell 1.3.1", "pbkdf2", "rand 0.7.3", "rustc-hash", @@ -8387,7 +8863,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de9222c50cc325855621271157c973da27a0dcd26fa06f8edf81020bd2333df0" dependencies = [ "hash-db", - "hashbrown", + "hashbrown 0.6.3", "log 0.4.8", "rustc-hex", "smallvec 1.2.0", @@ -9121,6 +9597,17 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "x25519-dalek" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ee1585dc1484373cbc1cee7aafda26634665cf449436fd6e24bfd1fad230538" +dependencies = [ + "clear_on_drop", + "curve25519-dalek 1.2.3", + "rand_core 0.3.1", +] + [[package]] name = "x25519-dalek" version = "0.6.0" diff --git a/client/cli/src/params/generate.rs b/client/cli/src/commands/generate.rs similarity index 100% rename from client/cli/src/params/generate.rs rename to client/cli/src/commands/generate.rs diff --git a/client/cli/src/params/generate_node_key.rs b/client/cli/src/commands/generate_node_key.rs similarity index 100% rename from client/cli/src/params/generate_node_key.rs rename to client/cli/src/commands/generate_node_key.rs diff --git a/client/cli/src/params/inspect.rs b/client/cli/src/commands/inspect.rs similarity index 100% rename from client/cli/src/params/inspect.rs rename to client/cli/src/commands/inspect.rs diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index e9f991c745883..c35ecd196d3da 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -21,6 +21,11 @@ mod import_blocks_cmd; mod check_block_cmd; mod revert_cmd; mod purge_chain_cmd; +mod generate_node_key; +mod generate; +mod inspect; +mod sign; +mod sign_transaction; use std::fmt::Debug; use structopt::StructOpt; @@ -69,6 +74,9 @@ pub enum Subcommand { /// Remove the whole chain data. PurgeChain(purge_chain_cmd::PurgeChainCmd), + + /// Generate a key for a node + // GenerateNodeKey(generate_node_key::GenerateNodeKeyCmd), } impl Subcommand { diff --git a/client/cli/src/commands/runcmd.rs b/client/cli/src/commands/runcmd.rs index f29bc3c743b64..c66210aea1012 100644 --- a/client/cli/src/commands/runcmd.rs +++ b/client/cli/src/commands/runcmd.rs @@ -245,20 +245,6 @@ pub struct RunCmd { #[structopt(long = "keystore-path", value_name = "PATH", parse(from_os_str))] pub keystore_path: Option, - /// Use interactive shell for entering the password used by the keystore. - #[structopt( - long = "password-interactive", - conflicts_with_all = &[ "password", "password-filename" ] - )] - pub password_interactive: bool, - - /// Password used by the keystore. - #[structopt( - long = "password", - conflicts_with_all = &[ "password-interactive", "password-filename" ] - )] - pub password: Option, - /// File that contains the password used by the keystore. #[structopt( long = "password-filename", diff --git a/client/cli/src/params/sign.rs b/client/cli/src/commands/sign.rs similarity index 100% rename from client/cli/src/params/sign.rs rename to client/cli/src/commands/sign.rs diff --git a/client/cli/src/params/sign_transaction.rs b/client/cli/src/commands/sign_transaction.rs similarity index 100% rename from client/cli/src/params/sign_transaction.rs rename to client/cli/src/commands/sign_transaction.rs diff --git a/client/cli/src/params/benchmark.rs b/client/cli/src/params/benchmark.rs deleted file mode 100644 index 6eaa4cda18b33..0000000000000 --- a/client/cli/src/params/benchmark.rs +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -use structopt::{StructOpt}; -use sc_service::{ - Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand, -}; -use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; -use crate::error; -use std::fmt::Debug; -use crate::execution_strategy::*; -use super::{SharedParams, WasmExecutionMethod}; - - -/// The `benchmark` command used to benchmark FRAME Pallets. -#[derive(Debug, StructOpt, Clone)] -pub struct BenchmarkCmd { - /// Select a FRAME Pallet to benchmark. - #[structopt(short, long)] - pub pallet: String, - - /// Select an extrinsic to benchmark. - #[structopt(short, long)] - pub extrinsic: String, - - /// Select how many samples we should take across the variable components. - #[structopt(short, long, default_value = "1")] - pub steps: u32, - - /// Select how many repetitions of this benchmark should run. - #[structopt(short, long, default_value = "1")] - pub repeat: u32, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - - /// The execution strategy that should be used for benchmarks - #[structopt( - long = "execution", - value_name = "STRATEGY", - possible_values = &ExecutionStrategy::variants(), - case_insensitive = true, - )] - pub execution: Option, - - /// Method for executing Wasm runtime code. - #[structopt( - long = "wasm-execution", - value_name = "METHOD", - possible_values = &WasmExecutionMethod::enabled_variants(), - case_insensitive = true, - default_value = "Interpreted" - )] - pub wasm_method: WasmExecutionMethod, -} - -impl BenchmarkCmd { - /// Runs the command and benchmarks the chain. - pub fn run( - self, - config: Configuration, - _builder: B, - ) -> error::Result<()> - where - B: FnOnce(Configuration) -> Result, - G: RuntimeGenesis, - E: ChainSpecExtension, - BC: ServiceBuilderCommand + Unpin, - BB: sp_runtime::traits::Block + Debug, - <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, - ::Hash: std::str::FromStr, - { - let spec = config.chain_spec.expect("chain_spec is always Some"); - let execution_strategy = self.execution.unwrap_or(ExecutionStrategy::Native).into(); - let wasm_method = self.wasm_method.into(); - let pallet = self.pallet; - let extrinsic = self.extrinsic; - let steps = self.steps; - let repeat = self.repeat; - sc_service::chain_ops::benchmark_runtime::( - spec, - execution_strategy, - wasm_method, - pallet, - extrinsic, - steps, - repeat - )?; - Ok(()) - } -} - - diff --git a/client/cli/src/params/build_spec.rs b/client/cli/src/params/build_spec.rs deleted file mode 100644 index 261e1cc411aef..0000000000000 --- a/client/cli/src/params/build_spec.rs +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -use structopt::{StructOpt}; -use sc_service::{ - Configuration, ChainSpecExtension, RuntimeGenesis, -}; -use crate::error; -use std::fmt::Debug; -use log::info; -use sc_network::config::build_multiaddr; -use crate::node_key::node_key_config; - -use super::{NodeKeyParams, SharedParams}; - -/// The `build-spec` command used to build a specification. -#[derive(Debug, StructOpt, Clone)] -pub struct BuildSpecCmd { - /// Force raw genesis storage output. - #[structopt(long = "raw")] - pub raw: bool, - - /// Disable adding the default bootnode to the specification. - /// - /// By default the `/ip4/127.0.0.1/tcp/30333/p2p/NODE_PEER_ID` bootnode is added to the - /// specification when no bootnode exists. - #[structopt(long = "disable-default-bootnode")] - pub disable_default_bootnode: bool, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub node_key_params: NodeKeyParams, -} - - -impl BuildSpecCmd { - /// Run the build-spec command - pub fn run( - self, - config: Configuration, - ) -> error::Result<()> - where - G: RuntimeGenesis, - E: ChainSpecExtension, - { - assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); - - info!("Building chain spec"); - let mut spec = config.expect_chain_spec().clone(); - let raw_output = self.raw; - - if spec.boot_nodes().is_empty() && !self.disable_default_bootnode { - let node_key = node_key_config( - self.node_key_params.clone(), - &Some(config - .in_chain_config_dir(crate::DEFAULT_NETWORK_CONFIG_PATH) - .expect("We provided a base_path")), - )?; - let keys = node_key.into_keypair()?; - let peer_id = keys.public().into_peer_id(); - let addr = build_multiaddr![ - Ip4([127, 0, 0, 1]), - Tcp(30333u16), - P2p(peer_id) - ]; - spec.add_boot_node(addr) - } - - let json = sc_service::chain_ops::build_spec(spec, raw_output)?; - - print!("{}", json); - - Ok(()) - } -} diff --git a/client/cli/src/params/check_block.rs b/client/cli/src/params/check_block.rs deleted file mode 100644 index c95f3cdb46e75..0000000000000 --- a/client/cli/src/params/check_block.rs +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -use std::{str::FromStr}; -use structopt::{StructOpt}; -use sc_service::{ - Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand, -}; -use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; -use crate::error; -use std::fmt::Debug; -use sp_runtime::generic::BlockId; -use crate::runtime::run_until_exit; - -use super::{ImportParams, SharedParams}; - -/// The `check-block` command used to validate blocks. -#[derive(Debug, StructOpt, Clone)] -pub struct CheckBlockCmd { - /// Block hash or number - #[structopt(value_name = "HASH or NUMBER")] - pub input: String, - - /// The default number of 64KB pages to ever allocate for Wasm execution. - /// - /// Don't alter this unless you know what you're doing. - #[structopt(long = "default-heap-pages", value_name = "COUNT")] - pub default_heap_pages: Option, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub import_params: ImportParams, -} - -impl CheckBlockCmd { - /// Run the check-block command - pub fn run( - self, - mut config: Configuration, - builder: B, - ) -> error::Result<()> - where - B: FnOnce(Configuration) -> Result, - G: RuntimeGenesis, - E: ChainSpecExtension, - BC: ServiceBuilderCommand + Unpin, - BB: sp_runtime::traits::Block + Debug, - <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, - ::Hash: std::str::FromStr, - { - assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); - - crate::fill_import_params( - &mut config, - &self.import_params, - sc_service::Roles::FULL, - self.shared_params.dev, - )?; - crate::fill_config_keystore_in_memory(&mut config)?; - - let input = if self.input.starts_with("0x") { &self.input[2..] } else { &self.input[..] }; - let block_id = match FromStr::from_str(input) { - Ok(hash) => BlockId::hash(hash), - Err(_) => match self.input.parse::() { - Ok(n) => BlockId::number((n as u32).into()), - Err(_) => return Err(error::Error::Input("Invalid hash or number specified".into())), - } - }; - - let start = std::time::Instant::now(); - run_until_exit(config, |config| { - Ok(builder(config)?.check_block(block_id)) - })?; - println!("Completed in {} ms.", start.elapsed().as_millis()); - - Ok(()) - } -} diff --git a/client/cli/src/params/export_blocks.rs b/client/cli/src/params/export_blocks.rs deleted file mode 100644 index 3c1891bfc7690..0000000000000 --- a/client/cli/src/params/export_blocks.rs +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -use std::{path::PathBuf}; -use structopt::{StructOpt}; -use sc_service::{ - Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand, - config::DatabaseConfig, -}; -use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; -use crate::error; -use std::fmt::Debug; -use log::info; -use std::io; -use std::fs; -use crate::runtime::run_until_exit; - -use super::{SharedParams, BlockNumber}; - -/// The `export-blocks` command used to export blocks. -#[derive(Debug, StructOpt, Clone)] -pub struct ExportBlocksCmd { - /// Output file name or stdout if unspecified. - #[structopt(parse(from_os_str))] - pub output: Option, - - /// Specify starting block number. - /// - /// Default is 1. - #[structopt(long = "from", value_name = "BLOCK")] - pub from: Option, - - /// Specify last block number. - /// - /// Default is best block. - #[structopt(long = "to", value_name = "BLOCK")] - pub to: Option, - - /// Use JSON output rather than binary. - #[structopt(long = "json")] - pub json: bool, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, -} - -impl ExportBlocksCmd { - /// Run the export-blocks command - pub fn run( - self, - mut config: Configuration, - builder: B, - ) -> error::Result<()> - where - B: FnOnce(Configuration) -> Result, - G: RuntimeGenesis, - E: ChainSpecExtension, - BC: ServiceBuilderCommand + Unpin, - BB: sp_runtime::traits::Block + Debug, - <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, - ::Hash: std::str::FromStr, - { - assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); - - crate::fill_config_keystore_in_memory(&mut config)?; - - if let DatabaseConfig::Path { ref path, .. } = config.expect_database() { - info!("DB path: {}", path.display()); - } - let from = self.from.as_ref().and_then(|f| f.parse().ok()).unwrap_or(1); - let to = self.to.as_ref().and_then(|t| t.parse().ok()); - - let json = self.json; - - let file: Box = match &self.output { - Some(filename) => Box::new(fs::File::create(filename)?), - None => Box::new(io::stdout()), - }; - - run_until_exit(config, |config| { - Ok(builder(config)?.export_blocks(file, from.into(), to, json)) - }) - } -} diff --git a/client/cli/src/params/import_blocks.rs b/client/cli/src/params/import_blocks.rs deleted file mode 100644 index 77671fe8f89ff..0000000000000 --- a/client/cli/src/params/import_blocks.rs +++ /dev/null @@ -1,235 +0,0 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -use std::path::PathBuf; -use structopt::{StructOpt, clap::arg_enum}; -use sc_service::{Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand}; -use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; -use crate::error; -use std::fmt::Debug; -use std::io; -use std::fs; -use std::io::Read; -use crate::runtime::run_until_exit; -use crate::execution_strategy::*; -use super::{SharedParams, WasmExecutionMethod, ReadPlusSeek}; - -arg_enum! { - #[allow(missing_docs)] - #[derive(Debug, Copy, Clone, PartialEq, Eq)] - pub enum TracingReceiver { - Log, - Telemetry, - Grafana, - } -} - -impl Into for TracingReceiver { - fn into(self) -> sc_tracing::TracingReceiver { - match self { - TracingReceiver::Log => sc_tracing::TracingReceiver::Log, - TracingReceiver::Telemetry => sc_tracing::TracingReceiver::Telemetry, - TracingReceiver::Grafana => sc_tracing::TracingReceiver::Grafana, - } - } -} - -/// Execution strategies parameters. -#[derive(Debug, StructOpt, Clone)] -pub struct ExecutionStrategies { - /// The means of execution used when calling into the runtime while syncing blocks. - #[structopt( - long = "execution-syncing", - value_name = "STRATEGY", - possible_values = &ExecutionStrategy::variants(), - case_insensitive = true, - default_value = DEFAULT_EXECUTION_SYNCING.as_str(), - )] - pub execution_syncing: ExecutionStrategy, - - /// The means of execution used when calling into the runtime while importing blocks. - #[structopt( - long = "execution-import-block", - value_name = "STRATEGY", - possible_values = &ExecutionStrategy::variants(), - case_insensitive = true, - default_value = DEFAULT_EXECUTION_IMPORT_BLOCK.as_str(), - )] - pub execution_import_block: ExecutionStrategy, - - /// The means of execution used when calling into the runtime while constructing blocks. - #[structopt( - long = "execution-block-construction", - value_name = "STRATEGY", - possible_values = &ExecutionStrategy::variants(), - case_insensitive = true, - default_value = DEFAULT_EXECUTION_BLOCK_CONSTRUCTION.as_str(), - )] - pub execution_block_construction: ExecutionStrategy, - - /// The means of execution used when calling into the runtime while using an off-chain worker. - #[structopt( - long = "execution-offchain-worker", - value_name = "STRATEGY", - possible_values = &ExecutionStrategy::variants(), - case_insensitive = true, - default_value = DEFAULT_EXECUTION_OFFCHAIN_WORKER.as_str(), - )] - pub execution_offchain_worker: ExecutionStrategy, - - /// The means of execution used when calling into the runtime while not syncing, importing or constructing blocks. - #[structopt( - long = "execution-other", - value_name = "STRATEGY", - possible_values = &ExecutionStrategy::variants(), - case_insensitive = true, - default_value = DEFAULT_EXECUTION_OTHER.as_str(), - )] - pub execution_other: ExecutionStrategy, - - /// The execution strategy that should be used by all execution contexts. - #[structopt( - long = "execution", - value_name = "STRATEGY", - possible_values = &ExecutionStrategy::variants(), - case_insensitive = true, - conflicts_with_all = &[ - "execution-other", - "execution-offchain-worker", - "execution-block-construction", - "execution-import-block", - "execution-syncing", - ] - )] - pub execution: Option, -} - -/// Parameters for block import. -#[derive(Debug, StructOpt, Clone)] -pub struct ImportParams { - /// Specify the state pruning mode, a number of blocks to keep or 'archive'. - /// - /// Default is to keep all block states if the node is running as a - /// validator (i.e. 'archive'), otherwise state is only kept for the last - /// 256 blocks. - #[structopt(long = "pruning", value_name = "PRUNING_MODE")] - pub pruning: Option, - - /// Force start with unsafe pruning settings. - /// - /// When running as a validator it is highly recommended to disable state - /// pruning (i.e. 'archive') which is the default. The node will refuse to - /// start as a validator if pruning is enabled unless this option is set. - #[structopt(long = "unsafe-pruning")] - pub unsafe_pruning: bool, - - /// Method for executing Wasm runtime code. - #[structopt( - long = "wasm-execution", - value_name = "METHOD", - possible_values = &WasmExecutionMethod::enabled_variants(), - case_insensitive = true, - default_value = "Interpreted" - )] - pub wasm_method: WasmExecutionMethod, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub execution_strategies: ExecutionStrategies, - - /// Limit the memory the database cache can use. - #[structopt(long = "db-cache", value_name = "MiB", default_value = "1024")] - pub database_cache_size: u32, - - /// Specify the state cache size. - #[structopt(long = "state-cache-size", value_name = "Bytes", default_value = "67108864")] - pub state_cache_size: usize, - - /// Comma separated list of targets for tracing - #[structopt(long = "tracing-targets", value_name = "TARGETS")] - pub tracing_targets: Option, - - /// Receiver to process tracing messages - #[structopt( - long = "tracing-receiver", - value_name = "RECEIVER", - possible_values = &TracingReceiver::variants(), - case_insensitive = true, - default_value = "Log" - )] - pub tracing_receiver: TracingReceiver, -} - - -/// The `import-blocks` command used to import blocks. -#[derive(Debug, StructOpt, Clone)] -pub struct ImportBlocksCmd { - /// Input file or stdin if unspecified. - #[structopt(parse(from_os_str))] - pub input: Option, - - /// The default number of 64KB pages to ever allocate for Wasm execution. - /// - /// Don't alter this unless you know what you're doing. - #[structopt(long = "default-heap-pages", value_name = "COUNT")] - pub default_heap_pages: Option, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub import_params: ImportParams, -} - -impl ImportBlocksCmd { - /// Run the import-blocks command - pub fn run( - self, - mut config: Configuration, - builder: B, - ) -> error::Result<()> - where - B: FnOnce(Configuration) -> Result, - G: RuntimeGenesis, - E: ChainSpecExtension, - BC: ServiceBuilderCommand + Unpin, - BB: sp_runtime::traits::Block + Debug, - <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, - ::Hash: std::str::FromStr, - { - crate::fill_import_params( - &mut config, - &self.import_params, - sc_service::Roles::FULL, - self.shared_params.dev, - )?; - - let file: Box = match &self.input { - Some(filename) => Box::new(fs::File::open(filename)?), - None => { - let mut buffer = Vec::new(); - io::stdin().read_to_end(&mut buffer)?; - Box::new(io::Cursor::new(buffer)) - }, - }; - - run_until_exit(config, |config| { - Ok(builder(config)?.import_blocks(file, false)) - }) - } -} diff --git a/client/cli/src/params/purge_chain.rs b/client/cli/src/params/purge_chain.rs deleted file mode 100644 index 591459a7530b3..0000000000000 --- a/client/cli/src/params/purge_chain.rs +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -use structopt::{StructOpt}; -use sc_service::{ - Configuration, ChainSpecExtension, RuntimeGenesis, config::DatabaseConfig, -}; -use crate::error; -use std::fmt::Debug; -use std::fs; -use std::io::{self, Write}; -use super::SharedParams; - -/// The `purge-chain` command used to remove the whole chain. -#[derive(Debug, StructOpt, Clone)] -pub struct PurgeChainCmd { - /// Skip interactive prompt by answering yes automatically. - #[structopt(short = "y")] - pub yes: bool, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, -} - -impl PurgeChainCmd { - /// Run the purge command - pub fn run( - self, - mut config: Configuration, - ) -> error::Result<()> - where - G: RuntimeGenesis, - E: ChainSpecExtension, - { - assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); - - crate::fill_config_keystore_in_memory(&mut config)?; - - let db_path = match config.expect_database() { - DatabaseConfig::Path { path, .. } => path, - _ => { - eprintln!("Cannot purge custom database implementation"); - return Ok(()); - } - }; - - if !self.yes { - print!("Are you sure to remove {:?}? [y/N]: ", &db_path); - io::stdout().flush().expect("failed to flush stdout"); - - let mut input = String::new(); - io::stdin().read_line(&mut input)?; - let input = input.trim(); - - match input.chars().nth(0) { - Some('y') | Some('Y') => {}, - _ => { - println!("Aborted"); - return Ok(()); - }, - } - } - - match fs::remove_dir_all(&db_path) { - Ok(_) => { - println!("{:?} removed.", &db_path); - Ok(()) - }, - Err(ref err) if err.kind() == io::ErrorKind::NotFound => { - eprintln!("{:?} did not exist.", &db_path); - Ok(()) - }, - Err(err) => Result::Err(err.into()) - } - } -} diff --git a/client/cli/src/params/revert.rs b/client/cli/src/params/revert.rs deleted file mode 100644 index 7ef9f00a33e24..0000000000000 --- a/client/cli/src/params/revert.rs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -use structopt::{StructOpt}; -use sc_service::{ - Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand, -}; -use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; -use crate::error; -use std::fmt::Debug; -use super::{BlockNumber, SharedParams}; - - -/// The `revert` command used revert the chain to a previous state. -#[derive(Debug, StructOpt, Clone)] -pub struct RevertCmd { - /// Number of blocks to revert. - #[structopt(default_value = "256")] - pub num: BlockNumber, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, -} - -impl RevertCmd { - /// Run the revert command - pub fn run( - self, - mut config: Configuration, - builder: B, - ) -> error::Result<()> - where - B: FnOnce(Configuration) -> Result, - G: RuntimeGenesis, - E: ChainSpecExtension, - BC: ServiceBuilderCommand + Unpin, - BB: sp_runtime::traits::Block + Debug, - <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, - ::Hash: std::str::FromStr, - { - assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); - - crate::fill_config_keystore_in_memory(&mut config)?; - - let blocks = self.num.parse()?; - builder(config)?.revert_chain(blocks)?; - - Ok(()) - } -} \ No newline at end of file diff --git a/client/cli/src/params/run.rs b/client/cli/src/params/run.rs deleted file mode 100644 index ae3d58106bb86..0000000000000 --- a/client/cli/src/params/run.rs +++ /dev/null @@ -1,493 +0,0 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -use std::{path::PathBuf}; -use structopt::{StructOpt, clap::arg_enum}; -use sc_service::{ - AbstractService, Configuration, ChainSpecExtension, RuntimeGenesis, -}; -use crate::VersionInfo; -use crate::error; -use std::fmt::Debug; -use super::{SharedParams, ImportParams}; - -/// CORS setting -/// -/// The type is introduced to overcome `Option>` -/// handling of `structopt`. -#[derive(Clone, Debug)] -pub enum Cors { - /// All hosts allowed - All, - /// Only hosts on the list are allowed. - List(Vec), -} - -impl From for Option> { - fn from(cors: Cors) -> Self { - match cors { - Cors::All => None, - Cors::List(list) => Some(list), - } - } -} - -/// Parse cors origins -fn parse_cors(s: &str) -> Result> { - let mut is_all = false; - let mut origins = Vec::new(); - for part in s.split(',') { - match part { - "all" | "*" => { - is_all = true; - break; - }, - other => origins.push(other.to_owned()), - } - } - - Ok(if is_all { Cors::All } else { Cors::List(origins) }) -} - -/// Default to verbosity level 0, if none is provided. -fn parse_telemetry_endpoints(s: &str) -> Result<(String, u8), Box> { - let pos = s.find(' '); - match pos { - None => { - Ok((s.to_owned(), 0)) - }, - Some(pos_) => { - let verbosity = s[pos_ + 1..].parse()?; - let url = s[..pos_].parse()?; - Ok((url, verbosity)) - } - } -} - -/// Parameters used to create the pool configuration. -#[derive(Debug, StructOpt, Clone)] -pub struct TransactionPoolParams { - /// Maximum number of transactions in the transaction pool. - #[structopt(long = "pool-limit", value_name = "COUNT", default_value = "8192")] - pub pool_limit: usize, - /// Maximum number of kilobytes of all transactions stored in the pool. - #[structopt(long = "pool-kbytes", value_name = "COUNT", default_value = "20480")] - pub pool_kbytes: usize, -} - -arg_enum! { - #[allow(missing_docs)] - #[derive(Debug, Copy, Clone, PartialEq, Eq)] - pub enum NodeKeyType { - Ed25519 - } -} - -arg_enum! { - /// Whether off-chain workers are enabled. - #[allow(missing_docs)] - #[derive(Debug, Clone)] - pub enum OffchainWorkerEnabled { - Always, - Never, - WhenValidating, - } -} - -/// Parameters used to create the `NodeKeyConfig`, which determines the keypair -/// used for libp2p networking. -#[derive(Debug, StructOpt, Clone)] -pub struct NodeKeyParams { - /// The secret key to use for libp2p networking. - /// - /// The value is a string that is parsed according to the choice of - /// `--node-key-type` as follows: - /// - /// `ed25519`: - /// The value is parsed as a hex-encoded Ed25519 32 bytes secret key, - /// i.e. 64 hex characters. - /// - /// The value of this option takes precedence over `--node-key-file`. - /// - /// WARNING: Secrets provided as command-line arguments are easily exposed. - /// Use of this option should be limited to development and testing. To use - /// an externally managed secret key, use `--node-key-file` instead. - #[structopt(long = "node-key", value_name = "KEY")] - pub node_key: Option, - - /// The type of secret key to use for libp2p networking. - /// - /// The secret key of the node is obtained as follows: - /// - /// * If the `--node-key` option is given, the value is parsed as a secret key - /// according to the type. See the documentation for `--node-key`. - /// - /// * If the `--node-key-file` option is given, the secret key is read from the - /// specified file. See the documentation for `--node-key-file`. - /// - /// * Otherwise, the secret key is read from a file with a predetermined, - /// type-specific name from the chain-specific network config directory - /// inside the base directory specified by `--base-dir`. If this file does - /// not exist, it is created with a newly generated secret key of the - /// chosen type. - /// - /// The node's secret key determines the corresponding public key and hence the - /// node's peer ID in the context of libp2p. - #[structopt( - long = "node-key-type", - value_name = "TYPE", - possible_values = &NodeKeyType::variants(), - case_insensitive = true, - default_value = "Ed25519" - )] - pub node_key_type: NodeKeyType, - - /// The file from which to read the node's secret key to use for libp2p networking. - /// - /// The contents of the file are parsed according to the choice of `--node-key-type` - /// as follows: - /// - /// `ed25519`: - /// The file must contain an unencoded 32 bytes Ed25519 secret key. - /// - /// If the file does not exist, it is created with a newly generated secret key of - /// the chosen type. - #[structopt(long = "node-key-file", value_name = "FILE")] - pub node_key_file: Option, -} - -/// Parameters used to create the network configuration. -#[derive(Debug, StructOpt, Clone)] -pub struct NetworkConfigurationParams { - /// Specify a list of bootnodes. - #[structopt(long = "bootnodes", value_name = "URL")] - pub bootnodes: Vec, - - /// Specify a list of reserved node addresses. - #[structopt(long = "reserved-nodes", value_name = "URL")] - pub reserved_nodes: Vec, - - /// Whether to only allow connections to/from reserved nodes. - /// - /// If you are a validator your node might still connect to other validator - /// nodes regardless of whether they are defined as reserved nodes. - #[structopt(long = "reserved-only")] - pub reserved_only: bool, - - /// Specify a list of sentry node public addresses. - #[structopt( - long = "sentry-nodes", - value_name = "URL", - conflicts_with_all = &[ "sentry" ] - )] - pub sentry_nodes: Vec, - - /// Listen on this multiaddress. - #[structopt(long = "listen-addr", value_name = "LISTEN_ADDR")] - pub listen_addr: Vec, - - /// Specify p2p protocol TCP port. - /// - /// Only used if --listen-addr is not specified. - #[structopt(long = "port", value_name = "PORT")] - pub port: Option, - - /// Allow connecting to private IPv4 addresses (as specified in - /// [RFC1918](https://tools.ietf.org/html/rfc1918)), unless the address was passed with - /// `--reserved-nodes` or `--bootnodes`. - #[structopt(long = "no-private-ipv4")] - pub no_private_ipv4: bool, - - /// Specify the number of outgoing connections we're trying to maintain. - #[structopt(long = "out-peers", value_name = "COUNT", default_value = "25")] - pub out_peers: u32, - - /// Specify the maximum number of incoming connections we're accepting. - #[structopt(long = "in-peers", value_name = "COUNT", default_value = "25")] - pub in_peers: u32, - - /// Disable mDNS discovery. - /// - /// By default, the network will use mDNS to discover other nodes on the - /// local network. This disables it. Automatically implied when using --dev. - #[structopt(long = "no-mdns")] - pub no_mdns: bool, - - /// Maximum number of peers to ask the same blocks in parallel. - /// - /// This allows downlading announced blocks from multiple peers. Decrease to save - /// traffic and risk increased latency. - #[structopt(long = "max-parallel-downloads", value_name = "COUNT", default_value = "5")] - pub max_parallel_downloads: u32, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub node_key_params: NodeKeyParams, - - /// Experimental feature flag. - #[structopt(long = "use-yamux-flow-control")] - pub use_yamux_flow_control: bool, -} - -/// The `run` command used to run a node. -#[derive(Debug, StructOpt, Clone)] -pub struct RunCmd { - /// Enable validator mode. - /// - /// The node will be started with the authority role and actively - /// participate in any consensus task that it can (e.g. depending on - /// availability of local keys). - #[structopt( - long = "validator", - conflicts_with_all = &[ "sentry" ] - )] - pub validator: bool, - - /// Enable sentry mode. - /// - /// The node will be started with the authority role and participate in - /// consensus tasks as an "observer", it will never actively participate - /// regardless of whether it could (e.g. keys are available locally). This - /// mode is useful as a secure proxy for validators (which would run - /// detached from the network), since we want this node to participate in - /// the full consensus protocols in order to have all needed consensus data - /// available to relay to private nodes. - #[structopt( - long = "sentry", - conflicts_with_all = &[ "validator", "light" ] - )] - pub sentry: bool, - - /// Disable GRANDPA voter when running in validator mode, otherwise disables the GRANDPA observer. - #[structopt(long = "no-grandpa")] - pub no_grandpa: bool, - - /// Experimental: Run in light client mode. - #[structopt(long = "light", conflicts_with = "sentry")] - pub light: bool, - - /// Listen to all RPC interfaces. - /// - /// Default is local. Note: not all RPC methods are safe to be exposed publicly. Use a RPC proxy - /// server to filter out dangerous methods. More details: https://github.com/paritytech/substrate/wiki/Public-RPC. - /// Use `--unsafe-rpc-external` to suppress the warning if you understand the risks. - #[structopt(long = "rpc-external")] - pub rpc_external: bool, - - /// Listen to all RPC interfaces. - /// - /// Same as `--rpc-external`. - #[structopt(long = "unsafe-rpc-external")] - pub unsafe_rpc_external: bool, - - /// Listen to all Websocket interfaces. - /// - /// Default is local. Note: not all RPC methods are safe to be exposed publicly. Use a RPC proxy - /// server to filter out dangerous methods. More details: https://github.com/paritytech/substrate/wiki/Public-RPC. - /// Use `--unsafe-ws-external` to suppress the warning if you understand the risks. - #[structopt(long = "ws-external")] - pub ws_external: bool, - - /// Listen to all Websocket interfaces. - /// - /// Same as `--ws-external`. - #[structopt(long = "unsafe-ws-external")] - pub unsafe_ws_external: bool, - - /// Listen to all Grafana data source interfaces. - /// - /// Default is local. - #[structopt(long = "grafana-external")] - pub grafana_external: bool, - - /// Specify HTTP RPC server TCP port. - #[structopt(long = "rpc-port", value_name = "PORT")] - pub rpc_port: Option, - - /// Specify WebSockets RPC server TCP port. - #[structopt(long = "ws-port", value_name = "PORT")] - pub ws_port: Option, - - /// Maximum number of WS RPC server connections. - #[structopt(long = "ws-max-connections", value_name = "COUNT")] - pub ws_max_connections: Option, - - /// Specify browser Origins allowed to access the HTTP & WS RPC servers. - /// - /// A comma-separated list of origins (protocol://domain or special `null` - /// value). Value of `all` will disable origin validation. Default is to - /// allow localhost, https://polkadot.js.org and - /// https://substrate-ui.parity.io origins. When running in --dev mode the - /// default is to allow all origins. - #[structopt(long = "rpc-cors", value_name = "ORIGINS", parse(try_from_str = parse_cors))] - pub rpc_cors: Option, - - /// Specify Grafana data source server TCP Port. - #[structopt(long = "grafana-port", value_name = "PORT")] - pub grafana_port: Option, - - /// The human-readable name for this node. - /// - /// The node name will be reported to the telemetry server, if enabled. - #[structopt(long = "name", value_name = "NAME")] - pub name: Option, - - /// Disable connecting to the Substrate telemetry server. - /// - /// Telemetry is on by default on global chains. - #[structopt(long = "no-telemetry")] - pub no_telemetry: bool, - - /// The URL of the telemetry server to connect to. - /// - /// This flag can be passed multiple times as a mean to specify multiple - /// telemetry endpoints. Verbosity levels range from 0-9, with 0 denoting - /// the least verbosity. If no verbosity level is specified the default is - /// 0. - #[structopt(long = "telemetry-url", value_name = "URL VERBOSITY", parse(try_from_str = parse_telemetry_endpoints))] - pub telemetry_endpoints: Vec<(String, u8)>, - - /// Should execute offchain workers on every block. - /// - /// By default it's only enabled for nodes that are authoring new blocks. - #[structopt( - long = "offchain-worker", - value_name = "ENABLED", - possible_values = &OffchainWorkerEnabled::variants(), - case_insensitive = true, - default_value = "WhenValidating" - )] - pub offchain_worker: OffchainWorkerEnabled, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub import_params: ImportParams, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub network_config: NetworkConfigurationParams, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub pool_config: TransactionPoolParams, - - /// Shortcut for `--name Alice --validator` with session keys for `Alice` added to keystore. - #[structopt(long, conflicts_with_all = &["bob", "charlie", "dave", "eve", "ferdie", "one", "two"])] - pub alice: bool, - - /// Shortcut for `--name Bob --validator` with session keys for `Bob` added to keystore. - #[structopt(long, conflicts_with_all = &["alice", "charlie", "dave", "eve", "ferdie", "one", "two"])] - pub bob: bool, - - /// Shortcut for `--name Charlie --validator` with session keys for `Charlie` added to keystore. - #[structopt(long, conflicts_with_all = &["alice", "bob", "dave", "eve", "ferdie", "one", "two"])] - pub charlie: bool, - - /// Shortcut for `--name Dave --validator` with session keys for `Dave` added to keystore. - #[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "eve", "ferdie", "one", "two"])] - pub dave: bool, - - /// Shortcut for `--name Eve --validator` with session keys for `Eve` added to keystore. - #[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "ferdie", "one", "two"])] - pub eve: bool, - - /// Shortcut for `--name Ferdie --validator` with session keys for `Ferdie` added to keystore. - #[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "one", "two"])] - pub ferdie: bool, - - /// Shortcut for `--name One --validator` with session keys for `One` added to keystore. - #[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "ferdie", "two"])] - pub one: bool, - - /// Shortcut for `--name Two --validator` with session keys for `Two` added to keystore. - #[structopt(long, conflicts_with_all = &["alice", "bob", "charlie", "dave", "eve", "ferdie", "one"])] - pub two: bool, - - /// Enable authoring even when offline. - #[structopt(long = "force-authoring")] - pub force_authoring: bool, - - /// Specify custom keystore path. - #[structopt(long = "keystore-path", value_name = "PATH", parse(from_os_str))] - pub keystore_path: Option, - - /// Use interactive shell for entering the password used by the keystore. - #[structopt( - long = "password-interactive", - conflicts_with_all = &[ "password", "password-filename" ] - )] - pub password_interactive: bool, - - /// Password used by the keystore. - #[structopt( - long = "password", - conflicts_with_all = &[ "password-interactive", "password-filename" ] - )] - pub password: Option, - - /// File that contains the password used by the keystore. - #[structopt( - long = "password-filename", - value_name = "PATH", - parse(from_os_str), - conflicts_with_all = &[ "password-interactive", "password" ] - )] - pub password_filename: Option -} - -impl RunCmd { - /// Get the `Sr25519Keyring` matching one of the flag - pub fn get_keyring(&self) -> Option { - use sp_keyring::Sr25519Keyring::*; - - if self.alice { Some(Alice) } - else if self.bob { Some(Bob) } - else if self.charlie { Some(Charlie) } - else if self.dave { Some(Dave) } - else if self.eve { Some(Eve) } - else if self.ferdie { Some(Ferdie) } - else if self.one { Some(One) } - else if self.two { Some(Two) } - else { None } - } - - /// Run the command that runs the node - pub fn run( - self, - mut config: Configuration, - new_light: FNL, - new_full: FNF, - version: &VersionInfo, - ) -> error::Result<()> - where - G: RuntimeGenesis, - E: ChainSpecExtension, - FNL: FnOnce(Configuration) -> Result, - FNF: FnOnce(Configuration) -> Result, - SL: AbstractService + Unpin, - SF: AbstractService + Unpin, - { - assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); - - crate::update_config_for_running_node(&mut config, self)?; - - crate::run_node(config, new_light, new_full, &version) - } -} diff --git a/client/cli/src/params/shared_params.rs b/client/cli/src/params/shared_params.rs index 03f44796460a2..45d6f2178410b 100644 --- a/client/cli/src/params/shared_params.rs +++ b/client/cli/src/params/shared_params.rs @@ -46,6 +46,20 @@ pub struct SharedParams { /// Sets a custom logging filter. #[structopt(short = "l", long = "log", value_name = "LOG_PATTERN")] pub log: Option, + + /// Use interactive shell for entering the password used by the keystore. + #[structopt( + long = "password-interactive", + conflicts_with_all = &[ "password", "password-filename" ] + )] + pub password_interactive: bool, + + /// Password used by the keystore. + #[structopt( + long = "password", + conflicts_with_all = &[ "password-interactive", "password-filename" ] + )] + pub password: Option, } impl SharedParams { diff --git a/client/cli/src/params/subcommand.rs b/client/cli/src/params/subcommand.rs deleted file mode 100644 index 3e303ca0b1bd2..0000000000000 --- a/client/cli/src/params/subcommand.rs +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -use structopt::{StructOpt}; -use sc_service::{ - Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand, -}; -use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; -use crate::error; -use std::fmt::Debug; -use super::*; - -/// All core commands that are provided by default. -/// -/// The core commands are split into multiple subcommands and `Run` is the default subcommand. From -/// the CLI user perspective, it is not visible that `Run` is a subcommand. So, all parameters of -/// `Run` are exported as main executable parameters. -#[derive(Debug, Clone, StructOpt)] -pub enum Subcommand { - /// Build a spec.json file, outputing to stdout. - BuildSpec(BuildSpecCmd), - - /// Export blocks to a file. - ExportBlocks(ExportBlocksCmd), - - /// Import blocks from file. - ImportBlocks(ImportBlocksCmd), - - /// Validte a single block. - CheckBlock(CheckBlockCmd), - - /// Revert chain to the previous state. - Revert(RevertCmd), - - /// Remove the whole chain data. - PurgeChain(PurgeChainCmd), - - /// Run runtime benchmarks. - Benchmark(BenchmarkCmd), - - /// Generate mmemonics - Generate(GenerateCmd), - - /// Generate Node Key - GenerateNodeKey(GenerateNodeKeyCmd), - - /// Inspect key. - Inspect(InspectCmd), - - /// Sign extrinsic - Sign(SignCmd), -} - -impl Subcommand { - /// Get the shared parameters of a `CoreParams` command - pub fn get_shared_params(&self) -> &SharedParams { - use Subcommand::*; - - match self { - BuildSpec(params) => ¶ms.shared_params, - ExportBlocks(params) => ¶ms.shared_params, - ImportBlocks(params) => ¶ms.shared_params, - CheckBlock(params) => ¶ms.shared_params, - Revert(params) => ¶ms.shared_params, - PurgeChain(params) => ¶ms.shared_params, - Benchmark(params) => ¶ms.shared_params, - Generate(params) => ¶ms.shared_params, - _ => unimplemented!() - } - } - - /// Run any `CoreParams` command - pub fn run( - self, - config: Configuration, - builder: B, - ) -> error::Result<()> - where - B: FnOnce(Configuration) -> Result, - G: RuntimeGenesis, - E: ChainSpecExtension, - BC: ServiceBuilderCommand + Unpin, - BB: sp_runtime::traits::Block + Debug, - <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, - ::Hash: std::str::FromStr, - { - assert!(config.chain_spec.is_some(), "chain_spec must be present before continuing"); - - match self { - Subcommand::BuildSpec(cmd) => cmd.run(config), - Subcommand::ExportBlocks(cmd) => cmd.run(config, builder), - Subcommand::ImportBlocks(cmd) => cmd.run(config, builder), - Subcommand::CheckBlock(cmd) => cmd.run(config, builder), - Subcommand::PurgeChain(cmd) => cmd.run(config), - Subcommand::Benchmark(cmd) => cmd.run(config, builder), - Subcommand::Revert(cmd) => cmd.run(config, builder), - _ => { - Ok(()) - }, - } - } -} \ No newline at end of file From f118c3adb66141e09398ea468e74b73c43622223 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 10 Mar 2020 20:29:40 +0100 Subject: [PATCH 03/77] WIP --- Cargo.lock | 638 ++++++++++++++++--- bin/utils/subkey/src/main.rs | 74 +-- client/cli/Cargo.toml | 12 +- client/cli/src/arg_enums.rs | 9 + client/cli/src/commands/generate.rs | 63 ++ client/cli/src/commands/generate_node_key.rs | 50 ++ client/cli/src/commands/inspect.rs | 61 ++ client/cli/src/commands/mod.rs | 12 + client/cli/src/commands/runcmd.rs | 29 +- client/cli/src/commands/sign.rs | 57 ++ client/cli/src/commands/sign_transaction.rs | 72 +++ client/cli/src/commands/transfer.rs | 85 +++ client/cli/src/commands/utils.rs | 261 ++++++++ client/cli/src/commands/verify.rs | 17 + client/cli/src/error.rs | 5 + client/cli/src/params/mod.rs | 6 +- client/cli/src/params/shared_params.rs | 50 +- frame/system/src/lib.rs | 3 +- primitives/core/src/crypto.rs | 15 +- 19 files changed, 1372 insertions(+), 147 deletions(-) create mode 100644 client/cli/src/commands/generate.rs create mode 100644 client/cli/src/commands/generate_node_key.rs create mode 100644 client/cli/src/commands/inspect.rs create mode 100644 client/cli/src/commands/sign.rs create mode 100644 client/cli/src/commands/sign_transaction.rs create mode 100644 client/cli/src/commands/transfer.rs create mode 100644 client/cli/src/commands/utils.rs create mode 100644 client/cli/src/commands/verify.rs diff --git a/Cargo.lock b/Cargo.lock index 32b2d0dc0f20b..5652280a1bff4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -189,7 +189,7 @@ dependencies = [ "mio", "mio-uds", "num_cpus", - "once_cell", + "once_cell 1.3.1", "pin-project-lite", "pin-utils", "slab", @@ -909,7 +909,7 @@ dependencies = [ "lazy_static", "maybe-uninit", "memoffset", - "scopeguard", + "scopeguard 1.1.0", ] [[package]] @@ -1511,7 +1511,7 @@ dependencies = [ "frame-system", "impl-trait-for-tuples", "log 0.4.8", - "once_cell", + "once_cell 1.3.1", "parity-scale-codec", "paste", "pretty_assertions", @@ -1993,6 +1993,16 @@ dependencies = [ "crunchy", ] +[[package]] +name = "hashbrown" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" +dependencies = [ + "byteorder 1.3.4", + "scopeguard 0.3.3", +] + [[package]] name = "hashbrown" version = "0.6.3" @@ -2612,6 +2622,43 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "libp2p" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f84847789ab24b3fc5971a68656ac85886df640986d9ce3264c0327694eae471" +dependencies = [ + "bytes 0.5.4", + "futures 0.3.4", + "lazy_static", + "libp2p-core 0.15.0", + "libp2p-core-derive 0.15.0", + "libp2p-deflate 0.7.0", + "libp2p-dns 0.15.0", + "libp2p-floodsub 0.15.0", + "libp2p-gossipsub 0.15.0", + "libp2p-identify 0.15.0", + "libp2p-kad 0.15.0", + "libp2p-mdns 0.15.0", + "libp2p-mplex 0.15.0", + "libp2p-noise 0.13.0", + "libp2p-ping 0.15.0", + "libp2p-plaintext 0.15.0", + "libp2p-secio 0.15.0", + "libp2p-swarm 0.5.0", + "libp2p-tcp 0.15.0", + "libp2p-uds 0.15.0", + "libp2p-wasm-ext 0.8.0", + "libp2p-websocket 0.15.0", + "libp2p-yamux 0.15.0", + "parity-multiaddr 0.7.2", + "parity-multihash 0.2.3", + "parking_lot 0.10.0", + "pin-project", + "smallvec 1.2.0", + "wasm-timer", +] + [[package]] name = "libp2p" version = "0.16.2" @@ -2621,27 +2668,27 @@ dependencies = [ "bytes 0.5.4", "futures 0.3.4", "lazy_static", - "libp2p-core", - "libp2p-core-derive", - "libp2p-deflate", - "libp2p-dns", - "libp2p-floodsub", - "libp2p-gossipsub", - "libp2p-identify", - "libp2p-kad", - "libp2p-mdns", - "libp2p-mplex", - "libp2p-noise", - "libp2p-ping", - "libp2p-plaintext", + "libp2p-core 0.16.0", + "libp2p-core-derive 0.16.0", + "libp2p-deflate 0.16.0", + "libp2p-dns 0.16.0", + "libp2p-floodsub 0.16.0", + "libp2p-gossipsub 0.16.0", + "libp2p-identify 0.16.0", + "libp2p-kad 0.16.2", + "libp2p-mdns 0.16.0", + "libp2p-mplex 0.16.0", + "libp2p-noise 0.16.2", + "libp2p-ping 0.16.0", + "libp2p-plaintext 0.16.0", "libp2p-pnet", - "libp2p-secio", - "libp2p-swarm", - "libp2p-tcp", - "libp2p-uds", - "libp2p-wasm-ext", - "libp2p-websocket", - "libp2p-yamux", + "libp2p-secio 0.16.1", + "libp2p-swarm 0.16.1", + "libp2p-tcp 0.16.0", + "libp2p-uds 0.16.0", + "libp2p-wasm-ext 0.16.2", + "libp2p-websocket 0.16.0", + "libp2p-yamux 0.16.2", "parity-multiaddr 0.7.2", "parity-multihash 0.2.3", "parking_lot 0.10.0", @@ -2650,6 +2697,40 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-core" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbafb2706b8082233f66dc13e196f9cf9b4c229f2cd7c96b2b16617ad6ee330b" +dependencies = [ + "asn1_der", + "bs58 0.3.0", + "ed25519-dalek", + "fnv", + "futures 0.3.4", + "futures-timer 2.0.2", + "lazy_static", + "libsecp256k1", + "log 0.4.8", + "multistream-select", + "parity-multiaddr 0.7.2", + "parity-multihash 0.2.3", + "parking_lot 0.10.0", + "pin-project", + "prost", + "prost-build", + "rand 0.7.3", + "ring", + "rw-stream-sink", + "sha2", + "smallvec 1.2.0", + "thiserror", + "unsigned-varint 0.3.1", + "untrusted", + "void", + "zeroize 1.1.0", +] + [[package]] name = "libp2p-core" version = "0.16.0" @@ -2683,6 +2764,16 @@ dependencies = [ "zeroize 1.1.0", ] +[[package]] +name = "libp2p-core-derive" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c320266be0a7760e23484d635acdb83844b2d74d3612d93b41c393c9bcf004e" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "libp2p-core-derive" version = "0.16.0" @@ -2693,6 +2784,17 @@ dependencies = [ "syn", ] +[[package]] +name = "libp2p-deflate" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be32697b42d040b325c3737f827ea04ede569ec956b7807700dd8d89d8210f9" +dependencies = [ + "flate2", + "futures 0.3.4", + "libp2p-core 0.15.0", +] + [[package]] name = "libp2p-deflate" version = "0.16.0" @@ -2701,7 +2803,18 @@ checksum = "2e25004d4d9837b44b22c5f1a69be1724a5168fef6cff1716b5176a972c3aa62" dependencies = [ "flate2", "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", +] + +[[package]] +name = "libp2p-dns" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f11c979b882f25d85726b15637d5bbc722dfa1be576605c54e99b8cf56906be3" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "log 0.4.8", ] [[package]] @@ -2711,10 +2824,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b99e552f9939b606eb4b59f7f64d9b01e3f96752f47e350fc3c5fc646ed3f649" dependencies = [ "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", ] +[[package]] +name = "libp2p-floodsub" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bdf6fba9272ad47dde94bade89540fdb16e24ae9ff7fb714c1c80a035165f28" +dependencies = [ + "bs58 0.3.0", + "cuckoofilter", + "fnv", + "futures 0.3.4", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "prost", + "prost-build", + "rand 0.7.3", + "smallvec 1.2.0", +] + [[package]] name = "libp2p-floodsub" version = "0.16.0" @@ -2724,14 +2855,40 @@ dependencies = [ "cuckoofilter", "fnv", "futures 0.3.4", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "prost", "prost-build", "rand 0.7.3", "smallvec 1.2.0", ] +[[package]] +name = "libp2p-gossipsub" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e6ecd058bf769d27ebec530544b081e08b0a1088e3186da8cc58d59915784d0" +dependencies = [ + "base64 0.11.0", + "bs58 0.3.0", + "byteorder 1.3.4", + "bytes 0.5.4", + "fnv", + "futures 0.3.4", + "futures_codec", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "lru", + "prost", + "prost-build", + "rand 0.7.3", + "sha2", + "smallvec 1.2.0", + "unsigned-varint 0.3.1", + "wasm-timer", +] + [[package]] name = "libp2p-gossipsub" version = "0.16.0" @@ -2744,8 +2901,8 @@ dependencies = [ "fnv", "futures 0.3.4", "futures_codec", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "lru", "prost", @@ -2757,6 +2914,22 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-identify" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1a6261b804111c2dbf53f8ca03f66edc5ad1c29b78a61cf0cc5354052e28e9" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "prost", + "prost-build", + "smallvec 1.2.0", + "wasm-timer", +] + [[package]] name = "libp2p-identify" version = "0.16.0" @@ -2764,8 +2937,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfeb935a9bd41263e4f3a24b988e9f4a044f3ae89ac284e83c17fe2f84e0d66b" dependencies = [ "futures 0.3.4", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "prost", "prost-build", @@ -2773,6 +2946,33 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-kad" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c6ea6fece0d99599afb1b2082ca8937944cdd6b0946a88d54cb3ae7a38d1253" +dependencies = [ + "arrayvec 0.5.1", + "bytes 0.5.4", + "either", + "fnv", + "futures 0.3.4", + "futures_codec", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "parity-multihash 0.2.3", + "prost", + "prost-build", + "rand 0.7.3", + "sha2", + "smallvec 1.2.0", + "uint", + "unsigned-varint 0.3.1", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-kad" version = "0.16.2" @@ -2785,8 +2985,8 @@ dependencies = [ "fnv", "futures 0.3.4", "futures_codec", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "parity-multihash 0.2.3", "prost", @@ -2800,6 +3000,28 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-mdns" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "074312353355df310affa105ec71b16fd7e52f5c6ae61d3dcbb3e79e8fdc9e5f" +dependencies = [ + "async-std", + "data-encoding", + "dns-parser", + "either", + "futures 0.3.4", + "lazy_static", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "net2", + "rand 0.7.3", + "smallvec 1.2.0", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-mdns" version = "0.16.0" @@ -2812,8 +3034,8 @@ dependencies = [ "either", "futures 0.3.4", "lazy_static", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "net2", "rand 0.7.3", @@ -2822,6 +3044,22 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-mplex" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89d0b44dfdef80cc2be4b42d127de1c793905eca2459415a5c57d6b4fbd8ec30" +dependencies = [ + "bytes 0.5.4", + "fnv", + "futures 0.3.4", + "futures_codec", + "libp2p-core 0.15.0", + "log 0.4.8", + "parking_lot 0.10.0", + "unsigned-varint 0.3.1", +] + [[package]] name = "libp2p-mplex" version = "0.16.0" @@ -2832,12 +3070,32 @@ dependencies = [ "fnv", "futures 0.3.4", "futures_codec", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "parking_lot 0.10.0", "unsigned-varint 0.3.1", ] +[[package]] +name = "libp2p-noise" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0845e8208d814cd41c26c90a6a2f2b720c31b588209cecc49a44c881a09f417f" +dependencies = [ + "curve25519-dalek 1.2.3", + "futures 0.3.4", + "lazy_static", + "libp2p-core 0.15.0", + "log 0.4.8", + "prost", + "prost-build", + "rand 0.7.3", + "ring", + "snow", + "x25519-dalek 0.5.2", + "zeroize 1.1.0", +] + [[package]] name = "libp2p-noise" version = "0.16.2" @@ -2847,7 +3105,7 @@ dependencies = [ "curve25519-dalek 2.0.0", "futures 0.3.4", "lazy_static", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "prost", "prost-build", @@ -2855,10 +3113,25 @@ dependencies = [ "sha2", "snow", "static_assertions", - "x25519-dalek", + "x25519-dalek 0.6.0", "zeroize 1.1.0", ] +[[package]] +name = "libp2p-ping" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ecced2949ae93b6ff29565303ecd1bef15c4e4efb689033ee744922561a36b" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "rand 0.7.3", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-ping" version = "0.16.0" @@ -2866,14 +3139,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d22f2f228b3a828dca1cb8aa9fa331e0bc9c36510cb2c1916956e20dc85e8c" dependencies = [ "futures 0.3.4", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "rand 0.7.3", "void", "wasm-timer", ] +[[package]] +name = "libp2p-plaintext" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "195fda6b6a948a242fd30570e0e3418ae8e0a20055ea75d45458e1079a8efb05" +dependencies = [ + "bytes 0.5.4", + "futures 0.3.4", + "futures_codec", + "libp2p-core 0.15.0", + "log 0.4.8", + "prost", + "prost-build", + "rw-stream-sink", + "unsigned-varint 0.3.1", + "void", +] + [[package]] name = "libp2p-plaintext" version = "0.16.0" @@ -2883,7 +3174,7 @@ dependencies = [ "bytes 0.5.4", "futures 0.3.4", "futures_codec", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "prost", "prost-build", @@ -2906,6 +3197,36 @@ dependencies = [ "sha3", ] +[[package]] +name = "libp2p-secio" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ceef68ca377b264f84d64c88739a8fa118b5db1e8f18297351dff75314504a5f" +dependencies = [ + "aes-ctr", + "ctr", + "futures 0.3.4", + "hmac", + "js-sys", + "lazy_static", + "libp2p-core 0.15.0", + "log 0.4.8", + "parity-send-wrapper", + "pin-project", + "prost", + "prost-build", + "quicksink", + "rand 0.7.3", + "ring", + "rw-stream-sink", + "sha2", + "static_assertions", + "twofish", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "libp2p-secio" version = "0.16.1" @@ -2918,7 +3239,7 @@ dependencies = [ "hmac", "js-sys", "lazy_static", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "parity-send-wrapper", "pin-project", @@ -2936,6 +3257,20 @@ dependencies = [ "web-sys", ] +[[package]] +name = "libp2p-swarm" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14ea00be81bc3985e36abad263ce2ad1b6aeb862aa743563eb70ad42880c05ae" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "log 0.4.8", + "smallvec 1.2.0", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-swarm" version = "0.16.1" @@ -2943,13 +3278,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "275471e7c0e88ae004660866cd54f603bd8bd1f4caef541a27f50dd8640c4d4c" dependencies = [ "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "smallvec 1.2.0", "void", "wasm-timer", ] +[[package]] +name = "libp2p-tcp" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e65ef381570df31cb047dfbc11483ab0fe7e6abbdcf2bdc2c60b5d11133d241" +dependencies = [ + "async-std", + "futures 0.3.4", + "futures-timer 2.0.2", + "get_if_addrs", + "ipnet", + "libp2p-core 0.15.0", + "log 0.4.8", +] + [[package]] name = "libp2p-tcp" version = "0.16.0" @@ -2961,7 +3311,19 @@ dependencies = [ "futures-timer 3.0.2", "get_if_addrs", "ipnet", - "libp2p-core", + "libp2p-core 0.16.0", + "log 0.4.8", +] + +[[package]] +name = "libp2p-uds" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e4f4f7989b35f33d4b9738aab2f031310eb20fec513cab44d12b1bc985a8074" +dependencies = [ + "async-std", + "futures 0.3.4", + "libp2p-core 0.15.0", "log 0.4.8", ] @@ -2973,10 +3335,24 @@ checksum = "76d329564a43da9d0e055a5b938633c4a8ceab1f59cec133fbc4647917c07341" dependencies = [ "async-std", "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", ] +[[package]] +name = "libp2p-wasm-ext" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b4d457adb91a5e2212343218a554394cd8ced64a79fb8e36e7aed2a16d49495" +dependencies = [ + "futures 0.3.4", + "js-sys", + "libp2p-core 0.15.0", + "parity-send-wrapper", + "wasm-bindgen", + "wasm-bindgen-futures", +] + [[package]] name = "libp2p-wasm-ext" version = "0.16.2" @@ -2985,12 +3361,33 @@ checksum = "923581c055bc4b8c5f42d4ce5ef43e52fe5216f1ea4bc26476cb8a966ce6220b" dependencies = [ "futures 0.3.4", "js-sys", - "libp2p-core", + "libp2p-core 0.16.0", "parity-send-wrapper", "wasm-bindgen", "wasm-bindgen-futures", ] +[[package]] +name = "libp2p-websocket" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bba425f2af1fdb7dece88b9ae05ca9430dfb0b72b2c078e73ded6f1556084509" +dependencies = [ + "async-tls", + "bytes 0.5.4", + "either", + "futures 0.3.4", + "libp2p-core 0.15.0", + "log 0.4.8", + "quicksink", + "rustls", + "rw-stream-sink", + "soketto", + "url 2.1.1", + "webpki", + "webpki-roots 0.18.0", +] + [[package]] name = "libp2p-websocket" version = "0.16.0" @@ -3001,7 +3398,7 @@ dependencies = [ "bytes 0.5.4", "either", "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "quicksink", "rustls", @@ -3012,6 +3409,20 @@ dependencies = [ "webpki-roots 0.18.0", ] +[[package]] +name = "libp2p-yamux" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca25b3aac78a3c93c2a567622abd3cfc16f96f26ae1bf6134f0056203d62d86" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "log 0.4.8", + "parking_lot 0.10.0", + "thiserror", + "yamux", +] + [[package]] name = "libp2p-yamux" version = "0.16.2" @@ -3019,7 +3430,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dac30de24ccde0e67f363d71a125c587bbe6589503f664947e9b084b68a34f1" dependencies = [ "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "parking_lot 0.10.0", "thiserror", "yamux", @@ -3080,13 +3491,22 @@ dependencies = [ "linked-hash-map", ] +[[package]] +name = "lock_api" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" +dependencies = [ + "scopeguard 0.3.3", +] + [[package]] name = "lock_api" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79b2de95ecb4691949fea4716ca53cdbcfccb2c612e19644a8bad05edcf9f47b" dependencies = [ - "scopeguard", + "scopeguard 1.1.0", ] [[package]] @@ -3113,7 +3533,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0609345ddee5badacf857d4f547e0e5a2e987db77085c24cd887f73573a04237" dependencies = [ - "hashbrown", + "hashbrown 0.6.3", ] [[package]] @@ -3160,7 +3580,7 @@ checksum = "198831fe8722331a395bc199a5d08efbc197497ef354cb4c77b969c02ffc0fc4" dependencies = [ "ahash", "hash-db", - "hashbrown", + "hashbrown 0.6.3", "parity-util-mem", ] @@ -3781,6 +4201,15 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "once_cell" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "532c29a261168a45ce28948f9537ddd7a5dd272cc513b3017b1e82a88f962c37" +dependencies = [ + "parking_lot 0.7.1", +] + [[package]] name = "once_cell" version = "1.3.1" @@ -4670,7 +5099,7 @@ checksum = "ef1476e40bf8f5c6776e9600983435821ca86eb9819d74a6207cca69d091406a" dependencies = [ "cfg-if", "ethereum-types", - "hashbrown", + "hashbrown 0.6.3", "impl-trait-for-tuples", "lru", "parity-util-mem-derive", @@ -4706,13 +5135,23 @@ version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" +[[package]] +name = "parking_lot" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" +dependencies = [ + "lock_api 0.1.5", + "parking_lot_core 0.4.0", +] + [[package]] name = "parking_lot" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" dependencies = [ - "lock_api", + "lock_api 0.3.3", "parking_lot_core 0.6.2", "rustc_version", ] @@ -4723,10 +5162,23 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92e98c49ab0b7ce5b222f2cc9193fc4efe11c6d0bd4f648e374684a6857b1cfc" dependencies = [ - "lock_api", + "lock_api 0.3.3", "parking_lot_core 0.7.0", ] +[[package]] +name = "parking_lot_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" +dependencies = [ + "libc", + "rand 0.6.5", + "rustc_version", + "smallvec 0.6.13", + "winapi 0.3.8", +] + [[package]] name = "parking_lot_core" version = "0.6.2" @@ -5595,7 +6047,7 @@ dependencies = [ "env_logger 0.7.1", "futures 0.3.4", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "parity-scale-codec", "prost", @@ -5689,10 +6141,18 @@ dependencies = [ "derive_more", "env_logger 0.7.1", "fdlimit", + "frame-system", "futures 0.3.4", + "hex", + "hex-literal", "lazy_static", + "libp2p 0.15.0", "log 0.4.8", "names", + "pallet-balances", + "pallet-indices", + "pallet-transaction-payment", + "parity-scale-codec", "parity-util-mem", "regex", "rpassword", @@ -5709,10 +6169,12 @@ dependencies = [ "sp-panic-handler", "sp-runtime", "sp-state-machine", + "sp-version", "structopt", "substrate-prometheus-endpoint", "tempfile", "time", + "tiny-bip39 0.6.2", "tokio 0.2.12", ] @@ -6194,7 +6656,7 @@ dependencies = [ "futures 0.3.4", "futures-timer 3.0.2", "futures_codec", - "libp2p", + "libp2p 0.16.2", "linked-hash-map", "linked_hash_set", "log 0.4.8", @@ -6242,7 +6704,7 @@ version = "0.8.0-alpha.3" dependencies = [ "futures 0.3.4", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "lru", "sc-network", @@ -6257,7 +6719,7 @@ dependencies = [ "env_logger 0.7.1", "futures 0.3.4", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "parking_lot 0.10.0", "rand 0.7.3", @@ -6311,7 +6773,7 @@ name = "sc-peerset" version = "2.0.0-alpha.3" dependencies = [ "futures 0.3.4", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "rand 0.7.3", "serde_json", @@ -6497,7 +6959,7 @@ dependencies = [ "bytes 0.5.4", "futures 0.3.4", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "parking_lot 0.10.0", "pin-project", @@ -6606,6 +7068,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" +[[package]] +name = "scopeguard" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" + [[package]] name = "scopeguard" version = "1.1.0" @@ -6886,7 +7354,7 @@ dependencies = [ "rustc_version", "sha2", "subtle 2.2.2", - "x25519-dalek", + "x25519-dalek 0.6.0", ] [[package]] @@ -7062,7 +7530,7 @@ dependencies = [ "futures 0.3.4", "futures-diagnose", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "parity-scale-codec", "parking_lot 0.10.0", @@ -7152,7 +7620,7 @@ dependencies = [ "sp-std", "sp-storage", "substrate-bip39", - "tiny-bip39", + "tiny-bip39 0.7.1", "tiny-keccak 2.0.1", "twox-hash", "wasmi", @@ -7552,9 +8020,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.9" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1bcbed7d48956fcbb5d80c6b95aedb553513de0a1b451ea92679d999c010e98" +checksum = "3fe43617218c0805c6eb37160119dc3c548110a67786da7218d1c6555212f073" dependencies = [ "clap", "lazy_static", @@ -7563,9 +8031,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "095064aa1f5b94d14e635d0a5684cf140c43ae40a0fd990708d38f5d669e5f64" +checksum = "c6e79c80e0f4efd86ca960218d4e056249be189ff1c42824dcd9a7f51a56f0bd" dependencies = [ "heck", "proc-macro-error", @@ -7608,7 +8076,7 @@ dependencies = [ "hyper 0.12.35", "itertools", "jsonrpc-core-client", - "libp2p", + "libp2p 0.16.2", "node-primitives", "node-runtime", "pallet-balances", @@ -7622,7 +8090,7 @@ dependencies = [ "sp-core", "sp-runtime", "substrate-bip39", - "tiny-bip39", + "tiny-bip39 0.7.1", ] [[package]] @@ -7650,7 +8118,7 @@ dependencies = [ "futures-timer 3.0.2", "js-sys", "kvdb-web", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "rand 0.6.5", "rand 0.7.3", @@ -8004,6 +8472,21 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "tiny-bip39" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1c5676413eaeb1ea35300a0224416f57abc3bd251657e0fafc12c47ff98c060" +dependencies = [ + "failure", + "hashbrown 0.1.8", + "hmac", + "once_cell 0.1.8", + "pbkdf2", + "rand 0.6.5", + "sha2", +] + [[package]] name = "tiny-bip39" version = "0.7.1" @@ -8012,7 +8495,7 @@ checksum = "a6848cd8f566953ce1e8faeba12ee23cbdbb0437754792cd857d44628b5685e3" dependencies = [ "failure", "hmac", - "once_cell", + "once_cell 1.3.1", "pbkdf2", "rand 0.7.3", "rustc-hash", @@ -8413,7 +8896,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de9222c50cc325855621271157c973da27a0dcd26fa06f8edf81020bd2333df0" dependencies = [ "hash-db", - "hashbrown", + "hashbrown 0.6.3", "log 0.4.8", "rustc-hex", "smallvec 1.2.0", @@ -9161,6 +9644,17 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "x25519-dalek" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ee1585dc1484373cbc1cee7aafda26634665cf449436fd6e24bfd1fad230538" +dependencies = [ + "clear_on_drop", + "curve25519-dalek 1.2.3", + "rand_core 0.3.1", +] + [[package]] name = "x25519-dalek" version = "0.6.0" diff --git a/bin/utils/subkey/src/main.rs b/bin/utils/subkey/src/main.rs index 33209692caffb..148d73e28d5bd 100644 --- a/bin/utils/subkey/src/main.rs +++ b/bin/utils/subkey/src/main.rs @@ -81,7 +81,7 @@ trait Crypto: Sized { { if let Ok((pair, seed)) = Self::Pair::from_phrase(uri, password) { let public_key = Self::public_from_pair(&pair); - + match output { OutputType::Json => { let json = json!({ @@ -99,11 +99,11 @@ trait Crypto: Sized { Public key (hex): {}\n \ Account ID: {}\n \ SS58 Address: {}", - uri, - format_seed::(seed), - format_public_key::(public_key.clone()), - format_account_id::(public_key), - Self::ss58_from_pair(&pair), + uri, + format_seed::(seed), + format_public_key::(public_key.clone()), + format_account_id::(public_key), + Self::ss58_from_pair(&pair), ); }, } @@ -127,17 +127,17 @@ trait Crypto: Sized { Public key (hex): {}\n \ Account ID: {}\n \ SS58 Address: {}", - uri, - if let Some(seed) = seed { format_seed::(seed) } else { "n/a".into() }, - format_public_key::(public_key.clone()), - format_account_id::(public_key), - Self::ss58_from_pair(&pair), + uri, + if let Some(seed) = seed { format_seed::(seed) } else { "n/a".into() }, + format_public_key::(public_key.clone()), + format_account_id::(public_key), + Self::ss58_from_pair(&pair), ); }, } - + } else if let Ok((public_key, v)) = - ::Public::from_string_with_version(uri) + ::Public::from_string_with_version(uri) { let v = network_override.unwrap_or(v); @@ -158,11 +158,11 @@ trait Crypto: Sized { Public key (hex): {}\n \ Account ID: {}\n \ SS58 Address: {}", - uri, - String::from(v), - format_public_key::(public_key.clone()), - format_account_id::(public_key.clone()), - public_key.to_ss58check_with_version(v), + uri, + String::from(v), + format_public_key::(public_key.clone()), + format_account_id::(public_key.clone()), + public_key.to_ss58check_with_version(v), ); }, } @@ -369,9 +369,9 @@ fn static_err(msg: &'static str) -> Result<(), Error> { } fn execute(matches: ArgMatches) -> Result<(), Error> -where - SignatureOf: SignatureT, - PublicOf: PublicT, + where + SignatureOf: SignatureT, + PublicOf: PublicT, { let password_interactive = matches.is_present("password-interactive"); let password = matches.value_of("password"); @@ -395,7 +395,7 @@ where Some(Err(e)) => return Err(e), Some(Ok(v)) => Some(v), None => None, - }; + }; if let Some(network) = maybe_network { set_default_ss58_version(network); @@ -405,7 +405,7 @@ where Some(Err(_)) => return Err(Error::Static("Invalid output name. See --help for available outputs.")), Some(Ok(v)) => v, None => OutputType::Text, - }; + }; match matches.subcommand() { ("generate", Some(matches)) => { @@ -521,9 +521,9 @@ fn generate_mnemonic(matches: &ArgMatches) -> Result { } fn do_sign(suri: &str, message: Vec, password: Option<&str>) -> Result -where - SignatureOf: SignatureT, - PublicOf: PublicT, + where + SignatureOf: SignatureT, + PublicOf: PublicT, { let pair = read_pair::(Some(suri), password)?; let signature = pair.sign(&message); @@ -531,9 +531,9 @@ where } fn do_verify(matches: &ArgMatches, uri: &str, message: Vec) -> Result -where - SignatureOf: SignatureT, - PublicOf: PublicT, + where + SignatureOf: SignatureT, + PublicOf: PublicT, { let signature = read_signature::(matches)?; @@ -582,9 +582,9 @@ fn read_genesis_hash(matches: &ArgMatches) -> Result { } fn read_signature(matches: &ArgMatches) -> Result, Error> -where - SignatureOf: SignatureT, - PublicOf: PublicT, + where + SignatureOf: SignatureT, + PublicOf: PublicT, { let sig_data = matches .value_of("sig") @@ -603,8 +603,8 @@ where } fn read_public_key(matched_uri: Option<&str>) -> PublicOf -where - PublicOf: PublicT, + where + PublicOf: PublicT, { let uri = matched_uri.expect("parameter is required; thus it can't be None; qed"); let uri = if uri.starts_with("0x") { @@ -724,9 +724,9 @@ mod tests { use super::*; fn test_generate_sign_verify() - where - SignatureOf: SignatureT, - PublicOf: PublicT, + where + SignatureOf: SignatureT, + PublicOf: PublicT, { let usage = get_usage(); let app = get_app(&usage); diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 588aa134ab172..691cfd5c20bcd 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -23,8 +23,15 @@ tokio = { version = "0.2.9", features = [ "signal", "rt-core", "rt-threaded" ] } futures = "0.3.1" fdlimit = "0.1.1" serde_json = "1.0.41" +parity-scale-codec = "1.2.0" +hex = "0.4.2" +frame-system = { version = "2.0.0-alpha.3", path = "../../frame/system" } +pallet-balances = { version = "2.0.0-alpha.3", path = "../../frame/balances" } +pallet-indices = { version = "2.0.0-alpha.3", path = "../../frame/indices" } +pallet-transaction-payment = { version = "2.0.0-alpha.3", path = "../../frame/transaction-payment" } sc-informant = { version = "0.8.0-alpha.2", path = "../informant" } sp-panic-handler = { version = "2.0.0-alpha.2", path = "../../primitives/panic-handler" } +sp-version = { version = "2.0.0-alpha.3", path = "../../primitives/version" } sc-client-api = { version = "2.0.0-alpha.2", path = "../api" } sp-blockchain = { version = "2.0.0-alpha.2", path = "../../primitives/blockchain" } sc-network = { version = "0.8.0-alpha.2", path = "../network" } @@ -36,10 +43,13 @@ sc-telemetry = { version = "2.0.0-alpha.2", path = "../telemetry" } substrate-prometheus-endpoint = { path = "../../utils/prometheus" , version = "0.8.0-alpha.2"} sp-keyring = { version = "2.0.0-alpha.2", path = "../../primitives/keyring" } names = "0.11.0" -structopt = "0.3.8" +structopt = "0.3.11" sc-tracing = { version = "2.0.0-alpha.2", path = "../tracing" } chrono = "0.4.10" parity-util-mem = { version = "0.5.1", default-features = false, features = ["primitive-types"] } +tiny-bip39 = "0.6.2" +libp2p = "0.15.0" +hex-literal = "0.2.1" [target.'cfg(not(target_os = "unknown"))'.dependencies] rpassword = "4.0.1" diff --git a/client/cli/src/arg_enums.rs b/client/cli/src/arg_enums.rs index 384087bec0dbe..564fbfdb31596 100644 --- a/client/cli/src/arg_enums.rs +++ b/client/cli/src/arg_enums.rs @@ -82,6 +82,15 @@ arg_enum! { } } +arg_enum! { + #[allow(missing_docs)] + #[derive(Debug, Copy, Clone, PartialEq, Eq)] + pub enum OutputType { + Json, + Text, + } +} + arg_enum! { /// How to execute blocks #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/client/cli/src/commands/generate.rs b/client/cli/src/commands/generate.rs new file mode 100644 index 0000000000000..a0880e67d5608 --- /dev/null +++ b/client/cli/src/commands/generate.rs @@ -0,0 +1,63 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Implementation of the `generate` subcommand + +use super::{SharedParams, Crypto, get_password}; +use crate::error::{self, Error}; +use bip39::{MnemonicType, Mnemonic, Language}; +use structopt::StructOpt; + +/// The `generate` command +#[derive(Debug, StructOpt, Clone)] +#[structopt(name = "generate", about = "Generate a random account")] +pub struct GenerateCmd { + /// The number of words in the phrase to generate. One of 12 default), 15, 18, 21 and 24. + #[structopt(long, short = "w", value_name = "WORDS")] + words: Option, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + +impl GenerateCmd { + /// Run the command + pub fn run(self) -> error::Result<()> { + let words = match self.words { + Some(words) => { + MnemonicType::for_word_count(words) + .map_err(|_| { + Error::Input("Invalid number of words given for phrase: must be 12/15/18/21/24".into()) + })? + }, + None => MnemonicType::Words12, + }; + let mnemonic = Mnemonic::new(words, Language::English); + let password = get_password(&self.shared_params)?; + let maybe_network = self.shared_params.network; + let output = self.shared_params.output_type; + + C::print_from_uri( + mnemonic.phrase(), + Some(password.as_str()), + Some(maybe_network), + output + ); + + Ok(()) + } +} diff --git a/client/cli/src/commands/generate_node_key.rs b/client/cli/src/commands/generate_node_key.rs new file mode 100644 index 0000000000000..8775b6c19cf5b --- /dev/null +++ b/client/cli/src/commands/generate_node_key.rs @@ -0,0 +1,50 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Implementation of the `generate-node-key` subcommand + +use crate::error; +use structopt::StructOpt; +use std::{path::PathBuf, fs}; +use libp2p::identity::{ed25519 as libp2p_ed25519, PublicKey}; + +#[derive(Debug, StructOpt, Clone)] +#[structopt( + name = "generate-node-key", + about = "Generate a random node libp2p key, save it to file and print its peer ID" +)] +pub struct GenerateNodeKeyCmd { + /// Name of file to save secret key to. + #[structopt(long)] + file: PathBuf, +} + +impl GenerateNodeKeyCmd { + /// Run the command + pub fn run(self) -> error::Result<()> { + let file = self.file; + + let keypair = libp2p_ed25519::Keypair::generate(); + let secret = keypair.secret(); + let peer_id = PublicKey::Ed25519(keypair.public()).into_peer_id(); + + fs::write(file, secret.as_ref())?; + + println!("{}", peer_id); + + Ok(()) + } +} diff --git a/client/cli/src/commands/inspect.rs b/client/cli/src/commands/inspect.rs new file mode 100644 index 0000000000000..ac0167e546c03 --- /dev/null +++ b/client/cli/src/commands/inspect.rs @@ -0,0 +1,61 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Implementation of the `inspect` subcommand + +use crate::{error, arg_enums::OutputType}; +use super::{SharedParams, RunCmd, get_password, read_uri, Crypto}; +use structopt::StructOpt; + + + +#[derive(Debug, StructOpt, Clone)] +#[structopt( + name = "inspect", + about = "Gets a public key and a SS58 address from the provided Secret URI" +)] +pub struct InspectCmd { + /// A Key URI to be inspected. May be a secret seed, secret URI (with derivation paths and password), SS58 or + /// public URI. If the value is a file, the file content is used as URI. + /// If not given, you will be prompted for the URI. + #[structopt(long)] + uri: Option, + + output_type: OutputType, + + network: String, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + +impl InspectCmd { + pub fn run(self, _run_cmd: RunCmd) -> error::Result<()> { + let uri = read_uri(self.uri)?; + let pass = get_password(&self.shared_params)?; + + C::print_from_uri( + &uri, + Some(pass.as_str()), + Some(self.shared_params.network), + self.shared_params.output_type + ); + + Ok(()) + } +} + diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index e9f991c745883..fd69d31a75577 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -21,6 +21,14 @@ mod import_blocks_cmd; mod check_block_cmd; mod revert_cmd; mod purge_chain_cmd; +mod generate_node_key; +mod generate; +mod inspect; +mod sign; +mod sign_transaction; +mod utils; +mod transfer; +mod verify; use std::fmt::Debug; use structopt::StructOpt; @@ -34,6 +42,7 @@ use crate::error; use crate::VersionInfo; use crate::params::SharedParams; +pub use crate::commands::utils::*; pub use crate::commands::runcmd::RunCmd; pub use crate::commands::export_blocks_cmd::ExportBlocksCmd; pub use crate::commands::build_spec_cmd::BuildSpecCmd; @@ -69,6 +78,9 @@ pub enum Subcommand { /// Remove the whole chain data. PurgeChain(purge_chain_cmd::PurgeChainCmd), + + // Generate a key for a node + // GenerateNodeKey(generate_node_key::GenerateNodeKeyCmd), } impl Subcommand { diff --git a/client/cli/src/commands/runcmd.rs b/client/cli/src/commands/runcmd.rs index 2a070b27b8b85..73b3b11260620 100644 --- a/client/cli/src/commands/runcmd.rs +++ b/client/cli/src/commands/runcmd.rs @@ -243,29 +243,6 @@ pub struct RunCmd { /// Specify custom keystore path. #[structopt(long = "keystore-path", value_name = "PATH", parse(from_os_str))] pub keystore_path: Option, - - /// Use interactive shell for entering the password used by the keystore. - #[structopt( - long = "password-interactive", - conflicts_with_all = &[ "password", "password-filename" ] - )] - pub password_interactive: bool, - - /// Password used by the keystore. - #[structopt( - long = "password", - conflicts_with_all = &[ "password-interactive", "password-filename" ] - )] - pub password: Option, - - /// File that contains the password used by the keystore. - #[structopt( - long = "password-filename", - value_name = "PATH", - parse(from_os_str), - conflicts_with_all = &[ "password-interactive", "password" ] - )] - pub password_filename: Option } impl RunCmd { @@ -298,16 +275,16 @@ impl RunCmd { { self.shared_params.update_config(&mut config, spec_factory, version)?; - let password = if self.password_interactive { + let password = if self.shared_params.password_interactive { #[cfg(not(target_os = "unknown"))] { Some(input_keystore_password()?.into()) } #[cfg(target_os = "unknown")] None - } else if let Some(ref file) = self.password_filename { + } else if let Some(ref file) = self.shared_params.password_filename { Some(fs::read_to_string(file).map_err(|e| format!("{}", e))?.into()) - } else if let Some(ref password) = self.password { + } else if let Some(ref password) = self.shared_params.password { Some(password.clone().into()) } else { None diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs new file mode 100644 index 0000000000000..b21dfdbc83f63 --- /dev/null +++ b/client/cli/src/commands/sign.rs @@ -0,0 +1,57 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Implementation of the `sign` subcommand +use crate::error; +use super::{SharedParams, RunCmd, get_password, read_message_from_stdin, read_uri, Crypto}; +use structopt::StructOpt; + +use sp_core::crypto::Pair; + +#[derive(Debug, StructOpt, Clone)] +#[structopt( + name = "sign", + about = "Sign a message, provided on STDIN, with a given (secret) key" +)] +pub struct SignCmd { + /// The secret key URI. + /// If the value is a file, the file content is used as URI. + /// If not given, you will be prompted for the URI. + #[structopt(long)] + suri: Option, + + /// The message on STDIN is hex-encoded data + #[structopt(long)] + hex: bool, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + + +impl SignCmd { + pub fn run(self, _run_cmd: RunCmd) -> error::Result<()> { + let suri = read_uri(self.suri)?; + + let message = read_message_from_stdin(self.hex)?; + let password = get_password(&self.shared_params)?; + let pair = C::pair_from_suri(&suri, Some(password.as_str())); + let signature = format!("{}", hex::encode(pair.sign(&message))); + println!("{}", signature); + Ok(()) + } +} diff --git a/client/cli/src/commands/sign_transaction.rs b/client/cli/src/commands/sign_transaction.rs new file mode 100644 index 0000000000000..dc4e1da159fcc --- /dev/null +++ b/client/cli/src/commands/sign_transaction.rs @@ -0,0 +1,72 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Implementation of the `sign-transaction` subcommand +use crate::error; +use super::{ + SharedParams, get_password, decode_hex, + create_extrinsic_for, Crypto, IndexFor, CallFor, +}; +use structopt::StructOpt; + +use parity_scale_codec::{Decode, Encode, WrapperTypeEncode}; +use std::str::FromStr; + +type Call = Vec; + +#[derive(Debug, StructOpt, Clone)] +#[structopt( + name = "sign-transaction", + about = "Sign transaction from encoded Call. Returns a signed and encoded UncheckedMortalCompactExtrinsic as hex." +)] +pub struct SignTransactionCmd { + /// The secret key URI. + #[structopt(long)] + suri: String, + + /// The nonce. + #[structopt(long)] + nonce: String, + + /// The call, hex-encoded. + #[structopt(long, parse(try_from_str = decode_hex))] + call: Call, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + +impl SignTransactionCmd { + pub fn run(self) -> error::Result<()> + where + as FromStr>::Err: Into, + CallFor: Encode + Decode + WrapperTypeEncode, + { + let signer = C::pair_from_suri( + &self.suri, + Some(get_password(&self.shared_params)?.as_str()), + ); + + let index = IndexFor::::from_str(&self.nonce).map_err(|e| e.into())?; + let function = CallFor::::decode(&mut &self.call[..])?; + let extrinsic = create_extrinsic_for::(function, index, signer)?; + + println!("0x{}", hex::encode(Encode::encode(&extrinsic))); + + Ok(()) + } +} diff --git a/client/cli/src/commands/transfer.rs b/client/cli/src/commands/transfer.rs new file mode 100644 index 0000000000000..5b0c9a200174f --- /dev/null +++ b/client/cli/src/commands/transfer.rs @@ -0,0 +1,85 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + + +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Implementation of the `sign` subcommand +use crate::error; +use super::{SharedParams, RunCmd, Crypto}; +use structopt::StructOpt; + + +#[derive(Debug, StructOpt, Clone)] +#[structopt( + name = "transfer", + about = "Author and sign a Node pallet_balances::Transfer transaction with a given (secret) key" +)] +pub struct TransferCmd { + /// The secret key URI. + /// If the value is a file, the file content is used as URI. + /// If not given, you will be prompted for the URI. + #[structopt(long)] + amount: Option, + + // #[structopt(long)] + // amount: Option, + // + // #[structopt(long)] + // amount: Option, + // + // #[structopt(long)] + // amount: Option, + + /// The message on STDIN is hex-encoded data + #[structopt(long)] + hex: bool, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + + +impl TransferCmd { + pub fn run(self, _run_cmd: RunCmd) -> error::Result<()> { + // let signer = read_pair::(matches.value_of("from"), password)?; + // let index = read_required_parameter::>(matches, "index")?; + // + // let to: AccountId = read_account_id(matches.value_of("to")); + // let amount = read_required_parameter::(matches, "amount")?; + // let function = Call::Balances(BalancesCall::transfer(to.into(), amount)); + // + // let extrinsic = create_extrinsic::(function, index, signer, genesis_hash); + // + // print_extrinsic(extrinsic); + unimplemented!() + } +} diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs new file mode 100644 index 0000000000000..65964526fce05 --- /dev/null +++ b/client/cli/src/commands/utils.rs @@ -0,0 +1,261 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! subcommand utilities +use std::{io::Read, path::PathBuf}; +use sp_core::{Pair, Public, crypto::{Ss58Codec, Ss58AddressFormat}, hexdisplay::HexDisplay}; +use sp_runtime::{ + MultiSignature, MultiSigner, + generic::{UncheckedExtrinsic, SignedPayload}, + traits::IdentifyAccount, +}; +use parity_scale_codec::{Encode, WrapperTypeEncode}; +use serde_json::json; +use sp_runtime::traits::SignedExtension; +use pallet_indices::address; +use crate::{error::{self, Error}, SharedParams, arg_enums::OutputType}; + +/// Signature type for Crypto +pub type SignatureFor = <::Pair as Pair>::Signature; +/// Public key type for Crypto +pub type PublicFor = <::Pair as Pair>::Public; +/// Seed type for Crypto +pub type SeedFor = <::Pair as Pair>::Seed; +/// AccountIndex type for Crypto +pub type IndexFor = <::Runtime as frame_system::Trait>::Index; +/// Address type for Crypto +pub type AddressOf = address::Address< + <::Runtime as frame_system::Trait>::AccountId, + <::Runtime as pallet_indices::Trait>::AccountIndex +>; +/// Call type for Crypto +pub type CallFor = <::Runtime as frame_system::Trait>::Call; + +/// Runtime adapter for signing utilities +pub trait Crypto: Sized { + /// Pair type + type Pair: Pair; + /// public type + type Public: Public + Into + Ss58Codec + AsRef<[u8]> + std::hash::Hash; + /// sugnature type + type Signature: Into + AsRef<[u8]> + Encode; + /// runtime + type Runtime: frame_system::Trait + pallet_balances::Trait + pallet_indices::Trait; + /// extras + type Extra: SignedExtension; + + /// generate a pair from suri + fn pair_from_suri(suri: &str, password: Option<&str>) -> Self::Pair { + Self::Pair::from_string(suri, password).expect("Invalid phrase") + } + + /// generate an ss58 encoded address from pair + fn ss58_from_pair(pair: &Self::Pair) -> String { + pair.public().into().into_account().to_ss58check() + } + + /// print formatted pair from uri + fn print_from_uri( + uri: &str, + password: Option<&str>, + network_override: Option, + output: OutputType, + ) { + if let Ok((pair, seed)) = Self::Pair::from_phrase(uri, password) { + let public_key = pair.public(); + + match output { + OutputType::Json => { + let json = json!({ + "secretPhrase": uri, + "secretSeed": format_seed::(seed), + "publicKey": format_public_key::(public_key.clone()), + "accountId": format_account_id::(public_key), + "ss58Address": Self::ss58_from_pair(&pair), + }); + println!("{}", serde_json::to_string_pretty(&json).expect("Json pretty print failed")); + }, + OutputType::Text => { + println!("Secret phrase `{}` is account:\n \ + Secret seed: {}\n \ + Public key (hex): {}\n \ + Account ID: {}\n \ + SS58 Address: {}", + uri, + format_seed::(seed), + format_public_key::(public_key.clone()), + format_account_id::(public_key), + Self::ss58_from_pair(&pair), + ); + }, + } + } else if let Ok((pair, seed)) = Self::Pair::from_string_with_seed(uri, password) { + let public_key = pair.public(); + + match output { + OutputType::Json => { + let json = json!({ + "secretKeyUri": uri, + "secretSeed": if let Some(seed) = seed { format_seed::(seed) } else { "n/a".into() }, + "publicKey": format_public_key::(public_key.clone()), + "accountId": format_account_id::(public_key), + "ss58Address": Self::ss58_from_pair(&pair), + }); + println!("{}", serde_json::to_string_pretty(&json).expect("Json pretty print failed")); + }, + OutputType::Text => { + println!("Secret Key URI `{}` is account:\n \ + Secret seed: {}\n \ + Public key (hex): {}\n \ + Account ID: {}\n \ + SS58 Address: {}", + uri, + if let Some(seed) = seed { format_seed::(seed) } else { "n/a".into() }, + format_public_key::(public_key.clone()), + format_account_id::(public_key), + Self::ss58_from_pair(&pair), + ); + }, + } + + } else if let Ok((public_key, v)) = + ::Public::from_string_with_version(uri) + { + let v = network_override.unwrap_or(v); + + match output { + OutputType::Json => { + let json = json!({ + "publicKeyUri": uri, + "networkId": String::from(v), + "publicKey": format_public_key::(public_key.clone()), + "accountId": format_account_id::(public_key.clone()), + "ss58Address": public_key.to_ss58check_with_version(v), + }); + println!("{}", serde_json::to_string_pretty(&json).expect("Json pretty print failed")); + }, + OutputType::Text => { + println!("Public Key URI `{}` is account:\n \ + Network ID/version: {}\n \ + Public key (hex): {}\n \ + Account ID: {}\n \ + SS58 Address: {}", + uri, + String::from(v), + format_public_key::(public_key.clone()), + format_account_id::(public_key.clone()), + public_key.to_ss58check_with_version(v), + ); + }, + } + } else { + println!("Invalid phrase/URI given"); + } + } + + /// build extras for inclusion in extrinsics + fn build_extra(index: IndexFor) -> Self::Extra; +} + +/// helper method to fetch password from `SharedParams` or read from stdin +pub fn get_password(run_cmd: &SharedParams) -> error::Result { + let (password_interactive, password) = (run_cmd.password_interactive, run_cmd.password.as_ref()); + + let pass = if password_interactive { + rpassword::read_password_from_tty(Some("Key password: "))? + } else { + password.map(Into::into).expect("") + }; + + Ok(pass) +} + +/// helper method to fetch uri from `Option` either as a file or read from stdin +pub fn read_uri(uri: Option) -> error::Result { + let uri = if let Some(uri) = uri { + let file = PathBuf::from(uri.clone()); + if file.is_file() { + std::fs::read_to_string(uri)? + .trim_end() + .to_owned() + } else { + uri.into() + } + } else { + rpassword::read_password_from_tty(Some("URI: "))? + }; + + Ok(uri) +} + +/// formats seed as hex +fn format_seed(seed: SeedFor) -> String { + format!("0x{}", HexDisplay::from(&seed.as_ref())) +} + +/// formats public key as hex +fn format_public_key(public_key: PublicFor) -> String { + format!("0x{}", HexDisplay::from(&public_key.as_ref())) +} + +/// formats public key as accountId as hex +fn format_account_id(public_key: PublicFor) -> String { + format!("0x{}", HexDisplay::from(&public_key.into().into_account().as_ref())) +} + +/// decode hex +pub fn decode_hex>(message: T) -> Result, Error> { + hex::decode(message) + .map_err(|e| Error::Other(format!("Invalid hex ({})", e))) +} + +/// reads input from stdin, optionally decodes hex to bytes. +pub fn read_message_from_stdin(should_decode: bool) -> Result, Error> { + let mut message = vec![]; + std::io::stdin().lock().read_to_end(&mut message)?; + if should_decode { + message = decode_hex(&message)?; + } + Ok(message) +} + +/// create an extrinsic for the runtime. +pub fn create_extrinsic_for( + call: CallFor, + index: IndexFor, + signer: C::Pair, +) -> Result, CallFor, C::Signature, C::Extra>, Error> + where + CallFor: Encode + WrapperTypeEncode, +{ + let extra = C::build_extra(index); + let additional_signed = extra.additional_signed() + .map_err(|_| Error::Other("Transaction validity error".into()))?; + let raw_payload = SignedPayload::from_raw(call, extra, additional_signed); + + let _signature = raw_payload.using_encoded(|payload| signer.sign(payload)); + let _signer = signer.public().into(); + let (_function, _extra, _) = raw_payload.deconstruct(); + + unimplemented!() + + // Ok(UncheckedExtrinsic::new_signed( + // function, + // signer.into_account().into(), + // signature, + // extra, + // )) +} diff --git a/client/cli/src/commands/verify.rs b/client/cli/src/commands/verify.rs new file mode 100644 index 0000000000000..7c0a48726e2af --- /dev/null +++ b/client/cli/src/commands/verify.rs @@ -0,0 +1,17 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! verify subcommand \ No newline at end of file diff --git a/client/cli/src/error.rs b/client/cli/src/error.rs index edc1adecc762c..a0af0a145f570 100644 --- a/client/cli/src/error.rs +++ b/client/cli/src/error.rs @@ -16,6 +16,8 @@ //! Initialization errors. + + /// Result type alias for the CLI. pub type Result = std::result::Result; @@ -30,6 +32,8 @@ pub enum Error { Service(sc_service::Error), /// Client error Client(sp_blockchain::Error), + /// scale codec error + Codec(parity_scale_codec::Error), /// Input error #[from(ignore)] Input(String), @@ -62,6 +66,7 @@ impl std::error::Error for Error { Error::Cli(ref err) => Some(err), Error::Service(ref err) => Some(err), Error::Client(ref err) => Some(err), + Error::Codec(ref err) => Some(err), Error::Input(_) => None, Error::InvalidListenMultiaddress => None, Error::Other(_) => None, diff --git a/client/cli/src/params/mod.rs b/client/cli/src/params/mod.rs index f684cab336423..c970c9feddb04 100644 --- a/client/cli/src/params/mod.rs +++ b/client/cli/src/params/mod.rs @@ -56,9 +56,9 @@ impl BlockNumber { /// See `https://doc.rust-lang.org/std/primitive.str.html#method.parse` for more elaborate /// documentation. pub fn parse(&self) -> Result - where - N: FromStr, - N::Err: std::fmt::Debug, + where + N: FromStr, + N::Err: std::fmt::Debug, { self.0 .parse() diff --git a/client/cli/src/params/shared_params.rs b/client/cli/src/params/shared_params.rs index 03f44796460a2..3ac168182a268 100644 --- a/client/cli/src/params/shared_params.rs +++ b/client/cli/src/params/shared_params.rs @@ -21,9 +21,9 @@ use sc_service::{ Configuration, ChainSpecExtension, RuntimeGenesis, config::DatabaseConfig, ChainSpec, }; - -use crate::VersionInfo; -use crate::error; +use sp_core::crypto::Ss58AddressFormat; +use std::convert::TryFrom; +use crate::{error, VersionInfo, arg_enums::OutputType}; /// default sub directory to store database const DEFAULT_DB_CONFIG_PATH : &'static str = "db"; @@ -46,6 +46,50 @@ pub struct SharedParams { /// Sets a custom logging filter. #[structopt(short = "l", long = "log", value_name = "LOG_PATTERN")] pub log: Option, + + /// Use interactive shell for entering the password used by the keystore. + #[structopt( + long = "password-interactive", + conflicts_with_all = &[ "password", "password-filename" ] + )] + pub password_interactive: bool, + + /// Password used by the keystore. + #[structopt( + long = "password", + conflicts_with_all = &[ "password-interactive", "password-filename" ] + )] + pub password: Option, + + /// File that contains the password used by the keystore. + #[structopt( + long = "password-filename", + value_name = "PATH", + parse(from_os_str), + conflicts_with_all = &[ "password-interactive", "password" ] + )] + pub password_filename: Option, + + /// network address format + #[structopt( + long, + value_name = "NETWORK", + possible_values = &Ss58AddressFormat::all_names()[..], + parse(try_from_str = Ss58AddressFormat::try_from), + case_insensitive = true, + default_value = "polkadot" + )] + pub network: Ss58AddressFormat, + + /// output format + #[structopt( + long, + value_name = "FORMAT", + possible_values = &OutputType::variants(), + case_insensitive = true, + default_value = "Text" + )] + pub output_type: OutputType, } impl SharedParams { diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index bd9e61b51abe3..87e02e7f832dc 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -108,6 +108,7 @@ use sp_runtime::{ self, CheckEqual, AtLeast32Bit, Zero, SignedExtension, Lookup, LookupError, SimpleBitOps, Hash, Member, MaybeDisplay, EnsureOrigin, BadOrigin, SaturatedConversion, MaybeSerialize, MaybeSerializeDeserialize, MaybeMallocSizeOf, StaticLookup, One, Bounded, + MaybeFromStr, }, }; @@ -150,7 +151,7 @@ pub trait Trait: 'static + Eq + Clone { /// Account index (aka nonce) type. This stores the number of previous transactions associated /// with a sender account. type Index: - Parameter + Member + MaybeSerialize + Debug + Default + MaybeDisplay + AtLeast32Bit + Parameter + Member + MaybeSerialize + MaybeFromStr + Debug + Default + MaybeDisplay + AtLeast32Bit + Copy; /// The block number type used by the runtime. diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 50f5c94b08af6..3c8393894518b 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -352,7 +352,7 @@ lazy_static::lazy_static! { macro_rules! ss58_address_format { ( $( $identifier:tt => ($number:expr, $name:expr, $desc:tt) )* ) => ( /// A known address (sub)format/network ID for SS58. - #[derive(Copy, Clone, PartialEq, Eq)] + #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum Ss58AddressFormat { $(#[doc = $desc] $identifier),*, /// Use a manually provided numeric value. @@ -364,6 +364,12 @@ macro_rules! ss58_address_format { ]; impl Ss58AddressFormat { + /// names of all address formats + pub fn all_names() -> Vec<&'static str> { + vec![ + $($name),*, + ] + } /// All known address formats. pub fn all() -> &'static [Ss58AddressFormat] { &ALL_SS58_ADDRESS_FORMATS @@ -399,12 +405,13 @@ macro_rules! ss58_address_format { } impl<'a> TryFrom<&'a str> for Ss58AddressFormat { - type Error = (); + type Error = String; - fn try_from(x: &'a str) -> Result { + fn try_from(x: &'a str) -> Result { match x { $($name => Ok(Ss58AddressFormat::$identifier)),*, - a => a.parse::().map(Ss58AddressFormat::Custom).map_err(|_| ()), + a => a.parse::().map(Ss58AddressFormat::Custom) + .map_err(|e| format!("failed to parse network value as u8 {:?}", e)), } } } From 0a1df9c6ad4db5842ea2c3ed474337e4ae8cae1c Mon Sep 17 00:00:00 2001 From: Seun Date: Wed, 11 Mar 2020 15:18:09 +0100 Subject: [PATCH 04/77] all that remains is tests --- Cargo.lock | 6 + client/cli/Cargo.toml | 6 + client/cli/src/commands/generate.rs | 6 +- client/cli/src/commands/insert.rs | 97 +++++++++ client/cli/src/commands/inspect.rs | 14 +- client/cli/src/commands/mod.rs | 2 + client/cli/src/commands/sign.rs | 6 +- client/cli/src/commands/sign_transaction.rs | 21 +- client/cli/src/commands/transfer.rs | 70 ++++--- client/cli/src/commands/utils.rs | 103 +++++----- client/cli/src/commands/vanity.rs | 207 ++++++++++++++++++++ client/cli/src/commands/verify.rs | 66 ++++++- frame/balances/src/lib.rs | 6 +- 13 files changed, 495 insertions(+), 115 deletions(-) create mode 100644 client/cli/src/commands/insert.rs create mode 100644 client/cli/src/commands/vanity.rs diff --git a/Cargo.lock b/Cargo.lock index 5652280a1bff4..acdacfa2f525f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6142,9 +6142,12 @@ dependencies = [ "env_logger 0.7.1", "fdlimit", "frame-system", + "futures 0.1.29", "futures 0.3.4", "hex", "hex-literal", + "hyper 0.12.35", + "jsonrpc-core-client", "lazy_static", "libp2p 0.15.0", "log 0.4.8", @@ -6154,14 +6157,17 @@ dependencies = [ "pallet-transaction-payment", "parity-scale-codec", "parity-util-mem", + "rand 0.7.3", "regex", "rpassword", "sc-client-api", "sc-informant", "sc-network", + "sc-rpc", "sc-service", "sc-telemetry", "sc-tracing", + "serde", "serde_json", "sp-blockchain", "sp-core", diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 691cfd5c20bcd..0f838dfa17c71 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -44,6 +44,12 @@ substrate-prometheus-endpoint = { path = "../../utils/prometheus" , version = "0 sp-keyring = { version = "2.0.0-alpha.2", path = "../../primitives/keyring" } names = "0.11.0" structopt = "0.3.11" +hyper = "0.12.35" +rand = "0.7.2" +serde = "1.0.104" +futures01 = { package = "futures", version = "0.1.29" } +sc-rpc = { version = "2.0.0-alpha.3", path = "../../client/rpc" } +jsonrpc-core-client = { version = "14.0.3", features = ["http"] } sc-tracing = { version = "2.0.0-alpha.2", path = "../tracing" } chrono = "0.4.10" parity-util-mem = { version = "0.5.1", default-features = false, features = ["primitive-types"] } diff --git a/client/cli/src/commands/generate.rs b/client/cli/src/commands/generate.rs index a0880e67d5608..a102d092ccba5 100644 --- a/client/cli/src/commands/generate.rs +++ b/client/cli/src/commands/generate.rs @@ -16,7 +16,7 @@ //! Implementation of the `generate` subcommand -use super::{SharedParams, Crypto, get_password}; +use super::{SharedParams, RuntimeAdapter, get_password}; use crate::error::{self, Error}; use bip39::{MnemonicType, Mnemonic, Language}; use structopt::StructOpt; @@ -36,7 +36,7 @@ pub struct GenerateCmd { impl GenerateCmd { /// Run the command - pub fn run(self) -> error::Result<()> { + pub fn run(self) -> error::Result<()> { let words = match self.words { Some(words) => { MnemonicType::for_word_count(words) @@ -54,7 +54,7 @@ impl GenerateCmd { C::print_from_uri( mnemonic.phrase(), Some(password.as_str()), - Some(maybe_network), + maybe_network, output ); diff --git a/client/cli/src/commands/insert.rs b/client/cli/src/commands/insert.rs new file mode 100644 index 0000000000000..21f52cee3abb0 --- /dev/null +++ b/client/cli/src/commands/insert.rs @@ -0,0 +1,97 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Implementation of the `insert` subcommand + +use crate::{error, HashFor}; +use super::{SharedParams, RunCmd, get_password, read_uri, RuntimeAdapter}; +use structopt::StructOpt; +use sp_core::{crypto::{KeyTypeId, Pair}, Bytes}; +use std::convert::TryFrom; +use futures01::Future; +use hyper::rt; +use sc_rpc::author::AuthorClient; +use jsonrpc_core_client::transports::http; +use serde::{de::DeserializeOwned, Serialize}; + +#[derive(Debug, StructOpt, Clone)] +#[structopt( + name = "insert", + about = "Insert a key to the keystore of a node." +)] +pub struct InsertCmd { + /// The secret key URI. + /// If the value is a file, the file content is used as URI. + /// If not given, you will be prompted for the URI. + #[structopt(long)] + suri: Option, + + /// Key type, examples: "gran", or "imon" + #[structopt(long)] + key_type: String, + + /// Node JSON-RPC endpoint, default "http://localhost:9933" + #[structopt(long)] + node_url: Option, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + +impl InsertCmd { + pub fn run(self) -> error::Result<()> + where + HashFor: DeserializeOwned + Serialize + Send + Sync, + { + let suri = read_uri(self.suri)?; + let password = get_password(&self.shared_params)?; + let pair = C::pair_from_suri(&suri, &password); + let node_url = self.node_url.unwrap_or("http://localhost:9933".into()); + let key_type = self.key_type; + + // Just checking + let _key_type_id = KeyTypeId::try_from(key_type.as_str()) + .map_err(|_| { + error::Error::Other("Cannot convert argument to keytype: argument should be 4-character string".into()) + })?; + + + insert_key::>( + &node_url, + key_type.to_string(), + suri, + sp_core::Bytes(pair.public().as_ref().to_vec()), + ); + + Ok(()) + } +} + +fn insert_key(url: &str, key_type: String, suri: String, public: Bytes) + where + H: DeserializeOwned + Serialize + Send + Sync + 'static, +{ + rt::run( + http::connect(&url) + .and_then(|client: AuthorClient| { + client.insert_key(key_type, suri, public).map(|_| ()) + }) + .map_err(|e| { + println!("Error inserting key: {:?}", e); + }) + ); +} diff --git a/client/cli/src/commands/inspect.rs b/client/cli/src/commands/inspect.rs index ac0167e546c03..d61eb186cd7cc 100644 --- a/client/cli/src/commands/inspect.rs +++ b/client/cli/src/commands/inspect.rs @@ -16,12 +16,10 @@ //! Implementation of the `inspect` subcommand -use crate::{error, arg_enums::OutputType}; -use super::{SharedParams, RunCmd, get_password, read_uri, Crypto}; +use crate::error; +use super::{SharedParams, RunCmd, get_password, read_uri, RuntimeAdapter}; use structopt::StructOpt; - - #[derive(Debug, StructOpt, Clone)] #[structopt( name = "inspect", @@ -34,24 +32,20 @@ pub struct InspectCmd { #[structopt(long)] uri: Option, - output_type: OutputType, - - network: String, - #[allow(missing_docs)] #[structopt(flatten)] pub shared_params: SharedParams, } impl InspectCmd { - pub fn run(self, _run_cmd: RunCmd) -> error::Result<()> { + pub fn run(self) -> error::Result<()> { let uri = read_uri(self.uri)?; let pass = get_password(&self.shared_params)?; C::print_from_uri( &uri, Some(pass.as_str()), - Some(self.shared_params.network), + self.shared_params.network, self.shared_params.output_type ); diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index fd69d31a75577..60d202373f7c0 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -29,6 +29,8 @@ mod sign_transaction; mod utils; mod transfer; mod verify; +mod vanity; +mod insert; use std::fmt::Debug; use structopt::StructOpt; diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs index b21dfdbc83f63..828a8da48fcf4 100644 --- a/client/cli/src/commands/sign.rs +++ b/client/cli/src/commands/sign.rs @@ -16,7 +16,7 @@ //! Implementation of the `sign` subcommand use crate::error; -use super::{SharedParams, RunCmd, get_password, read_message_from_stdin, read_uri, Crypto}; +use super::{SharedParams, get_password, read_message_from_stdin, read_uri, RuntimeAdapter}; use structopt::StructOpt; use sp_core::crypto::Pair; @@ -44,12 +44,12 @@ pub struct SignCmd { impl SignCmd { - pub fn run(self, _run_cmd: RunCmd) -> error::Result<()> { + pub fn run(self) -> error::Result<()> { let suri = read_uri(self.suri)?; let message = read_message_from_stdin(self.hex)?; let password = get_password(&self.shared_params)?; - let pair = C::pair_from_suri(&suri, Some(password.as_str())); + let pair = C::pair_from_suri(&suri, &password); let signature = format!("{}", hex::encode(pair.sign(&message))); println!("{}", signature); Ok(()) diff --git a/client/cli/src/commands/sign_transaction.rs b/client/cli/src/commands/sign_transaction.rs index dc4e1da159fcc..551d1821155b9 100644 --- a/client/cli/src/commands/sign_transaction.rs +++ b/client/cli/src/commands/sign_transaction.rs @@ -18,12 +18,12 @@ use crate::error; use super::{ SharedParams, get_password, decode_hex, - create_extrinsic_for, Crypto, IndexFor, CallFor, + create_extrinsic_for, RuntimeAdapter, IndexFor, CallFor, }; use structopt::StructOpt; - use parity_scale_codec::{Decode, Encode, WrapperTypeEncode}; use std::str::FromStr; +use std::fmt::Display; type Call = Vec; @@ -51,19 +51,16 @@ pub struct SignTransactionCmd { } impl SignTransactionCmd { - pub fn run(self) -> error::Result<()> + pub fn run(self) -> error::Result<()> where - as FromStr>::Err: Into, - CallFor: Encode + Decode + WrapperTypeEncode, + as FromStr>::Err: Display, + CallFor: Encode + Decode + WrapperTypeEncode, { - let signer = C::pair_from_suri( - &self.suri, - Some(get_password(&self.shared_params)?.as_str()), - ); + let signer = RA::pair_from_suri(&self.suri, &get_password(&self.shared_params)?); - let index = IndexFor::::from_str(&self.nonce).map_err(|e| e.into())?; - let function = CallFor::::decode(&mut &self.call[..])?; - let extrinsic = create_extrinsic_for::(function, index, signer)?; + let nonce = IndexFor::::from_str(&self.nonce).map_err(|e| format!("{}", e))?; + let call = CallFor::::decode(&mut &self.call[..])?; + let extrinsic = create_extrinsic_for::(call, nonce, signer)?; println!("0x{}", hex::encode(Encode::encode(&extrinsic))); diff --git a/client/cli/src/commands/transfer.rs b/client/cli/src/commands/transfer.rs index 5b0c9a200174f..22e0e4ec3a027 100644 --- a/client/cli/src/commands/transfer.rs +++ b/client/cli/src/commands/transfer.rs @@ -32,10 +32,13 @@ // along with Substrate. If not, see . //! Implementation of the `sign` subcommand -use crate::error; -use super::{SharedParams, RunCmd, Crypto}; +use crate::{error, IndexFor, BalanceFor, create_extrinsic_for, get_password, AddressFor}; +use super::{SharedParams, RuntimeAdapter}; use structopt::StructOpt; - +use pallet_balances::Call as BalancesCall; +use std::str::FromStr; +use parity_scale_codec::Encode; +use std::fmt::Display; #[derive(Debug, StructOpt, Clone)] #[structopt( @@ -43,24 +46,21 @@ use structopt::StructOpt; about = "Author and sign a Node pallet_balances::Transfer transaction with a given (secret) key" )] pub struct TransferCmd { - /// The secret key URI. - /// If the value is a file, the file content is used as URI. - /// If not given, you will be prompted for the URI. + /// The number of units to transfer. + #[structopt(long)] + amount: String, + + /// The signing secret key URI. #[structopt(long)] - amount: Option, - - // #[structopt(long)] - // amount: Option, - // - // #[structopt(long)] - // amount: Option, - // - // #[structopt(long)] - // amount: Option, - - /// The message on STDIN is hex-encoded data + from: String, + + /// The signing account's transaction index. + #[structopt(long)] + index: String, + + /// The destination account public key URI. #[structopt(long)] - hex: bool, + to: String, #[allow(missing_docs)] #[structopt(flatten)] @@ -69,17 +69,25 @@ pub struct TransferCmd { impl TransferCmd { - pub fn run(self, _run_cmd: RunCmd) -> error::Result<()> { - // let signer = read_pair::(matches.value_of("from"), password)?; - // let index = read_required_parameter::>(matches, "index")?; - // - // let to: AccountId = read_account_id(matches.value_of("to")); - // let amount = read_required_parameter::(matches, "amount")?; - // let function = Call::Balances(BalancesCall::transfer(to.into(), amount)); - // - // let extrinsic = create_extrinsic::(function, index, signer, genesis_hash); - // - // print_extrinsic(extrinsic); - unimplemented!() + pub fn run(self) -> error::Result<()> + where + AddressFor: FromStr, + as FromStr>::Err: Display, + as FromStr>::Err: Display, + as FromStr>::Err: Display, + BalancesCall: Encode, + { + let password = get_password(&self.shared_params)?; + let nonce = IndexFor::::from_str(&self.index).map_err(|e| format!("{}", e))?; + let to = AddressFor::::from_str(&self.to).map_err(|e| format!("{}", e))?; + let amount = BalanceFor::::from_str(&self.amount).map_err(|e| format!("{}", e))?; + + let signer = RA::pair_from_suri(&self.from, &password); + let call = BalancesCall::transfer(to.into(), amount); + + let extrinsic = create_extrinsic_for::(call, nonce, signer)?; + println!("0x{}", hex::encode(Encode::encode(&extrinsic))); + + Ok(()) } } diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 65964526fce05..3a0e6bad89fd3 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -22,56 +22,57 @@ use sp_runtime::{ generic::{UncheckedExtrinsic, SignedPayload}, traits::IdentifyAccount, }; -use parity_scale_codec::{Encode, WrapperTypeEncode}; +use parity_scale_codec::{Encode, Decode}; use serde_json::json; -use sp_runtime::traits::SignedExtension; -use pallet_indices::address; +use sp_runtime::traits::{SignedExtension, StaticLookup}; use crate::{error::{self, Error}, SharedParams, arg_enums::OutputType}; -/// Signature type for Crypto -pub type SignatureFor = <::Pair as Pair>::Signature; -/// Public key type for Crypto -pub type PublicFor = <::Pair as Pair>::Public; -/// Seed type for Crypto -pub type SeedFor = <::Pair as Pair>::Seed; -/// AccountIndex type for Crypto -pub type IndexFor = <::Runtime as frame_system::Trait>::Index; -/// Address type for Crypto -pub type AddressOf = address::Address< - <::Runtime as frame_system::Trait>::AccountId, - <::Runtime as pallet_indices::Trait>::AccountIndex ->; -/// Call type for Crypto -pub type CallFor = <::Runtime as frame_system::Trait>::Call; +/// Public key type for Runtime +pub type PublicFor = <::Pair as Pair>::Public; +/// Seed type for Runtime +pub type SeedFor = <::Pair as Pair>::Seed; +/// AccountIndex type for Runtime +pub type IndexFor = <::Runtime as frame_system::Trait>::Index; +/// Balance type +pub type BalanceFor = <::Runtime as pallet_balances::Trait>::Balance; +/// Call type for Runtime +pub type CallFor = <::Runtime as frame_system::Trait>::Call; +/// Address type for runtime. +pub type AddressFor = <<::Runtime as frame_system::Trait>::Lookup as StaticLookup>::Source; +/// Hash for runtime. +pub type HashFor = <::Runtime as frame_system::Trait>::Hash; /// Runtime adapter for signing utilities -pub trait Crypto: Sized { +pub trait RuntimeAdapter: Sized { /// Pair type type Pair: Pair; /// public type type Public: Public + Into + Ss58Codec + AsRef<[u8]> + std::hash::Hash; /// sugnature type - type Signature: Into + AsRef<[u8]> + Encode; + type Signature: Into + AsRef<[u8]> + AsMut<[u8]> + Encode + Default; /// runtime type Runtime: frame_system::Trait + pallet_balances::Trait + pallet_indices::Trait; /// extras type Extra: SignedExtension; + /// Address type + type Address: Encode + Decode + From; /// generate a pair from suri - fn pair_from_suri(suri: &str, password: Option<&str>) -> Self::Pair { - Self::Pair::from_string(suri, password).expect("Invalid phrase") + fn pair_from_suri(suri: &str, password: &str) -> Self::Pair { + Self::Pair::from_string(suri, Some(password)).expect("Invalid phrase") } /// generate an ss58 encoded address from pair fn ss58_from_pair(pair: &Self::Pair) -> String { - pair.public().into().into_account().to_ss58check() + let public: MultiSigner = pair.public().into(); + public.into_account().to_ss58check() } /// print formatted pair from uri fn print_from_uri( uri: &str, password: Option<&str>, - network_override: Option, + network_override: Ss58AddressFormat, output: OutputType, ) { if let Ok((pair, seed)) = Self::Pair::from_phrase(uri, password) { @@ -131,10 +132,10 @@ pub trait Crypto: Sized { }, } - } else if let Ok((public_key, v)) = + } else if let Ok((public_key, _v)) = ::Public::from_string_with_version(uri) { - let v = network_override.unwrap_or(v); + let v = network_override; match output { OutputType::Json => { @@ -171,8 +172,8 @@ pub trait Crypto: Sized { } /// helper method to fetch password from `SharedParams` or read from stdin -pub fn get_password(run_cmd: &SharedParams) -> error::Result { - let (password_interactive, password) = (run_cmd.password_interactive, run_cmd.password.as_ref()); +pub fn get_password(params: &SharedParams) -> error::Result { + let (password_interactive, password) = (params.password_interactive, params.password.as_ref()); let pass = if password_interactive { rpassword::read_password_from_tty(Some("Key password: "))? @@ -202,21 +203,21 @@ pub fn read_uri(uri: Option) -> error::Result { } /// formats seed as hex -fn format_seed(seed: SeedFor) -> String { +pub fn format_seed(seed: SeedFor) -> String { format!("0x{}", HexDisplay::from(&seed.as_ref())) } /// formats public key as hex -fn format_public_key(public_key: PublicFor) -> String { +fn format_public_key(public_key: PublicFor) -> String { format!("0x{}", HexDisplay::from(&public_key.as_ref())) } /// formats public key as accountId as hex -fn format_account_id(public_key: PublicFor) -> String { +fn format_account_id(public_key: PublicFor) -> String { format!("0x{}", HexDisplay::from(&public_key.into().into_account().as_ref())) } -/// decode hex +/// helper method for decoding hex pub fn decode_hex>(message: T) -> Result, Error> { hex::decode(message) .map_err(|e| Error::Other(format!("Invalid hex ({})", e))) @@ -233,29 +234,27 @@ pub fn read_message_from_stdin(should_decode: bool) -> Result, Error> { } /// create an extrinsic for the runtime. -pub fn create_extrinsic_for( - call: CallFor, - index: IndexFor, - signer: C::Pair, -) -> Result, CallFor, C::Signature, C::Extra>, Error> +pub fn create_extrinsic_for( + call: Call, + nonce: IndexFor, + signer: RA::Pair, +) -> Result, Error> where - CallFor: Encode + WrapperTypeEncode, + Call: Encode, { - let extra = C::build_extra(index); - let additional_signed = extra.additional_signed() + let extra = RA::build_extra(nonce); + let payload = SignedPayload::new(call, extra) .map_err(|_| Error::Other("Transaction validity error".into()))?; - let raw_payload = SignedPayload::from_raw(call, extra, additional_signed); - let _signature = raw_payload.using_encoded(|payload| signer.sign(payload)); - let _signer = signer.public().into(); - let (_function, _extra, _) = raw_payload.deconstruct(); + let signature = payload.using_encoded(|payload| signer.sign(payload)); + let signer = RA::Address::from(signer.public()); + let (function, extra, _) = payload.deconstruct(); - unimplemented!() - - // Ok(UncheckedExtrinsic::new_signed( - // function, - // signer.into_account().into(), - // signature, - // extra, - // )) + Ok(UncheckedExtrinsic::new_signed( + function, + signer, + signature, + extra, + )) } + diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs new file mode 100644 index 0000000000000..b28dae7ba2d72 --- /dev/null +++ b/client/cli/src/commands/vanity.rs @@ -0,0 +1,207 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! implementation of the `verify` subcommand +use crate::{RuntimeAdapter, read_message_from_stdin, decode_hex, read_uri, error, format_seed, SharedParams}; +use sp_core::{Pair, Public, crypto::Ss58Codec}; +use structopt::StructOpt; +use rand::{rngs::OsRng, RngCore}; + + +#[derive(Debug, StructOpt, Clone)] +#[structopt( + name = "vanity", + about = "Generate a seed that provides a vanity address" +)] +pub struct VanityCmd { + /// Number of keys to generate + #[structopt(long, short)] + number: String, + + /// Desired pattern + #[structopt(long)] + pattern: Option, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + +impl VanityCmd { + pub fn run(self) -> error::Result<()> { + let desired: String = self.pattern.unwrap_or_default(); + let result = generate_key::(&desired)?; + let formated_seed = format_seed::(result.seed); + RA::print_from_uri(&formated_seed, None, self.shared_params.network, self.shared_params.output_type); + Ok(()) + } +} + +/// genertae a key based on given pattern +fn generate_key(desired: &str) -> Result, &'static str> where { + if desired.is_empty() { + return Err("Pattern must not be empty"); + } + + println!("Generating key containing pattern '{}'", desired); + + let top = 45 + (desired.len() * 48); + let mut best = 0; + let mut seed = ::Seed::default(); + let mut done = 0; + + loop { + if done % 100000 == 0 { + OsRng.fill_bytes(seed.as_mut()); + } else { + next_seed(seed.as_mut()); + } + + let p = C::Pair::from_seed(&seed); + let ss58 = C::ss58_from_pair(&p); + let score = calculate_score(&desired, &ss58); + if score > best || desired.len() < 2 { + best = score; + let keypair = KeyPair { + pair: p, + seed: seed.clone(), + score: score, + }; + if best >= top { + println!("best: {} == top: {}", best, top); + return Ok(keypair); + } + } + done += 1; + + if done % good_waypoint(done) == 0 { + println!("{} keys searched; best is {}/{} complete", done, best, top); + } + } +} + +fn good_waypoint(done: u64) -> u64 { + match done { + 0..=1_000_000 => 100_000, + 0..=10_000_000 => 1_000_000, + 0..=100_000_000 => 10_000_000, + _ => 100_000_000, + } +} + +fn next_seed(seed: &mut [u8]) { + for i in 0..seed.len() { + match seed[i] { + 255 => { + seed[i] = 0; + } + _ => { + seed[i] += 1; + break; + } + } + } +} + +/// A structure used to carry both Pair and seed. +/// This should usually NOT been used. If unsure, use Pair. +struct KeyPair { + pub pair: R::Pair, + pub seed: ::Seed, + pub score: usize, +} + +/// Calculate the score of a key based on the desired +/// input. +fn calculate_score(_desired: &str, key: &str) -> usize { + for truncate in 0.._desired.len() { + let snip_size = _desired.len() - truncate; + let truncated = &_desired[0..snip_size]; + if let Some(pos) = key.find(truncated) { + return (47 - pos) + (snip_size * 48); + } + } + 0 +} + + +// #[cfg(test)] +// mod tests { +// use super::*; +// use sp_core::{crypto::Ss58Codec, Pair}; +// #[cfg(feature = "bench")] +// use test::Bencher; +// +// #[test] +// fn test_generation_with_single_char() { +// assert!(generate_key::("j") +// .unwrap() +// .pair +// .public() +// .to_ss58check() +// .contains("j")); +// } +// +// #[test] +// fn test_score_1_char_100() { +// let score = calculate_score("j", "5jolkadotwHY5k9GpdTgpqs9xjuNvtv8EcwCFpEeyEf3KHim"); +// assert_eq!(score, 94); +// } +// +// #[test] +// fn test_score_100() { +// let score = calculate_score( +// "Polkadot", +// "5PolkadotwHY5k9GpdTgpqs9xjuNvtv8EcwCFpEeyEf3KHim", +// ); +// assert_eq!(score, 430); +// } +// +// #[test] +// fn test_score_50_2() { +// // 50% for the position + 50% for the size +// assert_eq!( +// calculate_score( +// "Polkadot", +// "5PolkXXXXwHY5k9GpdTgpqs9xjuNvtv8EcwCFpEeyEf3KHim" +// ), +// 238 +// ); +// } +// +// #[test] +// fn test_score_0() { +// assert_eq!( +// calculate_score( +// "Polkadot", +// "5GUWv4bLCchGUHJrzULXnh4JgXsMpTKRnjuXTY7Qo1Kh9uYK" +// ), +// 0 +// ); +// } +// +// #[cfg(feature = "bench")] +// #[bench] +// fn bench_paranoiac(b: &mut Bencher) { +// b.iter(|| generate_key("polk")); +// } +// +// #[cfg(feature = "bench")] +// #[bench] +// fn bench_not_paranoiac(b: &mut Bencher) { +// b.iter(|| generate_key("polk")); +// } +// } diff --git a/client/cli/src/commands/verify.rs b/client/cli/src/commands/verify.rs index 7c0a48726e2af..4cf8cb371a8fd 100644 --- a/client/cli/src/commands/verify.rs +++ b/client/cli/src/commands/verify.rs @@ -14,4 +14,68 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -//! verify subcommand \ No newline at end of file +//! implementation of the `verify` subcommand +use crate::{RuntimeAdapter, read_message_from_stdin, decode_hex, read_uri, error}; +use sp_core::{Pair, Public, crypto::Ss58Codec}; +use structopt::StructOpt; + +#[derive(Debug, StructOpt, Clone)] +#[structopt( + name = "verify", + about = "Verify a signature for a message, provided on STDIN, with a given (public or secret) key" +)] +pub struct VerifyCmd { + /// Signature, hex-encoded. + #[structopt(long)] + sig: String, + + /// The public or secret key URI. + /// If the value is a file, the file content is used as URI. + /// If not given, you will be prompted for the URI. + #[structopt(long)] + uri: Option, + + /// The message on STDIN is hex-encoded data + #[structopt(long)] + hex: bool, +} + +impl VerifyCmd { + pub fn run(self) -> error::Result<()> { + let message = read_message_from_stdin(self.hex)?; + let mut signature = <::Pair as Pair>::Signature::default(); + let sig_data = decode_hex(self.sig)?; + + if sig_data.len() != signature.as_ref().len() { + return Err(error::Error::Other(format!( + "signature has an invalid length. read {} bytes, expected {} bytes", + sig_data.len(), + signature.as_ref().len(), + ))); + } + + signature.as_mut().copy_from_slice(&sig_data); + let uri = read_uri(self.uri)?; + let uri = if uri.starts_with("0x") { + &uri[2..] + } else { + &uri + }; + + let pubkey = if let Ok(pubkey_vec) = hex::decode(uri) { + ::Public::from_slice(pubkey_vec.as_slice()) + } else { + ::Public::from_string(uri) + .ok() + .expect("Invalid URI; expecting either a secret URI or a public URI.") + }; + + if <::Pair as Pair>::verify(&signature, &message, &pubkey) { + println!("Signature verifies correctly."); + } else { + return Err(error::Error::Other("Signature invalid.".into())) + } + + Ok(()) + } +} diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index f91c9e8229050..c62f494478988 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -176,7 +176,7 @@ use sp_runtime::{ RuntimeDebug, DispatchResult, DispatchError, traits::{ Zero, AtLeast32Bit, StaticLookup, Member, CheckedAdd, CheckedSub, - MaybeSerializeDeserialize, Saturating, Bounded, + MaybeSerializeDeserialize, MaybeFromStr, Saturating, Bounded, }, }; use frame_system::{self as system, ensure_signed, ensure_root}; @@ -189,7 +189,7 @@ pub use self::imbalances::{PositiveImbalance, NegativeImbalance}; pub trait Subtrait: frame_system::Trait { /// The balance of an account. type Balance: Parameter + Member + AtLeast32Bit + Codec + Default + Copy + - MaybeSerializeDeserialize + Debug; + MaybeSerializeDeserialize + MaybeFromStr + Debug; /// The minimum amount required to keep an account open. type ExistentialDeposit: Get; @@ -201,7 +201,7 @@ pub trait Subtrait: frame_system::Trait { pub trait Trait: frame_system::Trait { /// The balance of an account. type Balance: Parameter + Member + AtLeast32Bit + Codec + Default + Copy + - MaybeSerializeDeserialize + Debug; + MaybeSerializeDeserialize + MaybeFromStr + Debug; /// Handler for the unbalanced reduction when removing a dust account. type DustRemoval: OnUnbalanced>; From 386cfcfdab5baad63bca13ada43cd2fa9d2a4f25 Mon Sep 17 00:00:00 2001 From: Seun Date: Fri, 13 Mar 2020 08:46:11 +0100 Subject: [PATCH 05/77] update Cargo.lock --- Cargo.lock | 646 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 573 insertions(+), 73 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1cb703fd5f713..4ca71a3319c57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -189,7 +189,7 @@ dependencies = [ "mio", "mio-uds", "num_cpus", - "once_cell", + "once_cell 1.3.1", "pin-project-lite", "pin-utils", "slab", @@ -919,7 +919,7 @@ dependencies = [ "lazy_static", "maybe-uninit", "memoffset", - "scopeguard", + "scopeguard 1.1.0", ] [[package]] @@ -1522,7 +1522,7 @@ dependencies = [ "frame-system", "impl-trait-for-tuples", "log 0.4.8", - "once_cell", + "once_cell 1.3.1", "parity-scale-codec", "paste", "pretty_assertions", @@ -2004,6 +2004,16 @@ dependencies = [ "crunchy", ] +[[package]] +name = "hashbrown" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" +dependencies = [ + "byteorder 1.3.4", + "scopeguard 0.3.3", +] + [[package]] name = "hashbrown" version = "0.6.3" @@ -2624,6 +2634,43 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "libp2p" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f84847789ab24b3fc5971a68656ac85886df640986d9ce3264c0327694eae471" +dependencies = [ + "bytes 0.5.4", + "futures 0.3.4", + "lazy_static", + "libp2p-core 0.15.0", + "libp2p-core-derive 0.15.0", + "libp2p-deflate 0.7.0", + "libp2p-dns 0.15.0", + "libp2p-floodsub 0.15.0", + "libp2p-gossipsub 0.15.0", + "libp2p-identify 0.15.0", + "libp2p-kad 0.15.0", + "libp2p-mdns 0.15.0", + "libp2p-mplex 0.15.0", + "libp2p-noise 0.13.0", + "libp2p-ping 0.15.0", + "libp2p-plaintext 0.15.0", + "libp2p-secio 0.15.0", + "libp2p-swarm 0.5.0", + "libp2p-tcp 0.15.0", + "libp2p-uds 0.15.0", + "libp2p-wasm-ext 0.8.0", + "libp2p-websocket 0.15.0", + "libp2p-yamux 0.15.0", + "parity-multiaddr", + "parity-multihash", + "parking_lot 0.10.0", + "pin-project", + "smallvec 1.2.0", + "wasm-timer", +] + [[package]] name = "libp2p" version = "0.16.2" @@ -2633,27 +2680,27 @@ dependencies = [ "bytes 0.5.4", "futures 0.3.4", "lazy_static", - "libp2p-core", - "libp2p-core-derive", - "libp2p-deflate", - "libp2p-dns", - "libp2p-floodsub", - "libp2p-gossipsub", - "libp2p-identify", - "libp2p-kad", - "libp2p-mdns", - "libp2p-mplex", - "libp2p-noise", - "libp2p-ping", - "libp2p-plaintext", + "libp2p-core 0.16.0", + "libp2p-core-derive 0.16.0", + "libp2p-deflate 0.16.0", + "libp2p-dns 0.16.0", + "libp2p-floodsub 0.16.0", + "libp2p-gossipsub 0.16.0", + "libp2p-identify 0.16.0", + "libp2p-kad 0.16.2", + "libp2p-mdns 0.16.0", + "libp2p-mplex 0.16.0", + "libp2p-noise 0.16.2", + "libp2p-ping 0.16.0", + "libp2p-plaintext 0.16.0", "libp2p-pnet", - "libp2p-secio", - "libp2p-swarm", - "libp2p-tcp", - "libp2p-uds", - "libp2p-wasm-ext", - "libp2p-websocket", - "libp2p-yamux", + "libp2p-secio 0.16.1", + "libp2p-swarm 0.16.1", + "libp2p-tcp 0.16.0", + "libp2p-uds 0.16.0", + "libp2p-wasm-ext 0.16.2", + "libp2p-websocket 0.16.0", + "libp2p-yamux 0.16.2", "parity-multiaddr", "parity-multihash", "parking_lot 0.10.0", @@ -2662,6 +2709,40 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-core" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbafb2706b8082233f66dc13e196f9cf9b4c229f2cd7c96b2b16617ad6ee330b" +dependencies = [ + "asn1_der", + "bs58", + "ed25519-dalek", + "fnv", + "futures 0.3.4", + "futures-timer 2.0.2", + "lazy_static", + "libsecp256k1", + "log 0.4.8", + "multistream-select", + "parity-multiaddr", + "parity-multihash", + "parking_lot 0.10.0", + "pin-project", + "prost", + "prost-build", + "rand 0.7.3", + "ring", + "rw-stream-sink", + "sha2", + "smallvec 1.2.0", + "thiserror", + "unsigned-varint", + "untrusted", + "void", + "zeroize 1.1.0", +] + [[package]] name = "libp2p-core" version = "0.16.0" @@ -2695,6 +2776,16 @@ dependencies = [ "zeroize 1.1.0", ] +[[package]] +name = "libp2p-core-derive" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c320266be0a7760e23484d635acdb83844b2d74d3612d93b41c393c9bcf004e" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "libp2p-core-derive" version = "0.16.0" @@ -2705,6 +2796,17 @@ dependencies = [ "syn", ] +[[package]] +name = "libp2p-deflate" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be32697b42d040b325c3737f827ea04ede569ec956b7807700dd8d89d8210f9" +dependencies = [ + "flate2", + "futures 0.3.4", + "libp2p-core 0.15.0", +] + [[package]] name = "libp2p-deflate" version = "0.16.0" @@ -2713,7 +2815,18 @@ checksum = "2e25004d4d9837b44b22c5f1a69be1724a5168fef6cff1716b5176a972c3aa62" dependencies = [ "flate2", "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", +] + +[[package]] +name = "libp2p-dns" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f11c979b882f25d85726b15637d5bbc722dfa1be576605c54e99b8cf56906be3" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "log 0.4.8", ] [[package]] @@ -2723,10 +2836,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b99e552f9939b606eb4b59f7f64d9b01e3f96752f47e350fc3c5fc646ed3f649" dependencies = [ "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", ] +[[package]] +name = "libp2p-floodsub" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bdf6fba9272ad47dde94bade89540fdb16e24ae9ff7fb714c1c80a035165f28" +dependencies = [ + "bs58", + "cuckoofilter", + "fnv", + "futures 0.3.4", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "prost", + "prost-build", + "rand 0.7.3", + "smallvec 1.2.0", +] + [[package]] name = "libp2p-floodsub" version = "0.16.0" @@ -2736,12 +2867,38 @@ dependencies = [ "cuckoofilter", "fnv", "futures 0.3.4", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", + "prost", + "prost-build", + "rand 0.7.3", + "smallvec 1.2.0", +] + +[[package]] +name = "libp2p-gossipsub" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e6ecd058bf769d27ebec530544b081e08b0a1088e3186da8cc58d59915784d0" +dependencies = [ + "base64 0.11.0", + "bs58", + "byteorder 1.3.4", + "bytes 0.5.4", + "fnv", + "futures 0.3.4", + "futures_codec", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "lru", "prost", "prost-build", "rand 0.7.3", + "sha2", "smallvec 1.2.0", + "unsigned-varint", + "wasm-timer", ] [[package]] @@ -2756,8 +2913,8 @@ dependencies = [ "fnv", "futures 0.3.4", "futures_codec", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "lru", "prost", @@ -2769,6 +2926,22 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-identify" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1a6261b804111c2dbf53f8ca03f66edc5ad1c29b78a61cf0cc5354052e28e9" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "prost", + "prost-build", + "smallvec 1.2.0", + "wasm-timer", +] + [[package]] name = "libp2p-identify" version = "0.16.0" @@ -2776,8 +2949,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfeb935a9bd41263e4f3a24b988e9f4a044f3ae89ac284e83c17fe2f84e0d66b" dependencies = [ "futures 0.3.4", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "prost", "prost-build", @@ -2785,6 +2958,33 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-kad" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c6ea6fece0d99599afb1b2082ca8937944cdd6b0946a88d54cb3ae7a38d1253" +dependencies = [ + "arrayvec 0.5.1", + "bytes 0.5.4", + "either", + "fnv", + "futures 0.3.4", + "futures_codec", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "parity-multihash", + "prost", + "prost-build", + "rand 0.7.3", + "sha2", + "smallvec 1.2.0", + "uint", + "unsigned-varint", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-kad" version = "0.16.2" @@ -2797,8 +2997,8 @@ dependencies = [ "fnv", "futures 0.3.4", "futures_codec", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "parity-multihash", "prost", @@ -2812,6 +3012,28 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-mdns" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "074312353355df310affa105ec71b16fd7e52f5c6ae61d3dcbb3e79e8fdc9e5f" +dependencies = [ + "async-std", + "data-encoding", + "dns-parser", + "either", + "futures 0.3.4", + "lazy_static", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "net2", + "rand 0.7.3", + "smallvec 1.2.0", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-mdns" version = "0.16.0" @@ -2824,8 +3046,8 @@ dependencies = [ "either", "futures 0.3.4", "lazy_static", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "net2", "rand 0.7.3", @@ -2834,6 +3056,22 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-mplex" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89d0b44dfdef80cc2be4b42d127de1c793905eca2459415a5c57d6b4fbd8ec30" +dependencies = [ + "bytes 0.5.4", + "fnv", + "futures 0.3.4", + "futures_codec", + "libp2p-core 0.15.0", + "log 0.4.8", + "parking_lot 0.10.0", + "unsigned-varint", +] + [[package]] name = "libp2p-mplex" version = "0.16.0" @@ -2844,12 +3082,32 @@ dependencies = [ "fnv", "futures 0.3.4", "futures_codec", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "parking_lot 0.10.0", "unsigned-varint", ] +[[package]] +name = "libp2p-noise" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0845e8208d814cd41c26c90a6a2f2b720c31b588209cecc49a44c881a09f417f" +dependencies = [ + "curve25519-dalek 1.2.3", + "futures 0.3.4", + "lazy_static", + "libp2p-core 0.15.0", + "log 0.4.8", + "prost", + "prost-build", + "rand 0.7.3", + "ring", + "snow", + "x25519-dalek 0.5.2", + "zeroize 1.1.0", +] + [[package]] name = "libp2p-noise" version = "0.16.2" @@ -2859,7 +3117,7 @@ dependencies = [ "curve25519-dalek 2.0.0", "futures 0.3.4", "lazy_static", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "prost", "prost-build", @@ -2867,10 +3125,25 @@ dependencies = [ "sha2", "snow", "static_assertions", - "x25519-dalek", + "x25519-dalek 0.6.0", "zeroize 1.1.0", ] +[[package]] +name = "libp2p-ping" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ecced2949ae93b6ff29565303ecd1bef15c4e4efb689033ee744922561a36b" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "rand 0.7.3", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-ping" version = "0.16.0" @@ -2878,14 +3151,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d22f2f228b3a828dca1cb8aa9fa331e0bc9c36510cb2c1916956e20dc85e8c" dependencies = [ "futures 0.3.4", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "rand 0.7.3", "void", "wasm-timer", ] +[[package]] +name = "libp2p-plaintext" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "195fda6b6a948a242fd30570e0e3418ae8e0a20055ea75d45458e1079a8efb05" +dependencies = [ + "bytes 0.5.4", + "futures 0.3.4", + "futures_codec", + "libp2p-core 0.15.0", + "log 0.4.8", + "prost", + "prost-build", + "rw-stream-sink", + "unsigned-varint", + "void", +] + [[package]] name = "libp2p-plaintext" version = "0.16.0" @@ -2895,7 +3186,7 @@ dependencies = [ "bytes 0.5.4", "futures 0.3.4", "futures_codec", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "prost", "prost-build", @@ -2918,6 +3209,36 @@ dependencies = [ "sha3", ] +[[package]] +name = "libp2p-secio" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ceef68ca377b264f84d64c88739a8fa118b5db1e8f18297351dff75314504a5f" +dependencies = [ + "aes-ctr", + "ctr", + "futures 0.3.4", + "hmac", + "js-sys", + "lazy_static", + "libp2p-core 0.15.0", + "log 0.4.8", + "parity-send-wrapper", + "pin-project", + "prost", + "prost-build", + "quicksink", + "rand 0.7.3", + "ring", + "rw-stream-sink", + "sha2", + "static_assertions", + "twofish", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "libp2p-secio" version = "0.16.1" @@ -2930,7 +3251,7 @@ dependencies = [ "hmac", "js-sys", "lazy_static", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "parity-send-wrapper", "pin-project", @@ -2948,6 +3269,20 @@ dependencies = [ "web-sys", ] +[[package]] +name = "libp2p-swarm" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14ea00be81bc3985e36abad263ce2ad1b6aeb862aa743563eb70ad42880c05ae" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "log 0.4.8", + "smallvec 1.2.0", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-swarm" version = "0.16.1" @@ -2955,13 +3290,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "275471e7c0e88ae004660866cd54f603bd8bd1f4caef541a27f50dd8640c4d4c" dependencies = [ "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "smallvec 1.2.0", "void", "wasm-timer", ] +[[package]] +name = "libp2p-tcp" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e65ef381570df31cb047dfbc11483ab0fe7e6abbdcf2bdc2c60b5d11133d241" +dependencies = [ + "async-std", + "futures 0.3.4", + "futures-timer 2.0.2", + "get_if_addrs", + "ipnet", + "libp2p-core 0.15.0", + "log 0.4.8", +] + [[package]] name = "libp2p-tcp" version = "0.16.0" @@ -2973,7 +3323,19 @@ dependencies = [ "futures-timer 3.0.2", "get_if_addrs", "ipnet", - "libp2p-core", + "libp2p-core 0.16.0", + "log 0.4.8", +] + +[[package]] +name = "libp2p-uds" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e4f4f7989b35f33d4b9738aab2f031310eb20fec513cab44d12b1bc985a8074" +dependencies = [ + "async-std", + "futures 0.3.4", + "libp2p-core 0.15.0", "log 0.4.8", ] @@ -2985,10 +3347,24 @@ checksum = "76d329564a43da9d0e055a5b938633c4a8ceab1f59cec133fbc4647917c07341" dependencies = [ "async-std", "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", ] +[[package]] +name = "libp2p-wasm-ext" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b4d457adb91a5e2212343218a554394cd8ced64a79fb8e36e7aed2a16d49495" +dependencies = [ + "futures 0.3.4", + "js-sys", + "libp2p-core 0.15.0", + "parity-send-wrapper", + "wasm-bindgen", + "wasm-bindgen-futures", +] + [[package]] name = "libp2p-wasm-ext" version = "0.16.2" @@ -2997,12 +3373,33 @@ checksum = "923581c055bc4b8c5f42d4ce5ef43e52fe5216f1ea4bc26476cb8a966ce6220b" dependencies = [ "futures 0.3.4", "js-sys", - "libp2p-core", + "libp2p-core 0.16.0", "parity-send-wrapper", "wasm-bindgen", "wasm-bindgen-futures", ] +[[package]] +name = "libp2p-websocket" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bba425f2af1fdb7dece88b9ae05ca9430dfb0b72b2c078e73ded6f1556084509" +dependencies = [ + "async-tls", + "bytes 0.5.4", + "either", + "futures 0.3.4", + "libp2p-core 0.15.0", + "log 0.4.8", + "quicksink", + "rustls 0.16.0", + "rw-stream-sink", + "soketto", + "url 2.1.1", + "webpki", + "webpki-roots 0.18.0", +] + [[package]] name = "libp2p-websocket" version = "0.16.0" @@ -3013,7 +3410,7 @@ dependencies = [ "bytes 0.5.4", "either", "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "quicksink", "rustls 0.16.0", @@ -3024,6 +3421,20 @@ dependencies = [ "webpki-roots 0.18.0", ] +[[package]] +name = "libp2p-yamux" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca25b3aac78a3c93c2a567622abd3cfc16f96f26ae1bf6134f0056203d62d86" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "log 0.4.8", + "parking_lot 0.10.0", + "thiserror", + "yamux", +] + [[package]] name = "libp2p-yamux" version = "0.16.2" @@ -3031,7 +3442,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dac30de24ccde0e67f363d71a125c587bbe6589503f664947e9b084b68a34f1" dependencies = [ "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "parking_lot 0.10.0", "thiserror", "yamux", @@ -3092,13 +3503,22 @@ dependencies = [ "linked-hash-map", ] +[[package]] +name = "lock_api" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" +dependencies = [ + "scopeguard 0.3.3", +] + [[package]] name = "lock_api" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79b2de95ecb4691949fea4716ca53cdbcfccb2c612e19644a8bad05edcf9f47b" dependencies = [ - "scopeguard", + "scopeguard 1.1.0", ] [[package]] @@ -3125,7 +3545,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0609345ddee5badacf857d4f547e0e5a2e987db77085c24cd887f73573a04237" dependencies = [ - "hashbrown", + "hashbrown 0.6.3", ] [[package]] @@ -3172,7 +3592,7 @@ checksum = "198831fe8722331a395bc199a5d08efbc197497ef354cb4c77b969c02ffc0fc4" dependencies = [ "ahash", "hash-db", - "hashbrown", + "hashbrown 0.6.3", "parity-util-mem", ] @@ -3805,6 +4225,15 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "once_cell" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "532c29a261168a45ce28948f9537ddd7a5dd272cc513b3017b1e82a88f962c37" +dependencies = [ + "parking_lot 0.7.1", +] + [[package]] name = "once_cell" version = "1.3.1" @@ -4661,7 +5090,7 @@ checksum = "ef1476e40bf8f5c6776e9600983435821ca86eb9819d74a6207cca69d091406a" dependencies = [ "cfg-if", "ethereum-types", - "hashbrown", + "hashbrown 0.6.3", "impl-trait-for-tuples", "lru", "parity-util-mem-derive", @@ -4697,13 +5126,23 @@ version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" +[[package]] +name = "parking_lot" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" +dependencies = [ + "lock_api 0.1.5", + "parking_lot_core 0.4.0", +] + [[package]] name = "parking_lot" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" dependencies = [ - "lock_api", + "lock_api 0.3.3", "parking_lot_core 0.6.2", "rustc_version", ] @@ -4714,10 +5153,23 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92e98c49ab0b7ce5b222f2cc9193fc4efe11c6d0bd4f648e374684a6857b1cfc" dependencies = [ - "lock_api", + "lock_api 0.3.3", "parking_lot_core 0.7.0", ] +[[package]] +name = "parking_lot_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" +dependencies = [ + "libc", + "rand 0.6.5", + "rustc_version", + "smallvec 0.6.13", + "winapi 0.3.8", +] + [[package]] name = "parking_lot_core" version = "0.6.2" @@ -5599,7 +6051,7 @@ dependencies = [ "env_logger 0.7.1", "futures 0.3.4", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "parity-scale-codec", "prost", @@ -5696,19 +6148,33 @@ dependencies = [ "derive_more", "env_logger 0.7.1", "fdlimit", + "frame-system", + "futures 0.1.29", "futures 0.3.4", + "hex", + "hex-literal", + "hyper 0.12.35", + "jsonrpc-core-client", "lazy_static", + "libp2p 0.15.0", "log 0.4.8", "names", + "pallet-balances", + "pallet-indices", + "pallet-transaction-payment", + "parity-scale-codec", "parity-util-mem", + "rand 0.7.3", "regex", "rpassword", "sc-client-api", "sc-informant", "sc-network", + "sc-rpc", "sc-service", "sc-telemetry", "sc-tracing", + "serde", "serde_json", "sp-blockchain", "sp-core", @@ -5716,10 +6182,12 @@ dependencies = [ "sp-panic-handler", "sp-runtime", "sp-state-machine", + "sp-version", "structopt", "substrate-prometheus-endpoint", "tempfile", "time", + "tiny-bip39 0.6.2", "tokio 0.2.12", ] @@ -6202,7 +6670,7 @@ dependencies = [ "futures 0.3.4", "futures-timer 3.0.2", "futures_codec", - "libp2p", + "libp2p 0.16.2", "linked-hash-map", "linked_hash_set", "log 0.4.8", @@ -6250,7 +6718,7 @@ version = "0.8.0-alpha.3" dependencies = [ "futures 0.3.4", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "lru", "sc-network", @@ -6265,7 +6733,7 @@ dependencies = [ "env_logger 0.7.1", "futures 0.3.4", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "parking_lot 0.10.0", "rand 0.7.3", @@ -6320,7 +6788,7 @@ name = "sc-peerset" version = "2.0.0-alpha.3" dependencies = [ "futures 0.3.4", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "rand 0.7.3", "serde_json", @@ -6507,7 +6975,7 @@ dependencies = [ "bytes 0.5.4", "futures 0.3.4", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "parking_lot 0.10.0", "pin-project", @@ -6616,6 +7084,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" +[[package]] +name = "scopeguard" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" + [[package]] name = "scopeguard" version = "1.1.0" @@ -6918,7 +7392,7 @@ dependencies = [ "rustc_version", "sha2", "subtle 2.2.2", - "x25519-dalek", + "x25519-dalek 0.6.0", ] [[package]] @@ -7095,7 +7569,7 @@ dependencies = [ "futures 0.3.4", "futures-diagnose", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "parity-scale-codec", "parking_lot 0.10.0", @@ -7185,7 +7659,7 @@ dependencies = [ "sp-std", "sp-storage", "substrate-bip39", - "tiny-bip39", + "tiny-bip39 0.7.1", "tiny-keccak 2.0.1", "twox-hash", "wasmi", @@ -7585,9 +8059,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.9" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1bcbed7d48956fcbb5d80c6b95aedb553513de0a1b451ea92679d999c010e98" +checksum = "3fe43617218c0805c6eb37160119dc3c548110a67786da7218d1c6555212f073" dependencies = [ "clap", "lazy_static", @@ -7596,9 +8070,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "095064aa1f5b94d14e635d0a5684cf140c43ae40a0fd990708d38f5d669e5f64" +checksum = "c6e79c80e0f4efd86ca960218d4e056249be189ff1c42824dcd9a7f51a56f0bd" dependencies = [ "heck", "proc-macro-error", @@ -7641,7 +8115,7 @@ dependencies = [ "hyper 0.12.35", "itertools", "jsonrpc-core-client", - "libp2p", + "libp2p 0.16.2", "node-primitives", "node-runtime", "pallet-balances", @@ -7655,7 +8129,7 @@ dependencies = [ "sp-core", "sp-runtime", "substrate-bip39", - "tiny-bip39", + "tiny-bip39 0.7.1", ] [[package]] @@ -7683,7 +8157,7 @@ dependencies = [ "futures-timer 3.0.2", "js-sys", "kvdb-web", - "libp2p-wasm-ext", + "libp2p-wasm-ext 0.16.2", "log 0.4.8", "rand 0.6.5", "rand 0.7.3", @@ -7923,7 +8397,7 @@ dependencies = [ "doc-comment", "libc", "ntapi", - "once_cell", + "once_cell 1.3.1", "rayon", "winapi 0.3.8", ] @@ -8040,6 +8514,21 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "tiny-bip39" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1c5676413eaeb1ea35300a0224416f57abc3bd251657e0fafc12c47ff98c060" +dependencies = [ + "failure", + "hashbrown 0.1.8", + "hmac", + "once_cell 0.1.8", + "pbkdf2", + "rand 0.6.5", + "sha2", +] + [[package]] name = "tiny-bip39" version = "0.7.1" @@ -8048,7 +8537,7 @@ checksum = "a6848cd8f566953ce1e8faeba12ee23cbdbb0437754792cd857d44628b5685e3" dependencies = [ "failure", "hmac", - "once_cell", + "once_cell 1.3.1", "pbkdf2", "rand 0.7.3", "rustc-hash", @@ -8449,7 +8938,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de9222c50cc325855621271157c973da27a0dcd26fa06f8edf81020bd2333df0" dependencies = [ "hash-db", - "hashbrown", + "hashbrown 0.6.3", "log 0.4.8", "rustc-hex", "smallvec 1.2.0", @@ -9191,6 +9680,17 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "x25519-dalek" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ee1585dc1484373cbc1cee7aafda26634665cf449436fd6e24bfd1fad230538" +dependencies = [ + "clear_on_drop", + "curve25519-dalek 1.2.3", + "rand_core 0.3.1", +] + [[package]] name = "x25519-dalek" version = "0.6.0" From fccf7ba698c94578eddceaf0a007bd7010d5bbff Mon Sep 17 00:00:00 2001 From: Seun Date: Fri, 13 Mar 2020 17:38:42 +0100 Subject: [PATCH 06/77] tests WIP --- Cargo.lock | 4 + client/cli/Cargo.toml | 2 + client/cli/src/commands/generate_node_key.rs | 2 +- client/cli/src/commands/inspect.rs | 4 +- client/cli/src/commands/mod.rs | 11 ++ client/cli/src/commands/runcmd.rs | 6 + client/cli/src/commands/sign.rs | 14 +-- client/cli/src/commands/tests.rs | 117 +++++++++++++++++++ client/cli/src/commands/transfer.rs | 24 +--- client/cli/src/commands/utils.rs | 14 +-- test-utils/runtime/Cargo.toml | 8 +- test-utils/runtime/src/lib.rs | 40 +++++-- 12 files changed, 197 insertions(+), 49 deletions(-) create mode 100644 client/cli/src/commands/tests.rs diff --git a/Cargo.lock b/Cargo.lock index 4ca71a3319c57..649f0877ce4f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6176,6 +6176,7 @@ dependencies = [ "sc-tracing", "serde", "serde_json", + "sp-application-crypto", "sp-blockchain", "sp-core", "sp-keyring", @@ -6185,6 +6186,7 @@ dependencies = [ "sp-version", "structopt", "substrate-prometheus-endpoint", + "substrate-test-runtime", "tempfile", "time", "tiny-bip39 0.6.2", @@ -8256,6 +8258,8 @@ dependencies = [ "log 0.4.8", "memory-db", "pallet-babe", + "pallet-balances", + "pallet-indices", "pallet-timestamp", "parity-scale-codec", "parity-util-mem", diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 0f838dfa17c71..c3384109efab2 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -62,6 +62,8 @@ rpassword = "4.0.1" [dev-dependencies] tempfile = "3.1.0" +substrate-test-runtime = { version = "2.0.0-dev", features = ["indices-lookup"], path = "../../test-utils/runtime" } +sp-application-crypto = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/application-crypto" } [features] wasmtime = [ diff --git a/client/cli/src/commands/generate_node_key.rs b/client/cli/src/commands/generate_node_key.rs index 8775b6c19cf5b..5dae01812f86d 100644 --- a/client/cli/src/commands/generate_node_key.rs +++ b/client/cli/src/commands/generate_node_key.rs @@ -41,7 +41,7 @@ impl GenerateNodeKeyCmd { let secret = keypair.secret(); let peer_id = PublicKey::Ed25519(keypair.public()).into_peer_id(); - fs::write(file, secret.as_ref())?; + fs::write(file, hex::encode(secret.as_ref()))?; println!("{}", peer_id); diff --git a/client/cli/src/commands/inspect.rs b/client/cli/src/commands/inspect.rs index d61eb186cd7cc..1d84d906a7727 100644 --- a/client/cli/src/commands/inspect.rs +++ b/client/cli/src/commands/inspect.rs @@ -40,11 +40,11 @@ pub struct InspectCmd { impl InspectCmd { pub fn run(self) -> error::Result<()> { let uri = read_uri(self.uri)?; - let pass = get_password(&self.shared_params)?; + let pass = get_password(&self.shared_params).ok(); C::print_from_uri( &uri, - Some(pass.as_str()), + pass.as_ref().map(String::as_str), self.shared_params.network, self.shared_params.output_type ); diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 789a36523f65d..66bb91e205a56 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -31,6 +31,8 @@ mod transfer; mod verify; mod vanity; mod insert; +#[cfg(test)] +mod tests; use std::fmt::Debug; use structopt::StructOpt; @@ -50,6 +52,15 @@ pub use crate::commands::import_blocks_cmd::ImportBlocksCmd; pub use crate::commands::check_block_cmd::CheckBlockCmd; pub use crate::commands::revert_cmd::RevertCmd; pub use crate::commands::purge_chain_cmd::PurgeChainCmd; +pub use crate::commands::generate::GenerateCmd; +pub use crate::commands::generate_node_key::GenerateNodeKeyCmd; +pub use crate::commands::insert::InsertCmd; +pub use crate::commands::sign::SignCmd; +pub use crate::commands::sign_transaction::SignTransactionCmd; +pub use crate::commands::transfer::TransferCmd; +pub use crate::commands::vanity::VanityCmd; +pub use crate::commands::verify::VerifyCmd; + /// default sub directory to store network config const DEFAULT_NETWORK_CONFIG_PATH : &'static str = "network"; diff --git a/client/cli/src/commands/runcmd.rs b/client/cli/src/commands/runcmd.rs index 43d8a6c41f781..d778257655faf 100644 --- a/client/cli/src/commands/runcmd.rs +++ b/client/cli/src/commands/runcmd.rs @@ -243,6 +243,12 @@ pub struct RunCmd { /// Specify custom keystore path. #[structopt(long = "keystore-path", value_name = "PATH", parse(from_os_str))] pub keystore_path: Option, + + /// The size of the instances cache for each runtime. + /// + /// The default value is 8 and the values higher than 256 are ignored. + #[structopt(long = "max-runtime-instances", default_value = "8")] + pub max_runtime_instances: usize, } impl RunCmd { diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs index 828a8da48fcf4..3cc0026488e67 100644 --- a/client/cli/src/commands/sign.rs +++ b/client/cli/src/commands/sign.rs @@ -16,11 +16,13 @@ //! Implementation of the `sign` subcommand use crate::error; -use super::{SharedParams, get_password, read_message_from_stdin, read_uri, RuntimeAdapter}; +use super::{SharedParams, decode_hex, get_password, read_message_from_stdin, read_uri, RuntimeAdapter}; use structopt::StructOpt; use sp_core::crypto::Pair; +type Bytes = Vec; + #[derive(Debug, StructOpt, Clone)] #[structopt( name = "sign", @@ -33,9 +35,9 @@ pub struct SignCmd { #[structopt(long)] suri: Option, - /// The message on STDIN is hex-encoded data - #[structopt(long)] - hex: bool, + /// Hex encoded message to sign + #[structopt(long, parse(try_from_str = decode_hex))] + message: Bytes, #[allow(missing_docs)] #[structopt(flatten)] @@ -46,11 +48,9 @@ pub struct SignCmd { impl SignCmd { pub fn run(self) -> error::Result<()> { let suri = read_uri(self.suri)?; - - let message = read_message_from_stdin(self.hex)?; let password = get_password(&self.shared_params)?; let pair = C::pair_from_suri(&suri, &password); - let signature = format!("{}", hex::encode(pair.sign(&message))); + let signature = format!("{}", hex::encode(pair.sign(&self.message))); println!("{}", signature); Ok(()) } diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs new file mode 100644 index 0000000000000..f4883d6481f2f --- /dev/null +++ b/client/cli/src/commands/tests.rs @@ -0,0 +1,117 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +use super::*; +use substrate_test_runtime::{AccountSignature, Runtime}; +use sp_core::sr25519; +use sp_runtime::{MultiSignature, MultiSigner}; +use sp_runtime::generic::Era; +use sp_runtime::traits::StaticLookup; +use tempfile::Builder; +use std::io::Read; +use crate::commands::inspect::InspectCmd; +use crate::Error; + +pub struct Adapter; + +impl RuntimeAdapter for Adapter { + type Pair = sr25519::Pair; + type Public = sr25519::Public; + type Signature = AccountSignature; + type Runtime = Runtime; + type Extra = ( + frame_system::CheckVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + ); + type Address = as StaticLookup>::Source; + + fn build_extra(index: IndexFor) -> Self::Extra { + ( + frame_system::CheckVersion::new(), + frame_system::CheckGenesis::new(), + frame_system::CheckEra::from(Era::Immortal), + frame_system::CheckNonce::from(index), + frame_system::CheckWeight::new(), + ) + } +} + +#[test] +fn generate() { + let generate = GenerateCmd::from_iter(&["generate", "--password", "12345"]); + assert!(generate.run::().is_ok()) +} + +#[test] +fn generate_node_key() { + let mut file = Builder::new() + .prefix("keyfile") + .tempfile() + .unwrap(); + let generate = GenerateNodeKeyCmd::from_iter(&["generate-node-key", "--file", "/tmp/keyfile"]); + assert!(generate.run().is_ok()); + let mut buf = String::new(); + assert!(file.read_to_string(&mut buf).is_ok()); + assert!(hex::decode(buf).is_ok()); +} + +#[test] +fn inspect() { + let words = "remember fiber forum demise paper uniform squirrel feel access exclude casual effort"; + let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; + + let inspect = InspectCmd::from_iter(&["inspect", "--uri", words, "--password", "12345"]); + assert!(inspect.run::().is_ok()); + + let inspect = InspectCmd::from_iter(&["inspect", "--uri", seed]); + assert!(inspect.run::().is_ok()); + + let inspect = InspectCmd::from_iter(&["inspect", "--uri", words]); + assert!(matches!(inspect.run::(), Err(Error::Input(_)))) +} + +#[test] +fn sign() { + let words = "remember fiber forum demise paper uniform squirrel feel access exclude casual effort"; + let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; + + let sign = SignCmd::from_iter(&["sign", "--suri", seed, "--message", &seed[2..], "--password", "12345"]); + assert!(sign.run::().is_ok()); + + let sign = SignCmd::from_iter(&["sign", "--suri", words, "--message", &seed[2..]]); + assert!(matches!(sign.run::(), Err(Error::Input(_)))) +} + + +#[test] +fn transfer() { + let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; + + let transfer = TransferCmd::from_iter(&["transfer", + "--from", seed, + "--to", "0xa2bc899a8a3b16a284a8cefcbc2dc48a687cd674e89b434fbbdb06f400979744", + "--amount", "5000", + "--index", "1", + "--password", "12345", + ]); + // println!("{:?}", transfer.run::()); + + // let transfer = TransferCmd::from_iter(&["transfer", "--suri", words, "--message", &seed[2..]]); + // assert!(matches!(transfer.run::(), Err(Error::Input(_)))) +} \ No newline at end of file diff --git a/client/cli/src/commands/transfer.rs b/client/cli/src/commands/transfer.rs index 22e0e4ec3a027..3c74f75bf1c04 100644 --- a/client/cli/src/commands/transfer.rs +++ b/client/cli/src/commands/transfer.rs @@ -14,30 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . - -// Copyright 2018-2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - //! Implementation of the `sign` subcommand use crate::{error, IndexFor, BalanceFor, create_extrinsic_for, get_password, AddressFor}; use super::{SharedParams, RuntimeAdapter}; use structopt::StructOpt; use pallet_balances::Call as BalancesCall; use std::str::FromStr; -use parity_scale_codec::Encode; +use parity_scale_codec::{Encode, Decode}; use std::fmt::Display; #[derive(Debug, StructOpt, Clone)] @@ -71,15 +54,14 @@ pub struct TransferCmd { impl TransferCmd { pub fn run(self) -> error::Result<()> where - AddressFor: FromStr, - as FromStr>::Err: Display, + AddressFor: Decode, as FromStr>::Err: Display, as FromStr>::Err: Display, BalancesCall: Encode, { let password = get_password(&self.shared_params)?; let nonce = IndexFor::::from_str(&self.index).map_err(|e| format!("{}", e))?; - let to = AddressFor::::from_str(&self.to).map_err(|e| format!("{}", e))?; + let to = AddressFor::::decode(&mut self.to.as_bytes()).map_err(|e| format!("{}", e))?; let amount = BalanceFor::::from_str(&self.amount).map_err(|e| format!("{}", e))?; let signer = RA::pair_from_suri(&self.from, &password); diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 3a0e6bad89fd3..a0b07f4e7f078 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -18,9 +18,8 @@ use std::{io::Read, path::PathBuf}; use sp_core::{Pair, Public, crypto::{Ss58Codec, Ss58AddressFormat}, hexdisplay::HexDisplay}; use sp_runtime::{ - MultiSignature, MultiSigner, - generic::{UncheckedExtrinsic, SignedPayload}, - traits::IdentifyAccount, + MultiSignature, MultiSigner, generic::{UncheckedExtrinsic, SignedPayload}, + traits::IdentifyAccount, AccountId32, }; use parity_scale_codec::{Encode, Decode}; use serde_json::json; @@ -48,14 +47,14 @@ pub trait RuntimeAdapter: Sized { type Pair: Pair; /// public type type Public: Public + Into + Ss58Codec + AsRef<[u8]> + std::hash::Hash; - /// sugnature type + /// signature type type Signature: Into + AsRef<[u8]> + AsMut<[u8]> + Encode + Default; /// runtime type Runtime: frame_system::Trait + pallet_balances::Trait + pallet_indices::Trait; /// extras type Extra: SignedExtension; /// Address type - type Address: Encode + Decode + From; + type Address: Encode + Decode + From; /// generate a pair from suri fn pair_from_suri(suri: &str, password: &str) -> Self::Pair { @@ -178,7 +177,7 @@ pub fn get_password(params: &SharedParams) -> error::Result { let pass = if password_interactive { rpassword::read_password_from_tty(Some("Key password: "))? } else { - password.map(Into::into).expect("") + password.map(Into::into).ok_or("Password not specified")? }; Ok(pass) @@ -241,13 +240,14 @@ pub fn create_extrinsic_for( ) -> Result, Error> where Call: Encode, + RA::Address: From, { let extra = RA::build_extra(nonce); let payload = SignedPayload::new(call, extra) .map_err(|_| Error::Other("Transaction validity error".into()))?; let signature = payload.using_encoded(|payload| signer.sign(payload)); - let signer = RA::Address::from(signer.public()); + let signer = signer.public().into().into_account().into(); let (function, extra, _) = payload.deconstruct(); Ok(UncheckedExtrinsic::new_signed( diff --git a/test-utils/runtime/Cargo.toml b/test-utils/runtime/Cargo.toml index b5ae15029a725..2343a996b524b 100644 --- a/test-utils/runtime/Cargo.toml +++ b/test-utils/runtime/Cargo.toml @@ -32,10 +32,12 @@ serde = { version = "1.0.101", optional = true, features = ["derive"] } sp-session = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/session" } sp-api = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/api" } sp-runtime = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/runtime" } -pallet-babe = { version = "2.0.0-alpha.2", default-features = false, path = "../../frame/babe" } frame-system = { version = "2.0.0-alpha.2", default-features = false, path = "../../frame/system" } frame-system-rpc-runtime-api = { version = "2.0.0-alpha.2", default-features = false, path = "../../frame/system/rpc/runtime-api" } -pallet-timestamp = { version = "2.0.0-alpha.2", default-features = false, path = "../../frame/timestamp" } +pallet-babe = { version = "2.0.0-alpha.2", default-features = false, path = "../../frame/babe" } +pallet-timestamp = { version = "2.0.0-alpha.3", default-features = false, path = "../../frame/timestamp" } +pallet-indices = { version = "2.0.0-alpha.3", default-features = false, path = "../../frame/indices" } +pallet-balances = { version = "2.0.0-alpha.3", default-features = false, path = "../../frame/balances" } sc-client = { version = "0.8.0-alpha.2", optional = true, path = "../../client" } sp-trie = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/trie" } sp-transaction-pool = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/transaction-pool" } @@ -55,6 +57,7 @@ wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-run default = [ "std", ] +indices-lookup = [] std = [ "sp-application-crypto/std", "sp-consensus-aura/std", @@ -79,6 +82,7 @@ std = [ "sp-api/std", "sp-runtime/std", "pallet-babe/std", + "pallet-indices/std", "frame-system-rpc-runtime-api/std", "frame-system/std", "pallet-timestamp/std", diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index 655cf96006cc8..ee9d1700894de 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -46,7 +46,7 @@ use sp_version::RuntimeVersion; pub use sp_core::{hash::H256}; #[cfg(any(feature = "std", test))] use sp_version::NativeVersion; -use frame_support::{impl_outer_origin, parameter_types, weights::Weight}; +use frame_support::{impl_outer_origin, impl_outer_event, parameter_types, weights::Weight}; use sp_inherents::{CheckInherentsResult, InherentData}; use cfg_if::cfg_if; use sp_core::storage::ChildType; @@ -359,12 +359,11 @@ impl_outer_origin!{ pub enum Origin for Runtime where system = frame_system {} } -#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug)] -pub struct Event; - -impl From> for Event { - fn from(_evt: frame_system::Event) -> Self { - unimplemented!("Not required in tests!") +impl_outer_event!{ + pub enum MetaEvent for Runtime { + frame_system, + pallet_balances, + pallet_indices, } } @@ -374,6 +373,23 @@ parameter_types! { pub const MaximumBlockWeight: Weight = 4 * 1024 * 1024; pub const MaximumBlockLength: u32 = 4 * 1024 * 1024; pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75); + pub const Deposit: u64 = 1; + pub const ExistentialDeposit: u64 = 1; +} + +impl pallet_indices::Trait for Runtime { + type AccountIndex = u64; + type Currency = pallet_balances::Module; + type Deposit = Deposit; + type Event = MetaEvent; +} + +impl pallet_balances::Trait for Runtime { + type Balance = u64; + type DustRemoval = (); + type Event = MetaEvent; + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = frame_system::Module; } impl frame_system::Trait for Runtime { @@ -383,17 +399,23 @@ impl frame_system::Trait for Runtime { type BlockNumber = u64; type Hash = H256; type Hashing = BlakeTwo256; + #[cfg(feature = "indices-lookup")] + type AccountId = sp_core::crypto::AccountId32; + #[cfg(not(feature = "indices-lookup"))] type AccountId = u64; + #[cfg(feature = "indices-lookup")] + type Lookup = pallet_indices::Module; + #[cfg(not(feature = "indices-lookup"))] type Lookup = IdentityLookup; type Header = Header; - type Event = Event; + type Event = MetaEvent; type BlockHashCount = BlockHashCount; type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; type Version = (); type ModuleToIndex = (); - type AccountData = (); + type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); } From 26e21da60ed4ec330e93adae0fb74bda6c43f5fd Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 16 Mar 2020 16:45:15 +0100 Subject: [PATCH 07/77] WIP refactor node-template-runtime and node-runtime --- Cargo.lock | 5 + bin/node-template/node/Cargo.toml | 4 +- bin/node-template/node/src/command.rs | 33 +++- bin/node/cli/build.rs | 4 +- client/cli/Cargo.toml | 2 + client/cli/src/commands/generate.rs | 25 ++- client/cli/src/commands/generate_node_key.rs | 23 ++- client/cli/src/commands/insert.rs | 29 ++- client/cli/src/commands/inspect.rs | 29 ++- client/cli/src/commands/mod.rs | 73 +++++++- client/cli/src/commands/sign.rs | 43 +++-- client/cli/src/commands/sign_transaction.rs | 32 +++- client/cli/src/commands/tests.rs | 32 +++- client/cli/src/commands/transfer.rs | 27 ++- client/cli/src/commands/utils.rs | 55 ++++-- client/cli/src/commands/vanity.rs | 184 +++++++++++-------- client/cli/src/commands/verify.rs | 39 +++- frame/balances/src/lib.rs | 1 - test-utils/runtime/src/lib.rs | 2 +- 19 files changed, 477 insertions(+), 165 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 649f0877ce4f8..e95d89948a23b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3996,9 +3996,12 @@ dependencies = [ name = "node-template" version = "2.0.0-alpha.3" dependencies = [ + "frame-system", "futures 0.3.4", "log 0.4.8", "node-template-runtime", + "pallet-indices", + "pallet-transaction-payment", "sc-basic-authorship", "sc-cli", "sc-client", @@ -6148,6 +6151,7 @@ dependencies = [ "derive_more", "env_logger 0.7.1", "fdlimit", + "frame-support", "frame-system", "futures 0.1.29", "futures 0.3.4", @@ -6179,6 +6183,7 @@ dependencies = [ "sp-application-crypto", "sp-blockchain", "sp-core", + "sp-io", "sp-keyring", "sp-panic-handler", "sp-runtime", diff --git a/bin/node-template/node/Cargo.toml b/bin/node-template/node/Cargo.toml index 1e8c3fad2e3c0..69f429e718ab8 100644 --- a/bin/node-template/node/Cargo.toml +++ b/bin/node-template/node/Cargo.toml @@ -33,7 +33,9 @@ sc-client = { version = "0.8.0-alpha.2", path = "../../../client/" } sc-client-api = { version = "2.0.0-alpha.2", path = "../../../client/api" } sp-runtime = { version = "2.0.0-alpha.2", path = "../../../primitives/runtime" } sc-basic-authorship = { path = "../../../client/basic-authorship" , version = "0.8.0-alpha.2"} - +frame-system = { version = "2.0.0-alpha.3", path= "../../../frame/system" } +pallet-transaction-payment = { version = "2.0.0-alpha.3", path = "../../../frame/transaction-payment" } +pallet-indices = { version = "2.0.0-alpha.3", path = "../../../frame/indices" } node-template-runtime = { version = "2.0.0-alpha.2", path = "../runtime" } [build-dependencies] diff --git a/bin/node-template/node/src/command.rs b/bin/node-template/node/src/command.rs index 0f4c301dbff5b..363788cbc77b6 100644 --- a/bin/node-template/node/src/command.rs +++ b/bin/node-template/node/src/command.rs @@ -15,10 +15,33 @@ // along with Substrate. If not, see . use sp_consensus_aura::sr25519::{AuthorityPair as AuraPair}; -use sc_cli::VersionInfo; -use crate::service; -use crate::chain_spec; -use crate::cli::Cli; +use sc_cli::{VersionInfo, RuntimeAdapter}; +use node_template_runtime::{Runtime, SignedExtra, Index, Balance}; +use crate::{chain_spec, service, cli::Cli}; +use sp_runtime::{MultiSignature, MultiSigner, generic::Era, traits::StaticLookup}; +use sp_core::sr25519; + +struct Adapter; + +impl RuntimeAdapter for Adapter { + type Pair = sr25519::Pair; + type Public = sr25519::Public; + type Signature = MultiSignature; + type Runtime = Runtime; + type Extra = SignedExtra; + type Address = as StaticLookup>::Source; + + fn build_extra(index: Index) -> Self::Extra { + ( + frame_system::CheckVersion::new(), + frame_system::CheckGenesis::new(), + frame_system::CheckEra::from(Era::Immortal), + frame_system::CheckNonce::from(index), + frame_system::CheckWeight::new(), + pallet_transaction_payment::ChargeTransactionPayment::from(0), + ) + } +} /// Parse and run command line arguments pub fn run(version: VersionInfo) -> sc_cli::Result<()> { @@ -30,7 +53,7 @@ pub fn run(version: VersionInfo) -> sc_cli::Result<()> { Some(subcommand) => { subcommand.init(&version)?; subcommand.update_config(&mut config, chain_spec::load_spec, &version)?; - subcommand.run( + subcommand.run::( config, |config: _| Ok(new_full_start!(config).0), ) diff --git a/bin/node/cli/build.rs b/bin/node/cli/build.rs index e824b59be64f3..3f3c0b3427f2a 100644 --- a/bin/node/cli/build.rs +++ b/bin/node/cli/build.rs @@ -15,8 +15,8 @@ // along with Substrate. If not, see . fn main() { - #[cfg(feature = "cli")] - cli::main(); + // #[cfg(feature = "cli")] + // cli::main(); } #[cfg(feature = "cli")] diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index c3384109efab2..6f06940b1e47f 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -26,12 +26,14 @@ serde_json = "1.0.41" parity-scale-codec = "1.2.0" hex = "0.4.2" frame-system = { version = "2.0.0-alpha.3", path = "../../frame/system" } +frame-support = { version = "2.0.0-alpha.3", path = "../../frame/support" } pallet-balances = { version = "2.0.0-alpha.3", path = "../../frame/balances" } pallet-indices = { version = "2.0.0-alpha.3", path = "../../frame/indices" } pallet-transaction-payment = { version = "2.0.0-alpha.3", path = "../../frame/transaction-payment" } sc-informant = { version = "0.8.0-alpha.2", path = "../informant" } sp-panic-handler = { version = "2.0.0-alpha.2", path = "../../primitives/panic-handler" } sp-version = { version = "2.0.0-alpha.3", path = "../../primitives/version" } +sp-io = { version = "2.0.0-alpha.3", path = "../../primitives/io" } sc-client-api = { version = "2.0.0-alpha.2", path = "../api" } sp-blockchain = { version = "2.0.0-alpha.2", path = "../../primitives/blockchain" } sc-network = { version = "0.8.0-alpha.2", path = "../network" } diff --git a/client/cli/src/commands/generate.rs b/client/cli/src/commands/generate.rs index a102d092ccba5..078c11b8de342 100644 --- a/client/cli/src/commands/generate.rs +++ b/client/cli/src/commands/generate.rs @@ -20,6 +20,9 @@ use super::{SharedParams, RuntimeAdapter, get_password}; use crate::error::{self, Error}; use bip39::{MnemonicType, Mnemonic, Language}; use structopt::StructOpt; +use crate::{AccountIdFor, VersionInfo}; +use sp_core::crypto::{Ss58Codec, Derive}; +use sc_service::{Configuration, ChainSpec}; /// The `generate` command #[derive(Debug, StructOpt, Clone)] @@ -36,7 +39,10 @@ pub struct GenerateCmd { impl GenerateCmd { /// Run the command - pub fn run(self) -> error::Result<()> { + pub fn run(self) -> error::Result<()> + where + AccountIdFor: Ss58Codec + Derive, + { let words = match self.words { Some(words) => { MnemonicType::for_word_count(words) @@ -51,7 +57,7 @@ impl GenerateCmd { let maybe_network = self.shared_params.network; let output = self.shared_params.output_type; - C::print_from_uri( + RA::print_from_uri( mnemonic.phrase(), Some(password.as_str()), maybe_network, @@ -60,4 +66,19 @@ impl GenerateCmd { Ok(()) } + + /// Update and prepare a `Configuration` with command line parameters + pub fn update_config( + &self, + mut config: &mut Configuration, + spec_factory: F, + version: &VersionInfo, + ) -> error::Result<()> where + F: FnOnce(&str) -> Result, String>, + { + self.shared_params.update_config(&mut config, spec_factory, version)?; + config.use_in_memory_keystore()?; + + Ok(()) + } } diff --git a/client/cli/src/commands/generate_node_key.rs b/client/cli/src/commands/generate_node_key.rs index 5dae01812f86d..28892a014da78 100644 --- a/client/cli/src/commands/generate_node_key.rs +++ b/client/cli/src/commands/generate_node_key.rs @@ -16,11 +16,13 @@ //! Implementation of the `generate-node-key` subcommand -use crate::error; +use crate::{error, SharedParams, VersionInfo}; use structopt::StructOpt; use std::{path::PathBuf, fs}; use libp2p::identity::{ed25519 as libp2p_ed25519, PublicKey}; +use sc_service::{Configuration, ChainSpec}; +/// The `generate-node-key` command #[derive(Debug, StructOpt, Clone)] #[structopt( name = "generate-node-key", @@ -30,6 +32,10 @@ pub struct GenerateNodeKeyCmd { /// Name of file to save secret key to. #[structopt(long)] file: PathBuf, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, } impl GenerateNodeKeyCmd { @@ -47,4 +53,19 @@ impl GenerateNodeKeyCmd { Ok(()) } + + /// Update and prepare a `Configuration` with command line parameters + pub fn update_config( + &self, + mut config: &mut Configuration, + spec_factory: F, + version: &VersionInfo, + ) -> error::Result<()> where + F: FnOnce(&str) -> Result, String>, + { + self.shared_params.update_config(&mut config, spec_factory, version)?; + config.use_in_memory_keystore()?; + + Ok(()) + } } diff --git a/client/cli/src/commands/insert.rs b/client/cli/src/commands/insert.rs index 21f52cee3abb0..1790dafc6a005 100644 --- a/client/cli/src/commands/insert.rs +++ b/client/cli/src/commands/insert.rs @@ -16,8 +16,8 @@ //! Implementation of the `insert` subcommand -use crate::{error, HashFor}; -use super::{SharedParams, RunCmd, get_password, read_uri, RuntimeAdapter}; +use crate::{error, HashFor, VersionInfo}; +use super::{SharedParams, get_password, read_uri, RuntimeAdapter}; use structopt::StructOpt; use sp_core::{crypto::{KeyTypeId, Pair}, Bytes}; use std::convert::TryFrom; @@ -26,7 +26,9 @@ use hyper::rt; use sc_rpc::author::AuthorClient; use jsonrpc_core_client::transports::http; use serde::{de::DeserializeOwned, Serialize}; +use sc_service::{Configuration, ChainSpec}; +/// The `insert` command #[derive(Debug, StructOpt, Clone)] #[structopt( name = "insert", @@ -53,13 +55,13 @@ pub struct InsertCmd { } impl InsertCmd { - pub fn run(self) -> error::Result<()> + pub fn run(self) -> error::Result<()> where - HashFor: DeserializeOwned + Serialize + Send + Sync, + HashFor: DeserializeOwned + Serialize + Send + Sync, { let suri = read_uri(self.suri)?; let password = get_password(&self.shared_params)?; - let pair = C::pair_from_suri(&suri, &password); + let pair = RA::pair_from_suri(&suri, &password); let node_url = self.node_url.unwrap_or("http://localhost:9933".into()); let key_type = self.key_type; @@ -70,7 +72,7 @@ impl InsertCmd { })?; - insert_key::>( + insert_key::>( &node_url, key_type.to_string(), suri, @@ -79,6 +81,21 @@ impl InsertCmd { Ok(()) } + + /// Update and prepare a `Configuration` with command line parameters + pub fn update_config( + &self, + mut config: &mut Configuration, + spec_factory: F, + version: &VersionInfo, + ) -> error::Result<()> where + F: FnOnce(&str) -> Result, String>, + { + self.shared_params.update_config(&mut config, spec_factory, version)?; + config.use_in_memory_keystore()?; + + Ok(()) + } } fn insert_key(url: &str, key_type: String, suri: String, public: Bytes) diff --git a/client/cli/src/commands/inspect.rs b/client/cli/src/commands/inspect.rs index 1d84d906a7727..2ab02af3b5773 100644 --- a/client/cli/src/commands/inspect.rs +++ b/client/cli/src/commands/inspect.rs @@ -16,10 +16,13 @@ //! Implementation of the `inspect` subcommand -use crate::error; -use super::{SharedParams, RunCmd, get_password, read_uri, RuntimeAdapter}; +use crate::{error, AccountIdFor, VersionInfo}; +use super::{SharedParams, get_password, read_uri, RuntimeAdapter}; use structopt::StructOpt; +use sp_core::crypto::{Ss58Codec, Derive}; +use sc_service::{Configuration, ChainSpec}; +/// The `inspect` command #[derive(Debug, StructOpt, Clone)] #[structopt( name = "inspect", @@ -38,11 +41,14 @@ pub struct InspectCmd { } impl InspectCmd { - pub fn run(self) -> error::Result<()> { + pub fn run(self) -> error::Result<()> + where + AccountIdFor: Ss58Codec + Derive, + { let uri = read_uri(self.uri)?; let pass = get_password(&self.shared_params).ok(); - C::print_from_uri( + RA::print_from_uri( &uri, pass.as_ref().map(String::as_str), self.shared_params.network, @@ -51,5 +57,20 @@ impl InspectCmd { Ok(()) } + + /// Update and prepare a `Configuration` with command line parameters + pub fn update_config( + &self, + mut config: &mut Configuration, + spec_factory: F, + version: &VersionInfo, + ) -> error::Result<()> where + F: FnOnce(&str) -> Result, String>, + { + self.shared_params.update_config(&mut config, spec_factory, version)?; + config.use_in_memory_keystore()?; + + Ok(()) + } } diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 66bb91e205a56..39f90a8ae54eb 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -32,13 +32,13 @@ mod verify; mod vanity; mod insert; #[cfg(test)] -mod tests; +pub mod tests; -use std::fmt::Debug; +use std::fmt::{Debug, Display}; use structopt::StructOpt; use sc_service::{ Configuration, ServiceBuilderCommand, ChainSpec }; -use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; +use sp_runtime::traits::{Block as BlockT, Header as HeaderT, IdentifyAccount}; use crate::error; use crate::VersionInfo; @@ -60,6 +60,9 @@ pub use crate::commands::sign_transaction::SignTransactionCmd; pub use crate::commands::transfer::TransferCmd; pub use crate::commands::vanity::VanityCmd; pub use crate::commands::verify::VerifyCmd; +use sp_core::crypto::{Ss58Codec, Derive}; +use std::str::FromStr; +use parity_scale_codec::{Codec, WrapperTypeEncode}; /// default sub directory to store network config @@ -90,8 +93,29 @@ pub enum Subcommand { /// Remove the whole chain data. PurgeChain(purge_chain_cmd::PurgeChainCmd), - // Generate a key for a node - // GenerateNodeKey(generate_node_key::GenerateNodeKeyCmd), + /// Generate a random node libp2p key, save it to file and print its peer ID + GenerateNodeKey(generate_node_key::GenerateNodeKeyCmd), + + /// Generate a random account + Generate(generate::GenerateCmd), + + /// Gets a public key and a SS58 address from the provided Secret URI + Inspect(inspect::InspectCmd), + + /// Insert a key to the keystore of a node. + Insert(insert::InsertCmd), + + /// Sign a message, with a given (secret) key + Sign(sign::SignCmd), + + /// Sign transaction from encoded Call. Returns a signed and encoded UncheckedMortalCompactExtrinsic as hex. + SignTransaction(sign_transaction::SignTransactionCmd), + + /// Verify a signature for a message, provided on STDIN, with a given (public or secret) key. + Verify(verify::VerifyCmd), + + /// Generate a seed that provides a vanity address. + Vanity(vanity::VanityCmd), } impl Subcommand { @@ -106,21 +130,34 @@ impl Subcommand { CheckBlock(params) => ¶ms.shared_params, Revert(params) => ¶ms.shared_params, PurgeChain(params) => ¶ms.shared_params, + GenerateNodeKey(params) => ¶ms.shared_params, + Generate(params) => ¶ms.shared_params, + Inspect(params) => ¶ms.shared_params, + Insert(params) => ¶ms.shared_params, + Sign(params) => ¶ms.shared_params, + SignTransaction(params) => ¶ms.shared_params, + Verify(params) => ¶ms.shared_params, + Vanity(params) => ¶ms.shared_params, } } /// Run any `CoreParams` command - pub fn run( + pub fn run( self, config: Configuration, builder: B, ) -> error::Result<()> where B: FnOnce(Configuration) -> Result, - BC: ServiceBuilderCommand + Unpin, - BB: sp_runtime::traits::Block + Debug, - <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, - ::Hash: std::str::FromStr, + BC: ServiceBuilderCommand + Unpin, + Block: BlockT + Debug, + <::Number as std::str::FromStr>::Err: std::fmt::Debug, + Block::Hash: std::str::FromStr, + RA: RuntimeAdapter, + AccountIdFor: Ss58Codec + Derive, + as FromStr>::Err: Display, + CallFor: Codec + WrapperTypeEncode, + RA::Address: From<::AccountId>, { match self { Subcommand::BuildSpec(cmd) => cmd.run(config), @@ -129,6 +166,14 @@ impl Subcommand { Subcommand::CheckBlock(cmd) => cmd.run(config, builder), Subcommand::PurgeChain(cmd) => cmd.run(config), Subcommand::Revert(cmd) => cmd.run(config, builder), + Subcommand::GenerateNodeKey(cmd) => cmd.run(), + Subcommand::Generate(cmd) => cmd.run::(), + Subcommand::Inspect(cmd) => cmd.run::(), + Subcommand::Insert(cmd) => cmd.run::(), + Subcommand::Sign(cmd) => cmd.run::(), + Subcommand::SignTransaction(cmd) => cmd.run::(), + Subcommand::Verify(cmd) => cmd.run::(), + Subcommand::Vanity(cmd) => cmd.run::(), } } @@ -148,6 +193,14 @@ impl Subcommand { Subcommand::CheckBlock(cmd) => cmd.update_config(&mut config, spec_factory, version), Subcommand::PurgeChain(cmd) => cmd.update_config(&mut config, spec_factory, version), Subcommand::Revert(cmd) => cmd.update_config(&mut config, spec_factory, version), + Subcommand::GenerateNodeKey(cmd) => cmd.update_config(&mut config, spec_factory, version), + Subcommand::Generate(cmd) => cmd.update_config(&mut config, spec_factory, version), + Subcommand::Inspect(cmd) => cmd.update_config(&mut config, spec_factory, version), + Subcommand::Insert(cmd) => cmd.update_config(&mut config, spec_factory, version), + Subcommand::Sign(cmd) => cmd.update_config(&mut config, spec_factory, version), + Subcommand::SignTransaction(cmd) => cmd.update_config(&mut config, spec_factory, version), + Subcommand::Verify(cmd) => cmd.update_config(&mut config, spec_factory, version), + Subcommand::Vanity(cmd) => cmd.update_config(&mut config, spec_factory, version), } } diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs index 3cc0026488e67..23430159fa37d 100644 --- a/client/cli/src/commands/sign.rs +++ b/client/cli/src/commands/sign.rs @@ -15,18 +15,18 @@ // along with Substrate. If not, see . //! Implementation of the `sign` subcommand -use crate::error; -use super::{SharedParams, decode_hex, get_password, read_message_from_stdin, read_uri, RuntimeAdapter}; +use crate::{error, VersionInfo}; +use super::{SharedParams, get_password, read_message, read_uri, RuntimeAdapter}; use structopt::StructOpt; use sp_core::crypto::Pair; +use sc_service::{Configuration, ChainSpec}; -type Bytes = Vec; - +/// The `sign` command #[derive(Debug, StructOpt, Clone)] #[structopt( name = "sign", - about = "Sign a message, provided on STDIN, with a given (secret) key" + about = "Sign a message, with a given (secret) key" )] pub struct SignCmd { /// The secret key URI. @@ -35,9 +35,14 @@ pub struct SignCmd { #[structopt(long)] suri: Option, - /// Hex encoded message to sign - #[structopt(long, parse(try_from_str = decode_hex))] - message: Bytes, + /// Message to sign, if not provided you will be prompted to + /// pass the message via STDIN + #[structopt(long)] + message: Option, + + /// The message on STDIN is hex-encoded data + #[structopt(long)] + hex: bool, #[allow(missing_docs)] #[structopt(flatten)] @@ -46,12 +51,28 @@ pub struct SignCmd { impl SignCmd { - pub fn run(self) -> error::Result<()> { + pub fn run(self) -> error::Result<()> { + let message = read_message(self.message, self.hex)?; let suri = read_uri(self.suri)?; let password = get_password(&self.shared_params)?; - let pair = C::pair_from_suri(&suri, &password); - let signature = format!("{}", hex::encode(pair.sign(&self.message))); + let pair = RA::pair_from_suri(&suri, &password); + let signature = format!("{}", hex::encode(pair.sign(&message))); println!("{}", signature); Ok(()) } + + /// Update and prepare a `Configuration` with command line parameters + pub fn update_config( + &self, + mut config: &mut Configuration, + spec_factory: F, + version: &VersionInfo, + ) -> error::Result<()> where + F: FnOnce(&str) -> Result, String>, + { + self.shared_params.update_config(&mut config, spec_factory, version)?; + config.use_in_memory_keystore()?; + + Ok(()) + } } diff --git a/client/cli/src/commands/sign_transaction.rs b/client/cli/src/commands/sign_transaction.rs index 551d1821155b9..885ba88d89dab 100644 --- a/client/cli/src/commands/sign_transaction.rs +++ b/client/cli/src/commands/sign_transaction.rs @@ -15,18 +15,20 @@ // along with Substrate. If not, see . //! Implementation of the `sign-transaction` subcommand -use crate::error; +use crate::{error, VersionInfo}; use super::{ - SharedParams, get_password, decode_hex, - create_extrinsic_for, RuntimeAdapter, IndexFor, CallFor, + SharedParams, get_password, decode_hex, create_extrinsic_for, + RuntimeAdapter, IndexFor, CallFor, }; use structopt::StructOpt; -use parity_scale_codec::{Decode, Encode, WrapperTypeEncode}; -use std::str::FromStr; -use std::fmt::Display; +use parity_scale_codec::{WrapperTypeEncode, Codec, Encode, Decode}; +use std::{str::FromStr, fmt::Display}; +use sp_runtime::traits::IdentifyAccount; +use sc_service::{Configuration, ChainSpec}; type Call = Vec; +/// The `sign-transaction` command #[derive(Debug, StructOpt, Clone)] #[structopt( name = "sign-transaction", @@ -54,7 +56,8 @@ impl SignTransactionCmd { pub fn run(self) -> error::Result<()> where as FromStr>::Err: Display, - CallFor: Encode + Decode + WrapperTypeEncode, + CallFor: Codec + WrapperTypeEncode, + RA::Address: From<::AccountId>, { let signer = RA::pair_from_suri(&self.suri, &get_password(&self.shared_params)?); @@ -66,4 +69,19 @@ impl SignTransactionCmd { Ok(()) } + + /// Update and prepare a `Configuration` with command line parameters + pub fn update_config( + &self, + mut config: &mut Configuration, + spec_factory: F, + version: &VersionInfo, + ) -> error::Result<()> where + F: FnOnce(&str) -> Result, String>, + { + self.shared_params.update_config(&mut config, spec_factory, version)?; + config.use_in_memory_keystore()?; + + Ok(()) + } } diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs index f4883d6481f2f..9cac36a9dbc28 100644 --- a/client/cli/src/commands/tests.rs +++ b/client/cli/src/commands/tests.rs @@ -17,7 +17,7 @@ use super::*; use substrate_test_runtime::{AccountSignature, Runtime}; use sp_core::sr25519; -use sp_runtime::{MultiSignature, MultiSigner}; + use sp_runtime::generic::Era; use sp_runtime::traits::StaticLookup; use tempfile::Builder; @@ -52,6 +52,14 @@ impl RuntimeAdapter for Adapter { } } +fn new_test_ext() -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + pallet_balances::GenesisConfig::{ + balances: vec![], + }.assimilate_storage(&mut t).unwrap(); + sp_io::TestExternalities::new(t) +} + #[test] fn generate() { let generate = GenerateCmd::from_iter(&["generate", "--password", "12345"]); @@ -81,9 +89,6 @@ fn inspect() { let inspect = InspectCmd::from_iter(&["inspect", "--uri", seed]); assert!(inspect.run::().is_ok()); - - let inspect = InspectCmd::from_iter(&["inspect", "--uri", words]); - assert!(matches!(inspect.run::(), Err(Error::Input(_)))) } #[test] @@ -98,10 +103,16 @@ fn sign() { assert!(matches!(sign.run::(), Err(Error::Input(_)))) } +#[test] +fn vanity() { + let vanity = VanityCmd::from_iter(&["vanity", "--number", "1", "--pattern", "j"]); + assert!(vanity.run::().is_ok()); +} #[test] fn transfer() { let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; + let words = "remember fiber forum demise paper uniform squirrel feel access exclude casual effort"; let transfer = TransferCmd::from_iter(&["transfer", "--from", seed, @@ -110,8 +121,15 @@ fn transfer() { "--index", "1", "--password", "12345", ]); - // println!("{:?}", transfer.run::()); - // let transfer = TransferCmd::from_iter(&["transfer", "--suri", words, "--message", &seed[2..]]); - // assert!(matches!(transfer.run::(), Err(Error::Input(_)))) + new_test_ext().execute_with(|| { + assert!(matches!(transfer.run::(), Ok(()))); + let transfer = TransferCmd::from_iter(&["transfer", + "--from", words, + "--to", "0xa2bc899a8a3b16a284a8cefcbc2dc48a687cd674e89b434fbbdb06f400979744", + "--amount", "5000", + "--index", "1", + ]); + assert!(matches!(transfer.run::(), Err(Error::Input(_)))) + }); } \ No newline at end of file diff --git a/client/cli/src/commands/transfer.rs b/client/cli/src/commands/transfer.rs index 3c74f75bf1c04..c6741cba245e3 100644 --- a/client/cli/src/commands/transfer.rs +++ b/client/cli/src/commands/transfer.rs @@ -14,15 +14,18 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -//! Implementation of the `sign` subcommand -use crate::{error, IndexFor, BalanceFor, create_extrinsic_for, get_password, AddressFor}; +//! Implementation of the `transfer` subcommand + +use crate::{error, IndexFor, BalanceFor, create_extrinsic_for, get_password, AddressFor, VersionInfo}; use super::{SharedParams, RuntimeAdapter}; use structopt::StructOpt; use pallet_balances::Call as BalancesCall; -use std::str::FromStr; +use std::{str::FromStr, fmt::Display}; use parity_scale_codec::{Encode, Decode}; -use std::fmt::Display; +use sp_runtime::traits::IdentifyAccount; +use sc_service::{Configuration, ChainSpec}; +/// The `transfer` command #[derive(Debug, StructOpt, Clone)] #[structopt( name = "transfer", @@ -58,6 +61,7 @@ impl TransferCmd { as FromStr>::Err: Display, as FromStr>::Err: Display, BalancesCall: Encode, + RA::Address: From<::AccountId>, { let password = get_password(&self.shared_params)?; let nonce = IndexFor::::from_str(&self.index).map_err(|e| format!("{}", e))?; @@ -72,4 +76,19 @@ impl TransferCmd { Ok(()) } + + /// Update and prepare a `Configuration` with command line parameters + pub fn update_config( + &self, + mut config: &mut Configuration, + spec_factory: F, + version: &VersionInfo, + ) -> error::Result<()> where + F: FnOnce(&str) -> Result, String>, + { + self.shared_params.update_config(&mut config, spec_factory, version)?; + config.use_in_memory_keystore()?; + + Ok(()) + } } diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index a0b07f4e7f078..110a609744a0a 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -16,14 +16,16 @@ //! subcommand utilities use std::{io::Read, path::PathBuf}; -use sp_core::{Pair, Public, crypto::{Ss58Codec, Ss58AddressFormat}, hexdisplay::HexDisplay}; +use sp_core::{Pair, Public, crypto::{Ss58Codec,Derive, Ss58AddressFormat}, hexdisplay::HexDisplay}; use sp_runtime::{ MultiSignature, MultiSigner, generic::{UncheckedExtrinsic, SignedPayload}, traits::IdentifyAccount, AccountId32, }; use parity_scale_codec::{Encode, Decode}; use serde_json::json; -use sp_runtime::traits::{SignedExtension, StaticLookup}; +use sp_runtime::traits::{ + SignedExtension, StaticLookup, +}; use crate::{error::{self, Error}, SharedParams, arg_enums::OutputType}; /// Public key type for Runtime @@ -32,6 +34,8 @@ pub type PublicFor = <::Pair as Pair>::Public; pub type SeedFor = <::Pair as Pair>::Seed; /// AccountIndex type for Runtime pub type IndexFor = <::Runtime as frame_system::Trait>::Index; +/// AccountId type for Runtime +pub type AccountIdFor = <::Runtime as frame_system::Trait>::AccountId; /// Balance type pub type BalanceFor = <::Runtime as pallet_balances::Trait>::Balance; /// Call type for Runtime @@ -46,15 +50,15 @@ pub trait RuntimeAdapter: Sized { /// Pair type type Pair: Pair; /// public type - type Public: Public + Into + Ss58Codec + AsRef<[u8]> + std::hash::Hash; + type Public: Public + IdentifyAccount> + std::hash::Hash + Ss58Codec; /// signature type - type Signature: Into + AsRef<[u8]> + AsMut<[u8]> + Encode + Default; + type Signature: AsRef<[u8]> + AsMut<[u8]> + Encode + Default; /// runtime type Runtime: frame_system::Trait + pallet_balances::Trait + pallet_indices::Trait; /// extras type Extra: SignedExtension; /// Address type - type Address: Encode + Decode + From; + type Address: Encode + Decode; /// generate a pair from suri fn pair_from_suri(suri: &str, password: &str) -> Self::Pair { @@ -62,9 +66,11 @@ pub trait RuntimeAdapter: Sized { } /// generate an ss58 encoded address from pair - fn ss58_from_pair(pair: &Self::Pair) -> String { - let public: MultiSigner = pair.public().into(); - public.into_account().to_ss58check() + fn ss58_from_pair(pair: &Self::Pair) -> String + where + AccountIdFor: Ss58Codec, + { + pair.public().into_account().to_ss58check() } /// print formatted pair from uri @@ -73,7 +79,10 @@ pub trait RuntimeAdapter: Sized { password: Option<&str>, network_override: Ss58AddressFormat, output: OutputType, - ) { + ) + where + AccountIdFor: Ss58Codec + Derive, + { if let Ok((pair, seed)) = Self::Pair::from_phrase(uri, password) { let public_key = pair.public(); @@ -212,8 +221,11 @@ fn format_public_key(public_key: PublicFor) -> String { } /// formats public key as accountId as hex -fn format_account_id(public_key: PublicFor) -> String { - format!("0x{}", HexDisplay::from(&public_key.into().into_account().as_ref())) +fn format_account_id(public_key: PublicFor) -> String + where + AccountIdFor: AsRef<[u8]>, +{ + format!("0x{}", HexDisplay::from(&public_key.into_account().as_ref())) } /// helper method for decoding hex @@ -222,12 +234,19 @@ pub fn decode_hex>(message: T) -> Result, Error> { .map_err(|e| Error::Other(format!("Invalid hex ({})", e))) } -/// reads input from stdin, optionally decodes hex to bytes. -pub fn read_message_from_stdin(should_decode: bool) -> Result, Error> { +/// checks if message is Some, otherwise reads message from stdin and optionally decodes hex +pub fn read_message(msg: Option, should_decode: bool) -> Result, Error> { let mut message = vec![]; - std::io::stdin().lock().read_to_end(&mut message)?; - if should_decode { - message = decode_hex(&message)?; + match msg { + Some(m) => { + message = decode_hex(&m)?; + }, + None => { + std::io::stdin().lock().read_to_end(&mut message)?; + if should_decode { + message = decode_hex(&message)?; + } + } } Ok(message) } @@ -240,14 +259,14 @@ pub fn create_extrinsic_for( ) -> Result, Error> where Call: Encode, - RA::Address: From, + RA::Address: From<::AccountId>, { let extra = RA::build_extra(nonce); let payload = SignedPayload::new(call, extra) .map_err(|_| Error::Other("Transaction validity error".into()))?; let signature = payload.using_encoded(|payload| signer.sign(payload)); - let signer = signer.public().into().into_account().into(); + let signer = signer.public().into_account().into(); let (function, extra, _) = payload.deconstruct(); Ok(UncheckedExtrinsic::new_signed( diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index b28dae7ba2d72..1bbe1dbeb5b2b 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -14,13 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -//! implementation of the `verify` subcommand -use crate::{RuntimeAdapter, read_message_from_stdin, decode_hex, read_uri, error, format_seed, SharedParams}; -use sp_core::{Pair, Public, crypto::Ss58Codec}; +//! implementation of the `vanity` subcommand + +use crate::{RuntimeAdapter, error, format_seed, SharedParams, AccountIdFor, VersionInfo}; +use sp_core::{Pair, crypto::{Ss58Codec, Derive}}; use structopt::StructOpt; use rand::{rngs::OsRng, RngCore}; +use sc_service::{Configuration, ChainSpec}; - +/// The `vanity` command #[derive(Debug, StructOpt, Clone)] #[structopt( name = "vanity", @@ -41,17 +43,40 @@ pub struct VanityCmd { } impl VanityCmd { - pub fn run(self) -> error::Result<()> { + pub fn run(self) -> error::Result<()> + where + RA: RuntimeAdapter, + AccountIdFor: Ss58Codec + Derive, + { let desired: String = self.pattern.unwrap_or_default(); let result = generate_key::(&desired)?; let formated_seed = format_seed::(result.seed); RA::print_from_uri(&formated_seed, None, self.shared_params.network, self.shared_params.output_type); Ok(()) } + + /// Update and prepare a `Configuration` with command line parameters + pub fn update_config( + &self, + mut config: &mut Configuration, + spec_factory: F, + version: &VersionInfo, + ) -> error::Result<()> where + F: FnOnce(&str) -> Result, String>, + { + self.shared_params.update_config(&mut config, spec_factory, version)?; + config.use_in_memory_keystore()?; + + Ok(()) + } } /// genertae a key based on given pattern -fn generate_key(desired: &str) -> Result, &'static str> where { +fn generate_key(desired: &str) -> Result, &'static str> + where + RA: RuntimeAdapter, + AccountIdFor: Ss58Codec + Derive, +{ if desired.is_empty() { return Err("Pattern must not be empty"); } @@ -60,7 +85,7 @@ fn generate_key(desired: &str) -> Result, &'static let top = 45 + (desired.len() * 48); let mut best = 0; - let mut seed = ::Seed::default(); + let mut seed = ::Seed::default(); let mut done = 0; loop { @@ -70,8 +95,8 @@ fn generate_key(desired: &str) -> Result, &'static next_seed(seed.as_mut()); } - let p = C::Pair::from_seed(&seed); - let ss58 = C::ss58_from_pair(&p); + let p = RA::Pair::from_seed(&seed); + let ss58 = RA::ss58_from_pair(&p); let score = calculate_score(&desired, &ss58); if score > best || desired.len() < 2 { best = score; @@ -118,9 +143,9 @@ fn next_seed(seed: &mut [u8]) { /// A structure used to carry both Pair and seed. /// This should usually NOT been used. If unsure, use Pair. -struct KeyPair { - pub pair: R::Pair, - pub seed: ::Seed, +struct KeyPair { + pub pair: P, + pub seed:

::Seed, pub score: usize, } @@ -138,70 +163,71 @@ fn calculate_score(_desired: &str, key: &str) -> usize { } -// #[cfg(test)] -// mod tests { -// use super::*; -// use sp_core::{crypto::Ss58Codec, Pair}; -// #[cfg(feature = "bench")] -// use test::Bencher; -// -// #[test] -// fn test_generation_with_single_char() { -// assert!(generate_key::("j") -// .unwrap() -// .pair -// .public() -// .to_ss58check() -// .contains("j")); -// } -// -// #[test] -// fn test_score_1_char_100() { -// let score = calculate_score("j", "5jolkadotwHY5k9GpdTgpqs9xjuNvtv8EcwCFpEeyEf3KHim"); -// assert_eq!(score, 94); -// } -// -// #[test] -// fn test_score_100() { -// let score = calculate_score( -// "Polkadot", -// "5PolkadotwHY5k9GpdTgpqs9xjuNvtv8EcwCFpEeyEf3KHim", -// ); -// assert_eq!(score, 430); -// } -// -// #[test] -// fn test_score_50_2() { -// // 50% for the position + 50% for the size -// assert_eq!( -// calculate_score( -// "Polkadot", -// "5PolkXXXXwHY5k9GpdTgpqs9xjuNvtv8EcwCFpEeyEf3KHim" -// ), -// 238 -// ); -// } -// -// #[test] -// fn test_score_0() { -// assert_eq!( -// calculate_score( -// "Polkadot", -// "5GUWv4bLCchGUHJrzULXnh4JgXsMpTKRnjuXTY7Qo1Kh9uYK" -// ), -// 0 -// ); -// } -// -// #[cfg(feature = "bench")] -// #[bench] -// fn bench_paranoiac(b: &mut Bencher) { -// b.iter(|| generate_key("polk")); -// } -// -// #[cfg(feature = "bench")] -// #[bench] -// fn bench_not_paranoiac(b: &mut Bencher) { -// b.iter(|| generate_key("polk")); -// } -// } +#[cfg(test)] +mod tests { + use super::*; + use sp_core::{crypto::Ss58Codec, Pair}; + use crate::commands::tests::Adapter; + #[cfg(feature = "bench")] + use test::Bencher; + + #[test] + fn test_generation_with_single_char() { + assert!(generate_key::("j") + .unwrap() + .pair + .public() + .to_ss58check() + .contains("j")); + } + + #[test] + fn test_score_1_char_100() { + let score = calculate_score("j", "5jolkadotwHY5k9GpdTgpqs9xjuNvtv8EcwCFpEeyEf3KHim"); + assert_eq!(score, 94); + } + + #[test] + fn test_score_100() { + let score = calculate_score( + "Polkadot", + "5PolkadotwHY5k9GpdTgpqs9xjuNvtv8EcwCFpEeyEf3KHim", + ); + assert_eq!(score, 430); + } + + #[test] + fn test_score_50_2() { + // 50% for the position + 50% for the size + assert_eq!( + calculate_score( + "Polkadot", + "5PolkXXXXwHY5k9GpdTgpqs9xjuNvtv8EcwCFpEeyEf3KHim" + ), + 238 + ); + } + + #[test] + fn test_score_0() { + assert_eq!( + calculate_score( + "Polkadot", + "5GUWv4bLCchGUHJrzULXnh4JgXsMpTKRnjuXTY7Qo1Kh9uYK" + ), + 0 + ); + } + + #[cfg(feature = "bench")] + #[bench] + fn bench_paranoiac(b: &mut Bencher) { + b.iter(|| generate_key("polk")); + } + + #[cfg(feature = "bench")] + #[bench] + fn bench_not_paranoiac(b: &mut Bencher) { + b.iter(|| generate_key("polk")); + } +} diff --git a/client/cli/src/commands/verify.rs b/client/cli/src/commands/verify.rs index 4cf8cb371a8fd..26eec55a95abf 100644 --- a/client/cli/src/commands/verify.rs +++ b/client/cli/src/commands/verify.rs @@ -15,10 +15,13 @@ // along with Substrate. If not, see . //! implementation of the `verify` subcommand -use crate::{RuntimeAdapter, read_message_from_stdin, decode_hex, read_uri, error}; + +use crate::{RuntimeAdapter, read_message, decode_hex, read_uri, error, SharedParams, VersionInfo}; use sp_core::{Pair, Public, crypto::Ss58Codec}; use structopt::StructOpt; +use sc_service::{Configuration, ChainSpec}; +/// The `verify` command #[derive(Debug, StructOpt, Clone)] #[structopt( name = "verify", @@ -35,15 +38,24 @@ pub struct VerifyCmd { #[structopt(long)] uri: Option, + /// Message to verify, if not provided you will be prompted to + /// pass the message via STDIN + #[structopt(long)] + message: Option, + /// The message on STDIN is hex-encoded data #[structopt(long)] hex: bool, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, } impl VerifyCmd { pub fn run(self) -> error::Result<()> { - let message = read_message_from_stdin(self.hex)?; - let mut signature = <::Pair as Pair>::Signature::default(); + let message = read_message(self.message, self.hex)?; + let mut signature = ::Signature::default(); let sig_data = decode_hex(self.sig)?; if sig_data.len() != signature.as_ref().len() { @@ -63,14 +75,14 @@ impl VerifyCmd { }; let pubkey = if let Ok(pubkey_vec) = hex::decode(uri) { - ::Public::from_slice(pubkey_vec.as_slice()) + RA::Public::from_slice(pubkey_vec.as_slice()) } else { - ::Public::from_string(uri) + RA::Public::from_string(uri) .ok() .expect("Invalid URI; expecting either a secret URI or a public URI.") }; - if <::Pair as Pair>::verify(&signature, &message, &pubkey) { + if ::verify(&signature, &message, &pubkey) { println!("Signature verifies correctly."); } else { return Err(error::Error::Other("Signature invalid.".into())) @@ -78,4 +90,19 @@ impl VerifyCmd { Ok(()) } + + /// Update and prepare a `Configuration` with command line parameters + pub fn update_config( + &self, + mut config: &mut Configuration, + spec_factory: F, + version: &VersionInfo, + ) -> error::Result<()> where + F: FnOnce(&str) -> Result, String>, + { + self.shared_params.update_config(&mut config, spec_factory, version)?; + config.use_in_memory_keystore()?; + + Ok(()) + } } diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index df219be0e5ef8..f27eed0aed873 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -160,7 +160,6 @@ mod benchmarking; use sp_std::prelude::*; use sp_std::{cmp, result, mem, fmt::Debug, ops::BitOr, convert::Infallible}; -use sp_io::hashing::twox_64; use codec::{Codec, Encode, Decode}; use frame_support::{ StorageValue, Parameter, decl_event, decl_storage, decl_module, decl_error, ensure, diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index ee9d1700894de..4f9723683cb3c 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -400,7 +400,7 @@ impl frame_system::Trait for Runtime { type Hash = H256; type Hashing = BlakeTwo256; #[cfg(feature = "indices-lookup")] - type AccountId = sp_core::crypto::AccountId32; + type AccountId = sr25519::Public; #[cfg(not(feature = "indices-lookup"))] type AccountId = u64; #[cfg(feature = "indices-lookup")] From aea449b006fb4f3f5dcb97f7c117f49819e9d568 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 17 Mar 2020 13:33:39 +0100 Subject: [PATCH 08/77] implments sc_cli::RuntimeAdapter for node_template_runtime::Runtime --- bin/node-template/node/src/cli.rs | 26 ++++- bin/node-template/node/src/command.rs | 29 +----- bin/node-template/runtime/src/lib.rs | 6 +- bin/node/cli/Cargo.toml | 106 ++++++++++---------- bin/node/cli/src/command.rs | 32 +++++- client/cli/src/commands/insert.rs | 1 + client/cli/src/commands/inspect.rs | 1 + client/cli/src/commands/mod.rs | 14 ++- client/cli/src/commands/sign.rs | 1 + client/cli/src/commands/sign_transaction.rs | 10 +- client/cli/src/commands/tests.rs | 1 - client/cli/src/commands/transfer.rs | 8 +- client/cli/src/commands/utils.rs | 21 ++-- client/cli/src/commands/vanity.rs | 1 + client/cli/src/commands/verify.rs | 1 + frame/balances/src/lib.rs | 4 - primitives/runtime/src/lib.rs | 2 +- test-utils/runtime/src/lib.rs | 2 +- 18 files changed, 144 insertions(+), 122 deletions(-) diff --git a/bin/node-template/node/src/cli.rs b/bin/node-template/node/src/cli.rs index 0091ef7d75912..25506a192ac76 100644 --- a/bin/node-template/node/src/cli.rs +++ b/bin/node-template/node/src/cli.rs @@ -1,5 +1,8 @@ -use sc_cli::{RunCmd, Subcommand}; use structopt::StructOpt; +use sc_cli::{RunCmd, Subcommand, RuntimeAdapter}; +use node_template_runtime::{Runtime, SignedExtra, Index}; +use sp_runtime::generic::Era; +use sp_core::sr25519; #[derive(Debug, StructOpt)] pub struct Cli { @@ -9,3 +12,24 @@ pub struct Cli { #[structopt(flatten)] pub run: RunCmd, } + +pub struct Adapter; + +impl RuntimeAdapter for Adapter { + type Pair = sr25519::Pair; + type Public = sr25519::Public; + type Signature = sr25519::Signature; + type Runtime = Runtime; + type Extra = SignedExtra; + + fn build_extra(index: Index) -> Self::Extra { + ( + frame_system::CheckVersion::new(), + frame_system::CheckGenesis::new(), + frame_system::CheckEra::from(Era::Immortal), + frame_system::CheckNonce::from(index), + frame_system::CheckWeight::new(), + pallet_transaction_payment::ChargeTransactionPayment::from(0), + ) + } +} diff --git a/bin/node-template/node/src/command.rs b/bin/node-template/node/src/command.rs index 363788cbc77b6..24467e7ca285f 100644 --- a/bin/node-template/node/src/command.rs +++ b/bin/node-template/node/src/command.rs @@ -15,33 +15,8 @@ // along with Substrate. If not, see . use sp_consensus_aura::sr25519::{AuthorityPair as AuraPair}; -use sc_cli::{VersionInfo, RuntimeAdapter}; -use node_template_runtime::{Runtime, SignedExtra, Index, Balance}; -use crate::{chain_spec, service, cli::Cli}; -use sp_runtime::{MultiSignature, MultiSigner, generic::Era, traits::StaticLookup}; -use sp_core::sr25519; - -struct Adapter; - -impl RuntimeAdapter for Adapter { - type Pair = sr25519::Pair; - type Public = sr25519::Public; - type Signature = MultiSignature; - type Runtime = Runtime; - type Extra = SignedExtra; - type Address = as StaticLookup>::Source; - - fn build_extra(index: Index) -> Self::Extra { - ( - frame_system::CheckVersion::new(), - frame_system::CheckGenesis::new(), - frame_system::CheckEra::from(Era::Immortal), - frame_system::CheckNonce::from(index), - frame_system::CheckWeight::new(), - pallet_transaction_payment::ChargeTransactionPayment::from(0), - ) - } -} +use sc_cli::VersionInfo; +use crate::{chain_spec, service, cli::{Cli, Adapter}}; /// Parse and run command line arguments pub fn run(version: VersionInfo) -> sc_cli::Result<()> { diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index 0414759a5ad86..cb3f630925150 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -9,10 +9,10 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); use sp_std::prelude::*; -use sp_core::OpaqueMetadata; +use sp_core::{OpaqueMetadata, sr25519}; use sp_runtime::{ ApplyExtrinsicResult, transaction_validity::TransactionValidity, generic, create_runtime_str, - impl_opaque_keys, MultiSignature, + impl_opaque_keys, }; use sp_runtime::traits::{ BlakeTwo256, Block as BlockT, IdentityLookup, Verify, ConvertInto, IdentifyAccount @@ -44,7 +44,7 @@ pub use template; pub type BlockNumber = u32; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. -pub type Signature = MultiSignature; +pub type Signature = sr25519::Signature; /// Some way of identifying an account on the chain. We intentionally make it equivalent /// to the public key of our transaction signing scheme. diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index e18b6b228e655..0a2fb81d7fdd2 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -42,68 +42,68 @@ structopt = { version = "0.3.8", optional = true } tracing = "0.1.10" # primitives -sp-authority-discovery = { version = "2.0.0-alpha.2", path = "../../../primitives/authority-discovery" } -sp-consensus-babe = { version = "0.8.0-alpha.2", path = "../../../primitives/consensus/babe" } -grandpa-primitives = { version = "2.0.0-alpha.2", package = "sp-finality-grandpa", path = "../../../primitives/finality-grandpa" } -sp-core = { version = "2.0.0-alpha.2", path = "../../../primitives/core" } -sp-runtime = { version = "2.0.0-alpha.2", path = "../../../primitives/runtime" } -sp-timestamp = { version = "2.0.0-alpha.2", default-features = false, path = "../../../primitives/timestamp" } -sp-finality-tracker = { version = "2.0.0-alpha.2", default-features = false, path = "../../../primitives/finality-tracker" } -sp-inherents = { version = "2.0.0-alpha.2", path = "../../../primitives/inherents" } -sp-keyring = { version = "2.0.0-alpha.2", path = "../../../primitives/keyring" } -sp-io = { version = "2.0.0-alpha.2", path = "../../../primitives/io" } -sp-consensus = { version = "0.8.0-alpha.2", path = "../../../primitives/consensus/common" } +sp-authority-discovery = { version = "2.0.0-alpha.3", path = "../../../primitives/authority-discovery" } +sp-consensus-babe = { version = "0.8.0-alpha.3", path = "../../../primitives/consensus/babe" } +grandpa-primitives = { version = "2.0.0-alpha.3", package = "sp-finality-grandpa", path = "../../../primitives/finality-grandpa" } +sp-core = { version = "2.0.0-alpha.3", path = "../../../primitives/core" } +sp-runtime = { version = "2.0.0-alpha.3", path = "../../../primitives/runtime" } +sp-timestamp = { version = "2.0.0-alpha.3", default-features = false, path = "../../../primitives/timestamp" } +sp-finality-tracker = { version = "2.0.0-alpha.3", default-features = false, path = "../../../primitives/finality-tracker" } +sp-inherents = { version = "2.0.0-alpha.3", path = "../../../primitives/inherents" } +sp-keyring = { version = "2.0.0-alpha.3", path = "../../../primitives/keyring" } +sp-io = { version = "2.0.0-alpha.3", path = "../../../primitives/io" } +sp-consensus = { version = "0.8.0-alpha.3", path = "../../../primitives/consensus/common" } # client dependencies -sc-client-api = { version = "2.0.0-alpha.2", path = "../../../client/api" } -sc-client = { version = "0.8.0-alpha.2", path = "../../../client/" } -sc-chain-spec = { version = "2.0.0-alpha.2", path = "../../../client/chain-spec" } -sc-transaction-pool = { version = "2.0.0-alpha.2", path = "../../../client/transaction-pool" } -sp-transaction-pool = { version = "2.0.0-alpha.2", path = "../../../primitives/transaction-pool" } -sc-network = { version = "0.8.0-alpha.2", path = "../../../client/network" } -sc-consensus-babe = { version = "0.8.0-alpha.2", path = "../../../client/consensus/babe" } -grandpa = { version = "0.8.0-alpha.2", package = "sc-finality-grandpa", path = "../../../client/finality-grandpa" } -sc-client-db = { version = "0.8.0-alpha.2", default-features = false, path = "../../../client/db" } -sc-offchain = { version = "2.0.0-alpha.2", path = "../../../client/offchain" } -sc-rpc = { version = "2.0.0-alpha.2", path = "../../../client/rpc" } -sc-basic-authorship = { version = "0.8.0-alpha.2", path = "../../../client/basic-authorship" } -sc-service = { version = "0.8.0-alpha.2", default-features = false, path = "../../../client/service" } -sc-tracing = { version = "2.0.0-alpha.2", path = "../../../client/tracing" } -sc-telemetry = { version = "2.0.0-alpha.2", path = "../../../client/telemetry" } -sc-authority-discovery = { version = "0.8.0-alpha.2", path = "../../../client/authority-discovery" } +sc-client-api = { version = "2.0.0-alpha.3", path = "../../../client/api" } +sc-client = { version = "0.8.0-alpha.3", path = "../../../client/" } +sc-chain-spec = { version = "2.0.0-alpha.3", path = "../../../client/chain-spec" } +sc-transaction-pool = { version = "2.0.0-alpha.3", path = "../../../client/transaction-pool" } +sp-transaction-pool = { version = "2.0.0-alpha.3", path = "../../../primitives/transaction-pool" } +sc-network = { version = "0.8.0-alpha.3", path = "../../../client/network" } +sc-consensus-babe = { version = "0.8.0-alpha.3", path = "../../../client/consensus/babe" } +grandpa = { version = "0.8.0-alpha.3", package = "sc-finality-grandpa", path = "../../../client/finality-grandpa" } +sc-client-db = { version = "0.8.0-alpha.3", default-features = false, path = "../../../client/db" } +sc-offchain = { version = "2.0.0-alpha.3", path = "../../../client/offchain" } +sc-rpc = { version = "2.0.0-alpha.3", path = "../../../client/rpc" } +sc-basic-authorship = { version = "0.8.0-alpha.3", path = "../../../client/basic-authorship" } +sc-service = { version = "0.8.0-alpha.3", default-features = false, path = "../../../client/service" } +sc-tracing = { version = "2.0.0-alpha.3", path = "../../../client/tracing" } +sc-telemetry = { version = "2.0.0-alpha.3", path = "../../../client/telemetry" } +sc-authority-discovery = { version = "0.8.0-alpha.3", path = "../../../client/authority-discovery" } # frame dependencies -pallet-indices = { version = "2.0.0-alpha.2", path = "../../../frame/indices" } -pallet-timestamp = { version = "2.0.0-alpha.2", default-features = false, path = "../../../frame/timestamp" } -pallet-contracts = { version = "2.0.0-alpha.2", path = "../../../frame/contracts" } -frame-system = { version = "2.0.0-alpha.2", path = "../../../frame/system" } -pallet-balances = { version = "2.0.0-alpha.2", path = "../../../frame/balances" } -pallet-transaction-payment = { version = "2.0.0-alpha.2", path = "../../../frame/transaction-payment" } -frame-support = { version = "2.0.0-alpha.2", default-features = false, path = "../../../frame/support" } -pallet-im-online = { version = "2.0.0-alpha.2", default-features = false, path = "../../../frame/im-online" } -pallet-authority-discovery = { version = "2.0.0-alpha.2", path = "../../../frame/authority-discovery" } +pallet-indices = { version = "2.0.0-alpha.3", path = "../../../frame/indices" } +pallet-timestamp = { version = "2.0.0-alpha.3", default-features = false, path = "../../../frame/timestamp" } +pallet-contracts = { version = "2.0.0-alpha.3", path = "../../../frame/contracts" } +frame-system = { version = "2.0.0-alpha.3", path = "../../../frame/system" } +pallet-balances = { version = "2.0.0-alpha.3", path = "../../../frame/balances" } +pallet-transaction-payment = { version = "2.0.0-alpha.3", path = "../../../frame/transaction-payment" } +frame-support = { version = "2.0.0-alpha.3", default-features = false, path = "../../../frame/support" } +pallet-im-online = { version = "2.0.0-alpha.3", default-features = false, path = "../../../frame/im-online" } +pallet-authority-discovery = { version = "2.0.0-alpha.3", path = "../../../frame/authority-discovery" } # node-specific dependencies -node-runtime = { version = "2.0.0-alpha.2", path = "../runtime" } -node-rpc = { version = "2.0.0-alpha.2", path = "../rpc" } -node-primitives = { version = "2.0.0-alpha.2", path = "../primitives" } -node-executor = { version = "2.0.0-alpha.2", path = "../executor" } +node-runtime = { version = "2.0.0-alpha.3", path = "../runtime" } +node-rpc = { version = "2.0.0-alpha.3", path = "../rpc" } +node-primitives = { version = "2.0.0-alpha.3", path = "../primitives" } +node-executor = { version = "2.0.0-alpha.3", path = "../executor" } # CLI-specific dependencies -sc-cli = { version = "0.8.0-alpha.2", optional = true, path = "../../../client/cli" } -frame-benchmarking-cli = { version = "2.0.0-alpha.2", optional = true, path = "../../../utils/frame/benchmarking-cli" } -node-transaction-factory = { version = "0.8.0-alpha.2", optional = true, path = "../transaction-factory" } -node-inspect = { version = "0.8.0-alpha.2", optional = true, path = "../inspect" } +sc-cli = { version = "0.8.0-alpha.3", optional = true, path = "../../../client/cli" } +frame-benchmarking-cli = { version = "2.0.0-alpha.3", optional = true, path = "../../../utils/frame/benchmarking-cli" } +node-transaction-factory = { version = "0.8.0-alpha.3", optional = true, path = "../transaction-factory" } +node-inspect = { version = "0.8.0-alpha.3", optional = true, path = "../inspect" } # WASM-specific dependencies wasm-bindgen = { version = "0.2.57", optional = true } wasm-bindgen-futures = { version = "0.4.7", optional = true } -browser-utils = { package = "substrate-browser-utils", path = "../../../utils/browser", optional = true, version = "0.8.0-alpha.2" } +browser-utils = { package = "substrate-browser-utils", path = "../../../utils/browser", optional = true, version = "0.8.0-alpha.3" } [dev-dependencies] -sc-keystore = { version = "2.0.0-alpha.2", path = "../../../client/keystore" } -sc-consensus-babe = { version = "0.8.0-alpha.2", features = ["test-helpers"], path = "../../../client/consensus/babe" } -sc-consensus-epochs = { version = "0.8.0-alpha.2", path = "../../../client/consensus/epochs" } +sc-keystore = { version = "2.0.0-alpha.3", path = "../../../client/keystore" } +sc-consensus-babe = { version = "0.8.0-alpha.3", features = ["test-helpers"], path = "../../../client/consensus/babe" } +sc-consensus-epochs = { version = "0.8.0-alpha.3", path = "../../../client/consensus/epochs" } sc-service-test = { version = "2.0.0-dev", path = "../../../client/service/test" } futures = "0.3.1" tempfile = "3.1.0" @@ -112,14 +112,14 @@ nix = "0.17" serde_json = "1.0" [build-dependencies] -build-script-utils = { version = "2.0.0-alpha.2", package = "substrate-build-script-utils", path = "../../../utils/build-script-utils" } +build-script-utils = { version = "2.0.0-alpha.3", package = "substrate-build-script-utils", path = "../../../utils/build-script-utils" } structopt = { version = "0.3.8", optional = true } -node-transaction-factory = { version = "0.8.0-alpha.2", optional = true, path = "../transaction-factory" } -node-inspect = { version = "0.8.0-alpha.2", optional = true, path = "../inspect" } -frame-benchmarking-cli = { version = "2.0.0-alpha.2", optional = true, path = "../../../utils/frame/benchmarking-cli" } +node-transaction-factory = { version = "0.8.0-alpha.3", optional = true, path = "../transaction-factory" } +node-inspect = { version = "0.8.0-alpha.3", optional = true, path = "../inspect" } +frame-benchmarking-cli = { version = "2.0.0-alpha.3", optional = true, path = "../../../utils/frame/benchmarking-cli" } [build-dependencies.sc-cli] -version = "0.8.0-alpha.2" +version = "0.8.0-alpha.3" package = "sc-cli" path = "../../../client/cli" optional = true diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index 21584f0898466..ac9e1e0eae17e 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -17,7 +17,13 @@ use sc_cli::VersionInfo; use sc_service::{Roles as ServiceRoles}; use node_transaction_factory::RuntimeAdapter; -use crate::{Cli, service, ChainSpec, load_spec, Subcommand, factory_impl::FactoryState}; +use crate::{ + Cli, service, ChainSpec, load_spec, Subcommand, + factory_impl::FactoryState, +}; +use sp_runtime::generic::Era; +use node_primitives::{Signature, AccountId, Index}; +use node_runtime::{Runtime, SignedExtra}; /// Parse command line arguments into service configuration. pub fn run(args: I, version: VersionInfo) -> sc_cli::Result<()> @@ -106,10 +112,32 @@ where Some(Subcommand::Base(subcommand)) => { subcommand.init(&version)?; subcommand.update_config(&mut config, load_spec, &version)?; - subcommand.run( + subcommand.run::( config, |config: sc_service::Configuration| Ok(new_full_start!(config).0), ) }, } } + +pub struct Adapter; + +impl sc_cli::RuntimeAdapter for Adapter { + type Pair = (); + type Public = (); + type Signature = Signature; + type Runtime = Runtime; + type Extra = SignedExtra; + + fn build_extra(index: Index) -> Self::Extra { + ( + frame_system::CheckVersion::new(), + frame_system::CheckGenesis::new(), + frame_system::CheckEra::from(Era::Immortal), + frame_system::CheckNonce::from(index), + frame_system::CheckWeight::new(), + pallet_transaction_payment::ChargeTransactionPayment::from(0), + pallet_contracts::CheckBlockGasLimit::default(), + ) + } +} diff --git a/client/cli/src/commands/insert.rs b/client/cli/src/commands/insert.rs index 1790dafc6a005..0dead71cafe23 100644 --- a/client/cli/src/commands/insert.rs +++ b/client/cli/src/commands/insert.rs @@ -55,6 +55,7 @@ pub struct InsertCmd { } impl InsertCmd { + /// Run the command pub fn run(self) -> error::Result<()> where HashFor: DeserializeOwned + Serialize + Send + Sync, diff --git a/client/cli/src/commands/inspect.rs b/client/cli/src/commands/inspect.rs index 2ab02af3b5773..11931c443b002 100644 --- a/client/cli/src/commands/inspect.rs +++ b/client/cli/src/commands/inspect.rs @@ -41,6 +41,7 @@ pub struct InspectCmd { } impl InspectCmd { + /// Run the command pub fn run(self) -> error::Result<()> where AccountIdFor: Ss58Codec + Derive, diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 39f90a8ae54eb..97322314002af 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -35,10 +35,12 @@ mod insert; pub mod tests; use std::fmt::{Debug, Display}; +use std::str::FromStr; use structopt::StructOpt; - -use sc_service::{ Configuration, ServiceBuilderCommand, ChainSpec }; -use sp_runtime::traits::{Block as BlockT, Header as HeaderT, IdentifyAccount}; +use sp_core::crypto::{Ss58Codec, Derive}; +use parity_scale_codec::Codec; +use sc_service::{Configuration, ServiceBuilderCommand, ChainSpec}; +use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; use crate::error; use crate::VersionInfo; @@ -60,9 +62,6 @@ pub use crate::commands::sign_transaction::SignTransactionCmd; pub use crate::commands::transfer::TransferCmd; pub use crate::commands::vanity::VanityCmd; pub use crate::commands::verify::VerifyCmd; -use sp_core::crypto::{Ss58Codec, Derive}; -use std::str::FromStr; -use parity_scale_codec::{Codec, WrapperTypeEncode}; /// default sub directory to store network config @@ -156,8 +155,7 @@ impl Subcommand { RA: RuntimeAdapter, AccountIdFor: Ss58Codec + Derive, as FromStr>::Err: Display, - CallFor: Codec + WrapperTypeEncode, - RA::Address: From<::AccountId>, + CallFor: Codec, { match self { Subcommand::BuildSpec(cmd) => cmd.run(config), diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs index 23430159fa37d..c31c9bf055663 100644 --- a/client/cli/src/commands/sign.rs +++ b/client/cli/src/commands/sign.rs @@ -51,6 +51,7 @@ pub struct SignCmd { impl SignCmd { + /// Run the command pub fn run(self) -> error::Result<()> { let message = read_message(self.message, self.hex)?; let suri = read_uri(self.suri)?; diff --git a/client/cli/src/commands/sign_transaction.rs b/client/cli/src/commands/sign_transaction.rs index 885ba88d89dab..45a8e91afc9b0 100644 --- a/client/cli/src/commands/sign_transaction.rs +++ b/client/cli/src/commands/sign_transaction.rs @@ -21,9 +21,8 @@ use super::{ RuntimeAdapter, IndexFor, CallFor, }; use structopt::StructOpt; -use parity_scale_codec::{WrapperTypeEncode, Codec, Encode, Decode}; +use parity_scale_codec::{Codec, Encode, Decode}; use std::{str::FromStr, fmt::Display}; -use sp_runtime::traits::IdentifyAccount; use sc_service::{Configuration, ChainSpec}; type Call = Vec; @@ -53,11 +52,12 @@ pub struct SignTransactionCmd { } impl SignTransactionCmd { - pub fn run(self) -> error::Result<()> + /// Run the command + pub fn run(self) -> error::Result<()> where + RA: RuntimeAdapter, as FromStr>::Err: Display, - CallFor: Codec + WrapperTypeEncode, - RA::Address: From<::AccountId>, + CallFor: Codec, { let signer = RA::pair_from_suri(&self.suri, &get_password(&self.shared_params)?); diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs index 9cac36a9dbc28..c37e1067019a7 100644 --- a/client/cli/src/commands/tests.rs +++ b/client/cli/src/commands/tests.rs @@ -39,7 +39,6 @@ impl RuntimeAdapter for Adapter { frame_system::CheckNonce, frame_system::CheckWeight, ); - type Address = as StaticLookup>::Source; fn build_extra(index: IndexFor) -> Self::Extra { ( diff --git a/client/cli/src/commands/transfer.rs b/client/cli/src/commands/transfer.rs index c6741cba245e3..cf38602654eb0 100644 --- a/client/cli/src/commands/transfer.rs +++ b/client/cli/src/commands/transfer.rs @@ -22,7 +22,6 @@ use structopt::StructOpt; use pallet_balances::Call as BalancesCall; use std::{str::FromStr, fmt::Display}; use parity_scale_codec::{Encode, Decode}; -use sp_runtime::traits::IdentifyAccount; use sc_service::{Configuration, ChainSpec}; /// The `transfer` command @@ -55,13 +54,14 @@ pub struct TransferCmd { impl TransferCmd { - pub fn run(self) -> error::Result<()> + /// Run the command + pub fn run(self) -> error::Result<()> where + RA: RuntimeAdapter, AddressFor: Decode, as FromStr>::Err: Display, as FromStr>::Err: Display, BalancesCall: Encode, - RA::Address: From<::AccountId>, { let password = get_password(&self.shared_params)?; let nonce = IndexFor::::from_str(&self.index).map_err(|e| format!("{}", e))?; @@ -69,7 +69,7 @@ impl TransferCmd { let amount = BalanceFor::::from_str(&self.amount).map_err(|e| format!("{}", e))?; let signer = RA::pair_from_suri(&self.from, &password); - let call = BalancesCall::transfer(to.into(), amount); + let call = BalancesCall::transfer(to, amount); let extrinsic = create_extrinsic_for::(call, nonce, signer)?; println!("0x{}", hex::encode(Encode::encode(&extrinsic))); diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 110a609744a0a..6460d2744e3f7 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -18,10 +18,10 @@ use std::{io::Read, path::PathBuf}; use sp_core::{Pair, Public, crypto::{Ss58Codec,Derive, Ss58AddressFormat}, hexdisplay::HexDisplay}; use sp_runtime::{ - MultiSignature, MultiSigner, generic::{UncheckedExtrinsic, SignedPayload}, - traits::IdentifyAccount, AccountId32, + generic::{UncheckedExtrinsic, SignedPayload}, + traits::IdentifyAccount, }; -use parity_scale_codec::{Encode, Decode}; +use parity_scale_codec::{Encode, Codec}; use serde_json::json; use sp_runtime::traits::{ SignedExtension, StaticLookup, @@ -50,15 +50,13 @@ pub trait RuntimeAdapter: Sized { /// Pair type type Pair: Pair; /// public type - type Public: Public + IdentifyAccount> + std::hash::Hash + Ss58Codec; + type Public: Codec + Public + IdentifyAccount> + std::hash::Hash + Ss58Codec; /// signature type type Signature: AsRef<[u8]> + AsMut<[u8]> + Encode + Default; /// runtime - type Runtime: frame_system::Trait + pallet_balances::Trait + pallet_indices::Trait; + type Runtime: frame_system::Trait + pallet_balances::Trait; /// extras type Extra: SignedExtension; - /// Address type - type Address: Encode + Decode; /// generate a pair from suri fn pair_from_suri(suri: &str, password: &str) -> Self::Pair { @@ -252,21 +250,21 @@ pub fn read_message(msg: Option, should_decode: bool) -> Result, } /// create an extrinsic for the runtime. -pub fn create_extrinsic_for( +pub fn create_extrinsic_for( call: Call, nonce: IndexFor, signer: RA::Pair, -) -> Result, Error> +) -> Result, Error> where Call: Encode, - RA::Address: From<::AccountId>, + RA: RuntimeAdapter, { let extra = RA::build_extra(nonce); let payload = SignedPayload::new(call, extra) .map_err(|_| Error::Other("Transaction validity error".into()))?; let signature = payload.using_encoded(|payload| signer.sign(payload)); - let signer = signer.public().into_account().into(); + let signer = signer.public(); let (function, extra, _) = payload.deconstruct(); Ok(UncheckedExtrinsic::new_signed( @@ -276,4 +274,3 @@ pub fn create_extrinsic_for( extra, )) } - diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index 1bbe1dbeb5b2b..f50798a836961 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -43,6 +43,7 @@ pub struct VanityCmd { } impl VanityCmd { + /// Run the command pub fn run(self) -> error::Result<()> where RA: RuntimeAdapter, diff --git a/client/cli/src/commands/verify.rs b/client/cli/src/commands/verify.rs index 26eec55a95abf..584b26280287a 100644 --- a/client/cli/src/commands/verify.rs +++ b/client/cli/src/commands/verify.rs @@ -53,6 +53,7 @@ pub struct VerifyCmd { } impl VerifyCmd { + /// Run the command pub fn run(self) -> error::Result<()> { let message = read_message(self.message, self.hex)?; let mut signature = ::Signature::default(); diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index f27eed0aed873..33900e963b0d0 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -178,10 +178,6 @@ use sp_runtime::{ }, }; use frame_system::{self as system, ensure_signed, ensure_root}; -use frame_support::storage::migration::{ - get_storage_value, take_storage_value, put_storage_value, StorageIterator, have_storage_value -}; - pub use self::imbalances::{PositiveImbalance, NegativeImbalance}; pub trait Subtrait: frame_system::Trait { diff --git a/primitives/runtime/src/lib.rs b/primitives/runtime/src/lib.rs index 632deb13cbb45..f30eb49624237 100644 --- a/primitives/runtime/src/lib.rs +++ b/primitives/runtime/src/lib.rs @@ -152,7 +152,7 @@ impl BuildStorage for () { fn assimilate_storage( &self, _: &mut sp_core::storage::Storage, - )-> Result<(), String> { + ) -> Result<(), String> { Err("`assimilate_storage` not implemented for `()`".into()) } } diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index 4f9723683cb3c..6ffbac026cd5a 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -39,7 +39,7 @@ use sp_runtime::{ }, traits::{ BlindCheckable, BlakeTwo256, Block as BlockT, Extrinsic as ExtrinsicT, - GetNodeBlockType, GetRuntimeBlockType, Verify, IdentityLookup, + GetNodeBlockType, GetRuntimeBlockType, Verify, }, }; use sp_version::RuntimeVersion; From f96d007eaae77d5cd59ee2699877936a36691803 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 17 Mar 2020 19:38:29 +0100 Subject: [PATCH 09/77] final draft --- bin/node-template/node/src/cli.rs | 4 - bin/node/cli/build.rs | 4 +- bin/node/cli/src/command.rs | 7 +- client/cli/Cargo.toml | 2 +- client/cli/src/arg_enums.rs | 10 +- client/cli/src/commands/generate.rs | 23 +- client/cli/src/commands/insert.rs | 18 +- client/cli/src/commands/inspect.rs | 23 +- client/cli/src/commands/mod.rs | 21 +- client/cli/src/commands/sign.rs | 26 +- client/cli/src/commands/sign_transaction.rs | 33 ++- client/cli/src/commands/tests.rs | 19 +- client/cli/src/commands/transfer.rs | 45 +++- client/cli/src/commands/utils.rs | 284 ++++++++++---------- client/cli/src/commands/vanity.rs | 70 +++-- client/cli/src/commands/verify.rs | 71 +++-- client/cli/src/params/shared_params.rs | 12 +- 17 files changed, 381 insertions(+), 291 deletions(-) diff --git a/bin/node-template/node/src/cli.rs b/bin/node-template/node/src/cli.rs index 25506a192ac76..15ceff50821af 100644 --- a/bin/node-template/node/src/cli.rs +++ b/bin/node-template/node/src/cli.rs @@ -2,7 +2,6 @@ use structopt::StructOpt; use sc_cli::{RunCmd, Subcommand, RuntimeAdapter}; use node_template_runtime::{Runtime, SignedExtra, Index}; use sp_runtime::generic::Era; -use sp_core::sr25519; #[derive(Debug, StructOpt)] pub struct Cli { @@ -16,9 +15,6 @@ pub struct Cli { pub struct Adapter; impl RuntimeAdapter for Adapter { - type Pair = sr25519::Pair; - type Public = sr25519::Public; - type Signature = sr25519::Signature; type Runtime = Runtime; type Extra = SignedExtra; diff --git a/bin/node/cli/build.rs b/bin/node/cli/build.rs index 3f3c0b3427f2a..e824b59be64f3 100644 --- a/bin/node/cli/build.rs +++ b/bin/node/cli/build.rs @@ -15,8 +15,8 @@ // along with Substrate. If not, see . fn main() { - // #[cfg(feature = "cli")] - // cli::main(); + #[cfg(feature = "cli")] + cli::main(); } #[cfg(feature = "cli")] diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index ac9e1e0eae17e..6d4d54dd324f1 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -22,7 +22,7 @@ use crate::{ factory_impl::FactoryState, }; use sp_runtime::generic::Era; -use node_primitives::{Signature, AccountId, Index}; +use node_primitives::Index; use node_runtime::{Runtime, SignedExtra}; /// Parse command line arguments into service configuration. @@ -120,12 +120,9 @@ where } } -pub struct Adapter; +struct Adapter; impl sc_cli::RuntimeAdapter for Adapter { - type Pair = (); - type Public = (); - type Signature = Signature; type Runtime = Runtime; type Extra = SignedExtra; diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 6f06940b1e47f..fe8799256b50f 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -38,7 +38,7 @@ sc-client-api = { version = "2.0.0-alpha.2", path = "../api" } sp-blockchain = { version = "2.0.0-alpha.2", path = "../../primitives/blockchain" } sc-network = { version = "0.8.0-alpha.2", path = "../network" } sp-runtime = { version = "2.0.0-alpha.2", path = "../../primitives/runtime" } -sp-core = { version = "2.0.0-alpha.2", path = "../../primitives/core" } +sp-core = { version = "2.0.0-alpha.2", path = "../../primitives/core", features = [ "full_crypto"] } sc-service = { version = "0.8.0-alpha.2", default-features = false, path = "../service" } sp-state-machine = { version = "0.8.0-alpha.2", path = "../../primitives/state-machine" } sc-telemetry = { version = "2.0.0-alpha.2", path = "../telemetry" } diff --git a/client/cli/src/arg_enums.rs b/client/cli/src/arg_enums.rs index 564fbfdb31596..ed8f25a5381ac 100644 --- a/client/cli/src/arg_enums.rs +++ b/client/cli/src/arg_enums.rs @@ -83,7 +83,6 @@ arg_enum! { } arg_enum! { - #[allow(missing_docs)] #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum OutputType { Json, @@ -91,6 +90,15 @@ arg_enum! { } } +arg_enum! { + #[derive(Debug, Copy, Clone, PartialEq, Eq)] + pub enum CryptoScheme { + Ed25519, + Sr25519, + Ecdsa, + } +} + arg_enum! { /// How to execute blocks #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/client/cli/src/commands/generate.rs b/client/cli/src/commands/generate.rs index 078c11b8de342..191664647ab9d 100644 --- a/client/cli/src/commands/generate.rs +++ b/client/cli/src/commands/generate.rs @@ -16,12 +16,11 @@ //! Implementation of the `generate` subcommand -use super::{SharedParams, RuntimeAdapter, get_password}; +use super::{SharedParams, get_password}; use crate::error::{self, Error}; use bip39::{MnemonicType, Mnemonic, Language}; use structopt::StructOpt; -use crate::{AccountIdFor, VersionInfo}; -use sp_core::crypto::{Ss58Codec, Derive}; +use crate::{VersionInfo, print_from_uri, with_crypto_scheme}; use sc_service::{Configuration, ChainSpec}; /// The `generate` command @@ -39,9 +38,7 @@ pub struct GenerateCmd { impl GenerateCmd { /// Run the command - pub fn run(self) -> error::Result<()> - where - AccountIdFor: Ss58Codec + Derive, + pub fn run(self) -> error::Result<()> { let words = match self.words { Some(words) => { @@ -57,13 +54,15 @@ impl GenerateCmd { let maybe_network = self.shared_params.network; let output = self.shared_params.output_type; - RA::print_from_uri( - mnemonic.phrase(), - Some(password.as_str()), - maybe_network, - output + with_crypto_scheme!( + self.shared_params.scheme, + print_from_uri( + mnemonic.phrase(), + Some(password.as_str()), + maybe_network, + output + ) ); - Ok(()) } diff --git a/client/cli/src/commands/insert.rs b/client/cli/src/commands/insert.rs index 0dead71cafe23..7ceb2570049b2 100644 --- a/client/cli/src/commands/insert.rs +++ b/client/cli/src/commands/insert.rs @@ -16,10 +16,10 @@ //! Implementation of the `insert` subcommand -use crate::{error, HashFor, VersionInfo}; +use crate::{error, HashFor, VersionInfo, with_crypto_scheme, pair_from_suri}; use super::{SharedParams, get_password, read_uri, RuntimeAdapter}; use structopt::StructOpt; -use sp_core::{crypto::{KeyTypeId, Pair}, Bytes}; +use sp_core::{crypto::KeyTypeId, Bytes}; use std::convert::TryFrom; use futures01::Future; use hyper::rt; @@ -62,7 +62,12 @@ impl InsertCmd { { let suri = read_uri(self.suri)?; let password = get_password(&self.shared_params)?; - let pair = RA::pair_from_suri(&suri, &password); + + let public = with_crypto_scheme!( + self.shared_params.scheme, + to_vec(&suri, &password) + ); + let node_url = self.node_url.unwrap_or("http://localhost:9933".into()); let key_type = self.key_type; @@ -77,7 +82,7 @@ impl InsertCmd { &node_url, key_type.to_string(), suri, - sp_core::Bytes(pair.public().as_ref().to_vec()), + sp_core::Bytes(public), ); Ok(()) @@ -99,6 +104,11 @@ impl InsertCmd { } } +fn to_vec(uri: &str, pass: &str) -> Vec { + let p = pair_from_suri::

(uri, pass); + p.public().as_ref().to_vec() +} + fn insert_key(url: &str, key_type: String, suri: String, public: Bytes) where H: DeserializeOwned + Serialize + Send + Sync + 'static, diff --git a/client/cli/src/commands/inspect.rs b/client/cli/src/commands/inspect.rs index 11931c443b002..aa8a9e6c13b67 100644 --- a/client/cli/src/commands/inspect.rs +++ b/client/cli/src/commands/inspect.rs @@ -16,10 +16,9 @@ //! Implementation of the `inspect` subcommand -use crate::{error, AccountIdFor, VersionInfo}; -use super::{SharedParams, get_password, read_uri, RuntimeAdapter}; +use crate::{error, VersionInfo, print_from_uri, with_crypto_scheme}; +use super::{SharedParams, get_password, read_uri}; use structopt::StructOpt; -use sp_core::crypto::{Ss58Codec, Derive}; use sc_service::{Configuration, ChainSpec}; /// The `inspect` command @@ -42,18 +41,18 @@ pub struct InspectCmd { impl InspectCmd { /// Run the command - pub fn run(self) -> error::Result<()> - where - AccountIdFor: Ss58Codec + Derive, - { + pub fn run(self) -> error::Result<()> { let uri = read_uri(self.uri)?; let pass = get_password(&self.shared_params).ok(); - RA::print_from_uri( - &uri, - pass.as_ref().map(String::as_str), - self.shared_params.network, - self.shared_params.output_type + with_crypto_scheme!( + self.shared_params.scheme, + print_from_uri( + &uri, + pass.as_ref().map(String::as_str), + self.shared_params.network, + self.shared_params.output_type + ) ); Ok(()) diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 97322314002af..24a25b516631a 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -37,7 +37,6 @@ pub mod tests; use std::fmt::{Debug, Display}; use std::str::FromStr; use structopt::StructOpt; -use sp_core::crypto::{Ss58Codec, Derive}; use parity_scale_codec::Codec; use sc_service::{Configuration, ServiceBuilderCommand, ChainSpec}; use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; @@ -110,6 +109,9 @@ pub enum Subcommand { /// Sign transaction from encoded Call. Returns a signed and encoded UncheckedMortalCompactExtrinsic as hex. SignTransaction(sign_transaction::SignTransactionCmd), + /// Author and sign a Node pallet_balances::Transfer transaction with a given (secret) key. + Transfer(transfer::TransferCmd), + /// Verify a signature for a message, provided on STDIN, with a given (public or secret) key. Verify(verify::VerifyCmd), @@ -135,6 +137,7 @@ impl Subcommand { Insert(params) => ¶ms.shared_params, Sign(params) => ¶ms.shared_params, SignTransaction(params) => ¶ms.shared_params, + Transfer(params) => ¶ms.shared_params, Verify(params) => ¶ms.shared_params, Vanity(params) => ¶ms.shared_params, } @@ -153,8 +156,8 @@ impl Subcommand { <::Number as std::str::FromStr>::Err: std::fmt::Debug, Block::Hash: std::str::FromStr, RA: RuntimeAdapter, - AccountIdFor: Ss58Codec + Derive, as FromStr>::Err: Display, + as FromStr>::Err: Display, CallFor: Codec, { match self { @@ -165,13 +168,14 @@ impl Subcommand { Subcommand::PurgeChain(cmd) => cmd.run(config), Subcommand::Revert(cmd) => cmd.run(config, builder), Subcommand::GenerateNodeKey(cmd) => cmd.run(), - Subcommand::Generate(cmd) => cmd.run::(), - Subcommand::Inspect(cmd) => cmd.run::(), - Subcommand::Insert(cmd) => cmd.run::(), - Subcommand::Sign(cmd) => cmd.run::(), + Subcommand::Generate(cmd) => cmd.run(), + Subcommand::Inspect(cmd) => cmd.run(), + Subcommand::Sign(cmd) => cmd.run(), + Subcommand::Verify(cmd) => cmd.run(), + Subcommand::Vanity(cmd) => cmd.run(), + Subcommand::Transfer(cmd) => cmd.run::(), Subcommand::SignTransaction(cmd) => cmd.run::(), - Subcommand::Verify(cmd) => cmd.run::(), - Subcommand::Vanity(cmd) => cmd.run::(), + Subcommand::Insert(cmd) => cmd.run::(), } } @@ -197,6 +201,7 @@ impl Subcommand { Subcommand::Insert(cmd) => cmd.update_config(&mut config, spec_factory, version), Subcommand::Sign(cmd) => cmd.update_config(&mut config, spec_factory, version), Subcommand::SignTransaction(cmd) => cmd.update_config(&mut config, spec_factory, version), + Subcommand::Transfer(cmd) => cmd.update_config(&mut config, spec_factory, version), Subcommand::Verify(cmd) => cmd.update_config(&mut config, spec_factory, version), Subcommand::Vanity(cmd) => cmd.update_config(&mut config, spec_factory, version), } diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs index c31c9bf055663..2d967fa7f7aa1 100644 --- a/client/cli/src/commands/sign.rs +++ b/client/cli/src/commands/sign.rs @@ -15,11 +15,9 @@ // along with Substrate. If not, see . //! Implementation of the `sign` subcommand -use crate::{error, VersionInfo}; -use super::{SharedParams, get_password, read_message, read_uri, RuntimeAdapter}; +use crate::{error, VersionInfo, with_crypto_scheme, pair_from_suri}; +use super::{SharedParams, get_password, read_message, read_uri}; use structopt::StructOpt; - -use sp_core::crypto::Pair; use sc_service::{Configuration, ChainSpec}; /// The `sign` command @@ -52,12 +50,20 @@ pub struct SignCmd { impl SignCmd { /// Run the command - pub fn run(self) -> error::Result<()> { + pub fn run(self) -> error::Result<()> { let message = read_message(self.message, self.hex)?; let suri = read_uri(self.suri)?; let password = get_password(&self.shared_params)?; - let pair = RA::pair_from_suri(&suri, &password); - let signature = format!("{}", hex::encode(pair.sign(&message))); + + let signature = with_crypto_scheme!( + self.shared_params.scheme, + sign( + &suri, + &password, + message + ) + )?; + println!("{}", signature); Ok(()) } @@ -72,8 +78,12 @@ impl SignCmd { F: FnOnce(&str) -> Result, String>, { self.shared_params.update_config(&mut config, spec_factory, version)?; - config.use_in_memory_keystore()?; Ok(()) } } + +fn sign(suri: &str, password: &str, message: Vec) -> error::Result { + let pair = pair_from_suri::

(suri, password); + Ok(format!("{}", hex::encode(pair.sign(&message)))) +} diff --git a/client/cli/src/commands/sign_transaction.rs b/client/cli/src/commands/sign_transaction.rs index 45a8e91afc9b0..1799c8c116899 100644 --- a/client/cli/src/commands/sign_transaction.rs +++ b/client/cli/src/commands/sign_transaction.rs @@ -15,15 +15,16 @@ // along with Substrate. If not, see . //! Implementation of the `sign-transaction` subcommand -use crate::{error, VersionInfo}; +use crate::{error, VersionInfo, with_crypto_scheme}; use super::{ SharedParams, get_password, decode_hex, create_extrinsic_for, - RuntimeAdapter, IndexFor, CallFor, + RuntimeAdapter, IndexFor, CallFor, pair_from_suri, }; use structopt::StructOpt; use parity_scale_codec::{Codec, Encode, Decode}; use std::{str::FromStr, fmt::Display}; use sc_service::{Configuration, ChainSpec}; +use sp_runtime::MultiSigner; type Call = Vec; @@ -59,15 +60,19 @@ impl SignTransactionCmd { as FromStr>::Err: Display, CallFor: Codec, { - let signer = RA::pair_from_suri(&self.suri, &get_password(&self.shared_params)?); let nonce = IndexFor::::from_str(&self.nonce).map_err(|e| format!("{}", e))?; let call = CallFor::::decode(&mut &self.call[..])?; - let extrinsic = create_extrinsic_for::(call, nonce, signer)?; - println!("0x{}", hex::encode(Encode::encode(&extrinsic))); - - Ok(()) + with_crypto_scheme!( + self.shared_params.scheme, + print_ext( + &self.suri, + &get_password(&self.shared_params)?, + call, + nonce + ) + ) } /// Update and prepare a `Configuration` with command line parameters @@ -85,3 +90,17 @@ impl SignTransactionCmd { Ok(()) } } + +fn print_ext(uri: &str, pass: &str, call: CallFor, nonce: IndexFor) -> error::Result<()> + where + Pair: sp_core::Pair, + Pair::Public: Into, + Pair::Signature: Encode, + RA: RuntimeAdapter, + CallFor: Codec, +{ + let signer = pair_from_suri::(uri, pass); + let extrinsic = create_extrinsic_for::>(call, nonce, signer)?; + println!("0x{}", hex::encode(Encode::encode(&extrinsic))); + Ok(()) +} diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs index c37e1067019a7..15ccd2a356a2a 100644 --- a/client/cli/src/commands/tests.rs +++ b/client/cli/src/commands/tests.rs @@ -15,11 +15,9 @@ // along with Substrate. If not, see . use super::*; -use substrate_test_runtime::{AccountSignature, Runtime}; -use sp_core::sr25519; +use substrate_test_runtime::Runtime; use sp_runtime::generic::Era; -use sp_runtime::traits::StaticLookup; use tempfile::Builder; use std::io::Read; use crate::commands::inspect::InspectCmd; @@ -28,9 +26,6 @@ use crate::Error; pub struct Adapter; impl RuntimeAdapter for Adapter { - type Pair = sr25519::Pair; - type Public = sr25519::Public; - type Signature = AccountSignature; type Runtime = Runtime; type Extra = ( frame_system::CheckVersion, @@ -62,7 +57,7 @@ fn new_test_ext() -> sp_io::TestExternalities { #[test] fn generate() { let generate = GenerateCmd::from_iter(&["generate", "--password", "12345"]); - assert!(generate.run::().is_ok()) + assert!(generate.run().is_ok()) } #[test] @@ -84,10 +79,10 @@ fn inspect() { let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; let inspect = InspectCmd::from_iter(&["inspect", "--uri", words, "--password", "12345"]); - assert!(inspect.run::().is_ok()); + assert!(inspect.run().is_ok()); let inspect = InspectCmd::from_iter(&["inspect", "--uri", seed]); - assert!(inspect.run::().is_ok()); + assert!(inspect.run().is_ok()); } #[test] @@ -96,16 +91,16 @@ fn sign() { let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; let sign = SignCmd::from_iter(&["sign", "--suri", seed, "--message", &seed[2..], "--password", "12345"]); - assert!(sign.run::().is_ok()); + assert!(sign.run().is_ok()); let sign = SignCmd::from_iter(&["sign", "--suri", words, "--message", &seed[2..]]); - assert!(matches!(sign.run::(), Err(Error::Input(_)))) + assert!(matches!(sign.run(), Err(Error::Input(_)))) } #[test] fn vanity() { let vanity = VanityCmd::from_iter(&["vanity", "--number", "1", "--pattern", "j"]); - assert!(vanity.run::().is_ok()); + assert!(vanity.run().is_ok()); } #[test] diff --git a/client/cli/src/commands/transfer.rs b/client/cli/src/commands/transfer.rs index cf38602654eb0..47128d9af4da8 100644 --- a/client/cli/src/commands/transfer.rs +++ b/client/cli/src/commands/transfer.rs @@ -16,13 +16,17 @@ //! Implementation of the `transfer` subcommand -use crate::{error, IndexFor, BalanceFor, create_extrinsic_for, get_password, AddressFor, VersionInfo}; +use crate::{ + error, IndexFor, BalanceFor, create_extrinsic_for, get_password, + AddressFor, VersionInfo, with_crypto_scheme, pair_from_suri, +}; use super::{SharedParams, RuntimeAdapter}; use structopt::StructOpt; use pallet_balances::Call as BalancesCall; use std::{str::FromStr, fmt::Display}; use parity_scale_codec::{Encode, Decode}; use sc_service::{Configuration, ChainSpec}; +use sp_runtime::MultiSigner; /// The `transfer` command #[derive(Debug, StructOpt, Clone)] @@ -61,20 +65,22 @@ impl TransferCmd { AddressFor: Decode, as FromStr>::Err: Display, as FromStr>::Err: Display, - BalancesCall: Encode, { let password = get_password(&self.shared_params)?; let nonce = IndexFor::::from_str(&self.index).map_err(|e| format!("{}", e))?; let to = AddressFor::::decode(&mut self.to.as_bytes()).map_err(|e| format!("{}", e))?; let amount = BalanceFor::::from_str(&self.amount).map_err(|e| format!("{}", e))?; - let signer = RA::pair_from_suri(&self.from, &password); - let call = BalancesCall::transfer(to, amount); - - let extrinsic = create_extrinsic_for::(call, nonce, signer)?; - println!("0x{}", hex::encode(Encode::encode(&extrinsic))); - - Ok(()) + with_crypto_scheme!( + self.shared_params.scheme, + print_ext( + &self.from, + &password, + to, + nonce, + amount + ) + ) } /// Update and prepare a `Configuration` with command line parameters @@ -92,3 +98,24 @@ impl TransferCmd { Ok(()) } } + +fn print_ext( + uri: &str, + pass: &str, + to: AddressFor, + nonce: IndexFor, + amount: BalanceFor, +) -> error::Result<()> + where + Pair: sp_core::Pair, + Pair::Public: Into, + Pair::Signature: Encode, + RA: RuntimeAdapter, + BalancesCall: Encode, +{ + let signer = pair_from_suri::(uri, pass); + let call = BalancesCall::transfer(to, amount); + let extrinsic = create_extrinsic_for::(call, nonce, signer)?; + println!("0x{}", hex::encode(Encode::encode(&extrinsic))); + Ok(()) +} diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 6460d2744e3f7..cc822f0b66a21 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -16,22 +16,20 @@ //! subcommand utilities use std::{io::Read, path::PathBuf}; -use sp_core::{Pair, Public, crypto::{Ss58Codec,Derive, Ss58AddressFormat}, hexdisplay::HexDisplay}; -use sp_runtime::{ - generic::{UncheckedExtrinsic, SignedPayload}, - traits::IdentifyAccount, -}; -use parity_scale_codec::{Encode, Codec}; +use sp_core::{Pair, crypto::{Ss58Codec, Ss58AddressFormat}, hexdisplay::HexDisplay}; +use sp_runtime::{generic::{UncheckedExtrinsic, SignedPayload}, traits::IdentifyAccount, MultiSigner}; +use parity_scale_codec::Encode; use serde_json::json; use sp_runtime::traits::{ SignedExtension, StaticLookup, }; -use crate::{error::{self, Error}, SharedParams, arg_enums::OutputType}; +use crate::{error::{self, Error}, SharedParams, arg_enums::{OutputType}}; +use sp_core::crypto::AccountId32; /// Public key type for Runtime -pub type PublicFor = <::Pair as Pair>::Public; +pub type PublicFor

=

::Public; /// Seed type for Runtime -pub type SeedFor = <::Pair as Pair>::Seed; +pub type SeedFor

=

::Seed; /// AccountIndex type for Runtime pub type IndexFor = <::Runtime as frame_system::Trait>::Index; /// AccountId type for Runtime @@ -47,132 +45,11 @@ pub type HashFor = <::Runtime as frame_system::Trait>::H /// Runtime adapter for signing utilities pub trait RuntimeAdapter: Sized { - /// Pair type - type Pair: Pair; - /// public type - type Public: Codec + Public + IdentifyAccount> + std::hash::Hash + Ss58Codec; - /// signature type - type Signature: AsRef<[u8]> + AsMut<[u8]> + Encode + Default; /// runtime type Runtime: frame_system::Trait + pallet_balances::Trait; /// extras type Extra: SignedExtension; - /// generate a pair from suri - fn pair_from_suri(suri: &str, password: &str) -> Self::Pair { - Self::Pair::from_string(suri, Some(password)).expect("Invalid phrase") - } - - /// generate an ss58 encoded address from pair - fn ss58_from_pair(pair: &Self::Pair) -> String - where - AccountIdFor: Ss58Codec, - { - pair.public().into_account().to_ss58check() - } - - /// print formatted pair from uri - fn print_from_uri( - uri: &str, - password: Option<&str>, - network_override: Ss58AddressFormat, - output: OutputType, - ) - where - AccountIdFor: Ss58Codec + Derive, - { - if let Ok((pair, seed)) = Self::Pair::from_phrase(uri, password) { - let public_key = pair.public(); - - match output { - OutputType::Json => { - let json = json!({ - "secretPhrase": uri, - "secretSeed": format_seed::(seed), - "publicKey": format_public_key::(public_key.clone()), - "accountId": format_account_id::(public_key), - "ss58Address": Self::ss58_from_pair(&pair), - }); - println!("{}", serde_json::to_string_pretty(&json).expect("Json pretty print failed")); - }, - OutputType::Text => { - println!("Secret phrase `{}` is account:\n \ - Secret seed: {}\n \ - Public key (hex): {}\n \ - Account ID: {}\n \ - SS58 Address: {}", - uri, - format_seed::(seed), - format_public_key::(public_key.clone()), - format_account_id::(public_key), - Self::ss58_from_pair(&pair), - ); - }, - } - } else if let Ok((pair, seed)) = Self::Pair::from_string_with_seed(uri, password) { - let public_key = pair.public(); - - match output { - OutputType::Json => { - let json = json!({ - "secretKeyUri": uri, - "secretSeed": if let Some(seed) = seed { format_seed::(seed) } else { "n/a".into() }, - "publicKey": format_public_key::(public_key.clone()), - "accountId": format_account_id::(public_key), - "ss58Address": Self::ss58_from_pair(&pair), - }); - println!("{}", serde_json::to_string_pretty(&json).expect("Json pretty print failed")); - }, - OutputType::Text => { - println!("Secret Key URI `{}` is account:\n \ - Secret seed: {}\n \ - Public key (hex): {}\n \ - Account ID: {}\n \ - SS58 Address: {}", - uri, - if let Some(seed) = seed { format_seed::(seed) } else { "n/a".into() }, - format_public_key::(public_key.clone()), - format_account_id::(public_key), - Self::ss58_from_pair(&pair), - ); - }, - } - - } else if let Ok((public_key, _v)) = - ::Public::from_string_with_version(uri) - { - let v = network_override; - - match output { - OutputType::Json => { - let json = json!({ - "publicKeyUri": uri, - "networkId": String::from(v), - "publicKey": format_public_key::(public_key.clone()), - "accountId": format_account_id::(public_key.clone()), - "ss58Address": public_key.to_ss58check_with_version(v), - }); - println!("{}", serde_json::to_string_pretty(&json).expect("Json pretty print failed")); - }, - OutputType::Text => { - println!("Public Key URI `{}` is account:\n \ - Network ID/version: {}\n \ - Public key (hex): {}\n \ - Account ID: {}\n \ - SS58 Address: {}", - uri, - String::from(v), - format_public_key::(public_key.clone()), - format_account_id::(public_key.clone()), - public_key.to_ss58check_with_version(v), - ); - }, - } - } else { - println!("Invalid phrase/URI given"); - } - } - /// build extras for inclusion in extrinsics fn build_extra(index: IndexFor) -> Self::Extra; } @@ -208,22 +85,148 @@ pub fn read_uri(uri: Option) -> error::Result { Ok(uri) } +/// Allows for calling $method with appropriate crypto impl. +#[macro_export] +macro_rules! with_crypto_scheme { + ($scheme:expr, $method:ident($($params:expr),*)) => { + with_crypto_scheme!($scheme, $method<>($($params),*)) + }; + ($scheme:expr, $method:ident<$($gen:ident),*>($($params:expr),*)) => { + match $scheme { + $crate::arg_enums::CryptoScheme::Ecdsa => { + $method::($($params),*) + } + $crate::arg_enums::CryptoScheme::Sr25519 => { + $method::($($params),*) + } + $crate::arg_enums::CryptoScheme::Ed25519 => { + $method::($($params),*) + } + } + }; +} + +/// print formatted pair from uri +pub fn print_from_uri( + uri: &str, + password: Option<&str>, + network_override: Ss58AddressFormat, + output: OutputType, +) + where + Pair: sp_core::Pair, + Pair::Public: Into, +{ + if let Ok((pair, seed)) = Pair::from_phrase(uri, password) { + let public_key = pair.public(); + + match output { + OutputType::Json => { + let json = json!({ + "secretPhrase": uri, + "secretSeed": format_seed::(seed), + "publicKey": format_public_key::(public_key.clone()), + "accountId": format_account_id::(public_key), + "ss58Address": pair.public().into().into_account().to_ss58check(), + }); + println!("{}", serde_json::to_string_pretty(&json).expect("Json pretty print failed")); + }, + OutputType::Text => { + println!("Secret phrase `{}` is account:\n \ + Secret seed: {}\n \ + Public key (hex): {}\n \ + Account ID: {}\n \ + SS58 Address: {}", + uri, + format_seed::(seed), + format_public_key::(public_key.clone()), + format_account_id::(public_key), + pair.public().into().into_account().to_ss58check(), + ); + }, + } + } else if let Ok((pair, seed)) = Pair::from_string_with_seed(uri, password) { + let public_key = pair.public(); + + match output { + OutputType::Json => { + let json = json!({ + "secretKeyUri": uri, + "secretSeed": if let Some(seed) = seed { format_seed::(seed) } else { "n/a".into() }, + "publicKey": format_public_key::(public_key.clone()), + "accountId": format_account_id::(public_key), + "ss58Address": pair.public().into().into_account().to_ss58check(), + }); + println!("{}", serde_json::to_string_pretty(&json).expect("Json pretty print failed")); + }, + OutputType::Text => { + println!("Secret Key URI `{}` is account:\n \ + Secret seed: {}\n \ + Public key (hex): {}\n \ + Account ID: {}\n \ + SS58 Address: {}", + uri, + if let Some(seed) = seed { format_seed::(seed) } else { "n/a".into() }, + format_public_key::(public_key.clone()), + format_account_id::(public_key), + pair.public().into().into_account().to_ss58check(), + ); + }, + } + } else if let Ok((public_key, _v)) = Pair::Public::from_string_with_version(uri) { + let v = network_override; + + match output { + OutputType::Json => { + let json = json!({ + "publicKeyUri": uri, + "networkId": String::from(v), + "publicKey": format_public_key::(public_key.clone()), + "accountId": format_account_id::(public_key.clone()), + "ss58Address": public_key.to_ss58check_with_version(v), + }); + println!("{}", serde_json::to_string_pretty(&json).expect("Json pretty print failed")); + }, + OutputType::Text => { + println!("Public Key URI `{}` is account:\n \ + Network ID/version: {}\n \ + Public key (hex): {}\n \ + Account ID: {}\n \ + SS58 Address: {}", + uri, + String::from(v), + format_public_key::(public_key.clone()), + format_account_id::(public_key.clone()), + public_key.to_ss58check_with_version(v), + ); + }, + } + } else { + println!("Invalid phrase/URI given"); + } +} + +/// generate a pair from suri +pub fn pair_from_suri(suri: &str, password: &str) -> P { + P::from_string(suri, Some(password)).expect("Invalid phrase") +} + /// formats seed as hex -pub fn format_seed(seed: SeedFor) -> String { +pub fn format_seed(seed: SeedFor

) -> String { format!("0x{}", HexDisplay::from(&seed.as_ref())) } /// formats public key as hex -fn format_public_key(public_key: PublicFor) -> String { +fn format_public_key(public_key: PublicFor

) -> String { format!("0x{}", HexDisplay::from(&public_key.as_ref())) } /// formats public key as accountId as hex -fn format_account_id(public_key: PublicFor) -> String +fn format_account_id(public_key: PublicFor

) -> String where - AccountIdFor: AsRef<[u8]>, + PublicFor

: Into, { - format!("0x{}", HexDisplay::from(&public_key.into_account().as_ref())) + format!("0x{}", HexDisplay::from(&public_key.into().into_account().as_ref())) } /// helper method for decoding hex @@ -250,13 +253,16 @@ pub fn read_message(msg: Option, should_decode: bool) -> Result, } /// create an extrinsic for the runtime. -pub fn create_extrinsic_for( +pub fn create_extrinsic_for( call: Call, nonce: IndexFor, - signer: RA::Pair, -) -> Result, Error> + signer: Pair, +) -> Result, Error> where Call: Encode, + Pair: sp_core::Pair, + Pair::Public: Into, + Pair::Signature: Encode, RA: RuntimeAdapter, { let extra = RA::build_extra(nonce); @@ -264,7 +270,7 @@ pub fn create_extrinsic_for( .map_err(|_| Error::Other("Transaction validity error".into()))?; let signature = payload.using_encoded(|payload| signer.sign(payload)); - let signer = signer.public(); + let signer = signer.public().into().into_account(); let (function, extra, _) = payload.deconstruct(); Ok(UncheckedExtrinsic::new_signed( diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index f50798a836961..1077c07ca4c52 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -16,11 +16,15 @@ //! implementation of the `vanity` subcommand -use crate::{RuntimeAdapter, error, format_seed, SharedParams, AccountIdFor, VersionInfo}; -use sp_core::{Pair, crypto::{Ss58Codec, Derive}}; +use crate::{ + error, format_seed, SharedParams, + VersionInfo, print_from_uri, with_crypto_scheme, +}; +use sp_core::crypto::Ss58Codec; use structopt::StructOpt; use rand::{rngs::OsRng, RngCore}; use sc_service::{Configuration, ChainSpec}; +use sp_runtime::traits::IdentifyAccount; /// The `vanity` command #[derive(Debug, StructOpt, Clone)] @@ -44,15 +48,18 @@ pub struct VanityCmd { impl VanityCmd { /// Run the command - pub fn run(self) -> error::Result<()> - where - RA: RuntimeAdapter, - AccountIdFor: Ss58Codec + Derive, - { + pub fn run(self) -> error::Result<()> { let desired: String = self.pattern.unwrap_or_default(); - let result = generate_key::(&desired)?; - let formated_seed = format_seed::(result.seed); - RA::print_from_uri(&formated_seed, None, self.shared_params.network, self.shared_params.output_type); + let formated_seed = with_crypto_scheme!(self.shared_params.scheme, generate_key(&desired))?; + with_crypto_scheme!( + self.shared_params.scheme, + print_from_uri( + &formated_seed, + None, + self.shared_params.network, + self.shared_params.output_type + ) + ); Ok(()) } @@ -73,10 +80,11 @@ impl VanityCmd { } /// genertae a key based on given pattern -fn generate_key(desired: &str) -> Result, &'static str> +fn generate_key(desired: &str) -> Result where - RA: RuntimeAdapter, - AccountIdFor: Ss58Codec + Derive, + Pair: sp_core::Pair, + Pair::Public: IdentifyAccount, + ::AccountId: Ss58Codec, { if desired.is_empty() { return Err("Pattern must not be empty"); @@ -86,7 +94,7 @@ fn generate_key(desired: &str) -> Result, &'static str> let top = 45 + (desired.len() * 48); let mut best = 0; - let mut seed = ::Seed::default(); + let mut seed = Pair::Seed::default(); let mut done = 0; loop { @@ -96,19 +104,14 @@ fn generate_key(desired: &str) -> Result, &'static str> next_seed(seed.as_mut()); } - let p = RA::Pair::from_seed(&seed); - let ss58 = RA::ss58_from_pair(&p); + let p = Pair::from_seed(&seed); + let ss58 = p.public().into_account().to_ss58check(); let score = calculate_score(&desired, &ss58); if score > best || desired.len() < 2 { best = score; - let keypair = KeyPair { - pair: p, - seed: seed.clone(), - score: score, - }; if best >= top { println!("best: {} == top: {}", best, top); - return Ok(keypair); + return Ok(format_seed::(seed.clone())); } } done += 1; @@ -142,14 +145,6 @@ fn next_seed(seed: &mut [u8]) { } } -/// A structure used to carry both Pair and seed. -/// This should usually NOT been used. If unsure, use Pair. -struct KeyPair { - pub pair: P, - pub seed:

::Seed, - pub score: usize, -} - /// Calculate the score of a key based on the desired /// input. fn calculate_score(_desired: &str, key: &str) -> usize { @@ -168,18 +163,19 @@ fn calculate_score(_desired: &str, key: &str) -> usize { mod tests { use super::*; use sp_core::{crypto::Ss58Codec, Pair}; - use crate::commands::tests::Adapter; + use sp_core::sr25519; #[cfg(feature = "bench")] use test::Bencher; #[test] fn test_generation_with_single_char() { - assert!(generate_key::("j") - .unwrap() - .pair - .public() - .to_ss58check() - .contains("j")); + let seed = generate_key::("j").unwrap(); + assert!( + sr25519::Pair::from_seed_slice(&hex::decode(&seed[2..]).unwrap()) + .unwrap() + .public() + .to_ss58check() + .contains("j")); } #[test] diff --git a/client/cli/src/commands/verify.rs b/client/cli/src/commands/verify.rs index 584b26280287a..16abf1bba130d 100644 --- a/client/cli/src/commands/verify.rs +++ b/client/cli/src/commands/verify.rs @@ -16,8 +16,11 @@ //! implementation of the `verify` subcommand -use crate::{RuntimeAdapter, read_message, decode_hex, read_uri, error, SharedParams, VersionInfo}; -use sp_core::{Pair, Public, crypto::Ss58Codec}; +use crate::{ + read_message, decode_hex, read_uri, + error, SharedParams, VersionInfo, with_crypto_scheme, +}; +use sp_core::{Public, crypto::Ss58Codec}; use structopt::StructOpt; use sc_service::{Configuration, ChainSpec}; @@ -54,20 +57,9 @@ pub struct VerifyCmd { impl VerifyCmd { /// Run the command - pub fn run(self) -> error::Result<()> { + pub fn run(self) -> error::Result<()> { let message = read_message(self.message, self.hex)?; - let mut signature = ::Signature::default(); let sig_data = decode_hex(self.sig)?; - - if sig_data.len() != signature.as_ref().len() { - return Err(error::Error::Other(format!( - "signature has an invalid length. read {} bytes, expected {} bytes", - sig_data.len(), - signature.as_ref().len(), - ))); - } - - signature.as_mut().copy_from_slice(&sig_data); let uri = read_uri(self.uri)?; let uri = if uri.starts_with("0x") { &uri[2..] @@ -75,21 +67,10 @@ impl VerifyCmd { &uri }; - let pubkey = if let Ok(pubkey_vec) = hex::decode(uri) { - RA::Public::from_slice(pubkey_vec.as_slice()) - } else { - RA::Public::from_string(uri) - .ok() - .expect("Invalid URI; expecting either a secret URI or a public URI.") - }; - - if ::verify(&signature, &message, &pubkey) { - println!("Signature verifies correctly."); - } else { - return Err(error::Error::Other("Signature invalid.".into())) - } - - Ok(()) + with_crypto_scheme!( + self.shared_params.scheme, + verify(sig_data, message, uri) + ) } /// Update and prepare a `Configuration` with command line parameters @@ -107,3 +88,35 @@ impl VerifyCmd { Ok(()) } } + +fn verify(sig_data: Vec, message: Vec, uri: &str) -> error::Result<()> + where + Pair: sp_core::Pair, + Pair::Signature: Default + AsMut<[u8]>, +{ + let mut signature = Pair::Signature::default(); + if sig_data.len() != signature.as_ref().len() { + return Err(error::Error::Other(format!( + "signature has an invalid length. read {} bytes, expected {} bytes", + sig_data.len(), + signature.as_ref().len(), + ))); + } + signature.as_mut().copy_from_slice(&sig_data); + + let pubkey = if let Ok(pubkey_vec) = hex::decode(uri) { + Pair::Public::from_slice(pubkey_vec.as_slice()) + } else { + Pair::Public::from_string(uri) + .ok() + .expect("Invalid URI; expecting either a secret URI or a public URI.") + }; + + if Pair::verify(&signature, &message, &pubkey) { + println!("Signature verifies correctly."); + } else { + return Err(error::Error::Other("Signature invalid.".into())) + } + + Ok(()) +} diff --git a/client/cli/src/params/shared_params.rs b/client/cli/src/params/shared_params.rs index 9b04a8d0fb59b..e11e064f6c5be 100644 --- a/client/cli/src/params/shared_params.rs +++ b/client/cli/src/params/shared_params.rs @@ -22,7 +22,7 @@ use sc_service::{ }; use sp_core::crypto::Ss58AddressFormat; use std::convert::TryFrom; -use crate::{error, VersionInfo, arg_enums::OutputType}; +use crate::{error, VersionInfo, arg_enums::{OutputType, CryptoScheme}}; /// default sub directory to store database const DEFAULT_DB_CONFIG_PATH : &'static str = "db"; @@ -89,6 +89,16 @@ pub struct SharedParams { default_value = "Text" )] pub output_type: OutputType, + + /// output format + #[structopt( + long, + value_name = "SCHEME", + possible_values = &CryptoScheme::variants(), + case_insensitive = true, + default_value = "Sr25519" + )] + pub scheme: CryptoScheme, } impl SharedParams { From ddbf1a8ba30ae997e960b69d4a0376966ae1101e Mon Sep 17 00:00:00 2001 From: Seun Date: Wed, 18 Mar 2020 08:39:52 +0100 Subject: [PATCH 10/77] fix update_config for subcommands --- client/cli/src/commands/generate.rs | 1 - client/cli/src/commands/generate_node_key.rs | 1 - client/cli/src/commands/insert.rs | 1 - client/cli/src/commands/inspect.rs | 1 - client/cli/src/commands/sign_transaction.rs | 1 - client/cli/src/commands/transfer.rs | 1 - client/cli/src/commands/vanity.rs | 1 - client/cli/src/commands/verify.rs | 1 - 8 files changed, 8 deletions(-) diff --git a/client/cli/src/commands/generate.rs b/client/cli/src/commands/generate.rs index 191664647ab9d..1d2b98501ce57 100644 --- a/client/cli/src/commands/generate.rs +++ b/client/cli/src/commands/generate.rs @@ -76,7 +76,6 @@ impl GenerateCmd { F: FnOnce(&str) -> Result, String>, { self.shared_params.update_config(&mut config, spec_factory, version)?; - config.use_in_memory_keystore()?; Ok(()) } diff --git a/client/cli/src/commands/generate_node_key.rs b/client/cli/src/commands/generate_node_key.rs index 28892a014da78..c4d3a22089b10 100644 --- a/client/cli/src/commands/generate_node_key.rs +++ b/client/cli/src/commands/generate_node_key.rs @@ -64,7 +64,6 @@ impl GenerateNodeKeyCmd { F: FnOnce(&str) -> Result, String>, { self.shared_params.update_config(&mut config, spec_factory, version)?; - config.use_in_memory_keystore()?; Ok(()) } diff --git a/client/cli/src/commands/insert.rs b/client/cli/src/commands/insert.rs index 7ceb2570049b2..a7b8f09410516 100644 --- a/client/cli/src/commands/insert.rs +++ b/client/cli/src/commands/insert.rs @@ -98,7 +98,6 @@ impl InsertCmd { F: FnOnce(&str) -> Result, String>, { self.shared_params.update_config(&mut config, spec_factory, version)?; - config.use_in_memory_keystore()?; Ok(()) } diff --git a/client/cli/src/commands/inspect.rs b/client/cli/src/commands/inspect.rs index aa8a9e6c13b67..59d617da47774 100644 --- a/client/cli/src/commands/inspect.rs +++ b/client/cli/src/commands/inspect.rs @@ -68,7 +68,6 @@ impl InspectCmd { F: FnOnce(&str) -> Result, String>, { self.shared_params.update_config(&mut config, spec_factory, version)?; - config.use_in_memory_keystore()?; Ok(()) } diff --git a/client/cli/src/commands/sign_transaction.rs b/client/cli/src/commands/sign_transaction.rs index 1799c8c116899..efed2cc8ad587 100644 --- a/client/cli/src/commands/sign_transaction.rs +++ b/client/cli/src/commands/sign_transaction.rs @@ -85,7 +85,6 @@ impl SignTransactionCmd { F: FnOnce(&str) -> Result, String>, { self.shared_params.update_config(&mut config, spec_factory, version)?; - config.use_in_memory_keystore()?; Ok(()) } diff --git a/client/cli/src/commands/transfer.rs b/client/cli/src/commands/transfer.rs index 47128d9af4da8..871634fee859a 100644 --- a/client/cli/src/commands/transfer.rs +++ b/client/cli/src/commands/transfer.rs @@ -93,7 +93,6 @@ impl TransferCmd { F: FnOnce(&str) -> Result, String>, { self.shared_params.update_config(&mut config, spec_factory, version)?; - config.use_in_memory_keystore()?; Ok(()) } diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index 1077c07ca4c52..c64fdecc91f0d 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -73,7 +73,6 @@ impl VanityCmd { F: FnOnce(&str) -> Result, String>, { self.shared_params.update_config(&mut config, spec_factory, version)?; - config.use_in_memory_keystore()?; Ok(()) } diff --git a/client/cli/src/commands/verify.rs b/client/cli/src/commands/verify.rs index 16abf1bba130d..36a3cfe709e7e 100644 --- a/client/cli/src/commands/verify.rs +++ b/client/cli/src/commands/verify.rs @@ -83,7 +83,6 @@ impl VerifyCmd { F: FnOnce(&str) -> Result, String>, { self.shared_params.update_config(&mut config, spec_factory, version)?; - config.use_in_memory_keystore()?; Ok(()) } From fa4feb1a3e7ace680e1e9017e20c3f89f316c771 Mon Sep 17 00:00:00 2001 From: Seun Date: Wed, 18 Mar 2020 09:29:49 +0100 Subject: [PATCH 11/77] proper AccountId decoding --- Cargo.lock | 5 ----- bin/node-template/node/Cargo.toml | 1 - bin/node-template/runtime/src/lib.rs | 6 +++--- client/cli/Cargo.toml | 3 --- client/cli/src/commands/mod.rs | 3 +++ client/cli/src/commands/transfer.rs | 19 ++++++++++++------- client/cli/src/commands/utils.rs | 6 ++++-- client/cli/src/params/shared_params.rs | 2 +- test-utils/runtime/Cargo.toml | 8 +++----- test-utils/runtime/src/lib.rs | 14 +------------- 10 files changed, 27 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e95d89948a23b..284368f41fcee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4000,7 +4000,6 @@ dependencies = [ "futures 0.3.4", "log 0.4.8", "node-template-runtime", - "pallet-indices", "pallet-transaction-payment", "sc-basic-authorship", "sc-cli", @@ -6151,7 +6150,6 @@ dependencies = [ "derive_more", "env_logger 0.7.1", "fdlimit", - "frame-support", "frame-system", "futures 0.1.29", "futures 0.3.4", @@ -6164,8 +6162,6 @@ dependencies = [ "log 0.4.8", "names", "pallet-balances", - "pallet-indices", - "pallet-transaction-payment", "parity-scale-codec", "parity-util-mem", "rand 0.7.3", @@ -8264,7 +8260,6 @@ dependencies = [ "memory-db", "pallet-babe", "pallet-balances", - "pallet-indices", "pallet-timestamp", "parity-scale-codec", "parity-util-mem", diff --git a/bin/node-template/node/Cargo.toml b/bin/node-template/node/Cargo.toml index 69f429e718ab8..3a152848cd1ce 100644 --- a/bin/node-template/node/Cargo.toml +++ b/bin/node-template/node/Cargo.toml @@ -35,7 +35,6 @@ sp-runtime = { version = "2.0.0-alpha.2", path = "../../../primitives/runtime" } sc-basic-authorship = { path = "../../../client/basic-authorship" , version = "0.8.0-alpha.2"} frame-system = { version = "2.0.0-alpha.3", path= "../../../frame/system" } pallet-transaction-payment = { version = "2.0.0-alpha.3", path = "../../../frame/transaction-payment" } -pallet-indices = { version = "2.0.0-alpha.3", path = "../../../frame/indices" } node-template-runtime = { version = "2.0.0-alpha.2", path = "../runtime" } [build-dependencies] diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index cb3f630925150..0414759a5ad86 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -9,10 +9,10 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); use sp_std::prelude::*; -use sp_core::{OpaqueMetadata, sr25519}; +use sp_core::OpaqueMetadata; use sp_runtime::{ ApplyExtrinsicResult, transaction_validity::TransactionValidity, generic, create_runtime_str, - impl_opaque_keys, + impl_opaque_keys, MultiSignature, }; use sp_runtime::traits::{ BlakeTwo256, Block as BlockT, IdentityLookup, Verify, ConvertInto, IdentifyAccount @@ -44,7 +44,7 @@ pub use template; pub type BlockNumber = u32; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. -pub type Signature = sr25519::Signature; +pub type Signature = MultiSignature; /// Some way of identifying an account on the chain. We intentionally make it equivalent /// to the public key of our transaction signing scheme. diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index fe8799256b50f..2b55b2d1cf16b 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -26,10 +26,7 @@ serde_json = "1.0.41" parity-scale-codec = "1.2.0" hex = "0.4.2" frame-system = { version = "2.0.0-alpha.3", path = "../../frame/system" } -frame-support = { version = "2.0.0-alpha.3", path = "../../frame/support" } pallet-balances = { version = "2.0.0-alpha.3", path = "../../frame/balances" } -pallet-indices = { version = "2.0.0-alpha.3", path = "../../frame/indices" } -pallet-transaction-payment = { version = "2.0.0-alpha.3", path = "../../frame/transaction-payment" } sc-informant = { version = "0.8.0-alpha.2", path = "../informant" } sp-panic-handler = { version = "2.0.0-alpha.2", path = "../../primitives/panic-handler" } sp-version = { version = "2.0.0-alpha.3", path = "../../primitives/version" } diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 24a25b516631a..839c93d10f519 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -61,6 +61,8 @@ pub use crate::commands::sign_transaction::SignTransactionCmd; pub use crate::commands::transfer::TransferCmd; pub use crate::commands::vanity::VanityCmd; pub use crate::commands::verify::VerifyCmd; +use std::convert::TryFrom; +use sp_core::crypto::Ss58Codec; /// default sub directory to store network config @@ -156,6 +158,7 @@ impl Subcommand { <::Number as std::str::FromStr>::Err: std::fmt::Debug, Block::Hash: std::str::FromStr, RA: RuntimeAdapter, + AddressFor: for<'a> TryFrom<&'a [u8], Error = ()> + Ss58Codec, as FromStr>::Err: Display, as FromStr>::Err: Display, CallFor: Codec, diff --git a/client/cli/src/commands/transfer.rs b/client/cli/src/commands/transfer.rs index 871634fee859a..03d15bed95e12 100644 --- a/client/cli/src/commands/transfer.rs +++ b/client/cli/src/commands/transfer.rs @@ -16,17 +16,16 @@ //! Implementation of the `transfer` subcommand -use crate::{ - error, IndexFor, BalanceFor, create_extrinsic_for, get_password, - AddressFor, VersionInfo, with_crypto_scheme, pair_from_suri, -}; +use crate::{error, IndexFor, BalanceFor, create_extrinsic_for, get_password, AddressFor, VersionInfo, with_crypto_scheme, pair_from_suri, decode_hex}; use super::{SharedParams, RuntimeAdapter}; use structopt::StructOpt; use pallet_balances::Call as BalancesCall; use std::{str::FromStr, fmt::Display}; -use parity_scale_codec::{Encode, Decode}; +use parity_scale_codec::Encode; use sc_service::{Configuration, ChainSpec}; use sp_runtime::MultiSigner; +use std::convert::TryFrom; +use sp_core::crypto::Ss58Codec; /// The `transfer` command #[derive(Debug, StructOpt, Clone)] @@ -62,13 +61,19 @@ impl TransferCmd { pub fn run(self) -> error::Result<()> where RA: RuntimeAdapter, - AddressFor: Decode, + AddressFor: for<'a> TryFrom<&'a [u8], Error = ()> + Ss58Codec, as FromStr>::Err: Display, as FromStr>::Err: Display, { let password = get_password(&self.shared_params)?; let nonce = IndexFor::::from_str(&self.index).map_err(|e| format!("{}", e))?; - let to = AddressFor::::decode(&mut self.to.as_bytes()).map_err(|e| format!("{}", e))?; + let to = if let Ok(data_vec) = decode_hex(&self.to) { + AddressFor::::try_from(&data_vec) + .expect("Invalid hex length for account ID; should be 32 bytes") + } else { + AddressFor::::from_ss58check(&self.to).ok() + .expect("Invalid SS58-check address given for account ID.") + }; let amount = BalanceFor::::from_str(&self.amount).map_err(|e| format!("{}", e))?; with_crypto_scheme!( diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index cc822f0b66a21..677d76c558d76 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -32,8 +32,6 @@ pub type PublicFor

=

::Public; pub type SeedFor

=

::Seed; /// AccountIndex type for Runtime pub type IndexFor = <::Runtime as frame_system::Trait>::Index; -/// AccountId type for Runtime -pub type AccountIdFor = <::Runtime as frame_system::Trait>::AccountId; /// Balance type pub type BalanceFor = <::Runtime as pallet_balances::Trait>::Balance; /// Call type for Runtime @@ -231,6 +229,10 @@ fn format_account_id(public_key: PublicFor

) -> String /// helper method for decoding hex pub fn decode_hex>(message: T) -> Result, Error> { + let mut message = message.as_ref(); + if message[..2] == [b'0', b'x'] { + message = &message[2..] + } hex::decode(message) .map_err(|e| Error::Other(format!("Invalid hex ({})", e))) } diff --git a/client/cli/src/params/shared_params.rs b/client/cli/src/params/shared_params.rs index e11e064f6c5be..a878d8b4a9296 100644 --- a/client/cli/src/params/shared_params.rs +++ b/client/cli/src/params/shared_params.rs @@ -90,7 +90,7 @@ pub struct SharedParams { )] pub output_type: OutputType, - /// output format + /// cryptography scheme #[structopt( long, value_name = "SCHEME", diff --git a/test-utils/runtime/Cargo.toml b/test-utils/runtime/Cargo.toml index 2343a996b524b..c8fea053e0066 100644 --- a/test-utils/runtime/Cargo.toml +++ b/test-utils/runtime/Cargo.toml @@ -32,12 +32,11 @@ serde = { version = "1.0.101", optional = true, features = ["derive"] } sp-session = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/session" } sp-api = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/api" } sp-runtime = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/runtime" } -frame-system = { version = "2.0.0-alpha.2", default-features = false, path = "../../frame/system" } -frame-system-rpc-runtime-api = { version = "2.0.0-alpha.2", default-features = false, path = "../../frame/system/rpc/runtime-api" } pallet-babe = { version = "2.0.0-alpha.2", default-features = false, path = "../../frame/babe" } -pallet-timestamp = { version = "2.0.0-alpha.3", default-features = false, path = "../../frame/timestamp" } -pallet-indices = { version = "2.0.0-alpha.3", default-features = false, path = "../../frame/indices" } pallet-balances = { version = "2.0.0-alpha.3", default-features = false, path = "../../frame/balances" } +frame-system = { version = "2.0.0-alpha.2", default-features = false, path = "../../frame/system" } +frame-system-rpc-runtime-api = { version = "2.0.0-alpha.2", default-features = false, path = "../../frame/system/rpc/runtime-api" } +pallet-timestamp = { version = "2.0.0-alpha.2", default-features = false, path = "../../frame/timestamp" } sc-client = { version = "0.8.0-alpha.2", optional = true, path = "../../client" } sp-trie = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/trie" } sp-transaction-pool = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/transaction-pool" } @@ -82,7 +81,6 @@ std = [ "sp-api/std", "sp-runtime/std", "pallet-babe/std", - "pallet-indices/std", "frame-system-rpc-runtime-api/std", "frame-system/std", "pallet-timestamp/std", diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index 6ffbac026cd5a..bf263cf8f10f6 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -39,7 +39,7 @@ use sp_runtime::{ }, traits::{ BlindCheckable, BlakeTwo256, Block as BlockT, Extrinsic as ExtrinsicT, - GetNodeBlockType, GetRuntimeBlockType, Verify, + GetNodeBlockType, GetRuntimeBlockType, Verify, IdentityLookup, }, }; use sp_version::RuntimeVersion; @@ -363,7 +363,6 @@ impl_outer_event!{ pub enum MetaEvent for Runtime { frame_system, pallet_balances, - pallet_indices, } } @@ -377,13 +376,6 @@ parameter_types! { pub const ExistentialDeposit: u64 = 1; } -impl pallet_indices::Trait for Runtime { - type AccountIndex = u64; - type Currency = pallet_balances::Module; - type Deposit = Deposit; - type Event = MetaEvent; -} - impl pallet_balances::Trait for Runtime { type Balance = u64; type DustRemoval = (); @@ -403,9 +395,6 @@ impl frame_system::Trait for Runtime { type AccountId = sr25519::Public; #[cfg(not(feature = "indices-lookup"))] type AccountId = u64; - #[cfg(feature = "indices-lookup")] - type Lookup = pallet_indices::Module; - #[cfg(not(feature = "indices-lookup"))] type Lookup = IdentityLookup; type Header = Header; type Event = MetaEvent; @@ -974,7 +963,6 @@ mod tests { use sp_core::storage::well_known_keys::HEAP_PAGES; use sp_state_machine::ExecutionStrategy; use codec::Encode; - use sc_block_builder::BlockBuilderProvider; #[test] fn heap_pages_is_respected() { From 4815f3d4e09b629d43f070edee55933c241326f5 Mon Sep 17 00:00:00 2001 From: Seun Date: Wed, 18 Mar 2020 09:32:53 +0100 Subject: [PATCH 12/77] test-runtime tests --- test-utils/runtime/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index bf263cf8f10f6..e675986f31592 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -963,6 +963,7 @@ mod tests { use sp_core::storage::well_known_keys::HEAP_PAGES; use sp_state_machine::ExecutionStrategy; use codec::Encode; + use sc_block_builder::BlockBuilderProvider; #[test] fn heap_pages_is_respected() { From f8a672843b94fcbc183657fad9de5d394b82e784 Mon Sep 17 00:00:00 2001 From: Seun Date: Fri, 20 Mar 2020 13:37:34 +0100 Subject: [PATCH 13/77] revert --- .maintain/rename-crates-for-2.0.sh | 2 +- Cargo.lock | 15 ++++++- Cargo.toml | 1 + bin/node-template/node/Cargo.toml | 1 + bin/node-template/node/src/cli.rs | 22 +--------- bin/node-template/node/src/command.rs | 5 ++- bin/node-template/runtime/Cargo.toml | 3 +- bin/node-template/runtime/src/lib.rs | 27 +++++++++--- bin/node/cli/build.rs | 4 +- bin/node/cli/src/command.rs | 19 --------- bin/node/runtime/Cargo.toml | 3 ++ bin/node/runtime/src/lib.rs | 17 ++++++++ client/cli/Cargo.toml | 40 +++++++++--------- client/cli/src/commands/insert.rs | 8 ++-- client/cli/src/commands/mod.rs | 1 + client/cli/src/commands/sign_transaction.rs | 5 ++- client/cli/src/commands/tests.rs | 9 ++-- client/cli/src/commands/transfer.rs | 11 +++-- client/cli/src/commands/utils.rs | 41 ++++++------------- .../params/network_configuration_params.rs | 2 +- .../cli/src/params/transaction_pool_params.rs | 2 +- utils/cli-utils/Cargo.toml | 23 +++++++++++ utils/cli-utils/src/lib.rs | 39 ++++++++++++++++++ 23 files changed, 183 insertions(+), 117 deletions(-) create mode 100644 utils/cli-utils/Cargo.toml create mode 100644 utils/cli-utils/src/lib.rs diff --git a/.maintain/rename-crates-for-2.0.sh b/.maintain/rename-crates-for-2.0.sh index 5d873d26cdfca..7ac444fdd7193 100755 --- a/.maintain/rename-crates-for-2.0.sh +++ b/.maintain/rename-crates-for-2.0.sh @@ -95,7 +95,7 @@ TO_RENAME=( "substrate-block-builder sc-block-builder" "substrate-chain-spec sc-chain-spec" "substrate-chain-spec-derive sc-chain-spec-derive" - "substrate-cli sc-cli" + "substrate-cli-utils sc-cli-utils" "substrate-consensus-aura sc-consensus-aura" "substrate-consensus-babe sc-consensus-babe" "substrate-consensus-pow sc-consensus-pow" diff --git a/Cargo.lock b/Cargo.lock index 284368f41fcee..a4849231999ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -625,6 +625,15 @@ dependencies = [ "cc", ] +[[package]] +name = "cli-utils" +version = "2.0.0-alpha.3" +dependencies = [ + "frame-system", + "pallet-balances", + "sp-runtime", +] + [[package]] name = "cloudabi" version = "0.0.3" @@ -3934,6 +3943,7 @@ dependencies = [ name = "node-runtime" version = "2.0.0-alpha.3" dependencies = [ + "cli-utils", "frame-benchmarking", "frame-executive", "frame-support", @@ -3996,6 +4006,7 @@ dependencies = [ name = "node-template" version = "2.0.0-alpha.3" dependencies = [ + "cli-utils", "frame-system", "futures 0.3.4", "log 0.4.8", @@ -4027,6 +4038,7 @@ dependencies = [ name = "node-template-runtime" version = "2.0.0-alpha.3" dependencies = [ + "cli-utils", "frame-executive", "frame-support", "frame-system", @@ -6147,10 +6159,10 @@ dependencies = [ "atty", "chrono", "clap", + "cli-utils", "derive_more", "env_logger 0.7.1", "fdlimit", - "frame-system", "futures 0.1.29", "futures 0.3.4", "hex", @@ -6161,7 +6173,6 @@ dependencies = [ "libp2p 0.15.0", "log 0.4.8", "names", - "pallet-balances", "parity-scale-codec", "parity-util-mem", "rand 0.7.3", diff --git a/Cargo.toml b/Cargo.toml index 0459bc8ebbd6a..c173e292713b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -157,6 +157,7 @@ members = [ "test-utils/runtime/transaction-pool", "utils/browser", "utils/build-script-utils", + "utils/cli-utils", "utils/fork-tree", "utils/frame/benchmarking-cli", "utils/frame/rpc/support", diff --git a/bin/node-template/node/Cargo.toml b/bin/node-template/node/Cargo.toml index 3a152848cd1ce..f702928a968be 100644 --- a/bin/node-template/node/Cargo.toml +++ b/bin/node-template/node/Cargo.toml @@ -32,6 +32,7 @@ grandpa-primitives = { version = "2.0.0-alpha.2", package = "sp-finality-grandpa sc-client = { version = "0.8.0-alpha.2", path = "../../../client/" } sc-client-api = { version = "2.0.0-alpha.2", path = "../../../client/api" } sp-runtime = { version = "2.0.0-alpha.2", path = "../../../primitives/runtime" } +cli-utils = { version = "2.0.0-alpha.3", path = "../../../utils/cli-utils" } sc-basic-authorship = { path = "../../../client/basic-authorship" , version = "0.8.0-alpha.2"} frame-system = { version = "2.0.0-alpha.3", path= "../../../frame/system" } pallet-transaction-payment = { version = "2.0.0-alpha.3", path = "../../../frame/transaction-payment" } diff --git a/bin/node-template/node/src/cli.rs b/bin/node-template/node/src/cli.rs index 15ceff50821af..46ab9bc3dafac 100644 --- a/bin/node-template/node/src/cli.rs +++ b/bin/node-template/node/src/cli.rs @@ -1,7 +1,5 @@ use structopt::StructOpt; -use sc_cli::{RunCmd, Subcommand, RuntimeAdapter}; -use node_template_runtime::{Runtime, SignedExtra, Index}; -use sp_runtime::generic::Era; +use sc_cli::{RunCmd, Subcommand}; #[derive(Debug, StructOpt)] pub struct Cli { @@ -11,21 +9,3 @@ pub struct Cli { #[structopt(flatten)] pub run: RunCmd, } - -pub struct Adapter; - -impl RuntimeAdapter for Adapter { - type Runtime = Runtime; - type Extra = SignedExtra; - - fn build_extra(index: Index) -> Self::Extra { - ( - frame_system::CheckVersion::new(), - frame_system::CheckGenesis::new(), - frame_system::CheckEra::from(Era::Immortal), - frame_system::CheckNonce::from(index), - frame_system::CheckWeight::new(), - pallet_transaction_payment::ChargeTransactionPayment::from(0), - ) - } -} diff --git a/bin/node-template/node/src/command.rs b/bin/node-template/node/src/command.rs index 24467e7ca285f..57101185d2442 100644 --- a/bin/node-template/node/src/command.rs +++ b/bin/node-template/node/src/command.rs @@ -16,7 +16,8 @@ use sp_consensus_aura::sr25519::{AuthorityPair as AuraPair}; use sc_cli::VersionInfo; -use crate::{chain_spec, service, cli::{Cli, Adapter}}; +use node_template_runtime::Runtime; +use crate::{chain_spec, service, cli::Cli}; /// Parse and run command line arguments pub fn run(version: VersionInfo) -> sc_cli::Result<()> { @@ -28,7 +29,7 @@ pub fn run(version: VersionInfo) -> sc_cli::Result<()> { Some(subcommand) => { subcommand.init(&version)?; subcommand.update_config(&mut config, chain_spec::load_spec, &version)?; - subcommand.run::( + subcommand.run::( config, |config: _| Ok(new_full_start!(config).0), ) diff --git a/bin/node-template/runtime/Cargo.toml b/bin/node-template/runtime/Cargo.toml index 9268dd8c05035..1321c3e23910a 100644 --- a/bin/node-template/runtime/Cargo.toml +++ b/bin/node-template/runtime/Cargo.toml @@ -33,7 +33,7 @@ sp-session = { version = "2.0.0-alpha.2", default-features = false, path = "../. sp-std = { version = "2.0.0-alpha.2", default-features = false, path = "../../../primitives/std" } sp-transaction-pool = { version = "2.0.0-alpha.2", default-features = false, path = "../../../primitives/transaction-pool" } sp-version = { version = "2.0.0-alpha.2", default-features = false, path = "../../../primitives/version" } - +cli-utils = { version = "2.0.0-alpha.3", default-features = false, path = "../../../utils/cli-utils" } template = { version = "2.0.0-alpha.2", default-features = false, path = "../pallets/template", package = "pallet-template" } [build-dependencies] @@ -67,4 +67,5 @@ std = [ "timestamp/std", "transaction-payment/std", "template/std", + "cli-utils/std", ] diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index 0414759a5ad86..1a28d6e3990f4 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -11,12 +11,14 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); use sp_std::prelude::*; use sp_core::OpaqueMetadata; use sp_runtime::{ - ApplyExtrinsicResult, transaction_validity::TransactionValidity, generic, create_runtime_str, - impl_opaque_keys, MultiSignature, -}; -use sp_runtime::traits::{ - BlakeTwo256, Block as BlockT, IdentityLookup, Verify, ConvertInto, IdentifyAccount + ApplyExtrinsicResult, transaction_validity::TransactionValidity, + generic::{self, Era}, create_runtime_str, impl_opaque_keys, MultiSignature, + traits::{ + BlakeTwo256, Block as BlockT, IdentityLookup, + Verify, ConvertInto, IdentifyAccount, + }, }; +use cli_utils::RuntimeAdapter; use sp_api::impl_runtime_apis; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use grandpa::AuthorityList as GrandpaAuthorityList; @@ -357,3 +359,18 @@ impl_runtime_apis! { } } } + +impl RuntimeAdapter for Runtime { + type Extra = SignedExtra; + + fn build_extra(index: Index) -> Self::Extra { + ( + system::CheckVersion::new(), + system::CheckGenesis::new(), + system::CheckEra::from(Era::Immortal), + system::CheckNonce::from(index), + system::CheckWeight::new(), + transaction_payment::ChargeTransactionPayment::from(0), + ) + } +} diff --git a/bin/node/cli/build.rs b/bin/node/cli/build.rs index e824b59be64f3..3f3c0b3427f2a 100644 --- a/bin/node/cli/build.rs +++ b/bin/node/cli/build.rs @@ -15,8 +15,8 @@ // along with Substrate. If not, see . fn main() { - #[cfg(feature = "cli")] - cli::main(); + // #[cfg(feature = "cli")] + // cli::main(); } #[cfg(feature = "cli")] diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index 6d4d54dd324f1..dd05c05f41c55 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -119,22 +119,3 @@ where }, } } - -struct Adapter; - -impl sc_cli::RuntimeAdapter for Adapter { - type Runtime = Runtime; - type Extra = SignedExtra; - - fn build_extra(index: Index) -> Self::Extra { - ( - frame_system::CheckVersion::new(), - frame_system::CheckGenesis::new(), - frame_system::CheckEra::from(Era::Immortal), - frame_system::CheckNonce::from(index), - frame_system::CheckWeight::new(), - pallet_transaction_payment::ChargeTransactionPayment::from(0), - pallet_contracts::CheckBlockGasLimit::default(), - ) - } -} diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index 15672715a415d..84d8718ab7741 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -70,6 +70,8 @@ pallet-transaction-payment = { version = "2.0.0-alpha.2", default-features = fal pallet-transaction-payment-rpc-runtime-api = { version = "2.0.0-alpha.2", default-features = false, path = "../../../frame/transaction-payment/rpc/runtime-api/" } pallet-vesting = { version = "2.0.0-alpha.2", default-features = false, path = "../../../frame/vesting" } +cli-utils = { version = "2.0.0-alpha.3", default-features = false, path = "../../../utils/cli-utils" } + [build-dependencies] wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-runner", path = "../../../utils/wasm-builder-runner" } @@ -131,6 +133,7 @@ std = [ "pallet-society/std", "pallet-recovery/std", "pallet-vesting/std", + "cli-utils/std", ] runtime-benchmarks = [ "frame-benchmarking", diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index ed10357e5983f..c5f7525c16771 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -68,6 +68,7 @@ use impls::{CurrencyToVoteHandler, Author, LinearWeightToFee, TargetedFeeAdjustm /// Constant values used within the runtime. pub mod constants; use constants::{time::*, currency::*}; +use sp_runtime::generic::Era; // Make the WASM binary available. #[cfg(feature = "std")] @@ -888,6 +889,22 @@ impl_runtime_apis! { } } +impl cli_utils::RuntimeAdapter for Runtime { + type Extra = SignedExtra; + + fn build_extra(index: Index) -> Self::Extra { + ( + frame_system::CheckVersion::new(), + frame_system::CheckGenesis::new(), + frame_system::CheckEra::from(Era::Immortal), + frame_system::CheckNonce::from(index), + frame_system::CheckWeight::new(), + pallet_transaction_payment::ChargeTransactionPayment::from(0), + pallet_contracts::CheckBlockGasLimit::default(), + ) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 2b55b2d1cf16b..cd9726b883b84 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -25,36 +25,38 @@ fdlimit = "0.1.1" serde_json = "1.0.41" parity-scale-codec = "1.2.0" hex = "0.4.2" -frame-system = { version = "2.0.0-alpha.3", path = "../../frame/system" } -pallet-balances = { version = "2.0.0-alpha.3", path = "../../frame/balances" } -sc-informant = { version = "0.8.0-alpha.2", path = "../informant" } +names = "0.11.0" +structopt = "0.3.11" +hyper = "0.12.35" +rand = "0.7.2" +serde = "1.0.104" +futures01 = { package = "futures", version = "0.1.29" } +tiny-bip39 = "0.6.2" +libp2p = "0.15.0" +hex-literal = "0.2.1" +chrono = "0.4.10" + sp-panic-handler = { version = "2.0.0-alpha.2", path = "../../primitives/panic-handler" } sp-version = { version = "2.0.0-alpha.3", path = "../../primitives/version" } sp-io = { version = "2.0.0-alpha.3", path = "../../primitives/io" } -sc-client-api = { version = "2.0.0-alpha.2", path = "../api" } sp-blockchain = { version = "2.0.0-alpha.2", path = "../../primitives/blockchain" } -sc-network = { version = "0.8.0-alpha.2", path = "../network" } sp-runtime = { version = "2.0.0-alpha.2", path = "../../primitives/runtime" } sp-core = { version = "2.0.0-alpha.2", path = "../../primitives/core", features = [ "full_crypto"] } -sc-service = { version = "0.8.0-alpha.2", default-features = false, path = "../service" } sp-state-machine = { version = "0.8.0-alpha.2", path = "../../primitives/state-machine" } -sc-telemetry = { version = "2.0.0-alpha.2", path = "../telemetry" } -substrate-prometheus-endpoint = { path = "../../utils/prometheus" , version = "0.8.0-alpha.2"} sp-keyring = { version = "2.0.0-alpha.2", path = "../../primitives/keyring" } -names = "0.11.0" -structopt = "0.3.11" -hyper = "0.12.35" -rand = "0.7.2" -serde = "1.0.104" -futures01 = { package = "futures", version = "0.1.29" } + +sc-informant = { version = "0.8.0-alpha.2", path = "../informant" } +sc-tracing = { version = "2.0.0-alpha.2", path = "../tracing" } sc-rpc = { version = "2.0.0-alpha.3", path = "../../client/rpc" } +sc-client-api = { version = "2.0.0-alpha.2", path = "../api" } +sc-network = { version = "0.8.0-alpha.2", path = "../network" } +sc-service = { version = "0.8.0-alpha.2", default-features = false, path = "../service" } +sc-telemetry = { version = "2.0.0-alpha.2", path = "../telemetry" } + +substrate-prometheus-endpoint = { path = "../../utils/prometheus" , version = "0.8.0-alpha.2"} +cli-utils = { version = "2.0.0-alpha.3", path = "../../utils/cli-utils" } jsonrpc-core-client = { version = "14.0.3", features = ["http"] } -sc-tracing = { version = "2.0.0-alpha.2", path = "../tracing" } -chrono = "0.4.10" parity-util-mem = { version = "0.5.1", default-features = false, features = ["primitive-types"] } -tiny-bip39 = "0.6.2" -libp2p = "0.15.0" -hex-literal = "0.2.1" [target.'cfg(not(target_os = "unknown"))'.dependencies] rpassword = "4.0.1" diff --git a/client/cli/src/commands/insert.rs b/client/cli/src/commands/insert.rs index a7b8f09410516..59c6c62221d8a 100644 --- a/client/cli/src/commands/insert.rs +++ b/client/cli/src/commands/insert.rs @@ -16,8 +16,8 @@ //! Implementation of the `insert` subcommand -use crate::{error, HashFor, VersionInfo, with_crypto_scheme, pair_from_suri}; -use super::{SharedParams, get_password, read_uri, RuntimeAdapter}; +use crate::{error, VersionInfo, with_crypto_scheme, pair_from_suri}; +use super::{SharedParams, get_password, read_uri}; use structopt::StructOpt; use sp_core::{crypto::KeyTypeId, Bytes}; use std::convert::TryFrom; @@ -27,6 +27,7 @@ use sc_rpc::author::AuthorClient; use jsonrpc_core_client::transports::http; use serde::{de::DeserializeOwned, Serialize}; use sc_service::{Configuration, ChainSpec}; +use cli_utils::{HashFor, RuntimeAdapter}; /// The `insert` command #[derive(Debug, StructOpt, Clone)] @@ -56,8 +57,9 @@ pub struct InsertCmd { impl InsertCmd { /// Run the command - pub fn run(self) -> error::Result<()> + pub fn run(self) -> error::Result<()> where + RA: RuntimeAdapter, HashFor: DeserializeOwned + Serialize + Send + Sync, { let suri = read_uri(self.suri)?; diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 839c93d10f519..eefeb083e3daa 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -63,6 +63,7 @@ pub use crate::commands::vanity::VanityCmd; pub use crate::commands::verify::VerifyCmd; use std::convert::TryFrom; use sp_core::crypto::Ss58Codec; +use cli_utils::{RuntimeAdapter, AddressFor, IndexFor, BalanceFor, CallFor}; /// default sub directory to store network config diff --git a/client/cli/src/commands/sign_transaction.rs b/client/cli/src/commands/sign_transaction.rs index efed2cc8ad587..dae916a3660f3 100644 --- a/client/cli/src/commands/sign_transaction.rs +++ b/client/cli/src/commands/sign_transaction.rs @@ -17,14 +17,15 @@ //! Implementation of the `sign-transaction` subcommand use crate::{error, VersionInfo, with_crypto_scheme}; use super::{ - SharedParams, get_password, decode_hex, create_extrinsic_for, - RuntimeAdapter, IndexFor, CallFor, pair_from_suri, + SharedParams, get_password, + IndexFor, CallFor, pair_from_suri, decode_hex, create_extrinsic_for, }; use structopt::StructOpt; use parity_scale_codec::{Codec, Encode, Decode}; use std::{str::FromStr, fmt::Display}; use sc_service::{Configuration, ChainSpec}; use sp_runtime::MultiSigner; +use cli_utils::RuntimeAdapter; type Call = Vec; diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs index 15ccd2a356a2a..820734eec8a7f 100644 --- a/client/cli/src/commands/tests.rs +++ b/client/cli/src/commands/tests.rs @@ -23,10 +23,7 @@ use std::io::Read; use crate::commands::inspect::InspectCmd; use crate::Error; -pub struct Adapter; - -impl RuntimeAdapter for Adapter { - type Runtime = Runtime; +impl RuntimeAdapter for Runtime { type Extra = ( frame_system::CheckVersion, frame_system::CheckGenesis, @@ -117,13 +114,13 @@ fn transfer() { ]); new_test_ext().execute_with(|| { - assert!(matches!(transfer.run::(), Ok(()))); + assert!(matches!(transfer.run::(), Ok(()))); let transfer = TransferCmd::from_iter(&["transfer", "--from", words, "--to", "0xa2bc899a8a3b16a284a8cefcbc2dc48a687cd674e89b434fbbdb06f400979744", "--amount", "5000", "--index", "1", ]); - assert!(matches!(transfer.run::(), Err(Error::Input(_)))) + assert!(matches!(transfer.run::(), Err(Error::Input(_)))) }); } \ No newline at end of file diff --git a/client/cli/src/commands/transfer.rs b/client/cli/src/commands/transfer.rs index 03d15bed95e12..4d87ed34fa57e 100644 --- a/client/cli/src/commands/transfer.rs +++ b/client/cli/src/commands/transfer.rs @@ -16,16 +16,19 @@ //! Implementation of the `transfer` subcommand -use crate::{error, IndexFor, BalanceFor, create_extrinsic_for, get_password, AddressFor, VersionInfo, with_crypto_scheme, pair_from_suri, decode_hex}; -use super::{SharedParams, RuntimeAdapter}; +use crate::{ + error, create_extrinsic_for, get_password, + with_crypto_scheme, pair_from_suri, decode_hex, VersionInfo, +}; +use super::SharedParams; use structopt::StructOpt; -use pallet_balances::Call as BalancesCall; use std::{str::FromStr, fmt::Display}; use parity_scale_codec::Encode; use sc_service::{Configuration, ChainSpec}; use sp_runtime::MultiSigner; use std::convert::TryFrom; use sp_core::crypto::Ss58Codec; +use cli_utils::{RuntimeAdapter, AddressFor, IndexFor, BalanceFor, BalancesCall}; /// The `transfer` command #[derive(Debug, StructOpt, Clone)] @@ -115,7 +118,7 @@ fn print_ext( Pair::Public: Into, Pair::Signature: Encode, RA: RuntimeAdapter, - BalancesCall: Encode, + BalancesCall: Encode, { let signer = pair_from_suri::(uri, pass); let call = BalancesCall::transfer(to, amount); diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 677d76c558d76..f8ec3a0e36a91 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -16,41 +16,26 @@ //! subcommand utilities use std::{io::Read, path::PathBuf}; -use sp_core::{Pair, crypto::{Ss58Codec, Ss58AddressFormat}, hexdisplay::HexDisplay}; -use sp_runtime::{generic::{UncheckedExtrinsic, SignedPayload}, traits::IdentifyAccount, MultiSigner}; +use sp_core::{ + Pair, hexdisplay::HexDisplay, + crypto::{Ss58Codec, Ss58AddressFormat, AccountId32}, +}; +use sp_runtime::{ + traits::IdentifyAccount, MultiSigner, + generic::{UncheckedExtrinsic, SignedPayload}, +}; +use crate::{ + SharedParams, arg_enums::{OutputType}, + error::{self, Error}, +}; use parity_scale_codec::Encode; use serde_json::json; -use sp_runtime::traits::{ - SignedExtension, StaticLookup, -}; -use crate::{error::{self, Error}, SharedParams, arg_enums::{OutputType}}; -use sp_core::crypto::AccountId32; +use cli_utils::{RuntimeAdapter, IndexFor}; /// Public key type for Runtime pub type PublicFor

=

::Public; /// Seed type for Runtime pub type SeedFor

=

::Seed; -/// AccountIndex type for Runtime -pub type IndexFor = <::Runtime as frame_system::Trait>::Index; -/// Balance type -pub type BalanceFor = <::Runtime as pallet_balances::Trait>::Balance; -/// Call type for Runtime -pub type CallFor = <::Runtime as frame_system::Trait>::Call; -/// Address type for runtime. -pub type AddressFor = <<::Runtime as frame_system::Trait>::Lookup as StaticLookup>::Source; -/// Hash for runtime. -pub type HashFor = <::Runtime as frame_system::Trait>::Hash; - -/// Runtime adapter for signing utilities -pub trait RuntimeAdapter: Sized { - /// runtime - type Runtime: frame_system::Trait + pallet_balances::Trait; - /// extras - type Extra: SignedExtension; - - /// build extras for inclusion in extrinsics - fn build_extra(index: IndexFor) -> Self::Extra; -} /// helper method to fetch password from `SharedParams` or read from stdin pub fn get_password(params: &SharedParams) -> error::Result { diff --git a/client/cli/src/params/network_configuration_params.rs b/client/cli/src/params/network_configuration_params.rs index 974fa0be937a7..4971e0ebc4363 100644 --- a/client/cli/src/params/network_configuration_params.rs +++ b/client/cli/src/params/network_configuration_params.rs @@ -100,7 +100,7 @@ pub struct NetworkConfigurationParams { } impl NetworkConfigurationParams { - /// Fill the given `NetworkConfiguration` by looking at the cli parameters. + /// Fill the given `NetworkConfiguration` by looking at the cli-utils parameters. pub fn update_config( &self, mut config: &mut Configuration, diff --git a/client/cli/src/params/transaction_pool_params.rs b/client/cli/src/params/transaction_pool_params.rs index 3468c12243b3f..365752de898ff 100644 --- a/client/cli/src/params/transaction_pool_params.rs +++ b/client/cli/src/params/transaction_pool_params.rs @@ -30,7 +30,7 @@ pub struct TransactionPoolParams { } impl TransactionPoolParams { - /// Fill the given `PoolConfiguration` by looking at the cli parameters. + /// Fill the given `PoolConfiguration` by looking at the cli-utils parameters. pub fn update_config( &self, config: &mut Configuration, diff --git a/utils/cli-utils/Cargo.toml b/utils/cli-utils/Cargo.toml new file mode 100644 index 0000000000000..075306e1ccd7f --- /dev/null +++ b/utils/cli-utils/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "cli-utils" +version = "2.0.0-alpha.3" +authors = ["Parity Technologies "] +edition = "2018" +license = "GPL-3.0" +homepage = "https://substrate.dev" +repository = "https://github.com/paritytech/substrate/" +description = "CLI utils" +documentation = "https://docs.rs/cli-utils" + +[dependencies] +frame-system = { version = "2.0.0-alpha.3", default-features = false, path = "../../frame/system" } +pallet-balances = { version = "2.0.0-alpha.3", default-features = false, path = "../../frame/balances" } +sp-runtime = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/runtime" } + +[features] +default = ["std"] +std = [ + "frame-system/std", + "pallet-balances/std", + "sp-runtime/std", +] \ No newline at end of file diff --git a/utils/cli-utils/src/lib.rs b/utils/cli-utils/src/lib.rs new file mode 100644 index 0000000000000..611f572404228 --- /dev/null +++ b/utils/cli-utils/src/lib.rs @@ -0,0 +1,39 @@ +// Copyright 2019-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Utilities for cli. +use sp_runtime::traits::{StaticLookup, SignedExtension}; +pub use pallet_balances::Call as BalancesCall; + +/// AccountIndex type for Runtime +pub type IndexFor = ::Index; +/// Balance type +pub type BalanceFor = ::Balance; +/// Call type for Runtime +pub type CallFor = ::Call; +/// Address type for runtime. +pub type AddressFor = <::Lookup as StaticLookup>::Source; +/// Hash for runtime. +pub type HashFor = ::Hash; + +/// Runtime adapter for signing utilities +pub trait RuntimeAdapter: frame_system::Trait + pallet_balances::Trait { + /// extras + type Extra: SignedExtension; + + /// build extras for inclusion in extrinsics + fn build_extra(index: IndexFor) -> Self::Extra; +} From 70d1dbe994f21ad4fa60bf96997e86868734a9e3 Mon Sep 17 00:00:00 2001 From: Seun Date: Fri, 20 Mar 2020 15:06:02 +0100 Subject: [PATCH 14/77] move RuntimeAdapter to cli-utils --- Cargo.lock | 671 +++++++++++++++++++++++++--- bin/node/cli/build.rs | 4 +- bin/node/cli/src/command.rs | 8 +- client/cli/Cargo.toml | 14 + client/cli/src/commands/mod.rs | 5 +- client/cli/src/commands/transfer.rs | 11 +- utils/cli-utils/Cargo.toml | 8 +- utils/cli-utils/src/lib.rs | 4 + 8 files changed, 634 insertions(+), 91 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 046712c0af148..443fc91c40671 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -189,7 +189,7 @@ dependencies = [ "mio", "mio-uds", "num_cpus", - "once_cell", + "once_cell 1.3.1", "pin-project-lite", "pin-utils", "slab", @@ -616,6 +616,15 @@ dependencies = [ "cc", ] +[[package]] +name = "cli-utils" +version = "2.0.0-alpha.3" +dependencies = [ + "frame-system", + "pallet-balances", + "sp-runtime", +] + [[package]] name = "cloudabi" version = "0.0.3" @@ -902,7 +911,7 @@ dependencies = [ "lazy_static", "maybe-uninit", "memoffset", - "scopeguard", + "scopeguard 1.1.0", ] [[package]] @@ -1003,6 +1012,19 @@ dependencies = [ "rand 0.3.23", ] +[[package]] +name = "curve25519-dalek" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b7dcd30ba50cdf88b55b033456138b7c0ac4afdc436d82e1b79f370f24cc66d" +dependencies = [ + "byteorder 1.3.4", + "clear_on_drop", + "digest", + "rand_core 0.3.1", + "subtle 2.2.2", +] + [[package]] name = "curve25519-dalek" version = "2.0.0" @@ -1093,7 +1115,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "978710b352437433c97b2bff193f2fb1dfd58a093f863dd95e225a19baa599a2" dependencies = [ "clear_on_drop", - "curve25519-dalek", + "curve25519-dalek 2.0.0", "rand 0.7.3", "sha2", ] @@ -1494,7 +1516,7 @@ dependencies = [ "frame-system", "impl-trait-for-tuples", "log 0.4.8", - "once_cell", + "once_cell 1.3.1", "parity-scale-codec", "paste", "pretty_assertions", @@ -1976,6 +1998,16 @@ dependencies = [ "crunchy", ] +[[package]] +name = "hashbrown" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" +dependencies = [ + "byteorder 1.3.4", + "scopeguard 0.3.3", +] + [[package]] name = "hashbrown" version = "0.6.3" @@ -2595,6 +2627,43 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "libp2p" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f84847789ab24b3fc5971a68656ac85886df640986d9ce3264c0327694eae471" +dependencies = [ + "bytes 0.5.4", + "futures 0.3.4", + "lazy_static", + "libp2p-core 0.15.0", + "libp2p-core-derive 0.15.0", + "libp2p-deflate 0.7.0", + "libp2p-dns 0.15.0", + "libp2p-floodsub 0.15.0", + "libp2p-gossipsub 0.15.0", + "libp2p-identify 0.15.0", + "libp2p-kad 0.15.0", + "libp2p-mdns 0.15.0", + "libp2p-mplex 0.15.0", + "libp2p-noise 0.13.0", + "libp2p-ping 0.15.0", + "libp2p-plaintext 0.15.0", + "libp2p-secio 0.15.0", + "libp2p-swarm 0.5.0", + "libp2p-tcp 0.15.0", + "libp2p-uds 0.15.0", + "libp2p-wasm-ext 0.8.0", + "libp2p-websocket 0.15.0", + "libp2p-yamux 0.15.0", + "parity-multiaddr", + "parity-multihash", + "parking_lot 0.10.0", + "pin-project", + "smallvec 1.2.0", + "wasm-timer", +] + [[package]] name = "libp2p" version = "0.16.2" @@ -2604,27 +2673,27 @@ dependencies = [ "bytes 0.5.4", "futures 0.3.4", "lazy_static", - "libp2p-core", - "libp2p-core-derive", - "libp2p-deflate", - "libp2p-dns", - "libp2p-floodsub", - "libp2p-gossipsub", - "libp2p-identify", - "libp2p-kad", - "libp2p-mdns", - "libp2p-mplex", - "libp2p-noise", - "libp2p-ping", - "libp2p-plaintext", + "libp2p-core 0.16.0", + "libp2p-core-derive 0.16.0", + "libp2p-deflate 0.16.0", + "libp2p-dns 0.16.0", + "libp2p-floodsub 0.16.0", + "libp2p-gossipsub 0.16.0", + "libp2p-identify 0.16.0", + "libp2p-kad 0.16.2", + "libp2p-mdns 0.16.0", + "libp2p-mplex 0.16.0", + "libp2p-noise 0.16.2", + "libp2p-ping 0.16.0", + "libp2p-plaintext 0.16.0", "libp2p-pnet", - "libp2p-secio", - "libp2p-swarm", - "libp2p-tcp", - "libp2p-uds", - "libp2p-wasm-ext", - "libp2p-websocket", - "libp2p-yamux", + "libp2p-secio 0.16.1", + "libp2p-swarm 0.16.1", + "libp2p-tcp 0.16.0", + "libp2p-uds 0.16.0", + "libp2p-wasm-ext 0.16.2", + "libp2p-websocket 0.16.0", + "libp2p-yamux 0.16.2", "parity-multiaddr", "parity-multihash", "parking_lot 0.10.0", @@ -2633,6 +2702,40 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-core" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbafb2706b8082233f66dc13e196f9cf9b4c229f2cd7c96b2b16617ad6ee330b" +dependencies = [ + "asn1_der", + "bs58", + "ed25519-dalek", + "fnv", + "futures 0.3.4", + "futures-timer 2.0.2", + "lazy_static", + "libsecp256k1", + "log 0.4.8", + "multistream-select", + "parity-multiaddr", + "parity-multihash", + "parking_lot 0.10.0", + "pin-project", + "prost", + "prost-build", + "rand 0.7.3", + "ring", + "rw-stream-sink", + "sha2", + "smallvec 1.2.0", + "thiserror", + "unsigned-varint", + "untrusted", + "void", + "zeroize", +] + [[package]] name = "libp2p-core" version = "0.16.0" @@ -2666,6 +2769,16 @@ dependencies = [ "zeroize", ] +[[package]] +name = "libp2p-core-derive" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c320266be0a7760e23484d635acdb83844b2d74d3612d93b41c393c9bcf004e" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "libp2p-core-derive" version = "0.16.0" @@ -2676,6 +2789,17 @@ dependencies = [ "syn", ] +[[package]] +name = "libp2p-deflate" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be32697b42d040b325c3737f827ea04ede569ec956b7807700dd8d89d8210f9" +dependencies = [ + "flate2", + "futures 0.3.4", + "libp2p-core 0.15.0", +] + [[package]] name = "libp2p-deflate" version = "0.16.0" @@ -2684,7 +2808,18 @@ checksum = "2e25004d4d9837b44b22c5f1a69be1724a5168fef6cff1716b5176a972c3aa62" dependencies = [ "flate2", "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", +] + +[[package]] +name = "libp2p-dns" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f11c979b882f25d85726b15637d5bbc722dfa1be576605c54e99b8cf56906be3" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "log 0.4.8", ] [[package]] @@ -2694,10 +2829,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b99e552f9939b606eb4b59f7f64d9b01e3f96752f47e350fc3c5fc646ed3f649" dependencies = [ "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", ] +[[package]] +name = "libp2p-floodsub" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bdf6fba9272ad47dde94bade89540fdb16e24ae9ff7fb714c1c80a035165f28" +dependencies = [ + "bs58", + "cuckoofilter", + "fnv", + "futures 0.3.4", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "prost", + "prost-build", + "rand 0.7.3", + "smallvec 1.2.0", +] + [[package]] name = "libp2p-floodsub" version = "0.16.0" @@ -2707,12 +2860,38 @@ dependencies = [ "cuckoofilter", "fnv", "futures 0.3.4", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", + "prost", + "prost-build", + "rand 0.7.3", + "smallvec 1.2.0", +] + +[[package]] +name = "libp2p-gossipsub" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e6ecd058bf769d27ebec530544b081e08b0a1088e3186da8cc58d59915784d0" +dependencies = [ + "base64 0.11.0", + "bs58", + "byteorder 1.3.4", + "bytes 0.5.4", + "fnv", + "futures 0.3.4", + "futures_codec", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "lru", "prost", "prost-build", "rand 0.7.3", + "sha2", "smallvec 1.2.0", + "unsigned-varint", + "wasm-timer", ] [[package]] @@ -2727,8 +2906,8 @@ dependencies = [ "fnv", "futures 0.3.4", "futures_codec", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "lru", "prost", @@ -2740,6 +2919,22 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-identify" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1a6261b804111c2dbf53f8ca03f66edc5ad1c29b78a61cf0cc5354052e28e9" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "prost", + "prost-build", + "smallvec 1.2.0", + "wasm-timer", +] + [[package]] name = "libp2p-identify" version = "0.16.0" @@ -2747,12 +2942,39 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfeb935a9bd41263e4f3a24b988e9f4a044f3ae89ac284e83c17fe2f84e0d66b" dependencies = [ "futures 0.3.4", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", + "log 0.4.8", + "prost", + "prost-build", + "smallvec 1.2.0", + "wasm-timer", +] + +[[package]] +name = "libp2p-kad" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c6ea6fece0d99599afb1b2082ca8937944cdd6b0946a88d54cb3ae7a38d1253" +dependencies = [ + "arrayvec 0.5.1", + "bytes 0.5.4", + "either", + "fnv", + "futures 0.3.4", + "futures_codec", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", "log 0.4.8", + "parity-multihash", "prost", "prost-build", + "rand 0.7.3", + "sha2", "smallvec 1.2.0", + "uint", + "unsigned-varint", + "void", "wasm-timer", ] @@ -2768,8 +2990,8 @@ dependencies = [ "fnv", "futures 0.3.4", "futures_codec", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "parity-multihash", "prost", @@ -2783,6 +3005,28 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-mdns" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "074312353355df310affa105ec71b16fd7e52f5c6ae61d3dcbb3e79e8fdc9e5f" +dependencies = [ + "async-std", + "data-encoding", + "dns-parser", + "either", + "futures 0.3.4", + "lazy_static", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "net2", + "rand 0.7.3", + "smallvec 1.2.0", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-mdns" version = "0.16.0" @@ -2795,8 +3039,8 @@ dependencies = [ "either", "futures 0.3.4", "lazy_static", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "net2", "rand 0.7.3", @@ -2805,6 +3049,22 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-mplex" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89d0b44dfdef80cc2be4b42d127de1c793905eca2459415a5c57d6b4fbd8ec30" +dependencies = [ + "bytes 0.5.4", + "fnv", + "futures 0.3.4", + "futures_codec", + "libp2p-core 0.15.0", + "log 0.4.8", + "parking_lot 0.10.0", + "unsigned-varint", +] + [[package]] name = "libp2p-mplex" version = "0.16.0" @@ -2815,22 +3075,42 @@ dependencies = [ "fnv", "futures 0.3.4", "futures_codec", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "parking_lot 0.10.0", "unsigned-varint", ] +[[package]] +name = "libp2p-noise" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0845e8208d814cd41c26c90a6a2f2b720c31b588209cecc49a44c881a09f417f" +dependencies = [ + "curve25519-dalek 1.2.3", + "futures 0.3.4", + "lazy_static", + "libp2p-core 0.15.0", + "log 0.4.8", + "prost", + "prost-build", + "rand 0.7.3", + "ring", + "snow", + "x25519-dalek 0.5.2", + "zeroize", +] + [[package]] name = "libp2p-noise" version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15a8a3d71f898beb6f854c8aae27aa1d198e0d1f2e49412261c2d90ef39675a" dependencies = [ - "curve25519-dalek", + "curve25519-dalek 2.0.0", "futures 0.3.4", "lazy_static", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "prost", "prost-build", @@ -2838,10 +3118,25 @@ dependencies = [ "sha2", "snow", "static_assertions", - "x25519-dalek", + "x25519-dalek 0.6.0", "zeroize", ] +[[package]] +name = "libp2p-ping" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ecced2949ae93b6ff29565303ecd1bef15c4e4efb689033ee744922561a36b" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "libp2p-swarm 0.5.0", + "log 0.4.8", + "rand 0.7.3", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-ping" version = "0.16.0" @@ -2849,14 +3144,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d22f2f228b3a828dca1cb8aa9fa331e0bc9c36510cb2c1916956e20dc85e8c" dependencies = [ "futures 0.3.4", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.16.0", + "libp2p-swarm 0.16.1", "log 0.4.8", "rand 0.7.3", "void", "wasm-timer", ] +[[package]] +name = "libp2p-plaintext" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "195fda6b6a948a242fd30570e0e3418ae8e0a20055ea75d45458e1079a8efb05" +dependencies = [ + "bytes 0.5.4", + "futures 0.3.4", + "futures_codec", + "libp2p-core 0.15.0", + "log 0.4.8", + "prost", + "prost-build", + "rw-stream-sink", + "unsigned-varint", + "void", +] + [[package]] name = "libp2p-plaintext" version = "0.16.0" @@ -2866,7 +3179,7 @@ dependencies = [ "bytes 0.5.4", "futures 0.3.4", "futures_codec", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "prost", "prost-build", @@ -2889,6 +3202,36 @@ dependencies = [ "sha3", ] +[[package]] +name = "libp2p-secio" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ceef68ca377b264f84d64c88739a8fa118b5db1e8f18297351dff75314504a5f" +dependencies = [ + "aes-ctr", + "ctr", + "futures 0.3.4", + "hmac", + "js-sys", + "lazy_static", + "libp2p-core 0.15.0", + "log 0.4.8", + "parity-send-wrapper", + "pin-project", + "prost", + "prost-build", + "quicksink", + "rand 0.7.3", + "ring", + "rw-stream-sink", + "sha2", + "static_assertions", + "twofish", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "libp2p-secio" version = "0.16.1" @@ -2901,7 +3244,7 @@ dependencies = [ "hmac", "js-sys", "lazy_static", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "parity-send-wrapper", "pin-project", @@ -2919,6 +3262,20 @@ dependencies = [ "web-sys", ] +[[package]] +name = "libp2p-swarm" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14ea00be81bc3985e36abad263ce2ad1b6aeb862aa743563eb70ad42880c05ae" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "log 0.4.8", + "smallvec 1.2.0", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-swarm" version = "0.16.1" @@ -2926,13 +3283,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "275471e7c0e88ae004660866cd54f603bd8bd1f4caef541a27f50dd8640c4d4c" dependencies = [ "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "smallvec 1.2.0", "void", "wasm-timer", ] +[[package]] +name = "libp2p-tcp" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e65ef381570df31cb047dfbc11483ab0fe7e6abbdcf2bdc2c60b5d11133d241" +dependencies = [ + "async-std", + "futures 0.3.4", + "futures-timer 2.0.2", + "get_if_addrs", + "ipnet", + "libp2p-core 0.15.0", + "log 0.4.8", +] + [[package]] name = "libp2p-tcp" version = "0.16.0" @@ -2944,7 +3316,19 @@ dependencies = [ "futures-timer 3.0.2", "get_if_addrs", "ipnet", - "libp2p-core", + "libp2p-core 0.16.0", + "log 0.4.8", +] + +[[package]] +name = "libp2p-uds" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e4f4f7989b35f33d4b9738aab2f031310eb20fec513cab44d12b1bc985a8074" +dependencies = [ + "async-std", + "futures 0.3.4", + "libp2p-core 0.15.0", "log 0.4.8", ] @@ -2956,10 +3340,24 @@ checksum = "76d329564a43da9d0e055a5b938633c4a8ceab1f59cec133fbc4647917c07341" dependencies = [ "async-std", "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", ] +[[package]] +name = "libp2p-wasm-ext" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b4d457adb91a5e2212343218a554394cd8ced64a79fb8e36e7aed2a16d49495" +dependencies = [ + "futures 0.3.4", + "js-sys", + "libp2p-core 0.15.0", + "parity-send-wrapper", + "wasm-bindgen", + "wasm-bindgen-futures", +] + [[package]] name = "libp2p-wasm-ext" version = "0.16.2" @@ -2968,12 +3366,33 @@ checksum = "923581c055bc4b8c5f42d4ce5ef43e52fe5216f1ea4bc26476cb8a966ce6220b" dependencies = [ "futures 0.3.4", "js-sys", - "libp2p-core", + "libp2p-core 0.16.0", "parity-send-wrapper", "wasm-bindgen", "wasm-bindgen-futures", ] +[[package]] +name = "libp2p-websocket" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bba425f2af1fdb7dece88b9ae05ca9430dfb0b72b2c078e73ded6f1556084509" +dependencies = [ + "async-tls", + "bytes 0.5.4", + "either", + "futures 0.3.4", + "libp2p-core 0.15.0", + "log 0.4.8", + "quicksink", + "rustls 0.16.0", + "rw-stream-sink", + "soketto", + "url 2.1.1", + "webpki", + "webpki-roots 0.18.0", +] + [[package]] name = "libp2p-websocket" version = "0.16.0" @@ -2984,7 +3403,7 @@ dependencies = [ "bytes 0.5.4", "either", "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "log 0.4.8", "quicksink", "rustls 0.16.0", @@ -2995,6 +3414,20 @@ dependencies = [ "webpki-roots 0.18.0", ] +[[package]] +name = "libp2p-yamux" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca25b3aac78a3c93c2a567622abd3cfc16f96f26ae1bf6134f0056203d62d86" +dependencies = [ + "futures 0.3.4", + "libp2p-core 0.15.0", + "log 0.4.8", + "parking_lot 0.10.0", + "thiserror", + "yamux", +] + [[package]] name = "libp2p-yamux" version = "0.16.2" @@ -3002,7 +3435,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dac30de24ccde0e67f363d71a125c587bbe6589503f664947e9b084b68a34f1" dependencies = [ "futures 0.3.4", - "libp2p-core", + "libp2p-core 0.16.0", "parking_lot 0.10.0", "thiserror", "yamux", @@ -3063,13 +3496,22 @@ dependencies = [ "linked-hash-map", ] +[[package]] +name = "lock_api" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" +dependencies = [ + "scopeguard 0.3.3", +] + [[package]] name = "lock_api" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79b2de95ecb4691949fea4716ca53cdbcfccb2c612e19644a8bad05edcf9f47b" dependencies = [ - "scopeguard", + "scopeguard 1.1.0", ] [[package]] @@ -3096,7 +3538,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0609345ddee5badacf857d4f547e0e5a2e987db77085c24cd887f73573a04237" dependencies = [ - "hashbrown", + "hashbrown 0.6.3", ] [[package]] @@ -3143,7 +3585,7 @@ checksum = "198831fe8722331a395bc199a5d08efbc197497ef354cb4c77b969c02ffc0fc4" dependencies = [ "ahash", "hash-db", - "hashbrown", + "hashbrown 0.6.3", "parity-util-mem 0.5.2", ] @@ -3485,6 +3927,7 @@ dependencies = [ name = "node-runtime" version = "2.0.0-alpha.4" dependencies = [ + "cli-utils", "frame-benchmarking", "frame-executive", "frame-support", @@ -3577,6 +4020,7 @@ dependencies = [ name = "node-template-runtime" version = "2.0.0-alpha.4" dependencies = [ + "cli-utils", "frame-executive", "frame-support", "frame-system", @@ -3777,6 +4221,15 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "once_cell" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "532c29a261168a45ce28948f9537ddd7a5dd272cc513b3017b1e82a88f962c37" +dependencies = [ + "parking_lot 0.7.1", +] + [[package]] name = "once_cell" version = "1.3.1" @@ -4655,7 +5108,7 @@ checksum = "6e42755f26e5ea21a6a819d9e63cbd70713e9867a2b767ec2cc65ca7659532c5" dependencies = [ "cfg-if", "ethereum-types", - "hashbrown", + "hashbrown 0.6.3", "impl-trait-for-tuples", "lru", "parity-util-mem-derive", @@ -4691,13 +5144,23 @@ version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" +[[package]] +name = "parking_lot" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" +dependencies = [ + "lock_api 0.1.5", + "parking_lot_core 0.4.0", +] + [[package]] name = "parking_lot" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" dependencies = [ - "lock_api", + "lock_api 0.3.3", "parking_lot_core 0.6.2", "rustc_version", ] @@ -4708,10 +5171,23 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92e98c49ab0b7ce5b222f2cc9193fc4efe11c6d0bd4f648e374684a6857b1cfc" dependencies = [ - "lock_api", + "lock_api 0.3.3", "parking_lot_core 0.7.0", ] +[[package]] +name = "parking_lot_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" +dependencies = [ + "libc", + "rand 0.6.5", + "rustc_version", + "smallvec 0.6.13", + "winapi 0.3.8", +] + [[package]] name = "parking_lot_core" version = "0.6.2" @@ -5593,7 +6069,7 @@ dependencies = [ "env_logger 0.7.1", "futures 0.3.4", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "parity-scale-codec", "prost", @@ -5688,33 +6164,49 @@ dependencies = [ "atty", "chrono", "clap", + "cli-utils", "derive_more", "env_logger 0.7.1", "fdlimit", + "futures 0.1.29", "futures 0.3.4", + "hex", + "hex-literal", + "hyper 0.12.35", + "jsonrpc-core-client", "lazy_static", + "libp2p 0.15.0", "log 0.4.8", "names", + "parity-scale-codec", "parity-util-mem 0.6.0", + "rand 0.7.3", "regex", "rpassword", "sc-client-api", "sc-informant", "sc-network", + "sc-rpc", "sc-service", "sc-telemetry", "sc-tracing", + "serde", "serde_json", + "sp-application-crypto", "sp-blockchain", "sp-core", + "sp-io", "sp-keyring", "sp-panic-handler", "sp-runtime", "sp-state-machine", + "sp-version", "structopt", "substrate-prometheus-endpoint", + "substrate-test-runtime", "tempfile", "time", + "tiny-bip39 0.6.2", "tokio 0.2.13", ] @@ -6198,7 +6690,7 @@ dependencies = [ "futures 0.3.4", "futures-timer 3.0.2", "futures_codec", - "libp2p", + "libp2p 0.16.2", "linked-hash-map", "linked_hash_set", "log 0.4.8", @@ -6246,7 +6738,7 @@ version = "0.8.0-alpha.4" dependencies = [ "futures 0.3.4", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "lru", "sc-network", @@ -6262,7 +6754,7 @@ dependencies = [ "env_logger 0.7.1", "futures 0.3.4", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "parking_lot 0.10.0", "rand 0.7.3", @@ -6317,7 +6809,7 @@ name = "sc-peerset" version = "2.0.0-alpha.4" dependencies = [ "futures 0.3.4", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "rand 0.7.3", "serde_json", @@ -6504,7 +6996,7 @@ dependencies = [ "bytes 0.5.4", "futures 0.3.4", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "parking_lot 0.10.0", "pin-project", @@ -6598,7 +7090,7 @@ checksum = "021b403afe70d81eea68f6ea12f6b3c9588e5d536a94c3bf80f15e7faa267862" dependencies = [ "arrayref", "arrayvec 0.5.1", - "curve25519-dalek", + "curve25519-dalek 2.0.0", "getrandom", "merlin", "rand 0.7.3", @@ -6614,6 +7106,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" +[[package]] +name = "scopeguard" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" + [[package]] name = "scopeguard" version = "1.1.0" @@ -6895,7 +7393,7 @@ dependencies = [ "rustc_version", "sha2", "subtle 2.2.2", - "x25519-dalek", + "x25519-dalek 0.6.0", ] [[package]] @@ -7066,7 +7564,7 @@ dependencies = [ "futures 0.3.4", "futures-diagnose", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.16.2", "log 0.4.8", "parity-scale-codec", "parking_lot 0.10.0", @@ -7157,7 +7655,7 @@ dependencies = [ "sp-std", "sp-storage", "substrate-bip39", - "tiny-bip39", + "tiny-bip39 0.7.1", "tiny-keccak 2.0.1", "twox-hash", "wasmi", @@ -7613,7 +8111,7 @@ dependencies = [ "hyper 0.12.35", "itertools", "jsonrpc-core-client", - "libp2p", + "libp2p 0.16.2", "node-primitives", "node-runtime", "pallet-balances", @@ -7627,7 +8125,7 @@ dependencies = [ "sp-core", "sp-runtime", "substrate-bip39", - "tiny-bip39", + "tiny-bip39 0.7.1", ] [[package]] @@ -7655,7 +8153,7 @@ dependencies = [ "futures-timer 3.0.2", "js-sys", "kvdb-web", - "libp2p-wasm-ext", + "libp2p-wasm-ext 0.16.2", "log 0.4.8", "rand 0.6.5", "rand 0.7.3", @@ -7754,6 +8252,7 @@ dependencies = [ "log 0.4.8", "memory-db", "pallet-babe", + "pallet-balances", "pallet-timestamp", "parity-scale-codec", "parity-util-mem 0.6.0", @@ -7964,7 +8463,7 @@ dependencies = [ "doc-comment", "libc", "ntapi", - "once_cell", + "once_cell 1.3.1", "rayon", "winapi 0.3.8", ] @@ -8081,6 +8580,21 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "tiny-bip39" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1c5676413eaeb1ea35300a0224416f57abc3bd251657e0fafc12c47ff98c060" +dependencies = [ + "failure", + "hashbrown 0.1.8", + "hmac", + "once_cell 0.1.8", + "pbkdf2", + "rand 0.6.5", + "sha2", +] + [[package]] name = "tiny-bip39" version = "0.7.1" @@ -8089,7 +8603,7 @@ checksum = "a6848cd8f566953ce1e8faeba12ee23cbdbb0437754792cd857d44628b5685e3" dependencies = [ "failure", "hmac", - "once_cell", + "once_cell 1.3.1", "pbkdf2", "rand 0.7.3", "rustc-hash", @@ -8490,7 +9004,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de9222c50cc325855621271157c973da27a0dcd26fa06f8edf81020bd2333df0" dependencies = [ "hash-db", - "hashbrown", + "hashbrown 0.6.3", "log 0.4.8", "rustc-hex", "smallvec 1.2.0", @@ -9141,13 +9655,24 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "x25519-dalek" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ee1585dc1484373cbc1cee7aafda26634665cf449436fd6e24bfd1fad230538" +dependencies = [ + "clear_on_drop", + "curve25519-dalek 1.2.3", + "rand_core 0.3.1", +] + [[package]] name = "x25519-dalek" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "637ff90c9540fa3073bb577e65033069e4bae7c79d49d74aa3ffdf5342a53217" dependencies = [ - "curve25519-dalek", + "curve25519-dalek 2.0.0", "rand_core 0.5.1", "zeroize", ] diff --git a/bin/node/cli/build.rs b/bin/node/cli/build.rs index 3f3c0b3427f2a..e824b59be64f3 100644 --- a/bin/node/cli/build.rs +++ b/bin/node/cli/build.rs @@ -15,8 +15,8 @@ // along with Substrate. If not, see . fn main() { - // #[cfg(feature = "cli")] - // cli::main(); + #[cfg(feature = "cli")] + cli::main(); } #[cfg(feature = "cli")] diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index dd05c05f41c55..0a4291c9428e6 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -16,14 +16,12 @@ use sc_cli::VersionInfo; use sc_service::{Roles as ServiceRoles}; -use node_transaction_factory::RuntimeAdapter; +use node_transaction_factory::RuntimeAdapter as _; use crate::{ Cli, service, ChainSpec, load_spec, Subcommand, factory_impl::FactoryState, }; -use sp_runtime::generic::Era; -use node_primitives::Index; -use node_runtime::{Runtime, SignedExtra}; +use node_runtime::Runtime; /// Parse command line arguments into service configuration. pub fn run(args: I, version: VersionInfo) -> sc_cli::Result<()> @@ -112,7 +110,7 @@ where Some(Subcommand::Base(subcommand)) => { subcommand.init(&version)?; subcommand.update_config(&mut config, load_spec, &version)?; - subcommand.run::( + subcommand.run::( config, |config: sc_service::Configuration| Ok(new_full_start!(config).0), ) diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 91d8a54242f6d..6a759a8915e9d 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -23,12 +23,25 @@ tokio = { version = "0.2.9", features = [ "signal", "rt-core", "rt-threaded" ] } futures = "0.3.1" fdlimit = "0.1.4" serde_json = "1.0.41" +parity-scale-codec = "1.2.0" +hex = "0.4.2" +hyper = "0.12.35" +rand = "0.7.2" +serde = "1.0.104" +futures01 = { package = "futures", version = "0.1.29" } +sc-rpc = { version = "2.0.0-alpha.3", path = "../../client/rpc" } +jsonrpc-core-client = { version = "14.0.3", features = ["http"] } +tiny-bip39 = "0.6.2" +libp2p = "0.15.0" +hex-literal = "0.2.1" sc-informant = { version = "0.8.0-alpha.4", path = "../informant" } sp-panic-handler = { version = "2.0.0-alpha.4", path = "../../primitives/panic-handler" } sc-client-api = { version = "2.0.0-alpha.4", path = "../api" } sp-blockchain = { version = "2.0.0-alpha.4", path = "../../primitives/blockchain" } sc-network = { version = "0.8.0-alpha.4", path = "../network" } sp-runtime = { version = "2.0.0-alpha.4", path = "../../primitives/runtime" } +sp-version = { version = "2.0.0-alpha.3", path = "../../primitives/version" } +sp-io = { version = "2.0.0-alpha.3", path = "../../primitives/io" } sp-core = { version = "2.0.0-alpha.4", path = "../../primitives/core" } sc-service = { version = "0.8.0-alpha.4", default-features = false, path = "../service" } sp-state-machine = { version = "0.8.0-alpha.4", path = "../../primitives/state-machine" } @@ -40,6 +53,7 @@ structopt = "0.3.8" sc-tracing = { version = "2.0.0-alpha.4", path = "../tracing" } chrono = "0.4.10" parity-util-mem = { version = "0.6.0", default-features = false, features = ["primitive-types"] } +cli-utils = { path = "../../utils/cli-utils" , version = "2.0.0-alpha.3" } [target.'cfg(not(target_os = "unknown"))'.dependencies] rpassword = "4.0.1" diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index eefeb083e3daa..c45069c9046e7 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -63,7 +63,7 @@ pub use crate::commands::vanity::VanityCmd; pub use crate::commands::verify::VerifyCmd; use std::convert::TryFrom; use sp_core::crypto::Ss58Codec; -use cli_utils::{RuntimeAdapter, AddressFor, IndexFor, BalanceFor, CallFor}; +use cli_utils::{RuntimeAdapter, AccountIdFor, IndexFor, BalanceFor, CallFor, AddressFor}; /// default sub directory to store network config @@ -159,7 +159,8 @@ impl Subcommand { <::Number as std::str::FromStr>::Err: std::fmt::Debug, Block::Hash: std::str::FromStr, RA: RuntimeAdapter, - AddressFor: for<'a> TryFrom<&'a [u8], Error = ()> + Ss58Codec, + AccountIdFor: for<'a> TryFrom<&'a [u8], Error = ()> + Ss58Codec, + AddressFor: From>, as FromStr>::Err: Display, as FromStr>::Err: Display, CallFor: Codec, diff --git a/client/cli/src/commands/transfer.rs b/client/cli/src/commands/transfer.rs index 4d87ed34fa57e..ec826bb937a71 100644 --- a/client/cli/src/commands/transfer.rs +++ b/client/cli/src/commands/transfer.rs @@ -28,7 +28,7 @@ use sc_service::{Configuration, ChainSpec}; use sp_runtime::MultiSigner; use std::convert::TryFrom; use sp_core::crypto::Ss58Codec; -use cli_utils::{RuntimeAdapter, AddressFor, IndexFor, BalanceFor, BalancesCall}; +use cli_utils::{RuntimeAdapter, AddressFor, IndexFor, BalanceFor, BalancesCall, AccountIdFor}; /// The `transfer` command #[derive(Debug, StructOpt, Clone)] @@ -64,17 +64,18 @@ impl TransferCmd { pub fn run(self) -> error::Result<()> where RA: RuntimeAdapter, - AddressFor: for<'a> TryFrom<&'a [u8], Error = ()> + Ss58Codec, + AccountIdFor: for<'a> TryFrom<&'a [u8], Error = ()> + Ss58Codec, + AddressFor: From>, as FromStr>::Err: Display, as FromStr>::Err: Display, { let password = get_password(&self.shared_params)?; let nonce = IndexFor::::from_str(&self.index).map_err(|e| format!("{}", e))?; let to = if let Ok(data_vec) = decode_hex(&self.to) { - AddressFor::::try_from(&data_vec) + AccountIdFor::::try_from(&data_vec) .expect("Invalid hex length for account ID; should be 32 bytes") } else { - AddressFor::::from_ss58check(&self.to).ok() + AccountIdFor::::from_ss58check(&self.to).ok() .expect("Invalid SS58-check address given for account ID.") }; let amount = BalanceFor::::from_str(&self.amount).map_err(|e| format!("{}", e))?; @@ -84,7 +85,7 @@ impl TransferCmd { print_ext( &self.from, &password, - to, + to.into(), nonce, amount ) diff --git a/utils/cli-utils/Cargo.toml b/utils/cli-utils/Cargo.toml index 075306e1ccd7f..99f66de4a23dd 100644 --- a/utils/cli-utils/Cargo.toml +++ b/utils/cli-utils/Cargo.toml @@ -10,9 +10,9 @@ description = "CLI utils" documentation = "https://docs.rs/cli-utils" [dependencies] -frame-system = { version = "2.0.0-alpha.3", default-features = false, path = "../../frame/system" } -pallet-balances = { version = "2.0.0-alpha.3", default-features = false, path = "../../frame/balances" } -sp-runtime = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/runtime" } +frame-system = { version = "2.0.0-alpha.4", default-features = false, path = "../../frame/system" } +pallet-balances = { version = "2.0.0-alpha.4", default-features = false, path = "../../frame/balances" } +sp-runtime = { version = "2.0.0-alpha.4", default-features = false, path = "../../primitives/runtime" } [features] default = ["std"] @@ -20,4 +20,4 @@ std = [ "frame-system/std", "pallet-balances/std", "sp-runtime/std", -] \ No newline at end of file +] diff --git a/utils/cli-utils/src/lib.rs b/utils/cli-utils/src/lib.rs index 611f572404228..30aea660f4abb 100644 --- a/utils/cli-utils/src/lib.rs +++ b/utils/cli-utils/src/lib.rs @@ -15,6 +15,8 @@ // along with Substrate. If not, see . //! Utilities for cli. +#![cfg_attr(not(feature = "std"), no_std)] + use sp_runtime::traits::{StaticLookup, SignedExtension}; pub use pallet_balances::Call as BalancesCall; @@ -28,6 +30,8 @@ pub type CallFor = ::Call; pub type AddressFor = <::Lookup as StaticLookup>::Source; /// Hash for runtime. pub type HashFor = ::Hash; +/// AccountId type for runtime. +pub type AccountIdFor = ::AccountId; /// Runtime adapter for signing utilities pub trait RuntimeAdapter: frame_system::Trait + pallet_balances::Trait { From aa71995433e0fa58a802b5794a5692702c40b766 Mon Sep 17 00:00:00 2001 From: Seun Date: Fri, 20 Mar 2020 16:19:10 +0100 Subject: [PATCH 15/77] use &'static str for TryFrom::<&'a str>::Error for Ss58AddressFormat --- primitives/core/src/crypto.rs | 10 +++++----- primitives/core/src/lib.rs | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index d6e169c8fa075..52e9cd6a2bbb9 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -365,8 +365,8 @@ macro_rules! ss58_address_format { impl Ss58AddressFormat { /// names of all address formats - pub fn all_names() -> Vec<&'static str> { - vec![ + pub fn all_names() -> [&'static str; 0 $(+ { let _ = $number; 1})*] { + [ $($name),*, ] } @@ -405,13 +405,13 @@ macro_rules! ss58_address_format { } impl<'a> TryFrom<&'a str> for Ss58AddressFormat { - type Error = String; + type Error = &'static str; - fn try_from(x: &'a str) -> Result { + fn try_from(x: &'a str) -> Result { match x { $($name => Ok(Ss58AddressFormat::$identifier)),*, a => a.parse::().map(Ss58AddressFormat::Custom) - .map_err(|e| format!("failed to parse network value as u8 {:?}", e)), + .map_err(|_| "failed to parse network value as u8"), } } } diff --git a/primitives/core/src/lib.rs b/primitives/core/src/lib.rs index 79380a6fc6532..b4f99169ef7d9 100644 --- a/primitives/core/src/lib.rs +++ b/primitives/core/src/lib.rs @@ -49,6 +49,7 @@ pub use impl_serde::serialize as bytes; #[cfg(feature = "full_crypto")] pub mod hashing; + #[cfg(feature = "full_crypto")] pub use hashing::{blake2_128, blake2_256, twox_64, twox_128, twox_256, keccak_256}; #[cfg(feature = "std")] From 65eeefcc56cf2ca28ed52376953ea9e383573cb5 Mon Sep 17 00:00:00 2001 From: Seun Date: Fri, 20 Mar 2020 16:36:28 +0100 Subject: [PATCH 16/77] tests --- Cargo.lock | 1 + client/cli/src/commands/tests.rs | 27 +-------------------------- test-utils/runtime/Cargo.toml | 1 + test-utils/runtime/src/lib.rs | 23 +++++++++++++++++++++++ 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 443fc91c40671..6818749bac406 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8245,6 +8245,7 @@ name = "substrate-test-runtime" version = "2.0.0-dev" dependencies = [ "cfg-if", + "cli-utils", "frame-executive", "frame-support", "frame-system", diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs index 820734eec8a7f..6f2c0af58ff16 100644 --- a/client/cli/src/commands/tests.rs +++ b/client/cli/src/commands/tests.rs @@ -16,38 +16,13 @@ use super::*; use substrate_test_runtime::Runtime; - -use sp_runtime::generic::Era; use tempfile::Builder; use std::io::Read; use crate::commands::inspect::InspectCmd; use crate::Error; -impl RuntimeAdapter for Runtime { - type Extra = ( - frame_system::CheckVersion, - frame_system::CheckGenesis, - frame_system::CheckEra, - frame_system::CheckNonce, - frame_system::CheckWeight, - ); - - fn build_extra(index: IndexFor) -> Self::Extra { - ( - frame_system::CheckVersion::new(), - frame_system::CheckGenesis::new(), - frame_system::CheckEra::from(Era::Immortal), - frame_system::CheckNonce::from(index), - frame_system::CheckWeight::new(), - ) - } -} - fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - pallet_balances::GenesisConfig::{ - balances: vec![], - }.assimilate_storage(&mut t).unwrap(); + let t = frame_system::GenesisConfig::default().build_storage::().unwrap(); sp_io::TestExternalities::new(t) } diff --git a/test-utils/runtime/Cargo.toml b/test-utils/runtime/Cargo.toml index 8bd96e42f1555..2735ec8c19c25 100644 --- a/test-utils/runtime/Cargo.toml +++ b/test-utils/runtime/Cargo.toml @@ -42,6 +42,7 @@ sp-trie = { version = "2.0.0-alpha.4", default-features = false, path = "../../p sp-transaction-pool = { version = "2.0.0-alpha.4", default-features = false, path = "../../primitives/transaction-pool" } trie-db = { version = "0.20.0", default-features = false } parity-util-mem = { version = "0.6.0", default-features = false, features = ["primitive-types"] } +cli-utils = { version = "2.0.0-alpha.3", default-features = false, path = "../../utils/cli-utils" } [dev-dependencies] sc-block-builder = { version = "0.8.0-alpha.4", path = "../../client/block-builder" } diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index a5a0ca6225e00..23a29d68e95d2 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -50,9 +50,12 @@ use frame_support::{impl_outer_origin, impl_outer_event, parameter_types, weight use sp_inherents::{CheckInherentsResult, InherentData}; use cfg_if::cfg_if; use sp_core::storage::ChildType; +use sp_runtime::generic::Era; +use cli_utils::IndexFor; // Ensure Babe and Aura use the same crypto to simplify things a bit. pub use sp_consensus_babe::{AuthorityId, SlotNumber}; + pub type AuraId = sp_consensus_aura::sr25519::AuthorityId; // Include the WASM binary @@ -348,6 +351,26 @@ impl GetNodeBlockType for Runtime { type NodeBlock = Block; } +impl cli_utils::RuntimeAdapter for Runtime { + type Extra = ( + frame_system::CheckVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + ); + + fn build_extra(index: IndexFor) -> Self::Extra { + ( + frame_system::CheckVersion::new(), + frame_system::CheckGenesis::new(), + frame_system::CheckEra::from(Era::Immortal), + frame_system::CheckNonce::from(index), + frame_system::CheckWeight::new(), + ) + } +} + impl GetRuntimeBlockType for Runtime { type RuntimeBlock = Block; } From 1ee33bb7b422a3dca42b4ba928b307ed0eb51479 Mon Sep 17 00:00:00 2001 From: Seun Date: Fri, 20 Mar 2020 18:27:34 +0100 Subject: [PATCH 17/77] add frame-system to sc-cli dev-dependencies --- client/cli/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 6a759a8915e9d..759ea07fc2afb 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -62,6 +62,7 @@ rpassword = "4.0.1" tempfile = "3.1.0" substrate-test-runtime = { version = "2.0.0-dev", features = ["indices-lookup"], path = "../../test-utils/runtime" } sp-application-crypto = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/application-crypto" } +frame-system = { version = "2.0.0-aplha.4", path = "../../frame/system" } [features] wasmtime = [ From e5336b63ba6358d874d03f9b7591579f96f53039 Mon Sep 17 00:00:00 2001 From: Seun Date: Fri, 20 Mar 2020 18:33:12 +0100 Subject: [PATCH 18/77] add frame-system to sc-cli dev-dependencies --- Cargo.lock | 1 + client/cli/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 6818749bac406..937f6c9ff26c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6168,6 +6168,7 @@ dependencies = [ "derive_more", "env_logger 0.7.1", "fdlimit", + "frame-system", "futures 0.1.29", "futures 0.3.4", "hex", diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 759ea07fc2afb..0bed18e4ff2bb 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -62,7 +62,7 @@ rpassword = "4.0.1" tempfile = "3.1.0" substrate-test-runtime = { version = "2.0.0-dev", features = ["indices-lookup"], path = "../../test-utils/runtime" } sp-application-crypto = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/application-crypto" } -frame-system = { version = "2.0.0-aplha.4", path = "../../frame/system" } +frame-system = { version = "2.0.0-alpha.4", path = "../../frame/system" } [features] wasmtime = [ From cf6f0b9e516e1dc2f076a351fa1f32939a213542 Mon Sep 17 00:00:00 2001 From: Seun Date: Wed, 15 Apr 2020 12:03:26 +0100 Subject: [PATCH 19/77] fix ui test --- primitives/api/test/tests/ui/mock_only_one_error_type.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/api/test/tests/ui/mock_only_one_error_type.stderr b/primitives/api/test/tests/ui/mock_only_one_error_type.stderr index 8f026838c96b8..d7aef66fcfc28 100644 --- a/primitives/api/test/tests/ui/mock_only_one_error_type.stderr +++ b/primitives/api/test/tests/ui/mock_only_one_error_type.stderr @@ -24,4 +24,4 @@ error[E0277]: the trait bound `u32: std::convert::From` is > > > - and 16 others + and 18 others From 6a4d66af9dccaeac48487ed91f4b4f97a3543a65 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 5 May 2020 16:28:14 +0100 Subject: [PATCH 20/77] wip --- Cargo.lock | 105 ++++++++++++++++++-- client/cli/Cargo.toml | 11 ++ client/cli/src/commands/generate.rs | 4 +- client/cli/src/commands/insert.rs | 6 +- client/cli/src/commands/inspect.rs | 4 +- client/cli/src/commands/sign.rs | 10 +- client/cli/src/commands/sign_transaction.rs | 14 +-- client/cli/src/commands/transfer.rs | 6 +- client/cli/src/commands/utils.rs | 17 +--- client/cli/src/params/keystore_params.rs | 14 +++ client/cli/src/runner.rs | 5 +- 11 files changed, 141 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4c2346538e1ec..08be806268830 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -215,7 +215,7 @@ dependencies = [ "mio", "mio-uds", "num_cpus", - "once_cell", + "once_cell 1.3.1", "pin-project-lite", "pin-utils", "slab", @@ -334,6 +334,21 @@ dependencies = [ "which", ] +[[package]] +name = "bip39" +version = "0.6.0-beta.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7059804e226b3ac116519a252d7f5fb985a5ccc0e93255e036a5f7e7283323f4" +dependencies = [ + "failure", + "hashbrown 0.1.8", + "hmac", + "once_cell 0.1.8", + "pbkdf2", + "rand 0.6.5", + "sha2", +] + [[package]] name = "bitflags" version = "1.2.1" @@ -934,7 +949,7 @@ dependencies = [ "lazy_static", "maybe-uninit", "memoffset", - "scopeguard", + "scopeguard 1.1.0", ] [[package]] @@ -1485,7 +1500,7 @@ dependencies = [ "frame-system", "impl-trait-for-tuples", "log", - "once_cell", + "once_cell 1.3.1", "parity-scale-codec", "paste", "pretty_assertions", @@ -1967,6 +1982,16 @@ dependencies = [ "crunchy", ] +[[package]] +name = "hashbrown" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" +dependencies = [ + "byteorder 1.3.4", + "scopeguard 0.3.3", +] + [[package]] name = "hashbrown" version = "0.6.3" @@ -3080,13 +3105,22 @@ dependencies = [ "paste", ] +[[package]] +name = "lock_api" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" +dependencies = [ + "scopeguard 0.3.3", +] + [[package]] name = "lock_api" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" dependencies = [ - "scopeguard", + "scopeguard 1.1.0", ] [[package]] @@ -3104,7 +3138,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0609345ddee5badacf857d4f547e0e5a2e987db77085c24cd887f73573a04237" dependencies = [ - "hashbrown", + "hashbrown 0.6.3", ] [[package]] @@ -3170,7 +3204,7 @@ checksum = "be512cb2ccb4ecbdca937fdd4a62ea5f09f8e7195466a85e4632b3d5bcce82e6" dependencies = [ "ahash", "hash-db", - "hashbrown", + "hashbrown 0.6.3", "parity-util-mem", ] @@ -3892,6 +3926,15 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "once_cell" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "532c29a261168a45ce28948f9537ddd7a5dd272cc513b3017b1e82a88f962c37" +dependencies = [ + "parking_lot 0.7.1", +] + [[package]] name = "once_cell" version = "1.3.1" @@ -4867,13 +4910,23 @@ version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" +[[package]] +name = "parking_lot" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" +dependencies = [ + "lock_api 0.1.5", + "parking_lot_core 0.4.0", +] + [[package]] name = "parking_lot" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" dependencies = [ - "lock_api", + "lock_api 0.3.4", "parking_lot_core 0.6.2", "rustc_version", ] @@ -4884,10 +4937,23 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" dependencies = [ - "lock_api", + "lock_api 0.3.4", "parking_lot_core 0.7.2", ] +[[package]] +name = "parking_lot_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" +dependencies = [ + "libc", + "rand 0.6.5", + "rustc_version", + "smallvec 0.6.13", + "winapi 0.3.8", +] + [[package]] name = "parking_lot_core" version = "0.6.2" @@ -4947,6 +5013,7 @@ checksum = "006c038a43a45995a9670da19e67600114740e8511d4333bf97a56e66a7542d9" dependencies = [ "byteorder 1.3.4", "crypto-mac", + "rayon", ] [[package]] @@ -5927,6 +5994,7 @@ dependencies = [ "ansi_term 0.12.1", "app_dirs", "atty", + "bip39", "chrono", "clap", "cli-utils", @@ -5934,20 +6002,29 @@ dependencies = [ "env_logger 0.7.1", "fdlimit", "frame-system", + "futures 0.1.29", "futures 0.3.4", + "hex", + "hyper 0.12.35", + "jsonrpc-core-client", "lazy_static", + "libp2p", "log", "names", "nix", + "parity-scale-codec", "parity-util-mem", + "rand 0.7.3", "regex", "rpassword", "sc-client-api", "sc-informant", "sc-network", + "sc-rpc", "sc-service", "sc-telemetry", "sc-tracing", + "serde", "serde_json", "sp-application-crypto", "sp-blockchain", @@ -6882,6 +6959,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" +[[package]] +name = "scopeguard" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" + [[package]] name = "scopeguard" version = "1.1.0" @@ -8372,7 +8455,7 @@ dependencies = [ "doc-comment", "libc", "ntapi", - "once_cell", + "once_cell 1.3.1", "rayon", "winapi 0.3.8", ] @@ -8490,7 +8573,7 @@ checksum = "b0165e045cc2ae1660270ca65e1676dbaab60feb0f91b10f7d0665e9b47e31f2" dependencies = [ "failure", "hmac", - "once_cell", + "once_cell 1.3.1", "pbkdf2", "rand 0.7.3", "rustc-hash", @@ -8875,7 +8958,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcc309f34008563989045a4c4dbcc5770467f3a3785ee80a9b5cc0d83362475f" dependencies = [ "hash-db", - "hashbrown", + "hashbrown 0.6.3", "log", "rustc-hex", "smallvec 1.3.0", diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 03b6d6431f5fe..ba422e0d5e037 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -24,13 +24,24 @@ lazy_static = "1.4.0" app_dirs = "1.2.1" tokio = { version = "0.2.9", features = [ "signal", "rt-core", "rt-threaded" ] } futures = "0.3.4" +futures01 = { package = "futures", version = "0.1.29" } fdlimit = "0.1.4" +serde = "1.0.106" +libp2p = "0.18.1" +parity-scale-codec = "1.3.0" +hex = "0.4.2" +jsonrpc-core-client = { version = "14.0.3", features = ["http"] } +hyper = "0.12.35" +rand = "0.7.3" +bip39 = "0.6.0-beta.1" serde_json = "1.0.41" +frame-system = { version = "2.0.0-alpha.6", path = "../../frame/system" } sc-informant = { version = "0.8.0-dev", path = "../informant" } sp-panic-handler = { version = "2.0.0-dev", path = "../../primitives/panic-handler" } sc-client-api = { version = "2.0.0-dev", path = "../api" } sp-blockchain = { version = "2.0.0-dev", path = "../../primitives/blockchain" } sc-network = { version = "0.8.0-dev", path = "../network" } +sc-rpc = { version = "2.0.0-dev", path = "../rpc" } sp-runtime = { version = "2.0.0-dev", path = "../../primitives/runtime" } sp-utils = { version = "2.0.0-dev", path = "../../primitives/utils" } sp-version = { version = "2.0.0-dev", path = "../../primitives/version" } diff --git a/client/cli/src/commands/generate.rs b/client/cli/src/commands/generate.rs index ac224b5453b7d..d110581b1b556 100644 --- a/client/cli/src/commands/generate.rs +++ b/client/cli/src/commands/generate.rs @@ -16,7 +16,7 @@ //! Implementation of the `generate` subcommand -use super::{SharedParams, get_password}; +use super::{SharedParams}; use crate::error::{self, Error}; use bip39::{MnemonicType, Mnemonic, Language}; use structopt::StructOpt; @@ -52,7 +52,7 @@ impl GenerateCmd { None => MnemonicType::Words12, }; let mnemonic = Mnemonic::new(words, Language::English); - let password = get_password(&self.keystore_params)?; + let password = self.keystore_params.read_password()?; let maybe_network = self.shared_params.network; let output = self.shared_params.output_type; diff --git a/client/cli/src/commands/insert.rs b/client/cli/src/commands/insert.rs index 386425ae63aca..5185a3a327785 100644 --- a/client/cli/src/commands/insert.rs +++ b/client/cli/src/commands/insert.rs @@ -17,7 +17,7 @@ //! Implementation of the `insert` subcommand use crate::{error, with_crypto_scheme, pair_from_suri, CliConfiguration, KeystoreParams}; -use super::{SharedParams, get_password, read_uri}; +use super::{SharedParams, read_uri}; use structopt::StructOpt; use sp_core::{crypto::KeyTypeId, Bytes}; use std::convert::TryFrom; @@ -26,7 +26,7 @@ use hyper::rt; use sc_rpc::author::AuthorClient; use jsonrpc_core_client::transports::http; use serde::{de::DeserializeOwned, Serialize}; -use cli_utils::HashFor; +use cli_utils::{HashFor, RuntimeAdapter}; /// The `insert` command #[derive(Debug, StructOpt, Clone)] @@ -66,7 +66,7 @@ impl InsertCmd { HashFor: DeserializeOwned + Serialize + Send + Sync, { let suri = read_uri(self.suri)?; - let password = get_password(&self.keystore_params)?; + let password = self.keystore_params.read_password()?; let public = with_crypto_scheme!( self.shared_params.scheme, diff --git a/client/cli/src/commands/inspect.rs b/client/cli/src/commands/inspect.rs index 9f4c1e5296976..0006f6260efe3 100644 --- a/client/cli/src/commands/inspect.rs +++ b/client/cli/src/commands/inspect.rs @@ -17,7 +17,7 @@ //! Implementation of the `inspect` subcommand use crate::{error, print_from_uri, with_crypto_scheme, CliConfiguration, KeystoreParams}; -use super::{SharedParams, get_password, read_uri}; +use super::{SharedParams, read_uri}; use structopt::StructOpt; /// The `inspect` command @@ -46,7 +46,7 @@ impl InspectCmd { /// Run the command pub fn run(self) -> error::Result<()> { let uri = read_uri(self.uri)?; - let pass = get_password(&self.keystore_params).ok(); + let pass = self.keystore_params.read_password().ok(); with_crypto_scheme!( self.shared_params.scheme, diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs index 3a53c5c87b584..6c7371043b6fe 100644 --- a/client/cli/src/commands/sign.rs +++ b/client/cli/src/commands/sign.rs @@ -16,7 +16,7 @@ //! Implementation of the `sign` subcommand use crate::{error, with_crypto_scheme, pair_from_suri, CliConfiguration, KeystoreParams}; -use super::{SharedParams, get_password, read_message, read_uri}; +use super::{SharedParams, read_message, read_uri}; use structopt::StructOpt; /// The `sign` command @@ -56,15 +56,11 @@ impl SignCmd { pub fn run(self) -> error::Result<()> { let message = read_message(self.message, self.hex)?; let suri = read_uri(self.suri)?; - let password = get_password(&self.keystore_params)?; + let password = self.keystore_params.read_password()?; let signature = with_crypto_scheme!( self.shared_params.scheme, - sign( - &suri, - &password, - message - ) + sign(&suri, &password, message) )?; println!("{}", signature); diff --git a/client/cli/src/commands/sign_transaction.rs b/client/cli/src/commands/sign_transaction.rs index 352afc21e772b..3710bfba76cee 100644 --- a/client/cli/src/commands/sign_transaction.rs +++ b/client/cli/src/commands/sign_transaction.rs @@ -16,14 +16,12 @@ //! Implementation of the `sign-transaction` subcommand use crate::{error, with_crypto_scheme, CliConfiguration, KeystoreParams}; -use super::{ - SharedParams, get_password, - IndexFor, CallFor, pair_from_suri, decode_hex, create_extrinsic_for, -}; +use super::{SharedParams, IndexFor, CallFor, pair_from_suri, decode_hex, create_extrinsic_for}; use structopt::StructOpt; use parity_scale_codec::{Codec, Encode, Decode}; use std::{str::FromStr, fmt::Display}; use sp_runtime::MultiSigner; +use cli_utils::RuntimeAdapter; type Call = Vec; @@ -66,15 +64,11 @@ impl SignTransactionCmd { let nonce = IndexFor::::from_str(&self.nonce).map_err(|e| format!("{}", e))?; let call = CallFor::::decode(&mut &self.call[..])?; + let pass = self.keystore_params.read_password()?; with_crypto_scheme!( self.shared_params.scheme, - print_ext( - &self.suri, - &get_password(&self.keystore_params)?, - call, - nonce - ) + print_ext(&self.suri, &pass, call, nonce) ) } } diff --git a/client/cli/src/commands/transfer.rs b/client/cli/src/commands/transfer.rs index 2a34e3b2f70d0..66092cbceaf98 100644 --- a/client/cli/src/commands/transfer.rs +++ b/client/cli/src/commands/transfer.rs @@ -17,7 +17,7 @@ //! Implementation of the `transfer` subcommand use crate::{ - error, create_extrinsic_for, get_password, with_crypto_scheme, + error, create_extrinsic_for, with_crypto_scheme, pair_from_suri, decode_hex, CliConfiguration, KeystoreParams, }; use super::SharedParams; @@ -27,7 +27,7 @@ use parity_scale_codec::Encode; use sp_runtime::MultiSigner; use std::convert::TryFrom; use sp_core::crypto::Ss58Codec; -use cli_utils::{AddressFor, IndexFor, BalanceFor, BalancesCall, AccountIdFor}; +use cli_utils::{AddressFor, IndexFor, BalanceFor, BalancesCall, AccountIdFor, RuntimeAdapter}; /// The `transfer` command #[derive(Debug, StructOpt, Clone)] @@ -72,7 +72,7 @@ impl TransferCmd { as FromStr>::Err: Display, as FromStr>::Err: Display, { - let password = get_password(&self.keystore_params)?; + let password = self.keystore_params.read_password()?; let nonce = IndexFor::::from_str(&self.index).map_err(|e| format!("{}", e))?; let to = if let Ok(data_vec) = decode_hex(&self.to) { AccountIdFor::::try_from(&data_vec) diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 2c5561a776f71..a8beb622741af 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -24,29 +24,16 @@ use sp_runtime::{ traits::IdentifyAccount, MultiSigner, generic::{UncheckedExtrinsic, SignedPayload}, }; -use crate::{arg_enums::{OutputType}, error::{self, Error}, KeystoreParams}; +use crate::{arg_enums::OutputType, error::{self, Error}}; use parity_scale_codec::Encode; use serde_json::json; -use cli_utils::IndexFor; +use cli_utils::{IndexFor, RuntimeAdapter}; /// Public key type for Runtime pub type PublicFor

=

::Public; /// Seed type for Runtime pub type SeedFor

=

::Seed; -/// helper method to fetch password from `SharedParams` or read from stdin -pub fn get_password(params: &KeystoreParams) -> error::Result { - let (password_interactive, password) = (params.password_interactive, params.password.as_ref()); - - let pass = if password_interactive { - rpassword::read_password_from_tty(Some("Key password: "))? - } else { - password.map(Into::into).ok_or("Password not specified")? - }; - - Ok(pass) -} - /// helper method to fetch uri from `Option` either as a file or read from stdin pub fn read_uri(uri: Option) -> error::Result { let uri = if let Some(uri) = uri { diff --git a/client/cli/src/params/keystore_params.rs b/client/cli/src/params/keystore_params.rs index c6131c2f64941..d7cd96c69bc29 100644 --- a/client/cli/src/params/keystore_params.rs +++ b/client/cli/src/params/keystore_params.rs @@ -19,6 +19,7 @@ use sc_service::config::KeystoreConfig; use std::fs; use std::path::PathBuf; use structopt::StructOpt; +use crate::error; /// default sub directory for the key store const DEFAULT_KEYSTORE_CONFIG_PATH: &'static str = "keystore"; @@ -83,6 +84,19 @@ impl KeystoreParams { Ok(KeystoreConfig::Path { path, password }) } + + /// helper method to fetch password from `KeyParams` or read from stdin + pub fn read_password(self) -> error::Result { + let (password_interactive, password) = (self.password_interactive, self.password.as_ref()); + + let pass = if password_interactive { + rpassword::read_password_from_tty(Some("Key password: "))? + } else { + password.map(Into::into).ok_or("Password not specified")? + }; + + Ok(pass) + } } #[cfg(not(target_os = "unknown"))] diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index 774a1ae6b006d..4e00b0f3e6e6c 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -29,7 +29,7 @@ use sp_utils::metrics::{TOKIO_THREADS_ALIVE, TOKIO_THREADS_TOTAL}; use std::fmt::{Debug, Display}; use std::marker::PhantomData; use std::sync::Arc; -use cli_utils::{AccountIdFor, AddressFor, IndexFor, BalanceFor, CallFor}; +use cli_utils::{AccountIdFor, AddressFor, IndexFor, BalanceFor, CallFor, RuntimeAdapter}; use std::convert::TryFrom; use sp_core::crypto::Ss58Codec; use std::str::FromStr; @@ -212,9 +212,10 @@ impl Runner { Subcommand::Sign(cmd) => cmd.run(), Subcommand::Verify(cmd) => cmd.run(), Subcommand::Vanity(cmd) => cmd.run(), - Subcommand::Transfer(cmd) => cmd.run::(), + // Subcommand::Transfer(cmd) => cmd.run::(), Subcommand::SignTransaction(cmd) => cmd.run::(), Subcommand::Insert(cmd) => cmd.run::(), + _ => unimplemented!() } } From e23b87b87cf8ef323795501ae7b7b951d63de3fd Mon Sep 17 00:00:00 2001 From: Seun Date: Wed, 6 May 2020 10:51:21 +0100 Subject: [PATCH 21/77] fixed inspect test --- bin/node/cli/build.rs | 2 +- client/cli/Cargo.toml | 1 - client/cli/src/commands/inspect.rs | 2 +- client/cli/src/commands/mod.rs | 4 ++-- client/cli/src/commands/tests.rs | 4 ++-- client/cli/src/runner.rs | 2 +- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/bin/node/cli/build.rs b/bin/node/cli/build.rs index 89e9748463b8b..12e0cab58ada5 100644 --- a/bin/node/cli/build.rs +++ b/bin/node/cli/build.rs @@ -38,7 +38,7 @@ mod cli { /// Full list in https://github.com/kbknapp/clap-rs/blob/e9d0562a1dc5dfe731ed7c767e6cee0af08f0cf9/src/app/parser.rs#L123 fn build_shell_completion() { for shell in &[Shell::Bash, Shell::Fish, Shell::Zsh, Shell::Elvish, Shell::PowerShell] { - // build_completion(shell); + build_completion(shell); } } diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index fc38f90e92956..932d1529805fe 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -35,7 +35,6 @@ hyper = "0.12.35" rand = "0.7.3" bip39 = "0.6.0-beta.1" serde_json = "1.0.41" -frame-system = { version = "2.0.0-alpha.6", path = "../../frame/system" } sc-informant = { version = "0.8.0-dev", path = "../informant" } sp-panic-handler = { version = "2.0.0-dev", path = "../../primitives/panic-handler" } sc-client-api = { version = "2.0.0-dev", path = "../api" } diff --git a/client/cli/src/commands/inspect.rs b/client/cli/src/commands/inspect.rs index 0006f6260efe3..54ff1f2d353e1 100644 --- a/client/cli/src/commands/inspect.rs +++ b/client/cli/src/commands/inspect.rs @@ -23,7 +23,7 @@ use structopt::StructOpt; /// The `inspect` command #[derive(Debug, StructOpt, Clone)] #[structopt( - name = "inspect", + name = "inspect-key", about = "Gets a public key and a SS58 address from the provided Secret URI" )] pub struct InspectCmd { diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 4db8551ca134f..d868325f9290f 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -98,7 +98,7 @@ pub enum Subcommand { Generate(GenerateCmd), /// Gets a public key and a SS58 address from the provided Secret URI - Inspect(InspectCmd), + InspectKey(InspectCmd), /// Insert a key to the keystore of a node. Insert(InsertCmd), @@ -472,7 +472,7 @@ substrate_cli_subcommands!( PurgeChain, GenerateNodeKey, Generate, - Inspect, + InspectKey, Insert, Sign, SignTransaction, diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs index 6f2c0af58ff16..4f892438909f7 100644 --- a/client/cli/src/commands/tests.rs +++ b/client/cli/src/commands/tests.rs @@ -50,10 +50,10 @@ fn inspect() { let words = "remember fiber forum demise paper uniform squirrel feel access exclude casual effort"; let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; - let inspect = InspectCmd::from_iter(&["inspect", "--uri", words, "--password", "12345"]); + let inspect = InspectCmd::from_iter(&["inspect-key", "--uri", words, "--password", "12345"]); assert!(inspect.run().is_ok()); - let inspect = InspectCmd::from_iter(&["inspect", "--uri", seed]); + let inspect = InspectCmd::from_iter(&["inspect-key", "--uri", seed]); assert!(inspect.run().is_ok()); } diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index 3266a3aef2542..3efb52076e739 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -214,7 +214,7 @@ impl Runner { Subcommand::PurgeChain(cmd) => cmd.run(self.config), Subcommand::GenerateNodeKey(cmd) => cmd.run(), Subcommand::Generate(cmd) => cmd.run(), - Subcommand::Inspect(cmd) => cmd.run(), + Subcommand::InspectKey(cmd) => cmd.run(), Subcommand::Sign(cmd) => cmd.run(), Subcommand::Verify(cmd) => cmd.run(), Subcommand::Vanity(cmd) => cmd.run(), From 62e9e0d054bb613da38cc370a1d01518efc5f2ec Mon Sep 17 00:00:00 2001 From: Seun Date: Wed, 6 May 2020 12:10:03 +0100 Subject: [PATCH 22/77] bump impl version --- bin/node/runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index b6f4334585d91..e8c70fc2c3e2d 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -82,7 +82,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("node"), impl_name: create_runtime_str!("substrate-node"), - authoring_version: 10, + authoring_version: 11, // Per convention: if the runtime behavior changes, increment spec_version // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as From 03ca897fa8ae651a5755758b8e6368962469ee2c Mon Sep 17 00:00:00 2001 From: Seun Date: Wed, 6 May 2020 12:25:59 +0100 Subject: [PATCH 23/77] bump impl version, fixx spaces remove todos --- bin/node/runtime/src/lib.rs | 4 ++-- client/cli/src/commands/utils.rs | 12 ++++++------ client/cli/src/runner.rs | 4 +--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index e8c70fc2c3e2d..4437b132063e5 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -82,12 +82,12 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("node"), impl_name: create_runtime_str!("substrate-node"), - authoring_version: 11, + authoring_version: 10, // Per convention: if the runtime behavior changes, increment spec_version // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 246, + spec_version: 247, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index a8beb622741af..4d775609705a9 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -58,19 +58,19 @@ macro_rules! with_crypto_scheme { ($scheme:expr, $method:ident($($params:expr),*)) => { with_crypto_scheme!($scheme, $method<>($($params),*)) }; - ($scheme:expr, $method:ident<$($gen:ident),*>($($params:expr),*)) => { - match $scheme { + ($scheme:expr, $method:ident<$($generics:ident),*>($($params:expr),*)) => { + match $scheme { $crate::arg_enums::CryptoScheme::Ecdsa => { - $method::($($params),*) + $method::($($params),*) } $crate::arg_enums::CryptoScheme::Sr25519 => { - $method::($($params),*) + $method::($($params),*) } $crate::arg_enums::CryptoScheme::Ed25519 => { - $method::($($params),*) + $method::($($params),*) } } - }; + }; } /// print formatted pair from uri diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index 3efb52076e739..1397c55bcc8b4 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -218,11 +218,9 @@ impl Runner { Subcommand::Sign(cmd) => cmd.run(), Subcommand::Verify(cmd) => cmd.run(), Subcommand::Vanity(cmd) => cmd.run(), - // Subcommand::Transfer(cmd) => cmd.run::(), + Subcommand::Transfer(cmd) => cmd.run::(), Subcommand::SignTransaction(cmd) => cmd.run::(), Subcommand::Insert(cmd) => cmd.run::(), - _ => unimplemented!() - } } From cd4cad59267914f19891be8ce695cc9fa91607d1 Mon Sep 17 00:00:00 2001 From: Seun Date: Thu, 7 May 2020 16:21:08 +0100 Subject: [PATCH 24/77] =?UTF-8?q?pallet-balances-cli,=20rustc=20for=20some?= =?UTF-8?q?=20reason=20cannot=20resolve=20pallet=5Fbalances=5Fcli=20in=20n?= =?UTF-8?q?ode-cli=20=F0=9F=98=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .maintain/rename-crates-for-2.0.sh | 2 +- Cargo.lock | 27 +++- Cargo.toml | 1 + bin/node/cli/Cargo.toml | 2 + bin/node/cli/src/cli.rs | 5 + bin/node/cli/src/command.rs | 5 + client/cli/Cargo.toml | 2 - client/cli/src/arg_enums.rs | 14 +- client/cli/src/commands/generate.rs | 23 ++- client/cli/src/commands/insert.rs | 10 +- client/cli/src/commands/inspect.rs | 23 ++- client/cli/src/commands/mod.rs | 6 - client/cli/src/commands/sign.rs | 8 +- client/cli/src/commands/sign_transaction.rs | 13 +- client/cli/src/commands/tests.rs | 31 ---- client/cli/src/commands/transfer.rs | 128 --------------- client/cli/src/commands/utils.rs | 59 ++++--- client/cli/src/commands/vanity.rs | 25 ++- client/cli/src/commands/verify.rs | 8 +- client/cli/src/lib.rs | 2 +- client/cli/src/params/shared_params.rs | 41 +++-- client/cli/src/runner.rs | 2 +- utils/frame/pallet-balances-cli/Cargo.toml | 19 +++ utils/frame/pallet-balances-cli/src/lib.rs | 167 ++++++++++++++++++++ 24 files changed, 373 insertions(+), 250 deletions(-) delete mode 100644 client/cli/src/commands/transfer.rs create mode 100644 utils/frame/pallet-balances-cli/Cargo.toml create mode 100644 utils/frame/pallet-balances-cli/src/lib.rs diff --git a/.maintain/rename-crates-for-2.0.sh b/.maintain/rename-crates-for-2.0.sh index 7ac444fdd7193..5d873d26cdfca 100755 --- a/.maintain/rename-crates-for-2.0.sh +++ b/.maintain/rename-crates-for-2.0.sh @@ -95,7 +95,7 @@ TO_RENAME=( "substrate-block-builder sc-block-builder" "substrate-chain-spec sc-chain-spec" "substrate-chain-spec-derive sc-chain-spec-derive" - "substrate-cli-utils sc-cli-utils" + "substrate-cli sc-cli" "substrate-consensus-aura sc-consensus-aura" "substrate-consensus-babe sc-consensus-babe" "substrate-consensus-pow sc-consensus-pow" diff --git a/Cargo.lock b/Cargo.lock index 7d01c038db511..de538433002a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3482,6 +3482,7 @@ dependencies = [ "node-runtime", "pallet-authority-discovery", "pallet-balances", + "pallet-balances-cli", "pallet-contracts", "pallet-im-online", "pallet-indices", @@ -4093,6 +4094,22 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-balances-cli" +version = "2.0.0-dev" +dependencies = [ + "cli-utils", + "frame-system", + "hex", + "parity-scale-codec", + "sc-cli", + "sp-core", + "sp-io", + "sp-runtime", + "structopt", + "substrate-test-runtime", +] + [[package]] name = "pallet-benchmark" version = "2.0.0-dev" @@ -6018,7 +6035,6 @@ dependencies = [ "derive_more", "env_logger 0.7.1", "fdlimit", - "frame-system", "futures 0.1.29", "futures 0.3.4", "hex", @@ -6055,7 +6071,6 @@ dependencies = [ "sp-version", "structopt", "substrate-prometheus-endpoint", - "substrate-test-runtime", "tempfile", "time", "tokio 0.2.18", @@ -8058,9 +8073,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff6da2e8d107dfd7b74df5ef4d205c6aebee0706c647f6bc6a2d5789905c00fb" +checksum = "863246aaf5ddd0d6928dfeb1a9ca65f505599e4e1b399935ef7e75107516b4ef" dependencies = [ "clap", "lazy_static", @@ -8069,9 +8084,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a489c87c08fbaf12e386665109dd13470dcc9c4583ea3e10dd2b4523e5ebd9ac" +checksum = "d239ca4b13aee7a2142e6795cbd69e457665ff8037aed33b3effdc430d2f927a" dependencies = [ "heck", "proc-macro-error", diff --git a/Cargo.toml b/Cargo.toml index a524152ef6d1c..3b120fd38146e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -174,6 +174,7 @@ members = [ "utils/cli-utils", "utils/fork-tree", "utils/frame/benchmarking-cli", + "utils/frame/pallet-balances-cli", "utils/frame/rpc/support", "utils/frame/rpc/system", "utils/wasm-builder", diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index 5b23a989cd0bf..2b14da011a16e 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -96,6 +96,7 @@ node-executor = { version = "2.0.0-dev", path = "../executor" } # CLI-specific dependencies sc-cli = { version = "0.8.0-dev", optional = true, path = "../../../client/cli" } +pallet-balances-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/pallet-balances-cli" } frame-benchmarking-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/benchmarking-cli" } node-inspect = { version = "0.8.0-dev", optional = true, path = "../inspect" } @@ -146,6 +147,7 @@ cli = [ "node-executor/wasmi-errno", "node-inspect", "sc-cli", + "pallet-balances-cli", "frame-benchmarking-cli", "sc-service/db", "structopt", diff --git a/bin/node/cli/src/cli.rs b/bin/node/cli/src/cli.rs index fa9a43ee6841c..303a37dc7f2b8 100644 --- a/bin/node/cli/src/cli.rs +++ b/bin/node/cli/src/cli.rs @@ -16,6 +16,7 @@ use sc_cli::RunCmd; use structopt::StructOpt; +use pallet_balances_cli::TransferCmd; /// An overarching CLI command definition. #[derive(Clone, Debug, StructOpt)] @@ -35,6 +36,10 @@ pub enum Subcommand { #[structopt(flatten)] Base(sc_cli::Subcommand), + /// prints hex-encoded, signed, transfer extrinsic with given arguments. + #[structopt(flatten)] + Transfer(TransferCmd), + /// The custom inspect subcommmand for decoding blocks and extrinsics. #[structopt( name = "inspect", diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index f7641b9c24648..94736acdb7ae9 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -92,6 +92,11 @@ pub fn run() -> Result<()> { Ok(()) } } + Some(Subcommand::Transfer(cmd)) => { + let runner = cli.create_runner(cmd)?; + + runner.sync_run(|_| cmd.run::()) + } Some(Subcommand::Base(subcommand)) => { let runner = cli.create_runner(subcommand)?; diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 932d1529805fe..8949596893515 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -66,9 +66,7 @@ nix = "0.17.0" [dev-dependencies] tempfile = "3.1.0" sp-io = { version = "2.0.0-dev", path = "../../primitives/io" } -substrate-test-runtime = { version = "2.0.0-dev", features = ["indices-lookup"], path = "../../test-utils/runtime" } sp-application-crypto = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/application-crypto" } -frame-system = { version = "2.0.0-alpha.4", path = "../../frame/system" } [features] wasmtime = [ diff --git a/client/cli/src/arg_enums.rs b/client/cli/src/arg_enums.rs index 3401748104d17..3bb82be67e3ac 100644 --- a/client/cli/src/arg_enums.rs +++ b/client/cli/src/arg_enums.rs @@ -86,18 +86,18 @@ arg_enum! { arg_enum! { #[derive(Debug, Copy, Clone, PartialEq, Eq)] - pub enum OutputType { - Json, - Text, + pub enum CryptoScheme { + Ed25519, + Sr25519, + Ecdsa, } } arg_enum! { #[derive(Debug, Copy, Clone, PartialEq, Eq)] - pub enum CryptoScheme { - Ed25519, - Sr25519, - Ecdsa, + pub enum OutputType { + Json, + Text, } } diff --git a/client/cli/src/commands/generate.rs b/client/cli/src/commands/generate.rs index d110581b1b556..b0ce432c62bed 100644 --- a/client/cli/src/commands/generate.rs +++ b/client/cli/src/commands/generate.rs @@ -20,7 +20,10 @@ use super::{SharedParams}; use crate::error::{self, Error}; use bip39::{MnemonicType, Mnemonic, Language}; use structopt::StructOpt; -use crate::{print_from_uri, with_crypto_scheme, CliConfiguration, KeystoreParams}; +use crate::{ + print_from_uri, CliConfiguration, KeystoreParams, + with_crypto_scheme, NetworkSchemeFlag, OutputTypeFlag, CryptoSchemeFlag, +}; /// The `generate` command #[derive(Debug, StructOpt, Clone)] @@ -37,6 +40,18 @@ pub struct GenerateCmd { #[allow(missing_docs)] #[structopt(flatten)] pub shared_params: SharedParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub network_scheme: NetworkSchemeFlag, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub output_scheme: OutputTypeFlag, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub crypto_scheme: CryptoSchemeFlag, } impl GenerateCmd { @@ -53,11 +68,11 @@ impl GenerateCmd { }; let mnemonic = Mnemonic::new(words, Language::English); let password = self.keystore_params.read_password()?; - let maybe_network = self.shared_params.network; - let output = self.shared_params.output_type; + let maybe_network = self.network_scheme.network; + let output = self.output_scheme.output_type; with_crypto_scheme!( - self.shared_params.scheme, + self.crypto_scheme.scheme, print_from_uri( mnemonic.phrase(), Some(password.as_str()), diff --git a/client/cli/src/commands/insert.rs b/client/cli/src/commands/insert.rs index 5185a3a327785..018f4f82adc6f 100644 --- a/client/cli/src/commands/insert.rs +++ b/client/cli/src/commands/insert.rs @@ -16,7 +16,7 @@ //! Implementation of the `insert` subcommand -use crate::{error, with_crypto_scheme, pair_from_suri, CliConfiguration, KeystoreParams}; +use crate::{error, pair_from_suri, CliConfiguration, KeystoreParams, with_crypto_scheme, CryptoSchemeFlag}; use super::{SharedParams, read_uri}; use structopt::StructOpt; use sp_core::{crypto::KeyTypeId, Bytes}; @@ -26,7 +26,7 @@ use hyper::rt; use sc_rpc::author::AuthorClient; use jsonrpc_core_client::transports::http; use serde::{de::DeserializeOwned, Serialize}; -use cli_utils::{HashFor, RuntimeAdapter}; +use cli_utils::{HashFor, RuntimeAdapter,}; /// The `insert` command #[derive(Debug, StructOpt, Clone)] @@ -56,6 +56,10 @@ pub struct InsertCmd { #[allow(missing_docs)] #[structopt(flatten)] pub shared_params: SharedParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub crypto_scheme: CryptoSchemeFlag, } impl InsertCmd { @@ -69,7 +73,7 @@ impl InsertCmd { let password = self.keystore_params.read_password()?; let public = with_crypto_scheme!( - self.shared_params.scheme, + self.crypto_scheme.scheme, to_vec(&suri, &password) ); diff --git a/client/cli/src/commands/inspect.rs b/client/cli/src/commands/inspect.rs index 54ff1f2d353e1..3074f121cc8a3 100644 --- a/client/cli/src/commands/inspect.rs +++ b/client/cli/src/commands/inspect.rs @@ -16,7 +16,10 @@ //! Implementation of the `inspect` subcommand -use crate::{error, print_from_uri, with_crypto_scheme, CliConfiguration, KeystoreParams}; +use crate::{ + error, print_from_uri, CliConfiguration, KeystoreParams, + with_crypto_scheme, NetworkSchemeFlag, OutputTypeFlag, CryptoSchemeFlag, +}; use super::{SharedParams, read_uri}; use structopt::StructOpt; @@ -40,6 +43,18 @@ pub struct InspectCmd { #[allow(missing_docs)] #[structopt(flatten)] pub shared_params: SharedParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub network_scheme: NetworkSchemeFlag, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub output_scheme: OutputTypeFlag, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub crypto_scheme: CryptoSchemeFlag, } impl InspectCmd { @@ -49,12 +64,12 @@ impl InspectCmd { let pass = self.keystore_params.read_password().ok(); with_crypto_scheme!( - self.shared_params.scheme, + self.crypto_scheme.scheme, print_from_uri( &uri, pass.as_ref().map(String::as_str), - self.shared_params.network, - self.shared_params.output_type + self.network_scheme.network, + self.output_scheme.output_type ) ); diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index d868325f9290f..129cd5690c684 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -26,7 +26,6 @@ mod inspect; mod sign; mod sign_transaction; mod utils; -mod transfer; mod verify; mod vanity; mod insert; @@ -53,7 +52,6 @@ pub use self::{ sign::SignCmd, vanity::VanityCmd, sign_transaction::SignTransactionCmd, - transfer::TransferCmd, verify::VerifyCmd, revert_cmd::RevertCmd, run_cmd::RunCmd, @@ -109,9 +107,6 @@ pub enum Subcommand { /// Sign transaction from encoded Call. Returns a signed and encoded UncheckedMortalCompactExtrinsic as hex. SignTransaction(SignTransactionCmd), - /// Author and sign a Node pallet_balances::Transfer transaction with a given (secret) key. - Transfer(TransferCmd), - /// Verify a signature for a message, provided on STDIN, with a given (public or secret) key. Verify(VerifyCmd), @@ -476,7 +471,6 @@ substrate_cli_subcommands!( Insert, Sign, SignTransaction, - Transfer, Verify, Vanity ); diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs index 6c7371043b6fe..8681efa15a09b 100644 --- a/client/cli/src/commands/sign.rs +++ b/client/cli/src/commands/sign.rs @@ -15,7 +15,7 @@ // along with Substrate. If not, see . //! Implementation of the `sign` subcommand -use crate::{error, with_crypto_scheme, pair_from_suri, CliConfiguration, KeystoreParams}; +use crate::{error, pair_from_suri, CliConfiguration, KeystoreParams, with_crypto_scheme, CryptoSchemeFlag}; use super::{SharedParams, read_message, read_uri}; use structopt::StructOpt; @@ -48,6 +48,10 @@ pub struct SignCmd { #[allow(missing_docs)] #[structopt(flatten)] pub shared_params: SharedParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub crypto_scheme: CryptoSchemeFlag, } @@ -59,7 +63,7 @@ impl SignCmd { let password = self.keystore_params.read_password()?; let signature = with_crypto_scheme!( - self.shared_params.scheme, + self.crypto_scheme.scheme, sign(&suri, &password, message) )?; diff --git a/client/cli/src/commands/sign_transaction.rs b/client/cli/src/commands/sign_transaction.rs index 3710bfba76cee..93e8ea297569a 100644 --- a/client/cli/src/commands/sign_transaction.rs +++ b/client/cli/src/commands/sign_transaction.rs @@ -15,8 +15,11 @@ // along with Substrate. If not, see . //! Implementation of the `sign-transaction` subcommand -use crate::{error, with_crypto_scheme, CliConfiguration, KeystoreParams}; -use super::{SharedParams, IndexFor, CallFor, pair_from_suri, decode_hex, create_extrinsic_for}; +use crate::{ + error, CliConfiguration, KeystoreParams, + with_crypto_scheme, create_extrinsic_for, CryptoSchemeFlag +}; +use super::{SharedParams, IndexFor, CallFor, pair_from_suri, decode_hex}; use structopt::StructOpt; use parity_scale_codec::{Codec, Encode, Decode}; use std::{str::FromStr, fmt::Display}; @@ -51,6 +54,10 @@ pub struct SignTransactionCmd { #[allow(missing_docs)] #[structopt(flatten)] pub shared_params: SharedParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub crypto_scheme: CryptoSchemeFlag, } impl SignTransactionCmd { @@ -67,7 +74,7 @@ impl SignTransactionCmd { let pass = self.keystore_params.read_password()?; with_crypto_scheme!( - self.shared_params.scheme, + self.crypto_scheme.scheme, print_ext(&self.suri, &pass, call, nonce) ) } diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs index 4f892438909f7..486b1d1361a9d 100644 --- a/client/cli/src/commands/tests.rs +++ b/client/cli/src/commands/tests.rs @@ -15,17 +15,11 @@ // along with Substrate. If not, see . use super::*; -use substrate_test_runtime::Runtime; use tempfile::Builder; use std::io::Read; use crate::commands::inspect::InspectCmd; use crate::Error; -fn new_test_ext() -> sp_io::TestExternalities { - let t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - sp_io::TestExternalities::new(t) -} - #[test] fn generate() { let generate = GenerateCmd::from_iter(&["generate", "--password", "12345"]); @@ -74,28 +68,3 @@ fn vanity() { let vanity = VanityCmd::from_iter(&["vanity", "--number", "1", "--pattern", "j"]); assert!(vanity.run().is_ok()); } - -#[test] -fn transfer() { - let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; - let words = "remember fiber forum demise paper uniform squirrel feel access exclude casual effort"; - - let transfer = TransferCmd::from_iter(&["transfer", - "--from", seed, - "--to", "0xa2bc899a8a3b16a284a8cefcbc2dc48a687cd674e89b434fbbdb06f400979744", - "--amount", "5000", - "--index", "1", - "--password", "12345", - ]); - - new_test_ext().execute_with(|| { - assert!(matches!(transfer.run::(), Ok(()))); - let transfer = TransferCmd::from_iter(&["transfer", - "--from", words, - "--to", "0xa2bc899a8a3b16a284a8cefcbc2dc48a687cd674e89b434fbbdb06f400979744", - "--amount", "5000", - "--index", "1", - ]); - assert!(matches!(transfer.run::(), Err(Error::Input(_)))) - }); -} \ No newline at end of file diff --git a/client/cli/src/commands/transfer.rs b/client/cli/src/commands/transfer.rs deleted file mode 100644 index 66092cbceaf98..0000000000000 --- a/client/cli/src/commands/transfer.rs +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -//! Implementation of the `transfer` subcommand - -use crate::{ - error, create_extrinsic_for, with_crypto_scheme, - pair_from_suri, decode_hex, CliConfiguration, KeystoreParams, -}; -use super::SharedParams; -use structopt::StructOpt; -use std::{str::FromStr, fmt::Display}; -use parity_scale_codec::Encode; -use sp_runtime::MultiSigner; -use std::convert::TryFrom; -use sp_core::crypto::Ss58Codec; -use cli_utils::{AddressFor, IndexFor, BalanceFor, BalancesCall, AccountIdFor, RuntimeAdapter}; - -/// The `transfer` command -#[derive(Debug, StructOpt, Clone)] -#[structopt( - name = "transfer", - about = "Author and sign a Node pallet_balances::Transfer transaction with a given (secret) key" -)] -pub struct TransferCmd { - /// The number of units to transfer. - #[structopt(long)] - amount: String, - - /// The signing secret key URI. - #[structopt(long)] - from: String, - - /// The signing account's transaction index. - #[structopt(long)] - index: String, - - /// The destination account public key URI. - #[structopt(long)] - to: String, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub keystore_params: KeystoreParams, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, -} - - -impl TransferCmd { - /// Run the command - pub fn run(self) -> error::Result<()> - where - RA: RuntimeAdapter, - AccountIdFor: for<'a> TryFrom<&'a [u8], Error = ()> + Ss58Codec, - AddressFor: From>, - as FromStr>::Err: Display, - as FromStr>::Err: Display, - { - let password = self.keystore_params.read_password()?; - let nonce = IndexFor::::from_str(&self.index).map_err(|e| format!("{}", e))?; - let to = if let Ok(data_vec) = decode_hex(&self.to) { - AccountIdFor::::try_from(&data_vec) - .expect("Invalid hex length for account ID; should be 32 bytes") - } else { - AccountIdFor::::from_ss58check(&self.to).ok() - .expect("Invalid SS58-check address given for account ID.") - }; - let amount = BalanceFor::::from_str(&self.amount).map_err(|e| format!("{}", e))?; - - with_crypto_scheme!( - self.shared_params.scheme, - print_ext( - &self.from, - &password, - to.into(), - nonce, - amount - ) - ) - } -} - -impl CliConfiguration for TransferCmd { - fn shared_params(&self) -> &SharedParams { - &self.shared_params - } - - fn keystore_params(&self) -> Option<&KeystoreParams> { - Some(&self.keystore_params) - } -} - -fn print_ext( - uri: &str, - pass: &str, - to: AddressFor, - nonce: IndexFor, - amount: BalanceFor, -) -> error::Result<()> - where - Pair: sp_core::Pair, - Pair::Public: Into, - Pair::Signature: Encode, - RA: RuntimeAdapter, - BalancesCall: Encode, -{ - let signer = pair_from_suri::(uri, pass); - let call = BalancesCall::transfer(to, amount); - let extrinsic = create_extrinsic_for::(call, nonce, signer)?; - println!("0x{}", hex::encode(Encode::encode(&extrinsic))); - Ok(()) -} diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 4d775609705a9..94e65a7da435c 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -18,16 +18,14 @@ use std::{io::Read, path::PathBuf}; use sp_core::{ Pair, hexdisplay::HexDisplay, - crypto::{Ss58Codec, Ss58AddressFormat, AccountId32}, + crypto::{Ss58Codec, Ss58AddressFormat}, }; -use sp_runtime::{ - traits::IdentifyAccount, MultiSigner, - generic::{UncheckedExtrinsic, SignedPayload}, -}; -use crate::{arg_enums::OutputType, error::{self, Error}}; -use parity_scale_codec::Encode; +use sp_runtime::{MultiSigner, traits::IdentifyAccount, AccountId32}; +use crate::{OutputType, error::{self, Error}}; use serde_json::json; use cli_utils::{IndexFor, RuntimeAdapter}; +use sp_runtime::generic::{UncheckedExtrinsic, SignedPayload}; +use parity_scale_codec::Encode; /// Public key type for Runtime pub type PublicFor

=

::Public; @@ -52,27 +50,6 @@ pub fn read_uri(uri: Option) -> error::Result { Ok(uri) } -/// Allows for calling $method with appropriate crypto impl. -#[macro_export] -macro_rules! with_crypto_scheme { - ($scheme:expr, $method:ident($($params:expr),*)) => { - with_crypto_scheme!($scheme, $method<>($($params),*)) - }; - ($scheme:expr, $method:ident<$($generics:ident),*>($($params:expr),*)) => { - match $scheme { - $crate::arg_enums::CryptoScheme::Ecdsa => { - $method::($($params),*) - } - $crate::arg_enums::CryptoScheme::Sr25519 => { - $method::($($params),*) - } - $crate::arg_enums::CryptoScheme::Ed25519 => { - $method::($($params),*) - } - } - }; -} - /// print formatted pair from uri pub fn print_from_uri( uri: &str, @@ -223,12 +200,34 @@ pub fn read_message(msg: Option, should_decode: bool) -> Result, Ok(message) } + +/// Allows for calling $method with appropriate crypto impl. +#[macro_export] +macro_rules! with_crypto_scheme { + ($scheme:expr, $method:ident($($params:expr),*)) => { + with_crypto_scheme!($scheme, $method<>($($params),*)) + }; + ($scheme:expr, $method:ident<$($generics:ident),*>($($params:expr),*)) => { + match $scheme { + $crate::CryptoScheme::Ecdsa => { + $method::($($params),*) + } + $crate::CryptoScheme::Sr25519 => { + $method::($($params),*) + } + $crate::CryptoScheme::Ed25519 => { + $method::($($params),*) + } + } + }; +} + /// create an extrinsic for the runtime. pub fn create_extrinsic_for( call: Call, nonce: IndexFor, signer: Pair, -) -> Result, Error> +) -> Result, &'static str> where Call: Encode, Pair: sp_core::Pair, @@ -238,7 +237,7 @@ pub fn create_extrinsic_for( { let extra = RA::build_extra(nonce); let payload = SignedPayload::new(call, extra) - .map_err(|_| Error::Other("Transaction validity error".into()))?; + .map_err(|_| "Transaction validity error")?; let signature = payload.using_encoded(|payload| signer.sign(payload)); let signer = signer.public().into().into_account(); diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index df0406bd27879..54c2fb466b02d 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -16,7 +16,10 @@ //! implementation of the `vanity` subcommand -use crate::{error, format_seed, SharedParams, print_from_uri, with_crypto_scheme, CliConfiguration}; +use crate::{ + error, format_seed, SharedParams, print_from_uri, CliConfiguration, + with_crypto_scheme, CryptoSchemeFlag, NetworkSchemeFlag, OutputTypeFlag, +}; use sp_core::crypto::Ss58Codec; use structopt::StructOpt; use rand::{rngs::OsRng, RngCore}; @@ -40,20 +43,32 @@ pub struct VanityCmd { #[allow(missing_docs)] #[structopt(flatten)] pub shared_params: SharedParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub network_scheme: NetworkSchemeFlag, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub output_scheme: OutputTypeFlag, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub crypto_scheme: CryptoSchemeFlag, } impl VanityCmd { /// Run the command pub fn run(self) -> error::Result<()> { let desired: String = self.pattern.unwrap_or_default(); - let formated_seed = with_crypto_scheme!(self.shared_params.scheme, generate_key(&desired))?; + let formated_seed = with_crypto_scheme!(self.crypto_scheme.scheme, generate_key(&desired))?; with_crypto_scheme!( - self.shared_params.scheme, + self.crypto_scheme.scheme, print_from_uri( &formated_seed, None, - self.shared_params.network, - self.shared_params.output_type + self.network_scheme.network, + self.output_scheme.output_type ) ); Ok(()) diff --git a/client/cli/src/commands/verify.rs b/client/cli/src/commands/verify.rs index 38cb93c8aa157..513276b88dab8 100644 --- a/client/cli/src/commands/verify.rs +++ b/client/cli/src/commands/verify.rs @@ -18,7 +18,7 @@ use crate::{ read_message, decode_hex, read_uri, CliConfiguration, - error, SharedParams, with_crypto_scheme, + error, SharedParams, with_crypto_scheme, CryptoSchemeFlag, }; use sp_core::{Public, crypto::Ss58Codec}; use structopt::StructOpt; @@ -52,6 +52,10 @@ pub struct VerifyCmd { #[allow(missing_docs)] #[structopt(flatten)] pub shared_params: SharedParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub crypto_scheme: CryptoSchemeFlag, } impl VerifyCmd { @@ -67,7 +71,7 @@ impl VerifyCmd { }; with_crypto_scheme!( - self.shared_params.scheme, + self.crypto_scheme.scheme, verify(sig_data, message, uri) ) } diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index e723573bc2bdd..2a0fa7f776f69 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -19,7 +19,7 @@ #![warn(missing_docs)] #![warn(unused_extern_crates)] -mod arg_enums; +pub mod arg_enums; mod commands; mod config; mod error; diff --git a/client/cli/src/params/shared_params.rs b/client/cli/src/params/shared_params.rs index 98a9003ae669e..88bdcceae60bd 100644 --- a/client/cli/src/params/shared_params.rs +++ b/client/cli/src/params/shared_params.rs @@ -14,10 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -use std::{path::PathBuf, convert::TryFrom}; -use sp_core::crypto::Ss58AddressFormat; -use crate::arg_enums::{CryptoScheme, OutputType}; +use std::path::PathBuf; use structopt::StructOpt; +use sp_core::crypto::Ss58AddressFormat; +use crate::arg_enums::{OutputType, CryptoScheme}; +use std::convert::TryFrom; /// Shared parameters used by all `CoreParams`. #[derive(Debug, StructOpt, Clone)] @@ -45,18 +46,25 @@ pub struct SharedParams { /// By default, all targets log `info`. The global log level can be set with -l. #[structopt(short = "l", long = "log", value_name = "LOG_PATTERN")] pub log: Option, +} - /// network address format +/// Optional flag for specifying crypto algorithm +#[derive(Debug, StructOpt, Clone)] +pub struct CryptoSchemeFlag { + /// cryptography scheme #[structopt( long, - value_name = "NETWORK", - possible_values = &Ss58AddressFormat::all_names()[..], - parse(try_from_str = Ss58AddressFormat::try_from), + value_name = "SCHEME", + possible_values = &CryptoScheme::variants(), case_insensitive = true, - default_value = "polkadot" + default_value = "Sr25519" )] - pub network: Ss58AddressFormat, + pub scheme: CryptoScheme, +} +/// Optional flag for specifying output type +#[derive(Debug, StructOpt, Clone)] +pub struct OutputTypeFlag { /// output format #[structopt( long, @@ -66,16 +74,21 @@ pub struct SharedParams { default_value = "Text" )] pub output_type: OutputType, +} - /// cryptography scheme +/// Optional flag for specifying network scheme +#[derive(Debug, StructOpt, Clone)] +pub struct NetworkSchemeFlag { + /// network address format #[structopt( long, - value_name = "SCHEME", - possible_values = &CryptoScheme::variants(), + value_name = "NETWORK", + possible_values = &Ss58AddressFormat::all_names()[..], + parse(try_from_str = Ss58AddressFormat::try_from), case_insensitive = true, - default_value = "Sr25519" + default_value = "polkadot" )] - pub scheme: CryptoScheme, + pub network: Ss58AddressFormat, } impl SharedParams { diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index 1397c55bcc8b4..2382ffc3d28b7 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -218,7 +218,7 @@ impl Runner { Subcommand::Sign(cmd) => cmd.run(), Subcommand::Verify(cmd) => cmd.run(), Subcommand::Vanity(cmd) => cmd.run(), - Subcommand::Transfer(cmd) => cmd.run::(), + // Subcommand::Transfer(cmd) => cmd.run::(), Subcommand::SignTransaction(cmd) => cmd.run::(), Subcommand::Insert(cmd) => cmd.run::(), } diff --git a/utils/frame/pallet-balances-cli/Cargo.toml b/utils/frame/pallet-balances-cli/Cargo.toml new file mode 100644 index 0000000000000..b10e41bbcd543 --- /dev/null +++ b/utils/frame/pallet-balances-cli/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "pallet-balances-cli" +version = "2.0.0-dev" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +sp-core = { version = "2.0.0-dev", path = "../../../primitives/core" } +sc-cli = { version = "0.8.0-dev", path = "../../../client/cli" } +sp-runtime = { version = "2.0.0-dev", path = "../../../primitives/runtime" } +structopt = "0.3.8" +codec = { version = "1.3.0", package = "parity-scale-codec" } +cli-utils = { path = "../../cli-utils", version = "2.0.0-dev" } +hex = "0.4.2" + +[dev-dependencies] +sp-io = { version = "2.0.0-dev", path = "../../../primitives/io" } +frame-system = { version = "2.0.0-alpha.4", path = "../../../frame/system" } +substrate-test-runtime = { version = "2.0.0-dev", features = ["indices-lookup"], path = "../../../test-utils/runtime" } diff --git a/utils/frame/pallet-balances-cli/src/lib.rs b/utils/frame/pallet-balances-cli/src/lib.rs new file mode 100644 index 0000000000000..ea06063eb243d --- /dev/null +++ b/utils/frame/pallet-balances-cli/src/lib.rs @@ -0,0 +1,167 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Implementation of the `transfer` cli subcommand for nodes that use the pallet-balances crate. + +use sc_cli::{ + Error, SharedParams, pair_from_suri, create_extrinsic_for, with_crypto_scheme, + CryptoSchemeFlag, decode_hex, CliConfiguration, KeystoreParams, +}; +use structopt::StructOpt; +use std::{str::FromStr, fmt::Display}; +use codec::Encode; +use sp_runtime::MultiSigner; +use std::convert::TryFrom; +use sp_core::crypto::Ss58Codec; +use cli_utils::{AddressFor, IndexFor, BalanceFor, BalancesCall, AccountIdFor, RuntimeAdapter}; + +/// The `transfer` command +#[derive(Debug, StructOpt, Clone)] +#[structopt( + name = "transfer", + about = "Author and sign a Node pallet_balances::Transfer transaction with a given (secret) key" +)] +pub struct TransferCmd { + /// The number of units to transfer. + #[structopt(long)] + amount: String, + + /// The signing secret key URI. + #[structopt(long)] + from: String, + + /// The signing account's transaction index. + #[structopt(long)] + index: String, + + /// The destination account public key URI. + #[structopt(long)] + to: String, + + #[allow(missing_docs)] + #[structopt(flatten)] + keystore_params: KeystoreParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + shared_params: SharedParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + crypto_scheme: CryptoSchemeFlag, +} + + +impl TransferCmd { + /// Run the command + pub fn run(self) -> Result<(), Error> + where + RA: RuntimeAdapter, + AccountIdFor: for<'a> TryFrom<&'a [u8], Error = ()> + Ss58Codec, + AddressFor: From>, + as FromStr>::Err: Display, + as FromStr>::Err: Display, + { + let password = self.keystore_params.read_password()?; + let nonce = IndexFor::::from_str(&self.index).map_err(|e| format!("{}", e))?; + let to = if let Ok(data_vec) = decode_hex(&self.to) { + AccountIdFor::::try_from(&data_vec) + .expect("Invalid hex length for account ID; should be 32 bytes") + } else { + AccountIdFor::::from_ss58check(&self.to).ok() + .expect("Invalid SS58-check address given for account ID.") + }; + let amount = BalanceFor::::from_str(&self.amount).map_err(|e| format!("{}", e))?; + + with_crypto_scheme!( + self.crypto_scheme.scheme, + print_ext( + &self.from, + &password, + to.into(), + nonce, + amount + ) + ) + } +} + +impl CliConfiguration for TransferCmd { + fn shared_params(&self) -> &SharedParams { + &self.shared_params + } + + fn keystore_params(&self) -> Option<&KeystoreParams> { + Some(&self.keystore_params) + } +} + +fn print_ext( + uri: &str, + pass: &str, + to: AddressFor, + nonce: IndexFor, + amount: BalanceFor, +) -> Result<(), Error> + where + Pair: sp_core::Pair, + Pair::Public: Into, + Pair::Signature: Encode, + RA: RuntimeAdapter, + BalancesCall: Encode, +{ + let signer = pair_from_suri::(uri, pass); + let call = BalancesCall::transfer(to, amount); + let extrinsic = create_extrinsic_for::(call, nonce, signer)?; + println!("0x{}", hex::encode(Encode::encode(&extrinsic))); + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + use substrate_test_runtime::Runtime; + + fn new_test_ext() -> sp_io::TestExternalities { + let t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + sp_io::TestExternalities::new(t) + } + + #[test] + fn transfer() { + let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; + let words = "remember fiber forum demise paper uniform squirrel feel access exclude casual effort"; + + let transfer = TransferCmd::from_iter(&["transfer", + "--from", seed, + "--to", "0xa2bc899a8a3b16a284a8cefcbc2dc48a687cd674e89b434fbbdb06f400979744", + "--amount", "5000", + "--index", "1", + "--password", "12345", + ]); + + new_test_ext().execute_with(|| { + assert!(matches!(transfer.run::(), Ok(()))); + let transfer = TransferCmd::from_iter(&["transfer", + "--from", words, + "--to", "0xa2bc899a8a3b16a284a8cefcbc2dc48a687cd674e89b434fbbdb06f400979744", + "--amount", "5000", + "--index", "1", + ]); + assert!(matches!(transfer.run::(), Err(Error::Input(_)))) + }); + } +} \ No newline at end of file From 5e351b94aaf65c2c31e3b95a1c3f03ccc04877b4 Mon Sep 17 00:00:00 2001 From: Seun Date: Fri, 8 May 2020 10:38:42 +0100 Subject: [PATCH 25/77] wip --- Cargo.lock | 602 ++++++++++++++++++++-------------------- bin/node/cli/Cargo.toml | 4 +- 2 files changed, 309 insertions(+), 297 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index de538433002a7..126ec4e939d6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -126,15 +126,15 @@ dependencies = [ [[package]] name = "arbitrary" -version = "0.4.1" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75153c95fdedd7db9732dfbfc3702324a1627eec91ba56e37cd0ac78314ab2ed" +checksum = "c5eb01a9ab8a3369f2f7632b9461c34f5920bd454774bab5b9fc6744f21d6143" [[package]] name = "arc-swap" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d663a8e9a99154b5fb793032533f6328da35e23aac63d5c152279aa8ba356825" +checksum = "b585a98a234c46fc563103e9278c9391fde1f4e6850334da895d27edb9580f62" [[package]] name = "arrayref" @@ -172,8 +172,8 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d0864d84b8e07b145449be9a8537db86bf9de5ce03b913214694643b4743502" dependencies = [ - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -280,9 +280,9 @@ dependencies = [ [[package]] name = "backtrace-sys" -version = "0.1.35" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7de8aba10a69c8e8d7622c5710229485ec32e9d55fdad160ea559c086fdcd118" +checksum = "18fbebbe1c9d1f383a9cc7e8ccdb471b91c8d024ee9c2ca5b5346121fe8b4399" dependencies = [ "cc", "libc", @@ -302,9 +302,9 @@ checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" [[package]] name = "base64" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d5ca2cd0adc3f48f9e9ea5a6bbdf9ccc0bfade884847e484d452414c7ccffb3" +checksum = "53d1ccbaf7d9ec9537465a97bf19edc1a4e158ecb49fc16178202238c569cc42" [[package]] name = "bincode" @@ -333,7 +333,7 @@ dependencies = [ "log", "peeking_take_while", "proc-macro2", - "quote 1.0.3", + "quote 1.0.4", "regex", "rustc-hash", "shlex", @@ -467,9 +467,9 @@ dependencies = [ [[package]] name = "bs58" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b170cd256a3f9fa6b9edae3e44a7dfdfc77e8124dbc3e2612d75f9c3e2396dae" +checksum = "476e9cd489f9e121e02ffa6014a8ef220ecb15c05ed23fc34cca13925dc283fb" [[package]] name = "bstr" @@ -568,9 +568,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.50" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd" +checksum = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d" dependencies = [ "jobserver", ] @@ -773,7 +773,7 @@ dependencies = [ "log", "regalloc", "serde", - "smallvec 1.3.0", + "smallvec 1.4.0", "target-lexicon", "thiserror", ] @@ -811,7 +811,7 @@ checksum = "e45f82e3446dd1ebb8c2c2f6a6b0e6cd6cd52965c7e5f7b1b35e9a9ace31ccde" dependencies = [ "cranelift-codegen", "log", - "smallvec 1.3.0", + "smallvec 1.4.0", "target-lexicon", ] @@ -838,7 +838,7 @@ dependencies = [ "log", "serde", "thiserror", - "wasmparser", + "wasmparser 0.51.4", ] [[package]] @@ -861,7 +861,7 @@ dependencies = [ "clap", "criterion-plot 0.3.1", "csv", - "itertools", + "itertools 0.8.2", "lazy_static", "libc", "num-traits 0.2.11", @@ -879,16 +879,16 @@ dependencies = [ [[package]] name = "criterion" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fc755679c12bda8e5523a71e4d654b6bf2e14bd838dfc48cde6559a05caf7d1" +checksum = "63f696897c88b57f4ffe3c69d8e1a0613c7d0e6c4833363c8560fbde9c47b966" dependencies = [ "atty", "cast", "clap", - "criterion-plot 0.4.1", + "criterion-plot 0.4.2", "csv", - "itertools", + "itertools 0.9.0", "lazy_static", "num-traits 0.2.11", "oorandom", @@ -910,17 +910,17 @@ checksum = "76f9212ddf2f4a9eb2d401635190600656a1f88a932ef53d06e7fa4c7e02fb8e" dependencies = [ "byteorder 1.3.4", "cast", - "itertools", + "itertools 0.8.2", ] [[package]] name = "criterion-plot" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01e15e0ea58e8234f96146b1f91fa9d0e4dd7a38da93ff7a75d42c0b9d3a545" +checksum = "ddeaf7989f00f2e1d871a26a110f3ed713632feac17f65f03ca938c542618b60" dependencies = [ "cast", - "itertools", + "itertools 0.9.0", ] [[package]] @@ -1029,12 +1029,12 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47c5e5ac752e18207b12e16b10631ae5f7f68f8805f335f9b817ead83d9ffce1" +checksum = "cf6b25ee9ac1995c54d7adb2eff8cfffb7260bc774fb63c601ec65467f43cd9d" dependencies = [ - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -1083,8 +1083,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2323f3f47db9a0e77ce7a300605d8d2098597fc451ed1a97bb1f6411bb550a7" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -1171,22 +1171,22 @@ dependencies = [ [[package]] name = "enumflags2" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a80e524ebf194285b57e5e7944018721c7fffc673253f5183f7accd88a2a3b0c" +checksum = "83c8d82922337cd23a15f88b70d8e4ef5f11da38dd7cdb55e84dd5de99695da0" dependencies = [ "enumflags2_derive", ] [[package]] name = "enumflags2_derive" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ed9afacaea0301eefb738c9deea725e6d53938004597cdc518a8cf9a7aa2f03" +checksum = "946ee94e3dbf58fdd324f9ce245c7b238d46a66f00e86a020b71996349e46cce" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -1323,9 +1323,9 @@ dependencies = [ [[package]] name = "failure" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8529c2421efa3066a5cbd8063d2244603824daccb6936b079010bb2aa89464b" +checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" dependencies = [ "backtrace", "failure_derive", @@ -1333,13 +1333,13 @@ dependencies = [ [[package]] name = "failure_derive" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "030a733c8287d6213886dd487564ff5c8f6aae10278b3588ed177f9d18f8d231" +checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", "synstructure", ] @@ -1376,9 +1376,9 @@ dependencies = [ [[package]] name = "finality-grandpa" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab32971efbe776e46bfbc34d5b662d8e1de51fd14e26a2eba522c0f3470fc0f" +checksum = "1f4682570188cd105606e621b9992e580f717c15f8cd1b7d106b59f1c6e54680" dependencies = [ "either", "futures 0.3.4", @@ -1392,9 +1392,9 @@ dependencies = [ [[package]] name = "fixed-hash" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32529fc42e86ec06e5047092082aab9ad459b070c5d2a76b14f4f5ce70bf2e84" +checksum = "11498d382790b7a8f2fd211780bec78619bba81cdad3a283997c0c41f836759c" dependencies = [ "byteorder 1.3.4", "rand 0.7.3", @@ -1528,8 +1528,8 @@ version = "2.0.0-dev" dependencies = [ "frame-support-procedural-tools", "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -1539,8 +1539,8 @@ dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -1548,8 +1548,8 @@ name = "frame-support-procedural-tools-derive" version = "2.0.0-dev" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -1764,8 +1764,8 @@ checksum = "9a5081aa3de1f7542a794a397cde100ed903b0630152d0973479018fd85423a7" dependencies = [ "proc-macro-hack", "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -1899,7 +1899,7 @@ dependencies = [ "byteorder 1.3.4", "fallible-iterator", "indexmap", - "smallvec 1.3.0", + "smallvec 1.4.0", "stable_deref_trait", ] @@ -1972,9 +1972,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "377038bf3c89d18d6ca1431e7a5027194fbd724ca10592b9487ede5e8e144f42" +checksum = "79b7246d7e4b979c03fa093da39cfb3617a96bbeee6310af63991668d7e843ff" dependencies = [ "bytes 0.5.4", "fnv", @@ -1985,7 +1985,7 @@ dependencies = [ "indexmap", "log", "slab", - "tokio 0.2.18", + "tokio 0.2.20", "tokio-util", ] @@ -2035,9 +2035,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.10" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e" +checksum = "61565ff7aaace3525556587bd2dc31d4a07071957be715e63ce7b1eccf51a8f4" dependencies = [ "libc", ] @@ -2090,9 +2090,9 @@ dependencies = [ [[package]] name = "honggfuzz" -version = "0.5.47" +version = "0.5.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3de2c3273ef7735df1c5a72128ca85b1d20105b9aac643cdfd7a6e581311150" +checksum = "2a4ae2efc127fb46f7d28bf568e8338d5aaf6e465adb7b9f401806c94f36b073" dependencies = [ "arbitrary", "lazy_static", @@ -2190,15 +2190,15 @@ dependencies = [ [[package]] name = "hyper" -version = "0.13.4" +version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed6081100e960d9d74734659ffc9cc91daf1c0fc7aceb8eaa94ee1a3f5046f2e" +checksum = "96816e1d921eca64d208a85aab4f7798455a8e34229ee5a88c935bdee1b78b14" dependencies = [ "bytes 0.5.4", "futures-channel", "futures-core", "futures-util", - "h2 0.2.4", + "h2 0.2.5", "http 0.2.1", "http-body 0.3.1", "httparse", @@ -2207,7 +2207,7 @@ dependencies = [ "net2", "pin-project", "time", - "tokio 0.2.18", + "tokio 0.2.20", "tower-service", "want 0.3.0", ] @@ -2221,11 +2221,11 @@ dependencies = [ "bytes 0.5.4", "ct-logs", "futures-util", - "hyper 0.13.4", + "hyper 0.13.5", "log", "rustls", "rustls-native-certs", - "tokio 0.2.18", + "tokio 0.2.20", "tokio-rustls", "webpki", ] @@ -2281,9 +2281,9 @@ dependencies = [ [[package]] name = "impl-serde" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bbe9ea9b182f0fb1cabbd61f4ff9b7b7b9197955e95a7e4c27de5055eb29ff8" +checksum = "b47ca4d2b6931707a55fce5cf66aff80e2178c8b63bbb4ecb5695cbc870ddf6f" dependencies = [ "serde", ] @@ -2295,8 +2295,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef5550a42e3740a0e71f909d4c861056a284060af885ae7aa6242820f920d9d" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -2360,6 +2360,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "0.4.5" @@ -2377,9 +2386,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.37" +version = "0.3.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a27d435371a2fa5b6d2b028a74bbdb1234f308da363226a2854ca3ff8ba7055" +checksum = "fa5a448de267e7358beaf4a5d849518fe9a0c13fce7afd44b06e68550e5562a7" dependencies = [ "wasm-bindgen", ] @@ -2431,8 +2440,8 @@ checksum = "8609af8f63b626e8e211f52441fcdb6ec54f1a446606b10d5c89ae9bf8a20058" dependencies = [ "proc-macro-crate", "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -2535,7 +2544,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cad096c6849b2ef027fabe35c4aed356d0e3d3f586d0a8361e5e17f1e50a7ce5" dependencies = [ "parity-util-mem", - "smallvec 1.3.0", + "smallvec 1.4.0", ] [[package]] @@ -2565,7 +2574,7 @@ dependencies = [ "parking_lot 0.10.2", "regex", "rocksdb", - "smallvec 1.3.0", + "smallvec 1.4.0", ] [[package]] @@ -2671,7 +2680,7 @@ dependencies = [ "parity-multiaddr 0.8.0", "parking_lot 0.10.2", "pin-project", - "smallvec 1.3.0", + "smallvec 1.4.0", "wasm-timer", ] @@ -2702,7 +2711,7 @@ dependencies = [ "ring", "rw-stream-sink", "sha2", - "smallvec 1.3.0", + "smallvec 1.4.0", "thiserror", "unsigned-varint", "void", @@ -2715,8 +2724,8 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "329127858e4728db5ab60c33d5ae352a999325fdf190ed022ec7d3a4685ae2e6" dependencies = [ - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -2755,7 +2764,7 @@ dependencies = [ "prost", "prost-build", "rand 0.7.3", - "smallvec 1.3.0", + "smallvec 1.4.0", ] [[package]] @@ -2778,7 +2787,7 @@ dependencies = [ "prost-build", "rand 0.7.3", "sha2", - "smallvec 1.3.0", + "smallvec 1.4.0", "unsigned-varint", "wasm-timer", ] @@ -2795,7 +2804,7 @@ dependencies = [ "log", "prost", "prost-build", - "smallvec 1.3.0", + "smallvec 1.4.0", "wasm-timer", ] @@ -2819,7 +2828,7 @@ dependencies = [ "prost-build", "rand 0.7.3", "sha2", - "smallvec 1.3.0", + "smallvec 1.4.0", "uint", "unsigned-varint", "void", @@ -2843,7 +2852,7 @@ dependencies = [ "log", "net2", "rand 0.7.3", - "smallvec 1.3.0", + "smallvec 1.4.0", "void", "wasm-timer", ] @@ -2972,7 +2981,7 @@ dependencies = [ "libp2p-core", "log", "rand 0.7.3", - "smallvec 1.3.0", + "smallvec 1.4.0", "void", "wasm-timer", ] @@ -3054,9 +3063,9 @@ dependencies = [ [[package]] name = "librocksdb-sys" -version = "6.6.4" +version = "6.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e3b727e2dd20ec2fb7ed93f23d9fd5328a0871185485ebdaff007b47d3e27e4" +checksum = "883213ae3d09bfc3d104aefe94b25ebb183b6f4d3a515b23b14817e1f4854005" dependencies = [ "bindgen", "cc", @@ -3094,9 +3103,9 @@ dependencies = [ [[package]] name = "linked-hash-map" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" +checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a" [[package]] name = "linked_hash_set" @@ -3259,9 +3268,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.6.21" +version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f" +checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" dependencies = [ "cfg-if", "fuchsia-zircon", @@ -3290,9 +3299,9 @@ dependencies = [ [[package]] name = "mio-uds" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" +checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" dependencies = [ "iovec", "libc", @@ -3348,7 +3357,7 @@ dependencies = [ "futures 0.3.4", "log", "pin-project", - "smallvec 1.3.0", + "smallvec 1.4.0", "unsigned-varint", ] @@ -3380,9 +3389,9 @@ dependencies = [ [[package]] name = "net2" -version = "0.2.33" +version = "0.2.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" +checksum = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7" dependencies = [ "cfg-if", "libc", @@ -3540,7 +3549,7 @@ dependencies = [ name = "node-executor" version = "2.0.0-dev" dependencies = [ - "criterion 0.3.1", + "criterion 0.3.2", "frame-benchmarking", "frame-support", "frame-system", @@ -3766,7 +3775,7 @@ dependencies = [ name = "node-testing" version = "2.0.0-dev" dependencies = [ - "criterion 0.3.1", + "criterion 0.3.2", "frame-support", "frame-system", "fs_extra", @@ -3903,9 +3912,9 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46203554f085ff89c235cd12f7075f3233af9b11ed7c9e16dfe2560d03313ce6" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" dependencies = [ "hermit-abi", "libc", @@ -3917,9 +3926,7 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5666bbb90bc4d1e5bdcb26c0afda1822d25928341e9384ab187a9b37ab69e36" dependencies = [ - "flate2", "target-lexicon", - "wasmparser", ] [[package]] @@ -3952,9 +3959,9 @@ dependencies = [ [[package]] name = "oorandom" -version = "11.1.0" +version = "11.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebcec7c9c2a95cacc7cd0ecb89d8a8454eca13906f6deb55258ffff0adeb9405" +checksum = "94af325bc33c7f60191be4e2c984d48aaa21e2854f473b85398344b60c9b6358" [[package]] name = "opaque-debug" @@ -4650,9 +4657,9 @@ version = "2.0.0-dev" dependencies = [ "proc-macro-crate", "proc-macro2", - "quote 1.0.3", + "quote 1.0.4", "sp-runtime", - "syn 1.0.17", + "syn 1.0.19", ] [[package]] @@ -4882,8 +4889,8 @@ checksum = "5a0ec292e92e8ec7c58e576adacc1e3f399c597c8f263c42f18420abe58e7245" dependencies = [ "proc-macro-crate", "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -4903,7 +4910,7 @@ dependencies = [ "parity-util-mem-derive", "parking_lot 0.10.2", "primitive-types", - "smallvec 1.3.0", + "smallvec 1.4.0", "winapi 0.3.8", ] @@ -4914,7 +4921,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f557c32c6d268a07c921471619c0295f5efad3a0e76d4f97a05c091a51d110b2" dependencies = [ "proc-macro2", - "syn 1.0.17", + "syn 1.0.19", "synstructure", ] @@ -4961,7 +4968,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" dependencies = [ "lock_api 0.3.4", - "parking_lot_core 0.7.1", + "parking_lot_core 0.7.2", ] [[package]] @@ -4994,23 +5001,23 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e136c1904604defe99ce5fd71a28d473fa60a12255d511aa78a9ddf11237aeb" +checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" dependencies = [ "cfg-if", "cloudabi", "libc", "redox_syscall", - "smallvec 1.3.0", + "smallvec 1.4.0", "winapi 0.3.8", ] [[package]] name = "paste" -version = "0.1.10" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab4fb1930692d1b6a9cfabdde3d06ea0a7d186518e2f4d67660d8970e2fa647a" +checksum = "0a229b1c58c692edcaa5b9b0948084f130f55d2dcc15b02fcc5340b2b4521476" dependencies = [ "paste-impl", "proc-macro-hack", @@ -5018,14 +5025,14 @@ dependencies = [ [[package]] name = "paste-impl" -version = "0.1.10" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62486e111e571b1e93b710b61e8f493c0013be39629b714cb166bdb06aa5a8a" +checksum = "2e0bf239e447e67ff6d16a8bb5e4d4bd2343acf5066061c0e8e06ac5ba8ca68c" dependencies = [ "proc-macro-hack", "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -5075,35 +5082,35 @@ dependencies = [ [[package]] name = "pin-project" -version = "0.4.9" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f6a7f5eee6292c559c793430c55c00aea9d3b3d1905e855806ca4d7253426a2" +checksum = "82c3bfbfb5bb42f99498c7234bbd768c220eb0cea6818259d0d18a1aa3d2595d" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "0.4.9" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8988430ce790d8682672117bc06dda364c0be32d3abd738234f19f3240bad99a" +checksum = "ccbf6449dcfb18562c015526b085b8df1aa3cdab180af8ec2ebd300a3bd28f63" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] name = "pin-project-lite" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "237844750cfbb86f67afe27eee600dfbbcb6188d734139b534cbfbf4f96792ae" +checksum = "f7505eeebd78492e0f6108f7171c4948dbb120ee8119d9d77d0afa5469bef67f" [[package]] name = "pin-utils" -version = "0.1.0-alpha.4" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" @@ -5125,9 +5132,9 @@ checksum = "feb3b2b1033b8a60b4da6ee470325f887758c95d5320f52f9ce0df055a55940e" [[package]] name = "plotters" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e3bb8da247d27ae212529352020f3e5ee16e83c0c258061d27b08ab92675eeb" +checksum = "f9b1d9ca091d370ea3a78d5619145d1b59426ab0c9eedbad2514a4cee08bf389" dependencies = [ "js-sys", "num-traits 0.2.11", @@ -5181,14 +5188,14 @@ dependencies = [ [[package]] name = "primitive-types" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5e4b9943a2da369aec5e96f7c10ebc74fcf434d39590d974b0a3460e6f67fbb" +checksum = "c55c21c64d0eaa4d7ed885d959ef2d62d9e488c27c0e02d9aa5ce6c877b7d5f8" dependencies = [ "fixed-hash", "impl-codec", "impl-rlp", - "impl-serde 0.3.0", + "impl-serde 0.3.1", "uint", ] @@ -5209,8 +5216,8 @@ checksum = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678" dependencies = [ "proc-macro-error-attr", "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", "version_check", ] @@ -5221,8 +5228,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", "syn-mid", "version_check", ] @@ -5241,9 +5248,9 @@ checksum = "8e946095f9d3ed29ec38de908c22f95d9ac008e424c7bcae54c75a79c527c694" [[package]] name = "proc-macro2" -version = "1.0.10" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3" +checksum = "8872cf6f48eee44265156c111456a700ab3483686b3f96df4cf5481c89157319" dependencies = [ "unicode-xid 0.2.0", ] @@ -5295,7 +5302,7 @@ checksum = "02b10678c913ecbd69350e8535c3aef91a8676c0773fc1d7b95cdd196d7f2f26" dependencies = [ "bytes 0.5.4", "heck", - "itertools", + "itertools 0.8.2", "log", "multimap", "petgraph", @@ -5312,10 +5319,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "537aa19b95acde10a12fec4301466386f757403de4cd4e5b4fa78fb5ecb18f72" dependencies = [ "anyhow", - "itertools", + "itertools 0.8.2", "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -5382,9 +5389,9 @@ checksum = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" [[package]] name = "quote" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" +checksum = "4c1f4b0efa5fc5e8ceb705136bfee52cfdb6a4e3509f770b478cd6ed434232a7" dependencies = [ "proc-macro2", ] @@ -5682,8 +5689,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "602eb59cda66fcb9aec25841fb76bc01d2b34282dcdd705028da297db6f3eec8" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -5694,14 +5701,14 @@ checksum = "b27b256b41986ac5141b37b8bbba85d314fbf546c182eb255af6720e07e4f804" dependencies = [ "log", "rustc-hash", - "smallvec 1.3.0", + "smallvec 1.4.0", ] [[package]] name = "regex" -version = "1.3.6" +version = "1.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6946991529684867e47d86474e3a6d0c0ab9b82d5821e314b1ede31fa3a4b3" +checksum = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692" dependencies = [ "aho-corasick", "memchr", @@ -5747,13 +5754,13 @@ dependencies = [ [[package]] name = "ring" -version = "0.16.12" +version = "0.16.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ba5a8ec64ee89a76c98c549af81ff14813df09c3e6dc4766c3856da48597a0c" +checksum = "703516ae74571f24b465b4a1431e81e2ad51336cb0ded733a55a1aa3eccac196" dependencies = [ "cc", - "lazy_static", "libc", + "once_cell 1.3.1", "spin", "untrusted", "web-sys", @@ -5866,8 +5873,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3bba175698996010c4f6dce5e7f173b6eb781fce25d2cfc45e27091ce0b79f6" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -5883,9 +5890,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "535622e6be132bccd223f4bb2b8ac8d53cda3c7a6394944d3b2b33fb974f9d76" +checksum = "ed3d612bc64430efeb3f7ee6ef26d590dce0c43249217bddc62112540c7941e1" [[package]] name = "safe-mix" @@ -6017,8 +6024,8 @@ version = "2.0.0-dev" dependencies = [ "proc-macro-crate", "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -6073,7 +6080,7 @@ dependencies = [ "substrate-prometheus-endpoint", "tempfile", "time", - "tokio 0.2.18", + "tokio 0.2.20", ] [[package]] @@ -6306,7 +6313,7 @@ dependencies = [ "substrate-test-runtime-client", "substrate-test-runtime-transaction-pool", "tempfile", - "tokio 0.2.18", + "tokio 0.2.20", ] [[package]] @@ -6490,7 +6497,7 @@ dependencies = [ "substrate-prometheus-endpoint", "substrate-test-runtime-client", "tempfile", - "tokio 0.2.18", + "tokio 0.2.20", ] [[package]] @@ -6653,7 +6660,7 @@ dependencies = [ "fnv", "futures 0.3.4", "futures-timer 3.0.2", - "hyper 0.13.4", + "hyper 0.13.5", "hyper-rustls", "log", "num_cpus", @@ -6673,7 +6680,7 @@ dependencies = [ "sp-utils", "substrate-test-runtime-client", "threadpool", - "tokio 0.2.18", + "tokio 0.2.20", ] [[package]] @@ -6928,7 +6935,7 @@ name = "sc-transaction-graph" version = "2.0.0-dev" dependencies = [ "assert_matches", - "criterion 0.3.1", + "criterion 0.3.2", "derive_more", "futures 0.3.4", "linked-hash-map", @@ -7038,8 +7045,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8584eea9b9ff42825b46faf46a8c24d2cff13ec152fa2a50df788b87c07ee28" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -7054,9 +7061,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "572dfa3a0785509e7a44b5b4bebcf94d41ba34e9ed9eb9df722545c3b3c4144a" +checksum = "3f331b9025654145cd425b9ded0caf8f5ae0df80d418b326e2dc1c3dc5eb0620" dependencies = [ "bitflags", "core-foundation", @@ -7067,9 +7074,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ddb15a5fec93b7021b8a9e96009c5d8d51c15673569f7c0f6b7204e5b7b404f" +checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405" dependencies = [ "core-foundation-sys", "libc", @@ -7134,15 +7141,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] name = "serde_json" -version = "1.0.51" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da07b57ee2623368351e9a0488bb0b261322a15a6e0ae53e243cbdc0f4208da9" +checksum = "a7894c8ed05b7a3a279aeb79025fdec1d3158080b75b98a08faf2806bb799edd" dependencies = [ "itoa", "ryu", @@ -7264,8 +7271,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a945ec7f7ce853e89ffa36be1e27dce9a43e82ff9093bf3461c30d5da74ed11b" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -7279,9 +7286,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05720e22615919e4734f6a99ceae50d00226c3c5aca406e102ebc33298214e0a" +checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" [[package]] name = "snow" @@ -7316,7 +7323,7 @@ dependencies = [ "log", "rand 0.7.3", "sha1", - "smallvec 1.3.0", + "smallvec 1.4.0", "static_assertions", "thiserror", ] @@ -7354,15 +7361,15 @@ dependencies = [ "blake2-rfc", "proc-macro-crate", "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] name = "sp-api-test" version = "2.0.0-dev" dependencies = [ - "criterion 0.3.1", + "criterion 0.3.2", "parity-scale-codec", "rustversion", "sc-block-builder", @@ -7403,7 +7410,7 @@ dependencies = [ name = "sp-arithmetic" version = "2.0.0-dev" dependencies = [ - "criterion 0.3.1", + "criterion 0.3.2", "integer-sqrt", "num-traits 0.2.11", "parity-scale-codec", @@ -7568,7 +7575,7 @@ dependencies = [ "hash256-std-hasher", "hex", "hex-literal", - "impl-serde 0.3.0", + "impl-serde 0.3.1", "lazy_static", "libsecp256k1", "log", @@ -7612,8 +7619,8 @@ name = "sp-debug-derive" version = "2.0.0-dev" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -7726,8 +7733,8 @@ version = "2.0.0-dev" dependencies = [ "proc-macro-crate", "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -7799,8 +7806,8 @@ dependencies = [ "Inflector", "proc-macro-crate", "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -8091,8 +8098,8 @@ dependencies = [ "heck", "proc-macro-error", "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -8112,8 +8119,8 @@ checksum = "0054a7df764039a6cd8592b9de84be4bec368ff081d203a7d5371cbfa8e65c81" dependencies = [ "heck", "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -8127,7 +8134,7 @@ dependencies = [ "hex", "hex-literal", "hyper 0.12.35", - "itertools", + "itertools 0.8.2", "jsonrpc-core-client", "libp2p", "node-primitives", @@ -8203,7 +8210,7 @@ dependencies = [ "sc-rpc-api", "serde", "sp-storage", - "tokio 0.2.18", + "tokio 0.2.20", ] [[package]] @@ -8236,10 +8243,10 @@ dependencies = [ "async-std", "derive_more", "futures-util", - "hyper 0.13.4", + "hyper 0.13.5", "log", "prometheus", - "tokio 0.2.18", + "tokio 0.2.20", ] [[package]] @@ -8352,7 +8359,7 @@ dependencies = [ "build-helper", "cargo_metadata", "fs2", - "itertools", + "itertools 0.8.2", "tempfile", "toml", "walkdir", @@ -8365,9 +8372,9 @@ version = "1.0.5" [[package]] name = "substrate-wasmtime" -version = "0.16.0-threadsafe.1" +version = "0.16.0-threadsafe.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b8f9558e3fe7018b9aeac2aba318664dd7b15e307de11b09f58240695688a96" +checksum = "7b40a6f3d5d3c00754e348863fead4f37763c32eedf950f5b23df87769882311" dependencies = [ "anyhow", "backtrace", @@ -8380,7 +8387,7 @@ dependencies = [ "substrate-wasmtime-profiling", "substrate-wasmtime-runtime", "target-lexicon", - "wasmparser", + "wasmparser 0.52.2", "wasmtime-environ", "wat", "winapi 0.3.8", @@ -8388,9 +8395,9 @@ dependencies = [ [[package]] name = "substrate-wasmtime-jit" -version = "0.16.0-threadsafe.1" +version = "0.16.0-threadsafe.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6b681b90a8d48b9535e4287c02e5aef6c72228ff45cbb60b4d195a762cc0770" +checksum = "09712de4f56a2c2912bee7763b0877d17d72cfb2237987d63ab78956907e7692" dependencies = [ "anyhow", "cfg-if", @@ -8407,7 +8414,7 @@ dependencies = [ "substrate-wasmtime-runtime", "target-lexicon", "thiserror", - "wasmparser", + "wasmparser 0.52.2", "wasmtime-debug", "wasmtime-environ", "winapi 0.3.8", @@ -8415,9 +8422,9 @@ dependencies = [ [[package]] name = "substrate-wasmtime-profiling" -version = "0.16.0-threadsafe.1" +version = "0.16.0-threadsafe.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7cb99b24e771de6c20b380fdf2d26ffc2c20701892c540830beb83af98bb3b7" +checksum = "31505dd221f001634a54ea51472bc0058bcbde9186eaf8dd31d0859638121385" dependencies = [ "anyhow", "cfg-if", @@ -8434,9 +8441,9 @@ dependencies = [ [[package]] name = "substrate-wasmtime-runtime" -version = "0.16.0-threadsafe.1" +version = "0.16.0-threadsafe.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaccd27cc466bd2904aa14f984f642083037bf5b47e251ccaf1009aed0a2a185" +checksum = "3708081f04d9216d4dee487abf94872065f930cf82e287bd0c5bdb57895460ba" dependencies = [ "backtrace", "cc", @@ -8477,12 +8484,12 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.17" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03" +checksum = "e8e5aa70697bb26ee62214ae3288465ecec0000f05182f039b477001f08f5ae7" dependencies = [ "proc-macro2", - "quote 1.0.3", + "quote 1.0.4", "unicode-xid 0.2.0", ] @@ -8493,8 +8500,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -8513,16 +8520,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", "unicode-xid 0.2.0", ] [[package]] name = "sysinfo" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a0338198966bde7feb14b011a33d404a62a6e03b843352c71512a2a002634b7" +checksum = "1cac193374347e7c263c5f547524f36ff8ec6702d56c8799c8331d26dffe8c1e" dependencies = [ "cfg-if", "doc-comment", @@ -8576,8 +8583,8 @@ checksum = "a605baa797821796a751f4a959e1206079b24a4b7e1ed302b7d785d81a9276c9" dependencies = [ "lazy_static", "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", "version_check", ] @@ -8592,22 +8599,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.15" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54b3d3d2ff68104100ab257bb6bb0cb26c901abe4bd4ba15961f3bf867924012" +checksum = "d12a1dae4add0f0d568eebc7bf142f145ba1aa2544cafb195c76f0f409091b60" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.15" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca972988113b7715266f91250ddb98070d033c62a011fa0fcc57434a649310dd" +checksum = "3f34e0c1caaa462fd840ec6b768946ea1e7842620d94fe29d5b847138f521269" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -8621,21 +8628,20 @@ dependencies = [ [[package]] name = "threadpool" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865" +checksum = "e8dae184447c15d5a6916d973c642aec485105a13cd238192a6927ae3e077d66" dependencies = [ "num_cpus", ] [[package]] name = "time" -version = "0.1.42" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "redox_syscall", "winapi 0.3.8", ] @@ -8675,9 +8681,9 @@ dependencies = [ [[package]] name = "tinytemplate" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a3c6667d3e65eb1bc3aed6fd14011c6cbc3a0665218ab7f5daf040b9ec371a" +checksum = "45e4bc5ac99433e0dcb8b9f309dd271a165ae37dde129b9e0ce1bfdd8bfe4891" dependencies = [ "serde", "serde_json", @@ -8709,9 +8715,9 @@ dependencies = [ [[package]] name = "tokio" -version = "0.2.18" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34ef16d072d2b6dc8b4a56c70f5c5ced1a37752116f8e7c1e80c659aa7cb6713" +checksum = "05c1d570eb1a36f0345a5ce9c6c6e665b70b73d11236912c0b477616aeec47b1" dependencies = [ "bytes 0.5.4", "fnv", @@ -8812,8 +8818,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -8843,7 +8849,7 @@ checksum = "4adb8b3e5f86b707f1b54e7c15b6de52617a823608ccda98a15d3a24222f265a" dependencies = [ "futures-core", "rustls", - "tokio 0.2.18", + "tokio 0.2.20", "webpki", ] @@ -8955,7 +8961,7 @@ dependencies = [ "futures-sink", "log", "pin-project-lite", - "tokio 0.2.18", + "tokio 0.2.20", ] [[package]] @@ -8990,8 +8996,8 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fbad39da2f9af1cae3016339ad7f2c7a9e870f12e8fd04c4fd7ef35b30c0d2b" dependencies = [ - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", ] [[package]] @@ -9035,7 +9041,7 @@ dependencies = [ "hashbrown 0.6.3", "log", "rustc-hex", - "smallvec 1.3.0", + "smallvec 1.4.0", ] [[package]] @@ -9065,9 +9071,9 @@ checksum = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" [[package]] name = "trybuild" -version = "1.0.25" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "459186ab1afd6d93bd23c2269125f4f7694f8771fe0e64434b4bdc212b94034d" +checksum = "744665442556a91933cee5e75b0371376eb03498c4d0bfbcebd2a9882b4fb5ef" dependencies = [ "glob 0.3.0", "lazy_static", @@ -9105,9 +9111,9 @@ checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" [[package]] name = "uint" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e75a4cdd7b87b28840dba13c483b9a88ee6bbf16ba5c951ee1ecfcf723078e0d" +checksum = "173cd16430c206dc1a430af8a89a0e9c076cf15cb42b4aedb10e8cc8fee73681" dependencies = [ "byteorder 1.3.4", "crunchy", @@ -9139,7 +9145,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5479532badd04e128284890390c1e876ef7a993d0570b3597ae43dfa1d59afa4" dependencies = [ - "smallvec 1.3.0", + "smallvec 1.4.0", ] [[package]] @@ -9180,9 +9186,9 @@ dependencies = [ [[package]] name = "untrusted" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60369ef7a31de49bcb3f6ca728d4ba7300d9a1658f94c727d4cab8c8d9f4aece" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" @@ -9214,9 +9220,9 @@ checksum = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" [[package]] name = "vec_map" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "version_check" @@ -9302,9 +9308,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasm-bindgen" -version = "0.2.60" +version = "0.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cc57ce05287f8376e998cbddfb4c8cb43b84a7ec55cf4551d7c00eef317a47f" +checksum = "e3c7d40d09cdbf0f4895ae58cf57d92e1e57a9dd8ed2e8390514b54a47cc5551" dependencies = [ "cfg-if", "serde", @@ -9314,24 +9320,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.60" +version = "0.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d967d37bf6c16cca2973ca3af071d0a2523392e4a594548155d89a678f4237cd" +checksum = "c3972e137ebf830900db522d6c8fd74d1900dcfc733462e9a12e942b00b4ac94" dependencies = [ "bumpalo", "lazy_static", "log", "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.10" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7add542ea1ac7fdaa9dc25e031a6af33b7d63376292bd24140c637d00d1c312a" +checksum = "8a369c5e1dfb7569e14d62af4da642a3cbc2f9a3652fe586e26ac22222aa4b04" dependencies = [ "cfg-if", "js-sys", @@ -9341,38 +9347,38 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.60" +version = "0.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bd151b63e1ea881bb742cd20e1d6127cef28399558f3b5d415289bc41eee3a4" +checksum = "2cd85aa2c579e8892442954685f0d801f9129de24fa2136b2c6a539c76b65776" dependencies = [ - "quote 1.0.3", + "quote 1.0.4", "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.60" +version = "0.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d68a5b36eef1be7868f668632863292e37739656a80fc4b9acec7b0bd35a4931" +checksum = "8eb197bd3a47553334907ffd2f16507b4f4f01bbec3ac921a7719e0decdfe72a" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.60" +version = "0.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf76fe7d25ac79748a37538b7daeed1c7a6867c92d3245c12c6222e4a20d639" +checksum = "a91c2916119c17a8e316507afaaa2dd94b47646048014bbdf6bef098c1bb58ad" [[package]] name = "wasm-bindgen-test" -version = "0.3.10" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648da3460c6d2aa04b715a936329e2e311180efe650b2127d6267f4193ccac14" +checksum = "fd8e9dad8040e378f0696b017570c6bc929aac373180e06b3d67ac5059c52da3" dependencies = [ "console_error_panic_hook", "js-sys", @@ -9384,12 +9390,12 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.10" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf2f86cd78a2aa7b1fb4bb6ed854eccb7f9263089c79542dca1576a1518a8467" +checksum = "c358c8d2507c1bae25efa069e62ea907aa28700b25c8c33dafb0b15ba4603627" dependencies = [ "proc-macro2", - "quote 1.0.3", + "quote 1.0.4", ] [[package]] @@ -9449,6 +9455,12 @@ version = "0.51.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" +[[package]] +name = "wasmparser" +version = "0.52.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "733954023c0b39602439e60a65126fd31b003196d3a1e8e4531b055165a79b31" + [[package]] name = "wasmtime-debug" version = "0.16.0" @@ -9461,7 +9473,7 @@ dependencies = [ "more-asserts", "target-lexicon", "thiserror", - "wasmparser", + "wasmparser 0.51.4", "wasmtime-environ", ] @@ -9472,7 +9484,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed54fd9d64dfeeee7c285fd126174a6b5e6d4efc7e5a1566fdb635e60ff6a74e" dependencies = [ "anyhow", - "base64 0.12.0", + "base64 0.12.1", "bincode", "cranelift-codegen", "cranelift-entity", @@ -9489,34 +9501,34 @@ dependencies = [ "sha2", "thiserror", "toml", - "wasmparser", + "wasmparser 0.51.4", "winapi 0.3.8", "zstd", ] [[package]] name = "wast" -version = "13.0.0" +version = "15.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b20abd8b4a26f7e0d4dd5e357e90a3d555ec190e94472c9b2b27c5b9777f9ae" +checksum = "a10df5277f68adee65bba117b40235f07a4cb3d59e5ec9aa86dbee180fb1bc04" dependencies = [ "leb128", ] [[package]] name = "wat" -version = "1.0.14" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51a615830ee3e7200b505c441fec09aac2f114deae69df52f215cb828ba112c4" +checksum = "526d28df6c047d9f9a92d4925b98afd8d8d95b1b3aa4f13eb1306f17d1da56c4" dependencies = [ "wast", ] [[package]] name = "web-sys" -version = "0.3.37" +version = "0.3.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d6f51648d8c56c366144378a33290049eafdd784071077f6fe37dae64c1c4cb" +checksum = "8bc359e5dd3b46cb9687a051d50a2fdd228e4ba7cf6fcf861a5365c3d671a642" dependencies = [ "js-sys", "wasm-bindgen", @@ -9589,9 +9601,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa515c5163a99cc82bab70fd3bfdd36d827be85de63737b40fcef2ce084a436e" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ "winapi 0.3.8", ] @@ -9677,8 +9689,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de251eec69fc7c1bc3923403d18ececb929380e016afe103da75f396704f8ca2" dependencies = [ "proc-macro2", - "quote 1.0.3", - "syn 1.0.17", + "quote 1.0.4", + "syn 1.0.19", "synstructure", ] diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index 2b14da011a16e..ea1a0fe84169b 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -96,7 +96,7 @@ node-executor = { version = "2.0.0-dev", path = "../executor" } # CLI-specific dependencies sc-cli = { version = "0.8.0-dev", optional = true, path = "../../../client/cli" } -pallet-balances-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/pallet-balances-cli" } +pallet-balances-cli = { version = "2.0.0-dev", path = "../../../utils/frame/pallet-balances-cli" } frame-benchmarking-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/benchmarking-cli" } node-inspect = { version = "0.8.0-dev", optional = true, path = "../inspect" } @@ -147,7 +147,7 @@ cli = [ "node-executor/wasmi-errno", "node-inspect", "sc-cli", - "pallet-balances-cli", +# "pallet-balances-cli", "frame-benchmarking-cli", "sc-service/db", "structopt", From de123f2cfb2332b8ed12955a3274fc607e7a4c77 Mon Sep 17 00:00:00 2001 From: Seun Date: Fri, 8 May 2020 14:18:39 +0100 Subject: [PATCH 26/77] Subcommand::run takes &self --- client/cli/src/commands/generate.rs | 6 +++--- client/cli/src/commands/generate_node_key.rs | 4 ++-- client/cli/src/commands/insert.rs | 10 ++++++---- client/cli/src/commands/inspect.rs | 8 ++++---- client/cli/src/commands/sign.rs | 8 ++++---- client/cli/src/commands/sign_transaction.rs | 4 ++-- client/cli/src/commands/utils.rs | 6 +++--- client/cli/src/commands/vanity.rs | 12 +++++++----- client/cli/src/commands/verify.rs | 8 ++++---- client/cli/src/runner.rs | 3 +-- 10 files changed, 36 insertions(+), 33 deletions(-) diff --git a/client/cli/src/commands/generate.rs b/client/cli/src/commands/generate.rs index b0ce432c62bed..5d52422ea0c43 100644 --- a/client/cli/src/commands/generate.rs +++ b/client/cli/src/commands/generate.rs @@ -56,7 +56,7 @@ pub struct GenerateCmd { impl GenerateCmd { /// Run the command - pub fn run(self) -> error::Result<()> { + pub fn run(&self) -> error::Result<()> { let words = match self.words { Some(words) => { MnemonicType::for_word_count(words) @@ -68,8 +68,8 @@ impl GenerateCmd { }; let mnemonic = Mnemonic::new(words, Language::English); let password = self.keystore_params.read_password()?; - let maybe_network = self.network_scheme.network; - let output = self.output_scheme.output_type; + let maybe_network = self.network_scheme.network.clone(); + let output = self.output_scheme.output_type.clone(); with_crypto_scheme!( self.crypto_scheme.scheme, diff --git a/client/cli/src/commands/generate_node_key.rs b/client/cli/src/commands/generate_node_key.rs index f168e81d7653b..b6db792bc6880 100644 --- a/client/cli/src/commands/generate_node_key.rs +++ b/client/cli/src/commands/generate_node_key.rs @@ -39,8 +39,8 @@ pub struct GenerateNodeKeyCmd { impl GenerateNodeKeyCmd { /// Run the command - pub fn run(self) -> error::Result<()> { - let file = self.file; + pub fn run(&self) -> error::Result<()> { + let file = &self.file; let keypair = libp2p_ed25519::Keypair::generate(); let secret = keypair.secret(); diff --git a/client/cli/src/commands/insert.rs b/client/cli/src/commands/insert.rs index 018f4f82adc6f..0fd04d5e9b5b4 100644 --- a/client/cli/src/commands/insert.rs +++ b/client/cli/src/commands/insert.rs @@ -64,12 +64,12 @@ pub struct InsertCmd { impl InsertCmd { /// Run the command - pub fn run(self) -> error::Result<()> + pub fn run(&self) -> error::Result<()> where RA: RuntimeAdapter, HashFor: DeserializeOwned + Serialize + Send + Sync, { - let suri = read_uri(self.suri)?; + let suri = read_uri(self.suri.as_ref())?; let password = self.keystore_params.read_password()?; let public = with_crypto_scheme!( @@ -77,8 +77,10 @@ impl InsertCmd { to_vec(&suri, &password) ); - let node_url = self.node_url.unwrap_or("http://localhost:9933".into()); - let key_type = self.key_type; + let node_url = self.node_url.as_ref() + .map(String::as_str) + .unwrap_or("http://localhost:9933"); + let key_type = &self.key_type; // Just checking let _key_type_id = KeyTypeId::try_from(key_type.as_str()) diff --git a/client/cli/src/commands/inspect.rs b/client/cli/src/commands/inspect.rs index 3074f121cc8a3..ef8a12aac4418 100644 --- a/client/cli/src/commands/inspect.rs +++ b/client/cli/src/commands/inspect.rs @@ -59,8 +59,8 @@ pub struct InspectCmd { impl InspectCmd { /// Run the command - pub fn run(self) -> error::Result<()> { - let uri = read_uri(self.uri)?; + pub fn run(&self) -> error::Result<()> { + let uri = read_uri(self.uri.as_ref())?; let pass = self.keystore_params.read_password().ok(); with_crypto_scheme!( @@ -68,8 +68,8 @@ impl InspectCmd { print_from_uri( &uri, pass.as_ref().map(String::as_str), - self.network_scheme.network, - self.output_scheme.output_type + self.network_scheme.network.clone(), + self.output_scheme.output_type.clone() ) ); diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs index 8681efa15a09b..1e2165b3f5319 100644 --- a/client/cli/src/commands/sign.rs +++ b/client/cli/src/commands/sign.rs @@ -57,13 +57,13 @@ pub struct SignCmd { impl SignCmd { /// Run the command - pub fn run(self) -> error::Result<()> { - let message = read_message(self.message, self.hex)?; - let suri = read_uri(self.suri)?; + pub fn run(&self) -> error::Result<()> { + let message = read_message(self.message.as_ref(), self.hex)?; + let suri = read_uri(self.suri.as_ref())?; let password = self.keystore_params.read_password()?; let signature = with_crypto_scheme!( - self.crypto_scheme.scheme, + self.crypto_scheme.scheme.clone(), sign(&suri, &password, message) )?; diff --git a/client/cli/src/commands/sign_transaction.rs b/client/cli/src/commands/sign_transaction.rs index 93e8ea297569a..36927c468cfdd 100644 --- a/client/cli/src/commands/sign_transaction.rs +++ b/client/cli/src/commands/sign_transaction.rs @@ -62,7 +62,7 @@ pub struct SignTransactionCmd { impl SignTransactionCmd { /// Run the command - pub fn run(self) -> error::Result<()> + pub fn run(&self) -> error::Result<()> where RA: RuntimeAdapter, as FromStr>::Err: Display, @@ -74,7 +74,7 @@ impl SignTransactionCmd { let pass = self.keystore_params.read_password()?; with_crypto_scheme!( - self.crypto_scheme.scheme, + self.crypto_scheme.scheme.clone(), print_ext(&self.suri, &pass, call, nonce) ) } diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 94e65a7da435c..1c400fa9f1ed1 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -33,7 +33,7 @@ pub type PublicFor

=

::Public; pub type SeedFor

=

::Seed; /// helper method to fetch uri from `Option` either as a file or read from stdin -pub fn read_uri(uri: Option) -> error::Result { +pub fn read_uri(uri: Option<&String>) -> error::Result { let uri = if let Some(uri) = uri { let file = PathBuf::from(uri.clone()); if file.is_file() { @@ -184,11 +184,11 @@ pub fn decode_hex>(message: T) -> Result, Error> { } /// checks if message is Some, otherwise reads message from stdin and optionally decodes hex -pub fn read_message(msg: Option, should_decode: bool) -> Result, Error> { +pub fn read_message(msg: Option<&String>, should_decode: bool) -> Result, Error> { let mut message = vec![]; match msg { Some(m) => { - message = decode_hex(&m)?; + message = decode_hex(m)?; }, None => { std::io::stdin().lock().read_to_end(&mut message)?; diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index 54c2fb466b02d..c706d548a1a21 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -59,16 +59,18 @@ pub struct VanityCmd { impl VanityCmd { /// Run the command - pub fn run(self) -> error::Result<()> { - let desired: String = self.pattern.unwrap_or_default(); - let formated_seed = with_crypto_scheme!(self.crypto_scheme.scheme, generate_key(&desired))?; + pub fn run(&self) -> error::Result<()> { + let desired: &str = self.pattern.as_ref() + .map(String::as_str) + .unwrap_or(""); + let formated_seed = with_crypto_scheme!(self.crypto_scheme.scheme, generate_key(desired))?; with_crypto_scheme!( self.crypto_scheme.scheme, print_from_uri( &formated_seed, None, - self.network_scheme.network, - self.output_scheme.output_type + self.network_scheme.network.clone(), + self.output_scheme.output_type.clone() ) ); Ok(()) diff --git a/client/cli/src/commands/verify.rs b/client/cli/src/commands/verify.rs index 513276b88dab8..a41b34b694174 100644 --- a/client/cli/src/commands/verify.rs +++ b/client/cli/src/commands/verify.rs @@ -60,10 +60,10 @@ pub struct VerifyCmd { impl VerifyCmd { /// Run the command - pub fn run(self) -> error::Result<()> { - let message = read_message(self.message, self.hex)?; - let sig_data = decode_hex(self.sig)?; - let uri = read_uri(self.uri)?; + pub fn run(&self) -> error::Result<()> { + let message = read_message(self.message.as_ref(), self.hex)?; + let sig_data = decode_hex(&self.sig)?; + let uri = read_uri(self.uri.as_ref())?; let uri = if uri.starts_with("0x") { &uri[2..] } else { diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index ecd1edfe4a7c0..bacc215d2ab7f 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -183,7 +183,7 @@ impl Runner { /// A helper function that runs a future with tokio and stops if the process receives the signal /// `SIGTERM` or `SIGINT`. - pub fn run_subcommand(self, subcommand: Subcommand, builder: B) -> Result<()> + pub fn run_subcommand(self, subcommand: &Subcommand, builder: B) -> Result<()> where B: FnOnce(Configuration) -> sc_service::error::Result, BC: ServiceBuilderCommand + Unpin, @@ -218,7 +218,6 @@ impl Runner { Subcommand::Sign(cmd) => cmd.run(), Subcommand::Verify(cmd) => cmd.run(), Subcommand::Vanity(cmd) => cmd.run(), - // Subcommand::Transfer(cmd) => cmd.run::(), Subcommand::SignTransaction(cmd) => cmd.run::(), Subcommand::Insert(cmd) => cmd.run::(), } From c1a5b31b4d05477202c8ffac6865041d4d2633f5 Mon Sep 17 00:00:00 2001 From: Seun Date: Fri, 8 May 2020 14:26:15 +0100 Subject: [PATCH 27/77] =?UTF-8?q?can't=20believe=20i=20missed=20that=20?= =?UTF-8?q?=F0=9F=A4=A6=F0=9F=8F=BE=E2=80=8D=E2=99=82=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/node-template/node/src/command.rs | 2 +- bin/node/cli/src/command.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/node-template/node/src/command.rs b/bin/node-template/node/src/command.rs index cb85c524c200f..aaaaf05814e82 100644 --- a/bin/node-template/node/src/command.rs +++ b/bin/node-template/node/src/command.rs @@ -68,7 +68,7 @@ pub fn run() -> sc_cli::Result<()> { Some(ref subcommand) => { let runner = cli.create_runner(subcommand)?; runner.run_subcommand::( - subcommand.clone(), + subcommand, |config| Ok(new_full_start!(config).0) ) } diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index 94736acdb7ae9..9b7f8dba015d0 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -101,7 +101,7 @@ pub fn run() -> Result<()> { let runner = cli.create_runner(subcommand)?; runner.run_subcommand::( - subcommand.clone(), + subcommand, |config| Ok(new_full_start!(config).0) ) } From 57228de5f1da68e7c27631ff438f74aba3545852 Mon Sep 17 00:00:00 2001 From: Seun Date: Fri, 8 May 2020 15:40:16 +0100 Subject: [PATCH 28/77] bump wasm-bindgen for some reason --- bin/node/browser-testing/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node/browser-testing/Cargo.toml b/bin/node/browser-testing/Cargo.toml index 391f2fa2267d5..99c52365f2962 100644 --- a/bin/node/browser-testing/Cargo.toml +++ b/bin/node/browser-testing/Cargo.toml @@ -12,7 +12,7 @@ libp2p = { version = "0.18.0", default-features = false } jsonrpc-core = "14.0.5" serde = "1.0.106" serde_json = "1.0.48" -wasm-bindgen = { version = "0.2.60", features = ["serde-serialize"] } +wasm-bindgen = { version = "0.2.62", features = ["serde-serialize"] } wasm-bindgen-futures = "0.4.10" wasm-bindgen-test = "0.3.10" futures = "0.3.4" From 1c84698fdb1903f0e88dafdecfef56702f819c3f Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 11 May 2020 11:39:09 +0100 Subject: [PATCH 29/77] adds key subcommand, rename generate-node-key to generate-node-id --- Cargo.lock | 2 +- client/cli/src/commands/generate_node_key.rs | 10 ++-- client/cli/src/commands/key.rs | 61 ++++++++++++++++++++ client/cli/src/commands/mod.rs | 23 ++------ client/cli/src/commands/sign.rs | 2 +- client/cli/src/commands/sign_transaction.rs | 2 +- client/cli/src/commands/tests.rs | 2 +- client/cli/src/runner.rs | 5 +- 8 files changed, 77 insertions(+), 30 deletions(-) create mode 100644 client/cli/src/commands/key.rs diff --git a/Cargo.lock b/Cargo.lock index 2a5379ccac300..f7cf8120a2f42 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5722,7 +5722,7 @@ checksum = "b27b256b41986ac5141b37b8bbba85d314fbf546c182eb255af6720e07e4f804" dependencies = [ "log", "rustc-hash", - "smallvec 1.3.0", + "smallvec 1.4.0", ] [[package]] diff --git a/client/cli/src/commands/generate_node_key.rs b/client/cli/src/commands/generate_node_key.rs index b6db792bc6880..18c99b6aafa3e 100644 --- a/client/cli/src/commands/generate_node_key.rs +++ b/client/cli/src/commands/generate_node_key.rs @@ -21,13 +21,13 @@ use structopt::StructOpt; use std::{path::PathBuf, fs}; use libp2p::identity::{ed25519 as libp2p_ed25519, PublicKey}; -/// The `generate-node-key` command +/// The `generate-node-id` command #[derive(Debug, StructOpt, Clone)] #[structopt( - name = "generate-node-key", + name = "generate-node-id", about = "Generate a random node libp2p key, save it to file and print its peer ID" )] -pub struct GenerateNodeKeyCmd { +pub struct GenerateNodeIdCmd { /// Name of file to save secret key to. #[structopt(long)] file: PathBuf, @@ -37,7 +37,7 @@ pub struct GenerateNodeKeyCmd { pub shared_params: SharedParams, } -impl GenerateNodeKeyCmd { +impl GenerateNodeIdCmd { /// Run the command pub fn run(&self) -> error::Result<()> { let file = &self.file; @@ -54,7 +54,7 @@ impl GenerateNodeKeyCmd { } } -impl CliConfiguration for GenerateNodeKeyCmd { +impl CliConfiguration for GenerateNodeIdCmd { fn shared_params(&self) -> &SharedParams { &self.shared_params } diff --git a/client/cli/src/commands/key.rs b/client/cli/src/commands/key.rs new file mode 100644 index 0000000000000..f04e639467626 --- /dev/null +++ b/client/cli/src/commands/key.rs @@ -0,0 +1,61 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . +use crate::{error, substrate_cli_subcommands}; +use structopt::StructOpt; +use cli_utils::{HashFor, RuntimeAdapter}; +use serde::{de::DeserializeOwned, Serialize}; +use super::{GenerateNodeIdCmd, GenerateCmd, InspectCmd, InsertCmd}; + +/// key utilities for the cli. +#[derive(Debug, Clone, StructOpt)] +pub enum KeySubcommand { + /// Generate a random node libp2p key, save it to file and print its peer ID + GenerateNodeKey(GenerateNodeIdCmd), + + /// Generate a random account + Generate(GenerateCmd), + + /// Gets a public key and a SS58 address from the provided Secret URI + InspectKey(InspectCmd), + + /// Insert a key to the keystore of a node. + Insert(InsertCmd), +} + +impl KeySubcommand { + /// run the key subcommands + pub fn run(&self) -> error::Result<()> + where + RA: RuntimeAdapter, + HashFor: DeserializeOwned + Serialize + Send + Sync, + { + match self { + KeySubcommand::GenerateNodeKey(cmd) => cmd.run(), + KeySubcommand::Generate(cmd) => cmd.run(), + KeySubcommand::InspectKey(cmd) => cmd.run(), + KeySubcommand::Insert(cmd) => cmd.run::(), + } + } +} + +// CliConfiguration implementation +substrate_cli_subcommands!( + KeySubcommand => + GenerateNodeKey, + Generate, + InspectKey, + Insert +); diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 889f8ad0c7317..5e730ef2ff821 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -23,6 +23,7 @@ mod purge_chain_cmd; mod generate_node_key; mod generate; mod inspect; +mod key; mod sign; mod sign_transaction; mod utils; @@ -47,7 +48,7 @@ pub use self::{ import_blocks_cmd::ImportBlocksCmd, purge_chain_cmd::PurgeChainCmd, generate::GenerateCmd, - generate_node_key::GenerateNodeKeyCmd, + generate_node_key::GenerateNodeIdCmd, insert::InsertCmd, sign::SignCmd, vanity::VanityCmd, @@ -56,11 +57,11 @@ pub use self::{ revert_cmd::RevertCmd, run_cmd::RunCmd, inspect::InspectCmd, + key::KeySubcommand, utils::* }; use cli_utils::{IndexFor, CallFor}; - /// All core commands that are provided by default. /// /// The core commands are split into multiple subcommands and `Run` is the default subcommand. From @@ -89,17 +90,8 @@ pub enum Subcommand { /// Remove the whole chain data. PurgeChain(PurgeChainCmd), - /// Generate a random node libp2p key, save it to file and print its peer ID - GenerateNodeKey(GenerateNodeKeyCmd), - - /// Generate a random account - Generate(GenerateCmd), - - /// Gets a public key and a SS58 address from the provided Secret URI - InspectKey(InspectCmd), - - /// Insert a key to the keystore of a node. - Insert(InsertCmd), + /// Subcommand for key utilities, eg. generate-node-key, inspect. + Key(KeySubcommand), /// Sign a message, with a given (secret) key Sign(SignCmd), @@ -465,10 +457,7 @@ substrate_cli_subcommands!( CheckBlock, Revert, PurgeChain, - GenerateNodeKey, - Generate, - InspectKey, - Insert, + Key, Sign, SignTransaction, Verify, diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs index 1e2165b3f5319..ffad2244a9e37 100644 --- a/client/cli/src/commands/sign.rs +++ b/client/cli/src/commands/sign.rs @@ -63,7 +63,7 @@ impl SignCmd { let password = self.keystore_params.read_password()?; let signature = with_crypto_scheme!( - self.crypto_scheme.scheme.clone(), + self.crypto_scheme.scheme, sign(&suri, &password, message) )?; diff --git a/client/cli/src/commands/sign_transaction.rs b/client/cli/src/commands/sign_transaction.rs index 36927c468cfdd..a711070093606 100644 --- a/client/cli/src/commands/sign_transaction.rs +++ b/client/cli/src/commands/sign_transaction.rs @@ -74,7 +74,7 @@ impl SignTransactionCmd { let pass = self.keystore_params.read_password()?; with_crypto_scheme!( - self.crypto_scheme.scheme.clone(), + self.crypto_scheme.scheme, print_ext(&self.suri, &pass, call, nonce) ) } diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs index 486b1d1361a9d..b84a0ea54f0d4 100644 --- a/client/cli/src/commands/tests.rs +++ b/client/cli/src/commands/tests.rs @@ -32,7 +32,7 @@ fn generate_node_key() { .prefix("keyfile") .tempfile() .unwrap(); - let generate = GenerateNodeKeyCmd::from_iter(&["generate-node-key", "--file", "/tmp/keyfile"]); + let generate = GenerateNodeIdCmd::from_iter(&["generate-node-key", "--file", "/tmp/keyfile"]); assert!(generate.run().is_ok()); let mut buf = String::new(); assert!(file.read_to_string(&mut buf).is_ok()); diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index bacc215d2ab7f..3e89c1572dd59 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -210,16 +210,13 @@ impl Runner { run_until_exit(self.tokio_runtime, cmd.run(self.config, builder)) } Subcommand::ExportState(cmd) => cmd.run(self.config, builder), + Subcommand::Key(cmd) => cmd.run::(), Subcommand::Revert(cmd) => cmd.run(self.config, builder), Subcommand::PurgeChain(cmd) => cmd.run(self.config), - Subcommand::GenerateNodeKey(cmd) => cmd.run(), - Subcommand::Generate(cmd) => cmd.run(), - Subcommand::InspectKey(cmd) => cmd.run(), Subcommand::Sign(cmd) => cmd.run(), Subcommand::Verify(cmd) => cmd.run(), Subcommand::Vanity(cmd) => cmd.run(), Subcommand::SignTransaction(cmd) => cmd.run::(), - Subcommand::Insert(cmd) => cmd.run::(), } } From 66d14947cac0fe415691ecafbb266224bd21a03c Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 11 May 2020 17:36:05 +0100 Subject: [PATCH 30/77] =?UTF-8?q?cargo=20update=20and=20crossed=20fingers?= =?UTF-8?q?=20=F0=9F=A4=9E=F0=9F=8F=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 256 ++++++++++++++-------------- bin/node/browser-testing/Cargo.toml | 2 +- 2 files changed, 131 insertions(+), 127 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7cf8120a2f42..be2ccfc61fc36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -237,7 +237,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95fd83426b89b034bf4e9ceb9c533c2f2386b813fd3dcae0a425ec6f1837d78a" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "rustls", "webpki", "webpki-roots 0.19.0", @@ -302,9 +302,9 @@ checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" [[package]] name = "base64" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d5ca2cd0adc3f48f9e9ea5a6bbdf9ccc0bfade884847e484d452414c7ccffb3" +checksum = "53d1ccbaf7d9ec9537465a97bf19edc1a4e158ecb49fc16178202238c569cc42" [[package]] name = "bincode" @@ -473,9 +473,9 @@ checksum = "476e9cd489f9e121e02ffa6014a8ef220ecb15c05ed23fc34cca13925dc283fb" [[package]] name = "bstr" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2889e6d50f394968c8bf4240dc3f2a7eb4680844d27308f798229ac9d4725f41" +checksum = "31accafdb70df7871592c058eca3985b71104e15ac32f64706022c58867da931" dependencies = [ "lazy_static", "memchr", @@ -1303,7 +1303,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e43f2f1833d64e33f15592464d6fdd70f349dda7b1a53088eb83cd94014008c5" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", ] [[package]] @@ -1376,12 +1376,12 @@ dependencies = [ [[package]] name = "finality-grandpa" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4682570188cd105606e621b9992e580f717c15f8cd1b7d106b59f1c6e54680" +checksum = "8feb87a63249689640ac9c011742c33139204e3c134293d3054022276869133b" dependencies = [ "either", - "futures 0.3.4", + "futures 0.3.5", "futures-timer 2.0.2", "log", "num-traits 0.2.11", @@ -1668,9 +1668,9 @@ checksum = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" [[package]] name = "futures" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c329ae8753502fb44ae4fc2b622fa2a94652c41e795143765ba0927f92ab780" +checksum = "1e05b85ec287aac0dc34db7d4a569323df697f9c55b99b15d6b4ef8cde49f613" dependencies = [ "futures-channel", "futures-core", @@ -1683,9 +1683,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c77d04ce8edd9cb903932b608268b3fffec4163dc053b3b402bf47eac1f1a8" +checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" dependencies = [ "futures-core", "futures-sink", @@ -1702,9 +1702,9 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f25592f769825e89b92358db00d26f965761e094951ac44d3663ef25b7ac464a" +checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" [[package]] name = "futures-core-preview" @@ -1729,7 +1729,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fdcef58a173af8148b182684c9f2d5250875adbcaff7b5794073894f9d8634a9" dependencies = [ "futures 0.1.29", - "futures 0.3.4", + "futures 0.3.5", "lazy_static", "log", "parking_lot 0.9.0", @@ -1740,9 +1740,9 @@ dependencies = [ [[package]] name = "futures-executor" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f674f3e1bcb15b37284a90cedf55afdba482ab061c407a9c0ebbd0f3109741ba" +checksum = "10d6bb888be1153d3abeb9006b11b02cf5e9b209fda28693c31ae1e4e012e314" dependencies = [ "futures-core", "futures-task", @@ -1752,15 +1752,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a638959aa96152c7a4cddf50fcb1e3fede0583b27157c26e67d6f99904090dc6" +checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" [[package]] name = "futures-macro" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a5081aa3de1f7542a794a397cde100ed903b0630152d0973479018fd85423a7" +checksum = "d0b5a30a4328ab5473878237c447333c093297bded83a4983d10f4deea240d39" dependencies = [ "proc-macro-hack", "proc-macro2", @@ -1770,15 +1770,18 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3466821b4bc114d95b087b850a724c6f83115e929bc88f1fa98a3304a944c8a6" +checksum = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc" [[package]] name = "futures-task" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0a34e53cf6cdcd0178aa573aed466b646eb3db769570841fda0c7ede375a27" +checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" +dependencies = [ + "once_cell 1.3.1", +] [[package]] name = "futures-timer" @@ -1798,9 +1801,9 @@ dependencies = [ [[package]] name = "futures-util" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22766cf25d64306bedf0384da004d05c9974ab104fcc4528f1236181c18004c5" +checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" dependencies = [ "futures 0.1.29", "futures-channel", @@ -1810,6 +1813,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", + "pin-project", "pin-utils", "proc-macro-hack", "proc-macro-nested", @@ -1835,7 +1839,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0a73299e4718f5452e45980fc1d6957a070abe308d3700b63b8673f47e1c2b3" dependencies = [ "bytes 0.5.4", - "futures 0.3.4", + "futures 0.3.5", "memchr", "pin-project", ] @@ -2090,9 +2094,9 @@ dependencies = [ [[package]] name = "honggfuzz" -version = "0.5.48" +version = "0.5.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a4ae2efc127fb46f7d28bf568e8338d5aaf6e465adb7b9f401806c94f36b073" +checksum = "832bac18a82ec7d6c21887daa8616b238fe90d5d5e762d0d4b9372cdaa9e097f" dependencies = [ "arbitrary", "lazy_static", @@ -2326,7 +2330,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64fa110ec7b8f493f416eed552740d10e7030ad5f63b2308f82c9608ec2df275" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "futures-timer 2.0.2", ] @@ -2530,9 +2534,9 @@ dependencies = [ [[package]] name = "kv-log-macro" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c54d9f465d530a752e6ebdc217e081a7a614b48cb200f6f0aee21ba6bc9aabb" +checksum = "2a2d3beed37e5483887d81eb39de6de03a8346531410e1306ca48a9a89bd3a51" dependencies = [ "log", ] @@ -2583,7 +2587,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26f96eec962af83cdf7c83036b3dbb0ae6a1249ddab746820618e2567ca8ebcd" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "js-sys", "kvdb", "kvdb-memorydb", @@ -2653,7 +2657,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32ea742c86405b659c358223a8f0f9f5a9eb27bb6083894c6340959b05269662" dependencies = [ "bytes 0.5.4", - "futures 0.3.4", + "futures 0.3.5", "lazy_static", "libp2p-core", "libp2p-core-derive", @@ -2695,7 +2699,7 @@ dependencies = [ "ed25519-dalek", "either", "fnv", - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "lazy_static", "libsecp256k1", @@ -2735,7 +2739,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ad32b006ea922da8cc66e537cf2df4b0fad8ebaa467d2a8c63d7784ac252ec6" dependencies = [ "flate2", - "futures 0.3.4", + "futures 0.3.5", "libp2p-core", ] @@ -2745,7 +2749,7 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0d0993481203d68e5ce2f787d033fb0cac6b850659ed6c784612db678977c71" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "libp2p-core", "log", ] @@ -2758,7 +2762,7 @@ checksum = "3673153ca967c179d745fadf047d069355d6669ecf7f261b450fbaebf1bffd3d" dependencies = [ "cuckoofilter", "fnv", - "futures 0.3.4", + "futures 0.3.5", "libp2p-core", "libp2p-swarm", "prost", @@ -2777,7 +2781,7 @@ dependencies = [ "byteorder 1.3.4", "bytes 0.5.4", "fnv", - "futures 0.3.4", + "futures 0.3.5", "futures_codec", "libp2p-core", "libp2p-swarm", @@ -2798,7 +2802,7 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a38ca3eb807789e26f41c82ca7cd2b3843c66c5587b8b5f709a2f421f3061414" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "libp2p-core", "libp2p-swarm", "log", @@ -2818,7 +2822,7 @@ dependencies = [ "bytes 0.5.4", "either", "fnv", - "futures 0.3.4", + "futures 0.3.5", "futures_codec", "libp2p-core", "libp2p-swarm", @@ -2845,7 +2849,7 @@ dependencies = [ "data-encoding", "dns-parser", "either", - "futures 0.3.4", + "futures 0.3.5", "lazy_static", "libp2p-core", "libp2p-swarm", @@ -2865,7 +2869,7 @@ checksum = "0832882b06619b2e81d74e71447753ea3c068164a0bca67847d272e856a04a02" dependencies = [ "bytes 0.5.4", "fnv", - "futures 0.3.4", + "futures 0.3.5", "futures_codec", "libp2p-core", "log", @@ -2880,7 +2884,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "918e94a649e1139c24ee9f1f8c1f2adaba6d157b9471af787f2d9beac8c29c77" dependencies = [ "curve25519-dalek", - "futures 0.3.4", + "futures 0.3.5", "lazy_static", "libp2p-core", "log", @@ -2900,7 +2904,7 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9bfbf87eebb492d040f9899c5c81c9738730465ac5e78d9b7a7d086d0f07230" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "libp2p-core", "libp2p-swarm", "log", @@ -2916,7 +2920,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fabb00553a49bf6d4a8ce362f6eefac410227a14d03c3acffbb8cc3f022ea019" dependencies = [ "bytes 0.5.4", - "futures 0.3.4", + "futures 0.3.5", "futures_codec", "libp2p-core", "log", @@ -2933,7 +2937,7 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f81b8b37ff529e1f51c20c396dac657def2108da174c1d27e57e72c9fe2d411" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "log", "pin-project", "rand 0.7.3", @@ -2949,7 +2953,7 @@ checksum = "a7a0509a7e47245259954fef58b85b81bf4d29ae33a4365e38d718a866698774" dependencies = [ "aes-ctr", "ctr", - "futures 0.3.4", + "futures 0.3.5", "hmac", "js-sys", "lazy_static", @@ -2977,7 +2981,7 @@ version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44ab289ae44cc691da0a6fe96aefa43f26c86c6c7813998e203f6d80f1860f18" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "libp2p-core", "log", "rand 0.7.3", @@ -2993,7 +2997,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b37ea44823d3ed223e4605da94b50177bc520f05ae2452286700549a32d81669" dependencies = [ "async-std", - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "get_if_addrs", "ipnet", @@ -3008,7 +3012,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "281c18ea2faacb9c8a6ff76c4405df5918d9a263770e3847bf03f099abadc010" dependencies = [ "async-std", - "futures 0.3.4", + "futures 0.3.5", "libp2p-core", "log", ] @@ -3019,7 +3023,7 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3ac7dbde0f88cad191dcdfd073b8bae28d01823e8ca313f117b6ecb914160c3" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "js-sys", "libp2p-core", "parity-send-wrapper", @@ -3036,7 +3040,7 @@ dependencies = [ "async-tls", "bytes 0.5.4", "either", - "futures 0.3.4", + "futures 0.3.5", "libp2p-core", "log", "quicksink", @@ -3054,7 +3058,7 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02f91aea50f6571e0bc6c058dc0e9b270afd41ec28dd94e9e4bf607e78b9ab87" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "libp2p-core", "parking_lot 0.10.2", "thiserror", @@ -3354,7 +3358,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74cdcf7cfb3402881e15a1f95116cb033d69b33c83d481e1234777f5ef0c3d2c" dependencies = [ "bytes 0.5.4", - "futures 0.3.4", + "futures 0.3.5", "log", "pin-project", "smallvec 1.4.0", @@ -3458,7 +3462,7 @@ dependencies = [ name = "node-browser-testing" version = "2.0.0-dev" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "jsonrpc-core", "libp2p", @@ -3479,7 +3483,7 @@ dependencies = [ "frame-benchmarking-cli", "frame-support", "frame-system", - "futures 0.3.4", + "futures 0.3.5", "hex-literal", "jsonrpc-core", "log", @@ -3717,7 +3721,7 @@ dependencies = [ name = "node-template" version = "2.0.0-dev" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "log", "node-template-runtime", "parking_lot 0.10.2", @@ -3783,7 +3787,7 @@ dependencies = [ "frame-support", "frame-system", "fs_extra", - "futures 0.3.4", + "futures 0.3.5", "log", "node-executor", "node-primitives", @@ -3845,9 +3849,9 @@ dependencies = [ [[package]] name = "ntapi" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26e041cd983acbc087e30fcba770380cfa352d0e392e175b2344ebaf7ea0602" +checksum = "7a31937dea023539c72ddae0e3571deadc1414b300483fa7aaec176168cfa9d2" dependencies = [ "winapi 0.3.8", ] @@ -5103,18 +5107,18 @@ dependencies = [ [[package]] name = "pin-project" -version = "0.4.13" +version = "0.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c3bfbfb5bb42f99498c7234bbd768c220eb0cea6818259d0d18a1aa3d2595d" +checksum = "81d480cb4e89522ccda96d0eed9af94180b7a5f93fb28f66e1fd7d68431663d1" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "0.4.13" +version = "0.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccbf6449dcfb18562c015526b085b8df1aa3cdab180af8ec2ebd300a3bd28f63" +checksum = "a82996f11efccb19b685b14b5df818de31c1edcee3daa256ab5775dd98e72feb" dependencies = [ "proc-macro2", "quote 1.0.4", @@ -5904,7 +5908,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4da5fcb054c46f5a5dff833b129285a93d3f0179531735e6c866e8cc307d2020" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "pin-project", "static_assertions", ] @@ -5960,7 +5964,7 @@ dependencies = [ "bytes 0.5.4", "derive_more", "env_logger 0.7.1", - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "libp2p", "log", @@ -5987,7 +5991,7 @@ dependencies = [ name = "sc-basic-authorship" version = "0.8.0-dev" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "log", "parity-scale-codec", @@ -6064,7 +6068,7 @@ dependencies = [ "env_logger 0.7.1", "fdlimit", "futures 0.1.29", - "futures 0.3.4", + "futures 0.3.5", "hex", "hyper 0.12.35", "jsonrpc-core-client", @@ -6110,7 +6114,7 @@ version = "2.0.0-dev" dependencies = [ "derive_more", "fnv", - "futures 0.3.4", + "futures 0.3.5", "hash-db", "hex-literal", "kvdb", @@ -6191,7 +6195,7 @@ version = "0.8.0-dev" dependencies = [ "derive_more", "env_logger 0.7.1", - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "log", "parity-scale-codec", @@ -6229,7 +6233,7 @@ dependencies = [ "derive_more", "env_logger 0.7.1", "fork-tree", - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "log", "merlin", @@ -6276,7 +6280,7 @@ name = "sc-consensus-babe-rpc" version = "0.8.0-dev" dependencies = [ "derive_more", - "futures 0.3.4", + "futures 0.3.5", "jsonrpc-core", "jsonrpc-core-client", "jsonrpc-derive", @@ -6315,7 +6319,7 @@ dependencies = [ "assert_matches", "derive_more", "env_logger 0.7.1", - "futures 0.3.4", + "futures 0.3.5", "jsonrpc-core", "jsonrpc-core-client", "jsonrpc-derive", @@ -6342,7 +6346,7 @@ name = "sc-consensus-pow" version = "0.8.0-dev" dependencies = [ "derive_more", - "futures 0.3.4", + "futures 0.3.5", "log", "parity-scale-codec", "sc-client-api", @@ -6361,7 +6365,7 @@ dependencies = [ name = "sc-consensus-slots" version = "0.8.0-dev" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "log", "parity-scale-codec", @@ -6486,7 +6490,7 @@ dependencies = [ "env_logger 0.7.1", "finality-grandpa", "fork-tree", - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "log", "parity-scale-codec", @@ -6527,7 +6531,7 @@ version = "0.8.0-dev" dependencies = [ "derive_more", "finality-grandpa", - "futures 0.3.4", + "futures 0.3.5", "jsonrpc-core", "jsonrpc-core-client", "jsonrpc-derive", @@ -6543,7 +6547,7 @@ name = "sc-informant" version = "0.8.0-dev" dependencies = [ "ansi_term 0.12.1", - "futures 0.3.4", + "futures 0.3.5", "log", "parity-util-mem", "sc-client-api", @@ -6583,7 +6587,7 @@ dependencies = [ "erased-serde", "fnv", "fork-tree", - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "futures_codec", "hex", @@ -6633,7 +6637,7 @@ name = "sc-network-gossip" version = "0.8.0-dev" dependencies = [ "async-std", - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "libp2p", "log", @@ -6651,7 +6655,7 @@ name = "sc-network-test" version = "0.8.0-dev" dependencies = [ "env_logger 0.7.1", - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "libp2p", "log", @@ -6680,7 +6684,7 @@ dependencies = [ "env_logger 0.7.1", "fdlimit", "fnv", - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "hyper 0.13.5", "hyper-rustls", @@ -6709,7 +6713,7 @@ dependencies = [ name = "sc-peerset" version = "2.0.0-dev" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "libp2p", "log", "rand 0.7.3", @@ -6724,7 +6728,7 @@ version = "2.0.0-dev" dependencies = [ "assert_matches", "futures 0.1.29", - "futures 0.3.4", + "futures 0.3.5", "hash-db", "jsonrpc-core", "jsonrpc-pubsub", @@ -6761,7 +6765,7 @@ name = "sc-rpc-api" version = "0.8.0-dev" dependencies = [ "derive_more", - "futures 0.3.4", + "futures 0.3.5", "jsonrpc-core", "jsonrpc-core-client", "jsonrpc-derive", @@ -6813,7 +6817,7 @@ dependencies = [ "derive_more", "exit-future", "futures 0.1.29", - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "hash-db", "lazy_static", @@ -6874,7 +6878,7 @@ dependencies = [ "env_logger 0.7.1", "fdlimit", "futures 0.1.29", - "futures 0.3.4", + "futures 0.3.5", "hex-literal", "log", "parity-scale-codec", @@ -6921,7 +6925,7 @@ name = "sc-telemetry" version = "2.0.0-dev" dependencies = [ "bytes 0.5.4", - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "libp2p", "log", @@ -6959,7 +6963,7 @@ dependencies = [ "assert_matches", "criterion 0.3.2", "derive_more", - "futures 0.3.4", + "futures 0.3.5", "linked-hash-map", "log", "parity-scale-codec", @@ -6981,7 +6985,7 @@ version = "2.0.0-dev" dependencies = [ "assert_matches", "derive_more", - "futures 0.3.4", + "futures 0.3.5", "futures-diagnose", "hex", "intervalier", @@ -7007,9 +7011,9 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "039c25b130bd8c1321ee2d7de7fde2659fa9c2744e4bb29711cfc852ea53cd19" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" dependencies = [ "lazy_static", "winapi 0.3.8", @@ -7062,9 +7066,9 @@ dependencies = [ [[package]] name = "scroll_derive" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8584eea9b9ff42825b46faf46a8c24d2cff13ec152fa2a50df788b87c07ee28" +checksum = "e367622f934864ffa1c704ba2b82280aab856e3d8213c84c5720257eb34b15b9" dependencies = [ "proc-macro2", "quote 1.0.4", @@ -7083,9 +7087,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f331b9025654145cd425b9ded0caf8f5ae0df80d418b326e2dc1c3dc5eb0620" +checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535" dependencies = [ "bitflags", "core-foundation", @@ -7149,18 +7153,18 @@ checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0" [[package]] name = "serde" -version = "1.0.106" +version = "1.0.110" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399" +checksum = "99e7b308464d16b56eba9964e4972a3eee817760ab60d88c3f86e1fecb08204c" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.106" +version = "1.0.110" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c" +checksum = "818fbf6bfa9a42d3bfcaca148547aa00c7b915bec71d1757aa2d44ca68771984" dependencies = [ "proc-macro2", "quote 1.0.4", @@ -7169,9 +7173,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.52" +version = "1.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7894c8ed05b7a3a279aeb79025fdec1d3158080b75b98a08faf2806bb799edd" +checksum = "993948e75b189211a9b31a7528f950c6adc21f9720b6438ff80a7fa2f864cea2" dependencies = [ "itoa", "ryu", @@ -7339,7 +7343,7 @@ dependencies = [ "base64 0.11.0", "bytes 0.5.4", "flate2", - "futures 0.3.4", + "futures 0.3.5", "http 0.2.1", "httparse", "log", @@ -7515,7 +7519,7 @@ name = "sp-consensus" version = "0.8.0-dev" dependencies = [ "derive_more", - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "libp2p", "log", @@ -7592,7 +7596,7 @@ dependencies = [ "byteorder 1.3.4", "criterion 0.2.11", "ed25519-dalek", - "futures 0.3.4", + "futures 0.3.5", "hash-db", "hash256-std-hasher", "hex", @@ -7694,7 +7698,7 @@ dependencies = [ name = "sp-io" version = "2.0.0-dev" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "hash-db", "libsecp256k1", "log", @@ -7987,7 +7991,7 @@ name = "sp-transaction-pool" version = "2.0.0-dev" dependencies = [ "derive_more", - "futures 0.3.4", + "futures 0.3.5", "log", "parity-scale-codec", "serde", @@ -8018,7 +8022,7 @@ dependencies = [ name = "sp-utils" version = "2.0.0-dev" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "futures-core", "lazy_static", "prometheus", @@ -8201,7 +8205,7 @@ dependencies = [ "console_error_panic_hook", "console_log", "futures 0.1.29", - "futures 0.3.4", + "futures 0.3.5", "futures-timer 3.0.2", "js-sys", "kvdb-web", @@ -8231,7 +8235,7 @@ version = "2.0.0-dev" dependencies = [ "frame-support", "frame-system", - "futures 0.3.4", + "futures 0.3.5", "jsonrpc-client-transports", "jsonrpc-core", "parity-scale-codec", @@ -8247,7 +8251,7 @@ version = "2.0.0-dev" dependencies = [ "env_logger 0.7.1", "frame-system-rpc-runtime-api", - "futures 0.3.4", + "futures 0.3.5", "jsonrpc-core", "jsonrpc-core-client", "jsonrpc-derive", @@ -8281,7 +8285,7 @@ dependencies = [ name = "substrate-test-client" version = "2.0.0-dev" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "hash-db", "parity-scale-codec", "sc-client-api", @@ -8346,7 +8350,7 @@ dependencies = [ name = "substrate-test-runtime-client" version = "2.0.0-dev" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "parity-scale-codec", "sc-block-builder", "sc-client-api", @@ -8366,7 +8370,7 @@ name = "substrate-test-runtime-transaction-pool" version = "2.0.0-dev" dependencies = [ "derive_more", - "futures 0.3.4", + "futures 0.3.5", "parity-scale-codec", "parking_lot 0.10.2", "sc-transaction-graph", @@ -8657,9 +8661,9 @@ dependencies = [ [[package]] name = "threadpool" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8dae184447c15d5a6916d973c642aec485105a13cd238192a6927ae3e077d66" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" dependencies = [ "num_cpus", ] @@ -9444,7 +9448,7 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "324c5e65a08699c9c4334ba136597ab22b85dccd4b65dd1e36ccf8f723a95b54" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "js-sys", "parking_lot 0.9.0", "pin-utils", @@ -9513,7 +9517,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed54fd9d64dfeeee7c285fd126174a6b5e6d4efc7e5a1566fdb635e60ff6a74e" dependencies = [ "anyhow", - "base64 0.12.0", + "base64 0.12.1", "bincode", "cranelift-codegen", "cranelift-entity", @@ -9537,18 +9541,18 @@ dependencies = [ [[package]] name = "wast" -version = "15.0.0" +version = "16.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a10df5277f68adee65bba117b40235f07a4cb3d59e5ec9aa86dbee180fb1bc04" +checksum = "8564a0c8f4d468d71c2b263dd1f675fa2cac6e7331ff8379cbb88cb79fcef8d1" dependencies = [ "leb128", ] [[package]] name = "wat" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "526d28df6c047d9f9a92d4925b98afd8d8d95b1b3aa4f13eb1306f17d1da56c4" +checksum = "a02463c6661a0d5a089d795e2e49ab34594b41265e8bd5ff3e0810e2a1f84222" dependencies = [ "wast", ] @@ -9694,7 +9698,7 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84300bb493cc878f3638b981c62b4632ec1a5c52daaa3036651e8c106d3b55ea" dependencies = [ - "futures 0.3.4", + "futures 0.3.5", "log", "nohash-hasher", "parking_lot 0.10.2", diff --git a/bin/node/browser-testing/Cargo.toml b/bin/node/browser-testing/Cargo.toml index 99c52365f2962..391f2fa2267d5 100644 --- a/bin/node/browser-testing/Cargo.toml +++ b/bin/node/browser-testing/Cargo.toml @@ -12,7 +12,7 @@ libp2p = { version = "0.18.0", default-features = false } jsonrpc-core = "14.0.5" serde = "1.0.106" serde_json = "1.0.48" -wasm-bindgen = { version = "0.2.62", features = ["serde-serialize"] } +wasm-bindgen = { version = "0.2.60", features = ["serde-serialize"] } wasm-bindgen-futures = "0.4.10" wasm-bindgen-test = "0.3.10" futures = "0.3.4" From fa4de238a38d0eb404814c19f5795aa246ed74f1 Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 11 May 2020 19:47:02 +0100 Subject: [PATCH 31/77] update ui test --- .../ui/empty_impl_runtime_apis_call.stderr | 4 ++- .../ui/impl_incorrect_method_signature.stderr | 22 +++++----------- .../tests/ui/mock_only_one_error_type.stderr | 6 ++--- .../tests/ui/mock_only_self_reference.stderr | 26 +++---------------- ...reference_in_impl_runtime_apis_call.stderr | 22 +++++----------- 5 files changed, 21 insertions(+), 59 deletions(-) diff --git a/primitives/api/test/tests/ui/empty_impl_runtime_apis_call.stderr b/primitives/api/test/tests/ui/empty_impl_runtime_apis_call.stderr index f927912879ad0..b08f056b57d1c 100644 --- a/primitives/api/test/tests/ui/empty_impl_runtime_apis_call.stderr +++ b/primitives/api/test/tests/ui/empty_impl_runtime_apis_call.stderr @@ -2,4 +2,6 @@ error: No api implementation given! --> $DIR/empty_impl_runtime_apis_call.rs:17:1 | 17 | sp_api::impl_runtime_apis! {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/primitives/api/test/tests/ui/impl_incorrect_method_signature.stderr b/primitives/api/test/tests/ui/impl_incorrect_method_signature.stderr index 4f112e91bb7a9..851d2b8a4b652 100644 --- a/primitives/api/test/tests/ui/impl_incorrect_method_signature.stderr +++ b/primitives/api/test/tests/ui/impl_incorrect_method_signature.stderr @@ -19,22 +19,13 @@ error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for tr 14 | | } 15 | | } | |_- type in trait -16 | +16 | 17 | sp_api::impl_runtime_apis! { - | -^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | _expected `u64`, found struct `std::string::String` - | | -18 | | impl self::Api for Runtime { -19 | | fn test(data: String) {} -20 | | } -... | -32 | | } -33 | | } - | |_- in this macro invocation + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found struct `std::string::String` | = note: expected fn pointer `fn(&RuntimeApiImpl<__SR_API_BLOCK__, RuntimeApiImplCall>, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId<__SR_API_BLOCK__>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option, std::vec::Vec<_>) -> std::result::Result<_, _>` found fn pointer `fn(&RuntimeApiImpl<__SR_API_BLOCK__, RuntimeApiImplCall>, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId<__SR_API_BLOCK__>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option, std::vec::Vec<_>) -> std::result::Result<_, _>` + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types --> $DIR/impl_incorrect_method_signature.rs:17:1 @@ -46,10 +37,9 @@ error[E0308]: mismatched types ... | 32 | | } 33 | | } - | | ^ - | | | - | |_expected `u64`, found struct `std::string::String` - | in this macro invocation + | |_^ expected `u64`, found struct `std::string::String` + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types --> $DIR/impl_incorrect_method_signature.rs:19:11 diff --git a/primitives/api/test/tests/ui/mock_only_one_error_type.stderr b/primitives/api/test/tests/ui/mock_only_one_error_type.stderr index 7cec5246ca825..b190c2134fafa 100644 --- a/primitives/api/test/tests/ui/mock_only_one_error_type.stderr +++ b/primitives/api/test/tests/ui/mock_only_one_error_type.stderr @@ -14,10 +14,7 @@ error[E0277]: the trait bound `u32: std::convert::From` is ... | 26 | | } 27 | | } - | | ^ - | | | - | |_the trait `std::convert::From` is not implemented for `u32` - | in this macro invocation + | |_^ the trait `std::convert::From` is not implemented for `u32` | = help: the following implementations were found: > @@ -25,3 +22,4 @@ error[E0277]: the trait bound `u32: std::convert::From` is > > and 18 others + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/primitives/api/test/tests/ui/mock_only_self_reference.stderr b/primitives/api/test/tests/ui/mock_only_self_reference.stderr index 9c1658b0a6cea..6d1ac0e9a2563 100644 --- a/primitives/api/test/tests/ui/mock_only_self_reference.stderr +++ b/primitives/api/test/tests/ui/mock_only_self_reference.stderr @@ -22,20 +22,11 @@ error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for tr | |_- type in trait ... 12 | sp_api::mock_impl_runtime_apis! { - | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | _expected `u64`, found `()` - | | -13 | | impl Api for MockApi { -14 | | fn test(self, data: u64) {} -15 | | -16 | | fn test2(&mut self, data: u64) {} -17 | | } -18 | | } - | |_- in this macro invocation + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found `()` | = note: expected fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option, std::vec::Vec<_>) -> std::result::Result<_, _>` found fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<()>, std::vec::Vec<_>) -> std::result::Result<_, _>` + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error[E0053]: method `Api_test2_runtime_api_impl` has an incompatible type for trait --> $DIR/mock_only_self_reference.rs:12:1 @@ -49,17 +40,8 @@ error[E0053]: method `Api_test2_runtime_api_impl` has an incompatible type for t | |_- type in trait ... 12 | sp_api::mock_impl_runtime_apis! { - | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | _expected `u64`, found `()` - | | -13 | | impl Api for MockApi { -14 | | fn test(self, data: u64) {} -15 | | -16 | | fn test2(&mut self, data: u64) {} -17 | | } -18 | | } - | |_- in this macro invocation + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found `()` | = note: expected fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option, std::vec::Vec<_>) -> std::result::Result<_, _>` found fn pointer `fn(&MockApi, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<()>, std::vec::Vec<_>) -> std::result::Result<_, _>` + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/primitives/api/test/tests/ui/type_reference_in_impl_runtime_apis_call.stderr b/primitives/api/test/tests/ui/type_reference_in_impl_runtime_apis_call.stderr index 1d7d0a78a86df..c3e4850036090 100644 --- a/primitives/api/test/tests/ui/type_reference_in_impl_runtime_apis_call.stderr +++ b/primitives/api/test/tests/ui/type_reference_in_impl_runtime_apis_call.stderr @@ -19,22 +19,13 @@ error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for tr 14 | | } 15 | | } | |_- type in trait -16 | +16 | 17 | sp_api::impl_runtime_apis! { - | -^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | _expected `u64`, found `&u64` - | | -18 | | impl self::Api for Runtime { -19 | | fn test(data: &u64) { -20 | | unimplemented!() -... | -34 | | } -35 | | } - | |_- in this macro invocation + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found `&u64` | = note: expected fn pointer `fn(&RuntimeApiImpl<__SR_API_BLOCK__, RuntimeApiImplCall>, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId<__SR_API_BLOCK__>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option, std::vec::Vec<_>) -> std::result::Result<_, _>` found fn pointer `fn(&RuntimeApiImpl<__SR_API_BLOCK__, RuntimeApiImplCall>, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId<__SR_API_BLOCK__>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<&u64>, std::vec::Vec<_>) -> std::result::Result<_, _>` + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types --> $DIR/type_reference_in_impl_runtime_apis_call.rs:17:1 @@ -46,10 +37,9 @@ error[E0308]: mismatched types ... | 34 | | } 35 | | } - | | ^ - | | | - | |_expected `u64`, found `&u64` - | in this macro invocation + | |_^ expected `u64`, found `&u64` + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types --> $DIR/type_reference_in_impl_runtime_apis_call.rs:19:11 From 000b4ad23ba361a35972a971c213023a81098569 Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 11 May 2020 20:14:58 +0100 Subject: [PATCH 32/77] update more ui tests --- .../reserved_keyword/on_initialize.stderr | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/frame/support/test/tests/reserved_keyword/on_initialize.stderr b/frame/support/test/tests/reserved_keyword/on_initialize.stderr index e899ef5d78942..dbe07195e89dd 100644 --- a/frame/support/test/tests/reserved_keyword/on_initialize.stderr +++ b/frame/support/test/tests/reserved_keyword/on_initialize.stderr @@ -2,38 +2,38 @@ error: Invalid call fn name: `on_finalize`, name is reserved and doesn't match e --> $DIR/on_initialize.rs:31:1 | 31 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: Invalid call fn name: `on_initialize`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword. --> $DIR/on_initialize.rs:31:1 | 31 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: Invalid call fn name: `on_runtime_upgrade`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword. --> $DIR/on_initialize.rs:31:1 | 31 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: Invalid call fn name: `offchain_worker`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword. --> $DIR/on_initialize.rs:31:1 | 31 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: Invalid call fn name: `deposit_event`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword. --> $DIR/on_initialize.rs:31:1 | 31 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) From 1c4048a5755c5ddfb5605154697c28c96141fc70 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 12 May 2020 07:53:24 +0100 Subject: [PATCH 33/77] should be all good now --- .../runtime-interface/tests/ui/pass_by_enum_with_struct.stderr | 2 ++ .../tests/ui/pass_by_enum_with_value_variant.stderr | 2 ++ .../tests/ui/pass_by_inner_with_two_fields.stderr | 2 ++ 3 files changed, 6 insertions(+) diff --git a/primitives/runtime-interface/tests/ui/pass_by_enum_with_struct.stderr b/primitives/runtime-interface/tests/ui/pass_by_enum_with_struct.stderr index 6502a36fc18b7..c7ed1af3b1a03 100644 --- a/primitives/runtime-interface/tests/ui/pass_by_enum_with_struct.stderr +++ b/primitives/runtime-interface/tests/ui/pass_by_enum_with_struct.stderr @@ -3,3 +3,5 @@ error: `PassByEnum` only supports enums as input type. | 3 | #[derive(PassByEnum)] | ^^^^^^^^^^ + | + = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/primitives/runtime-interface/tests/ui/pass_by_enum_with_value_variant.stderr b/primitives/runtime-interface/tests/ui/pass_by_enum_with_value_variant.stderr index 1f03436d4e007..f6c85ed2bba3e 100644 --- a/primitives/runtime-interface/tests/ui/pass_by_enum_with_value_variant.stderr +++ b/primitives/runtime-interface/tests/ui/pass_by_enum_with_value_variant.stderr @@ -3,3 +3,5 @@ error: `PassByEnum` only supports unit variants. | 3 | #[derive(PassByEnum)] | ^^^^^^^^^^ + | + = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/primitives/runtime-interface/tests/ui/pass_by_inner_with_two_fields.stderr b/primitives/runtime-interface/tests/ui/pass_by_inner_with_two_fields.stderr index 7f576a69f0e50..9afbce76f0c23 100644 --- a/primitives/runtime-interface/tests/ui/pass_by_inner_with_two_fields.stderr +++ b/primitives/runtime-interface/tests/ui/pass_by_inner_with_two_fields.stderr @@ -3,3 +3,5 @@ error: Only newtype/one field structs are supported by `PassByInner`! | 3 | #[derive(PassByInner)] | ^^^^^^^^^^^ + | + = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) From fce2b0de3e54c6b668e56d61f5986bdb050a0697 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 12 May 2020 09:18:19 +0100 Subject: [PATCH 34/77] revert subkey change --- bin/utils/subkey/Cargo.toml | 1 - bin/utils/subkey/src/main.rs | 52 +++++++++++++++++------------------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/bin/utils/subkey/Cargo.toml b/bin/utils/subkey/Cargo.toml index 7f50f4546ce5a..b0c642ec43e7c 100644 --- a/bin/utils/subkey/Cargo.toml +++ b/bin/utils/subkey/Cargo.toml @@ -26,7 +26,6 @@ codec = { package = "parity-scale-codec", version = "1.3.0" } frame-system = { version = "2.0.0-dev", path = "../../../frame/system" } pallet-balances = { version = "2.0.0-dev", path = "../../../frame/balances" } pallet-transaction-payment = { version = "2.0.0-dev", path = "../../../frame/transaction-payment" } -pallet-grandpa = { version = "2.0.0-dev", path = "../../../frame/grandpa" } rpassword = "4.0.1" itertools = "0.8.2" derive_more = { version = "0.99.2" } diff --git a/bin/utils/subkey/src/main.rs b/bin/utils/subkey/src/main.rs index d04b94fc9882d..22706ebd822da 100644 --- a/bin/utils/subkey/src/main.rs +++ b/bin/utils/subkey/src/main.rs @@ -143,7 +143,7 @@ trait Crypto: Sized { }, } } else if let Ok((public_key, v)) = - ::Public::from_string_with_version(uri) + ::Public::from_string_with_version(uri) { let v = network_override.unwrap_or(v); @@ -164,11 +164,11 @@ trait Crypto: Sized { Public key (hex): {}\n \ Account ID: {}\n \ SS58 Address: {}", - uri, - String::from(v), - format_public_key::(public_key.clone()), - format_account_id::(public_key.clone()), - public_key.to_ss58check_with_version(v), + uri, + String::from(v), + format_public_key::(public_key.clone()), + format_account_id::(public_key.clone()), + public_key.to_ss58check_with_version(v), ); }, } @@ -380,9 +380,9 @@ fn static_err(msg: &'static str) -> Result<(), Error> { } fn execute(matches: ArgMatches) -> Result<(), Error> - where - SignatureOf: SignatureT, - PublicOf: PublicT, +where + SignatureOf: SignatureT, + PublicOf: PublicT, { let password_interactive = matches.is_present("password-interactive"); let password = matches.value_of("password"); @@ -406,7 +406,7 @@ fn execute(matches: ArgMatches) -> Result<(), Error> Some(Err(e)) => return Err(e), Some(Ok(v)) => Some(v), None => None, - }; + }; if let Some(network) = maybe_network { set_default_ss58_version(network); @@ -416,7 +416,7 @@ fn execute(matches: ArgMatches) -> Result<(), Error> Some(Err(_)) => return Err(Error::Static("Invalid output name. See --help for available outputs.")), Some(Ok(v)) => v, None => OutputType::Text, - }; + }; match matches.subcommand() { ("generate", Some(matches)) => { @@ -546,9 +546,9 @@ fn generate_mnemonic(matches: &ArgMatches) -> Result { } fn do_sign(suri: &str, message: Vec, password: Option<&str>) -> Result - where - SignatureOf: SignatureT, - PublicOf: PublicT, +where + SignatureOf: SignatureT, + PublicOf: PublicT, { let pair = read_pair::(Some(suri), password)?; let signature = pair.sign(&message); @@ -556,9 +556,9 @@ fn do_sign(suri: &str, message: Vec, password: Option<&str>) -> R } fn do_verify(matches: &ArgMatches, uri: &str, message: Vec) -> Result - where - SignatureOf: SignatureT, - PublicOf: PublicT, +where + SignatureOf: SignatureT, + PublicOf: PublicT, { let signature = read_signature::(matches)?; @@ -607,9 +607,9 @@ fn read_genesis_hash(matches: &ArgMatches) -> Result { } fn read_signature(matches: &ArgMatches) -> Result, Error> - where - SignatureOf: SignatureT, - PublicOf: PublicT, +where + SignatureOf: SignatureT, + PublicOf: PublicT, { let sig_data = matches .value_of("sig") @@ -628,8 +628,8 @@ fn read_signature(matches: &ArgMatches) -> Result, Err } fn read_public_key(matched_uri: Option<&str>) -> PublicOf - where - PublicOf: PublicT, +where + PublicOf: PublicT, { let uri = matched_uri.expect("parameter is required; thus it can't be None; qed"); let uri = if uri.starts_with("0x") { @@ -708,7 +708,6 @@ fn create_extrinsic( frame_system::CheckNonce::::from(i), frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(f), - pallet_grandpa::ValidateEquivocationReport::::new(), ) }; let raw_payload = SignedPayload::from_raw( @@ -721,7 +720,6 @@ fn create_extrinsic( (), (), (), - (), ), ); let signature = raw_payload.using_encoded(|payload| signer.sign(payload)).into_runtime(); @@ -749,9 +747,9 @@ mod tests { use super::*; fn test_generate_sign_verify() - where - SignatureOf: SignatureT, - PublicOf: PublicT, + where + SignatureOf: SignatureT, + PublicOf: PublicT, { let usage = get_usage(); let app = get_app(&usage); From f06ce667e595ce6a0471524c272c5e7becb3da2a Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 12 May 2020 13:29:40 +0100 Subject: [PATCH 35/77] revert subkey change --- bin/utils/subkey/Cargo.toml | 1 + bin/utils/subkey/src/main.rs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/bin/utils/subkey/Cargo.toml b/bin/utils/subkey/Cargo.toml index b0c642ec43e7c..7f50f4546ce5a 100644 --- a/bin/utils/subkey/Cargo.toml +++ b/bin/utils/subkey/Cargo.toml @@ -26,6 +26,7 @@ codec = { package = "parity-scale-codec", version = "1.3.0" } frame-system = { version = "2.0.0-dev", path = "../../../frame/system" } pallet-balances = { version = "2.0.0-dev", path = "../../../frame/balances" } pallet-transaction-payment = { version = "2.0.0-dev", path = "../../../frame/transaction-payment" } +pallet-grandpa = { version = "2.0.0-dev", path = "../../../frame/grandpa" } rpassword = "4.0.1" itertools = "0.8.2" derive_more = { version = "0.99.2" } diff --git a/bin/utils/subkey/src/main.rs b/bin/utils/subkey/src/main.rs index 22706ebd822da..754a2611bcd0f 100644 --- a/bin/utils/subkey/src/main.rs +++ b/bin/utils/subkey/src/main.rs @@ -708,6 +708,7 @@ fn create_extrinsic( frame_system::CheckNonce::::from(i), frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(f), + pallet_grandpa::ValidateEquivocationReport::::new(), ) }; let raw_payload = SignedPayload::from_raw( @@ -720,6 +721,7 @@ fn create_extrinsic( (), (), (), + (), ), ); let signature = raw_payload.using_encoded(|payload| signer.sign(payload)).into_runtime(); From 7ac9a2ee7f3fa6cb4e343c0290e8af75083ad2b4 Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 18 May 2020 13:47:51 +0100 Subject: [PATCH 36/77] adds frame-utilities-cli --- Cargo.lock | 26 +++++++- Cargo.toml | 1 + bin/node-template/node/src/command.rs | 3 +- bin/node/cli/Cargo.toml | 3 + bin/node/cli/src/cli.rs | 7 ++ bin/node/cli/src/command.rs | 12 +++- client/cli/Cargo.toml | 1 - client/cli/src/commands/mod.rs | 21 ------ client/cli/src/commands/tests.rs | 36 +--------- client/cli/src/runner.rs | 19 +----- utils/frame/frame-utilities-cli/Cargo.toml | 32 +++++++++ .../frame-utilities-cli/src}/generate.rs | 9 +-- .../src}/generate_node_key.rs | 4 +- .../frame/frame-utilities-cli/src}/insert.rs | 13 ++-- .../frame/frame-utilities-cli/src}/inspect.rs | 9 ++- .../frame/frame-utilities-cli/src}/key.rs | 16 ++++- utils/frame/frame-utilities-cli/src/lib.rs | 65 +++++++++++++++++++ .../src}/sign_transaction.rs | 21 +++--- 18 files changed, 188 insertions(+), 110 deletions(-) create mode 100644 utils/frame/frame-utilities-cli/Cargo.toml rename {client/cli/src/commands => utils/frame/frame-utilities-cli/src}/generate.rs (93%) rename {client/cli/src/commands => utils/frame/frame-utilities-cli/src}/generate_node_key.rs (94%) rename {client/cli/src/commands => utils/frame/frame-utilities-cli/src}/insert.rs (90%) rename {client/cli/src/commands => utils/frame/frame-utilities-cli/src}/inspect.rs (93%) rename {client/cli/src/commands => utils/frame/frame-utilities-cli/src}/key.rs (87%) create mode 100644 utils/frame/frame-utilities-cli/src/lib.rs rename {client/cli/src/commands => utils/frame/frame-utilities-cli/src}/sign_transaction.rs (84%) diff --git a/Cargo.lock b/Cargo.lock index ff6d2b6ca91fe..d33efbf4c41bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1610,6 +1610,30 @@ dependencies = [ "sp-api", ] +[[package]] +name = "frame-utilities-cli" +version = "2.0.0-dev" +dependencies = [ + "bip39", + "cli-utils", + "futures 0.1.29", + "hex", + "hyper 0.12.35", + "jsonrpc-core-client", + "libp2p", + "parity-scale-codec", + "sc-cli", + "sc-client-api", + "sc-rpc", + "sc-service", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "structopt", + "tempfile", +] + [[package]] name = "fs-swap" version = "0.2.4" @@ -3476,6 +3500,7 @@ dependencies = [ "frame-benchmarking-cli", "frame-support", "frame-system", + "frame-utilities-cli", "futures 0.3.5", "hex-literal", "jsonrpc-core", @@ -6079,7 +6104,6 @@ dependencies = [ "sc-client-api", "sc-informant", "sc-network", - "sc-rpc", "sc-service", "sc-telemetry", "sc-tracing", diff --git a/Cargo.toml b/Cargo.toml index 3b120fd38146e..054583903d96c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -174,6 +174,7 @@ members = [ "utils/cli-utils", "utils/fork-tree", "utils/frame/benchmarking-cli", + "utils/frame/frame-utilities-cli", "utils/frame/pallet-balances-cli", "utils/frame/rpc/support", "utils/frame/rpc/system", diff --git a/bin/node-template/node/src/command.rs b/bin/node-template/node/src/command.rs index aaaaf05814e82..da949ad85fe80 100644 --- a/bin/node-template/node/src/command.rs +++ b/bin/node-template/node/src/command.rs @@ -18,7 +18,6 @@ use crate::chain_spec; use crate::cli::Cli; use crate::service; use sc_cli::SubstrateCli; -use node_template_runtime::Runtime; impl SubstrateCli for Cli { fn impl_name() -> &'static str { @@ -67,7 +66,7 @@ pub fn run() -> sc_cli::Result<()> { match cli.subcommand { Some(ref subcommand) => { let runner = cli.create_runner(subcommand)?; - runner.run_subcommand::( + runner.run_subcommand( subcommand, |config| Ok(new_full_start!(config).0) ) diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index 9467908dfaf2c..d3e19d6f10e62 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -98,6 +98,7 @@ node-executor = { version = "2.0.0-dev", path = "../executor" } # CLI-specific dependencies sc-cli = { version = "0.8.0-dev", optional = true, path = "../../../client/cli" } pallet-balances-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/pallet-balances-cli" } +frame-utilities-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/frame-utilities-cli" } frame-benchmarking-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/benchmarking-cli" } node-inspect = { version = "0.8.0-dev", optional = true, path = "../inspect" } @@ -131,6 +132,7 @@ node-inspect = { version = "0.8.0-dev", optional = true, path = "../inspect" } frame-benchmarking-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/benchmarking-cli" } substrate-build-script-utils = { version = "2.0.0-dev", optional = true, path = "../../../utils/build-script-utils" } pallet-balances-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/pallet-balances-cli" } +frame-utilities-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/frame-utilities-cli" } [build-dependencies.sc-cli] version = "0.8.0-dev" @@ -151,6 +153,7 @@ cli = [ "sc-cli", "pallet-balances-cli", "frame-benchmarking-cli", + "frame-utilities-cli", "sc-service/db", "structopt", "substrate-build-script-utils", diff --git a/bin/node/cli/src/cli.rs b/bin/node/cli/src/cli.rs index 4b5e8f9952578..333e302af8647 100644 --- a/bin/node/cli/src/cli.rs +++ b/bin/node/cli/src/cli.rs @@ -17,6 +17,7 @@ use sc_cli::RunCmd; use structopt::StructOpt; use pallet_balances_cli::TransferCmd; +use frame_utilities_cli::{KeySubcommand, SignTransactionCmd}; /// An overarching CLI command definition. #[derive(Clone, Debug, StructOpt)] @@ -39,6 +40,12 @@ pub enum Subcommand { /// prints hex-encoded, signed, transfer extrinsic with given arguments. Transfer(TransferCmd), + /// key utilities + Key(KeySubcommand), + + /// sign transaction + SignTransaction(SignTransactionCmd), + /// The custom inspect subcommmand for decoding blocks and extrinsics. #[structopt( name = "inspect", diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index 8bd6cb78623aa..9f97384efd43a 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -90,6 +90,16 @@ pub fn run() -> Result<()> { Ok(()) } } + Some(Subcommand::Key(cmd)) => { + let runner = cli.create_runner(cmd)?; + + runner.sync_run(|_| cmd.run::()) + }, + Some(Subcommand::SignTransaction(cmd)) => { + let runner = cli.create_runner(cmd)?; + + runner.sync_run(|_| cmd.run::()) + } Some(Subcommand::Transfer(cmd)) => { let runner = cli.create_runner(cmd)?; @@ -98,7 +108,7 @@ pub fn run() -> Result<()> { Some(Subcommand::Base(subcommand)) => { let runner = cli.create_runner(subcommand)?; - runner.run_subcommand::( + runner.run_subcommand( subcommand, |config| Ok(new_full_start!(config).0) ) diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 8949596893515..40d4f793f2abb 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -40,7 +40,6 @@ sp-panic-handler = { version = "2.0.0-dev", path = "../../primitives/panic-handl sc-client-api = { version = "2.0.0-dev", path = "../api" } sp-blockchain = { version = "2.0.0-dev", path = "../../primitives/blockchain" } sc-network = { version = "0.8.0-dev", path = "../network" } -sc-rpc = { version = "2.0.0-dev", path = "../rpc" } sp-runtime = { version = "2.0.0-dev", path = "../../primitives/runtime" } sp-utils = { version = "2.0.0-dev", path = "../../primitives/utils" } sp-version = { version = "2.0.0-dev", path = "../../primitives/version" } diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 7a7db53b5bf29..5e30cbe5a229c 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -20,16 +20,10 @@ mod export_blocks_cmd; mod export_state_cmd; mod import_blocks_cmd; mod purge_chain_cmd; -mod generate_node_key; -mod generate; -mod inspect; -mod key; mod sign; -mod sign_transaction; mod utils; mod verify; mod vanity; -mod insert; mod revert_cmd; mod run_cmd; @@ -47,20 +41,13 @@ pub use self::{ export_state_cmd::ExportStateCmd, import_blocks_cmd::ImportBlocksCmd, purge_chain_cmd::PurgeChainCmd, - generate::GenerateCmd, - generate_node_key::GenerateNodeIdCmd, - insert::InsertCmd, sign::SignCmd, vanity::VanityCmd, - sign_transaction::SignTransactionCmd, verify::VerifyCmd, revert_cmd::RevertCmd, run_cmd::RunCmd, - inspect::InspectCmd, - key::KeySubcommand, utils::* }; -use cli_utils::{IndexFor, CallFor}; /// All core commands that are provided by default. /// @@ -90,15 +77,9 @@ pub enum Subcommand { /// Remove the whole chain data. PurgeChain(PurgeChainCmd), - /// Subcommand for key utilities, eg. generate-node-key, inspect. - Key(KeySubcommand), - /// Sign a message, with a given (secret) key Sign(SignCmd), - /// Sign transaction from encoded Call. Returns a signed and encoded UncheckedMortalCompactExtrinsic as hex. - SignTransaction(SignTransactionCmd), - /// Verify a signature for a message, provided on STDIN, with a given (public or secret) key. Verify(VerifyCmd), @@ -457,9 +438,7 @@ substrate_cli_subcommands!( CheckBlock, Revert, PurgeChain, - Key, Sign, - SignTransaction, Verify, Vanity ); diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs index b84a0ea54f0d4..88915ba625e00 100644 --- a/client/cli/src/commands/tests.rs +++ b/client/cli/src/commands/tests.rs @@ -14,42 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -use super::*; -use tempfile::Builder; -use std::io::Read; -use crate::commands::inspect::InspectCmd; +use super::{SignCmd, VanityCmd}; +use structopt::StructOpt; use crate::Error; -#[test] -fn generate() { - let generate = GenerateCmd::from_iter(&["generate", "--password", "12345"]); - assert!(generate.run().is_ok()) -} - -#[test] -fn generate_node_key() { - let mut file = Builder::new() - .prefix("keyfile") - .tempfile() - .unwrap(); - let generate = GenerateNodeIdCmd::from_iter(&["generate-node-key", "--file", "/tmp/keyfile"]); - assert!(generate.run().is_ok()); - let mut buf = String::new(); - assert!(file.read_to_string(&mut buf).is_ok()); - assert!(hex::decode(buf).is_ok()); -} - -#[test] -fn inspect() { - let words = "remember fiber forum demise paper uniform squirrel feel access exclude casual effort"; - let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; - - let inspect = InspectCmd::from_iter(&["inspect-key", "--uri", words, "--password", "12345"]); - assert!(inspect.run().is_ok()); - - let inspect = InspectCmd::from_iter(&["inspect-key", "--uri", seed]); - assert!(inspect.run().is_ok()); -} #[test] fn sign() { diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index 12e9e6ff9f530..7b149a00e1d19 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -26,14 +26,7 @@ use log::info; use sc_service::{AbstractService, Configuration, Role, ServiceBuilderCommand, TaskType}; use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; use sp_utils::metrics::{TOKIO_THREADS_ALIVE, TOKIO_THREADS_TOTAL}; -use cli_utils::{AccountIdFor, AddressFor, IndexFor, BalanceFor, CallFor, RuntimeAdapter}; -use std::convert::TryFrom; -use sp_core::crypto::Ss58Codec; -use parity_scale_codec::Codec; -use std::{ - str::FromStr, marker::PhantomData, - sync::Arc, fmt::{Debug, Display} -}; +use std::{str::FromStr, marker::PhantomData, sync::Arc, fmt::Debug}; #[cfg(target_family = "unix")] async fn main(func: F) -> std::result::Result<(), Box> @@ -183,7 +176,7 @@ impl Runner { /// A helper function that runs a future with tokio and stops if the process receives the signal /// `SIGTERM` or `SIGINT`. - pub fn run_subcommand(self, subcommand: &Subcommand, builder: B) -> Result<()> + pub fn run_subcommand(self, subcommand: &Subcommand, builder: B) -> Result<()> where B: FnOnce(Configuration) -> sc_service::error::Result, BC: ServiceBuilderCommand + Unpin, @@ -191,12 +184,6 @@ impl Runner { <<::Header as HeaderT>::Number as FromStr>::Err: Debug, ::Hash: FromStr, <::Hash as FromStr>::Err: Debug, - RA: RuntimeAdapter, - AccountIdFor: for<'a> TryFrom<&'a [u8], Error = ()> + Ss58Codec, - AddressFor: From>, - as FromStr>::Err: Display, - as FromStr>::Err: Display, - CallFor: Codec, { match subcommand { Subcommand::BuildSpec(cmd) => cmd.run(self.config), @@ -210,13 +197,11 @@ impl Runner { run_until_exit(self.tokio_runtime, cmd.run(self.config, builder)) } Subcommand::ExportState(cmd) => cmd.run(self.config, builder), - Subcommand::Key(cmd) => cmd.run::(), Subcommand::Revert(cmd) => cmd.run(self.config, builder), Subcommand::PurgeChain(cmd) => cmd.run(self.config), Subcommand::Sign(cmd) => cmd.run(), Subcommand::Verify(cmd) => cmd.run(), Subcommand::Vanity(cmd) => cmd.run(), - Subcommand::SignTransaction(cmd) => cmd.run::(), } } diff --git a/utils/frame/frame-utilities-cli/Cargo.toml b/utils/frame/frame-utilities-cli/Cargo.toml new file mode 100644 index 0000000000000..77a9b59a380e8 --- /dev/null +++ b/utils/frame/frame-utilities-cli/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "frame-utilities-cli" +version = "2.0.0-dev" +authors = ["Parity Technologies "] +edition = "2018" +license = "GPL-3.0" +homepage = "https://substrate.dev" +repository = "https://github.com/paritytech/substrate/" +description = "CLI utils" +documentation = "https://docs.rs/cli-utils" + +[dependencies] +sp-core = { version = "2.0.0-dev", path = "../../../primitives/core" } +sc-cli = { version = "0.8.0-dev", path = "../../../client/cli" } +sp-runtime = { version = "2.0.0-dev", path = "../../../primitives/runtime" } +structopt = "0.3.8" +codec = { version = "1.3.0", package = "parity-scale-codec" } +cli-utils = { path = "../../cli-utils", version = "2.0.0-dev" } +hex = "0.4.2" +serde = "1.0.106" +hyper = "0.12.35" +libp2p = "0.18.1" +bip39 = "0.6.0-beta.1" +jsonrpc-core-client = { version = "14.0.3", features = ["http"] } +sc-rpc = { version = "2.0.0-dev", path = "../../../client/rpc" } +sc-service = { version = "0.8.0-dev", default-features = false, path = "../../../client/service" } +sc-client-api = { version = "2.0.0-dev", default-features = false, path = "../../../client/api" } +futures01 = { package = "futures", version = "0.1.29" } + +[dev-dependencies] +tempfile = "3.1.0" +sp-io = { version = "2.0.0-dev", path = "../../../primitives/io" } diff --git a/client/cli/src/commands/generate.rs b/utils/frame/frame-utilities-cli/src/generate.rs similarity index 93% rename from client/cli/src/commands/generate.rs rename to utils/frame/frame-utilities-cli/src/generate.rs index 5d52422ea0c43..7a1de8a7c9d6b 100644 --- a/client/cli/src/commands/generate.rs +++ b/utils/frame/frame-utilities-cli/src/generate.rs @@ -15,13 +15,10 @@ // along with Substrate. If not, see . //! Implementation of the `generate` subcommand - -use super::{SharedParams}; -use crate::error::{self, Error}; use bip39::{MnemonicType, Mnemonic, Language}; use structopt::StructOpt; -use crate::{ - print_from_uri, CliConfiguration, KeystoreParams, +use sc_cli::{ + print_from_uri, CliConfiguration, KeystoreParams, SharedParams, Error, with_crypto_scheme, NetworkSchemeFlag, OutputTypeFlag, CryptoSchemeFlag, }; @@ -56,7 +53,7 @@ pub struct GenerateCmd { impl GenerateCmd { /// Run the command - pub fn run(&self) -> error::Result<()> { + pub fn run(&self) -> Result<(), Error> { let words = match self.words { Some(words) => { MnemonicType::for_word_count(words) diff --git a/client/cli/src/commands/generate_node_key.rs b/utils/frame/frame-utilities-cli/src/generate_node_key.rs similarity index 94% rename from client/cli/src/commands/generate_node_key.rs rename to utils/frame/frame-utilities-cli/src/generate_node_key.rs index 18c99b6aafa3e..b6bce3c9233e6 100644 --- a/client/cli/src/commands/generate_node_key.rs +++ b/utils/frame/frame-utilities-cli/src/generate_node_key.rs @@ -16,7 +16,7 @@ //! Implementation of the `generate-node-key` subcommand -use crate::{error, SharedParams, CliConfiguration}; +use sc_cli::{Error, SharedParams, CliConfiguration}; use structopt::StructOpt; use std::{path::PathBuf, fs}; use libp2p::identity::{ed25519 as libp2p_ed25519, PublicKey}; @@ -39,7 +39,7 @@ pub struct GenerateNodeIdCmd { impl GenerateNodeIdCmd { /// Run the command - pub fn run(&self) -> error::Result<()> { + pub fn run(&self) -> Result<(), Error> { let file = &self.file; let keypair = libp2p_ed25519::Keypair::generate(); diff --git a/client/cli/src/commands/insert.rs b/utils/frame/frame-utilities-cli/src/insert.rs similarity index 90% rename from client/cli/src/commands/insert.rs rename to utils/frame/frame-utilities-cli/src/insert.rs index 0fd04d5e9b5b4..4641362086033 100644 --- a/client/cli/src/commands/insert.rs +++ b/utils/frame/frame-utilities-cli/src/insert.rs @@ -16,8 +16,11 @@ //! Implementation of the `insert` subcommand -use crate::{error, pair_from_suri, CliConfiguration, KeystoreParams, with_crypto_scheme, CryptoSchemeFlag}; -use super::{SharedParams, read_uri}; +use sc_cli::{ + Error, pair_from_suri, CliConfiguration, + KeystoreParams, with_crypto_scheme, + CryptoSchemeFlag, SharedParams, read_uri, +}; use structopt::StructOpt; use sp_core::{crypto::KeyTypeId, Bytes}; use std::convert::TryFrom; @@ -26,7 +29,7 @@ use hyper::rt; use sc_rpc::author::AuthorClient; use jsonrpc_core_client::transports::http; use serde::{de::DeserializeOwned, Serialize}; -use cli_utils::{HashFor, RuntimeAdapter,}; +use cli_utils::{HashFor, RuntimeAdapter}; /// The `insert` command #[derive(Debug, StructOpt, Clone)] @@ -64,7 +67,7 @@ pub struct InsertCmd { impl InsertCmd { /// Run the command - pub fn run(&self) -> error::Result<()> + pub fn run(&self) -> Result<(), Error> where RA: RuntimeAdapter, HashFor: DeserializeOwned + Serialize + Send + Sync, @@ -85,7 +88,7 @@ impl InsertCmd { // Just checking let _key_type_id = KeyTypeId::try_from(key_type.as_str()) .map_err(|_| { - error::Error::Other("Cannot convert argument to keytype: argument should be 4-character string".into()) + Error::Other("Cannot convert argument to keytype: argument should be 4-character string".into()) })?; diff --git a/client/cli/src/commands/inspect.rs b/utils/frame/frame-utilities-cli/src/inspect.rs similarity index 93% rename from client/cli/src/commands/inspect.rs rename to utils/frame/frame-utilities-cli/src/inspect.rs index ef8a12aac4418..76ab7b43c7231 100644 --- a/client/cli/src/commands/inspect.rs +++ b/utils/frame/frame-utilities-cli/src/inspect.rs @@ -16,11 +16,10 @@ //! Implementation of the `inspect` subcommand -use crate::{ - error, print_from_uri, CliConfiguration, KeystoreParams, - with_crypto_scheme, NetworkSchemeFlag, OutputTypeFlag, CryptoSchemeFlag, +use sc_cli::{ + print_from_uri, CliConfiguration, KeystoreParams, SharedParams, read_uri, + with_crypto_scheme, NetworkSchemeFlag, OutputTypeFlag, CryptoSchemeFlag, Error, }; -use super::{SharedParams, read_uri}; use structopt::StructOpt; /// The `inspect` command @@ -59,7 +58,7 @@ pub struct InspectCmd { impl InspectCmd { /// Run the command - pub fn run(&self) -> error::Result<()> { + pub fn run(&self) -> Result<(), Error> { let uri = read_uri(self.uri.as_ref())?; let pass = self.keystore_params.read_password().ok(); diff --git a/client/cli/src/commands/key.rs b/utils/frame/frame-utilities-cli/src/key.rs similarity index 87% rename from client/cli/src/commands/key.rs rename to utils/frame/frame-utilities-cli/src/key.rs index f04e639467626..37ab5221ae351 100644 --- a/client/cli/src/commands/key.rs +++ b/utils/frame/frame-utilities-cli/src/key.rs @@ -13,11 +13,21 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -use crate::{error, substrate_cli_subcommands}; + +//! Key related CLI utilities + +use sc_cli::{Error, substrate_cli_subcommands}; use structopt::StructOpt; use cli_utils::{HashFor, RuntimeAdapter}; use serde::{de::DeserializeOwned, Serialize}; -use super::{GenerateNodeIdCmd, GenerateCmd, InspectCmd, InsertCmd}; + + +use crate::{ + generate_node_key::GenerateNodeIdCmd, + generate::GenerateCmd, + inspect::InspectCmd, + insert::InsertCmd +}; /// key utilities for the cli. #[derive(Debug, Clone, StructOpt)] @@ -37,7 +47,7 @@ pub enum KeySubcommand { impl KeySubcommand { /// run the key subcommands - pub fn run(&self) -> error::Result<()> + pub fn run(&self) -> Result<(), Error> where RA: RuntimeAdapter, HashFor: DeserializeOwned + Serialize + Send + Sync, diff --git a/utils/frame/frame-utilities-cli/src/lib.rs b/utils/frame/frame-utilities-cli/src/lib.rs new file mode 100644 index 0000000000000..93c179c1ff062 --- /dev/null +++ b/utils/frame/frame-utilities-cli/src/lib.rs @@ -0,0 +1,65 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! frame-system CLI utilities + +mod generate; +mod generate_node_key; +mod insert; +mod inspect; +mod key; +mod sign_transaction; + +pub use {key::KeySubcommand, sign_transaction::SignTransactionCmd}; + +#[cfg(test)] +mod tests { + use super::{generate::GenerateCmd, generate_node_key::GenerateNodeIdCmd, inspect::InspectCmd}; + use tempfile::Builder; + use structopt::StructOpt; + use std::io::Read; + + #[test] + fn generate() { + let generate = GenerateCmd::from_iter(&["generate", "--password", "12345"]); + assert!(generate.run().is_ok()) + } + + #[test] + fn generate_node_key() { + let mut file = Builder::new().prefix("keyfile").tempfile().unwrap(); + let generate = + GenerateNodeIdCmd::from_iter(&["generate-node-key", "--file", "/tmp/keyfile"]); + assert!(generate.run().is_ok()); + let mut buf = String::new(); + assert!(file.read_to_string(&mut buf).is_ok()); + assert!(hex::decode(buf).is_ok()); + } + + #[test] + fn inspect() { + let words = + "remember fiber forum demise paper uniform squirrel feel access exclude casual effort"; + let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; + + let inspect = + InspectCmd::from_iter(&["inspect-key", "--uri", words, "--password", "12345"]); + assert!(inspect.run().is_ok()); + + let inspect = InspectCmd::from_iter(&["inspect-key", "--uri", seed]); + assert!(inspect.run().is_ok()); + } +} diff --git a/client/cli/src/commands/sign_transaction.rs b/utils/frame/frame-utilities-cli/src/sign_transaction.rs similarity index 84% rename from client/cli/src/commands/sign_transaction.rs rename to utils/frame/frame-utilities-cli/src/sign_transaction.rs index a711070093606..35b9058583901 100644 --- a/client/cli/src/commands/sign_transaction.rs +++ b/utils/frame/frame-utilities-cli/src/sign_transaction.rs @@ -15,16 +15,16 @@ // along with Substrate. If not, see . //! Implementation of the `sign-transaction` subcommand -use crate::{ - error, CliConfiguration, KeystoreParams, - with_crypto_scheme, create_extrinsic_for, CryptoSchemeFlag +use sc_cli::{ + Error, CliConfiguration, KeystoreParams, SharedParams, + pair_from_suri, decode_hex,with_crypto_scheme, create_extrinsic_for, + CryptoSchemeFlag, }; -use super::{SharedParams, IndexFor, CallFor, pair_from_suri, decode_hex}; use structopt::StructOpt; -use parity_scale_codec::{Codec, Encode, Decode}; +use codec::{Codec, Encode, Decode}; use std::{str::FromStr, fmt::Display}; use sp_runtime::MultiSigner; -use cli_utils::RuntimeAdapter; +use cli_utils::{RuntimeAdapter, IndexFor, CallFor}; type Call = Vec; @@ -62,7 +62,7 @@ pub struct SignTransactionCmd { impl SignTransactionCmd { /// Run the command - pub fn run(&self) -> error::Result<()> + pub fn run(&self) -> Result<(), Error> where RA: RuntimeAdapter, as FromStr>::Err: Display, @@ -73,10 +73,7 @@ impl SignTransactionCmd { let call = CallFor::::decode(&mut &self.call[..])?; let pass = self.keystore_params.read_password()?; - with_crypto_scheme!( - self.crypto_scheme.scheme, - print_ext(&self.suri, &pass, call, nonce) - ) + with_crypto_scheme!(self.crypto_scheme.scheme, print_ext(&self.suri, &pass, call, nonce)) } } @@ -92,7 +89,7 @@ impl CliConfiguration for SignTransactionCmd { } -fn print_ext(uri: &str, pass: &str, call: CallFor, nonce: IndexFor) -> error::Result<()> +fn print_ext(uri: &str, pass: &str, call: CallFor, nonce: IndexFor) -> Result<(), Error> where Pair: sp_core::Pair, Pair::Public: Into, From ce642a2bd84f6cf85980ca1911848aab5b3462e4 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Mon, 18 May 2020 14:05:21 +0100 Subject: [PATCH 37/77] Apply suggestions from code review Co-authored-by: Benjamin Kampmann --- client/cli/src/commands/sign.rs | 14 ++++--- client/cli/src/commands/tests.rs | 14 ++++--- client/cli/src/commands/utils.rs | 44 +++++++++++----------- client/cli/src/commands/vanity.rs | 14 ++++--- client/cli/src/commands/verify.rs | 14 ++++--- utils/cli-utils/src/lib.rs | 27 ++++++------- utils/frame/pallet-balances-cli/src/lib.rs | 29 +++++++------- 7 files changed, 84 insertions(+), 72 deletions(-) diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs index ffad2244a9e37..25617a010e379 100644 --- a/client/cli/src/commands/sign.rs +++ b/client/cli/src/commands/sign.rs @@ -1,18 +1,20 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. -// Substrate is free software: you can redistribute it and/or modify +// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or +// the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Substrate is distributed in the hope that it will be useful, +// This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . +// along with this program. If not, see . //! Implementation of the `sign` subcommand use crate::{error, pair_from_suri, CliConfiguration, KeystoreParams, with_crypto_scheme, CryptoSchemeFlag}; diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs index 88915ba625e00..43cb5715f6fd8 100644 --- a/client/cli/src/commands/tests.rs +++ b/client/cli/src/commands/tests.rs @@ -1,18 +1,20 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. -// Substrate is free software: you can redistribute it and/or modify +// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or +// the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Substrate is distributed in the hope that it will be useful, +// This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . +// along with this program. If not, see . use super::{SignCmd, VanityCmd}; use structopt::StructOpt; diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 1c400fa9f1ed1..c0ca1fbebfb41 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -1,18 +1,20 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. -// Substrate is free software: you can redistribute it and/or modify +// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or +// the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Substrate is distributed in the hope that it will be useful, +// This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . +// along with this program. If not, see . //! subcommand utilities use std::{io::Read, path::PathBuf}; @@ -81,11 +83,11 @@ pub fn print_from_uri( Public key (hex): {}\n \ Account ID: {}\n \ SS58 Address: {}", - uri, - format_seed::(seed), - format_public_key::(public_key.clone()), - format_account_id::(public_key), - pair.public().into().into_account().to_ss58check(), + uri, + format_seed::(seed), + format_public_key::(public_key.clone()), + format_account_id::(public_key), + pair.public().into().into_account().to_ss58check(), ); }, } @@ -109,11 +111,11 @@ pub fn print_from_uri( Public key (hex): {}\n \ Account ID: {}\n \ SS58 Address: {}", - uri, - if let Some(seed) = seed { format_seed::(seed) } else { "n/a".into() }, - format_public_key::(public_key.clone()), - format_account_id::(public_key), - pair.public().into().into_account().to_ss58check(), + uri, + if let Some(seed) = seed { format_seed::(seed) } else { "n/a".into() }, + format_public_key::(public_key.clone()), + format_account_id::(public_key), + pair.public().into().into_account().to_ss58check(), ); }, } @@ -137,11 +139,11 @@ pub fn print_from_uri( Public key (hex): {}\n \ Account ID: {}\n \ SS58 Address: {}", - uri, - String::from(v), - format_public_key::(public_key.clone()), - format_account_id::(public_key.clone()), - public_key.to_ss58check_with_version(v), + uri, + String::from(v), + format_public_key::(public_key.clone()), + format_account_id::(public_key.clone()), + public_key.to_ss58check_with_version(v), ); }, } diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index c706d548a1a21..b4f8ae5f63072 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -1,18 +1,20 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. -// Substrate is free software: you can redistribute it and/or modify +// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or +// the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Substrate is distributed in the hope that it will be useful, +// This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . +// along with this program. If not, see . //! implementation of the `vanity` subcommand diff --git a/client/cli/src/commands/verify.rs b/client/cli/src/commands/verify.rs index a41b34b694174..9278dec81d856 100644 --- a/client/cli/src/commands/verify.rs +++ b/client/cli/src/commands/verify.rs @@ -1,18 +1,20 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. -// Substrate is free software: you can redistribute it and/or modify +// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or +// the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Substrate is distributed in the hope that it will be useful, +// This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . +// along with this program. If not, see . //! implementation of the `verify` subcommand diff --git a/utils/cli-utils/src/lib.rs b/utils/cli-utils/src/lib.rs index 30aea660f4abb..a3958f3d10d37 100644 --- a/utils/cli-utils/src/lib.rs +++ b/utils/cli-utils/src/lib.rs @@ -1,18 +1,19 @@ -// Copyright 2019-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . +// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. //! Utilities for cli. #![cfg_attr(not(feature = "std"), no_std)] diff --git a/utils/frame/pallet-balances-cli/src/lib.rs b/utils/frame/pallet-balances-cli/src/lib.rs index 9032f9b55a1f5..83ab7ae625758 100644 --- a/utils/frame/pallet-balances-cli/src/lib.rs +++ b/utils/frame/pallet-balances-cli/src/lib.rs @@ -1,18 +1,19 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . +// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. //! Implementation of the `transfer` cli subcommand for nodes that use the pallet-balances crate. @@ -164,4 +165,4 @@ mod tests { assert!(matches!(transfer.run::(), Err(Error::Input(_)))) }); } -} \ No newline at end of file +} From 2937b8cdedd937f7992de65751b9cf2b8ad8af78 Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 18 May 2020 16:30:09 +0100 Subject: [PATCH 38/77] removes frame from sc-cli, fix license --- Cargo.lock | 4 +- client/cli/Cargo.toml | 2 - client/cli/src/commands/utils.rs | 33 +---------------- utils/cli-utils/Cargo.toml | 9 +++-- utils/cli-utils/src/lib.rs | 37 ++++++++++++++++++- .../src/sign_transaction.rs | 4 +- utils/frame/pallet-balances-cli/Cargo.toml | 2 +- utils/frame/pallet-balances-cli/src/lib.rs | 4 +- 8 files changed, 50 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4347391010a07..088d201bd85a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -666,6 +666,8 @@ version = "2.0.0-dev" dependencies = [ "frame-system", "pallet-balances", + "parity-scale-codec", + "sp-core", "sp-runtime", ] @@ -6083,11 +6085,9 @@ dependencies = [ "bip39", "chrono", "clap", - "cli-utils", "derive_more", "env_logger 0.7.1", "fdlimit", - "futures 0.1.29", "futures 0.3.5", "hex", "hyper 0.12.35", diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 31ef11907c022..8ca9baa550cef 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -24,7 +24,6 @@ lazy_static = "1.4.0" app_dirs = "1.2.1" tokio = { version = "0.2.9", features = [ "signal", "rt-core", "rt-threaded" ] } futures = "0.3.4" -futures01 = { package = "futures", version = "0.1.29" } fdlimit = "0.1.4" serde = "1.0.106" libp2p = "0.18.1" @@ -54,7 +53,6 @@ structopt = "0.3.8" sc-tracing = { version = "2.0.0-dev", path = "../tracing" } chrono = "0.4.10" parity-util-mem = { version = "0.6.1", default-features = false, features = ["primitive-types"] } -cli-utils = { path = "../../utils/cli-utils" , version = "2.0.0-dev" } [target.'cfg(not(target_os = "unknown"))'.dependencies] rpassword = "4.0.1" diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index c0ca1fbebfb41..0e7a8b29055d2 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -22,12 +22,9 @@ use sp_core::{ Pair, hexdisplay::HexDisplay, crypto::{Ss58Codec, Ss58AddressFormat}, }; -use sp_runtime::{MultiSigner, traits::IdentifyAccount, AccountId32}; +use sp_runtime::{MultiSigner, traits::IdentifyAccount}; use crate::{OutputType, error::{self, Error}}; use serde_json::json; -use cli_utils::{IndexFor, RuntimeAdapter}; -use sp_runtime::generic::{UncheckedExtrinsic, SignedPayload}; -use parity_scale_codec::Encode; /// Public key type for Runtime pub type PublicFor

=

::Public; @@ -224,31 +221,3 @@ macro_rules! with_crypto_scheme { }; } -/// create an extrinsic for the runtime. -pub fn create_extrinsic_for( - call: Call, - nonce: IndexFor, - signer: Pair, -) -> Result, &'static str> - where - Call: Encode, - Pair: sp_core::Pair, - Pair::Public: Into, - Pair::Signature: Encode, - RA: RuntimeAdapter, -{ - let extra = RA::build_extra(nonce); - let payload = SignedPayload::new(call, extra) - .map_err(|_| "Transaction validity error")?; - - let signature = payload.using_encoded(|payload| signer.sign(payload)); - let signer = signer.public().into().into_account(); - let (function, extra, _) = payload.deconstruct(); - - Ok(UncheckedExtrinsic::new_signed( - function, - signer, - signature, - extra, - )) -} diff --git a/utils/cli-utils/Cargo.toml b/utils/cli-utils/Cargo.toml index 3d783d3964cee..c0c3bebe0d11e 100644 --- a/utils/cli-utils/Cargo.toml +++ b/utils/cli-utils/Cargo.toml @@ -10,9 +10,11 @@ description = "CLI utils" documentation = "https://docs.rs/cli-utils" [dependencies] -frame-system = { version = "2.0.0-alpha.4", default-features = false, path = "../../frame/system" } -pallet-balances = { version = "2.0.0-alpha.4", default-features = false, path = "../../frame/balances" } -sp-runtime = { version = "2.0.0-alpha.4", default-features = false, path = "../../primitives/runtime" } +frame-system = { version = "2.0.0-alpha.7", default-features = false, path = "../../frame/system" } +pallet-balances = { version = "2.0.0-alpha.7", default-features = false, path = "../../frame/balances" } +sp-runtime = { version = "2.0.0-alpha.7", default-features = false, path = "../../primitives/runtime" } +sp-core = { version = "2.0.0-alpha.7", default-features = false, path = "../../primitives/core" } +codec = { version = "1.3.0", package = "parity-scale-codec" } [features] default = ["std"] @@ -20,4 +22,5 @@ std = [ "frame-system/std", "pallet-balances/std", "sp-runtime/std", + "sp-core/std", ] diff --git a/utils/cli-utils/src/lib.rs b/utils/cli-utils/src/lib.rs index a3958f3d10d37..c715c71956425 100644 --- a/utils/cli-utils/src/lib.rs +++ b/utils/cli-utils/src/lib.rs @@ -18,7 +18,12 @@ //! Utilities for cli. #![cfg_attr(not(feature = "std"), no_std)] -use sp_runtime::traits::{StaticLookup, SignedExtension}; +use sp_runtime::{ + MultiSigner, AccountId32, + traits::{StaticLookup, SignedExtension, IdentifyAccount}, + generic::{UncheckedExtrinsic, SignedPayload}, +}; +use codec::Encode; pub use pallet_balances::Call as BalancesCall; /// AccountIndex type for Runtime @@ -42,3 +47,33 @@ pub trait RuntimeAdapter: frame_system::Trait + pallet_balances::Trait { /// build extras for inclusion in extrinsics fn build_extra(index: IndexFor) -> Self::Extra; } + + +/// create an extrinsic for the runtime. +pub fn create_extrinsic_for( + call: Call, + nonce: IndexFor, + signer: Pair, +) -> Result, &'static str> + where + Call: Encode, + Pair: sp_core::Pair, + Pair::Public: Into, + Pair::Signature: Encode, + RA: RuntimeAdapter, +{ + let extra = RA::build_extra(nonce); + let payload = SignedPayload::new(call, extra) + .map_err(|_| "Transaction validity error")?; + + let signature = payload.using_encoded(|payload| signer.sign(payload)); + let signer = signer.public().into().into_account(); + let (function, extra, _) = payload.deconstruct(); + + Ok(UncheckedExtrinsic::new_signed( + function, + signer, + signature, + extra, + )) +} diff --git a/utils/frame/frame-utilities-cli/src/sign_transaction.rs b/utils/frame/frame-utilities-cli/src/sign_transaction.rs index 35b9058583901..25f8847057e8f 100644 --- a/utils/frame/frame-utilities-cli/src/sign_transaction.rs +++ b/utils/frame/frame-utilities-cli/src/sign_transaction.rs @@ -17,14 +17,14 @@ //! Implementation of the `sign-transaction` subcommand use sc_cli::{ Error, CliConfiguration, KeystoreParams, SharedParams, - pair_from_suri, decode_hex,with_crypto_scheme, create_extrinsic_for, + pair_from_suri, decode_hex,with_crypto_scheme, CryptoSchemeFlag, }; use structopt::StructOpt; use codec::{Codec, Encode, Decode}; use std::{str::FromStr, fmt::Display}; use sp_runtime::MultiSigner; -use cli_utils::{RuntimeAdapter, IndexFor, CallFor}; +use cli_utils::{RuntimeAdapter, IndexFor, CallFor, create_extrinsic_for}; type Call = Vec; diff --git a/utils/frame/pallet-balances-cli/Cargo.toml b/utils/frame/pallet-balances-cli/Cargo.toml index 3a5e1655c3610..8247579d8259d 100644 --- a/utils/frame/pallet-balances-cli/Cargo.toml +++ b/utils/frame/pallet-balances-cli/Cargo.toml @@ -20,5 +20,5 @@ hex = "0.4.2" [dev-dependencies] sp-io = { version = "2.0.0-dev", path = "../../../primitives/io" } -frame-system = { version = "2.0.0-alpha.4", path = "../../../frame/system" } +frame-system = { version = "2.0.0-alpha.7", path = "../../../frame/system" } substrate-test-runtime = { version = "2.0.0-dev", features = ["indices-lookup"], path = "../../../test-utils/runtime" } diff --git a/utils/frame/pallet-balances-cli/src/lib.rs b/utils/frame/pallet-balances-cli/src/lib.rs index 83ab7ae625758..5309184350c1f 100644 --- a/utils/frame/pallet-balances-cli/src/lib.rs +++ b/utils/frame/pallet-balances-cli/src/lib.rs @@ -18,7 +18,7 @@ //! Implementation of the `transfer` cli subcommand for nodes that use the pallet-balances crate. use sc_cli::{ - Error, SharedParams, pair_from_suri, create_extrinsic_for, with_crypto_scheme, + Error, SharedParams, pair_from_suri, with_crypto_scheme, CryptoSchemeFlag, decode_hex, CliConfiguration, KeystoreParams, }; use structopt::StructOpt; @@ -27,7 +27,7 @@ use codec::Encode; use sp_runtime::MultiSigner; use std::convert::TryFrom; use sp_core::crypto::Ss58Codec; -use cli_utils::{AddressFor, IndexFor, BalanceFor, BalancesCall, AccountIdFor, RuntimeAdapter}; +use cli_utils::{AddressFor, IndexFor, BalanceFor, BalancesCall, AccountIdFor, RuntimeAdapter, create_extrinsic_for}; /// The `transfer` command #[derive(Debug, StructOpt, Clone)] From a9d25a3bd2ceed6648e0602ab0be8d126f7fb323 Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 18 May 2020 16:41:05 +0100 Subject: [PATCH 39/77] my editor and ci disagrees on line width --- utils/frame/frame-utilities-cli/src/inspect.rs | 5 +++-- utils/frame/frame-utilities-cli/src/sign_transaction.rs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/utils/frame/frame-utilities-cli/src/inspect.rs b/utils/frame/frame-utilities-cli/src/inspect.rs index 76ab7b43c7231..9fb0a9433d749 100644 --- a/utils/frame/frame-utilities-cli/src/inspect.rs +++ b/utils/frame/frame-utilities-cli/src/inspect.rs @@ -29,8 +29,9 @@ use structopt::StructOpt; about = "Gets a public key and a SS58 address from the provided Secret URI" )] pub struct InspectCmd { - /// A Key URI to be inspected. May be a secret seed, secret URI (with derivation paths and password), SS58 or - /// public URI. If the value is a file, the file content is used as URI. + /// A Key URI to be inspected. May be a secret seed, secret URI + /// (with derivation paths and password), SS58 or public URI. + /// If the value is a file, the file content is used as URI. /// If not given, you will be prompted for the URI. #[structopt(long)] uri: Option, diff --git a/utils/frame/frame-utilities-cli/src/sign_transaction.rs b/utils/frame/frame-utilities-cli/src/sign_transaction.rs index 25f8847057e8f..2537c70975c4f 100644 --- a/utils/frame/frame-utilities-cli/src/sign_transaction.rs +++ b/utils/frame/frame-utilities-cli/src/sign_transaction.rs @@ -32,7 +32,8 @@ type Call = Vec; #[derive(Debug, StructOpt, Clone)] #[structopt( name = "sign-transaction", - about = "Sign transaction from encoded Call. Returns a signed and encoded UncheckedMortalCompactExtrinsic as hex." + about = "Sign transaction from encoded Call.\ + Returns a signed and encoded UncheckedMortalCompactExtrinsic as hex." )] pub struct SignTransactionCmd { /// The secret key URI. From f5d0e463132696d954fb79050ef93213a0bc354c Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 18 May 2020 16:43:45 +0100 Subject: [PATCH 40/77] bump spec version --- bin/node/runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 99b718e97c454..e2b942ff07030 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -94,7 +94,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 248, + spec_version: 249, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 1a556ca65505a69bec5cc0c2f55e52b6a4a182f9 Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 18 May 2020 18:08:52 +0100 Subject: [PATCH 41/77] turn off default features for parity-scale-codec --- utils/cli-utils/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/cli-utils/Cargo.toml b/utils/cli-utils/Cargo.toml index c0c3bebe0d11e..a03ce89ba08fa 100644 --- a/utils/cli-utils/Cargo.toml +++ b/utils/cli-utils/Cargo.toml @@ -14,7 +14,7 @@ frame-system = { version = "2.0.0-alpha.7", default-features = false, path = ".. pallet-balances = { version = "2.0.0-alpha.7", default-features = false, path = "../../frame/balances" } sp-runtime = { version = "2.0.0-alpha.7", default-features = false, path = "../../primitives/runtime" } sp-core = { version = "2.0.0-alpha.7", default-features = false, path = "../../primitives/core" } -codec = { version = "1.3.0", package = "parity-scale-codec" } +codec = { version = "1.3.0", default-features = false, package = "parity-scale-codec" } [features] default = ["std"] From 5a0616b291f8f8d56f888a8c3baf510db31109c0 Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 18 May 2020 18:15:21 +0100 Subject: [PATCH 42/77] enable full_crypto feature for sp-core in cli-utils --- utils/cli-utils/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/cli-utils/Cargo.toml b/utils/cli-utils/Cargo.toml index a03ce89ba08fa..e5db8fb1d2dad 100644 --- a/utils/cli-utils/Cargo.toml +++ b/utils/cli-utils/Cargo.toml @@ -13,7 +13,7 @@ documentation = "https://docs.rs/cli-utils" frame-system = { version = "2.0.0-alpha.7", default-features = false, path = "../../frame/system" } pallet-balances = { version = "2.0.0-alpha.7", default-features = false, path = "../../frame/balances" } sp-runtime = { version = "2.0.0-alpha.7", default-features = false, path = "../../primitives/runtime" } -sp-core = { version = "2.0.0-alpha.7", default-features = false, path = "../../primitives/core" } +sp-core = { version = "2.0.0-alpha.7", default-features = false, features = ["full_crypto"], path = "../../primitives/core" } codec = { version = "1.3.0", default-features = false, package = "parity-scale-codec" } [features] From 69ab3ee401ecefaf26d2cacbe338b231bcc703ea Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 18 May 2020 18:55:39 +0100 Subject: [PATCH 43/77] merge frame-utilities-cli with pallet-balances-cli --- Cargo.lock | 19 +------ Cargo.toml | 1 - bin/node/cli/Cargo.toml | 7 +-- bin/node/cli/src/cli.rs | 3 +- utils/cli-utils/src/lib.rs | 36 +------------ utils/frame/frame-utilities-cli/Cargo.toml | 5 ++ utils/frame/frame-utilities-cli/src/key.rs | 1 - utils/frame/frame-utilities-cli/src/lib.rs | 6 +++ .../src/sign_transaction.rs | 3 +- .../src/transfer.rs} | 3 +- utils/frame/frame-utilities-cli/src/utils.rs | 51 +++++++++++++++++++ utils/frame/pallet-balances-cli/Cargo.toml | 24 --------- 12 files changed, 72 insertions(+), 87 deletions(-) rename utils/frame/{pallet-balances-cli/src/lib.rs => frame-utilities-cli/src/transfer.rs} (98%) create mode 100644 utils/frame/frame-utilities-cli/src/utils.rs delete mode 100644 utils/frame/pallet-balances-cli/Cargo.toml diff --git a/Cargo.lock b/Cargo.lock index 99b6a64abdaf8..9c3ddc5579b7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1618,6 +1618,7 @@ version = "2.0.0-dev" dependencies = [ "bip39", "cli-utils", + "frame-system", "futures 0.1.29", "hex", "hyper 0.12.35", @@ -1633,6 +1634,7 @@ dependencies = [ "sp-io", "sp-runtime", "structopt", + "substrate-test-runtime", "tempfile", ] @@ -3515,7 +3517,6 @@ dependencies = [ "node-runtime", "pallet-authority-discovery", "pallet-balances", - "pallet-balances-cli", "pallet-contracts", "pallet-grandpa", "pallet-im-online", @@ -4130,22 +4131,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-balances-cli" -version = "2.0.0-dev" -dependencies = [ - "cli-utils", - "frame-system", - "hex", - "parity-scale-codec", - "sc-cli", - "sp-core", - "sp-io", - "sp-runtime", - "structopt", - "substrate-test-runtime", -] - [[package]] name = "pallet-benchmark" version = "2.0.0-dev" diff --git a/Cargo.toml b/Cargo.toml index 03316738593ef..0c2a18ff3e54e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -176,7 +176,6 @@ members = [ "utils/fork-tree", "utils/frame/benchmarking-cli", "utils/frame/frame-utilities-cli", - "utils/frame/pallet-balances-cli", "utils/frame/rpc/support", "utils/frame/rpc/system", "utils/wasm-builder", diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index b944b3aaf4fde..107489553551c 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -97,8 +97,7 @@ node-executor = { version = "2.0.0-dev", path = "../executor" } # CLI-specific dependencies sc-cli = { version = "0.8.0-dev", optional = true, path = "../../../client/cli" } -pallet-balances-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/pallet-balances-cli" } -frame-utilities-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/frame-utilities-cli" } +frame-utilities-cli = { version = "2.0.0-dev", optional = true, features = ["pallet-balances"], path = "../../../utils/frame/frame-utilities-cli" } frame-benchmarking-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/benchmarking-cli" } node-inspect = { version = "0.8.0-dev", optional = true, path = "../inspect" } @@ -131,8 +130,7 @@ structopt = { version = "0.3.8", optional = true } node-inspect = { version = "0.8.0-dev", optional = true, path = "../inspect" } frame-benchmarking-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/benchmarking-cli" } substrate-build-script-utils = { version = "2.0.0-dev", optional = true, path = "../../../utils/build-script-utils" } -pallet-balances-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/pallet-balances-cli" } -frame-utilities-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/frame-utilities-cli" } +frame-utilities-cli = { version = "2.0.0-dev", optional = true, features = ["pallet-balances"], path = "../../../utils/frame/frame-utilities-cli" } [build-dependencies.sc-cli] version = "0.8.0-dev" @@ -151,7 +149,6 @@ cli = [ "node-executor/wasmi-errno", "node-inspect", "sc-cli", - "pallet-balances-cli", "frame-benchmarking-cli", "frame-utilities-cli", "sc-service/db", diff --git a/bin/node/cli/src/cli.rs b/bin/node/cli/src/cli.rs index e4fe4ed9f09c2..0172087fbd97c 100644 --- a/bin/node/cli/src/cli.rs +++ b/bin/node/cli/src/cli.rs @@ -18,8 +18,7 @@ use sc_cli::RunCmd; use structopt::StructOpt; -use pallet_balances_cli::TransferCmd; -use frame_utilities_cli::{KeySubcommand, SignTransactionCmd}; +use frame_utilities_cli::{KeySubcommand, SignTransactionCmd, TransferCmd}; /// An overarching CLI command definition. #[derive(Clone, Debug, StructOpt)] diff --git a/utils/cli-utils/src/lib.rs b/utils/cli-utils/src/lib.rs index c715c71956425..758ccaf126c48 100644 --- a/utils/cli-utils/src/lib.rs +++ b/utils/cli-utils/src/lib.rs @@ -18,12 +18,7 @@ //! Utilities for cli. #![cfg_attr(not(feature = "std"), no_std)] -use sp_runtime::{ - MultiSigner, AccountId32, - traits::{StaticLookup, SignedExtension, IdentifyAccount}, - generic::{UncheckedExtrinsic, SignedPayload}, -}; -use codec::Encode; +use sp_runtime::traits::{StaticLookup, SignedExtension}; pub use pallet_balances::Call as BalancesCall; /// AccountIndex type for Runtime @@ -48,32 +43,3 @@ pub trait RuntimeAdapter: frame_system::Trait + pallet_balances::Trait { fn build_extra(index: IndexFor) -> Self::Extra; } - -/// create an extrinsic for the runtime. -pub fn create_extrinsic_for( - call: Call, - nonce: IndexFor, - signer: Pair, -) -> Result, &'static str> - where - Call: Encode, - Pair: sp_core::Pair, - Pair::Public: Into, - Pair::Signature: Encode, - RA: RuntimeAdapter, -{ - let extra = RA::build_extra(nonce); - let payload = SignedPayload::new(call, extra) - .map_err(|_| "Transaction validity error")?; - - let signature = payload.using_encoded(|payload| signer.sign(payload)); - let signer = signer.public().into().into_account(); - let (function, extra, _) = payload.deconstruct(); - - Ok(UncheckedExtrinsic::new_signed( - function, - signer, - signature, - extra, - )) -} diff --git a/utils/frame/frame-utilities-cli/Cargo.toml b/utils/frame/frame-utilities-cli/Cargo.toml index 77a9b59a380e8..4f840f4e5c7ef 100644 --- a/utils/frame/frame-utilities-cli/Cargo.toml +++ b/utils/frame/frame-utilities-cli/Cargo.toml @@ -30,3 +30,8 @@ futures01 = { package = "futures", version = "0.1.29" } [dev-dependencies] tempfile = "3.1.0" sp-io = { version = "2.0.0-dev", path = "../../../primitives/io" } +frame-system = { version = "2.0.0-alpha.7", path = "../../../frame/system" } +substrate-test-runtime = { version = "2.0.0-dev", features = ["indices-lookup"], path = "../../../test-utils/runtime" } + +[features] +pallet-balances = [] diff --git a/utils/frame/frame-utilities-cli/src/key.rs b/utils/frame/frame-utilities-cli/src/key.rs index 37ab5221ae351..1bab181bd7ad2 100644 --- a/utils/frame/frame-utilities-cli/src/key.rs +++ b/utils/frame/frame-utilities-cli/src/key.rs @@ -21,7 +21,6 @@ use structopt::StructOpt; use cli_utils::{HashFor, RuntimeAdapter}; use serde::{de::DeserializeOwned, Serialize}; - use crate::{ generate_node_key::GenerateNodeIdCmd, generate::GenerateCmd, diff --git a/utils/frame/frame-utilities-cli/src/lib.rs b/utils/frame/frame-utilities-cli/src/lib.rs index 93c179c1ff062..20b0d52edc1b6 100644 --- a/utils/frame/frame-utilities-cli/src/lib.rs +++ b/utils/frame/frame-utilities-cli/src/lib.rs @@ -21,10 +21,16 @@ mod generate_node_key; mod insert; mod inspect; mod key; +mod utils; mod sign_transaction; +#[cfg(feature = "pallet-balances")] +mod transfer; +#[cfg(feature = "pallet-balances")] +pub use transfer::TransferCmd; pub use {key::KeySubcommand, sign_transaction::SignTransactionCmd}; + #[cfg(test)] mod tests { use super::{generate::GenerateCmd, generate_node_key::GenerateNodeIdCmd, inspect::InspectCmd}; diff --git a/utils/frame/frame-utilities-cli/src/sign_transaction.rs b/utils/frame/frame-utilities-cli/src/sign_transaction.rs index 2537c70975c4f..830dd7f0feaea 100644 --- a/utils/frame/frame-utilities-cli/src/sign_transaction.rs +++ b/utils/frame/frame-utilities-cli/src/sign_transaction.rs @@ -24,7 +24,8 @@ use structopt::StructOpt; use codec::{Codec, Encode, Decode}; use std::{str::FromStr, fmt::Display}; use sp_runtime::MultiSigner; -use cli_utils::{RuntimeAdapter, IndexFor, CallFor, create_extrinsic_for}; +use cli_utils::{RuntimeAdapter, IndexFor, CallFor}; +use crate::utils::create_extrinsic_for; type Call = Vec; diff --git a/utils/frame/pallet-balances-cli/src/lib.rs b/utils/frame/frame-utilities-cli/src/transfer.rs similarity index 98% rename from utils/frame/pallet-balances-cli/src/lib.rs rename to utils/frame/frame-utilities-cli/src/transfer.rs index 5309184350c1f..11319bf7ad929 100644 --- a/utils/frame/pallet-balances-cli/src/lib.rs +++ b/utils/frame/frame-utilities-cli/src/transfer.rs @@ -27,7 +27,8 @@ use codec::Encode; use sp_runtime::MultiSigner; use std::convert::TryFrom; use sp_core::crypto::Ss58Codec; -use cli_utils::{AddressFor, IndexFor, BalanceFor, BalancesCall, AccountIdFor, RuntimeAdapter, create_extrinsic_for}; +use cli_utils::{AddressFor, IndexFor, BalanceFor, BalancesCall, AccountIdFor, RuntimeAdapter}; +use crate::utils::create_extrinsic_for; /// The `transfer` command #[derive(Debug, StructOpt, Clone)] diff --git a/utils/frame/frame-utilities-cli/src/utils.rs b/utils/frame/frame-utilities-cli/src/utils.rs new file mode 100644 index 0000000000000..43bd14863a06a --- /dev/null +++ b/utils/frame/frame-utilities-cli/src/utils.rs @@ -0,0 +1,51 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . +use sp_runtime::{ + MultiSigner, AccountId32, + traits::IdentifyAccount, + generic::{UncheckedExtrinsic, SignedPayload}, +}; +use codec::Encode; +use cli_utils::{RuntimeAdapter, IndexFor}; + +/// create an extrinsic for the runtime. +pub fn create_extrinsic_for( + call: Call, + nonce: IndexFor, + signer: Pair, +) -> Result, &'static str> + where + Call: Encode, + Pair: sp_core::Pair, + Pair::Public: Into, + Pair::Signature: Encode, + RA: RuntimeAdapter, +{ + let extra = RA::build_extra(nonce); + let payload = SignedPayload::new(call, extra) + .map_err(|_| "Transaction validity error")?; + + let signature = payload.using_encoded(|payload| signer.sign(payload)); + let signer = signer.public().into().into_account(); + let (function, extra, _) = payload.deconstruct(); + + Ok(UncheckedExtrinsic::new_signed( + function, + signer, + signature, + extra, + )) +} diff --git a/utils/frame/pallet-balances-cli/Cargo.toml b/utils/frame/pallet-balances-cli/Cargo.toml deleted file mode 100644 index 8247579d8259d..0000000000000 --- a/utils/frame/pallet-balances-cli/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "pallet-balances-cli" -version = "2.0.0-dev" -authors = ["Parity Technologies "] -edition = "2018" -license = "GPL-3.0" -homepage = "https://substrate.dev" -repository = "https://github.com/paritytech/substrate/" -description = "CLI utils" -documentation = "https://docs.rs/cli-utils" - -[dependencies] -sp-core = { version = "2.0.0-dev", path = "../../../primitives/core" } -sc-cli = { version = "0.8.0-dev", path = "../../../client/cli" } -sp-runtime = { version = "2.0.0-dev", path = "../../../primitives/runtime" } -structopt = "0.3.8" -codec = { version = "1.3.0", package = "parity-scale-codec" } -cli-utils = { path = "../../cli-utils", version = "2.0.0-dev" } -hex = "0.4.2" - -[dev-dependencies] -sp-io = { version = "2.0.0-dev", path = "../../../primitives/io" } -frame-system = { version = "2.0.0-alpha.7", path = "../../../frame/system" } -substrate-test-runtime = { version = "2.0.0-dev", features = ["indices-lookup"], path = "../../../test-utils/runtime" } From 5f670a6e077f981090cf9d78bcf8394a8d7e91ca Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 19 May 2020 14:56:56 +0100 Subject: [PATCH 44/77] remove full_crypto feature from sp_core in cli-utils --- utils/cli-utils/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/cli-utils/Cargo.toml b/utils/cli-utils/Cargo.toml index e5db8fb1d2dad..a03ce89ba08fa 100644 --- a/utils/cli-utils/Cargo.toml +++ b/utils/cli-utils/Cargo.toml @@ -13,7 +13,7 @@ documentation = "https://docs.rs/cli-utils" frame-system = { version = "2.0.0-alpha.7", default-features = false, path = "../../frame/system" } pallet-balances = { version = "2.0.0-alpha.7", default-features = false, path = "../../frame/balances" } sp-runtime = { version = "2.0.0-alpha.7", default-features = false, path = "../../primitives/runtime" } -sp-core = { version = "2.0.0-alpha.7", default-features = false, features = ["full_crypto"], path = "../../primitives/core" } +sp-core = { version = "2.0.0-alpha.7", default-features = false, path = "../../primitives/core" } codec = { version = "1.3.0", default-features = false, package = "parity-scale-codec" } [features] From 0ad4d4874abab4919fd51d47ec0d9c37ad797370 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 19 May 2020 15:56:50 +0100 Subject: [PATCH 45/77] bump Cargo.lock --- Cargo.lock | 570 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 509 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0a3fae2377303..ed02e904632fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1623,7 +1623,7 @@ dependencies = [ "hex", "hyper 0.12.35", "jsonrpc-core-client", - "libp2p", + "libp2p 0.18.1", "parity-scale-codec", "sc-cli", "sc-client-api", @@ -2671,6 +2671,44 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" +[[package]] +name = "libp2p" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32ea742c86405b659c358223a8f0f9f5a9eb27bb6083894c6340959b05269662" +dependencies = [ + "bytes 0.5.4", + "futures 0.3.5", + "lazy_static", + "libp2p-core 0.18.0", + "libp2p-core-derive 0.18.0", + "libp2p-deflate 0.18.0", + "libp2p-dns 0.18.0", + "libp2p-floodsub 0.18.0", + "libp2p-gossipsub 0.18.0", + "libp2p-identify 0.18.0", + "libp2p-kad 0.18.0", + "libp2p-mdns 0.18.0", + "libp2p-mplex 0.18.0", + "libp2p-noise 0.18.0", + "libp2p-ping 0.18.0", + "libp2p-plaintext 0.18.0", + "libp2p-pnet 0.18.0", + "libp2p-secio 0.18.0", + "libp2p-swarm 0.18.1", + "libp2p-tcp 0.18.0", + "libp2p-uds 0.18.0", + "libp2p-wasm-ext 0.18.0", + "libp2p-websocket 0.18.0", + "libp2p-yamux 0.18.0", + "multihash 0.10.1", + "parity-multiaddr 0.8.0", + "parking_lot 0.10.2", + "pin-project", + "smallvec 1.4.0", + "wasm-timer", +] + [[package]] name = "libp2p" version = "0.19.0" @@ -2680,28 +2718,28 @@ dependencies = [ "bytes 0.5.4", "futures 0.3.5", "lazy_static", - "libp2p-core", - "libp2p-core-derive", - "libp2p-deflate", - "libp2p-dns", - "libp2p-floodsub", - "libp2p-gossipsub", - "libp2p-identify", - "libp2p-kad", - "libp2p-mdns", - "libp2p-mplex", - "libp2p-noise", - "libp2p-ping", - "libp2p-plaintext", - "libp2p-pnet", - "libp2p-secio", - "libp2p-swarm", - "libp2p-tcp", - "libp2p-uds", - "libp2p-wasm-ext", - "libp2p-websocket", - "libp2p-yamux", - "multihash", + "libp2p-core 0.19.0", + "libp2p-core-derive 0.19.0", + "libp2p-deflate 0.19.0", + "libp2p-dns 0.19.0", + "libp2p-floodsub 0.19.0", + "libp2p-gossipsub 0.19.0", + "libp2p-identify 0.19.0", + "libp2p-kad 0.19.0", + "libp2p-mdns 0.19.0", + "libp2p-mplex 0.19.0", + "libp2p-noise 0.19.0", + "libp2p-ping 0.19.0", + "libp2p-plaintext 0.19.0", + "libp2p-pnet 0.19.0", + "libp2p-secio 0.19.0", + "libp2p-swarm 0.19.0", + "libp2p-tcp 0.19.0", + "libp2p-uds 0.19.0", + "libp2p-wasm-ext 0.19.0", + "libp2p-websocket 0.19.0", + "libp2p-yamux 0.19.0", + "multihash 0.11.1", "parity-multiaddr 0.9.0", "parking_lot 0.10.2", "pin-project", @@ -2709,6 +2747,40 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-core" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d2c17158c4dca984a77a5927aac6f0862d7f50c013470a415f93be498b5739" +dependencies = [ + "asn1_der", + "bs58", + "ed25519-dalek", + "either", + "fnv", + "futures 0.3.5", + "futures-timer 3.0.2", + "lazy_static", + "libsecp256k1", + "log", + "multihash 0.10.1", + "multistream-select", + "parity-multiaddr 0.8.0", + "parking_lot 0.10.2", + "pin-project", + "prost", + "prost-build", + "rand 0.7.3", + "ring", + "rw-stream-sink", + "sha2", + "smallvec 1.4.0", + "thiserror", + "unsigned-varint", + "void", + "zeroize", +] + [[package]] name = "libp2p-core" version = "0.19.0" @@ -2725,7 +2797,7 @@ dependencies = [ "lazy_static", "libsecp256k1", "log", - "multihash", + "multihash 0.11.1", "multistream-select", "parity-multiaddr 0.9.0", "parking_lot 0.10.2", @@ -2743,6 +2815,16 @@ dependencies = [ "zeroize", ] +[[package]] +name = "libp2p-core-derive" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "329127858e4728db5ab60c33d5ae352a999325fdf190ed022ec7d3a4685ae2e6" +dependencies = [ + "quote 1.0.4", + "syn 1.0.19", +] + [[package]] name = "libp2p-core-derive" version = "0.19.0" @@ -2753,6 +2835,17 @@ dependencies = [ "syn 1.0.19", ] +[[package]] +name = "libp2p-deflate" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ad32b006ea922da8cc66e537cf2df4b0fad8ebaa467d2a8c63d7784ac252ec6" +dependencies = [ + "flate2", + "futures 0.3.5", + "libp2p-core 0.18.0", +] + [[package]] name = "libp2p-deflate" version = "0.19.0" @@ -2761,7 +2854,18 @@ checksum = "975c847575ef9b3d63f9c11d465e9a9b0ea940cfa408b93cc6981bbc3b1bac40" dependencies = [ "flate2", "futures 0.3.5", - "libp2p-core", + "libp2p-core 0.19.0", +] + +[[package]] +name = "libp2p-dns" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0d0993481203d68e5ce2f787d033fb0cac6b850659ed6c784612db678977c71" +dependencies = [ + "futures 0.3.5", + "libp2p-core 0.18.0", + "log", ] [[package]] @@ -2771,10 +2875,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cc186d9a941fd0207cf8f08ef225a735e2d7296258f570155e525f6ee732f87" dependencies = [ "futures 0.3.5", - "libp2p-core", + "libp2p-core 0.19.0", "log", ] +[[package]] +name = "libp2p-floodsub" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3673153ca967c179d745fadf047d069355d6669ecf7f261b450fbaebf1bffd3d" +dependencies = [ + "cuckoofilter", + "fnv", + "futures 0.3.5", + "libp2p-core 0.18.0", + "libp2p-swarm 0.18.1", + "prost", + "prost-build", + "rand 0.7.3", + "smallvec 1.4.0", +] + [[package]] name = "libp2p-floodsub" version = "0.19.0" @@ -2784,14 +2905,39 @@ dependencies = [ "cuckoofilter", "fnv", "futures 0.3.5", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.19.0", + "libp2p-swarm 0.19.0", "prost", "prost-build", "rand 0.7.3", "smallvec 1.4.0", ] +[[package]] +name = "libp2p-gossipsub" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f7f3f79f060864db0317cc47641b7d35276dee52a0ffa91553fbd0c153863a3" +dependencies = [ + "base64 0.11.0", + "byteorder 1.3.4", + "bytes 0.5.4", + "fnv", + "futures 0.3.5", + "futures_codec", + "libp2p-core 0.18.0", + "libp2p-swarm 0.18.1", + "log", + "lru", + "prost", + "prost-build", + "rand 0.7.3", + "sha2", + "smallvec 1.4.0", + "unsigned-varint", + "wasm-timer", +] + [[package]] name = "libp2p-gossipsub" version = "0.19.0" @@ -2804,8 +2950,8 @@ dependencies = [ "fnv", "futures 0.3.5", "futures_codec", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.19.0", + "libp2p-swarm 0.19.0", "log", "lru", "prost", @@ -2817,6 +2963,22 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-identify" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a38ca3eb807789e26f41c82ca7cd2b3843c66c5587b8b5f709a2f421f3061414" +dependencies = [ + "futures 0.3.5", + "libp2p-core 0.18.0", + "libp2p-swarm 0.18.1", + "log", + "prost", + "prost-build", + "smallvec 1.4.0", + "wasm-timer", +] + [[package]] name = "libp2p-identify" version = "0.19.0" @@ -2824,8 +2986,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a455af71c59473444eba05e83dbaa20262bdbd9b4154f22389510fbac16f201" dependencies = [ "futures 0.3.5", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.19.0", + "libp2p-swarm 0.19.0", "log", "prost", "prost-build", @@ -2833,6 +2995,33 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-kad" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92cda1fb8149ea64d092a2b99d2bd7a2c309eee38ea322d02e4480bd6ee1759" +dependencies = [ + "arrayvec 0.5.1", + "bytes 0.5.4", + "either", + "fnv", + "futures 0.3.5", + "futures_codec", + "libp2p-core 0.18.0", + "libp2p-swarm 0.18.1", + "log", + "multihash 0.10.1", + "prost", + "prost-build", + "rand 0.7.3", + "sha2", + "smallvec 1.4.0", + "uint", + "unsigned-varint", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-kad" version = "0.19.0" @@ -2845,10 +3034,10 @@ dependencies = [ "fnv", "futures 0.3.5", "futures_codec", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.19.0", + "libp2p-swarm 0.19.0", "log", - "multihash", + "multihash 0.11.1", "prost", "prost-build", "rand 0.7.3", @@ -2860,6 +3049,28 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-mdns" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41e908d2aaf8ff0ec6ad1f02fe1844fd777fb0b03a68a226423630750ab99471" +dependencies = [ + "async-std", + "data-encoding", + "dns-parser", + "either", + "futures 0.3.5", + "lazy_static", + "libp2p-core 0.18.0", + "libp2p-swarm 0.18.1", + "log", + "net2", + "rand 0.7.3", + "smallvec 1.4.0", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-mdns" version = "0.19.0" @@ -2872,8 +3083,8 @@ dependencies = [ "either", "futures 0.3.5", "lazy_static", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.19.0", + "libp2p-swarm 0.19.0", "log", "net2", "rand 0.7.3", @@ -2882,6 +3093,22 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-mplex" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0832882b06619b2e81d74e71447753ea3c068164a0bca67847d272e856a04a02" +dependencies = [ + "bytes 0.5.4", + "fnv", + "futures 0.3.5", + "futures_codec", + "libp2p-core 0.18.0", + "log", + "parking_lot 0.10.2", + "unsigned-varint", +] + [[package]] name = "libp2p-mplex" version = "0.19.0" @@ -2892,12 +3119,33 @@ dependencies = [ "fnv", "futures 0.3.5", "futures_codec", - "libp2p-core", + "libp2p-core 0.19.0", "log", "parking_lot 0.10.2", "unsigned-varint", ] +[[package]] +name = "libp2p-noise" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918e94a649e1139c24ee9f1f8c1f2adaba6d157b9471af787f2d9beac8c29c77" +dependencies = [ + "curve25519-dalek", + "futures 0.3.5", + "lazy_static", + "libp2p-core 0.18.0", + "log", + "prost", + "prost-build", + "rand 0.7.3", + "sha2", + "snow", + "static_assertions", + "x25519-dalek", + "zeroize", +] + [[package]] name = "libp2p-noise" version = "0.19.0" @@ -2907,7 +3155,7 @@ dependencies = [ "curve25519-dalek", "futures 0.3.5", "lazy_static", - "libp2p-core", + "libp2p-core 0.19.0", "log", "prost", "prost-build", @@ -2919,6 +3167,21 @@ dependencies = [ "zeroize", ] +[[package]] +name = "libp2p-ping" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9bfbf87eebb492d040f9899c5c81c9738730465ac5e78d9b7a7d086d0f07230" +dependencies = [ + "futures 0.3.5", + "libp2p-core 0.18.0", + "libp2p-swarm 0.18.1", + "log", + "rand 0.7.3", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-ping" version = "0.19.0" @@ -2926,14 +3189,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "82930c36490008b1ef2f26c237a2c205c38ef6edc263738d0528b842740ab09f" dependencies = [ "futures 0.3.5", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.19.0", + "libp2p-swarm 0.19.0", "log", "rand 0.7.3", "void", "wasm-timer", ] +[[package]] +name = "libp2p-plaintext" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabb00553a49bf6d4a8ce362f6eefac410227a14d03c3acffbb8cc3f022ea019" +dependencies = [ + "bytes 0.5.4", + "futures 0.3.5", + "futures_codec", + "libp2p-core 0.18.0", + "log", + "prost", + "prost-build", + "rw-stream-sink", + "unsigned-varint", + "void", +] + [[package]] name = "libp2p-plaintext" version = "0.19.0" @@ -2943,7 +3224,7 @@ dependencies = [ "bytes 0.5.4", "futures 0.3.5", "futures_codec", - "libp2p-core", + "libp2p-core 0.19.0", "log", "prost", "prost-build", @@ -2952,6 +3233,20 @@ dependencies = [ "void", ] +[[package]] +name = "libp2p-pnet" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f81b8b37ff529e1f51c20c396dac657def2108da174c1d27e57e72c9fe2d411" +dependencies = [ + "futures 0.3.5", + "log", + "pin-project", + "rand 0.7.3", + "salsa20", + "sha3", +] + [[package]] name = "libp2p-pnet" version = "0.19.0" @@ -2966,6 +3261,36 @@ dependencies = [ "sha3", ] +[[package]] +name = "libp2p-secio" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a0509a7e47245259954fef58b85b81bf4d29ae33a4365e38d718a866698774" +dependencies = [ + "aes-ctr", + "ctr", + "futures 0.3.5", + "hmac", + "js-sys", + "lazy_static", + "libp2p-core 0.18.0", + "log", + "parity-send-wrapper", + "pin-project", + "prost", + "prost-build", + "quicksink", + "rand 0.7.3", + "ring", + "rw-stream-sink", + "sha2", + "static_assertions", + "twofish", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "libp2p-secio" version = "0.19.0" @@ -2978,7 +3303,7 @@ dependencies = [ "hmac", "js-sys", "lazy_static", - "libp2p-core", + "libp2p-core 0.19.0", "log", "parity-send-wrapper", "pin-project", @@ -2996,6 +3321,21 @@ dependencies = [ "web-sys", ] +[[package]] +name = "libp2p-swarm" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44ab289ae44cc691da0a6fe96aefa43f26c86c6c7813998e203f6d80f1860f18" +dependencies = [ + "futures 0.3.5", + "libp2p-core 0.18.0", + "log", + "rand 0.7.3", + "smallvec 1.4.0", + "void", + "wasm-timer", +] + [[package]] name = "libp2p-swarm" version = "0.19.0" @@ -3003,7 +3343,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4a8101a0e0d5f04562137a476bf5f5423cd5bdab2f7e43a75909668e63cb102" dependencies = [ "futures 0.3.5", - "libp2p-core", + "libp2p-core 0.19.0", "log", "rand 0.7.3", "smallvec 1.4.0", @@ -3011,6 +3351,21 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-tcp" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b37ea44823d3ed223e4605da94b50177bc520f05ae2452286700549a32d81669" +dependencies = [ + "async-std", + "futures 0.3.5", + "futures-timer 3.0.2", + "get_if_addrs", + "ipnet", + "libp2p-core 0.18.0", + "log", +] + [[package]] name = "libp2p-tcp" version = "0.19.0" @@ -3022,11 +3377,23 @@ dependencies = [ "futures-timer 3.0.2", "get_if_addrs", "ipnet", - "libp2p-core", + "libp2p-core 0.19.0", "log", "socket2", ] +[[package]] +name = "libp2p-uds" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "281c18ea2faacb9c8a6ff76c4405df5918d9a263770e3847bf03f099abadc010" +dependencies = [ + "async-std", + "futures 0.3.5", + "libp2p-core 0.18.0", + "log", +] + [[package]] name = "libp2p-uds" version = "0.19.0" @@ -3035,10 +3402,24 @@ checksum = "69660d235449bb2d99333b9892c9176d06fd2b380490cb8213feb5b015678cf1" dependencies = [ "async-std", "futures 0.3.5", - "libp2p-core", + "libp2p-core 0.19.0", "log", ] +[[package]] +name = "libp2p-wasm-ext" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ac7dbde0f88cad191dcdfd073b8bae28d01823e8ca313f117b6ecb914160c3" +dependencies = [ + "futures 0.3.5", + "js-sys", + "libp2p-core 0.18.0", + "parity-send-wrapper", + "wasm-bindgen", + "wasm-bindgen-futures", +] + [[package]] name = "libp2p-wasm-ext" version = "0.19.0" @@ -3047,12 +3428,33 @@ checksum = "f59fdbb5706f2723ca108c088b1c7a37f735a8c328021f0508007162627e9885" dependencies = [ "futures 0.3.5", "js-sys", - "libp2p-core", + "libp2p-core 0.19.0", "parity-send-wrapper", "wasm-bindgen", "wasm-bindgen-futures", ] +[[package]] +name = "libp2p-websocket" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6874c9069ce93d899df9dc7b29f129c706b2a0fdc048f11d878935352b580190" +dependencies = [ + "async-tls", + "bytes 0.5.4", + "either", + "futures 0.3.5", + "libp2p-core 0.18.0", + "log", + "quicksink", + "rustls", + "rw-stream-sink", + "soketto", + "url 2.1.1", + "webpki", + "webpki-roots 0.18.0", +] + [[package]] name = "libp2p-websocket" version = "0.19.0" @@ -3063,7 +3465,7 @@ dependencies = [ "bytes 0.5.4", "either", "futures 0.3.5", - "libp2p-core", + "libp2p-core 0.19.0", "log", "quicksink", "rustls", @@ -3074,6 +3476,19 @@ dependencies = [ "webpki-roots 0.18.0", ] +[[package]] +name = "libp2p-yamux" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02f91aea50f6571e0bc6c058dc0e9b270afd41ec28dd94e9e4bf607e78b9ab87" +dependencies = [ + "futures 0.3.5", + "libp2p-core 0.18.0", + "parking_lot 0.10.2", + "thiserror", + "yamux", +] + [[package]] name = "libp2p-yamux" version = "0.19.0" @@ -3081,7 +3496,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b305d3a8981e68f11c0e17f2d11d5c52fae95e0d7c283f9e462b5b2dab413b2" dependencies = [ "futures 0.3.5", - "libp2p-core", + "libp2p-core 0.19.0", "parking_lot 0.10.2", "thiserror", "yamux", @@ -3352,6 +3767,21 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238" +[[package]] +name = "multihash" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47fbc227f7e2b1cb701f95404579ecb2668abbdd3c7ef7a6cbb3cc0d3b236869" +dependencies = [ + "blake2b_simd", + "blake2s_simd", + "digest", + "sha-1", + "sha2", + "sha3", + "unsigned-varint", +] + [[package]] name = "multihash" version = "0.11.1" @@ -3487,7 +3917,7 @@ dependencies = [ "futures 0.3.5", "futures-timer 3.0.2", "jsonrpc-core", - "libp2p", + "libp2p 0.19.0", "node-cli", "sc-rpc-api", "serde", @@ -4868,6 +5298,24 @@ dependencies = [ "url 2.1.1", ] +[[package]] +name = "parity-multiaddr" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4db35e222f783ef4e6661873f6c165c4eb7b65e0c408349818517d5705c2d7d3" +dependencies = [ + "arrayref", + "bs58", + "byteorder 1.3.4", + "data-encoding", + "multihash 0.10.1", + "percent-encoding 2.1.0", + "serde", + "static_assertions", + "unsigned-varint", + "url 2.1.1", +] + [[package]] name = "parity-multiaddr" version = "0.9.0" @@ -4878,7 +5326,7 @@ dependencies = [ "bs58", "byteorder 1.3.4", "data-encoding", - "multihash", + "multihash 0.11.1", "percent-encoding 2.1.0", "serde", "static_assertions", @@ -5974,7 +6422,7 @@ dependencies = [ "env_logger 0.7.1", "futures 0.3.5", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.19.0", "log", "parity-scale-codec", "prost", @@ -6081,7 +6529,7 @@ dependencies = [ "hyper 0.12.35", "jsonrpc-core-client", "lazy_static", - "libp2p", + "libp2p 0.18.1", "log", "names", "nix", @@ -6605,7 +7053,7 @@ dependencies = [ "futures_codec", "hex", "ip_network", - "libp2p", + "libp2p 0.19.0", "linked-hash-map", "linked_hash_set", "log", @@ -6652,7 +7100,7 @@ dependencies = [ "async-std", "futures 0.3.5", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.19.0", "log", "lru", "quickcheck", @@ -6670,7 +7118,7 @@ dependencies = [ "env_logger 0.7.1", "futures 0.3.5", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.19.0", "log", "parking_lot 0.10.2", "rand 0.7.3", @@ -6727,7 +7175,7 @@ name = "sc-peerset" version = "2.0.0-dev" dependencies = [ "futures 0.3.5", - "libp2p", + "libp2p 0.19.0", "log", "rand 0.7.3", "serde_json", @@ -6949,7 +7397,7 @@ dependencies = [ "bytes 0.5.4", "futures 0.3.5", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.19.0", "log", "parking_lot 0.10.2", "pin-project", @@ -7555,7 +8003,7 @@ dependencies = [ "derive_more", "futures 0.3.5", "futures-timer 3.0.2", - "libp2p", + "libp2p 0.19.0", "log", "parity-scale-codec", "parking_lot 0.10.2", @@ -8203,7 +8651,7 @@ dependencies = [ "hyper 0.12.35", "itertools 0.8.2", "jsonrpc-core-client", - "libp2p", + "libp2p 0.19.0", "node-primitives", "node-runtime", "pallet-balances", @@ -8245,7 +8693,7 @@ dependencies = [ "futures-timer 3.0.2", "js-sys", "kvdb-web", - "libp2p-wasm-ext", + "libp2p-wasm-ext 0.19.0", "log", "rand 0.6.5", "rand 0.7.3", From 7b4cd95f9dc822f089627e6e1b705de715a39613 Mon Sep 17 00:00:00 2001 From: Seun Date: Thu, 21 May 2020 12:53:40 +0100 Subject: [PATCH 46/77] cli-utils -> frame-utils --- Cargo.lock | 32 ++++---- Cargo.toml | 2 +- bin/node-template/runtime/Cargo.toml | 4 +- bin/node-template/runtime/src/lib.rs | 6 +- bin/node/cli/Cargo.toml | 4 +- bin/node/runtime/Cargo.toml | 4 +- bin/node/runtime/src/lib.rs | 8 +- test-utils/runtime/Cargo.toml | 2 +- test-utils/runtime/src/lib.rs | 6 +- utils/cli-utils/src/lib.rs | 45 ---------- utils/{cli-utils => frame-utils}/Cargo.toml | 4 +- utils/frame-utils/src/lib.rs | 82 +++++++++++++++++++ utils/frame/frame-utilities-cli/Cargo.toml | 8 +- .../frame/frame-utilities-cli/src/generate.rs | 25 +++--- .../src/generate_node_key.rs | 27 +++--- utils/frame/frame-utilities-cli/src/insert.rs | 37 +++++---- .../frame/frame-utilities-cli/src/inspect.rs | 27 +++--- utils/frame/frame-utilities-cli/src/key.rs | 35 ++++---- utils/frame/frame-utilities-cli/src/lib.rs | 29 +++---- .../src/sign_transaction.rs | 39 ++++----- .../frame/frame-utilities-cli/src/transfer.rs | 22 ++--- utils/frame/frame-utilities-cli/src/utils.rs | 36 ++++---- 22 files changed, 268 insertions(+), 216 deletions(-) delete mode 100644 utils/cli-utils/src/lib.rs rename utils/{cli-utils => frame-utils}/Cargo.toml (92%) create mode 100644 utils/frame-utils/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index ed02e904632fa..9c4e757f3b040 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -660,17 +660,6 @@ dependencies = [ "cc", ] -[[package]] -name = "cli-utils" -version = "2.0.0-dev" -dependencies = [ - "frame-system", - "pallet-balances", - "parity-scale-codec", - "sp-core", - "sp-runtime", -] - [[package]] name = "cloudabi" version = "0.0.3" @@ -1617,13 +1606,15 @@ name = "frame-utilities-cli" version = "2.0.0-dev" dependencies = [ "bip39", - "cli-utils", "frame-system", + "frame-utils", "futures 0.1.29", + "futures 0.3.5", "hex", "hyper 0.12.35", "jsonrpc-core-client", "libp2p 0.18.1", + "pallet-balances", "parity-scale-codec", "sc-cli", "sc-client-api", @@ -1638,6 +1629,17 @@ dependencies = [ "tempfile", ] +[[package]] +name = "frame-utils" +version = "2.0.0-dev" +dependencies = [ + "frame-system", + "pallet-balances", + "parity-scale-codec", + "sp-core", + "sp-runtime", +] + [[package]] name = "fs-swap" version = "0.2.4" @@ -4107,13 +4109,13 @@ dependencies = [ name = "node-runtime" version = "2.0.0-dev" dependencies = [ - "cli-utils", "frame-benchmarking", "frame-executive", "frame-support", "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", + "frame-utils", "integer-sqrt", "node-primitives", "pallet-authority-discovery", @@ -4203,10 +4205,10 @@ dependencies = [ name = "node-template-runtime" version = "2.0.0-dev" dependencies = [ - "cli-utils", "frame-executive", "frame-support", "frame-system", + "frame-utils", "pallet-aura", "pallet-balances", "pallet-grandpa", @@ -8790,11 +8792,11 @@ name = "substrate-test-runtime" version = "2.0.0-dev" dependencies = [ "cfg-if", - "cli-utils", "frame-executive", "frame-support", "frame-system", "frame-system-rpc-runtime-api", + "frame-utils", "log", "memory-db", "pallet-babe", diff --git a/Cargo.toml b/Cargo.toml index 0c2a18ff3e54e..ae76af55db74d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -172,7 +172,7 @@ members = [ "test-utils/runtime/transaction-pool", "utils/browser", "utils/build-script-utils", - "utils/cli-utils", + "utils/frame-utils", "utils/fork-tree", "utils/frame/benchmarking-cli", "utils/frame/frame-utilities-cli", diff --git a/bin/node-template/runtime/Cargo.toml b/bin/node-template/runtime/Cargo.toml index e9c84bf8a85a8..73681a0a5c31f 100644 --- a/bin/node-template/runtime/Cargo.toml +++ b/bin/node-template/runtime/Cargo.toml @@ -36,7 +36,7 @@ sp-session = { version = "2.0.0-dev", default-features = false, path = "../../.. sp-std = { version = "2.0.0-dev", default-features = false, path = "../../../primitives/std" } sp-transaction-pool = { version = "2.0.0-dev", default-features = false, path = "../../../primitives/transaction-pool" } sp-version = { version = "2.0.0-dev", default-features = false, path = "../../../primitives/version" } -cli-utils = { version = "2.0.0-dev", default-features = false, path = "../../../utils/cli-utils" } +frame-utils = { version = "2.0.0-dev", default-features = false, path = "../../../utils/frame-utils" } template = { version = "2.0.0-dev", default-features = false, path = "../pallets/template", package = "pallet-template" } [build-dependencies] @@ -70,5 +70,5 @@ std = [ "timestamp/std", "transaction-payment/std", "template/std", - "cli-utils/std", + "frame-utils/std", ] diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index 9e6cf7deee8a9..4f87cf5379f55 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -21,7 +21,7 @@ use sp_api::impl_runtime_apis; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList}; use grandpa::fg_primitives; -use cli_utils::RuntimeAdapter; +use frame_utils::SignedExtensionProvider; use sp_version::RuntimeVersion; #[cfg(feature = "std")] use sp_version::NativeVersion; @@ -407,10 +407,10 @@ impl_runtime_apis! { } } -impl RuntimeAdapter for Runtime { +impl SignedExtensionProvider for Runtime { type Extra = SignedExtra; - fn build_extra(index: Index) -> Self::Extra { + fn construct_extras(index: Index) -> Self::Extra { ( system::CheckSpecVersion::new(), system::CheckTxVersion::new(), diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index 107489553551c..16e7a60b7248f 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -97,7 +97,7 @@ node-executor = { version = "2.0.0-dev", path = "../executor" } # CLI-specific dependencies sc-cli = { version = "0.8.0-dev", optional = true, path = "../../../client/cli" } -frame-utilities-cli = { version = "2.0.0-dev", optional = true, features = ["pallet-balances"], path = "../../../utils/frame/frame-utilities-cli" } +frame-utilities-cli = { version = "2.0.0-dev", optional = true, features = ["balances"], path = "../../../utils/frame/frame-utilities-cli" } frame-benchmarking-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/benchmarking-cli" } node-inspect = { version = "0.8.0-dev", optional = true, path = "../inspect" } @@ -130,7 +130,7 @@ structopt = { version = "0.3.8", optional = true } node-inspect = { version = "0.8.0-dev", optional = true, path = "../inspect" } frame-benchmarking-cli = { version = "2.0.0-dev", optional = true, path = "../../../utils/frame/benchmarking-cli" } substrate-build-script-utils = { version = "2.0.0-dev", optional = true, path = "../../../utils/build-script-utils" } -frame-utilities-cli = { version = "2.0.0-dev", optional = true, features = ["pallet-balances"], path = "../../../utils/frame/frame-utilities-cli" } +frame-utilities-cli = { version = "2.0.0-dev", optional = true, features = ["balances"], path = "../../../utils/frame/frame-utilities-cli" } [build-dependencies.sc-cli] version = "0.8.0-dev" diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index c537414cc570a..0cd54f2107ad9 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -77,7 +77,7 @@ pallet-transaction-payment = { version = "2.0.0-dev", default-features = false, pallet-transaction-payment-rpc-runtime-api = { version = "2.0.0-dev", default-features = false, path = "../../../frame/transaction-payment/rpc/runtime-api/" } pallet-vesting = { version = "2.0.0-dev", default-features = false, path = "../../../frame/vesting" } -cli-utils = { version = "2.0.0-alpha.3", default-features = false, path = "../../../utils/cli-utils" } +frame-utils = { version = "2.0.0-alpha.3", default-features = false, path = "../../../utils/frame-utils" } [build-dependencies] wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-runner", path = "../../../utils/wasm-builder-runner" } @@ -139,7 +139,7 @@ std = [ "pallet-society/std", "pallet-recovery/std", "pallet-vesting/std", - "cli-utils/std", + "frame-utils/std", ] runtime-benchmarks = [ "frame-benchmarking", diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index e2b942ff07030..2ca609dfd3982 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -49,7 +49,7 @@ use sp_runtime::traits::{ self, BlakeTwo256, Block as BlockT, StaticLookup, SaturatedConversion, ConvertInto, OpaqueKeys, NumberFor, }; -use cli_utils::{RuntimeAdapter, IndexFor}; +use frame_utils::{SignedExtensionProvider, IndexFor}; use sp_version::RuntimeVersion; #[cfg(any(feature = "std", test))] use sp_version::NativeVersion; @@ -518,10 +518,10 @@ parameter_types! { pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2; } -impl RuntimeAdapter for Runtime { +impl SignedExtensionProvider for Runtime { type Extra = SignedExtra; - fn build_extra(index: IndexFor) -> Self::Extra { + fn construct_extras(index: IndexFor) -> Self::Extra { // take the biggest period possible. let period = BlockHashCount::get() .checked_next_power_of_two() @@ -557,7 +557,7 @@ impl frame_system::offchain::CreateSignedTransaction for R account: AccountId, nonce: Index, ) -> Option<(Call, ::SignaturePayload)> { - let extra = Runtime::build_extra(nonce); + let extra = Runtime::construct_extras(nonce); let raw_payload = SignedPayload::new(call, extra).map_err(|e| { debug::warn!("Unable to create signed payload: {:?}", e); }).ok()?; diff --git a/test-utils/runtime/Cargo.toml b/test-utils/runtime/Cargo.toml index 5bfa5c415d7cc..6b7f9ed89fc34 100644 --- a/test-utils/runtime/Cargo.toml +++ b/test-utils/runtime/Cargo.toml @@ -43,7 +43,7 @@ sp-transaction-pool = { version = "2.0.0-dev", default-features = false, path = trie-db = { version = "0.20.1", default-features = false } parity-util-mem = { version = "0.6.1", default-features = false, features = ["primitive-types"] } sc-service = { version = "0.8.0-dev", default-features = false, optional = true, features = ["test-helpers"], path = "../../client/service" } -cli-utils = { version = "2.0.0-alpha.3", default-features = false, path = "../../utils/cli-utils" } +frame-utils = { version = "2.0.0-alpha.3", default-features = false, path = "../../utils/frame-utils" } # 3rd party cfg-if = "0.1.10" diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index 4505303c715d4..65ea59d5e14d7 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -55,7 +55,7 @@ use cfg_if::cfg_if; // Ensure Babe and Aura use the same crypto to simplify things a bit. pub use sp_consensus_babe::{AuthorityId, SlotNumber, AllowedSlots}; -use cli_utils::{RuntimeAdapter, IndexFor}; +use frame_utils::{SignedExtensionProvider, IndexFor}; use sp_runtime::generic::Era; pub type AuraId = sp_consensus_aura::sr25519::AuthorityId; @@ -417,14 +417,14 @@ impl pallet_balances::Trait for Runtime { type AccountStore = frame_system::Module; } -impl RuntimeAdapter for Runtime { +impl SignedExtensionProvider for Runtime { type Extra = ( frame_system::CheckTxVersion, frame_system::CheckGenesis, frame_system::CheckEra, ); - fn build_extra(_index: IndexFor) -> Self::Extra { + fn construct_extras(_index: IndexFor) -> Self::Extra { ( frame_system::CheckTxVersion::new(), frame_system::CheckGenesis::new(), diff --git a/utils/cli-utils/src/lib.rs b/utils/cli-utils/src/lib.rs deleted file mode 100644 index 758ccaf126c48..0000000000000 --- a/utils/cli-utils/src/lib.rs +++ /dev/null @@ -1,45 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Utilities for cli. -#![cfg_attr(not(feature = "std"), no_std)] - -use sp_runtime::traits::{StaticLookup, SignedExtension}; -pub use pallet_balances::Call as BalancesCall; - -/// AccountIndex type for Runtime -pub type IndexFor = ::Index; -/// Balance type -pub type BalanceFor = ::Balance; -/// Call type for Runtime -pub type CallFor = ::Call; -/// Address type for runtime. -pub type AddressFor = <::Lookup as StaticLookup>::Source; -/// Hash for runtime. -pub type HashFor = ::Hash; -/// AccountId type for runtime. -pub type AccountIdFor = ::AccountId; - -/// Runtime adapter for signing utilities -pub trait RuntimeAdapter: frame_system::Trait + pallet_balances::Trait { - /// extras - type Extra: SignedExtension; - - /// build extras for inclusion in extrinsics - fn build_extra(index: IndexFor) -> Self::Extra; -} - diff --git a/utils/cli-utils/Cargo.toml b/utils/frame-utils/Cargo.toml similarity index 92% rename from utils/cli-utils/Cargo.toml rename to utils/frame-utils/Cargo.toml index a03ce89ba08fa..92158b9744504 100644 --- a/utils/cli-utils/Cargo.toml +++ b/utils/frame-utils/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "cli-utils" +name = "frame-utils" version = "2.0.0-dev" authors = ["Parity Technologies "] edition = "2018" @@ -7,7 +7,7 @@ license = "GPL-3.0" homepage = "https://substrate.dev" repository = "https://github.com/paritytech/substrate/" description = "CLI utils" -documentation = "https://docs.rs/cli-utils" +documentation = "https://docs.rs/frame-utils" [dependencies] frame-system = { version = "2.0.0-alpha.7", default-features = false, path = "../../frame/system" } diff --git a/utils/frame-utils/src/lib.rs b/utils/frame-utils/src/lib.rs new file mode 100644 index 0000000000000..3ae560f1c4f73 --- /dev/null +++ b/utils/frame-utils/src/lib.rs @@ -0,0 +1,82 @@ +// This file is part of Substrate. + +// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! FRAME utilities +//! +#![cfg_attr(not(feature = "std"), no_std)] + +use sp_runtime::traits::{StaticLookup, SignedExtension}; +pub use pallet_balances::Call as BalancesCall; + +/// AccountIndex type for Runtime +pub type IndexFor = ::Index; +/// Balance type +pub type BalanceFor = ::Balance; +/// Call type for Runtime +pub type CallFor = ::Call; +/// Address type for runtime. +pub type AddressFor = <::Lookup as StaticLookup>::Source; +/// Hash for runtime. +pub type HashFor = ::Hash; +/// AccountId type for runtime. +pub type AccountIdFor = ::AccountId; + +/// +/// Strongly typed interface for the `SignedExtensions` that should be included in extrinsics +/// for them to valid for your runtime. +/// +/// ```rust,ignore +/// use runtime::{Runtime, SignedExtra}; +/// use frame_utils::{IndexFor}; +/// use sp_runtime::generic; +/// +/// impl RuntimeAdapter for Runtime { +/// type Extra = SignedExtra; +/// +/// fn construct_extras(index: IndexFor) -> Self::Extra { +/// // take the biggest period possible. +/// let period = BlockHashCount::get() +/// .checked_next_power_of_two() +/// .map(|c| c / 2) +/// .unwrap_or(2) as u64; +/// let current_block = System::block_number() +/// .saturated_into::() +/// // The `System::block_number` is initialized with `n+1`, +/// // so the actual block number is `n`. +/// .saturating_sub(1); +/// +/// ( +/// frame_system::CheckSpecVersion::new(), +/// frame_system::CheckTxVersion::new(), +/// frame_system::CheckGenesis::new(), +/// frame_system::CheckEra::from(generic::Era::mortal(period, current_block)), +/// frame_system::CheckNonce::from(index), +/// frame_system::CheckWeight::new(), +/// ) +/// } +/// } +/// +/// ``` +/// +pub trait SignedExtensionProvider: frame_system::Trait { + /// Concrete SignedExtension type. + type Extra: SignedExtension; + + /// build extras for inclusion in extrinsics + fn construct_extras(nonce: IndexFor) -> Self::Extra; +} + diff --git a/utils/frame/frame-utilities-cli/Cargo.toml b/utils/frame/frame-utilities-cli/Cargo.toml index 4f840f4e5c7ef..d25213ed8fa03 100644 --- a/utils/frame/frame-utilities-cli/Cargo.toml +++ b/utils/frame/frame-utilities-cli/Cargo.toml @@ -7,7 +7,7 @@ license = "GPL-3.0" homepage = "https://substrate.dev" repository = "https://github.com/paritytech/substrate/" description = "CLI utils" -documentation = "https://docs.rs/cli-utils" +documentation = "https://docs.rs/frame-utils" [dependencies] sp-core = { version = "2.0.0-dev", path = "../../../primitives/core" } @@ -15,7 +15,8 @@ sc-cli = { version = "0.8.0-dev", path = "../../../client/cli" } sp-runtime = { version = "2.0.0-dev", path = "../../../primitives/runtime" } structopt = "0.3.8" codec = { version = "1.3.0", package = "parity-scale-codec" } -cli-utils = { path = "../../cli-utils", version = "2.0.0-dev" } +pallet-balances = { version = "2.0.0-alpha.8", path = "../../../frame/balances" } +frame-utils = { path = "../../frame-utils", version = "2.0.0-dev" } hex = "0.4.2" serde = "1.0.106" hyper = "0.12.35" @@ -26,6 +27,7 @@ sc-rpc = { version = "2.0.0-dev", path = "../../../client/rpc" } sc-service = { version = "0.8.0-dev", default-features = false, path = "../../../client/service" } sc-client-api = { version = "2.0.0-dev", default-features = false, path = "../../../client/api" } futures01 = { package = "futures", version = "0.1.29" } +futures = "0.3" [dev-dependencies] tempfile = "3.1.0" @@ -34,4 +36,4 @@ frame-system = { version = "2.0.0-alpha.7", path = "../../../frame/system" } substrate-test-runtime = { version = "2.0.0-dev", features = ["indices-lookup"], path = "../../../test-utils/runtime" } [features] -pallet-balances = [] +balances = [] diff --git a/utils/frame/frame-utilities-cli/src/generate.rs b/utils/frame/frame-utilities-cli/src/generate.rs index 7a1de8a7c9d6b..b8c5692c9e8cd 100644 --- a/utils/frame/frame-utilities-cli/src/generate.rs +++ b/utils/frame/frame-utilities-cli/src/generate.rs @@ -1,18 +1,19 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. +// Copyright (C) 2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. //! Implementation of the `generate` subcommand use bip39::{MnemonicType, Mnemonic, Language}; diff --git a/utils/frame/frame-utilities-cli/src/generate_node_key.rs b/utils/frame/frame-utilities-cli/src/generate_node_key.rs index b6bce3c9233e6..af1cf4eebad77 100644 --- a/utils/frame/frame-utilities-cli/src/generate_node_key.rs +++ b/utils/frame/frame-utilities-cli/src/generate_node_key.rs @@ -1,18 +1,19 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . +// Copyright (C) 2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. //! Implementation of the `generate-node-key` subcommand diff --git a/utils/frame/frame-utilities-cli/src/insert.rs b/utils/frame/frame-utilities-cli/src/insert.rs index 4641362086033..75adf2f751349 100644 --- a/utils/frame/frame-utilities-cli/src/insert.rs +++ b/utils/frame/frame-utilities-cli/src/insert.rs @@ -1,18 +1,19 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . +// Copyright (C) 2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. //! Implementation of the `insert` subcommand @@ -29,7 +30,7 @@ use hyper::rt; use sc_rpc::author::AuthorClient; use jsonrpc_core_client::transports::http; use serde::{de::DeserializeOwned, Serialize}; -use cli_utils::{HashFor, RuntimeAdapter}; +use frame_utils::{HashFor, SignedExtensionProvider}; /// The `insert` command #[derive(Debug, StructOpt, Clone)] @@ -67,10 +68,10 @@ pub struct InsertCmd { impl InsertCmd { /// Run the command - pub fn run(&self) -> Result<(), Error> + pub fn run

(&self) -> Result<(), Error> where - RA: RuntimeAdapter, - HashFor: DeserializeOwned + Serialize + Send + Sync, + P: SignedExtensionProvider, + HashFor

: DeserializeOwned + Serialize + Send + Sync, { let suri = read_uri(self.suri.as_ref())?; let password = self.keystore_params.read_password()?; @@ -92,7 +93,7 @@ impl InsertCmd { })?; - insert_key::>( + insert_key::>( &node_url, key_type.to_string(), suri, diff --git a/utils/frame/frame-utilities-cli/src/inspect.rs b/utils/frame/frame-utilities-cli/src/inspect.rs index 9fb0a9433d749..3751f4acb19fd 100644 --- a/utils/frame/frame-utilities-cli/src/inspect.rs +++ b/utils/frame/frame-utilities-cli/src/inspect.rs @@ -1,18 +1,19 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . +// Copyright (C) 2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. //! Implementation of the `inspect` subcommand diff --git a/utils/frame/frame-utilities-cli/src/key.rs b/utils/frame/frame-utilities-cli/src/key.rs index 1bab181bd7ad2..67c830b258d78 100644 --- a/utils/frame/frame-utilities-cli/src/key.rs +++ b/utils/frame/frame-utilities-cli/src/key.rs @@ -1,24 +1,25 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. +// Copyright (C) 2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. //! Key related CLI utilities use sc_cli::{Error, substrate_cli_subcommands}; use structopt::StructOpt; -use cli_utils::{HashFor, RuntimeAdapter}; +use frame_utils::{HashFor, SignedExtensionProvider}; use serde::{de::DeserializeOwned, Serialize}; use crate::{ @@ -46,16 +47,16 @@ pub enum KeySubcommand { impl KeySubcommand { /// run the key subcommands - pub fn run(&self) -> Result<(), Error> + pub fn run

(&self) -> Result<(), Error> where - RA: RuntimeAdapter, - HashFor: DeserializeOwned + Serialize + Send + Sync, + P: SignedExtensionProvider, + HashFor

: DeserializeOwned + Serialize + Send + Sync, { match self { KeySubcommand::GenerateNodeKey(cmd) => cmd.run(), KeySubcommand::Generate(cmd) => cmd.run(), KeySubcommand::InspectKey(cmd) => cmd.run(), - KeySubcommand::Insert(cmd) => cmd.run::(), + KeySubcommand::Insert(cmd) => cmd.run::

(), } } } diff --git a/utils/frame/frame-utilities-cli/src/lib.rs b/utils/frame/frame-utilities-cli/src/lib.rs index 20b0d52edc1b6..fb3f54e30dd72 100644 --- a/utils/frame/frame-utilities-cli/src/lib.rs +++ b/utils/frame/frame-utilities-cli/src/lib.rs @@ -1,18 +1,19 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. +// Copyright (C) 2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. //! frame-system CLI utilities @@ -23,9 +24,9 @@ mod inspect; mod key; mod utils; mod sign_transaction; -#[cfg(feature = "pallet-balances")] +#[cfg(feature = "balances")] mod transfer; -#[cfg(feature = "pallet-balances")] +#[cfg(feature = "balances")] pub use transfer::TransferCmd; pub use {key::KeySubcommand, sign_transaction::SignTransactionCmd}; diff --git a/utils/frame/frame-utilities-cli/src/sign_transaction.rs b/utils/frame/frame-utilities-cli/src/sign_transaction.rs index 830dd7f0feaea..fa566f95a4361 100644 --- a/utils/frame/frame-utilities-cli/src/sign_transaction.rs +++ b/utils/frame/frame-utilities-cli/src/sign_transaction.rs @@ -1,18 +1,19 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . +// Copyright (C) 2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. //! Implementation of the `sign-transaction` subcommand use sc_cli::{ @@ -24,7 +25,7 @@ use structopt::StructOpt; use codec::{Codec, Encode, Decode}; use std::{str::FromStr, fmt::Display}; use sp_runtime::MultiSigner; -use cli_utils::{RuntimeAdapter, IndexFor, CallFor}; +use frame_utils::{SignedExtensionProvider, IndexFor, CallFor}; use crate::utils::create_extrinsic_for; type Call = Vec; @@ -66,7 +67,7 @@ impl SignTransactionCmd { /// Run the command pub fn run(&self) -> Result<(), Error> where - RA: RuntimeAdapter, + RA: SignedExtensionProvider, as FromStr>::Err: Display, CallFor: Codec, { @@ -91,16 +92,16 @@ impl CliConfiguration for SignTransactionCmd { } -fn print_ext(uri: &str, pass: &str, call: CallFor, nonce: IndexFor) -> Result<(), Error> +fn print_ext(uri: &str, pass: &str, call: CallFor

, nonce: IndexFor

) -> Result<(), Error> where Pair: sp_core::Pair, Pair::Public: Into, Pair::Signature: Encode, - RA: RuntimeAdapter, - CallFor: Codec, + P: SignedExtensionProvider, + CallFor

: Codec, { let signer = pair_from_suri::(uri, pass); - let extrinsic = create_extrinsic_for::>(call, nonce, signer)?; + let extrinsic = create_extrinsic_for::>(call, nonce, signer)?; println!("0x{}", hex::encode(Encode::encode(&extrinsic))); Ok(()) } diff --git a/utils/frame/frame-utilities-cli/src/transfer.rs b/utils/frame/frame-utilities-cli/src/transfer.rs index 11319bf7ad929..cdae9ef94e793 100644 --- a/utils/frame/frame-utilities-cli/src/transfer.rs +++ b/utils/frame/frame-utilities-cli/src/transfer.rs @@ -1,6 +1,6 @@ // This file is part of Substrate. -// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd. +// Copyright (C) 2020 Parity Technologies (UK) Ltd. // SPDX-License-Identifier: Apache-2.0 // Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,7 +27,9 @@ use codec::Encode; use sp_runtime::MultiSigner; use std::convert::TryFrom; use sp_core::crypto::Ss58Codec; -use cli_utils::{AddressFor, IndexFor, BalanceFor, BalancesCall, AccountIdFor, RuntimeAdapter}; +use frame_utils::{ + AddressFor, IndexFor, BalanceFor, BalancesCall, AccountIdFor, SignedExtensionProvider, +}; use crate::utils::create_extrinsic_for; /// The `transfer` command @@ -71,7 +73,7 @@ impl TransferCmd { /// Run the command pub fn run(&self) -> Result<(), Error> where - RA: RuntimeAdapter, + RA: pallet_balances::Trait + SignedExtensionProvider, AccountIdFor: for<'a> TryFrom<&'a [u8], Error = ()> + Ss58Codec, AddressFor: From>, as FromStr>::Err: Display, @@ -111,23 +113,23 @@ impl CliConfiguration for TransferCmd { } } -fn print_ext( +fn print_ext( uri: &str, pass: &str, - to: AddressFor, - nonce: IndexFor, - amount: BalanceFor, + to: AddressFor

, + nonce: IndexFor

, + amount: BalanceFor

, ) -> Result<(), Error> where Pair: sp_core::Pair, Pair::Public: Into, Pair::Signature: Encode, - RA: RuntimeAdapter, - BalancesCall: Encode, + P: pallet_balances::Trait + SignedExtensionProvider, + BalancesCall

: Encode, { let signer = pair_from_suri::(uri, pass); let call = BalancesCall::transfer(to, amount); - let extrinsic = create_extrinsic_for::(call, nonce, signer)?; + let extrinsic = create_extrinsic_for::(call, nonce, signer)?; println!("0x{}", hex::encode(Encode::encode(&extrinsic))); Ok(()) } diff --git a/utils/frame/frame-utilities-cli/src/utils.rs b/utils/frame/frame-utilities-cli/src/utils.rs index 43bd14863a06a..818245ee7555c 100644 --- a/utils/frame/frame-utilities-cli/src/utils.rs +++ b/utils/frame/frame-utilities-cli/src/utils.rs @@ -1,40 +1,42 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. +// Copyright (C) 2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . use sp_runtime::{ MultiSigner, AccountId32, traits::IdentifyAccount, generic::{UncheckedExtrinsic, SignedPayload}, }; use codec::Encode; -use cli_utils::{RuntimeAdapter, IndexFor}; +use frame_utils::{SignedExtensionProvider, IndexFor}; /// create an extrinsic for the runtime. -pub fn create_extrinsic_for( +pub fn create_extrinsic_for( call: Call, - nonce: IndexFor, + nonce: IndexFor

, signer: Pair, -) -> Result, &'static str> +) -> Result, &'static str> where Call: Encode, Pair: sp_core::Pair, Pair::Public: Into, Pair::Signature: Encode, - RA: RuntimeAdapter, + P: SignedExtensionProvider, { - let extra = RA::build_extra(nonce); + let extra = P::construct_extras(nonce); let payload = SignedPayload::new(call, extra) .map_err(|_| "Transaction validity error")?; From a0fe47d65da6f325a065279948daea913c8da1a0 Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 25 May 2020 13:59:12 +0100 Subject: [PATCH 47/77] rename BlockNumber to GenericNumber, fix spaces --- client/cli/src/commands/export_blocks_cmd.rs | 6 ++-- client/cli/src/commands/revert_cmd.rs | 4 +-- client/cli/src/params/keystore_params.rs | 2 +- client/cli/src/params/mod.rs | 10 +++--- utils/frame-utils/Cargo.toml | 6 ++-- utils/frame-utils/src/lib.rs | 2 +- utils/frame/frame-utilities-cli/src/lib.rs | 4 +-- .../src/sign_transaction.rs | 20 +++++------ .../frame/frame-utilities-cli/src/transfer.rs | 35 ++++++++++--------- 9 files changed, 45 insertions(+), 44 deletions(-) diff --git a/client/cli/src/commands/export_blocks_cmd.rs b/client/cli/src/commands/export_blocks_cmd.rs index 2fdc408250bce..fb57b87bf58b7 100644 --- a/client/cli/src/commands/export_blocks_cmd.rs +++ b/client/cli/src/commands/export_blocks_cmd.rs @@ -17,7 +17,7 @@ // along with this program. If not, see . use crate::error; -use crate::params::{BlockNumber, DatabaseParams, PruningParams, SharedParams}; +use crate::params::{GenericNumber, DatabaseParams, PruningParams, SharedParams}; use crate::CliConfiguration; use log::info; use sc_service::{ @@ -41,13 +41,13 @@ pub struct ExportBlocksCmd { /// /// Default is 1. #[structopt(long = "from", value_name = "BLOCK")] - pub from: Option, + pub from: Option, /// Specify last block number. /// /// Default is best block. #[structopt(long = "to", value_name = "BLOCK")] - pub to: Option, + pub to: Option, /// Use binary output rather than JSON. #[structopt(long)] diff --git a/client/cli/src/commands/revert_cmd.rs b/client/cli/src/commands/revert_cmd.rs index 6117eaf4880bf..63ca21e04343f 100644 --- a/client/cli/src/commands/revert_cmd.rs +++ b/client/cli/src/commands/revert_cmd.rs @@ -17,7 +17,7 @@ // along with this program. If not, see . use crate::error; -use crate::params::{BlockNumber, PruningParams, SharedParams}; +use crate::params::{GenericNumber, PruningParams, SharedParams}; use crate::CliConfiguration; use sc_service::{Configuration, ServiceBuilderCommand}; use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; @@ -29,7 +29,7 @@ use structopt::StructOpt; pub struct RevertCmd { /// Number of blocks to revert. #[structopt(default_value = "256")] - pub num: BlockNumber, + pub num: GenericNumber, #[allow(missing_docs)] #[structopt(flatten)] diff --git a/client/cli/src/params/keystore_params.rs b/client/cli/src/params/keystore_params.rs index b3ae9e31a6063..5e70142a0da61 100644 --- a/client/cli/src/params/keystore_params.rs +++ b/client/cli/src/params/keystore_params.rs @@ -94,7 +94,7 @@ impl KeystoreParams { let pass = if password_interactive { rpassword::read_password_from_tty(Some("Key password: "))? } else { - password.map(Into::into).ok_or("Password not specified")? + password.map(Into::into).ok_or("one of --password or --password-interactive was not specified")? }; Ok(pass) diff --git a/client/cli/src/params/mod.rs b/client/cli/src/params/mod.rs index 45899f5a4bedd..e69f34d8fb89c 100644 --- a/client/cli/src/params/mod.rs +++ b/client/cli/src/params/mod.rs @@ -40,9 +40,9 @@ pub use crate::params::transaction_pool_params::*; /// Wrapper type of `String` that holds an unsigned integer of arbitrary size, formatted as a decimal. #[derive(Debug, Clone)] -pub struct BlockNumber(String); +pub struct GenericNumber(String); -impl FromStr for BlockNumber { +impl FromStr for GenericNumber { type Err = String; fn from_str(block_number: &str) -> Result { @@ -57,7 +57,7 @@ impl FromStr for BlockNumber { } } -impl BlockNumber { +impl GenericNumber { /// Wrapper on top of `std::str::parse` but with `Error` as a `String` /// /// See `https://doc.rust-lang.org/std/primitive.str.html#method.parse` for more elaborate @@ -89,7 +89,7 @@ impl FromStr for BlockNumberOrHash { Ok(Self(block_number.into())) } } else { - BlockNumber::from_str(block_number).map(|v| Self(v.0)) + GenericNumber::from_str(block_number).map(|v| Self(v.0)) } } } @@ -109,7 +109,7 @@ impl BlockNumberOrHash { .map_err(|e| format!("Failed to parse block hash: {:?}", e))? )) } else { - BlockNumber(self.0.clone()).parse().map(BlockId::Number) + GenericNumber(self.0.clone()).parse().map(BlockId::Number) } } } diff --git a/utils/frame-utils/Cargo.toml b/utils/frame-utils/Cargo.toml index 92158b9744504..de2fe004dc1f6 100644 --- a/utils/frame-utils/Cargo.toml +++ b/utils/frame-utils/Cargo.toml @@ -19,8 +19,8 @@ codec = { version = "1.3.0", default-features = false, package = "parity-scale-c [features] default = ["std"] std = [ - "frame-system/std", - "pallet-balances/std", - "sp-runtime/std", + "frame-system/std", + "pallet-balances/std", + "sp-runtime/std", "sp-core/std", ] diff --git a/utils/frame-utils/src/lib.rs b/utils/frame-utils/src/lib.rs index 3ae560f1c4f73..7a0892545c879 100644 --- a/utils/frame-utils/src/lib.rs +++ b/utils/frame-utils/src/lib.rs @@ -41,7 +41,7 @@ pub type AccountIdFor = ::AccountId; /// /// ```rust,ignore /// use runtime::{Runtime, SignedExtra}; -/// use frame_utils::{IndexFor}; +/// use frame_utils::IndexFor; /// use sp_runtime::generic; /// /// impl RuntimeAdapter for Runtime { diff --git a/utils/frame/frame-utilities-cli/src/lib.rs b/utils/frame/frame-utilities-cli/src/lib.rs index fb3f54e30dd72..ce405531af3a5 100644 --- a/utils/frame/frame-utilities-cli/src/lib.rs +++ b/utils/frame/frame-utilities-cli/src/lib.rs @@ -27,7 +27,7 @@ mod sign_transaction; #[cfg(feature = "balances")] mod transfer; #[cfg(feature = "balances")] -pub use transfer::TransferCmd; +pub use transfer::TransferCmd; pub use {key::KeySubcommand, sign_transaction::SignTransactionCmd}; @@ -39,7 +39,7 @@ mod tests { use structopt::StructOpt; use std::io::Read; - #[test] + #[test] fn generate() { let generate = GenerateCmd::from_iter(&["generate", "--password", "12345"]); assert!(generate.run().is_ok()) diff --git a/utils/frame/frame-utilities-cli/src/sign_transaction.rs b/utils/frame/frame-utilities-cli/src/sign_transaction.rs index fa566f95a4361..f23acedf53b86 100644 --- a/utils/frame/frame-utilities-cli/src/sign_transaction.rs +++ b/utils/frame/frame-utilities-cli/src/sign_transaction.rs @@ -19,11 +19,11 @@ use sc_cli::{ Error, CliConfiguration, KeystoreParams, SharedParams, pair_from_suri, decode_hex,with_crypto_scheme, - CryptoSchemeFlag, + CryptoSchemeFlag, GenericNumber, }; use structopt::StructOpt; use codec::{Codec, Encode, Decode}; -use std::{str::FromStr, fmt::Display}; +use std::{str::FromStr, fmt::Debug}; use sp_runtime::MultiSigner; use frame_utils::{SignedExtensionProvider, IndexFor, CallFor}; use crate::utils::create_extrinsic_for; @@ -44,7 +44,7 @@ pub struct SignTransactionCmd { /// The nonce. #[structopt(long)] - nonce: String, + nonce: GenericNumber, /// The call, hex-encoded. #[structopt(long, parse(try_from_str = decode_hex))] @@ -65,18 +65,18 @@ pub struct SignTransactionCmd { impl SignTransactionCmd { /// Run the command - pub fn run(&self) -> Result<(), Error> + pub fn run

(&self) -> Result<(), Error> where - RA: SignedExtensionProvider, - as FromStr>::Err: Display, - CallFor: Codec, + P: SignedExtensionProvider, + as FromStr>::Err: Debug, + CallFor

: Codec, { - let nonce = IndexFor::::from_str(&self.nonce).map_err(|e| format!("{}", e))?; - let call = CallFor::::decode(&mut &self.call[..])?; + let nonce = self.nonce.parse::>()?; + let call = CallFor::

::decode(&mut &self.call[..])?; let pass = self.keystore_params.read_password()?; - with_crypto_scheme!(self.crypto_scheme.scheme, print_ext(&self.suri, &pass, call, nonce)) + with_crypto_scheme!(self.crypto_scheme.scheme, print_ext

(&self.suri, &pass, call, nonce)) } } diff --git a/utils/frame/frame-utilities-cli/src/transfer.rs b/utils/frame/frame-utilities-cli/src/transfer.rs index cdae9ef94e793..62b02ed278690 100644 --- a/utils/frame/frame-utilities-cli/src/transfer.rs +++ b/utils/frame/frame-utilities-cli/src/transfer.rs @@ -19,10 +19,11 @@ use sc_cli::{ Error, SharedParams, pair_from_suri, with_crypto_scheme, - CryptoSchemeFlag, decode_hex, CliConfiguration, KeystoreParams, + CryptoSchemeFlag, decode_hex, CliConfiguration, KeystoreParams, + GenericNumber, }; use structopt::StructOpt; -use std::{str::FromStr, fmt::Display}; +use std::{str::FromStr, fmt::Debug}; use codec::Encode; use sp_runtime::MultiSigner; use std::convert::TryFrom; @@ -41,7 +42,7 @@ use crate::utils::create_extrinsic_for; pub struct TransferCmd { /// The number of units to transfer. #[structopt(long)] - amount: String, + amount: GenericNumber, /// The signing secret key URI. #[structopt(long)] @@ -49,7 +50,7 @@ pub struct TransferCmd { /// The signing account's transaction index. #[structopt(long)] - index: String, + index: GenericNumber, /// The destination account public key URI. #[structopt(long)] @@ -71,28 +72,28 @@ pub struct TransferCmd { impl TransferCmd { /// Run the command - pub fn run(&self) -> Result<(), Error> + pub fn run(&self) -> Result<(), Error> where - RA: pallet_balances::Trait + SignedExtensionProvider, - AccountIdFor: for<'a> TryFrom<&'a [u8], Error = ()> + Ss58Codec, - AddressFor: From>, - as FromStr>::Err: Display, - as FromStr>::Err: Display, + R: pallet_balances::Trait + SignedExtensionProvider, + AccountIdFor: for<'a> TryFrom<&'a [u8], Error = ()> + Ss58Codec, + AddressFor: From>, + as FromStr>::Err: Debug, + as FromStr>::Err: Debug, { let password = self.keystore_params.read_password()?; - let nonce = IndexFor::::from_str(&self.index).map_err(|e| format!("{}", e))?; + let nonce = self.index.parse::>()?; let to = if let Ok(data_vec) = decode_hex(&self.to) { - AccountIdFor::::try_from(&data_vec) - .expect("Invalid hex length for account ID; should be 32 bytes") + AccountIdFor::::try_from(&data_vec) + .map_err(|_| Error::Other("Invalid hex length for account ID; should be 32 bytes".into()))? } else { - AccountIdFor::::from_ss58check(&self.to).ok() - .expect("Invalid SS58-check address given for account ID.") + AccountIdFor::::from_ss58check(&self.to) + .map_err(|_| Error::Other("Invalid SS58-check address given for account ID.".into()))? }; - let amount = BalanceFor::::from_str(&self.amount).map_err(|e| format!("{}", e))?; + let amount = self.amount.parse::>()?; with_crypto_scheme!( self.crypto_scheme.scheme, - print_ext( + print_ext( &self.from, &password, to.into(), From 762ed30a7b76df7b174fc296887e3a6e46cbcd75 Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 25 May 2020 19:40:33 +0100 Subject: [PATCH 48/77] fix spaces --- utils/frame/frame-utilities-cli/src/lib.rs | 50 +++++++++++----------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/utils/frame/frame-utilities-cli/src/lib.rs b/utils/frame/frame-utilities-cli/src/lib.rs index ce405531af3a5..0471131773fbc 100644 --- a/utils/frame/frame-utilities-cli/src/lib.rs +++ b/utils/frame/frame-utilities-cli/src/lib.rs @@ -40,33 +40,33 @@ mod tests { use std::io::Read; #[test] - fn generate() { - let generate = GenerateCmd::from_iter(&["generate", "--password", "12345"]); - assert!(generate.run().is_ok()) - } + fn generate() { + let generate = GenerateCmd::from_iter(&["generate", "--password", "12345"]); + assert!(generate.run().is_ok()) + } - #[test] - fn generate_node_key() { - let mut file = Builder::new().prefix("keyfile").tempfile().unwrap(); - let generate = - GenerateNodeIdCmd::from_iter(&["generate-node-key", "--file", "/tmp/keyfile"]); - assert!(generate.run().is_ok()); - let mut buf = String::new(); - assert!(file.read_to_string(&mut buf).is_ok()); - assert!(hex::decode(buf).is_ok()); - } + #[test] + fn generate_node_key() { + let mut file = Builder::new().prefix("keyfile").tempfile().unwrap(); + let generate = + GenerateNodeIdCmd::from_iter(&["generate-node-key", "--file", "/tmp/keyfile"]); + assert!(generate.run().is_ok()); + let mut buf = String::new(); + assert!(file.read_to_string(&mut buf).is_ok()); + assert!(hex::decode(buf).is_ok()); + } - #[test] - fn inspect() { - let words = - "remember fiber forum demise paper uniform squirrel feel access exclude casual effort"; - let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; + #[test] + fn inspect() { + let words = + "remember fiber forum demise paper uniform squirrel feel access exclude casual effort"; + let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; - let inspect = - InspectCmd::from_iter(&["inspect-key", "--uri", words, "--password", "12345"]); - assert!(inspect.run().is_ok()); + let inspect = + InspectCmd::from_iter(&["inspect-key", "--uri", words, "--password", "12345"]); + assert!(inspect.run().is_ok()); - let inspect = InspectCmd::from_iter(&["inspect-key", "--uri", seed]); - assert!(inspect.run().is_ok()); - } + let inspect = InspectCmd::from_iter(&["inspect-key", "--uri", seed]); + assert!(inspect.run().is_ok()); + } } From 8c19813a1b663b9e396ee561ce4c37cf9648a2c3 Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 1 Jun 2020 20:59:17 +0100 Subject: [PATCH 49/77] construct additional_signed manually --- Cargo.lock | 1 + bin/node-template/runtime/src/lib.rs | 17 --- bin/node/runtime/src/lib.rs | 84 ++++++++----- client/cli/src/commands/sign.rs | 4 +- client/cli/src/commands/utils.rs | 4 +- client/cli/src/params/keystore_params.rs | 8 +- client/service/src/builder.rs | 1 + test-utils/runtime/src/lib.rs | 15 ++- utils/frame-utils/src/lib.rs | 8 +- utils/frame/frame-utilities-cli/Cargo.toml | 3 +- .../frame/frame-utilities-cli/src/generate.rs | 2 +- utils/frame/frame-utilities-cli/src/insert.rs | 4 +- .../frame/frame-utilities-cli/src/inspect.rs | 4 +- .../src/sign_transaction.rs | 44 +++++-- .../frame/frame-utilities-cli/src/transfer.rs | 115 ++++++++++-------- utils/frame/frame-utilities-cli/src/utils.rs | 40 ++++-- 16 files changed, 209 insertions(+), 145 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae56942e45757..8b95ff0cb1ffe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1604,6 +1604,7 @@ dependencies = [ "jsonrpc-core-client", "libp2p 0.18.1", "pallet-balances", + "pallet-indices", "parity-scale-codec", "sc-cli", "sc-client-api", diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index 75756b9d011bf..68d4eeeb7ad3a 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -21,7 +21,6 @@ use sp_api::impl_runtime_apis; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList}; use grandpa::fg_primitives; -use frame_utils::SignedExtensionProvider; use sp_version::RuntimeVersion; #[cfg(feature = "std")] use sp_version::NativeVersion; @@ -413,19 +412,3 @@ impl_runtime_apis! { } } } - -impl SignedExtensionProvider for Runtime { - type Extra = SignedExtra; - - fn construct_extras(index: Index) -> Self::Extra { - ( - system::CheckSpecVersion::new(), - system::CheckTxVersion::new(), - system::CheckGenesis::new(), - system::CheckEra::from(generic::Era::Immortal), - system::CheckNonce::from(index), - system::CheckWeight::new(), - transaction_payment::ChargeTransactionPayment::from(0), - ) - } -} diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index f6a5a18a39ebc..a83b2a89093a3 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -45,10 +45,7 @@ use sp_runtime::{ }; use sp_runtime::curve::PiecewiseLinear; use sp_runtime::transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority}; -use sp_runtime::traits::{ - self, BlakeTwo256, Block as BlockT, StaticLookup, SaturatedConversion, - ConvertInto, OpaqueKeys, NumberFor, Saturating, -}; +use sp_runtime::traits::{self, BlakeTwo256, Block as BlockT, StaticLookup, SaturatedConversion, ConvertInto, OpaqueKeys, NumberFor, Saturating, SignedExtension}; use frame_utils::{SignedExtensionProvider, IndexFor}; use sp_version::RuntimeVersion; #[cfg(any(feature = "std", test))] @@ -80,6 +77,7 @@ use impls::{CurrencyToVoteHandler, Author, TargetedFeeAdjustment}; /// Constant values used within the runtime. pub mod constants; use constants::{time::*, currency::*}; +use sp_runtime::generic::Era; // Make the WASM binary available. #[cfg(feature = "std")] @@ -536,28 +534,34 @@ parameter_types! { impl SignedExtensionProvider for Runtime { type Extra = SignedExtra; - fn construct_extras(index: IndexFor) -> Self::Extra { - // take the biggest period possible. - let period = BlockHashCount::get() - .checked_next_power_of_two() - .map(|c| c / 2) - .unwrap_or(2) as u64; - let current_block = System::block_number() - .saturated_into::() - // The `System::block_number` is initialized with `n+1`, - // so the actual block number is `n`. - .saturating_sub(1); + fn construct_extras(index: IndexFor, era: Era, genesis: Option) -> ( + Self::Extra, + Option<::AdditionalSigned> + ) { let tip = 0; - ( - frame_system::CheckSpecVersion::::new(), - frame_system::CheckTxVersion::::new(), - frame_system::CheckGenesis::::new(), - frame_system::CheckEra::::from(generic::Era::mortal(period, current_block)), - frame_system::CheckNonce::::from(index), - frame_system::CheckWeight::::new(), - pallet_transaction_payment::ChargeTransactionPayment::::from(tip), - pallet_grandpa::ValidateEquivocationReport::::new(), + ( + frame_system::CheckSpecVersion::::new(), + frame_system::CheckTxVersion::::new(), + frame_system::CheckGenesis::::new(), + frame_system::CheckEra::::from(era), + frame_system::CheckNonce::::from(index), + frame_system::CheckWeight::::new(), + pallet_transaction_payment::ChargeTransactionPayment::::from(tip), + pallet_grandpa::ValidateEquivocationReport::::new(), + ), + genesis.map(|genesis| { + ( + VERSION.spec_version, + VERSION.transaction_version, + genesis, + genesis, + (), + (), + (), + (), + ) + }) ) } } @@ -572,13 +576,31 @@ impl frame_system::offchain::CreateSignedTransaction for R account: AccountId, nonce: Index, ) -> Option<(Call, ::SignaturePayload)> { - let extra = Runtime::construct_extras(nonce); - let raw_payload = SignedPayload::new(call, extra).map_err(|e| { - debug::warn!("Unable to create signed payload: {:?}", e); - }).ok()?; - let signature = raw_payload.using_encoded(|payload| { - C::sign(payload, public) - })?; + // take the biggest period possible. + let period = BlockHashCount::get() + .checked_next_power_of_two() + .map(|c| c / 2) + .unwrap_or(2) as u64; + let current_block = System::block_number() + .saturated_into::() + // The `System::block_number` is initialized with `n+1`, + // so the actual block number is `n`. + .saturating_sub(1); + let era = Era::mortal(period, current_block); + let (extra, additional) = Runtime::construct_extras(nonce, era, None); + let raw_payload = if let Some(additional_signed) = additional { + SignedPayload::from_raw(call, extra, additional_signed) + } else { + SignedPayload::new(call, extra) + .map_err(|e| { + debug::warn!("Unable to create signed payload: {:?}", e); + }) + .ok()? + }; + let signature = raw_payload + .using_encoded(|payload| { + C::sign(payload, public) + })?; let address = Indices::unlookup(account); let (call, extra, _) = raw_payload.deconstruct(); Some((call, (address, signature.into(), extra))) diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs index 25617a010e379..651fa6b86ad73 100644 --- a/client/cli/src/commands/sign.rs +++ b/client/cli/src/commands/sign.rs @@ -66,7 +66,7 @@ impl SignCmd { let signature = with_crypto_scheme!( self.crypto_scheme.scheme, - sign(&suri, &password, message) + sign(&suri, password.as_ref().map(String::as_str), message) )?; println!("{}", signature); @@ -84,7 +84,7 @@ impl CliConfiguration for SignCmd { } } -fn sign(suri: &str, password: &str, message: Vec) -> error::Result { +fn sign(suri: &str, password: Option<&str>, message: Vec) -> error::Result { let pair = pair_from_suri::

(suri, password); Ok(format!("{}", hex::encode(pair.sign(&message)))) } diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 0e7a8b29055d2..9c211fa67b94a 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -150,8 +150,8 @@ pub fn print_from_uri( } /// generate a pair from suri -pub fn pair_from_suri(suri: &str, password: &str) -> P { - P::from_string(suri, Some(password)).expect("Invalid phrase") +pub fn pair_from_suri(suri: &str, password: Option<&str>) -> P { + P::from_string(suri, password).expect("Invalid phrase") } /// formats seed as hex diff --git a/client/cli/src/params/keystore_params.rs b/client/cli/src/params/keystore_params.rs index 5e70142a0da61..4babc7d80d464 100644 --- a/client/cli/src/params/keystore_params.rs +++ b/client/cli/src/params/keystore_params.rs @@ -88,13 +88,13 @@ impl KeystoreParams { } /// helper method to fetch password from `KeyParams` or read from stdin - pub fn read_password(&self) -> error::Result { - let (password_interactive, password) = (self.password_interactive, self.password.as_ref()); + pub fn read_password(&self) -> error::Result> { + let (password_interactive, password) = (self.password_interactive, self.password.clone()); let pass = if password_interactive { - rpassword::read_password_from_tty(Some("Key password: "))? + Some(rpassword::read_password_from_tty(Some("Key password: "))?) } else { - password.map(Into::into).ok_or("one of --password or --password-interactive was not specified")? + password }; Ok(pass) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index d921606ea6b16..d7b4dbf9b452e 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -826,6 +826,7 @@ pub trait ServiceBuilderCommand { type Block: BlockT; /// Native execution dispatch required by some commands. type NativeDispatch: NativeExecutionDispatch + 'static; + /// Starts the process of importing blocks. fn import_blocks( self, diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index f550caf484c6f..8e0345e3f5839 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -57,6 +57,7 @@ use cfg_if::cfg_if; pub use sp_consensus_babe::{AuthorityId, SlotNumber, AllowedSlots}; use frame_utils::{SignedExtensionProvider, IndexFor}; use sp_runtime::generic::Era; +use sp_runtime::traits::SignedExtension; pub type AuraId = sp_consensus_aura::sr25519::AuthorityId; @@ -424,11 +425,17 @@ impl SignedExtensionProvider for Runtime { frame_system::CheckEra, ); - fn construct_extras(_index: IndexFor) -> Self::Extra { + fn construct_extras(_index: IndexFor, era: Era, _genesis: Option) -> ( + Self::Extra, + Option<::AdditionalSigned> + ) { ( - frame_system::CheckTxVersion::new(), - frame_system::CheckGenesis::new(), - frame_system::CheckEra::from(Era::Immortal), + ( + frame_system::CheckTxVersion::new(), + frame_system::CheckGenesis::new(), + frame_system::CheckEra::from(era) + ), + None ) } } diff --git a/utils/frame-utils/src/lib.rs b/utils/frame-utils/src/lib.rs index 7a0892545c879..522ed27e3feb6 100644 --- a/utils/frame-utils/src/lib.rs +++ b/utils/frame-utils/src/lib.rs @@ -21,6 +21,7 @@ use sp_runtime::traits::{StaticLookup, SignedExtension}; pub use pallet_balances::Call as BalancesCall; +use sp_runtime::generic::Era; /// AccountIndex type for Runtime pub type IndexFor = ::Index; @@ -76,7 +77,10 @@ pub trait SignedExtensionProvider: frame_system::Trait { /// Concrete SignedExtension type. type Extra: SignedExtension; - /// build extras for inclusion in extrinsics - fn construct_extras(nonce: IndexFor) -> Self::Extra; + /// construct extras and optionally additional_signed data for inclusion in extrinsics. + fn construct_extras(nonce: IndexFor, era: Era, genesis: Option) -> ( + Self::Extra, + Option<::AdditionalSigned> + ); } diff --git a/utils/frame/frame-utilities-cli/Cargo.toml b/utils/frame/frame-utilities-cli/Cargo.toml index 105f86e3342c4..bdc637cb04665 100644 --- a/utils/frame/frame-utilities-cli/Cargo.toml +++ b/utils/frame/frame-utilities-cli/Cargo.toml @@ -15,7 +15,8 @@ sc-cli = { version = "0.8.0-rc2", path = "../../../client/cli" } sp-runtime = { version = "2.0.0-rc2", path = "../../../primitives/runtime" } structopt = "0.3.8" codec = { version = "1.3.0", package = "parity-scale-codec" } -pallet-balances = { version = "2.0.0-alpha.8", path = "../../../frame/balances" } +pallet-balances = { version = "2.0.0-rc2", path = "../../../frame/balances" } +pallet-indices = { version = "2.0.0-rc2", path = "../../../frame/indices" } frame-utils = { path = "../../frame-utils", version = "2.0.0-rc2" } hex = "0.4.2" serde = "1.0.106" diff --git a/utils/frame/frame-utilities-cli/src/generate.rs b/utils/frame/frame-utilities-cli/src/generate.rs index b8c5692c9e8cd..f253eb2ad9b01 100644 --- a/utils/frame/frame-utilities-cli/src/generate.rs +++ b/utils/frame/frame-utilities-cli/src/generate.rs @@ -73,7 +73,7 @@ impl GenerateCmd { self.crypto_scheme.scheme, print_from_uri( mnemonic.phrase(), - Some(password.as_str()), + password.as_ref().map(String::as_str), maybe_network, output ) diff --git a/utils/frame/frame-utilities-cli/src/insert.rs b/utils/frame/frame-utilities-cli/src/insert.rs index 75adf2f751349..58cb7dbca65af 100644 --- a/utils/frame/frame-utilities-cli/src/insert.rs +++ b/utils/frame/frame-utilities-cli/src/insert.rs @@ -78,7 +78,7 @@ impl InsertCmd { let public = with_crypto_scheme!( self.crypto_scheme.scheme, - to_vec(&suri, &password) + to_vec(&suri, password.as_ref().map(String::as_str)) ); let node_url = self.node_url.as_ref() @@ -114,7 +114,7 @@ impl CliConfiguration for InsertCmd { } } -fn to_vec(uri: &str, pass: &str) -> Vec { +fn to_vec(uri: &str, pass: Option<&str>) -> Vec { let p = pair_from_suri::

(uri, pass); p.public().as_ref().to_vec() } diff --git a/utils/frame/frame-utilities-cli/src/inspect.rs b/utils/frame/frame-utilities-cli/src/inspect.rs index 3751f4acb19fd..da489b71e89aa 100644 --- a/utils/frame/frame-utilities-cli/src/inspect.rs +++ b/utils/frame/frame-utilities-cli/src/inspect.rs @@ -62,13 +62,13 @@ impl InspectCmd { /// Run the command pub fn run(&self) -> Result<(), Error> { let uri = read_uri(self.uri.as_ref())?; - let pass = self.keystore_params.read_password().ok(); + let password = self.keystore_params.read_password()?; with_crypto_scheme!( self.crypto_scheme.scheme, print_from_uri( &uri, - pass.as_ref().map(String::as_str), + password.as_ref().map(String::as_str), self.network_scheme.network.clone(), self.output_scheme.output_type.clone() ) diff --git a/utils/frame/frame-utilities-cli/src/sign_transaction.rs b/utils/frame/frame-utilities-cli/src/sign_transaction.rs index f23acedf53b86..669c594fee7c5 100644 --- a/utils/frame/frame-utilities-cli/src/sign_transaction.rs +++ b/utils/frame/frame-utilities-cli/src/sign_transaction.rs @@ -24,11 +24,12 @@ use sc_cli::{ use structopt::StructOpt; use codec::{Codec, Encode, Decode}; use std::{str::FromStr, fmt::Debug}; -use sp_runtime::MultiSigner; -use frame_utils::{SignedExtensionProvider, IndexFor, CallFor}; +use sp_runtime::{MultiSigner, MultiSignature, AccountId32}; +use frame_utils::{SignedExtensionProvider, IndexFor, CallFor, AccountIdFor, AddressFor}; use crate::utils::create_extrinsic_for; +use sp_core::hexdisplay::HexDisplay; -type Call = Vec; +type Bytes = Vec; /// The `sign-transaction` command #[derive(Debug, StructOpt, Clone)] @@ -46,9 +47,13 @@ pub struct SignTransactionCmd { #[structopt(long)] nonce: GenericNumber, + /// genesis hash, for signed extensions. + #[structopt(long, parse(try_from_str = decode_hex))] + genesis: Bytes, + /// The call, hex-encoded. #[structopt(long, parse(try_from_str = decode_hex))] - call: Call, + call: Bytes, #[allow(missing_docs)] #[structopt(flatten)] @@ -67,16 +72,21 @@ impl SignTransactionCmd { /// Run the command pub fn run

(&self) -> Result<(), Error> where - P: SignedExtensionProvider, + P: SignedExtensionProvider + pallet_indices::Trait, as FromStr>::Err: Debug, + AccountIdFor

: From, + AddressFor

: From>, CallFor

: Codec, { - let nonce = self.nonce.parse::>()?; + let genesis = ::decode(&mut &self.genesis[..])?; let call = CallFor::

::decode(&mut &self.call[..])?; - let pass = self.keystore_params.read_password()?; + let password = self.keystore_params.read_password()?; - with_crypto_scheme!(self.crypto_scheme.scheme, print_ext

(&self.suri, &pass, call, nonce)) + with_crypto_scheme!( + self.crypto_scheme.scheme, + print_ext

(&self.suri, password.as_ref().map(String::as_str), call, nonce, genesis) + ) } } @@ -92,16 +102,24 @@ impl CliConfiguration for SignTransactionCmd { } -fn print_ext(uri: &str, pass: &str, call: CallFor

, nonce: IndexFor

) -> Result<(), Error> +fn print_ext( + uri: &str, + pass: Option<&str>, + call: CallFor

, + nonce: IndexFor

, + genesis: P::Hash +) -> Result<(), Error> where Pair: sp_core::Pair, Pair::Public: Into, - Pair::Signature: Encode, - P: SignedExtensionProvider, + Pair::Signature: Into, + P: SignedExtensionProvider + pallet_indices::Trait, + AccountIdFor

: From, + AddressFor

: From>, CallFor

: Codec, { let signer = pair_from_suri::(uri, pass); - let extrinsic = create_extrinsic_for::>(call, nonce, signer)?; - println!("0x{}", hex::encode(Encode::encode(&extrinsic))); + let extrinsic = create_extrinsic_for::(call, nonce, signer, genesis)?; + println!("0x{}", HexDisplay::from(&extrinsic.encode())); Ok(()) } diff --git a/utils/frame/frame-utilities-cli/src/transfer.rs b/utils/frame/frame-utilities-cli/src/transfer.rs index 62b02ed278690..d8916cdd1cce2 100644 --- a/utils/frame/frame-utilities-cli/src/transfer.rs +++ b/utils/frame/frame-utilities-cli/src/transfer.rs @@ -24,15 +24,15 @@ use sc_cli::{ }; use structopt::StructOpt; use std::{str::FromStr, fmt::Debug}; -use codec::Encode; -use sp_runtime::MultiSigner; +use codec::{Encode, Decode}; +use sp_runtime::{MultiSigner, MultiSignature, AccountId32}; use std::convert::TryFrom; -use sp_core::crypto::Ss58Codec; -use frame_utils::{ - AddressFor, IndexFor, BalanceFor, BalancesCall, AccountIdFor, SignedExtensionProvider, -}; +use sp_core::{crypto::Ss58Codec, hexdisplay::HexDisplay}; +use frame_utils::{AddressFor, IndexFor, BalanceFor, BalancesCall, AccountIdFor, SignedExtensionProvider, CallFor}; use crate::utils::create_extrinsic_for; +type Bytes = Vec; + /// The `transfer` command #[derive(Debug, StructOpt, Clone)] #[structopt( @@ -56,6 +56,10 @@ pub struct TransferCmd { #[structopt(long)] to: String, + /// genesis hash, for signed extensions. + #[structopt(long, parse(try_from_str = decode_hex))] + genesis: Bytes, + #[allow(missing_docs)] #[structopt(flatten)] keystore_params: KeystoreParams, @@ -74,11 +78,13 @@ impl TransferCmd { /// Run the command pub fn run(&self) -> Result<(), Error> where - R: pallet_balances::Trait + SignedExtensionProvider, - AccountIdFor: for<'a> TryFrom<&'a [u8], Error = ()> + Ss58Codec, + R: pallet_balances::Trait + pallet_indices::Trait + SignedExtensionProvider, + AccountIdFor: for<'a> TryFrom<&'a [u8], Error = ()> + Ss58Codec + From, AddressFor: From>, as FromStr>::Err: Debug, as FromStr>::Err: Debug, + CallFor: Encode + From>, + BalancesCall: Encode, { let password = self.keystore_params.read_password()?; let nonce = self.index.parse::>()?; @@ -90,15 +96,18 @@ impl TransferCmd { .map_err(|_| Error::Other("Invalid SS58-check address given for account ID.".into()))? }; let amount = self.amount.parse::>()?; + let genesis = ::decode(&mut &self.genesis[..])?; + println!("Scheme {}", self.crypto_scheme.scheme); with_crypto_scheme!( self.crypto_scheme.scheme, print_ext( &self.from, - &password, + password.as_ref().map(String::as_str), to.into(), nonce, - amount + amount, + genesis ) ) } @@ -116,57 +125,61 @@ impl CliConfiguration for TransferCmd { fn print_ext( uri: &str, - pass: &str, + pass: Option<&str>, to: AddressFor

, nonce: IndexFor

, amount: BalanceFor

, + genesis: P::Hash ) -> Result<(), Error> where + CallFor

: Encode + From>, Pair: sp_core::Pair, Pair::Public: Into, - Pair::Signature: Encode, - P: pallet_balances::Trait + SignedExtensionProvider, + Pair::Signature: Into, + P: pallet_balances::Trait + pallet_indices::Trait + SignedExtensionProvider, BalancesCall

: Encode, + AccountIdFor

: From, + AddressFor

: From>, { let signer = pair_from_suri::(uri, pass); - let call = BalancesCall::transfer(to, amount); - let extrinsic = create_extrinsic_for::(call, nonce, signer)?; - println!("0x{}", hex::encode(Encode::encode(&extrinsic))); + let call: CallFor

= BalancesCall::transfer(to, amount).into(); + let extrinsic = create_extrinsic_for::(call, nonce, signer, genesis)?; + println!("0x{}", HexDisplay::from(&extrinsic.encode())); Ok(()) } -#[cfg(test)] -mod tests { - use super::*; - use substrate_test_runtime::Runtime; - - fn new_test_ext() -> sp_io::TestExternalities { - let t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - sp_io::TestExternalities::new(t) - } - - #[test] - fn transfer() { - let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; - let words = "remember fiber forum demise paper uniform squirrel feel access exclude casual effort"; - - let transfer = TransferCmd::from_iter(&["transfer", - "--from", seed, - "--to", "0xa2bc899a8a3b16a284a8cefcbc2dc48a687cd674e89b434fbbdb06f400979744", - "--amount", "5000", - "--index", "1", - "--password", "12345", - ]); - - new_test_ext().execute_with(|| { - assert!(matches!(transfer.run::(), Ok(()))); - let transfer = TransferCmd::from_iter(&["transfer", - "--from", words, - "--to", "0xa2bc899a8a3b16a284a8cefcbc2dc48a687cd674e89b434fbbdb06f400979744", - "--amount", "5000", - "--index", "1", - ]); - assert!(matches!(transfer.run::(), Err(Error::Input(_)))) - }); - } -} +// #[cfg(test)] +// mod tests { +// use super::*; +// use substrate_test_runtime::Runtime; +// +// fn new_test_ext() -> sp_io::TestExternalities { +// let t = frame_system::GenesisConfig::default().build_storage::().unwrap(); +// sp_io::TestExternalities::new(t) +// } +// +// #[test] +// fn transfer() { +// let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; +// let words = "remember fiber forum demise paper uniform squirrel feel access exclude casual effort"; +// +// let transfer = TransferCmd::from_iter(&["transfer", +// "--from", seed, +// "--to", "0xa2bc899a8a3b16a284a8cefcbc2dc48a687cd674e89b434fbbdb06f400979744", +// "--amount", "5000", +// "--index", "1", +// "--password", "12345", +// ]); +// +// new_test_ext().execute_with(|| { +// assert!(matches!(transfer.run::(), Ok(()))); +// let transfer = TransferCmd::from_iter(&["transfer", +// "--from", words, +// "--to", "0xa2bc899a8a3b16a284a8cefcbc2dc48a687cd674e89b434fbbdb06f400979744", +// "--amount", "5000", +// "--index", "1", +// ]); +// assert!(matches!(transfer.run::(), Err(Error::Input(_)))) +// }); +// } +// } diff --git a/utils/frame/frame-utilities-cli/src/utils.rs b/utils/frame/frame-utilities-cli/src/utils.rs index 818245ee7555c..9d9a18882297f 100644 --- a/utils/frame/frame-utilities-cli/src/utils.rs +++ b/utils/frame/frame-utilities-cli/src/utils.rs @@ -16,37 +16,51 @@ // limitations under the License. use sp_runtime::{ - MultiSigner, AccountId32, - traits::IdentifyAccount, generic::{UncheckedExtrinsic, SignedPayload}, + MultiSigner, AccountId32, traits::IdentifyAccount, MultiSignature, }; use codec::Encode; -use frame_utils::{SignedExtensionProvider, IndexFor}; +use frame_utils::{SignedExtensionProvider, IndexFor, AddressFor, AccountIdFor}; +use sp_runtime::generic::Era; /// create an extrinsic for the runtime. pub fn create_extrinsic_for( call: Call, nonce: IndexFor

, - signer: Pair, -) -> Result, &'static str> + pair: Pair, + genesis: P::Hash, +) -> Result< + UncheckedExtrinsic, Call, MultiSignature, P::Extra>, + &'static str + > where Call: Encode, Pair: sp_core::Pair, Pair::Public: Into, - Pair::Signature: Encode, - P: SignedExtensionProvider, + Pair::Signature: Into, + P: SignedExtensionProvider + pallet_indices::Trait, + AccountIdFor

: From, + AddressFor

: From>, { - let extra = P::construct_extras(nonce); - let payload = SignedPayload::new(call, extra) - .map_err(|_| "Transaction validity error")?; + let (extra, additional) = P::construct_extras(nonce, Era::Immortal, Some(genesis)); - let signature = payload.using_encoded(|payload| signer.sign(payload)); - let signer = signer.public().into().into_account(); + let payload = if let Some(additional_signed) = additional { + SignedPayload::from_raw(call, extra, additional_signed) + } else { + SignedPayload::new(call, extra) + .map_err(|_| "Transaction validity error")? + }; + + let signer = pair.public().into().into_account(); + let account_id: AccountIdFor

= From::from(signer.clone()); + let address = AddressFor::

::from(account_id); + + let signature = payload.using_encoded(|payload| pair.sign(payload).into()); let (function, extra, _) = payload.deconstruct(); Ok(UncheckedExtrinsic::new_signed( function, - signer, + address, signature, extra, )) From 753f5eb6d2766a937f6a5f8d8daf96ff6d75afd1 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 2 Jun 2020 07:48:22 +0100 Subject: [PATCH 50/77] sign test --- client/cli/src/commands/tests.rs | 3 --- utils/frame/frame-utilities-cli/src/transfer.rs | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs index 43cb5715f6fd8..bc2d996ae5539 100644 --- a/client/cli/src/commands/tests.rs +++ b/client/cli/src/commands/tests.rs @@ -28,9 +28,6 @@ fn sign() { let sign = SignCmd::from_iter(&["sign", "--suri", seed, "--message", &seed[2..], "--password", "12345"]); assert!(sign.run().is_ok()); - - let sign = SignCmd::from_iter(&["sign", "--suri", words, "--message", &seed[2..]]); - assert!(matches!(sign.run(), Err(Error::Input(_)))) } #[test] diff --git a/utils/frame/frame-utilities-cli/src/transfer.rs b/utils/frame/frame-utilities-cli/src/transfer.rs index d8916cdd1cce2..72e68c7a8559c 100644 --- a/utils/frame/frame-utilities-cli/src/transfer.rs +++ b/utils/frame/frame-utilities-cli/src/transfer.rs @@ -132,14 +132,14 @@ fn print_ext( genesis: P::Hash ) -> Result<(), Error> where - CallFor

: Encode + From>, Pair: sp_core::Pair, Pair::Public: Into, Pair::Signature: Into, - P: pallet_balances::Trait + pallet_indices::Trait + SignedExtensionProvider, BalancesCall

: Encode, AccountIdFor

: From, AddressFor

: From>, + CallFor

: Encode + From>, + P: pallet_balances::Trait + pallet_indices::Trait + SignedExtensionProvider, { let signer = pair_from_suri::(uri, pass); let call: CallFor

= BalancesCall::transfer(to, amount).into(); From 2a4374bca915312e5100e6b7d0f56dc593c3d0b7 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 2 Jun 2020 07:49:20 +0100 Subject: [PATCH 51/77] remove unused vars --- client/cli/src/commands/tests.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs index bc2d996ae5539..5d049f8dcde8e 100644 --- a/client/cli/src/commands/tests.rs +++ b/client/cli/src/commands/tests.rs @@ -18,12 +18,10 @@ use super::{SignCmd, VanityCmd}; use structopt::StructOpt; -use crate::Error; #[test] fn sign() { - let words = "remember fiber forum demise paper uniform squirrel feel access exclude casual effort"; let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; let sign = SignCmd::from_iter(&["sign", "--suri", seed, "--message", &seed[2..], "--password", "12345"]); From 3342d061cdc4f8916f8fa8212625a8bd12262e78 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 2 Jun 2020 09:50:42 +0100 Subject: [PATCH 52/77] implement subkey with frame-utilities-cli and sc_cli --- Cargo.lock | 141 +-- bin/node/runtime/src/lib.rs | 8 +- bin/utils/subkey/Cargo.toml | 25 +- bin/utils/subkey/README.adoc | 4 +- bin/utils/subkey/src/main.rs | 844 +----------------- bin/utils/subkey/src/rpc.rs | 51 -- bin/utils/subkey/src/vanity.rs | 205 ----- client/cli/src/commands/tests.rs | 1 - client/cli/src/commands/verify.rs | 2 - utils/frame-utils/src/lib.rs | 2 +- utils/frame/frame-utilities-cli/Cargo.toml | 3 +- .../src/generate_node_key.rs | 24 +- .../src/inspect_node_key.rs | 84 ++ utils/frame/frame-utilities-cli/src/key.rs | 14 +- utils/frame/frame-utilities-cli/src/lib.rs | 17 +- .../frame-utilities-cli/src/module_id.rs | 117 +++ .../src/sign_transaction.rs | 12 +- .../frame/frame-utilities-cli/src/transfer.rs | 46 +- utils/frame/frame-utilities-cli/src/utils.rs | 4 +- 19 files changed, 326 insertions(+), 1278 deletions(-) delete mode 100644 bin/utils/subkey/src/rpc.rs delete mode 100644 bin/utils/subkey/src/vanity.rs create mode 100644 utils/frame/frame-utilities-cli/src/inspect_node_key.rs create mode 100644 utils/frame/frame-utilities-cli/src/module_id.rs diff --git a/Cargo.lock b/Cargo.lock index 8b95ff0cb1ffe..41f908fc80f09 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1615,7 +1615,6 @@ dependencies = [ "sp-io", "sp-runtime", "structopt", - "substrate-test-runtime", "tempfile", ] @@ -2686,22 +2685,22 @@ dependencies = [ "lazy_static", "libp2p-core 0.18.0", "libp2p-core-derive 0.18.0", - "libp2p-deflate 0.18.0", + "libp2p-deflate", "libp2p-dns 0.18.0", - "libp2p-floodsub 0.18.0", - "libp2p-gossipsub 0.18.0", + "libp2p-floodsub", + "libp2p-gossipsub", "libp2p-identify 0.18.0", "libp2p-kad 0.18.0", "libp2p-mdns 0.18.0", "libp2p-mplex 0.18.0", "libp2p-noise 0.18.0", "libp2p-ping 0.18.0", - "libp2p-plaintext 0.18.0", - "libp2p-pnet 0.18.0", + "libp2p-plaintext", + "libp2p-pnet", "libp2p-secio 0.18.0", "libp2p-swarm 0.18.1", "libp2p-tcp 0.18.0", - "libp2p-uds 0.18.0", + "libp2p-uds", "libp2p-wasm-ext 0.18.0", "libp2p-websocket 0.18.0", "libp2p-yamux 0.18.0", @@ -2724,22 +2723,16 @@ dependencies = [ "lazy_static", "libp2p-core 0.19.0", "libp2p-core-derive 0.19.1", - "libp2p-deflate 0.19.1", "libp2p-dns 0.19.0", - "libp2p-floodsub 0.19.0", - "libp2p-gossipsub 0.19.1", "libp2p-identify 0.19.1", "libp2p-kad 0.19.0", "libp2p-mdns 0.19.1", "libp2p-mplex 0.19.1", "libp2p-noise 0.19.0", "libp2p-ping 0.19.1", - "libp2p-plaintext 0.19.0", - "libp2p-pnet 0.19.0", "libp2p-secio 0.19.1", "libp2p-swarm 0.19.0", "libp2p-tcp 0.19.1", - "libp2p-uds 0.19.1", "libp2p-wasm-ext 0.19.0", "libp2p-websocket 0.19.0", "libp2p-yamux 0.19.0", @@ -2850,17 +2843,6 @@ dependencies = [ "libp2p-core 0.18.0", ] -[[package]] -name = "libp2p-deflate" -version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c4acff33f5bfe154bafe14c6c08655d4b1e1736afaca78014111bc1742a2016" -dependencies = [ - "flate2", - "futures 0.3.5", - "libp2p-core 0.19.0", -] - [[package]] name = "libp2p-dns" version = "0.18.0" @@ -2900,23 +2882,6 @@ dependencies = [ "smallvec 1.4.0", ] -[[package]] -name = "libp2p-floodsub" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6dd8cc558e0edde2d4a423d017efd6b36c1b6bf97f4304c83076895c5edaed8" -dependencies = [ - "cuckoofilter", - "fnv", - "futures 0.3.5", - "libp2p-core 0.19.0", - "libp2p-swarm 0.19.0", - "prost", - "prost-build", - "rand 0.7.3", - "smallvec 1.4.0", -] - [[package]] name = "libp2p-gossipsub" version = "0.18.0" @@ -2942,31 +2907,6 @@ dependencies = [ "wasm-timer", ] -[[package]] -name = "libp2p-gossipsub" -version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1675c23765e37ddbf6bf05fb520be8f7df3f5f4981d68f185bb95f9b047c576a" -dependencies = [ - "base64 0.11.0", - "byteorder 1.3.4", - "bytes 0.5.4", - "fnv", - "futures 0.3.5", - "futures_codec", - "libp2p-core 0.19.0", - "libp2p-swarm 0.19.0", - "log", - "lru", - "prost", - "prost-build", - "rand 0.7.3", - "sha2", - "smallvec 1.4.0", - "unsigned-varint", - "wasm-timer", -] - [[package]] name = "libp2p-identify" version = "0.18.0" @@ -3219,24 +3159,6 @@ dependencies = [ "void", ] -[[package]] -name = "libp2p-plaintext" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad28fe7beaa3e516ee8ba2af8c4f6820f269afa60d661831e879f2afea64f4a0" -dependencies = [ - "bytes 0.5.4", - "futures 0.3.5", - "futures_codec", - "libp2p-core 0.19.0", - "log", - "prost", - "prost-build", - "rw-stream-sink", - "unsigned-varint", - "void", -] - [[package]] name = "libp2p-pnet" version = "0.18.0" @@ -3251,20 +3173,6 @@ dependencies = [ "sha3", ] -[[package]] -name = "libp2p-pnet" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dabaa2194e1ce3c51cd78d734dd4c81dc5c7b150b309cbf9029df044034ac261" -dependencies = [ - "futures 0.3.5", - "log", - "pin-project", - "rand 0.7.3", - "salsa20", - "sha3", -] - [[package]] name = "libp2p-secio" version = "0.18.0" @@ -3398,18 +3306,6 @@ dependencies = [ "log", ] -[[package]] -name = "libp2p-uds" -version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78d51726e063e8d73b103331576bb7e8fad187a3f0c227933a10b3542e2ad3f4" -dependencies = [ - "async-std", - "futures 0.3.5", - "libp2p-core 0.19.0", - "log", -] - [[package]] name = "libp2p-wasm-ext" version = "0.18.0" @@ -8635,30 +8531,11 @@ dependencies = [ name = "subkey" version = "2.0.0-rc2" dependencies = [ - "clap", - "derive_more", - "frame-system", - "futures 0.1.29", - "hex", - "hex-literal", - "hyper 0.12.35", - "itertools 0.8.2", - "jsonrpc-core-client", - "libp2p 0.19.1", + "frame-utilities-cli", "node-primitives", "node-runtime", - "pallet-balances", - "pallet-grandpa", - "pallet-transaction-payment", - "parity-scale-codec", - "rand 0.7.3", - "rpassword", - "sc-rpc", - "serde_json", - "sp-core", - "sp-runtime", - "substrate-bip39", - "tiny-bip39", + "sc-cli", + "structopt", ] [[package]] diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index a83b2a89093a3..87b64277b8b75 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -534,7 +534,7 @@ parameter_types! { impl SignedExtensionProvider for Runtime { type Extra = SignedExtra; - fn construct_extras(index: IndexFor, era: Era, genesis: Option) -> ( + fn construct_extras(index: IndexFor, era: Era, prior_block_hash: Option) -> ( Self::Extra, Option<::AdditionalSigned> ) { @@ -550,12 +550,12 @@ impl SignedExtensionProvider for Runtime { pallet_transaction_payment::ChargeTransactionPayment::::from(tip), pallet_grandpa::ValidateEquivocationReport::::new(), ), - genesis.map(|genesis| { + prior_block_hash.map(|hash| { ( VERSION.spec_version, VERSION.transaction_version, - genesis, - genesis, + hash, + hash, (), (), (), diff --git a/bin/utils/subkey/Cargo.toml b/bin/utils/subkey/Cargo.toml index c955ac3dd1241..4d70d853d1fee 100644 --- a/bin/utils/subkey/Cargo.toml +++ b/bin/utils/subkey/Cargo.toml @@ -11,30 +11,11 @@ repository = "https://github.com/paritytech/substrate/" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -futures = "0.1.29" -sp-core = { version = "2.0.0-rc2", path = "../../../primitives/core" } node-runtime = { version = "2.0.0-rc2", path = "../../node/runtime" } node-primitives = { version = "2.0.0-rc2", path = "../../node/primitives" } -sp-runtime = { version = "2.0.0-rc2", path = "../../../primitives/runtime" } -rand = "0.7.2" -clap = "2.33.0" -tiny-bip39 = "0.7" -substrate-bip39 = "0.4.1" -hex = "0.4.0" -hex-literal = "0.2.1" -codec = { package = "parity-scale-codec", version = "1.3.0" } -frame-system = { version = "2.0.0-rc2", path = "../../../frame/system" } -pallet-balances = { version = "2.0.0-rc2", path = "../../../frame/balances" } -pallet-transaction-payment = { version = "2.0.0-rc2", path = "../../../frame/transaction-payment" } -pallet-grandpa = { version = "2.0.0-rc2", path = "../../../frame/grandpa" } -rpassword = "4.0.1" -itertools = "0.8.2" -derive_more = { version = "0.99.2" } -sc-rpc = { version = "2.0.0-rc2", path = "../../../client/rpc" } -jsonrpc-core-client = { version = "14.0.3", features = ["http"] } -hyper = "0.12.35" -libp2p = "0.19.1" -serde_json = "1.0" +sc-cli = { version = "0.8.0-rc2", path = "../../../client/cli" } +frame-utilities-cli = { version = "2.0.0-rc2", features = ["balances"], path = "../../../utils/frame/frame-utilities-cli" } +structopt = "0.3.14" [features] bench = [] diff --git a/bin/utils/subkey/README.adoc b/bin/utils/subkey/README.adoc index 1fa0753312f0c..5ce0d2d324470 100644 --- a/bin/utils/subkey/README.adoc +++ b/bin/utils/subkey/README.adoc @@ -31,7 +31,7 @@ OUTPUT: `subkey` expects a message to come in on STDIN, one way to sign a message would look like this: ```bash -echo -n | subkey sign +echo -n | subkey sign --suri OUTPUT: a69da4a6ccbf81dbbbfad235fa12cf8528c18012b991ae89214de8d20d29c1280576ced6eb38b7406d1b7e03231df6dd4a5257546ddad13259356e1c3adfb509 @@ -72,7 +72,7 @@ Will output a signed and encoded `UncheckedMortalCompactExtrinsic` as hex. === Inspecting a module ID ```bash -subkey --network kusama moduleid "py/trsry" +subkey module-id "py/trsry" --network kusama OUTPUT: Public Key URI `F3opxRbN5ZbjJNU511Kj2TLuzFcDq9BGduA9TgiECafpg29` is account: diff --git a/bin/utils/subkey/src/main.rs b/bin/utils/subkey/src/main.rs index 4153e769c97f5..77fd7c975c657 100644 --- a/bin/utils/subkey/src/main.rs +++ b/bin/utils/subkey/src/main.rs @@ -16,816 +16,70 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![cfg_attr(feature = "bench", feature(test))] -#[cfg(feature = "bench")] -extern crate test; - -use bip39::{Language, Mnemonic, MnemonicType}; -use clap::{App, ArgMatches, SubCommand}; -use codec::{Decode, Encode}; -use hex_literal::hex; -use itertools::Itertools; -use libp2p::identity::{ed25519 as libp2p_ed25519, PublicKey}; -use node_primitives::{Balance, Hash, Index, AccountId, Signature}; -use node_runtime::{BalancesCall, Call, Runtime, SignedPayload, UncheckedExtrinsic, VERSION}; -use serde_json::json; -use sp_core::{ - crypto::{set_default_ss58_version, Ss58AddressFormat, Ss58Codec}, - ed25519, sr25519, ecdsa, Pair, Public, H256, hexdisplay::HexDisplay, -}; -use sp_runtime::{traits::{AccountIdConversion, IdentifyAccount, Verify}, generic::Era, ModuleId}; -use std::{ - convert::{TryInto, TryFrom}, io::{stdin, Read}, str::FromStr, path::PathBuf, fs, fmt, +use structopt::StructOpt; +use frame_utilities_cli::{ + InsertCmd, TransferCmd, SignTransactionCmd, ModuleIdCmd, + GenerateNodeKeyCmd, GenerateCmd, InspectCmd, InspectNodeKeyCmd, }; +use sc_cli::{Error, VanityCmd, SignCmd, VerifyCmd}; +use node_runtime::Runtime; -mod rpc; -mod vanity; - -enum OutputType { - Json, - Text, -} - -impl<'a> TryFrom<&'a str> for OutputType { - type Error = (); - - fn try_from(s: &'a str) -> Result { - match s { - "json" => Ok(OutputType::Json), - "text" => Ok(OutputType::Text), - _ => Err(()), - } - } - -} - -trait Crypto: Sized { - type Pair: Pair; - type Public: Public + Ss58Codec + AsRef<[u8]> + std::hash::Hash; - fn pair_from_suri(suri: &str, password: Option<&str>) -> Self::Pair { - Self::Pair::from_string(suri, password).expect("Invalid phrase") - } - fn ss58_from_pair(pair: &Self::Pair) -> String where - ::Public: PublicT, - { - pair.public().into_runtime().into_account().to_ss58check() - } - fn public_from_pair(pair: &Self::Pair) -> Self::Public { - pair.public() - } - fn print_from_uri( - uri: &str, - password: Option<&str>, - network_override: Option, - output: OutputType, - ) where - ::Public: PublicT, - { - let v = network_override.unwrap_or_default(); - if let Ok((pair, seed)) = Self::Pair::from_phrase(uri, password) { - let public_key = Self::public_from_pair(&pair); - - match output { - OutputType::Json => { - let json = json!({ - "secretPhrase": uri, - "networkId": String::from(v), - "secretSeed": format_seed::(seed), - "publicKey": format_public_key::(public_key.clone()), - "accountId": format_account_id::(public_key), - "ss58Address": Self::ss58_from_pair(&pair), - }); - println!("{}", serde_json::to_string_pretty(&json).expect("Json pretty print failed")); - }, - OutputType::Text => { - println!("Secret phrase `{}` is account:\n \ - Network ID/version: {}\n \ - Secret seed: {}\n \ - Public key (hex): {}\n \ - Account ID: {}\n \ - SS58 Address: {}", - uri, - String::from(v), - format_seed::(seed), - format_public_key::(public_key.clone()), - format_account_id::(public_key), - Self::ss58_from_pair(&pair), - ); - }, - } - } else if let Ok((pair, seed)) = Self::Pair::from_string_with_seed(uri, password) { - let public_key = Self::public_from_pair(&pair); - - match output { - OutputType::Json => { - let json = json!({ - "secretKeyUri": uri, - "networkId": String::from(v), - "secretSeed": if let Some(seed) = seed { format_seed::(seed) } else { "n/a".into() }, - "publicKey": format_public_key::(public_key.clone()), - "accountId": format_account_id::(public_key), - "ss58Address": Self::ss58_from_pair(&pair), - }); - println!("{}", serde_json::to_string_pretty(&json).expect("Json pretty print failed")); - }, - OutputType::Text => { - println!("Secret Key URI `{}` is account:\n \ - Network ID/version: {}\n \ - Secret seed: {}\n \ - Public key (hex): {}\n \ - Account ID: {}\n \ - SS58 Address: {}", - uri, - String::from(v), - if let Some(seed) = seed { format_seed::(seed) } else { "n/a".into() }, - format_public_key::(public_key.clone()), - format_account_id::(public_key), - Self::ss58_from_pair(&pair), - ); - }, - } - } else if let Ok((public_key, v)) = - ::Public::from_string_with_version(uri) - { - let v = network_override.unwrap_or(v); - - match output { - OutputType::Json => { - let json = json!({ - "publicKeyUri": uri, - "networkId": String::from(v), - "publicKey": format_public_key::(public_key.clone()), - "accountId": format_account_id::(public_key.clone()), - "ss58Address": public_key.to_ss58check_with_version(v), - }); - println!("{}", serde_json::to_string_pretty(&json).expect("Json pretty print failed")); - }, - OutputType::Text => { - println!("Public Key URI `{}` is account:\n \ - Network ID/version: {}\n \ - Public key (hex): {}\n \ - Account ID: {}\n \ - SS58 Address: {}", - uri, - String::from(v), - format_public_key::(public_key.clone()), - format_account_id::(public_key.clone()), - public_key.to_ss58check_with_version(v), - ); - }, - } - } else { - eprintln!("Invalid phrase/URI given"); - } - } -} - -struct Ed25519; - -impl Crypto for Ed25519 { - type Pair = ed25519::Pair; - type Public = ed25519::Public; +#[derive(Debug, StructOpt)] +#[structopt( + name = "subkey", + author = "Parity Team ", + about = "Utility for generating and restoring with Substrate keys", +)] +pub enum Subkey { + /// Generate a random node libp2p key, save it to file and print its peer ID + GenerateNodeKey(GenerateNodeKeyCmd), - fn pair_from_suri(suri: &str, password_override: Option<&str>) -> Self::Pair { - ed25519::Pair::from_legacy_string(suri, password_override) - } -} + /// Generate a random account + Generate(GenerateCmd), -struct Sr25519; + /// Gets a public key and a SS58 address from the provided Secret URI + InspectKey(InspectCmd), -impl Crypto for Sr25519 { - type Pair = sr25519::Pair; - type Public = sr25519::Public; -} + /// Print the peer ID corresponding to the node key in the given file + InspectNodeKey(InspectNodeKeyCmd), -struct Ecdsa; + /// Insert a key to the keystore of a node. + Insert(InsertCmd), -impl Crypto for Ecdsa { - type Pair = ecdsa::Pair; - type Public = ecdsa::Public; -} + /// Inspect a module ID address + ModuleId(ModuleIdCmd), -type SignatureOf = <::Pair as Pair>::Signature; -type PublicOf = <::Pair as Pair>::Public; -type SeedOf = <::Pair as Pair>::Seed; -type AccountPublic = ::Signer; + /// Author and sign a Node pallet_balances::Transfer transaction with a given (secret) key. + Transfer(TransferCmd), -trait SignatureT: AsRef<[u8]> + AsMut<[u8]> + Default { - /// Converts the signature into a runtime account signature, if possible. If not possible, bombs out. - fn into_runtime(self) -> Signature { - panic!("This cryptography isn't supported for this runtime.") - } -} -trait PublicT: Sized + AsRef<[u8]> + Ss58Codec { - /// Converts the public key into a runtime account public key, if possible. If not possible, bombs out. - fn into_runtime(self) -> AccountPublic { - panic!("This cryptography isn't supported for this runtime.") - } -} + /// Sign a message, with a given (secret) key. + Sign(SignCmd), -impl SignatureT for sr25519::Signature { fn into_runtime(self) -> Signature { self.into() } } -impl SignatureT for ed25519::Signature { fn into_runtime(self) -> Signature { self.into() } } -impl SignatureT for ecdsa::Signature { fn into_runtime(self) -> Signature { self.into() } } -impl PublicT for sr25519::Public { fn into_runtime(self) -> AccountPublic { self.into() } } -impl PublicT for ed25519::Public { fn into_runtime(self) -> AccountPublic { self.into() } } -impl PublicT for ecdsa::Public { fn into_runtime(self) -> AccountPublic { self.into() } } + /// Generate a seed that provides a vanity address. + Vanity(VanityCmd), -fn get_usage() -> String { - let networks = Ss58AddressFormat::all().iter().cloned().map(String::from).join("/"); - let default_network = String::from(Ss58AddressFormat::default()); - format!(" - -e, --ed25519 'Use Ed25519/BIP39 cryptography' - -k, --secp256k1 'Use SECP256k1/ECDSA/BIP39 cryptography' - -s, --sr25519 'Use Schnorr/Ristretto x25519/BIP39 cryptography' - [network] -n, --network 'Specify a network. One of {}. Default is {}' - [password] -p, --password 'The password for the key' - --password-interactive 'You will be prompted for the password for the key.' - [output] -o, --output 'Specify an output format. One of text, json. Default is text.' - ", networks, default_network) -} + /// Verify a signature for a message, provided on STDIN, with a given (public or secret) key. + Verify(VerifyCmd), -fn get_app<'a, 'b>(usage: &'a str) -> App<'a, 'b> { - App::new("subkey") - .author("Parity Team ") - .about("Utility for generating and restoring with Substrate keys") - .version(env!("CARGO_PKG_VERSION")) - .args_from_usage(usage) - .subcommands(vec![ - SubCommand::with_name("generate") - .about("Generate a random account") - .args_from_usage("[words] -w, --words \ - 'The number of words in the phrase to generate. One of 12 \ - (default), 15, 18, 21 and 24.' - "), - SubCommand::with_name("generate-node-key") - .about("Generate a random node libp2p key, save it to file and print its peer ID") - .args_from_usage("[file] 'Name of file to save secret key to'"), - SubCommand::with_name("inspect") - .about("Gets a public key and a SS58 address from the provided Secret URI") - .args_from_usage("[uri] 'A Key URI to be inspected. May be a secret seed, \ - secret URI (with derivation paths and password), SS58 or public URI. \ - If the value is a file, the file content is used as URI. \ - If not given, you will be prompted for the URI.' - "), - SubCommand::with_name("inspect-node-key") - .about("Print the peer ID corresponding to the node key in the given file") - .args_from_usage("[file] 'Name of file to read the secret key from'"), - SubCommand::with_name("sign") - .about("Sign a message, provided on STDIN, with a given (secret) key") - .args_from_usage(" - -h, --hex 'The message on STDIN is hex-encoded data' - 'The secret key URI. \ - If the value is a file, the file content is used as URI. \ - If not given, you will be prompted for the URI.' - "), - SubCommand::with_name("sign-transaction") - .about("Sign transaction from encoded Call. Returns a signed and encoded \ - UncheckedMortalCompactExtrinsic as hex.") - .args_from_usage(" - -c, --call 'The call, hex-encoded.' - -n, --nonce 'The nonce.' - -p, --password 'The password for the key.' - -h, --prior-block-hash 'The prior block hash, hex-encoded.' - -s, --suri 'The secret key URI.' - "), - SubCommand::with_name("transfer") - .about("Author and sign a Node pallet_balances::Transfer transaction with a given (secret) key") - .args_from_usage(" - -g, --genesis 'The genesis hash or a recognized \ - chain identifier (dev, elm, alex).' - 'The signing secret key URI.' - 'The destination account public key URI.' - 'The number of units to transfer.' - 'The signing account's transaction index.' - "), - SubCommand::with_name("vanity") - .about("Generate a seed that provides a vanity address") - .args_from_usage(" - -n, --number 'Number of keys to generate' - 'Desired pattern' - "), - SubCommand::with_name("verify") - .about("Verify a signature for a message, provided on STDIN, with a given \ - (public or secret) key") - .args_from_usage(" - -h, --hex 'The message on STDIN is hex-encoded data' - 'Signature, hex-encoded.' - 'The public or secret key URI. \ - If the value is a file, the file content is used as URI. \ - If not given, you will be prompted for the URI.' - "), - SubCommand::with_name("insert") - .about("Insert a key to the keystore of a node") - .args_from_usage(" - 'The secret key URI. \ - If the value is a file, the file content is used as URI. \ - If not given, you will be prompted for the URI.' - 'Key type, examples: \"gran\", or \"imon\" ' - [node-url] 'Node JSON-RPC endpoint, default \"http:://localhost:9933\"' - "), - SubCommand::with_name("moduleid") - .about("Inspect a module ID address") - .args_from_usage(" - 'The module ID used to derive the account' - ") - ]) + /// Sign transaction from encoded Call. + /// Prints a signed and encoded UncheckedMortalCompactExtrinsic as hex. + SignTransaction(SignTransactionCmd) } fn main() -> Result<(), Error> { - let usage = get_usage(); - let matches = get_app(&usage).get_matches(); - - if matches.is_present("ed25519") { - return execute::(matches); - } - if matches.is_present("secp256k1") { - return execute::(matches) - } - return execute::(matches) -} - -/// Get `URI` from CLI or prompt the user. -/// -/// `URI` is extracted from `matches` by using `match_name`. -/// -/// If the `URI` given as CLI argument is a file, the file content is taken as `URI`. -/// If no `URI` is given to the CLI, the user is prompted for it. -fn get_uri(match_name: &str, matches: &ArgMatches) -> Result { - let uri = if let Some(uri) = matches.value_of(match_name) { - let file = PathBuf::from(uri); - if file.is_file() { - fs::read_to_string(uri)? - .trim_end() - .into() - } else { - uri.into() - } - } else { - rpassword::read_password_from_tty(Some("URI: "))? + match Subkey::from_args() { + Subkey::GenerateNodeKey(cmd) => cmd.run()?, + Subkey::Generate(cmd) => cmd.run()?, + Subkey::InspectKey(cmd) => cmd.run()?, + Subkey::InspectNodeKey(cmd) => cmd.run()?, + Subkey::Insert(cmd) => cmd.run::()?, + Subkey::ModuleId(cmd) => cmd.run()?, + Subkey::Transfer(cmd) => cmd.run::()?, + Subkey::Vanity(cmd) => cmd.run()?, + Subkey::Verify(cmd) => cmd.run()?, + Subkey::Sign(cmd) => cmd.run()?, + Subkey::SignTransaction(cmd) => cmd.run::()?, }; - Ok(uri) -} - -#[derive(derive_more::Display, derive_more::From)] -enum Error { - Static(&'static str), - Io(std::io::Error), - Formatted(String), -} - -impl fmt::Debug for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(self, f) - } -} - -fn static_err(msg: &'static str) -> Result<(), Error> { - Err(Error::Static(msg)) -} - -fn execute(matches: ArgMatches) -> Result<(), Error> -where - SignatureOf: SignatureT, - PublicOf: PublicT, -{ - let password_interactive = matches.is_present("password-interactive"); - let password = matches.value_of("password"); - - let password = if password.is_some() && password_interactive { - return static_err("`--password` given and `--password-interactive` selected!"); - } else if password_interactive { - Some( - rpassword::read_password_from_tty(Some("Key password: "))? - ) - } else { - password.map(Into::into) - }; - let password = password.as_ref().map(String::as_str); - - let maybe_network: Option = match matches.value_of("network").map(|network| { - network - .try_into() - .map_err(|_| Error::Static("Invalid network name. See --help for available networks.")) - }) { - Some(Err(e)) => return Err(e), - Some(Ok(v)) => Some(v), - None => None, - }; - - if let Some(network) = maybe_network { - set_default_ss58_version(network); - } - - let output: OutputType = match matches.value_of("output").map(TryInto::try_into) { - Some(Err(_)) => return Err(Error::Static("Invalid output name. See --help for available outputs.")), - Some(Ok(v)) => v, - None => OutputType::Text, - }; - - match matches.subcommand() { - ("generate", Some(matches)) => { - let mnemonic = generate_mnemonic(matches)?; - C::print_from_uri(mnemonic.phrase(), password, maybe_network, output); - } - ("generate-node-key", Some(matches)) => { - let file = matches.value_of("file").ok_or(Error::Static("Output file name is required"))?; - - let keypair = libp2p_ed25519::Keypair::generate(); - let secret = keypair.secret(); - let peer_id = PublicKey::Ed25519(keypair.public()).into_peer_id(); - - fs::write(file, secret.as_ref())?; - - println!("{}", peer_id); - } - ("inspect", Some(matches)) => { - C::print_from_uri(&get_uri("uri", &matches)?, password, maybe_network, output); - } - ("inspect-node-key", Some(matches)) => { - let file = matches.value_of("file").ok_or(Error::Static("Input file name is required"))?; - - let mut file_content = fs::read(file)?; - let secret = libp2p_ed25519::SecretKey::from_bytes(&mut file_content) - .map_err(|_| Error::Static("Bad node key file"))?; - let keypair = libp2p_ed25519::Keypair::from(secret); - let peer_id = PublicKey::Ed25519(keypair.public()).into_peer_id(); - - println!("{}", peer_id); - } - ("sign", Some(matches)) => { - let suri = get_uri("suri", &matches)?; - let should_decode = matches.is_present("hex"); - - let message = read_message_from_stdin(should_decode)?; - let signature = do_sign::(&suri, message, password)?; - println!("{}", signature); - } - ("verify", Some(matches)) => { - let uri = get_uri("uri", &matches)?; - let should_decode = matches.is_present("hex"); - - let message = read_message_from_stdin(should_decode)?; - let is_valid_signature = do_verify::(matches, &uri, message)?; - if is_valid_signature { - println!("Signature verifies correctly."); - } else { - return static_err("Signature invalid."); - } - } - ("vanity", Some(matches)) => { - let desired: String = matches - .value_of("pattern") - .map(str::to_string) - .unwrap_or_default(); - let result = vanity::generate_key::(&desired)?; - let formated_seed = format_seed::(result.seed); - C::print_from_uri(&formated_seed, None, maybe_network, output); - } - ("transfer", Some(matches)) => { - let signer = read_pair::(matches.value_of("from"), password)?; - let index = read_required_parameter::(matches, "index")?; - let genesis_hash = read_genesis_hash(matches)?; - - let to: AccountId = read_account_id(matches.value_of("to")); - let amount = read_required_parameter::(matches, "amount")?; - let function = Call::Balances(BalancesCall::transfer(to.into(), amount)); - - let extrinsic = create_extrinsic::(function, index, signer, genesis_hash); - - print_extrinsic(extrinsic); - } - ("sign-transaction", Some(matches)) => { - let signer = read_pair::(matches.value_of("suri"), password)?; - let index = read_required_parameter::(matches, "nonce")?; - let genesis_hash = read_genesis_hash(matches)?; - - let call = matches.value_of("call").expect("call is required; qed"); - let function: Call = hex::decode(&call) - .ok() - .and_then(|x| Decode::decode(&mut &x[..]).ok()) - .unwrap(); - - let extrinsic = create_extrinsic::(function, index, signer, genesis_hash); - - print_extrinsic(extrinsic); - } - ("insert", Some(matches)) => { - let suri = get_uri("suri", &matches)?; - let pair = read_pair::(Some(&suri), password)?; - let node_url = matches.value_of("node-url").unwrap_or("http://localhost:9933"); - let key_type = matches.value_of("key-type").ok_or(Error::Static("Key type id is required"))?; - - // Just checking - let _key_type_id = sp_core::crypto::KeyTypeId::try_from(key_type) - .map_err(|_| Error::Static("Cannot convert argument to keytype: argument should be 4-character string"))?; - - let rpc = rpc::RpcClient::new(node_url.to_string()); - - rpc.insert_key( - key_type.to_string(), - suri, - sp_core::Bytes(pair.public().as_ref().to_vec()), - ); - } - ("moduleid", Some(matches)) => { - let id = get_uri("id", &matches)?; - if id.len() != 8 { - Err("a module id must be a string of 8 characters")? - } - - let id_fixed_array: [u8; 8] = id.as_bytes().try_into() - .map_err(|_| Error::Static("Cannot convert argument to moduleid: argument should be 8-character string"))?; - - let account_id: AccountId = ModuleId(id_fixed_array).into_account(); - let v = maybe_network.unwrap_or(Ss58AddressFormat::SubstrateAccount); - - C::print_from_uri(&account_id.to_ss58check_with_version(v), password, maybe_network, output); - } - _ => print_usage(&matches), - } - Ok(()) -} - -/// Creates a new randomly generated mnemonic phrase. -fn generate_mnemonic(matches: &ArgMatches) -> Result { - let words = match matches.value_of("words") { - Some(words) => { - let num = usize::from_str(words).map_err(|_| Error::Static("Invalid number given for --words"))?; - MnemonicType::for_word_count(num) - .map_err(|_| Error::Static("Invalid number of words given for phrase: must be 12/15/18/21/24"))? - }, - None => MnemonicType::Words12, - }; - Ok(Mnemonic::new(words, Language::English)) -} - -fn do_sign(suri: &str, message: Vec, password: Option<&str>) -> Result -where - SignatureOf: SignatureT, - PublicOf: PublicT, -{ - let pair = read_pair::(Some(suri), password)?; - let signature = pair.sign(&message); - Ok(format_signature::(&signature)) -} - -fn do_verify(matches: &ArgMatches, uri: &str, message: Vec) -> Result -where - SignatureOf: SignatureT, - PublicOf: PublicT, -{ - - let signature = read_signature::(matches)?; - let pubkey = read_public_key::(Some(uri)); - Ok(<::Pair as Pair>::verify(&signature, &message, &pubkey)) -} - -fn decode_hex>(message: T) -> Result, Error> { - hex::decode(message).map_err(|e| Error::Formatted(format!("Invalid hex ({})", e))) -} - -fn read_message_from_stdin(should_decode: bool) -> Result, Error> { - let mut message = vec![]; - stdin() - .lock() - .read_to_end(&mut message)?; - if should_decode { - message = decode_hex(&message)?; - } - Ok(message) -} - -fn read_required_parameter(matches: &ArgMatches, name: &str) -> Result where - ::Err: std::fmt::Debug, -{ - let str_value = matches - .value_of(name) - .expect("parameter is required; thus it can't be None; qed"); - str::parse::(str_value).map_err(|_| - Error::Formatted(format!("Invalid `{}' parameter; expecting an integer.", name)) - ) -} - -fn read_genesis_hash(matches: &ArgMatches) -> Result { - let genesis_hash: Hash = match matches.value_of("genesis").unwrap_or("alex") { - "elm" => hex!["10c08714a10c7da78f40a60f6f732cf0dba97acfb5e2035445b032386157d5c3"].into(), - "alex" => hex!["dcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b"].into(), - h => Decode::decode(&mut &decode_hex(h)?[..]) - .expect("Invalid genesis hash or unrecognized chain identifier"), - }; - println!( - "Using a genesis hash of {}", - HexDisplay::from(&genesis_hash.as_ref()) - ); - Ok(genesis_hash) -} - -fn read_signature(matches: &ArgMatches) -> Result, Error> -where - SignatureOf: SignatureT, - PublicOf: PublicT, -{ - let sig_data = matches - .value_of("sig") - .expect("signature parameter is required; thus it can't be None; qed"); - let mut signature = <::Pair as Pair>::Signature::default(); - let sig_data = decode_hex(sig_data)?; - if sig_data.len() != signature.as_ref().len() { - return Err(Error::Formatted(format!( - "signature has an invalid length. read {} bytes, expected {} bytes", - sig_data.len(), - signature.as_ref().len(), - ))); - } - signature.as_mut().copy_from_slice(&sig_data); - Ok(signature) -} - -fn read_public_key(matched_uri: Option<&str>) -> PublicOf -where - PublicOf: PublicT, -{ - let uri = matched_uri.expect("parameter is required; thus it can't be None; qed"); - let uri = if uri.starts_with("0x") { - &uri[2..] - } else { - uri - }; - if let Ok(pubkey_vec) = hex::decode(uri) { - ::Public::from_slice(pubkey_vec.as_slice()) - } else { - ::Public::from_string(uri) - .ok() - .expect("Invalid URI; expecting either a secret URI or a public URI.") - } -} - -fn read_account_id(matched_uri: Option<&str>) -> AccountId { - let uri = matched_uri.expect("parameter is required; thus it can't be None; qed"); - let uri = if uri.starts_with("0x") { - &uri[2..] - } else { - uri - }; - if let Ok(data_vec) = hex::decode(uri) { - AccountId::try_from(data_vec.as_slice()) - .expect("Invalid hex length for account ID; should be 32 bytes") - } else { - AccountId::from_ss58check(uri).ok() - .expect("Invalid SS58-check address given for account ID.") - } -} - -fn read_pair( - matched_suri: Option<&str>, - password: Option<&str>, -) -> Result<::Pair, Error> where - SignatureOf: SignatureT, - PublicOf: PublicT, -{ - let suri = matched_suri.ok_or(Error::Static("parameter is required; thus it can't be None; qed"))?; - Ok(C::pair_from_suri(suri, password)) -} - -fn format_signature(signature: &SignatureOf) -> String { - format!("{}", HexDisplay::from(&signature.as_ref())) -} - -fn format_seed(seed: SeedOf) -> String { - format!("0x{}", HexDisplay::from(&seed.as_ref())) -} - -fn format_public_key(public_key: PublicOf) -> String { - format!("0x{}", HexDisplay::from(&public_key.as_ref())) -} - -fn format_account_id(public_key: PublicOf) -> String where - PublicOf: PublicT, -{ - format!("0x{}", HexDisplay::from(&public_key.into_runtime().into_account().as_ref())) -} - -fn create_extrinsic( - function: Call, - index: Index, - signer: C::Pair, - genesis_hash: H256, -) -> UncheckedExtrinsic where - PublicOf: PublicT, - SignatureOf: SignatureT, -{ - let extra = |i: Index, f: Balance| { - ( - frame_system::CheckSpecVersion::::new(), - frame_system::CheckTxVersion::::new(), - frame_system::CheckGenesis::::new(), - frame_system::CheckEra::::from(Era::Immortal), - frame_system::CheckNonce::::from(i), - frame_system::CheckWeight::::new(), - pallet_transaction_payment::ChargeTransactionPayment::::from(f), - pallet_grandpa::ValidateEquivocationReport::::new(), - ) - }; - let raw_payload = SignedPayload::from_raw( - function, - extra(index, 0), - ( - VERSION.spec_version, - VERSION.transaction_version, - genesis_hash, - genesis_hash, - (), - (), - (), - (), - ), - ); - let signature = raw_payload.using_encoded(|payload| signer.sign(payload)).into_runtime(); - let signer = signer.public().into_runtime(); - let (function, extra, _) = raw_payload.deconstruct(); - - UncheckedExtrinsic::new_signed( - function, - signer.into_account().into(), - signature, - extra, - ) -} - -fn print_extrinsic(extrinsic: UncheckedExtrinsic) { - println!("0x{}", HexDisplay::from(&extrinsic.encode())); -} - -fn print_usage(matches: &ArgMatches) { - println!("{}", matches.usage()); -} - -#[cfg(test)] -mod tests { - use super::*; - - fn test_generate_sign_verify() - where - SignatureOf: SignatureT, - PublicOf: PublicT, - { - let usage = get_usage(); - let app = get_app(&usage); - let password = None; - - // Generate public key and seed. - let arg_vec = vec!["subkey", "generate"]; - - let matches = app.clone().get_matches_from(arg_vec); - let matches = matches.subcommand().1.unwrap(); - let mnemonic = generate_mnemonic(matches).expect("generate failed"); - - let (pair, seed) = - <::Pair as Pair>::from_phrase(mnemonic.phrase(), password) - .unwrap(); - let public_key = CryptoType::public_from_pair(&pair); - let public_key = format_public_key::(public_key); - let seed = format_seed::(seed); - let message = "Blah Blah\n".as_bytes().to_vec(); - - let signature = do_sign::(&seed, message.clone(), password).expect("signing failed"); - - // Verify the previous signature. - let arg_vec = vec!["subkey", "verify", &signature[..], &public_key[..]]; - - let matches = get_app(&usage).get_matches_from(arg_vec); - let matches = matches.subcommand().1.unwrap(); - - assert!(do_verify::(matches, &public_key, message).expect("verify failed")); - } - - #[test] - fn generate_sign_verify_should_work_for_ed25519() { - test_generate_sign_verify::(); - } - - #[test] - fn generate_sign_verify_should_work_for_sr25519() { - test_generate_sign_verify::(); - } - - #[test] - fn should_work() { - let s = "0123456789012345678901234567890123456789012345678901234567890123"; - - let d1: Hash = hex::decode(s) - .ok() - .and_then(|x| Decode::decode(&mut &x[..]).ok()) - .unwrap(); - - let d2: Hash = { - let mut gh: [u8; 32] = Default::default(); - gh.copy_from_slice(hex::decode(s).unwrap().as_ref()); - Hash::from(gh) - }; - - assert_eq!(d1, d2); - } -} +} \ No newline at end of file diff --git a/bin/utils/subkey/src/rpc.rs b/bin/utils/subkey/src/rpc.rs deleted file mode 100644 index e24cf50dc4502..0000000000000 --- a/bin/utils/subkey/src/rpc.rs +++ /dev/null @@ -1,51 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -//! Helper to run commands against current node RPC - -use futures::Future; -use hyper::rt; -use node_primitives::Hash; -use sc_rpc::author::AuthorClient; -use jsonrpc_core_client::transports::http; -use sp_core::Bytes; - -pub struct RpcClient { url: String } - -impl RpcClient { - pub fn new(url: String) -> Self { Self { url } } - - pub fn insert_key( - &self, - key_type: String, - suri: String, - public: Bytes, - ) { - let url = self.url.clone(); - - rt::run( - http::connect(&url) - .and_then(|client: AuthorClient| { - client.insert_key(key_type, suri, public).map(|_| ()) - }) - .map_err(|e| { - eprintln!("Error inserting key: {:?}", e); - }) - ); - } -} diff --git a/bin/utils/subkey/src/vanity.rs b/bin/utils/subkey/src/vanity.rs deleted file mode 100644 index d09aeeef25a47..0000000000000 --- a/bin/utils/subkey/src/vanity.rs +++ /dev/null @@ -1,205 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -use super::{PublicOf, PublicT, Crypto}; -use sp_core::Pair; -use rand::{rngs::OsRng, RngCore}; - -fn good_waypoint(done: u64) -> u64 { - match done { - 0..=1_000_000 => 100_000, - 0..=10_000_000 => 1_000_000, - 0..=100_000_000 => 10_000_000, - _ => 100_000_000, - } -} - -fn next_seed(seed: &mut [u8]) { - for i in 0..seed.len() { - match seed[i] { - 255 => { - seed[i] = 0; - } - _ => { - seed[i] += 1; - break; - } - } - } -} - -/// A structure used to carry both Pair and seed. -/// This should usually NOT been used. If unsure, use Pair. -pub(super) struct KeyPair { - pub pair: C::Pair, - pub seed: ::Seed, - pub score: usize, -} - -/// Calculate the score of a key based on the desired -/// input. -fn calculate_score(_desired: &str, key: &str) -> usize { - for truncate in 0.._desired.len() { - let snip_size = _desired.len() - truncate; - let truncated = &_desired[0..snip_size]; - if let Some(pos) = key.find(truncated) { - return (47 - pos) + (snip_size * 48); - } - } - 0 -} - -/// Validate whether the char is allowed to be used in base58. -/// num 0, lower l, upper I and O are not allowed. -fn validate_base58(c :char) -> bool { - c.is_alphanumeric() && !"0lIO".contains(c) -} - -pub(super) fn generate_key(desired: &str) -> Result, &'static str> where - PublicOf: PublicT, -{ - if desired.is_empty() { - return Err("Pattern must not be empty"); - } - - if !desired.chars().all(validate_base58) { - return Err("Pattern can only contains valid characters in base58 \ - (all alphanumeric except for 0, l, I and O)"); - } - - eprintln!("Generating key containing pattern '{}'", desired); - - let top = 45 + (desired.len() * 48); - let mut best = 0; - let mut seed = ::Seed::default(); - let mut done = 0; - - loop { - if done % 100000 == 0 { - OsRng.fill_bytes(seed.as_mut()); - } else { - next_seed(seed.as_mut()); - } - - let p = C::Pair::from_seed(&seed); - let ss58 = C::ss58_from_pair(&p); - let score = calculate_score(&desired, &ss58); - if score > best || desired.len() < 2 { - best = score; - let keypair = KeyPair { - pair: p, - seed: seed.clone(), - score: score, - }; - if best >= top { - eprintln!("best: {} == top: {}", best, top); - return Ok(keypair); - } - } - done += 1; - - if done % good_waypoint(done) == 0 { - eprintln!("{} keys searched; best is {}/{} complete", done, best, top); - } - } -} - -#[cfg(test)] -mod tests { - use super::super::Ed25519; - use super::*; - use sp_core::{crypto::Ss58Codec, Pair}; - #[cfg(feature = "bench")] - use test::Bencher; - - #[test] - fn test_generation_with_single_char() { - assert!(generate_key::("j") - .unwrap() - .pair - .public() - .to_ss58check() - .contains("j")); - } - - #[test] - fn test_score_1_char_100() { - let score = calculate_score("j", "5jolkadotwHY5k9GpdTgpqs9xjuNvtv8EcwCFpEeyEf3KHim"); - assert_eq!(score, 94); - } - - #[test] - fn test_score_100() { - let score = calculate_score( - "Polkadot", - "5PolkadotwHY5k9GpdTgpqs9xjuNvtv8EcwCFpEeyEf3KHim", - ); - assert_eq!(score, 430); - } - - #[test] - fn test_score_50_2() { - // 50% for the position + 50% for the size - assert_eq!( - calculate_score( - "Polkadot", - "5PolkXXXXwHY5k9GpdTgpqs9xjuNvtv8EcwCFpEeyEf3KHim" - ), - 238 - ); - } - - #[test] - fn test_score_0() { - assert_eq!( - calculate_score( - "Polkadot", - "5GUWv4bLCchGUHJrzULXnh4JgXsMpTKRnjuXTY7Qo1Kh9uYK" - ), - 0 - ); - } - - #[test] - fn test_invalid_pattern() { - assert!(generate_key::("").is_err()); - assert!(generate_key::("0").is_err()); - assert!(generate_key::("l").is_err()); - assert!(generate_key::("I").is_err()); - assert!(generate_key::("O").is_err()); - assert!(generate_key::("!").is_err()); - } - - #[test] - fn test_valid_pattern() { - assert!(generate_key::("o").is_ok()); - assert!(generate_key::("L").is_ok()); - } - - #[cfg(feature = "bench")] - #[bench] - fn bench_paranoiac(b: &mut Bencher) { - b.iter(|| generate_key("polk")); - } - - #[cfg(feature = "bench")] - #[bench] - fn bench_not_paranoiac(b: &mut Bencher) { - b.iter(|| generate_key("polk")); - } -} diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs index 5d049f8dcde8e..1ee37d086ca25 100644 --- a/client/cli/src/commands/tests.rs +++ b/client/cli/src/commands/tests.rs @@ -19,7 +19,6 @@ use super::{SignCmd, VanityCmd}; use structopt::StructOpt; - #[test] fn sign() { let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; diff --git a/client/cli/src/commands/verify.rs b/client/cli/src/commands/verify.rs index 9278dec81d856..071448c648aac 100644 --- a/client/cli/src/commands/verify.rs +++ b/client/cli/src/commands/verify.rs @@ -33,13 +33,11 @@ use structopt::StructOpt; )] pub struct VerifyCmd { /// Signature, hex-encoded. - #[structopt(long)] sig: String, /// The public or secret key URI. /// If the value is a file, the file content is used as URI. /// If not given, you will be prompted for the URI. - #[structopt(long)] uri: Option, /// Message to verify, if not provided you will be prompted to diff --git a/utils/frame-utils/src/lib.rs b/utils/frame-utils/src/lib.rs index 522ed27e3feb6..748700563f172 100644 --- a/utils/frame-utils/src/lib.rs +++ b/utils/frame-utils/src/lib.rs @@ -78,7 +78,7 @@ pub trait SignedExtensionProvider: frame_system::Trait { type Extra: SignedExtension; /// construct extras and optionally additional_signed data for inclusion in extrinsics. - fn construct_extras(nonce: IndexFor, era: Era, genesis: Option) -> ( + fn construct_extras(nonce: IndexFor, era: Era, prior_block_hash: Option) -> ( Self::Extra, Option<::AdditionalSigned> ); diff --git a/utils/frame/frame-utilities-cli/Cargo.toml b/utils/frame/frame-utilities-cli/Cargo.toml index bdc637cb04665..34c223c0f8f5a 100644 --- a/utils/frame/frame-utilities-cli/Cargo.toml +++ b/utils/frame/frame-utilities-cli/Cargo.toml @@ -33,8 +33,7 @@ futures = "0.3" [dev-dependencies] tempfile = "3.1.0" sp-io = { version = "2.0.0-rc2", path = "../../../primitives/io" } -frame-system = { version = "2.0.0-alpha.7", path = "../../../frame/system" } -substrate-test-runtime = { version = "2.0.0-rc2", features = ["indices-lookup"], path = "../../../test-utils/runtime" } +frame-system = { version = "2.0.0-rc2", path = "../../../frame/system" } [features] balances = [] diff --git a/utils/frame/frame-utilities-cli/src/generate_node_key.rs b/utils/frame/frame-utilities-cli/src/generate_node_key.rs index af1cf4eebad77..7a15e5ba07dd3 100644 --- a/utils/frame/frame-utilities-cli/src/generate_node_key.rs +++ b/utils/frame/frame-utilities-cli/src/generate_node_key.rs @@ -22,13 +22,13 @@ use structopt::StructOpt; use std::{path::PathBuf, fs}; use libp2p::identity::{ed25519 as libp2p_ed25519, PublicKey}; -/// The `generate-node-id` command +/// The `generate-node-key` command #[derive(Debug, StructOpt, Clone)] #[structopt( - name = "generate-node-id", + name = "generate-node-key", about = "Generate a random node libp2p key, save it to file and print its peer ID" )] -pub struct GenerateNodeIdCmd { +pub struct GenerateNodeKeyCmd { /// Name of file to save secret key to. #[structopt(long)] file: PathBuf, @@ -38,7 +38,7 @@ pub struct GenerateNodeIdCmd { pub shared_params: SharedParams, } -impl GenerateNodeIdCmd { +impl GenerateNodeKeyCmd { /// Run the command pub fn run(&self) -> Result<(), Error> { let file = &self.file; @@ -55,8 +55,22 @@ impl GenerateNodeIdCmd { } } -impl CliConfiguration for GenerateNodeIdCmd { +impl CliConfiguration for GenerateNodeKeyCmd { fn shared_params(&self) -> &SharedParams { &self.shared_params } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn inspect_node_key() { + let path = tempfile::tempdir().unwrap().into_path().join("node-id").into_os_string(); + let path = path.to_str().unwrap(); + let cmd = GenerateNodeKeyCmd::from_iter(&["generate-node-key", "--file", path.clone()]); + + assert!(cmd.run().is_ok()); + } +} diff --git a/utils/frame/frame-utilities-cli/src/inspect_node_key.rs b/utils/frame/frame-utilities-cli/src/inspect_node_key.rs new file mode 100644 index 0000000000000..3c5600da99565 --- /dev/null +++ b/utils/frame/frame-utilities-cli/src/inspect_node_key.rs @@ -0,0 +1,84 @@ +// This file is part of Substrate. + +// Copyright (C) 2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Implementation of the `inspect-node-key` subcommand + +use sc_cli::{Error, SharedParams, NetworkSchemeFlag, CliConfiguration}; +use std::fs; +use libp2p::identity::{PublicKey, ed25519}; +use std::path::PathBuf; +use structopt::StructOpt; + +/// The `inspect-node-key` command +#[derive(Debug, StructOpt, Clone)] +#[structopt( + name = "inspect-node-key", + about = "Print the peer ID corresponding to the node key in the given file." +)] +pub struct InspectNodeKeyCmd { + /// Name of file to read the secret key from. + #[structopt(long)] + file: PathBuf, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub network_scheme: NetworkSchemeFlag, +} + +impl InspectNodeKeyCmd { + pub fn run(&self) -> Result<(), Error> { + let mut file_content = hex::decode(fs::read(&self.file)?) + .map_err(|_| "failed to decode secret as hex")?; + let secret = ed25519::SecretKey::from_bytes(&mut file_content) + .map_err(|_| "Bad node key file")?; + + let keypair = ed25519::Keypair::from(secret); + let peer_id = PublicKey::Ed25519(keypair.public()).into_peer_id(); + + println!("{}", peer_id); + + Ok(()) + } +} + +impl CliConfiguration for InspectNodeKeyCmd { + fn shared_params(&self) -> &SharedParams { + &self.shared_params + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::generate_node_key::GenerateNodeKeyCmd; + + #[test] + fn inspect_node_key() { + let path = tempfile::tempdir().unwrap().into_path().join("node-id").into_os_string(); + let path = path.to_str().unwrap(); + let cmd = GenerateNodeKeyCmd::from_iter(&["generate-node-key", "--file", path.clone()]); + + assert!(cmd.run().is_ok()); + + let cmd = InspectNodeKeyCmd::from_iter(&["inspect-node-key", "--file", path]); + assert!(cmd.run().is_ok()); + } +} \ No newline at end of file diff --git a/utils/frame/frame-utilities-cli/src/key.rs b/utils/frame/frame-utilities-cli/src/key.rs index 67c830b258d78..5f6fa84be11a8 100644 --- a/utils/frame/frame-utilities-cli/src/key.rs +++ b/utils/frame/frame-utilities-cli/src/key.rs @@ -23,17 +23,18 @@ use frame_utils::{HashFor, SignedExtensionProvider}; use serde::{de::DeserializeOwned, Serialize}; use crate::{ - generate_node_key::GenerateNodeIdCmd, - generate::GenerateCmd, + insert::InsertCmd, inspect::InspectCmd, - insert::InsertCmd + generate::GenerateCmd, + inspect_node_key::InspectNodeKeyCmd, + generate_node_key::GenerateNodeKeyCmd, }; /// key utilities for the cli. #[derive(Debug, Clone, StructOpt)] pub enum KeySubcommand { /// Generate a random node libp2p key, save it to file and print its peer ID - GenerateNodeKey(GenerateNodeIdCmd), + GenerateNodeKey(GenerateNodeKeyCmd), /// Generate a random account Generate(GenerateCmd), @@ -41,6 +42,9 @@ pub enum KeySubcommand { /// Gets a public key and a SS58 address from the provided Secret URI InspectKey(InspectCmd), + /// Print the peer ID corresponding to the node key in the given file + InspectNodeKey(InspectNodeKeyCmd), + /// Insert a key to the keystore of a node. Insert(InsertCmd), } @@ -57,6 +61,7 @@ impl KeySubcommand { KeySubcommand::Generate(cmd) => cmd.run(), KeySubcommand::InspectKey(cmd) => cmd.run(), KeySubcommand::Insert(cmd) => cmd.run::

(), + KeySubcommand::InspectNodeKey(cmd) => cmd.run(), } } } @@ -65,6 +70,7 @@ impl KeySubcommand { substrate_cli_subcommands!( KeySubcommand => GenerateNodeKey, + InspectNodeKey, Generate, InspectKey, Insert diff --git a/utils/frame/frame-utilities-cli/src/lib.rs b/utils/frame/frame-utilities-cli/src/lib.rs index 0471131773fbc..d86ef699a98fc 100644 --- a/utils/frame/frame-utilities-cli/src/lib.rs +++ b/utils/frame/frame-utilities-cli/src/lib.rs @@ -21,6 +21,8 @@ mod generate; mod generate_node_key; mod insert; mod inspect; +mod inspect_node_key; +mod module_id; mod key; mod utils; mod sign_transaction; @@ -29,12 +31,21 @@ mod transfer; #[cfg(feature = "balances")] pub use transfer::TransferCmd; -pub use {key::KeySubcommand, sign_transaction::SignTransactionCmd}; +pub use { + key::KeySubcommand, + module_id::ModuleIdCmd, + generate::GenerateCmd, + insert::InsertCmd, + inspect::InspectCmd, + inspect_node_key::InspectNodeKeyCmd, + sign_transaction::SignTransactionCmd, + generate_node_key::GenerateNodeKeyCmd, +}; #[cfg(test)] mod tests { - use super::{generate::GenerateCmd, generate_node_key::GenerateNodeIdCmd, inspect::InspectCmd}; + use super::{generate::GenerateCmd, generate_node_key::GenerateNodeKeyCmd, inspect::InspectCmd}; use tempfile::Builder; use structopt::StructOpt; use std::io::Read; @@ -49,7 +60,7 @@ mod tests { fn generate_node_key() { let mut file = Builder::new().prefix("keyfile").tempfile().unwrap(); let generate = - GenerateNodeIdCmd::from_iter(&["generate-node-key", "--file", "/tmp/keyfile"]); + GenerateNodeKeyCmd::from_iter(&["generate-node-key", "--file", "/tmp/keyfile"]); assert!(generate.run().is_ok()); let mut buf = String::new(); assert!(file.read_to_string(&mut buf).is_ok()); diff --git a/utils/frame/frame-utilities-cli/src/module_id.rs b/utils/frame/frame-utilities-cli/src/module_id.rs new file mode 100644 index 0000000000000..24b95744d3e2e --- /dev/null +++ b/utils/frame/frame-utilities-cli/src/module_id.rs @@ -0,0 +1,117 @@ +// This file is part of Substrate. + +// Copyright (C) 2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Implementation of the `moduleid` subcommand + +use sc_cli::{ + Error, SharedParams, print_from_uri, CryptoSchemeFlag, + OutputTypeFlag, KeystoreParams, CliConfiguration, with_crypto_scheme, +}; +use sp_runtime::ModuleId; +use sp_runtime::traits::AccountIdConversion; +use sp_core::crypto::{AccountId32, Ss58Codec, Ss58AddressFormat}; +use std::convert::{TryInto, TryFrom}; +use structopt::StructOpt; + +/// The `moduleid` command +#[derive(Debug, StructOpt, Clone)] +#[structopt( + name = "moduleid", + about = "Inspect a module ID address" +)] +pub struct ModuleIdCmd { + /// The module ID used to derive the account + id: String, + + /// network address format + #[structopt( + long, + value_name = "NETWORK", + possible_values = &Ss58AddressFormat::all_names()[..], + parse(try_from_str = Ss58AddressFormat::try_from), + case_insensitive = true, + default_value = "substrate" + )] + pub network: Ss58AddressFormat, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub output_scheme: OutputTypeFlag, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub crypto_scheme: CryptoSchemeFlag, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub keystore_params: KeystoreParams, +} + +impl ModuleIdCmd { + pub fn run(&self) -> Result<(), Error> { + if self.id.len() != 8 { + Err("a module id must be a string of 8 characters")? + } + let password = self.keystore_params.read_password()?; + + let id_fixed_array: [u8; 8] = self.id.as_bytes() + .try_into() + .map_err(|_| "Cannot convert argument to moduleid: argument should be 8-character string")?; + + let account_id: AccountId32 = ModuleId(id_fixed_array).into_account(); + let network = self.network; + + with_crypto_scheme!( + self.crypto_scheme.scheme, + print_from_uri( + &account_id.to_ss58check_with_version(network), + password.as_ref().map(String::as_str), + network, + self.output_scheme.output_type.clone() + ) + ); + + Ok(()) + } +} + +impl CliConfiguration for ModuleIdCmd { + fn shared_params(&self) -> &SharedParams { + &self.shared_params + } + + fn keystore_params(&self) -> Option<&KeystoreParams> { + Some(&self.keystore_params) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn module_id() { + let seed = "sdad1fb7"; + + let cmd = ModuleIdCmd::from_iter(&["moduleid", "--id", seed]); + assert!(cmd.run().is_ok()); + } +} \ No newline at end of file diff --git a/utils/frame/frame-utilities-cli/src/sign_transaction.rs b/utils/frame/frame-utilities-cli/src/sign_transaction.rs index 669c594fee7c5..bca94ba2b2b20 100644 --- a/utils/frame/frame-utilities-cli/src/sign_transaction.rs +++ b/utils/frame/frame-utilities-cli/src/sign_transaction.rs @@ -18,7 +18,7 @@ //! Implementation of the `sign-transaction` subcommand use sc_cli::{ Error, CliConfiguration, KeystoreParams, SharedParams, - pair_from_suri, decode_hex,with_crypto_scheme, + pair_from_suri, decode_hex, with_crypto_scheme, CryptoSchemeFlag, GenericNumber, }; use structopt::StructOpt; @@ -49,7 +49,7 @@ pub struct SignTransactionCmd { /// genesis hash, for signed extensions. #[structopt(long, parse(try_from_str = decode_hex))] - genesis: Bytes, + prior_block_hash: Bytes, /// The call, hex-encoded. #[structopt(long, parse(try_from_str = decode_hex))] @@ -79,13 +79,13 @@ impl SignTransactionCmd { CallFor

: Codec, { let nonce = self.nonce.parse::>()?; - let genesis = ::decode(&mut &self.genesis[..])?; + let hash = ::decode(&mut &self.prior_block_hash[..])?; let call = CallFor::

::decode(&mut &self.call[..])?; let password = self.keystore_params.read_password()?; with_crypto_scheme!( self.crypto_scheme.scheme, - print_ext

(&self.suri, password.as_ref().map(String::as_str), call, nonce, genesis) + print_ext

(&self.suri, password.as_ref().map(String::as_str), call, nonce, hash) ) } } @@ -107,7 +107,7 @@ fn print_ext( pass: Option<&str>, call: CallFor

, nonce: IndexFor

, - genesis: P::Hash + hash: P::Hash ) -> Result<(), Error> where Pair: sp_core::Pair, @@ -119,7 +119,7 @@ fn print_ext( CallFor

: Codec, { let signer = pair_from_suri::(uri, pass); - let extrinsic = create_extrinsic_for::(call, nonce, signer, genesis)?; + let extrinsic = create_extrinsic_for::(call, nonce, signer, hash)?; println!("0x{}", HexDisplay::from(&extrinsic.encode())); Ok(()) } diff --git a/utils/frame/frame-utilities-cli/src/transfer.rs b/utils/frame/frame-utilities-cli/src/transfer.rs index 72e68c7a8559c..cfd177114739e 100644 --- a/utils/frame/frame-utilities-cli/src/transfer.rs +++ b/utils/frame/frame-utilities-cli/src/transfer.rs @@ -58,7 +58,7 @@ pub struct TransferCmd { /// genesis hash, for signed extensions. #[structopt(long, parse(try_from_str = decode_hex))] - genesis: Bytes, + prior_block_hash: Bytes, #[allow(missing_docs)] #[structopt(flatten)] @@ -96,7 +96,7 @@ impl TransferCmd { .map_err(|_| Error::Other("Invalid SS58-check address given for account ID.".into()))? }; let amount = self.amount.parse::>()?; - let genesis = ::decode(&mut &self.genesis[..])?; + let prior_block_hash = ::decode(&mut &self.prior_block_hash[..])?; println!("Scheme {}", self.crypto_scheme.scheme); with_crypto_scheme!( @@ -107,7 +107,7 @@ impl TransferCmd { to.into(), nonce, amount, - genesis + prior_block_hash ) ) } @@ -129,7 +129,7 @@ fn print_ext( to: AddressFor

, nonce: IndexFor

, amount: BalanceFor

, - genesis: P::Hash + prior_block_hash: P::Hash ) -> Result<(), Error> where Pair: sp_core::Pair, @@ -143,43 +143,7 @@ fn print_ext( { let signer = pair_from_suri::(uri, pass); let call: CallFor

= BalancesCall::transfer(to, amount).into(); - let extrinsic = create_extrinsic_for::(call, nonce, signer, genesis)?; + let extrinsic = create_extrinsic_for::(call, nonce, signer, prior_block_hash)?; println!("0x{}", HexDisplay::from(&extrinsic.encode())); Ok(()) } - -// #[cfg(test)] -// mod tests { -// use super::*; -// use substrate_test_runtime::Runtime; -// -// fn new_test_ext() -> sp_io::TestExternalities { -// let t = frame_system::GenesisConfig::default().build_storage::().unwrap(); -// sp_io::TestExternalities::new(t) -// } -// -// #[test] -// fn transfer() { -// let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; -// let words = "remember fiber forum demise paper uniform squirrel feel access exclude casual effort"; -// -// let transfer = TransferCmd::from_iter(&["transfer", -// "--from", seed, -// "--to", "0xa2bc899a8a3b16a284a8cefcbc2dc48a687cd674e89b434fbbdb06f400979744", -// "--amount", "5000", -// "--index", "1", -// "--password", "12345", -// ]); -// -// new_test_ext().execute_with(|| { -// assert!(matches!(transfer.run::(), Ok(()))); -// let transfer = TransferCmd::from_iter(&["transfer", -// "--from", words, -// "--to", "0xa2bc899a8a3b16a284a8cefcbc2dc48a687cd674e89b434fbbdb06f400979744", -// "--amount", "5000", -// "--index", "1", -// ]); -// assert!(matches!(transfer.run::(), Err(Error::Input(_)))) -// }); -// } -// } diff --git a/utils/frame/frame-utilities-cli/src/utils.rs b/utils/frame/frame-utilities-cli/src/utils.rs index 9d9a18882297f..7c4077c6ac4e1 100644 --- a/utils/frame/frame-utilities-cli/src/utils.rs +++ b/utils/frame/frame-utilities-cli/src/utils.rs @@ -28,7 +28,7 @@ pub fn create_extrinsic_for( call: Call, nonce: IndexFor

, pair: Pair, - genesis: P::Hash, + hash: P::Hash, ) -> Result< UncheckedExtrinsic, Call, MultiSignature, P::Extra>, &'static str @@ -42,7 +42,7 @@ pub fn create_extrinsic_for( AccountIdFor

: From, AddressFor

: From>, { - let (extra, additional) = P::construct_extras(nonce, Era::Immortal, Some(genesis)); + let (extra, additional) = P::construct_extras(nonce, Era::Immortal, Some(hash)); let payload = if let Some(additional_signed) = additional { SignedPayload::from_raw(call, extra, additional_signed) From 0590bbfcebc7eb45eb842197532ae96c812175a5 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 2 Jun 2020 11:09:19 +0100 Subject: [PATCH 53/77] fix moduleid test --- utils/frame/frame-utilities-cli/src/module_id.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/frame/frame-utilities-cli/src/module_id.rs b/utils/frame/frame-utilities-cli/src/module_id.rs index 24b95744d3e2e..3ef3228a5b63d 100644 --- a/utils/frame/frame-utilities-cli/src/module_id.rs +++ b/utils/frame/frame-utilities-cli/src/module_id.rs @@ -111,7 +111,7 @@ mod tests { fn module_id() { let seed = "sdad1fb7"; - let cmd = ModuleIdCmd::from_iter(&["moduleid", "--id", seed]); + let cmd = ModuleIdCmd::from_iter(&["moduleid", seed]); assert!(cmd.run().is_ok()); } } \ No newline at end of file From 5ac0694f0576787944f0536e60b120d27e6c87d4 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 2 Jun 2020 11:40:22 +0100 Subject: [PATCH 54/77] CI and clion disagree on line widths --- bin/node/runtime/src/lib.rs | 5 ++++- client/cli/src/commands/tests.rs | 10 +++++++++- utils/frame/frame-utilities-cli/src/transfer.rs | 9 ++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 87b64277b8b75..0cdc7dfb52a6e 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -45,7 +45,10 @@ use sp_runtime::{ }; use sp_runtime::curve::PiecewiseLinear; use sp_runtime::transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority}; -use sp_runtime::traits::{self, BlakeTwo256, Block as BlockT, StaticLookup, SaturatedConversion, ConvertInto, OpaqueKeys, NumberFor, Saturating, SignedExtension}; +use sp_runtime::traits::{ + self, BlakeTwo256, Block as BlockT, StaticLookup, SaturatedConversion, + ConvertInto, OpaqueKeys, NumberFor, Saturating, SignedExtension, +}; use frame_utils::{SignedExtensionProvider, IndexFor}; use sp_version::RuntimeVersion; #[cfg(any(feature = "std", test))] diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs index 1ee37d086ca25..192282bc006ea 100644 --- a/client/cli/src/commands/tests.rs +++ b/client/cli/src/commands/tests.rs @@ -23,7 +23,15 @@ use structopt::StructOpt; fn sign() { let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; - let sign = SignCmd::from_iter(&["sign", "--suri", seed, "--message", &seed[2..], "--password", "12345"]); + let sign = SignCmd::from_iter(&[ + "sign", + "--suri", + seed, + "--message", + &seed[2..], + "--password", + "12345" + ]); assert!(sign.run().is_ok()); } diff --git a/utils/frame/frame-utilities-cli/src/transfer.rs b/utils/frame/frame-utilities-cli/src/transfer.rs index cfd177114739e..e2f69f3922cee 100644 --- a/utils/frame/frame-utilities-cli/src/transfer.rs +++ b/utils/frame/frame-utilities-cli/src/transfer.rs @@ -28,7 +28,10 @@ use codec::{Encode, Decode}; use sp_runtime::{MultiSigner, MultiSignature, AccountId32}; use std::convert::TryFrom; use sp_core::{crypto::Ss58Codec, hexdisplay::HexDisplay}; -use frame_utils::{AddressFor, IndexFor, BalanceFor, BalancesCall, AccountIdFor, SignedExtensionProvider, CallFor}; +use frame_utils::{ + AddressFor, IndexFor, BalanceFor, BalancesCall, AccountIdFor, + SignedExtensionProvider, CallFor, +}; use crate::utils::create_extrinsic_for; type Bytes = Vec; @@ -90,10 +93,10 @@ impl TransferCmd { let nonce = self.index.parse::>()?; let to = if let Ok(data_vec) = decode_hex(&self.to) { AccountIdFor::::try_from(&data_vec) - .map_err(|_| Error::Other("Invalid hex length for account ID; should be 32 bytes".into()))? + .map_err(|_| "Invalid hex length for account ID; should be 32 bytes")? } else { AccountIdFor::::from_ss58check(&self.to) - .map_err(|_| Error::Other("Invalid SS58-check address given for account ID.".into()))? + .map_err(|_| "Invalid SS58-check address given for account ID.")? }; let amount = self.amount.parse::>()?; let prior_block_hash = ::decode(&mut &self.prior_block_hash[..])?; From aa16d9c1824183edf467c6cf69c32e8edd722ecb Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 9 Jun 2020 16:38:50 +0100 Subject: [PATCH 55/77] adds associated Params type to SignedExtensionProvider --- bin/node/runtime/src/lib.rs | 70 +++++++++++++++++--- test-utils/runtime/src/lib.rs | 43 ++++++++++-- utils/frame-utils/src/lib.rs | 28 ++++++-- utils/frame/frame-utilities-cli/src/utils.rs | 8 ++- 4 files changed, 127 insertions(+), 22 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index c5835eb06729c..032f3be8ccef1 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -52,7 +52,7 @@ use sp_runtime::traits::{ self, BlakeTwo256, Block as BlockT, StaticLookup, SaturatedConversion, ConvertInto, OpaqueKeys, NumberFor, Saturating, SignedExtension, }; -use frame_utils::{SignedExtensionProvider, IndexFor}; +use frame_utils::{SignedExtensionProvider, SystemExtraParams}; use sp_version::RuntimeVersion; #[cfg(any(feature = "std", test))] use sp_version::NativeVersion; @@ -608,15 +608,61 @@ parameter_types! { pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2; } +#[derive(Default)] +pub struct ExtrasParams { + era: Option, + index: Option, + tip: Option, + prior_block_hash: Option, +} + +impl SystemExtraParams for ExtrasParams { + fn set_nonce(&mut self, index: ::Index) { + self.index = Some(index); + } + + fn set_era(&mut self, era: Era) { + self.era = Some(era); + } + + fn set_prior_block_hash(&mut self, hash: ::Hash) { + self.prior_block_hash = Some(hash); + } +} + + impl SignedExtensionProvider for Runtime { type Extra = SignedExtra; + type Params = ExtrasParams; + + fn extension_params() -> ExtrasParams { + ExtrasParams { + prior_block_hash: None, + index: None, + era: None, + tip: Some(0), + } + } - fn construct_extras(index: IndexFor, era: Era, prior_block_hash: Option) -> ( - Self::Extra, - Option<::AdditionalSigned> - ) { - let tip = 0; + fn construct_extras(params: ExtrasParams) -> Result< ( + Self::Extra, + Option<::AdditionalSigned> + ), + &'static str + > { + let ExtrasParams { + tip, + era, + index, + prior_block_hash + } = params; + let (era, index) = ( + era.ok_or("era is required")?, + index.ok_or("index is required")?, + ); + let tip = tip.unwrap_or(0); + let data = ( ( frame_system::CheckSpecVersion::::new(), frame_system::CheckTxVersion::::new(), @@ -639,7 +685,9 @@ impl SignedExtensionProvider for Runtime { (), ) }) - ) + ); + + Ok(data) } } @@ -664,7 +712,13 @@ impl frame_system::offchain::CreateSignedTransaction for R // so the actual block number is `n`. .saturating_sub(1); let era = Era::mortal(period, current_block); - let (extra, additional) = Runtime::construct_extras(nonce, era, None); + let mut input = Runtime::extension_params(); + input.set_nonce(nonce); + input.set_era(era); + let (extra, additional) = match Runtime::construct_extras(input) { + Ok(d) => d, + Err(_) => return None, + }; let raw_payload = if let Some(additional_signed) = additional { SignedPayload::from_raw(call, extra, additional_signed) } else { diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index 6b7eca75fff6c..c8b14b406fa81 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -55,9 +55,10 @@ use cfg_if::cfg_if; // Ensure Babe and Aura use the same crypto to simplify things a bit. pub use sp_consensus_babe::{AuthorityId, SlotNumber, AllowedSlots}; -use frame_utils::{SignedExtensionProvider, IndexFor}; +use frame_utils::{SignedExtensionProvider, SystemExtraParams}; use sp_runtime::generic::Era; use sp_runtime::traits::SignedExtension; +use frame_system::Trait; pub type AuraId = sp_consensus_aura::sr25519::AuthorityId; @@ -420,6 +421,24 @@ impl pallet_balances::Trait for Runtime { type AccountStore = frame_system::Module; } +impl SystemExtraParams for ExtrasParams { + fn set_nonce(&mut self, _index: ::Index) { + unimplemented!() + } + + fn set_era(&mut self, era: Era) { + self.era = era; + } + + fn set_prior_block_hash(&mut self, _hash: ::Hash) { + unimplemented!() + } +} + +pub struct ExtrasParams { + era: Era +} + impl SignedExtensionProvider for Runtime { type Extra = ( frame_system::CheckTxVersion, @@ -427,18 +446,28 @@ impl SignedExtensionProvider for Runtime { frame_system::CheckEra, ); - fn construct_extras(_index: IndexFor, era: Era, _genesis: Option) -> ( - Self::Extra, - Option<::AdditionalSigned> - ) { + type Params = ExtrasParams; + + fn extension_params() -> Self::Params { + ExtrasParams { era: Era::Immortal } + } + + fn construct_extras(params: Self::Params) -> Result< ( + Self::Extra, + Option<::AdditionalSigned> + ), + &'static str + > { + let data = ( ( frame_system::CheckTxVersion::new(), frame_system::CheckGenesis::new(), - frame_system::CheckEra::from(era) + frame_system::CheckEra::from(params.era) ), None - ) + ); + Ok(data) } } diff --git a/utils/frame-utils/src/lib.rs b/utils/frame-utils/src/lib.rs index 748700563f172..26b462a2cbb98 100644 --- a/utils/frame-utils/src/lib.rs +++ b/utils/frame-utils/src/lib.rs @@ -75,12 +75,30 @@ pub type AccountIdFor = ::AccountId; /// pub trait SignedExtensionProvider: frame_system::Trait { /// Concrete SignedExtension type. - type Extra: SignedExtension; + type Extra: SignedExtension; + /// Concrete type for params + type Params: SystemExtraParams; + + /// retrieve an instance of the input object. + fn extension_params() -> Self::Params; /// construct extras and optionally additional_signed data for inclusion in extrinsics. - fn construct_extras(nonce: IndexFor, era: Era, prior_block_hash: Option) -> ( - Self::Extra, - Option<::AdditionalSigned> - ); + fn construct_extras(input: Self::Params) -> Result< + ( + Self::Extra, + Option<::AdditionalSigned> + ), + &'static str + >; } +/// used internally by substrate to set extras for inclusion in +/// `SignedExtensionProvider` +pub trait SystemExtraParams { + /// sets the nonce + fn set_nonce(&mut self, index: T::Index); + /// sets the nonce + fn set_era(&mut self, era: Era); + /// sets the prior block hash + fn set_prior_block_hash(&mut self, hash: T::Hash); +} \ No newline at end of file diff --git a/utils/frame/frame-utilities-cli/src/utils.rs b/utils/frame/frame-utilities-cli/src/utils.rs index 7c4077c6ac4e1..5d8d499eead39 100644 --- a/utils/frame/frame-utilities-cli/src/utils.rs +++ b/utils/frame/frame-utilities-cli/src/utils.rs @@ -20,7 +20,7 @@ use sp_runtime::{ MultiSigner, AccountId32, traits::IdentifyAccount, MultiSignature, }; use codec::Encode; -use frame_utils::{SignedExtensionProvider, IndexFor, AddressFor, AccountIdFor}; +use frame_utils::{SignedExtensionProvider, SystemExtraParams, IndexFor, AddressFor, AccountIdFor}; use sp_runtime::generic::Era; /// create an extrinsic for the runtime. @@ -42,7 +42,11 @@ pub fn create_extrinsic_for( AccountIdFor

: From, AddressFor

: From>, { - let (extra, additional) = P::construct_extras(nonce, Era::Immortal, Some(hash)); + let mut input = P::extension_params(); + input.set_nonce(nonce); + input.set_era(Era::Immortal); + input.set_prior_block_hash(hash); + let (extra, additional) = P::construct_extras(input)?; let payload = if let Some(additional_signed) = additional { SignedPayload::from_raw(call, extra, additional_signed) From 54277a74e6cf514bd22ad0d94cbcfe65f3d4bca8 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Thu, 11 Jun 2020 12:35:07 +0100 Subject: [PATCH 56/77] Apply suggestions from code review Co-authored-by: Benjamin Kampmann --- client/cli/src/commands/mod.rs | 20 ++++++++++---------- client/cli/src/commands/tests.rs | 2 +- client/cli/src/commands/utils.rs | 3 +-- client/cli/src/commands/verify.rs | 2 +- utils/frame-utils/src/lib.rs | 4 ++-- utils/frame/frame-utilities-cli/Cargo.toml | 6 ++++-- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 307f8bed86b68..53f14f87bf802 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -432,14 +432,14 @@ macro_rules! substrate_cli_subcommands { substrate_cli_subcommands!( Subcommand => - BuildSpec, - ExportBlocks, - ExportState, - ImportBlocks, - CheckBlock, - Revert, - PurgeChain, - Sign, - Verify, - Vanity + BuildSpec, + ExportBlocks, + ExportState, + ImportBlocks, + CheckBlock, + Revert, + PurgeChain, + Sign, + Verify, + Vanity ); diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs index 192282bc006ea..f05014c475349 100644 --- a/client/cli/src/commands/tests.rs +++ b/client/cli/src/commands/tests.rs @@ -1,6 +1,6 @@ // This file is part of Substrate. -// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd. +// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd. // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 // This program is free software: you can redistribute it and/or modify diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 9c211fa67b94a..8fc9e3698133c 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -1,6 +1,6 @@ // This file is part of Substrate. -// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd. +// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd. // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 // This program is free software: you can redistribute it and/or modify @@ -220,4 +220,3 @@ macro_rules! with_crypto_scheme { } }; } - diff --git a/client/cli/src/commands/verify.rs b/client/cli/src/commands/verify.rs index d029513930e36..be9e8928c8a35 100644 --- a/client/cli/src/commands/verify.rs +++ b/client/cli/src/commands/verify.rs @@ -1,6 +1,6 @@ // This file is part of Substrate. -// Copyright (C) 2018-2020 Parity Technologies (UK) Ltd. +// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd. // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 // This program is free software: you can redistribute it and/or modify diff --git a/utils/frame-utils/src/lib.rs b/utils/frame-utils/src/lib.rs index 26b462a2cbb98..da42c34bf2e9f 100644 --- a/utils/frame-utils/src/lib.rs +++ b/utils/frame-utils/src/lib.rs @@ -76,7 +76,7 @@ pub type AccountIdFor = ::AccountId; pub trait SignedExtensionProvider: frame_system::Trait { /// Concrete SignedExtension type. type Extra: SignedExtension; - /// Concrete type for params + /// Concrete type for params used to construct the `SignedExtension`-Data type Params: SystemExtraParams; /// retrieve an instance of the input object. @@ -101,4 +101,4 @@ pub trait SystemExtraParams { fn set_era(&mut self, era: Era); /// sets the prior block hash fn set_prior_block_hash(&mut self, hash: T::Hash); -} \ No newline at end of file +} diff --git a/utils/frame/frame-utilities-cli/Cargo.toml b/utils/frame/frame-utilities-cli/Cargo.toml index 94e617171f843..31f2e8b663618 100644 --- a/utils/frame/frame-utilities-cli/Cargo.toml +++ b/utils/frame/frame-utilities-cli/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "frame-utilities-cli" +name = "substrate-frame-utilities-cli" version = "2.0.0-rc3" authors = ["Parity Technologies "] edition = "2018" @@ -36,4 +36,6 @@ sp-io = { version = "2.0.0-rc3", path = "../../../primitives/io" } frame-system = { version = "2.0.0-rc3", path = "../../../frame/system" } [features] -balances = [] +default = [] +balances = ["pallet-balances"] +indices = ["pallet-indices"] From 22049d381e4c6711c3217abc10aa76b14cc86f9f Mon Sep 17 00:00:00 2001 From: Seun Date: Thu, 11 Jun 2020 13:39:54 +0100 Subject: [PATCH 57/77] move some code around --- Cargo.lock | 76 ++++++++----------- Cargo.toml | 1 - bin/node-template/runtime/Cargo.toml | 2 - bin/node/cli/Cargo.toml | 6 +- bin/node/cli/src/cli.rs | 4 +- bin/node/cli/src/command.rs | 3 +- bin/node/runtime/Cargo.toml | 2 - bin/node/runtime/src/lib.rs | 31 ++++---- bin/utils/subkey/Cargo.toml | 3 +- bin/utils/subkey/src/main.rs | 11 +-- client/cli/Cargo.toml | 2 + .../cli/src/commands}/generate.rs | 14 +++- .../cli/src/commands}/generate_node_key.rs | 18 +++-- .../src => client/cli/src/commands}/insert.rs | 11 ++- .../cli/src/commands}/inspect.rs | 22 +++++- .../cli/src/commands}/inspect_node_key.rs | 7 +- .../src => client/cli/src/commands}/key.rs | 12 ++- client/cli/src/commands/mod.rs | 14 ++++ .../cli/src/commands}/module_id.rs | 3 +- .../src/lib.rs => frame/system/src/extras.rs | 75 +++++++++--------- frame/system/src/lib.rs | 1 + test-utils/runtime/Cargo.toml | 1 - test-utils/runtime/src/lib.rs | 19 ++--- utils/frame-utils/Cargo.toml | 26 ------- utils/frame/frame-utilities-cli/Cargo.toml | 19 ++--- utils/frame/frame-utilities-cli/src/lib.rs | 59 +------------- .../src/sign_transaction.rs | 2 +- .../frame/frame-utilities-cli/src/transfer.rs | 11 ++- utils/frame/frame-utilities-cli/src/utils.rs | 7 +- 29 files changed, 209 insertions(+), 253 deletions(-) rename {utils/frame/frame-utilities-cli/src => client/cli/src/commands}/generate.rs (91%) rename {utils/frame/frame-utilities-cli/src => client/cli/src/commands}/generate_node_key.rs (79%) rename {utils/frame/frame-utilities-cli/src => client/cli/src/commands}/insert.rs (93%) rename {utils/frame/frame-utilities-cli/src => client/cli/src/commands}/inspect.rs (81%) rename {utils/frame/frame-utilities-cli/src => client/cli/src/commands}/inspect_node_key.rs (94%) rename {utils/frame/frame-utilities-cli/src => client/cli/src/commands}/key.rs (86%) rename {utils/frame/frame-utilities-cli/src => client/cli/src/commands}/module_id.rs (98%) rename utils/frame-utils/src/lib.rs => frame/system/src/extras.rs (55%) delete mode 100644 utils/frame-utils/Cargo.toml diff --git a/Cargo.lock b/Cargo.lock index e37c9251a3b4f..8e0b6b8b20aca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1590,45 +1590,6 @@ dependencies = [ "sp-api", ] -[[package]] -name = "frame-utilities-cli" -version = "2.0.0-rc3" -dependencies = [ - "bip39", - "frame-system", - "frame-utils", - "futures 0.1.29", - "futures 0.3.5", - "hex", - "hyper 0.12.35", - "jsonrpc-core-client", - "libp2p 0.18.1", - "pallet-balances", - "pallet-indices", - "parity-scale-codec", - "sc-cli", - "sc-client-api", - "sc-rpc", - "sc-service", - "serde", - "sp-core", - "sp-io", - "sp-runtime", - "structopt", - "tempfile", -] - -[[package]] -name = "frame-utils" -version = "2.0.0-rc3" -dependencies = [ - "frame-system", - "pallet-balances", - "parity-scale-codec", - "sp-core", - "sp-runtime", -] - [[package]] name = "fs-swap" version = "0.2.4" @@ -3837,7 +3798,6 @@ dependencies = [ "frame-benchmarking-cli", "frame-support", "frame-system", - "frame-utilities-cli", "futures 0.3.5", "hex-literal", "jsonrpc-core", @@ -3898,6 +3858,7 @@ dependencies = [ "structopt", "substrate-browser-utils", "substrate-build-script-utils", + "substrate-frame-cli", "tempfile", "tracing", "wasm-bindgen", @@ -4016,7 +3977,6 @@ dependencies = [ "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", - "frame-utils", "integer-sqrt", "node-primitives", "pallet-authority-discovery", @@ -4111,7 +4071,6 @@ dependencies = [ "frame-executive", "frame-support", "frame-system", - "frame-utils", "pallet-aura", "pallet-balances", "pallet-grandpa", @@ -6456,6 +6415,7 @@ dependencies = [ "derive_more", "env_logger 0.7.1", "fdlimit", + "futures 0.1.29", "futures 0.3.5", "hex", "hyper 0.12.35", @@ -6473,6 +6433,7 @@ dependencies = [ "sc-client-api", "sc-informant", "sc-network", + "sc-rpc", "sc-service", "sc-telemetry", "sc-tracing", @@ -8597,11 +8558,12 @@ dependencies = [ name = "subkey" version = "2.0.0-rc3" dependencies = [ - "frame-utilities-cli", + "frame-system", "node-primitives", "node-runtime", "sc-cli", "structopt", + "substrate-frame-cli", ] [[package]] @@ -8649,6 +8611,33 @@ dependencies = [ "platforms", ] +[[package]] +name = "substrate-frame-cli" +version = "2.0.0-rc3" +dependencies = [ + "bip39", + "frame-system", + "futures 0.1.29", + "futures 0.3.5", + "hex", + "hyper 0.12.35", + "jsonrpc-core-client", + "libp2p 0.18.1", + "pallet-balances", + "pallet-indices", + "parity-scale-codec", + "sc-cli", + "sc-client-api", + "sc-rpc", + "sc-service", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "structopt", + "tempfile", +] + [[package]] name = "substrate-frame-rpc-support" version = "2.0.0-rc3" @@ -8731,7 +8720,6 @@ dependencies = [ "frame-support", "frame-system", "frame-system-rpc-runtime-api", - "frame-utils", "log", "memory-db", "pallet-babe", diff --git a/Cargo.toml b/Cargo.toml index e7aa69fff8084..0d295f6972409 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -175,7 +175,6 @@ members = [ "test-utils/runtime/transaction-pool", "utils/browser", "utils/build-script-utils", - "utils/frame-utils", "utils/fork-tree", "utils/frame/benchmarking-cli", "utils/frame/frame-utilities-cli", diff --git a/bin/node-template/runtime/Cargo.toml b/bin/node-template/runtime/Cargo.toml index a8597fb6a20e7..d093c11dac0ee 100644 --- a/bin/node-template/runtime/Cargo.toml +++ b/bin/node-template/runtime/Cargo.toml @@ -36,7 +36,6 @@ sp-session = { version = "2.0.0-rc3", default-features = false, path = "../../.. sp-std = { version = "2.0.0-rc3", default-features = false, path = "../../../primitives/std" } sp-transaction-pool = { version = "2.0.0-rc3", default-features = false, path = "../../../primitives/transaction-pool" } sp-version = { version = "2.0.0-rc3", default-features = false, path = "../../../primitives/version" } -frame-utils = { version = "2.0.0-rc3", default-features = false, path = "../../../utils/frame-utils" } template = { version = "2.0.0-rc3", default-features = false, path = "../pallets/template", package = "pallet-template" } [build-dependencies] @@ -70,5 +69,4 @@ std = [ "timestamp/std", "transaction-payment/std", "template/std", - "frame-utils/std", ] diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index 7daa33e9002e4..0adad05f0ca1d 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -97,7 +97,7 @@ node-executor = { version = "2.0.0-rc3", path = "../executor" } # CLI-specific dependencies sc-cli = { version = "0.8.0-rc3", optional = true, path = "../../../client/cli" } -frame-utilities-cli = { version = "2.0.0-rc3", optional = true, features = ["balances"], path = "../../../utils/frame/frame-utilities-cli" } +substrate-frame-cli = { version = "2.0.0-rc3", optional = true, features = ["balances"], path = "../../../utils/frame/frame-utilities-cli" } frame-benchmarking-cli = { version = "2.0.0-rc3", optional = true, path = "../../../utils/frame/benchmarking-cli" } node-inspect = { version = "0.8.0-rc3", optional = true, path = "../inspect" } @@ -130,7 +130,7 @@ structopt = { version = "0.3.8", optional = true } node-inspect = { version = "0.8.0-rc3", optional = true, path = "../inspect" } frame-benchmarking-cli = { version = "2.0.0-rc3", optional = true, path = "../../../utils/frame/benchmarking-cli" } substrate-build-script-utils = { version = "2.0.0-rc3", optional = true, path = "../../../utils/build-script-utils" } -frame-utilities-cli = { version = "2.0.0-rc3", optional = true, features = ["balances"], path = "../../../utils/frame/frame-utilities-cli" } +substrate-frame-cli = { version = "2.0.0-rc3", optional = true, features = ["balances"], path = "../../../utils/frame/frame-utilities-cli" } [build-dependencies.sc-cli] version = "0.8.0-rc3" @@ -150,7 +150,7 @@ cli = [ "node-inspect", "sc-cli", "frame-benchmarking-cli", - "frame-utilities-cli", + "substrate-frame-cli", "sc-service/db", "structopt", "substrate-build-script-utils", diff --git a/bin/node/cli/src/cli.rs b/bin/node/cli/src/cli.rs index f608756d066b5..a5d48b35b31f2 100644 --- a/bin/node/cli/src/cli.rs +++ b/bin/node/cli/src/cli.rs @@ -16,9 +16,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use sc_cli::RunCmd; +use sc_cli::{RunCmd, KeySubcommand}; use structopt::StructOpt; -use frame_utilities_cli::{KeySubcommand, SignTransactionCmd, TransferCmd}; +use substrate_frame_cli::{SignTransactionCmd, TransferCmd}; /// An overarching CLI command definition. #[derive(Debug, StructOpt)] diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index 9fb16ae18651d..3b3baeb200d23 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -19,6 +19,7 @@ use crate::{chain_spec, service, Cli, Subcommand}; use node_executor::Executor; use node_runtime::{Block, RuntimeApi, Runtime}; +use node_primitives::Hash; use sc_cli::{Result, SubstrateCli}; impl SubstrateCli for Cli { @@ -95,7 +96,7 @@ pub fn run() -> Result<()> { Some(Subcommand::Key(cmd)) => { let runner = cli.create_runner(cmd)?; - runner.sync_run(|_| cmd.run::()) + runner.sync_run(|_| cmd.run::()) }, Some(Subcommand::SignTransaction(cmd)) => { let runner = cli.create_runner(cmd)?; diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index 6aea26af4f11d..ebe3196dd744e 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -78,7 +78,6 @@ pallet-utility = { version = "2.0.0-rc3", default-features = false, path = "../. pallet-transaction-payment = { version = "2.0.0-rc3", default-features = false, path = "../../../frame/transaction-payment" } pallet-transaction-payment-rpc-runtime-api = { version = "2.0.0-rc3", default-features = false, path = "../../../frame/transaction-payment/rpc/runtime-api/" } pallet-vesting = { version = "2.0.0-rc3", default-features = false, path = "../../../frame/vesting" } -frame-utils = { version = "2.0.0-rc3", default-features = false, path = "../../../utils/frame-utils" } [build-dependencies] wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-runner", path = "../../../utils/wasm-builder-runner" } @@ -142,7 +141,6 @@ std = [ "pallet-society/std", "pallet-recovery/std", "pallet-vesting/std", - "frame-utils/std", ] runtime-benchmarks = [ "frame-benchmarking", diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 8364170e3fa44..6e4e9b7d922e4 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -32,7 +32,10 @@ use frame_support::{ }, traits::{Currency, Imbalance, KeyOwnerProofSystem, OnUnbalanced, Randomness, LockIdentifier}, }; -use frame_system::{EnsureRoot, EnsureOneOf}; +use frame_system::{ + EnsureRoot, EnsureOneOf, + extras::{SignedExtensionProvider, SystemExtraParams, SignedExtensionData}, +}; use frame_support::traits::{Filter, InstanceFilter}; use codec::{Encode, Decode}; use sp_core::{ @@ -51,9 +54,8 @@ use sp_runtime::curve::PiecewiseLinear; use sp_runtime::transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority}; use sp_runtime::traits::{ self, BlakeTwo256, Block as BlockT, StaticLookup, SaturatedConversion, - ConvertInto, OpaqueKeys, NumberFor, Saturating, SignedExtension, + ConvertInto, OpaqueKeys, NumberFor, Saturating, }; -use frame_utils::{SignedExtensionProvider, SystemExtraParams}; use sp_version::RuntimeVersion; #[cfg(any(feature = "std", test))] use sp_version::NativeVersion; @@ -630,7 +632,7 @@ parameter_types! { pub struct ExtrasParams { era: Option, index: Option, - tip: Option, + tip: u128, prior_block_hash: Option, } @@ -658,17 +660,11 @@ impl SignedExtensionProvider for Runtime { prior_block_hash: None, index: None, era: None, - tip: Some(0), + tip: 0, } } - fn construct_extras(params: ExtrasParams) -> Result< - ( - Self::Extra, - Option<::AdditionalSigned> - ), - &'static str - > { + fn construct_extras(params: ExtrasParams) -> Result, &'static str> { let ExtrasParams { tip, era, @@ -679,9 +675,8 @@ impl SignedExtensionProvider for Runtime { era.ok_or("era is required")?, index.ok_or("index is required")?, ); - let tip = tip.unwrap_or(0); - let data = ( - ( + let data = SignedExtensionData { + extra: ( frame_system::CheckSpecVersion::::new(), frame_system::CheckTxVersion::::new(), frame_system::CheckGenesis::::new(), @@ -691,7 +686,7 @@ impl SignedExtensionProvider for Runtime { pallet_transaction_payment::ChargeTransactionPayment::::from(tip), pallet_grandpa::ValidateEquivocationReport::::new(), ), - prior_block_hash.map(|hash| { + additional: prior_block_hash.map(|hash| { ( VERSION.spec_version, VERSION.transaction_version, @@ -703,7 +698,7 @@ impl SignedExtensionProvider for Runtime { (), ) }) - ); + }; Ok(data) } @@ -733,7 +728,7 @@ impl frame_system::offchain::CreateSignedTransaction for R let mut input = Runtime::extension_params(); input.set_nonce(nonce); input.set_era(era); - let (extra, additional) = match Runtime::construct_extras(input) { + let SignedExtensionData { extra, additional } = match Runtime::construct_extras(input) { Ok(d) => d, Err(_) => return None, }; diff --git a/bin/utils/subkey/Cargo.toml b/bin/utils/subkey/Cargo.toml index 9b6f34f6b5f5b..bff4197227325 100644 --- a/bin/utils/subkey/Cargo.toml +++ b/bin/utils/subkey/Cargo.toml @@ -14,8 +14,9 @@ targets = ["x86_64-unknown-linux-gnu"] node-runtime = { version = "2.0.0-rc3", path = "../../node/runtime" } node-primitives = { version = "2.0.0-rc3", path = "../../node/primitives" } sc-cli = { version = "0.8.0-rc3", path = "../../../client/cli" } -frame-utilities-cli = { version = "2.0.0-rc3", features = ["balances"], path = "../../../utils/frame/frame-utilities-cli" } +substrate-frame-cli = { version = "2.0.0-rc3", features = ["balances"], path = "../../../utils/frame/frame-utilities-cli" } structopt = "0.3.14" +frame-system = { version = "2.0.0-rc3", path = "../../../frame/system" } [features] bench = [] diff --git a/bin/utils/subkey/src/main.rs b/bin/utils/subkey/src/main.rs index 77fd7c975c657..becfd44dbda8e 100644 --- a/bin/utils/subkey/src/main.rs +++ b/bin/utils/subkey/src/main.rs @@ -17,12 +17,13 @@ // along with this program. If not, see . use structopt::StructOpt; -use frame_utilities_cli::{ - InsertCmd, TransferCmd, SignTransactionCmd, ModuleIdCmd, - GenerateNodeKeyCmd, GenerateCmd, InspectCmd, InspectNodeKeyCmd, +use sc_cli::{ + Error, VanityCmd, SignCmd, VerifyCmd, ModuleIdCmd, InsertCmd, + GenerateNodeKeyCmd, GenerateCmd, InspectCmd, InspectNodeKeyCmd }; -use sc_cli::{Error, VanityCmd, SignCmd, VerifyCmd}; +use substrate_frame_cli::{TransferCmd, SignTransactionCmd}; use node_runtime::Runtime; +use frame_system::extras::HashFor; #[derive(Debug, StructOpt)] #[structopt( @@ -72,7 +73,7 @@ fn main() -> Result<(), Error> { Subkey::Generate(cmd) => cmd.run()?, Subkey::InspectKey(cmd) => cmd.run()?, Subkey::InspectNodeKey(cmd) => cmd.run()?, - Subkey::Insert(cmd) => cmd.run::()?, + Subkey::Insert(cmd) => cmd.run::>()?, Subkey::ModuleId(cmd) => cmd.run()?, Subkey::Transfer(cmd) => cmd.run::()?, Subkey::Vanity(cmd) => cmd.run()?, diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 708bdd2f6c36f..eeb54f17a59c7 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -42,6 +42,7 @@ sp-utils = { version = "2.0.0-rc3", path = "../../primitives/utils" } sp-version = { version = "2.0.0-rc3", path = "../../primitives/version" } sp-core = { version = "2.0.0-rc3", path = "../../primitives/core" } sc-service = { version = "0.8.0-rc3", default-features = false, path = "../service" } +sc-rpc = { version = "2.0.0-rc3", path = "../rpc" } sp-state-machine = { version = "0.8.0-rc3", path = "../../primitives/state-machine" } sc-telemetry = { version = "2.0.0-rc3", path = "../telemetry" } substrate-prometheus-endpoint = { path = "../../utils/prometheus" , version = "0.8.0-rc3"} @@ -51,6 +52,7 @@ structopt = "0.3.8" sc-tracing = { version = "2.0.0-rc3", path = "../tracing" } chrono = "0.4.10" parity-util-mem = { version = "0.6.1", default-features = false, features = ["primitive-types"] } +futures01 = { package = "futures", version = "0.1.29" } [target.'cfg(not(target_os = "unknown"))'.dependencies] rpassword = "4.0.1" diff --git a/utils/frame/frame-utilities-cli/src/generate.rs b/client/cli/src/commands/generate.rs similarity index 91% rename from utils/frame/frame-utilities-cli/src/generate.rs rename to client/cli/src/commands/generate.rs index 5fb8e80f4c87b..8e80ea228e9fa 100644 --- a/utils/frame/frame-utilities-cli/src/generate.rs +++ b/client/cli/src/commands/generate.rs @@ -18,7 +18,7 @@ //! Implementation of the `generate` subcommand use bip39::{MnemonicType, Mnemonic, Language}; use structopt::StructOpt; -use sc_cli::{ +use crate::{ print_from_uri, CliConfiguration, KeystoreParams, SharedParams, Error, with_crypto_scheme, NetworkSchemeFlag, OutputTypeFlag, CryptoSchemeFlag, }; @@ -91,3 +91,15 @@ impl CliConfiguration for GenerateCmd { Some(&self.keystore_params) } } + +#[cfg(test)] +mod tests { + use super::GenerateCmd; + use structopt::StructOpt; + + #[test] + fn generate() { + let generate = GenerateCmd::from_iter(&["generate", "--password", "12345"]); + assert!(generate.run().is_ok()) + } +} diff --git a/utils/frame/frame-utilities-cli/src/generate_node_key.rs b/client/cli/src/commands/generate_node_key.rs similarity index 79% rename from utils/frame/frame-utilities-cli/src/generate_node_key.rs rename to client/cli/src/commands/generate_node_key.rs index e1f3042d6ded4..c01406508c367 100644 --- a/utils/frame/frame-utilities-cli/src/generate_node_key.rs +++ b/client/cli/src/commands/generate_node_key.rs @@ -17,7 +17,7 @@ //! Implementation of the `generate-node-key` subcommand -use sc_cli::{Error, SharedParams, CliConfiguration}; +use crate::{Error, SharedParams, CliConfiguration}; use structopt::StructOpt; use std::{path::PathBuf, fs}; use libp2p::identity::{ed25519 as libp2p_ed25519, PublicKey}; @@ -64,13 +64,17 @@ impl CliConfiguration for GenerateNodeKeyCmd { #[cfg(test)] mod tests { use super::*; + use tempfile::Builder; + use std::io::Read; #[test] - fn inspect_node_key() { - let path = tempfile::tempdir().unwrap().into_path().join("node-id").into_os_string(); - let path = path.to_str().unwrap(); - let cmd = GenerateNodeKeyCmd::from_iter(&["generate-node-key", "--file", path.clone()]); - - assert!(cmd.run().is_ok()); + fn generate_node_key() { + let mut file = Builder::new().prefix("keyfile").tempfile().unwrap(); + let generate = + GenerateNodeKeyCmd::from_iter(&["generate-node-key", "--file", "/tmp/keyfile"]); + assert!(generate.run().is_ok()); + let mut buf = String::new(); + assert!(file.read_to_string(&mut buf).is_ok()); + assert!(hex::decode(buf).is_ok()); } } diff --git a/utils/frame/frame-utilities-cli/src/insert.rs b/client/cli/src/commands/insert.rs similarity index 93% rename from utils/frame/frame-utilities-cli/src/insert.rs rename to client/cli/src/commands/insert.rs index 5ca8f11d5e216..f444b9c8655d4 100644 --- a/utils/frame/frame-utilities-cli/src/insert.rs +++ b/client/cli/src/commands/insert.rs @@ -17,7 +17,7 @@ //! Implementation of the `insert` subcommand -use sc_cli::{ +use crate::{ Error, pair_from_suri, CliConfiguration, KeystoreParams, with_crypto_scheme, CryptoSchemeFlag, SharedParams, read_uri, @@ -30,7 +30,6 @@ use hyper::rt; use sc_rpc::author::AuthorClient; use jsonrpc_core_client::transports::http; use serde::{de::DeserializeOwned, Serialize}; -use frame_utils::{HashFor, SignedExtensionProvider}; /// The `insert` command #[derive(Debug, StructOpt)] @@ -68,10 +67,9 @@ pub struct InsertCmd { impl InsertCmd { /// Run the command - pub fn run

(&self) -> Result<(), Error> + pub fn run(&self) -> Result<(), Error> where - P: SignedExtensionProvider, - HashFor

: DeserializeOwned + Serialize + Send + Sync, + H: DeserializeOwned + Serialize + Send + Sync + 'static, { let suri = read_uri(self.suri.as_ref())?; let password = self.keystore_params.read_password()?; @@ -93,7 +91,7 @@ impl InsertCmd { })?; - insert_key::>( + insert_key::( &node_url, key_type.to_string(), suri, @@ -133,3 +131,4 @@ fn insert_key(url: &str, key_type: String, suri: String, public: Bytes) }) ); } + diff --git a/utils/frame/frame-utilities-cli/src/inspect.rs b/client/cli/src/commands/inspect.rs similarity index 81% rename from utils/frame/frame-utilities-cli/src/inspect.rs rename to client/cli/src/commands/inspect.rs index dedf139cb3312..8f9c56638dce5 100644 --- a/utils/frame/frame-utilities-cli/src/inspect.rs +++ b/client/cli/src/commands/inspect.rs @@ -17,7 +17,7 @@ //! Implementation of the `inspect` subcommand -use sc_cli::{ +use crate::{ print_from_uri, CliConfiguration, KeystoreParams, SharedParams, read_uri, with_crypto_scheme, NetworkSchemeFlag, OutputTypeFlag, CryptoSchemeFlag, Error, }; @@ -87,3 +87,23 @@ impl CliConfiguration for InspectCmd { Some(&self.keystore_params) } } + +#[cfg(test)] +mod tests { + use super::InspectCmd; + use structopt::StructOpt; + + #[test] + fn inspect() { + let words = + "remember fiber forum demise paper uniform squirrel feel access exclude casual effort"; + let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; + + let inspect = + InspectCmd::from_iter(&["inspect-key", "--uri", words, "--password", "12345"]); + assert!(inspect.run().is_ok()); + + let inspect = InspectCmd::from_iter(&["inspect-key", "--uri", seed]); + assert!(inspect.run().is_ok()); + } +} diff --git a/utils/frame/frame-utilities-cli/src/inspect_node_key.rs b/client/cli/src/commands/inspect_node_key.rs similarity index 94% rename from utils/frame/frame-utilities-cli/src/inspect_node_key.rs rename to client/cli/src/commands/inspect_node_key.rs index 47f234bb70f34..a574b3a9de0d0 100644 --- a/utils/frame/frame-utilities-cli/src/inspect_node_key.rs +++ b/client/cli/src/commands/inspect_node_key.rs @@ -17,7 +17,7 @@ //! Implementation of the `inspect-node-key` subcommand -use sc_cli::{Error, SharedParams, NetworkSchemeFlag, CliConfiguration}; +use crate::{Error, SharedParams, NetworkSchemeFlag, CliConfiguration}; use std::fs; use libp2p::identity::{PublicKey, ed25519}; use std::path::PathBuf; @@ -44,6 +44,7 @@ pub struct InspectNodeKeyCmd { } impl InspectNodeKeyCmd { + /// runs the command pub fn run(&self) -> Result<(), Error> { let mut file_content = hex::decode(fs::read(&self.file)?) .map_err(|_| "failed to decode secret as hex")?; @@ -68,7 +69,7 @@ impl CliConfiguration for InspectNodeKeyCmd { #[cfg(test)] mod tests { use super::*; - use crate::generate_node_key::GenerateNodeKeyCmd; + use super::super::GenerateNodeKeyCmd; #[test] fn inspect_node_key() { @@ -81,4 +82,4 @@ mod tests { let cmd = InspectNodeKeyCmd::from_iter(&["inspect-node-key", "--file", path]); assert!(cmd.run().is_ok()); } -} \ No newline at end of file +} diff --git a/utils/frame/frame-utilities-cli/src/key.rs b/client/cli/src/commands/key.rs similarity index 86% rename from utils/frame/frame-utilities-cli/src/key.rs rename to client/cli/src/commands/key.rs index abd4895330c38..13a59c527188e 100644 --- a/utils/frame/frame-utilities-cli/src/key.rs +++ b/client/cli/src/commands/key.rs @@ -17,12 +17,11 @@ //! Key related CLI utilities -use sc_cli::{Error, substrate_cli_subcommands}; +use crate::{Error, substrate_cli_subcommands}; use structopt::StructOpt; -use frame_utils::{HashFor, SignedExtensionProvider}; use serde::{de::DeserializeOwned, Serialize}; -use crate::{ +use super::{ insert::InsertCmd, inspect::InspectCmd, generate::GenerateCmd, @@ -51,16 +50,15 @@ pub enum KeySubcommand { impl KeySubcommand { /// run the key subcommands - pub fn run

(&self) -> Result<(), Error> + pub fn run(&self) -> Result<(), Error> where - P: SignedExtensionProvider, - HashFor

: DeserializeOwned + Serialize + Send + Sync, + Hash: DeserializeOwned + Serialize + Send + Sync + 'static, { match self { KeySubcommand::GenerateNodeKey(cmd) => cmd.run(), KeySubcommand::Generate(cmd) => cmd.run(), KeySubcommand::InspectKey(cmd) => cmd.run(), - KeySubcommand::Insert(cmd) => cmd.run::

(), + KeySubcommand::Insert(cmd) => cmd.run::(), KeySubcommand::InspectNodeKey(cmd) => cmd.run(), } } diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 53f14f87bf802..f9b724b1abbaa 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -27,6 +27,13 @@ mod verify; mod vanity; mod revert_cmd; mod run_cmd; +mod generate_node_key; +mod generate; +mod insert; +mod inspect_node_key; +mod inspect; +mod key; +mod module_id; #[cfg(test)] pub mod tests; @@ -43,6 +50,13 @@ pub use self::{ import_blocks_cmd::ImportBlocksCmd, purge_chain_cmd::PurgeChainCmd, sign::SignCmd, + generate::GenerateCmd, + insert::InsertCmd, + inspect::InspectCmd, + generate_node_key::GenerateNodeKeyCmd, + inspect_node_key::InspectNodeKeyCmd, + key::KeySubcommand, + module_id::ModuleIdCmd, vanity::VanityCmd, verify::VerifyCmd, revert_cmd::RevertCmd, diff --git a/utils/frame/frame-utilities-cli/src/module_id.rs b/client/cli/src/commands/module_id.rs similarity index 98% rename from utils/frame/frame-utilities-cli/src/module_id.rs rename to client/cli/src/commands/module_id.rs index ea6e4758f6e3b..ea3234e65afa0 100644 --- a/utils/frame/frame-utilities-cli/src/module_id.rs +++ b/client/cli/src/commands/module_id.rs @@ -17,7 +17,7 @@ //! Implementation of the `moduleid` subcommand -use sc_cli::{ +use crate::{ Error, SharedParams, print_from_uri, CryptoSchemeFlag, OutputTypeFlag, KeystoreParams, CliConfiguration, with_crypto_scheme, }; @@ -66,6 +66,7 @@ pub struct ModuleIdCmd { } impl ModuleIdCmd { + /// runs the command pub fn run(&self) -> Result<(), Error> { if self.id.len() != 8 { Err("a module id must be a string of 8 characters")? diff --git a/utils/frame-utils/src/lib.rs b/frame/system/src/extras.rs similarity index 55% rename from utils/frame-utils/src/lib.rs rename to frame/system/src/extras.rs index da42c34bf2e9f..46a46ef4bacf6 100644 --- a/utils/frame-utils/src/lib.rs +++ b/frame/system/src/extras.rs @@ -1,40 +1,32 @@ +// Copyright 2018-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. -// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. -//! FRAME utilities +//! Strongly typed interface for SignedExtensions //! -#![cfg_attr(not(feature = "std"), no_std)] use sp_runtime::traits::{StaticLookup, SignedExtension}; -pub use pallet_balances::Call as BalancesCall; use sp_runtime::generic::Era; /// AccountIndex type for Runtime -pub type IndexFor = ::Index; -/// Balance type -pub type BalanceFor = ::Balance; +pub type IndexFor = ::Index; /// Call type for Runtime -pub type CallFor = ::Call; +pub type CallFor = ::Call; /// Address type for runtime. -pub type AddressFor = <::Lookup as StaticLookup>::Source; +pub type AddressFor = <::Lookup as StaticLookup>::Source; /// Hash for runtime. -pub type HashFor = ::Hash; +pub type HashFor = ::Hash; /// AccountId type for runtime. -pub type AccountIdFor = ::AccountId; +pub type AccountIdFor = ::AccountId; /// /// Strongly typed interface for the `SignedExtensions` that should be included in extrinsics @@ -42,13 +34,23 @@ pub type AccountIdFor = ::AccountId; /// /// ```rust,ignore /// use runtime::{Runtime, SignedExtra}; -/// use frame_utils::IndexFor; -/// use sp_runtime::generic; +/// use frame_system::extras::IndexFor; +/// +/// #[derive(Default)] +/// struct ExtraParams { +/// +/// } /// /// impl RuntimeAdapter for Runtime { /// type Extra = SignedExtra; /// -/// fn construct_extras(index: IndexFor) -> Self::Extra { +/// type Params = ExtraParams; +/// +/// fn extension_params() -> Self::Params { +/// Default::default() +/// } +/// +/// fn construct_extras(params: ExtraParams) -> Result, &'static str> { /// // take the biggest period possible. /// let period = BlockHashCount::get() /// .checked_next_power_of_two() @@ -73,7 +75,7 @@ pub type AccountIdFor = ::AccountId; /// /// ``` /// -pub trait SignedExtensionProvider: frame_system::Trait { +pub trait SignedExtensionProvider: crate::Trait { /// Concrete SignedExtension type. type Extra: SignedExtension; /// Concrete type for params used to construct the `SignedExtension`-Data @@ -83,18 +85,21 @@ pub trait SignedExtensionProvider: frame_system::Trait { fn extension_params() -> Self::Params; /// construct extras and optionally additional_signed data for inclusion in extrinsics. - fn construct_extras(input: Self::Params) -> Result< - ( - Self::Extra, - Option<::AdditionalSigned> - ), - &'static str - >; + fn construct_extras(input: Self::Params) -> Result, &'static str>; +} + +/// extras that should be included in extrinsics, +/// additional data is provided for call sites that don't have access to storage. +pub struct SignedExtensionData { + /// signed extras + pub extra: S, + /// additional data for the signed extras. + pub additional: Option, } /// used internally by substrate to set extras for inclusion in /// `SignedExtensionProvider` -pub trait SystemExtraParams { +pub trait SystemExtraParams { /// sets the nonce fn set_nonce(&mut self, index: T::Index); /// sets the nonce diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index e9e45d0c4f8a8..fd0c05a90d7e5 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -137,6 +137,7 @@ use codec::{Encode, Decode, FullCodec, EncodeLike}; use sp_io::TestExternalities; pub mod offchain; +pub mod extras; /// Compute the trie root of a list of extrinsics. pub fn extrinsics_root(extrinsics: &[E]) -> H::Output { diff --git a/test-utils/runtime/Cargo.toml b/test-utils/runtime/Cargo.toml index 7fe19334fbd1b..21c269736d765 100644 --- a/test-utils/runtime/Cargo.toml +++ b/test-utils/runtime/Cargo.toml @@ -43,7 +43,6 @@ sp-transaction-pool = { version = "2.0.0-rc3", default-features = false, path = trie-db = { version = "0.20.1", default-features = false } parity-util-mem = { version = "0.6.1", default-features = false, features = ["primitive-types"] } sc-service = { version = "0.8.0-rc3", default-features = false, optional = true, features = ["test-helpers"], path = "../../client/service" } -frame-utils = { version = "2.0.0-rc3", default-features = false, path = "../../utils/frame-utils" } # 3rd party cfg-if = "0.1.10" diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index c8b14b406fa81..77699a8844e0d 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -55,9 +55,8 @@ use cfg_if::cfg_if; // Ensure Babe and Aura use the same crypto to simplify things a bit. pub use sp_consensus_babe::{AuthorityId, SlotNumber, AllowedSlots}; -use frame_utils::{SignedExtensionProvider, SystemExtraParams}; +use frame_system::extras::{SignedExtensionProvider, SystemExtraParams, SignedExtensionData}; use sp_runtime::generic::Era; -use sp_runtime::traits::SignedExtension; use frame_system::Trait; pub type AuraId = sp_consensus_aura::sr25519::AuthorityId; @@ -452,21 +451,15 @@ impl SignedExtensionProvider for Runtime { ExtrasParams { era: Era::Immortal } } - fn construct_extras(params: Self::Params) -> Result< - ( - Self::Extra, - Option<::AdditionalSigned> - ), - &'static str - > { - let data = ( - ( + fn construct_extras(params: Self::Params) -> Result, &'static str> { + let data = SignedExtensionData { + extra: ( frame_system::CheckTxVersion::new(), frame_system::CheckGenesis::new(), frame_system::CheckEra::from(params.era) ), - None - ); + additional: None + }; Ok(data) } } diff --git a/utils/frame-utils/Cargo.toml b/utils/frame-utils/Cargo.toml deleted file mode 100644 index 6f3272162b5e2..0000000000000 --- a/utils/frame-utils/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "frame-utils" -version = "2.0.0-rc3" -authors = ["Parity Technologies "] -edition = "2018" -license = "GPL-3.0" -homepage = "https://substrate.dev" -repository = "https://github.com/paritytech/substrate/" -description = "CLI utils" -documentation = "https://docs.rs/frame-utils" - -[dependencies] -frame-system = { version = "2.0.0-alpha.7", default-features = false, path = "../../frame/system" } -pallet-balances = { version = "2.0.0-alpha.7", default-features = false, path = "../../frame/balances" } -sp-runtime = { version = "2.0.0-alpha.7", default-features = false, path = "../../primitives/runtime" } -sp-core = { version = "2.0.0-alpha.7", default-features = false, path = "../../primitives/core" } -codec = { version = "1.3.0", default-features = false, package = "parity-scale-codec" } - -[features] -default = ["std"] -std = [ - "frame-system/std", - "pallet-balances/std", - "sp-runtime/std", - "sp-core/std", -] diff --git a/utils/frame/frame-utilities-cli/Cargo.toml b/utils/frame/frame-utilities-cli/Cargo.toml index 31f2e8b663618..311c22fd8ef51 100644 --- a/utils/frame/frame-utilities-cli/Cargo.toml +++ b/utils/frame/frame-utilities-cli/Cargo.toml @@ -1,13 +1,13 @@ [package] -name = "substrate-frame-utilities-cli" +name = "substrate-frame-cli" version = "2.0.0-rc3" authors = ["Parity Technologies "] edition = "2018" -license = "GPL-3.0" +license = "Apache-2.0" homepage = "https://substrate.dev" repository = "https://github.com/paritytech/substrate/" -description = "CLI utils" -documentation = "https://docs.rs/frame-utils" +description = "cli interface for FRAME" +documentation = "https://docs.rs/substrate-frame-cli" [dependencies] sp-core = { version = "2.0.0-rc3", path = "../../../primitives/core" } @@ -15,9 +15,6 @@ sc-cli = { version = "0.8.0-rc3", path = "../../../client/cli" } sp-runtime = { version = "2.0.0-rc3", path = "../../../primitives/runtime" } structopt = "0.3.8" codec = { version = "1.3.0", package = "parity-scale-codec" } -pallet-balances = { version = "2.0.0-rc3", path = "../../../frame/balances" } -pallet-indices = { version = "2.0.0-rc3", path = "../../../frame/indices" } -frame-utils = { path = "../../frame-utils", version = "2.0.0-rc3" } hex = "0.4.2" serde = "1.0.106" hyper = "0.12.35" @@ -29,6 +26,11 @@ sc-service = { version = "0.8.0-rc3", default-features = false, path = "../../.. sc-client-api = { version = "2.0.0-rc3", default-features = false, path = "../../../client/api" } futures01 = { package = "futures", version = "0.1.29" } futures = "0.3" +frame-system = { version = "2.0.0-rc3", path = "../../../frame/system" } + +# optional deps +pallet-balances = { version = "2.0.0-rc3", optional = true, path = "../../../frame/balances" } +pallet-indices = { version = "2.0.0-rc3", optional = true, path = "../../../frame/indices" } [dev-dependencies] tempfile = "3.1.0" @@ -37,5 +39,4 @@ frame-system = { version = "2.0.0-rc3", path = "../../../frame/system" } [features] default = [] -balances = ["pallet-balances"] -indices = ["pallet-indices"] +balances = ["pallet-balances", "pallet-indices"] diff --git a/utils/frame/frame-utilities-cli/src/lib.rs b/utils/frame/frame-utilities-cli/src/lib.rs index d86ef699a98fc..93f7c17331a24 100644 --- a/utils/frame/frame-utilities-cli/src/lib.rs +++ b/utils/frame/frame-utilities-cli/src/lib.rs @@ -17,67 +17,12 @@ //! frame-system CLI utilities -mod generate; -mod generate_node_key; -mod insert; -mod inspect; -mod inspect_node_key; -mod module_id; -mod key; mod utils; mod sign_transaction; + #[cfg(feature = "balances")] mod transfer; #[cfg(feature = "balances")] pub use transfer::TransferCmd; +pub use sign_transaction::SignTransactionCmd; -pub use { - key::KeySubcommand, - module_id::ModuleIdCmd, - generate::GenerateCmd, - insert::InsertCmd, - inspect::InspectCmd, - inspect_node_key::InspectNodeKeyCmd, - sign_transaction::SignTransactionCmd, - generate_node_key::GenerateNodeKeyCmd, -}; - - -#[cfg(test)] -mod tests { - use super::{generate::GenerateCmd, generate_node_key::GenerateNodeKeyCmd, inspect::InspectCmd}; - use tempfile::Builder; - use structopt::StructOpt; - use std::io::Read; - - #[test] - fn generate() { - let generate = GenerateCmd::from_iter(&["generate", "--password", "12345"]); - assert!(generate.run().is_ok()) - } - - #[test] - fn generate_node_key() { - let mut file = Builder::new().prefix("keyfile").tempfile().unwrap(); - let generate = - GenerateNodeKeyCmd::from_iter(&["generate-node-key", "--file", "/tmp/keyfile"]); - assert!(generate.run().is_ok()); - let mut buf = String::new(); - assert!(file.read_to_string(&mut buf).is_ok()); - assert!(hex::decode(buf).is_ok()); - } - - #[test] - fn inspect() { - let words = - "remember fiber forum demise paper uniform squirrel feel access exclude casual effort"; - let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; - - let inspect = - InspectCmd::from_iter(&["inspect-key", "--uri", words, "--password", "12345"]); - assert!(inspect.run().is_ok()); - - let inspect = InspectCmd::from_iter(&["inspect-key", "--uri", seed]); - assert!(inspect.run().is_ok()); - } -} diff --git a/utils/frame/frame-utilities-cli/src/sign_transaction.rs b/utils/frame/frame-utilities-cli/src/sign_transaction.rs index 03e29371e0453..17d65fc9f77d2 100644 --- a/utils/frame/frame-utilities-cli/src/sign_transaction.rs +++ b/utils/frame/frame-utilities-cli/src/sign_transaction.rs @@ -25,7 +25,7 @@ use structopt::StructOpt; use codec::{Codec, Encode, Decode}; use std::{str::FromStr, fmt::Debug}; use sp_runtime::{MultiSigner, MultiSignature, AccountId32}; -use frame_utils::{SignedExtensionProvider, IndexFor, CallFor, AccountIdFor, AddressFor}; +use frame_system::extras::{SignedExtensionProvider, IndexFor, CallFor, AccountIdFor, AddressFor}; use crate::utils::create_extrinsic_for; use sp_core::hexdisplay::HexDisplay; diff --git a/utils/frame/frame-utilities-cli/src/transfer.rs b/utils/frame/frame-utilities-cli/src/transfer.rs index 3f2ce917e6718..5a28a652e8c68 100644 --- a/utils/frame/frame-utilities-cli/src/transfer.rs +++ b/utils/frame/frame-utilities-cli/src/transfer.rs @@ -28,14 +28,18 @@ use codec::{Encode, Decode}; use sp_runtime::{MultiSigner, MultiSignature, AccountId32}; use std::convert::TryFrom; use sp_core::{crypto::Ss58Codec, hexdisplay::HexDisplay}; -use frame_utils::{ - AddressFor, IndexFor, BalanceFor, BalancesCall, AccountIdFor, +use frame_system::extras::{ + AddressFor, IndexFor, AccountIdFor, SignedExtensionProvider, CallFor, }; +use pallet_balances::Call as BalancesCall; use crate::utils::create_extrinsic_for; type Bytes = Vec; +/// Balance type +type BalanceFor = ::Balance; + /// The `transfer` command #[derive(Debug, StructOpt)] #[structopt( @@ -100,7 +104,6 @@ impl TransferCmd { }; let amount = self.amount.parse::>()?; let prior_block_hash = ::decode(&mut &self.prior_block_hash[..])?; - println!("Scheme {}", self.crypto_scheme.scheme); with_crypto_scheme!( self.crypto_scheme.scheme, @@ -147,6 +150,6 @@ fn print_ext( let signer = pair_from_suri::(uri, pass); let call: CallFor

= BalancesCall::transfer(to, amount).into(); let extrinsic = create_extrinsic_for::(call, nonce, signer, prior_block_hash)?; - println!("0x{}", HexDisplay::from(&extrinsic.encode())); + println!("extrinsic: 0x{}", HexDisplay::from(&extrinsic.encode())); Ok(()) } diff --git a/utils/frame/frame-utilities-cli/src/utils.rs b/utils/frame/frame-utilities-cli/src/utils.rs index 5d8d499eead39..049613c235315 100644 --- a/utils/frame/frame-utilities-cli/src/utils.rs +++ b/utils/frame/frame-utilities-cli/src/utils.rs @@ -20,7 +20,10 @@ use sp_runtime::{ MultiSigner, AccountId32, traits::IdentifyAccount, MultiSignature, }; use codec::Encode; -use frame_utils::{SignedExtensionProvider, SystemExtraParams, IndexFor, AddressFor, AccountIdFor}; +use frame_system::extras::{ + SignedExtensionProvider, SystemExtraParams, + IndexFor, AddressFor, AccountIdFor, SignedExtensionData, +}; use sp_runtime::generic::Era; /// create an extrinsic for the runtime. @@ -46,7 +49,7 @@ pub fn create_extrinsic_for( input.set_nonce(nonce); input.set_era(Era::Immortal); input.set_prior_block_hash(hash); - let (extra, additional) = P::construct_extras(input)?; + let SignedExtensionData { extra, additional } = P::construct_extras(input)?; let payload = if let Some(additional_signed) = additional { SignedPayload::from_raw(call, extra, additional_signed) From c6831814325afd86f4781185527b42d0f89ed5c6 Mon Sep 17 00:00:00 2001 From: Seun Date: Thu, 11 Jun 2020 13:45:23 +0100 Subject: [PATCH 58/77] removes unneccesary generic params --- bin/node/runtime/src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 6e4e9b7d922e4..d803a035545d9 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -629,15 +629,15 @@ parameter_types! { } #[derive(Default)] -pub struct ExtrasParams { +pub struct ExtrasParams { era: Option, - index: Option, + index: Option, tip: u128, - prior_block_hash: Option, + prior_block_hash: Option, } -impl SystemExtraParams for ExtrasParams { - fn set_nonce(&mut self, index: ::Index) { +impl SystemExtraParams for ExtrasParams { + fn set_nonce(&mut self, index: Index) { self.index = Some(index); } @@ -645,7 +645,7 @@ impl SystemExtraParams for ExtrasParams { self.era = Some(era); } - fn set_prior_block_hash(&mut self, hash: ::Hash) { + fn set_prior_block_hash(&mut self, hash: Hash) { self.prior_block_hash = Some(hash); } } @@ -653,9 +653,9 @@ impl SystemExtraParams for ExtrasParams { impl SignedExtensionProvider for Runtime { type Extra = SignedExtra; - type Params = ExtrasParams; + type Params = ExtrasParams; - fn extension_params() -> ExtrasParams { + fn extension_params() -> ExtrasParams { ExtrasParams { prior_block_hash: None, index: None, @@ -664,7 +664,7 @@ impl SignedExtensionProvider for Runtime { } } - fn construct_extras(params: ExtrasParams) -> Result, &'static str> { + fn construct_extras(params: ExtrasParams) -> Result, &'static str> { let ExtrasParams { tip, era, From a1535f69a1ed2636e29df648c4a936d21b374262 Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 15 Jun 2020 13:29:02 +0100 Subject: [PATCH 59/77] moves module_id back to frame_utilities_cli --- bin/node/cli/src/cli.rs | 6 +++--- bin/utils/subkey/src/main.rs | 6 +++--- client/cli/src/commands/mod.rs | 2 -- utils/frame/frame-utilities-cli/src/lib.rs | 3 +++ .../frame/frame-utilities-cli/src}/module_id.rs | 12 ++++++++---- 5 files changed, 17 insertions(+), 12 deletions(-) rename {client/cli/src/commands => utils/frame/frame-utilities-cli/src}/module_id.rs (91%) diff --git a/bin/node/cli/src/cli.rs b/bin/node/cli/src/cli.rs index a5d48b35b31f2..b16400e903fc9 100644 --- a/bin/node/cli/src/cli.rs +++ b/bin/node/cli/src/cli.rs @@ -38,13 +38,13 @@ pub enum Subcommand { #[structopt(flatten)] Base(sc_cli::Subcommand), - /// prints hex-encoded, signed, transfer extrinsic with given arguments. + /// Prints hex-encoded, signed, transfer extrinsic with given arguments. Transfer(TransferCmd), - /// key utilities + /// Key management cli utilities Key(KeySubcommand), - /// sign transaction + /// Sign transaction SignTransaction(SignTransactionCmd), /// The custom inspect subcommmand for decoding blocks and extrinsics. diff --git a/bin/utils/subkey/src/main.rs b/bin/utils/subkey/src/main.rs index becfd44dbda8e..2c4d018991fe6 100644 --- a/bin/utils/subkey/src/main.rs +++ b/bin/utils/subkey/src/main.rs @@ -18,10 +18,10 @@ use structopt::StructOpt; use sc_cli::{ - Error, VanityCmd, SignCmd, VerifyCmd, ModuleIdCmd, InsertCmd, + Error, VanityCmd, SignCmd, VerifyCmd, InsertCmd, GenerateNodeKeyCmd, GenerateCmd, InspectCmd, InspectNodeKeyCmd }; -use substrate_frame_cli::{TransferCmd, SignTransactionCmd}; +use substrate_frame_cli::{TransferCmd, SignTransactionCmd, ModuleIdCmd}; use node_runtime::Runtime; use frame_system::extras::HashFor; @@ -74,7 +74,7 @@ fn main() -> Result<(), Error> { Subkey::InspectKey(cmd) => cmd.run()?, Subkey::InspectNodeKey(cmd) => cmd.run()?, Subkey::Insert(cmd) => cmd.run::>()?, - Subkey::ModuleId(cmd) => cmd.run()?, + Subkey::ModuleId(cmd) => cmd.run::()?, Subkey::Transfer(cmd) => cmd.run::()?, Subkey::Vanity(cmd) => cmd.run()?, Subkey::Verify(cmd) => cmd.run()?, diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index f9b724b1abbaa..5397c9e7362f7 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -33,7 +33,6 @@ mod insert; mod inspect_node_key; mod inspect; mod key; -mod module_id; #[cfg(test)] pub mod tests; @@ -56,7 +55,6 @@ pub use self::{ generate_node_key::GenerateNodeKeyCmd, inspect_node_key::InspectNodeKeyCmd, key::KeySubcommand, - module_id::ModuleIdCmd, vanity::VanityCmd, verify::VerifyCmd, revert_cmd::RevertCmd, diff --git a/utils/frame/frame-utilities-cli/src/lib.rs b/utils/frame/frame-utilities-cli/src/lib.rs index 93f7c17331a24..3f9c3f8f7df51 100644 --- a/utils/frame/frame-utilities-cli/src/lib.rs +++ b/utils/frame/frame-utilities-cli/src/lib.rs @@ -18,11 +18,14 @@ //! frame-system CLI utilities mod utils; +mod module_id; mod sign_transaction; #[cfg(feature = "balances")] mod transfer; #[cfg(feature = "balances")] pub use transfer::TransferCmd; + pub use sign_transaction::SignTransactionCmd; +pub use module_id::ModuleIdCmd; diff --git a/client/cli/src/commands/module_id.rs b/utils/frame/frame-utilities-cli/src/module_id.rs similarity index 91% rename from client/cli/src/commands/module_id.rs rename to utils/frame/frame-utilities-cli/src/module_id.rs index ea3234e65afa0..3805b346d1388 100644 --- a/client/cli/src/commands/module_id.rs +++ b/utils/frame/frame-utilities-cli/src/module_id.rs @@ -17,13 +17,13 @@ //! Implementation of the `moduleid` subcommand -use crate::{ +use sc_cli::{ Error, SharedParams, print_from_uri, CryptoSchemeFlag, OutputTypeFlag, KeystoreParams, CliConfiguration, with_crypto_scheme, }; use sp_runtime::ModuleId; use sp_runtime::traits::AccountIdConversion; -use sp_core::crypto::{AccountId32, Ss58Codec, Ss58AddressFormat}; +use sp_core::crypto::{Ss58Codec, Ss58AddressFormat}; use std::convert::{TryInto, TryFrom}; use structopt::StructOpt; @@ -67,7 +67,11 @@ pub struct ModuleIdCmd { impl ModuleIdCmd { /// runs the command - pub fn run(&self) -> Result<(), Error> { + pub fn run(&self) -> Result<(), Error> + where + R: frame_system::Trait, + R::AccountId: Ss58Codec, + { if self.id.len() != 8 { Err("a module id must be a string of 8 characters")? } @@ -77,7 +81,7 @@ impl ModuleIdCmd { .try_into() .map_err(|_| "Cannot convert argument to moduleid: argument should be 8-character string")?; - let account_id: AccountId32 = ModuleId(id_fixed_array).into_account(); + let account_id: R::AccountId = ModuleId(id_fixed_array).into_account(); let network = self.network; with_crypto_scheme!( From 655e53ac0af2982947a1dc3d9559054847d0ee96 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Mon, 15 Jun 2020 13:29:12 +0100 Subject: [PATCH 60/77] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Benjamin Kampmann Co-authored-by: Bastian Köcher --- bin/node/runtime/src/lib.rs | 8 ++++---- client/cli/src/commands/mod.rs | 2 +- client/cli/src/commands/utils.rs | 2 +- primitives/core/src/crypto.rs | 4 ++-- utils/frame/frame-utilities-cli/src/sign_transaction.rs | 2 +- utils/frame/frame-utilities-cli/src/utils.rs | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index d803a035545d9..21433f94c37c4 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -631,13 +631,13 @@ parameter_types! { #[derive(Default)] pub struct ExtrasParams { era: Option, - index: Option, + index: Option, tip: u128, - prior_block_hash: Option, + prior_block_hash: Option, } impl SystemExtraParams for ExtrasParams { - fn set_nonce(&mut self, index: Index) { + fn set_nonce(&mut self, index: Runtime::Index) { self.index = Some(index); } @@ -645,7 +645,7 @@ impl SystemExtraParams for ExtrasParams { self.era = Some(era); } - fn set_prior_block_hash(&mut self, hash: Hash) { + fn set_prior_block_hash(&mut self, hash: Runtime::Hash) { self.prior_block_hash = Some(hash); } } diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index f9b724b1abbaa..c554ab33b793b 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -61,7 +61,7 @@ pub use self::{ verify::VerifyCmd, revert_cmd::RevertCmd, run_cmd::RunCmd, - utils::* + utils::*, }; /// All core commands that are provided by default. diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 8fc9e3698133c..d5f9e63e51bcd 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -34,7 +34,7 @@ pub type SeedFor

=

::Seed; /// helper method to fetch uri from `Option` either as a file or read from stdin pub fn read_uri(uri: Option<&String>) -> error::Result { let uri = if let Some(uri) = uri { - let file = PathBuf::from(uri.clone()); + let file = PathBuf::from(&uri); if file.is_file() { std::fs::read_to_string(uri)? .trim_end() diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 6d5cba87248d6..7d2b494bfbf49 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -377,8 +377,8 @@ macro_rules! ss58_address_format { impl Ss58AddressFormat { /// names of all address formats - pub fn all_names() -> [&'static str; 0 $(+ { let _ = $number; 1})*] { - [ + pub fn all_names() -> &[&'static str] { + &[ $($name),*, ] } diff --git a/utils/frame/frame-utilities-cli/src/sign_transaction.rs b/utils/frame/frame-utilities-cli/src/sign_transaction.rs index 17d65fc9f77d2..977e93932159f 100644 --- a/utils/frame/frame-utilities-cli/src/sign_transaction.rs +++ b/utils/frame/frame-utilities-cli/src/sign_transaction.rs @@ -107,7 +107,7 @@ fn print_ext( pass: Option<&str>, call: CallFor

, nonce: IndexFor

, - hash: P::Hash + hash: P::Hash, ) -> Result<(), Error> where Pair: sp_core::Pair, diff --git a/utils/frame/frame-utilities-cli/src/utils.rs b/utils/frame/frame-utilities-cli/src/utils.rs index 049613c235315..826efa1356d46 100644 --- a/utils/frame/frame-utilities-cli/src/utils.rs +++ b/utils/frame/frame-utilities-cli/src/utils.rs @@ -29,7 +29,7 @@ use sp_runtime::generic::Era; /// create an extrinsic for the runtime. pub fn create_extrinsic_for( call: Call, - nonce: IndexFor

, + nonce: IndexFor

, pair: Pair, hash: P::Hash, ) -> Result< From 974ef0a4d68cc1e79c093fb57238993a00c6004a Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 15 Jun 2020 13:47:59 +0100 Subject: [PATCH 61/77] remove print_ext --- client/cli/src/commands/utils.rs | 2 +- .../src/sign_transaction.rs | 44 ++++--------- .../frame/frame-utilities-cli/src/transfer.rs | 64 ++++++------------- utils/frame/frame-utilities-cli/src/utils.rs | 9 ++- 4 files changed, 42 insertions(+), 77 deletions(-) diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 8fc9e3698133c..86b0dd2878f3b 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -206,7 +206,7 @@ macro_rules! with_crypto_scheme { ($scheme:expr, $method:ident($($params:expr),*)) => { with_crypto_scheme!($scheme, $method<>($($params),*)) }; - ($scheme:expr, $method:ident<$($generics:ident),*>($($params:expr),*)) => { + ($scheme:expr, $method:ident<$($generics:ty),*>($($params:expr),*)) => { match $scheme { $crate::CryptoScheme::Ecdsa => { $method::($($params),*) diff --git a/utils/frame/frame-utilities-cli/src/sign_transaction.rs b/utils/frame/frame-utilities-cli/src/sign_transaction.rs index 17d65fc9f77d2..750926ad2dfbf 100644 --- a/utils/frame/frame-utilities-cli/src/sign_transaction.rs +++ b/utils/frame/frame-utilities-cli/src/sign_transaction.rs @@ -17,14 +17,13 @@ //! Implementation of the `sign-transaction` subcommand use sc_cli::{ - Error, CliConfiguration, KeystoreParams, SharedParams, - pair_from_suri, decode_hex, with_crypto_scheme, - CryptoSchemeFlag, GenericNumber, + Error, CliConfiguration, KeystoreParams, SharedParams, decode_hex, + with_crypto_scheme, CryptoSchemeFlag, GenericNumber, }; use structopt::StructOpt; use codec::{Codec, Encode, Decode}; use std::{str::FromStr, fmt::Debug}; -use sp_runtime::{MultiSigner, MultiSignature, AccountId32}; +use sp_runtime::AccountId32; use frame_system::extras::{SignedExtensionProvider, IndexFor, CallFor, AccountIdFor, AddressFor}; use crate::utils::create_extrinsic_for; use sp_core::hexdisplay::HexDisplay; @@ -83,10 +82,18 @@ impl SignTransactionCmd { let call = CallFor::

::decode(&mut &self.call[..])?; let password = self.keystore_params.read_password()?; - with_crypto_scheme!( + let extrinsic = with_crypto_scheme!( self.crypto_scheme.scheme, - print_ext

(&self.suri, password.as_ref().map(String::as_str), call, nonce, hash) - ) + create_extrinsic_for( + &self.suri, + password.as_ref().map(String::as_str), + call, + nonce, + hash + ) + )?; + println!("0x{}", HexDisplay::from(&extrinsic.encode())); + Ok(()) } } @@ -100,26 +107,3 @@ impl CliConfiguration for SignTransactionCmd { Some(&self.keystore_params) } } - - -fn print_ext( - uri: &str, - pass: Option<&str>, - call: CallFor

, - nonce: IndexFor

, - hash: P::Hash -) -> Result<(), Error> - where - Pair: sp_core::Pair, - Pair::Public: Into, - Pair::Signature: Into, - P: SignedExtensionProvider + pallet_indices::Trait, - AccountIdFor

: From, - AddressFor

: From>, - CallFor

: Codec, -{ - let signer = pair_from_suri::(uri, pass); - let extrinsic = create_extrinsic_for::(call, nonce, signer, hash)?; - println!("0x{}", HexDisplay::from(&extrinsic.encode())); - Ok(()) -} diff --git a/utils/frame/frame-utilities-cli/src/transfer.rs b/utils/frame/frame-utilities-cli/src/transfer.rs index 5a28a652e8c68..d5009bde5a9b3 100644 --- a/utils/frame/frame-utilities-cli/src/transfer.rs +++ b/utils/frame/frame-utilities-cli/src/transfer.rs @@ -18,20 +18,16 @@ //! Implementation of the `transfer` cli subcommand for nodes that use the pallet-balances crate. use sc_cli::{ - Error, SharedParams, pair_from_suri, with_crypto_scheme, - CryptoSchemeFlag, decode_hex, CliConfiguration, KeystoreParams, - GenericNumber, + Error, SharedParams, with_crypto_scheme, CryptoSchemeFlag, decode_hex, + CliConfiguration, KeystoreParams, GenericNumber, }; use structopt::StructOpt; use std::{str::FromStr, fmt::Debug}; use codec::{Encode, Decode}; -use sp_runtime::{MultiSigner, MultiSignature, AccountId32}; +use sp_runtime::AccountId32; use std::convert::TryFrom; use sp_core::{crypto::Ss58Codec, hexdisplay::HexDisplay}; -use frame_system::extras::{ - AddressFor, IndexFor, AccountIdFor, - SignedExtensionProvider, CallFor, -}; +use frame_system::extras::{AddressFor, IndexFor, AccountIdFor, SignedExtensionProvider, CallFor}; use pallet_balances::Call as BalancesCall; use crate::utils::create_extrinsic_for; @@ -94,6 +90,7 @@ impl TransferCmd { BalancesCall: Encode, { let password = self.keystore_params.read_password()?; + let pass = password.as_ref().map(String::as_str); let nonce = self.index.parse::>()?; let to = if let Ok(data_vec) = decode_hex(&self.to) { AccountIdFor::::try_from(&data_vec) @@ -102,20 +99,26 @@ impl TransferCmd { AccountIdFor::::from_ss58check(&self.to) .map_err(|_| "Invalid SS58-check address given for account ID.")? }; + let amount = self.amount.parse::>()?; let prior_block_hash = ::decode(&mut &self.prior_block_hash[..])?; - with_crypto_scheme!( + let call: CallFor = BalancesCall::transfer(to.into(), amount).into(); + + let extrinsic = with_crypto_scheme!( self.crypto_scheme.scheme, - print_ext( - &self.from, - password.as_ref().map(String::as_str), - to.into(), - nonce, - amount, - prior_block_hash - ) - ) + create_extrinsic_for( + &self.from, + pass, + call, + nonce, + prior_block_hash + ) + )?; + + println!("extrinsic: 0x{}", HexDisplay::from(&extrinsic.encode())); + + Ok(()) } } @@ -128,28 +131,3 @@ impl CliConfiguration for TransferCmd { Some(&self.keystore_params) } } - -fn print_ext( - uri: &str, - pass: Option<&str>, - to: AddressFor

, - nonce: IndexFor

, - amount: BalanceFor

, - prior_block_hash: P::Hash -) -> Result<(), Error> - where - Pair: sp_core::Pair, - Pair::Public: Into, - Pair::Signature: Into, - BalancesCall

: Encode, - AccountIdFor

: From, - AddressFor

: From>, - CallFor

: Encode + From>, - P: pallet_balances::Trait + pallet_indices::Trait + SignedExtensionProvider, -{ - let signer = pair_from_suri::(uri, pass); - let call: CallFor

= BalancesCall::transfer(to, amount).into(); - let extrinsic = create_extrinsic_for::(call, nonce, signer, prior_block_hash)?; - println!("extrinsic: 0x{}", HexDisplay::from(&extrinsic.encode())); - Ok(()) -} diff --git a/utils/frame/frame-utilities-cli/src/utils.rs b/utils/frame/frame-utilities-cli/src/utils.rs index 049613c235315..21e63f166ea09 100644 --- a/utils/frame/frame-utilities-cli/src/utils.rs +++ b/utils/frame/frame-utilities-cli/src/utils.rs @@ -25,12 +25,14 @@ use frame_system::extras::{ IndexFor, AddressFor, AccountIdFor, SignedExtensionData, }; use sp_runtime::generic::Era; +use sc_cli::pair_from_suri; /// create an extrinsic for the runtime. pub fn create_extrinsic_for( + uri: &str, + pass: Option<&str>, call: Call, nonce: IndexFor

, - pair: Pair, hash: P::Hash, ) -> Result< UncheckedExtrinsic, Call, MultiSignature, P::Extra>, @@ -45,6 +47,7 @@ pub fn create_extrinsic_for( AccountIdFor

: From, AddressFor

: From>, { + let pair = pair_from_suri::(uri, pass); let mut input = P::extension_params(); input.set_nonce(nonce); input.set_era(Era::Immortal); @@ -58,8 +61,8 @@ pub fn create_extrinsic_for( .map_err(|_| "Transaction validity error")? }; - let signer = pair.public().into().into_account(); - let account_id: AccountIdFor

= From::from(signer.clone()); + let account_public = pair.public().into().into_account(); + let account_id: AccountIdFor

= From::from(account_public.clone()); let address = AddressFor::

::from(account_id); let signature = payload.using_encoded(|payload| pair.sign(payload).into()); From 86f149aa5f3c166f88f6ddfab0e2f0c3be35c0fe Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 15 Jun 2020 14:10:53 +0100 Subject: [PATCH 62/77] remove MaybeDisplay from pallet_balances::Trait::Balance --- frame/balances/src/lib.rs | 6 +++--- primitives/core/src/crypto.rs | 2 +- utils/frame/frame-utilities-cli/src/transfer.rs | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index 7e8caba441cbc..c1636bb4ec051 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -171,7 +171,7 @@ use sp_runtime::{ RuntimeDebug, DispatchResult, DispatchError, traits::{ Zero, AtLeast32Bit, StaticLookup, Member, CheckedAdd, CheckedSub, - MaybeSerializeDeserialize, MaybeFromStr, Saturating, Bounded, + MaybeSerializeDeserialize, Saturating, Bounded, }, }; use frame_system::{self as system, ensure_signed, ensure_root}; @@ -180,7 +180,7 @@ pub use self::imbalances::{PositiveImbalance, NegativeImbalance}; pub trait Subtrait: frame_system::Trait { /// The balance of an account. type Balance: Parameter + Member + AtLeast32Bit + Codec + Default + Copy + - MaybeSerializeDeserialize + MaybeFromStr + Debug; + MaybeSerializeDeserialize + Debug; /// The minimum amount required to keep an account open. type ExistentialDeposit: Get; @@ -192,7 +192,7 @@ pub trait Subtrait: frame_system::Trait { pub trait Trait: frame_system::Trait { /// The balance of an account. type Balance: Parameter + Member + AtLeast32Bit + Codec + Default + Copy + - MaybeSerializeDeserialize + MaybeFromStr + Debug; + MaybeSerializeDeserialize + Debug; /// Handler for the unbalanced reduction when removing a dust account. type DustRemoval: OnUnbalanced>; diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 2f42b4517abae..6761030c28f24 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -356,7 +356,7 @@ lazy_static::lazy_static! { macro_rules! ss58_address_format { ( $( $identifier:tt => ($number:expr, $name:expr, $desc:tt) )* ) => ( /// A known address (sub)format/network ID for SS58. - #[derive(Copy, Clone, PartialEq, Eq, RuntimeDebug)] + #[derive(Copy, Clone, PartialEq, Eq, crate::RuntimeDebug)] pub enum Ss58AddressFormat { $(#[doc = $desc] $identifier),*, /// Use a manually provided numeric value. diff --git a/utils/frame/frame-utilities-cli/src/transfer.rs b/utils/frame/frame-utilities-cli/src/transfer.rs index eadf6bef1dad7..0a5dd07f8d8bb 100644 --- a/utils/frame/frame-utilities-cli/src/transfer.rs +++ b/utils/frame/frame-utilities-cli/src/transfer.rs @@ -86,7 +86,8 @@ impl TransferCmd { R: pallet_balances::Trait + pallet_indices::Trait + SignedExtensionProvider, AccountIdFor: for<'a> TryFrom<&'a [u8], Error = ()> + Ss58Codec + From, AddressFor: From>, - as FromStr>::Err: Debug, + as FromStr>::Err: Debug, + BalanceFor: FromStr, as FromStr>::Err: Debug, CallFor: Encode + From>, BalancesCall: Encode, From e7f732be59f4671740f62c1acb0b1eff767ab9b1 Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 15 Jun 2020 14:51:40 +0100 Subject: [PATCH 63/77] a lot of stuff tbh --- bin/node/runtime/src/lib.rs | 11 +++++++++-- client/cli/src/commands/insert.rs | 8 ++++---- client/cli/src/commands/sign.rs | 2 +- client/cli/src/commands/utils.rs | 6 ++++-- frame/system/src/extras.rs | 10 ++++++---- test-utils/runtime/Cargo.toml | 1 - test-utils/runtime/src/lib.rs | 9 +++++---- utils/frame/frame-utilities-cli/src/utils.rs | 12 ++++++------ 8 files changed, 35 insertions(+), 24 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index fb970d14239d7..45681e36b05fe 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -645,9 +645,13 @@ impl SystemExtraParams for ExtrasParams { self.era = Some(era); } - fn set_prior_block_hash(&mut self, hash: ::Hash) { + fn set_starting_era_hash(&mut self, hash: ::Hash) { self.prior_block_hash = Some(hash); } + + fn set_genesis_hash(&mut self, _: ::Hash) { + todo!() + } } @@ -730,7 +734,10 @@ impl frame_system::offchain::CreateSignedTransaction for R input.set_era(era); let SignedExtensionData { extra, additional } = match Runtime::construct_extras(input) { Ok(d) => d, - Err(_) => return None, + Err(e) => { + debug::warn!("unable to construct extras: {}", e); + return None + } }; let raw_payload = if let Some(additional_signed) = additional { SignedPayload::from_raw(call, extra, additional_signed) diff --git a/client/cli/src/commands/insert.rs b/client/cli/src/commands/insert.rs index f444b9c8655d4..3829a2326cb7a 100644 --- a/client/cli/src/commands/insert.rs +++ b/client/cli/src/commands/insert.rs @@ -77,7 +77,7 @@ impl InsertCmd { let public = with_crypto_scheme!( self.crypto_scheme.scheme, to_vec(&suri, password.as_ref().map(String::as_str)) - ); + )?; let node_url = self.node_url.as_ref() .map(String::as_str) @@ -112,9 +112,9 @@ impl CliConfiguration for InsertCmd { } } -fn to_vec(uri: &str, pass: Option<&str>) -> Vec { - let p = pair_from_suri::

(uri, pass); - p.public().as_ref().to_vec() +fn to_vec(uri: &str, pass: Option<&str>) -> Result, Error> { + let p = pair_from_suri::

(uri, pass)?; + Ok(p.public().as_ref().to_vec()) } fn insert_key(url: &str, key_type: String, suri: String, public: Bytes) diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs index d42d7e18a0005..cfa6ce942e975 100644 --- a/client/cli/src/commands/sign.rs +++ b/client/cli/src/commands/sign.rs @@ -85,6 +85,6 @@ impl CliConfiguration for SignCmd { } fn sign(suri: &str, password: Option<&str>, message: Vec) -> error::Result { - let pair = pair_from_suri::

(suri, password); + let pair = pair_from_suri::

(suri, password)?; Ok(format!("{}", hex::encode(pair.sign(&message)))) } diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 635e0bd766c47..ddbaf441ec232 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -150,8 +150,10 @@ pub fn print_from_uri( } /// generate a pair from suri -pub fn pair_from_suri(suri: &str, password: Option<&str>) -> P { - P::from_string(suri, password).expect("Invalid phrase") +pub fn pair_from_suri(suri: &str, password: Option<&str>) -> Result { + let pair = P::from_string(suri, password) + .map_err(|err| format!("Invalid phrase {:?}", err))?; + Ok(pair) } /// formats seed as hex diff --git a/frame/system/src/extras.rs b/frame/system/src/extras.rs index 46a46ef4bacf6..54583ab3f746e 100644 --- a/frame/system/src/extras.rs +++ b/frame/system/src/extras.rs @@ -32,7 +32,7 @@ pub type AccountIdFor = ::AccountId; /// Strongly typed interface for the `SignedExtensions` that should be included in extrinsics /// for them to valid for your runtime. /// -/// ```rust,ignore +/// ```rust /// use runtime::{Runtime, SignedExtra}; /// use frame_system::extras::IndexFor; /// @@ -41,7 +41,7 @@ pub type AccountIdFor = ::AccountId; /// /// } /// -/// impl RuntimeAdapter for Runtime { +/// impl SignedExtensionProvider for Runtime { /// type Extra = SignedExtra; /// /// type Params = ExtraParams; @@ -104,6 +104,8 @@ pub trait SystemExtraParams { fn set_nonce(&mut self, index: T::Index); /// sets the nonce fn set_era(&mut self, era: Era); - /// sets the prior block hash - fn set_prior_block_hash(&mut self, hash: T::Hash); + /// sets the block hash for the start of the era this transaction is valid for. + fn set_starting_era_hash(&mut self, hash: T::Hash); + /// set the genesis hash + fn set_genesis_hash(&mut self, hash: T::Hash); } diff --git a/test-utils/runtime/Cargo.toml b/test-utils/runtime/Cargo.toml index 21c269736d765..4a51c85085e3a 100644 --- a/test-utils/runtime/Cargo.toml +++ b/test-utils/runtime/Cargo.toml @@ -62,7 +62,6 @@ wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-run default = [ "std", ] -indices-lookup = [] std = [ "sp-application-crypto/std", "sp-consensus-aura/std", diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index 77699a8844e0d..2acf56661304b 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -429,9 +429,13 @@ impl SystemExtraParams for ExtrasParams { self.era = era; } - fn set_prior_block_hash(&mut self, _hash: ::Hash) { + fn set_starting_era_hash(&mut self, _hash: ::Hash) { unimplemented!() } + + fn set_genesis_hash(&mut self, _: ::Hash) { + todo!() + } } pub struct ExtrasParams { @@ -471,9 +475,6 @@ impl frame_system::Trait for Runtime { type BlockNumber = u64; type Hash = H256; type Hashing = Hashing; - #[cfg(feature = "indices-lookup")] - type AccountId = sr25519::Public; - #[cfg(not(feature = "indices-lookup"))] type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; diff --git a/utils/frame/frame-utilities-cli/src/utils.rs b/utils/frame/frame-utilities-cli/src/utils.rs index ea1dc127b86c5..e3c17ab39db1b 100644 --- a/utils/frame/frame-utilities-cli/src/utils.rs +++ b/utils/frame/frame-utilities-cli/src/utils.rs @@ -25,9 +25,9 @@ use frame_system::extras::{ IndexFor, AddressFor, AccountIdFor, SignedExtensionData, }; use sp_runtime::generic::Era; -use sc_cli::pair_from_suri; +use sc_cli::{pair_from_suri, Error}; -/// create an extrinsic for the runtime, takes a uri, password, call, nonce and prior hash (for extras). +/// Creates an extrinsic for the runtime, takes a uri, password, call, nonce and prior hash (for extras). pub fn create_extrinsic_for( uri: &str, pass: Option<&str>, @@ -36,7 +36,7 @@ pub fn create_extrinsic_for( hash: P::Hash, ) -> Result< UncheckedExtrinsic, Call, MultiSignature, P::Extra>, - &'static str + Error > where Call: Encode, @@ -47,18 +47,18 @@ pub fn create_extrinsic_for( AccountIdFor

: From, AddressFor

: From>, { - let pair = pair_from_suri::(uri, pass); + let pair = pair_from_suri::(uri, pass)?; let mut input = P::extension_params(); input.set_nonce(nonce); input.set_era(Era::Immortal); - input.set_prior_block_hash(hash); + input.set_starting_era_hash(hash); let SignedExtensionData { extra, additional } = P::construct_extras(input)?; let payload = if let Some(additional_signed) = additional { SignedPayload::from_raw(call, extra, additional_signed) } else { SignedPayload::new(call, extra) - .map_err(|_| "Transaction validity error")? + .map_err(|err| format!("Transaction validity error: {:?}", err))? }; let account_public = pair.public().into().into_account(); From 2be821f81838402ad4362eecee2778f51371f56f Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 15 Jun 2020 16:00:28 +0100 Subject: [PATCH 64/77] adds ExtrasParamsBuilder --- bin/node/runtime/src/lib.rs | 105 +++++++++++------- frame/system/src/extras.rs | 109 ++++++++----------- test-utils/runtime/src/lib.rs | 50 --------- utils/frame/frame-utilities-cli/src/utils.rs | 14 ++- 4 files changed, 117 insertions(+), 161 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 45681e36b05fe..c98e0ddd6d844 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -34,7 +34,7 @@ use frame_support::{ }; use frame_system::{ EnsureRoot, EnsureOneOf, - extras::{SignedExtensionProvider, SystemExtraParams, SignedExtensionData}, + extras::{SignedExtensionProvider, ExtrasParamsBuilder, SignedExtensionData, BuilderError}, }; use frame_support::traits::{Filter, InstanceFilter}; use codec::{Encode, Decode}; @@ -629,57 +629,80 @@ parameter_types! { } #[derive(Default)] -pub struct ExtrasParams { +pub struct RuntimeExtrasBuilder { era: Option, + tip: u128, index: Option<::Index>, + genesis_hash: Option<::Hash>, + era_start_hash: Option<::Hash>, +} + +pub struct RuntimeExtrasParams { + era: Era, tip: u128, - prior_block_hash: Option<::Hash>, + index: ::Index, + genesis_hash: Option<::Hash>, + era_start_hash: Option<::Hash>, } -impl SystemExtraParams for ExtrasParams { - fn set_nonce(&mut self, index: ::Index) { +impl ExtrasParamsBuilder for RuntimeExtrasBuilder { + type ExtrasParams = RuntimeExtrasParams; + + fn set_nonce(mut self, index: ::Index) -> Self { self.index = Some(index); + self } - fn set_era(&mut self, era: Era) { + fn set_era(mut self, era: Era) -> Self { self.era = Some(era); + self + } + + fn set_tip(mut self, tip: u128) -> Self { + self.tip = tip; + self + } + + fn set_starting_era_hash(mut self, hash: ::Hash) -> Self { + self.era_start_hash = Some(hash); + self } - fn set_starting_era_hash(&mut self, hash: ::Hash) { - self.prior_block_hash = Some(hash); + fn set_genesis_hash(mut self, hash: ::Hash) -> Self { + self.genesis_hash = Some(hash); + self } - fn set_genesis_hash(&mut self, _: ::Hash) { - todo!() + fn build(self) -> Result { + Ok(RuntimeExtrasParams { + era: self.era.ok_or_else(|| BuilderError::EraIsRequired)?, + index: self.index.ok_or_else(|| BuilderError::NonceIsRequired)?, + tip: self.tip, + genesis_hash: self.genesis_hash, + era_start_hash: self.era_start_hash, + }) } } impl SignedExtensionProvider for Runtime { type Extra = SignedExtra; - type Params = ExtrasParams; - - fn extension_params() -> ExtrasParams { - ExtrasParams { - prior_block_hash: None, - index: None, - era: None, - tip: 0, - } + type Builder = RuntimeExtrasBuilder; + + fn extras_params_builder() -> RuntimeExtrasBuilder { + RuntimeExtrasBuilder::default() } - fn construct_extras(params: ExtrasParams) -> Result, &'static str> { - let ExtrasParams { + fn construct_extras(params: RuntimeExtrasParams) -> SignedExtensionData { + let RuntimeExtrasParams { tip, era, index, - prior_block_hash + era_start_hash, + genesis_hash } = params; - let (era, index) = ( - era.ok_or("era is required")?, - index.ok_or("index is required")?, - ); - let data = SignedExtensionData { + + SignedExtensionData { extra: ( frame_system::CheckSpecVersion::::new(), frame_system::CheckTxVersion::::new(), @@ -690,21 +713,20 @@ impl SignedExtensionProvider for Runtime { pallet_transaction_payment::ChargeTransactionPayment::::from(tip), pallet_grandpa::ValidateEquivocationReport::::new(), ), - additional: prior_block_hash.map(|hash| { - ( + additional: match (genesis_hash, era_start_hash) { + (Some(genesis), Some(era)) => Some(( VERSION.spec_version, VERSION.transaction_version, - hash, - hash, + genesis, + era, (), (), (), (), - ) - }) - }; - - Ok(data) + )), + _ => None + } + } } } @@ -729,16 +751,17 @@ impl frame_system::offchain::CreateSignedTransaction for R // so the actual block number is `n`. .saturating_sub(1); let era = Era::mortal(period, current_block); - let mut input = Runtime::extension_params(); - input.set_nonce(nonce); - input.set_era(era); - let SignedExtensionData { extra, additional } = match Runtime::construct_extras(input) { + let input = Runtime::extras_params_builder() + .set_nonce(nonce) + .set_era(era); + let input = match input.build() { Ok(d) => d, Err(e) => { - debug::warn!("unable to construct extras: {}", e); + debug::warn!("unable to construct extras: {:?}", e); return None } }; + let SignedExtensionData { extra, additional } = Runtime::construct_extras(input); let raw_payload = if let Some(additional_signed) = additional { SignedPayload::from_raw(call, extra, additional_signed) } else { diff --git a/frame/system/src/extras.rs b/frame/system/src/extras.rs index 54583ab3f746e..93f761c174b36 100644 --- a/frame/system/src/extras.rs +++ b/frame/system/src/extras.rs @@ -16,6 +16,7 @@ use sp_runtime::traits::{StaticLookup, SignedExtension}; use sp_runtime::generic::Era; +use sp_runtime::RuntimeDebug; /// AccountIndex type for Runtime pub type IndexFor = ::Index; @@ -28,84 +29,64 @@ pub type HashFor = ::Hash; /// AccountId type for runtime. pub type AccountIdFor = ::AccountId; -/// /// Strongly typed interface for the `SignedExtensions` that should be included in extrinsics /// for them to valid for your runtime. -/// -/// ```rust -/// use runtime::{Runtime, SignedExtra}; -/// use frame_system::extras::IndexFor; -/// -/// #[derive(Default)] -/// struct ExtraParams { -/// -/// } -/// -/// impl SignedExtensionProvider for Runtime { -/// type Extra = SignedExtra; -/// -/// type Params = ExtraParams; -/// -/// fn extension_params() -> Self::Params { -/// Default::default() -/// } -/// -/// fn construct_extras(params: ExtraParams) -> Result, &'static str> { -/// // take the biggest period possible. -/// let period = BlockHashCount::get() -/// .checked_next_power_of_two() -/// .map(|c| c / 2) -/// .unwrap_or(2) as u64; -/// let current_block = System::block_number() -/// .saturated_into::() -/// // The `System::block_number` is initialized with `n+1`, -/// // so the actual block number is `n`. -/// .saturating_sub(1); -/// -/// ( -/// frame_system::CheckSpecVersion::new(), -/// frame_system::CheckTxVersion::new(), -/// frame_system::CheckGenesis::new(), -/// frame_system::CheckEra::from(generic::Era::mortal(period, current_block)), -/// frame_system::CheckNonce::from(index), -/// frame_system::CheckWeight::new(), -/// ) -/// } -/// } -/// -/// ``` -/// pub trait SignedExtensionProvider: crate::Trait { /// Concrete SignedExtension type. type Extra: SignedExtension; + /// Concrete type for params used to construct the `SignedExtension`-Data - type Params: SystemExtraParams; + type Builder: ExtrasParamsBuilder; - /// retrieve an instance of the input object. - fn extension_params() -> Self::Params; + /// Retrieve an instance of the builder. + fn extras_params_builder() -> Self::Builder; - /// construct extras and optionally additional_signed data for inclusion in extrinsics. - fn construct_extras(input: Self::Params) -> Result, &'static str>; + /// Construct extras and optionally additional_signed data for inclusion in extrinsics. + fn construct_extras(input: >::ExtrasParams) -> + SignedExtensionData; } -/// extras that should be included in extrinsics, + +/// Extras that should be included in extrinsics, /// additional data is provided for call sites that don't have access to storage. pub struct SignedExtensionData { - /// signed extras + /// Signed extras pub extra: S, - /// additional data for the signed extras. + /// Additional data for the signed extras. pub additional: Option, } -/// used internally by substrate to set extras for inclusion in -/// `SignedExtensionProvider` -pub trait SystemExtraParams { - /// sets the nonce - fn set_nonce(&mut self, index: T::Index); - /// sets the nonce - fn set_era(&mut self, era: Era); - /// sets the block hash for the start of the era this transaction is valid for. - fn set_starting_era_hash(&mut self, hash: T::Hash); - /// set the genesis hash - fn set_genesis_hash(&mut self, hash: T::Hash); +/// Builder for `ExtrasParams`, used by runtimes to define data required for constructing signed extras +pub trait ExtrasParamsBuilder { + /// Concrete type passed to `construct_extras`. + type ExtrasParams; + + /// Sets the nonce + fn set_nonce(self, index: T::Index) -> Self; + + /// Sets the era + fn set_era(self, era: Era) -> Self; + + /// Sets the tip + fn set_tip(self, tip: u128) -> Self; + + /// Sets the block hash for the start of the era this transaction is valid for. + /// this is an additional signed data and is therefore **optional** + /// only provide it you know `construct_extras` will be called outside of an externalities environment. + fn set_starting_era_hash(self, hash: T::Hash) -> Self; + + /// Sets the genesis hash + /// this is an additional signed data and is therefore **optional** + /// only provide it you know `construct_extras` will be called outside of an externalities environment. + fn set_genesis_hash(self, hash: T::Hash) -> Self; + + /// build the extras params + fn build(self) -> Result; +} +#[derive(RuntimeDebug)] +pub enum BuilderError { + /// Era value wasn't supplied + EraIsRequired, + /// Nonce value wasn't supplied + NonceIsRequired, } diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index 2acf56661304b..60a1f16ae240c 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -55,9 +55,6 @@ use cfg_if::cfg_if; // Ensure Babe and Aura use the same crypto to simplify things a bit. pub use sp_consensus_babe::{AuthorityId, SlotNumber, AllowedSlots}; -use frame_system::extras::{SignedExtensionProvider, SystemExtraParams, SignedExtensionData}; -use sp_runtime::generic::Era; -use frame_system::Trait; pub type AuraId = sp_consensus_aura::sr25519::AuthorityId; @@ -420,53 +417,6 @@ impl pallet_balances::Trait for Runtime { type AccountStore = frame_system::Module; } -impl SystemExtraParams for ExtrasParams { - fn set_nonce(&mut self, _index: ::Index) { - unimplemented!() - } - - fn set_era(&mut self, era: Era) { - self.era = era; - } - - fn set_starting_era_hash(&mut self, _hash: ::Hash) { - unimplemented!() - } - - fn set_genesis_hash(&mut self, _: ::Hash) { - todo!() - } -} - -pub struct ExtrasParams { - era: Era -} - -impl SignedExtensionProvider for Runtime { - type Extra = ( - frame_system::CheckTxVersion, - frame_system::CheckGenesis, - frame_system::CheckEra, - ); - - type Params = ExtrasParams; - - fn extension_params() -> Self::Params { - ExtrasParams { era: Era::Immortal } - } - - fn construct_extras(params: Self::Params) -> Result, &'static str> { - let data = SignedExtensionData { - extra: ( - frame_system::CheckTxVersion::new(), - frame_system::CheckGenesis::new(), - frame_system::CheckEra::from(params.era) - ), - additional: None - }; - Ok(data) - } -} impl frame_system::Trait for Runtime { type Origin = Origin; diff --git a/utils/frame/frame-utilities-cli/src/utils.rs b/utils/frame/frame-utilities-cli/src/utils.rs index e3c17ab39db1b..56cc40a8699df 100644 --- a/utils/frame/frame-utilities-cli/src/utils.rs +++ b/utils/frame/frame-utilities-cli/src/utils.rs @@ -21,7 +21,7 @@ use sp_runtime::{ }; use codec::Encode; use frame_system::extras::{ - SignedExtensionProvider, SystemExtraParams, + SignedExtensionProvider, ExtrasParamsBuilder, IndexFor, AddressFor, AccountIdFor, SignedExtensionData, }; use sp_runtime::generic::Era; @@ -48,11 +48,13 @@ pub fn create_extrinsic_for( AddressFor

: From>, { let pair = pair_from_suri::(uri, pass)?; - let mut input = P::extension_params(); - input.set_nonce(nonce); - input.set_era(Era::Immortal); - input.set_starting_era_hash(hash); - let SignedExtensionData { extra, additional } = P::construct_extras(input)?; + let input = P::extras_params_builder() + .set_nonce(nonce) + .set_era(Era::Immortal) + .set_starting_era_hash(hash) + .build() + .map_err(|err| format!("failed to construct extras: {:?}", err))?; + let SignedExtensionData { extra, additional } = P::construct_extras(input); let payload = if let Some(additional_signed) = additional { SignedPayload::from_raw(call, extra, additional_signed) From a7dd08793358de326c7e15b427d54a22e33940e4 Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 15 Jun 2020 16:05:37 +0100 Subject: [PATCH 65/77] remove tests for ModuleIdCmd --- utils/frame/frame-utilities-cli/src/module_id.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/utils/frame/frame-utilities-cli/src/module_id.rs b/utils/frame/frame-utilities-cli/src/module_id.rs index 3805b346d1388..fd78bbeabba38 100644 --- a/utils/frame/frame-utilities-cli/src/module_id.rs +++ b/utils/frame/frame-utilities-cli/src/module_id.rs @@ -107,16 +107,3 @@ impl CliConfiguration for ModuleIdCmd { Some(&self.keystore_params) } } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn module_id() { - let seed = "sdad1fb7"; - - let cmd = ModuleIdCmd::from_iter(&["moduleid", seed]); - assert!(cmd.run().is_ok()); - } -} \ No newline at end of file From 51c35c4fff309fa62f44d4d55b0d25fd834efb40 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 16 Jun 2020 16:29:36 +0100 Subject: [PATCH 66/77] address comments from PR --- bin/node/runtime/src/lib.rs | 36 +++++-------------- client/cli/src/commands/generate.rs | 4 +-- client/cli/src/commands/insert.rs | 10 ++---- client/cli/src/commands/inspect.rs | 5 +-- client/cli/src/commands/mod.rs | 3 +- client/cli/src/commands/sign.rs | 10 +++--- client/cli/src/commands/vanity.rs | 7 ++-- client/cli/src/commands/verify.rs | 10 +++--- frame/system/src/extras.rs | 20 ++--------- frame/system/src/lib.rs | 4 +-- primitives/core/src/crypto.rs | 18 ++++++++-- test-utils/runtime/src/lib.rs | 19 +--------- .../frame-utilities-cli/src/module_id.rs | 2 +- .../src/sign_transaction.rs | 7 ++-- .../frame/frame-utilities-cli/src/transfer.rs | 7 ++-- utils/frame/frame-utilities-cli/src/utils.rs | 9 ++--- 16 files changed, 64 insertions(+), 107 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index c98e0ddd6d844..d6150e8c85a50 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -34,7 +34,7 @@ use frame_support::{ }; use frame_system::{ EnsureRoot, EnsureOneOf, - extras::{SignedExtensionProvider, ExtrasParamsBuilder, SignedExtensionData, BuilderError}, + extras::{SignedExtensionProvider, ExtrasParamsBuilder, SignedExtensionData}, }; use frame_support::traits::{Filter, InstanceFilter}; use codec::{Encode, Decode}; @@ -630,9 +630,7 @@ parameter_types! { #[derive(Default)] pub struct RuntimeExtrasBuilder { - era: Option, tip: u128, - index: Option<::Index>, genesis_hash: Option<::Hash>, era_start_hash: Option<::Hash>, } @@ -648,16 +646,6 @@ pub struct RuntimeExtrasParams { impl ExtrasParamsBuilder for RuntimeExtrasBuilder { type ExtrasParams = RuntimeExtrasParams; - fn set_nonce(mut self, index: ::Index) -> Self { - self.index = Some(index); - self - } - - fn set_era(mut self, era: Era) -> Self { - self.era = Some(era); - self - } - fn set_tip(mut self, tip: u128) -> Self { self.tip = tip; self @@ -673,14 +661,14 @@ impl ExtrasParamsBuilder for RuntimeExtrasBuilder { self } - fn build(self) -> Result { - Ok(RuntimeExtrasParams { - era: self.era.ok_or_else(|| BuilderError::EraIsRequired)?, - index: self.index.ok_or_else(|| BuilderError::NonceIsRequired)?, + fn build(self, index: ::Index, era: Era) -> Self::ExtrasParams { + RuntimeExtrasParams { + era, + index, tip: self.tip, genesis_hash: self.genesis_hash, era_start_hash: self.era_start_hash, - }) + } } } @@ -751,16 +739,8 @@ impl frame_system::offchain::CreateSignedTransaction for R // so the actual block number is `n`. .saturating_sub(1); let era = Era::mortal(period, current_block); - let input = Runtime::extras_params_builder() - .set_nonce(nonce) - .set_era(era); - let input = match input.build() { - Ok(d) => d, - Err(e) => { - debug::warn!("unable to construct extras: {:?}", e); - return None - } - }; + let builder = Runtime::extras_params_builder(); + let input = builder.build(nonce, era); let SignedExtensionData { extra, additional } = Runtime::construct_extras(input); let raw_payload = if let Some(additional_signed) = additional { SignedPayload::from_raw(call, extra, additional_signed) diff --git a/client/cli/src/commands/generate.rs b/client/cli/src/commands/generate.rs index 8e80ea228e9fa..f2f7933208f71 100644 --- a/client/cli/src/commands/generate.rs +++ b/client/cli/src/commands/generate.rs @@ -19,7 +19,7 @@ use bip39::{MnemonicType, Mnemonic, Language}; use structopt::StructOpt; use crate::{ - print_from_uri, CliConfiguration, KeystoreParams, SharedParams, Error, + utils::print_from_uri, CliConfiguration, KeystoreParams, SharedParams, Error, with_crypto_scheme, NetworkSchemeFlag, OutputTypeFlag, CryptoSchemeFlag, }; @@ -27,7 +27,7 @@ use crate::{ #[derive(Debug, StructOpt)] #[structopt(name = "generate", about = "Generate a random account")] pub struct GenerateCmd { - /// The number of words in the phrase to generate. One of 12 default), 15, 18, 21 and 24. + /// The number of words in the phrase to generate. One of 12 (default), 15, 18, 21 and 24. #[structopt(long, short = "w", value_name = "WORDS")] words: Option, diff --git a/client/cli/src/commands/insert.rs b/client/cli/src/commands/insert.rs index 3829a2326cb7a..89ca2c9542b52 100644 --- a/client/cli/src/commands/insert.rs +++ b/client/cli/src/commands/insert.rs @@ -17,11 +17,7 @@ //! Implementation of the `insert` subcommand -use crate::{ - Error, pair_from_suri, CliConfiguration, - KeystoreParams, with_crypto_scheme, - CryptoSchemeFlag, SharedParams, read_uri, -}; +use crate::{Error, CliConfiguration, KeystoreParams, with_crypto_scheme, CryptoSchemeFlag, SharedParams, utils}; use structopt::StructOpt; use sp_core::{crypto::KeyTypeId, Bytes}; use std::convert::TryFrom; @@ -71,7 +67,7 @@ impl InsertCmd { where H: DeserializeOwned + Serialize + Send + Sync + 'static, { - let suri = read_uri(self.suri.as_ref())?; + let suri = utils::read_uri(self.suri.as_ref())?; let password = self.keystore_params.read_password()?; let public = with_crypto_scheme!( @@ -113,7 +109,7 @@ impl CliConfiguration for InsertCmd { } fn to_vec(uri: &str, pass: Option<&str>) -> Result, Error> { - let p = pair_from_suri::

(uri, pass)?; + let p = utils::pair_from_suri::

(uri, pass)?; Ok(p.public().as_ref().to_vec()) } diff --git a/client/cli/src/commands/inspect.rs b/client/cli/src/commands/inspect.rs index 8f9c56638dce5..0d714ef5471d5 100644 --- a/client/cli/src/commands/inspect.rs +++ b/client/cli/src/commands/inspect.rs @@ -18,7 +18,7 @@ //! Implementation of the `inspect` subcommand use crate::{ - print_from_uri, CliConfiguration, KeystoreParams, SharedParams, read_uri, + utils, CliConfiguration, KeystoreParams, SharedParams, with_crypto_scheme, NetworkSchemeFlag, OutputTypeFlag, CryptoSchemeFlag, Error, }; use structopt::StructOpt; @@ -61,9 +61,10 @@ pub struct InspectCmd { impl InspectCmd { /// Run the command pub fn run(&self) -> Result<(), Error> { - let uri = read_uri(self.uri.as_ref())?; + let uri = utils::read_uri(self.uri.as_ref())?; let password = self.keystore_params.read_password()?; + use utils::print_from_uri; with_crypto_scheme!( self.crypto_scheme.scheme, print_from_uri( diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index a625596a2820c..de7c84e72b2de 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -22,7 +22,6 @@ mod export_state_cmd; mod import_blocks_cmd; mod purge_chain_cmd; mod sign; -mod utils; mod verify; mod vanity; mod revert_cmd; @@ -33,6 +32,7 @@ mod insert; mod inspect_node_key; mod inspect; mod key; +pub mod utils; #[cfg(test)] pub mod tests; @@ -59,7 +59,6 @@ pub use self::{ verify::VerifyCmd, revert_cmd::RevertCmd, run_cmd::RunCmd, - utils::*, }; /// All core commands that are provided by default. diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs index cfa6ce942e975..f90477ce7ea98 100644 --- a/client/cli/src/commands/sign.rs +++ b/client/cli/src/commands/sign.rs @@ -17,8 +17,8 @@ // along with this program. If not, see . //! Implementation of the `sign` subcommand -use crate::{error, pair_from_suri, CliConfiguration, KeystoreParams, with_crypto_scheme, CryptoSchemeFlag}; -use super::{SharedParams, read_message, read_uri}; +use crate::{error, utils, CliConfiguration, KeystoreParams, with_crypto_scheme, CryptoSchemeFlag}; +use super::SharedParams; use structopt::StructOpt; /// The `sign` command @@ -60,8 +60,8 @@ pub struct SignCmd { impl SignCmd { /// Run the command pub fn run(&self) -> error::Result<()> { - let message = read_message(self.message.as_ref(), self.hex)?; - let suri = read_uri(self.suri.as_ref())?; + let message = utils::read_message(self.message.as_ref(), self.hex)?; + let suri = utils::read_uri(self.suri.as_ref())?; let password = self.keystore_params.read_password()?; let signature = with_crypto_scheme!( @@ -85,6 +85,6 @@ impl CliConfiguration for SignCmd { } fn sign(suri: &str, password: Option<&str>, message: Vec) -> error::Result { - let pair = pair_from_suri::

(suri, password)?; + let pair = utils::pair_from_suri::

(suri, password)?; Ok(format!("{}", hex::encode(pair.sign(&message)))) } diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index 90420e8511a86..7998c2ab84d17 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -19,8 +19,8 @@ //! implementation of the `vanity` subcommand use crate::{ - error, format_seed, SharedParams, print_from_uri, CliConfiguration, - with_crypto_scheme, CryptoSchemeFlag, NetworkSchemeFlag, OutputTypeFlag, + error, utils, CliConfiguration, with_crypto_scheme, + CryptoSchemeFlag, NetworkSchemeFlag, OutputTypeFlag, SharedParams, }; use sp_core::crypto::Ss58Codec; use structopt::StructOpt; @@ -66,6 +66,7 @@ impl VanityCmd { .map(String::as_str) .unwrap_or(""); let formated_seed = with_crypto_scheme!(self.crypto_scheme.scheme, generate_key(desired))?; + use utils::print_from_uri; with_crypto_scheme!( self.crypto_scheme.scheme, print_from_uri( @@ -117,7 +118,7 @@ fn generate_key(desired: &str) -> Result best = score; if best >= top { println!("best: {} == top: {}", best, top); - return Ok(format_seed::(seed.clone())); + return Ok(utils::format_seed::(seed.clone())); } } done += 1; diff --git a/client/cli/src/commands/verify.rs b/client/cli/src/commands/verify.rs index be9e8928c8a35..9cfb65d142203 100644 --- a/client/cli/src/commands/verify.rs +++ b/client/cli/src/commands/verify.rs @@ -19,8 +19,8 @@ //! implementation of the `verify` subcommand use crate::{ - read_message, decode_hex, read_uri, CliConfiguration, - error, SharedParams, with_crypto_scheme, CryptoSchemeFlag, + error, utils, with_crypto_scheme, + CliConfiguration, CryptoSchemeFlag, SharedParams, }; use sp_core::{Public, crypto::Ss58Codec}; use structopt::StructOpt; @@ -61,9 +61,9 @@ pub struct VerifyCmd { impl VerifyCmd { /// Run the command pub fn run(&self) -> error::Result<()> { - let message = read_message(self.message.as_ref(), self.hex)?; - let sig_data = decode_hex(&self.sig)?; - let uri = read_uri(self.uri.as_ref())?; + let message = utils::read_message(self.message.as_ref(), self.hex)?; + let sig_data = utils::decode_hex(&self.sig)?; + let uri = utils::read_uri(self.uri.as_ref())?; let uri = if uri.starts_with("0x") { &uri[2..] } else { diff --git a/frame/system/src/extras.rs b/frame/system/src/extras.rs index 93f761c174b36..95df5d0fa7abe 100644 --- a/frame/system/src/extras.rs +++ b/frame/system/src/extras.rs @@ -16,7 +16,6 @@ use sp_runtime::traits::{StaticLookup, SignedExtension}; use sp_runtime::generic::Era; -use sp_runtime::RuntimeDebug; /// AccountIndex type for Runtime pub type IndexFor = ::Index; @@ -32,7 +31,7 @@ pub type AccountIdFor = ::AccountId; /// Strongly typed interface for the `SignedExtensions` that should be included in extrinsics /// for them to valid for your runtime. pub trait SignedExtensionProvider: crate::Trait { - /// Concrete SignedExtension type. + /// Concrete SignedExtension type. type Extra: SignedExtension; /// Concrete type for params used to construct the `SignedExtension`-Data @@ -41,7 +40,7 @@ pub trait SignedExtensionProvider: crate::Trait { /// Retrieve an instance of the builder. fn extras_params_builder() -> Self::Builder; - /// Construct extras and optionally additional_signed data for inclusion in extrinsics. + /// Construct extras and optionally additional_signed data for inclusion in extrinsics. fn construct_extras(input: >::ExtrasParams) -> SignedExtensionData; } @@ -60,12 +59,6 @@ pub struct SignedExtensionData { pub trait ExtrasParamsBuilder { /// Concrete type passed to `construct_extras`. type ExtrasParams; - - /// Sets the nonce - fn set_nonce(self, index: T::Index) -> Self; - - /// Sets the era - fn set_era(self, era: Era) -> Self; /// Sets the tip fn set_tip(self, tip: u128) -> Self; @@ -81,12 +74,5 @@ pub trait ExtrasParamsBuilder { fn set_genesis_hash(self, hash: T::Hash) -> Self; /// build the extras params - fn build(self) -> Result; -} -#[derive(RuntimeDebug)] -pub enum BuilderError { - /// Era value wasn't supplied - EraIsRequired, - /// Nonce value wasn't supplied - NonceIsRequired, + fn build(self, nonce: T::Index, era: Era) -> Self::ExtrasParams; } diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index fd0c05a90d7e5..ab096044a058c 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -112,7 +112,7 @@ use sp_runtime::{ self, CheckEqual, AtLeast32Bit, Zero, SignedExtension, Lookup, LookupError, SimpleBitOps, Hash, Member, MaybeDisplay, BadOrigin, SaturatedConversion, MaybeSerialize, MaybeSerializeDeserialize, MaybeMallocSizeOf, StaticLookup, One, Bounded, - MaybeFromStr, Dispatchable, DispatchInfoOf, PostDispatchInfoOf, + Dispatchable, DispatchInfoOf, PostDispatchInfoOf, }, offchain::storage_lock::BlockNumberProvider, }; @@ -162,7 +162,7 @@ pub trait Trait: 'static + Eq + Clone { /// Account index (aka nonce) type. This stores the number of previous transactions associated /// with a sender account. type Index: - Parameter + Member + MaybeSerialize + MaybeFromStr + Debug + Default + MaybeDisplay + AtLeast32Bit + Parameter + Member + MaybeSerialize + Debug + Default + MaybeDisplay + AtLeast32Bit + Copy; /// The block number type used by the runtime. diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 6761030c28f24..1f2076cd6d3ed 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -415,18 +415,30 @@ macro_rules! ss58_address_format { } } + /// Error encountered while parsing `Ss58AddressFormat` from &'_ str + /// unit struct for now. + #[derive(Copy, Clone, PartialEq, Eq, crate::RuntimeDebug)] + pub struct ParseError; + impl<'a> TryFrom<&'a str> for Ss58AddressFormat { - type Error = &'static str; + type Error = ParseError; - fn try_from(x: &'a str) -> Result { + fn try_from(x: &'a str) -> Result { match x { $($name => Ok(Ss58AddressFormat::$identifier)),*, a => a.parse::().map(Ss58AddressFormat::Custom) - .map_err(|_| "failed to parse network value as u8"), + .map_err(|_| ParseError), } } } + #[cfg(feature = "std")] + impl std::fmt::Display for ParseError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "failed to parse network value as u8") + } + } + #[cfg(feature = "std")] impl Default for Ss58AddressFormat { fn default() -> Self { diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index 60a1f16ae240c..7e22c6efdbb04 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -389,12 +389,6 @@ impl From> for Event { } } -impl From> for Event { - fn from(_evt: pallet_balances::Event) -> Self { - unimplemented!("Not required in tests!") - } -} - parameter_types! { pub const BlockHashCount: BlockNumber = 2400; pub const MinimumPeriod: u64 = 5; @@ -405,19 +399,8 @@ parameter_types! { }; pub const MaximumBlockLength: u32 = 4 * 1024 * 1024; pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75); - pub const Deposit: u64 = 1; - pub const ExistentialDeposit: u64 = 1; } -impl pallet_balances::Trait for Runtime { - type Balance = u64; - type DustRemoval = (); - type Event = Event; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = frame_system::Module; -} - - impl frame_system::Trait for Runtime { type Origin = Origin; type Call = Extrinsic; @@ -439,7 +422,7 @@ impl frame_system::Trait for Runtime { type AvailableBlockRatio = AvailableBlockRatio; type Version = (); type ModuleToIndex = (); - type AccountData = pallet_balances::AccountData; + type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); } diff --git a/utils/frame/frame-utilities-cli/src/module_id.rs b/utils/frame/frame-utilities-cli/src/module_id.rs index fd78bbeabba38..5cde5dae26253 100644 --- a/utils/frame/frame-utilities-cli/src/module_id.rs +++ b/utils/frame/frame-utilities-cli/src/module_id.rs @@ -18,7 +18,7 @@ //! Implementation of the `moduleid` subcommand use sc_cli::{ - Error, SharedParams, print_from_uri, CryptoSchemeFlag, + Error, SharedParams, utils::print_from_uri, CryptoSchemeFlag, OutputTypeFlag, KeystoreParams, CliConfiguration, with_crypto_scheme, }; use sp_runtime::ModuleId; diff --git a/utils/frame/frame-utilities-cli/src/sign_transaction.rs b/utils/frame/frame-utilities-cli/src/sign_transaction.rs index e783b08e5cc11..a1c9a566a9eed 100644 --- a/utils/frame/frame-utilities-cli/src/sign_transaction.rs +++ b/utils/frame/frame-utilities-cli/src/sign_transaction.rs @@ -17,7 +17,7 @@ //! Implementation of the `sign-transaction` subcommand use sc_cli::{ - Error, CliConfiguration, KeystoreParams, SharedParams, decode_hex, + Error, CliConfiguration, KeystoreParams, SharedParams, utils, with_crypto_scheme, CryptoSchemeFlag, GenericNumber, }; use structopt::StructOpt; @@ -49,11 +49,11 @@ pub struct SignTransactionCmd { nonce: GenericNumber, /// genesis hash, for signed extensions. - #[structopt(long, parse(try_from_str = decode_hex))] + #[structopt(long, parse(try_from_str = utils::decode_hex))] prior_block_hash: Bytes, /// The call, hex-encoded. - #[structopt(long, parse(try_from_str = decode_hex))] + #[structopt(long, parse(try_from_str = utils::decode_hex))] call: Bytes, #[allow(missing_docs)] @@ -74,6 +74,7 @@ impl SignTransactionCmd { pub fn run

(&self) -> Result<(), Error> where P: SignedExtensionProvider + pallet_indices::Trait, + IndexFor

: FromStr, as FromStr>::Err: Debug, AccountIdFor

: From, AddressFor

: From>, diff --git a/utils/frame/frame-utilities-cli/src/transfer.rs b/utils/frame/frame-utilities-cli/src/transfer.rs index 0a5dd07f8d8bb..a433f35761785 100644 --- a/utils/frame/frame-utilities-cli/src/transfer.rs +++ b/utils/frame/frame-utilities-cli/src/transfer.rs @@ -18,7 +18,7 @@ //! Implementation of the `transfer` cli subcommand for nodes that use the pallet-balances crate. use sc_cli::{ - Error, SharedParams, with_crypto_scheme, CryptoSchemeFlag, decode_hex, + Error, SharedParams, with_crypto_scheme, CryptoSchemeFlag, utils, CliConfiguration, KeystoreParams, GenericNumber, }; use structopt::StructOpt; @@ -62,7 +62,7 @@ pub struct TransferCmd { to: String, /// Genesis hash, for signed extensions. - #[structopt(long, parse(try_from_str = decode_hex))] + #[structopt(long, parse(try_from_str = utils::decode_hex))] prior_block_hash: Bytes, #[allow(missing_docs)] @@ -86,6 +86,7 @@ impl TransferCmd { R: pallet_balances::Trait + pallet_indices::Trait + SignedExtensionProvider, AccountIdFor: for<'a> TryFrom<&'a [u8], Error = ()> + Ss58Codec + From, AddressFor: From>, + IndexFor: FromStr, as FromStr>::Err: Debug, BalanceFor: FromStr, as FromStr>::Err: Debug, @@ -94,7 +95,7 @@ impl TransferCmd { { let password = self.keystore_params.read_password()?; let nonce = self.index.parse::>()?; - let to = if let Ok(data_vec) = decode_hex(&self.to) { + let to = if let Ok(data_vec) = utils::decode_hex(&self.to) { AccountIdFor::::try_from(&data_vec) .map_err(|_| "Invalid hex length for account ID; should be 32 bytes")? } else { diff --git a/utils/frame/frame-utilities-cli/src/utils.rs b/utils/frame/frame-utilities-cli/src/utils.rs index 56cc40a8699df..1ed7233c4eb0a 100644 --- a/utils/frame/frame-utilities-cli/src/utils.rs +++ b/utils/frame/frame-utilities-cli/src/utils.rs @@ -25,7 +25,7 @@ use frame_system::extras::{ IndexFor, AddressFor, AccountIdFor, SignedExtensionData, }; use sp_runtime::generic::Era; -use sc_cli::{pair_from_suri, Error}; +use sc_cli::{utils, Error}; /// Creates an extrinsic for the runtime, takes a uri, password, call, nonce and prior hash (for extras). pub fn create_extrinsic_for( @@ -47,13 +47,10 @@ pub fn create_extrinsic_for( AccountIdFor

: From, AddressFor

: From>, { - let pair = pair_from_suri::(uri, pass)?; + let pair = utils::pair_from_suri::(uri, pass)?; let input = P::extras_params_builder() - .set_nonce(nonce) - .set_era(Era::Immortal) .set_starting_era_hash(hash) - .build() - .map_err(|err| format!("failed to construct extras: {:?}", err))?; + .build(nonce, Era::Immortal); let SignedExtensionData { extra, additional } = P::construct_extras(input); let payload = if let Some(additional_signed) = additional { From e5e8b5953279df7c170b9ae562e6db62272309ea Mon Sep 17 00:00:00 2001 From: Seun Date: Thu, 18 Jun 2020 17:25:23 +0100 Subject: [PATCH 67/77] bump Cargo.lock --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index df1fa2cecc548..18d9479cfeb03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6217,7 +6217,7 @@ checksum = "475e68978dc5b743f2f40d8e0a8fdc83f1c5e78cbf4b8fa5e74e73beebc340de" dependencies = [ "proc-macro2", "quote 1.0.6", - "syn 1.0.17", + "syn 1.0.21", ] [[package]] From bbb9079d85125289373cf97dd0b11bfd4a8e0ee9 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 14 Jul 2020 17:54:45 +0100 Subject: [PATCH 68/77] manually insert key into keystore --- Cargo.lock | 18 +--- bin/node/cli/src/command.rs | 7 +- bin/node/runtime/src/lib.rs | 122 +++-------------------- bin/utils/subkey/src/lib.rs | 3 +- client/cli/Cargo.toml | 7 +- client/cli/src/commands/insert.rs | 79 +++++---------- client/cli/src/commands/key.rs | 8 +- client/cli/src/commands/sign.rs | 5 +- client/cli/src/commands/utils.rs | 17 +++- client/cli/src/params/keystore_params.rs | 3 +- frame/system/src/extras.rs | 78 --------------- frame/system/src/lib.rs | 1 - 12 files changed, 63 insertions(+), 285 deletions(-) delete mode 100644 frame/system/src/extras.rs diff --git a/Cargo.lock b/Cargo.lock index 205fc00f86434..a5e16f5d7b92e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6693,11 +6693,8 @@ dependencies = [ "derive_more", "env_logger 0.7.1", "fdlimit", - "futures 0.1.29", "futures 0.3.5", "hex", - "hyper 0.12.35", - "jsonrpc-core-client", "lazy_static", "libp2p 0.18.1", "log", @@ -6710,12 +6707,11 @@ dependencies = [ "rpassword", "sc-client-api", "sc-informant", + "sc-keystore", "sc-network", - "sc-rpc", "sc-service", "sc-telemetry", "sc-tracing", - "secrecy 0.7.0", "serde", "serde_json", "sp-application-crypto", @@ -6733,7 +6729,6 @@ dependencies = [ "tempfile", "time", "tokio 0.2.21", - "zeroize", ] [[package]] @@ -7775,15 +7770,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "secrecy" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0673d6a6449f5e7d12a1caf424fd9363e2af3a4953023ed455e3c4beef4597c0" -dependencies = [ - "zeroize", -] - [[package]] name = "security-framework" version = "0.4.4" @@ -8387,7 +8373,7 @@ dependencies = [ "rand_chacha 0.2.2", "regex", "schnorrkel", - "secrecy 0.6.0", + "secrecy", "serde", "serde_json", "sha2", diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index e971cb1f1f5a9..0612968e43274 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -19,7 +19,6 @@ use crate::{chain_spec, service, Cli, Subcommand}; use node_executor::Executor; use node_runtime::{Block, RuntimeApi}; -use node_primitives::Hash; use sc_cli::{Result, SubstrateCli, RuntimeVersion, Role, ChainSpec}; impl SubstrateCli for Cli { @@ -92,11 +91,7 @@ pub fn run() -> Result<()> { Ok(()) } } - Some(Subcommand::Key(cmd)) => { - let runner = cli.create_runner(cmd)?; - - runner.sync_run(|_| cmd.run::()) - }, + Some(Subcommand::Key(cmd)) => cmd.run(), Some(Subcommand::Base(subcommand)) => { let runner = cli.create_runner(subcommand)?; runner.run_subcommand(subcommand, |config| { diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 3762a5ed6e936..d6a1219bfd43a 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -32,10 +32,7 @@ use frame_support::{ }, traits::{Currency, Imbalance, KeyOwnerProofSystem, OnUnbalanced, Randomness, LockIdentifier}, }; -use frame_system::{ - EnsureRoot, EnsureOneOf, - extras::{SignedExtensionProvider, ExtrasParamsBuilder, SignedExtensionData}, -}; +use frame_system::{EnsureRoot, EnsureOneOf}; use frame_support::traits::InstanceFilter; use codec::{Encode, Decode}; use sp_core::{ @@ -646,96 +643,6 @@ parameter_types! { pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2; } -#[derive(Default)] -pub struct RuntimeExtrasBuilder { - tip: u128, - genesis_hash: Option<::Hash>, - era_start_hash: Option<::Hash>, -} - -pub struct RuntimeExtrasParams { - era: Era, - tip: u128, - index: ::Index, - genesis_hash: Option<::Hash>, - era_start_hash: Option<::Hash>, -} - -impl ExtrasParamsBuilder for RuntimeExtrasBuilder { - type ExtrasParams = RuntimeExtrasParams; - - fn set_tip(mut self, tip: u128) -> Self { - self.tip = tip; - self - } - - fn set_starting_era_hash(mut self, hash: ::Hash) -> Self { - self.era_start_hash = Some(hash); - self - } - - fn set_genesis_hash(mut self, hash: ::Hash) -> Self { - self.genesis_hash = Some(hash); - self - } - - fn build(self, index: ::Index, era: Era) -> Self::ExtrasParams { - RuntimeExtrasParams { - era, - index, - tip: self.tip, - genesis_hash: self.genesis_hash, - era_start_hash: self.era_start_hash, - } - } -} - - -impl SignedExtensionProvider for Runtime { - type Extra = SignedExtra; - type Builder = RuntimeExtrasBuilder; - - fn extras_params_builder() -> RuntimeExtrasBuilder { - RuntimeExtrasBuilder::default() - } - - fn construct_extras(params: RuntimeExtrasParams) -> SignedExtensionData { - let RuntimeExtrasParams { - tip, - era, - index, - era_start_hash, - genesis_hash - } = params; - - SignedExtensionData { - extra: ( - frame_system::CheckSpecVersion::::new(), - frame_system::CheckTxVersion::::new(), - frame_system::CheckGenesis::::new(), - frame_system::CheckEra::::from(era), - frame_system::CheckNonce::::from(index), - frame_system::CheckWeight::::new(), - pallet_transaction_payment::ChargeTransactionPayment::::from(tip), - pallet_grandpa::ValidateEquivocationReport::::new(), - ), - additional: match (genesis_hash, era_start_hash) { - (Some(genesis), Some(era)) => Some(( - VERSION.spec_version, - VERSION.transaction_version, - genesis, - era, - (), - (), - (), - (), - )), - _ => None - } - } - } -} - impl frame_system::offchain::CreateSignedTransaction for Runtime where Call: From, @@ -757,18 +664,21 @@ impl frame_system::offchain::CreateSignedTransaction for R // so the actual block number is `n`. .saturating_sub(1); let era = Era::mortal(period, current_block); - let builder = Runtime::extras_params_builder(); - let input = builder.build(nonce, era); - let SignedExtensionData { extra, additional } = Runtime::construct_extras(input); - let raw_payload = if let Some(additional_signed) = additional { - SignedPayload::from_raw(call, extra, additional_signed) - } else { - SignedPayload::new(call, extra) - .map_err(|e| { - debug::warn!("Unable to create signed payload: {:?}", e); - }) - .ok()? - }; + let extra = ( + frame_system::CheckSpecVersion::::new(), + frame_system::CheckTxVersion::::new(), + frame_system::CheckGenesis::::new(), + frame_system::CheckEra::::from(era), + frame_system::CheckNonce::::from(nonce), + frame_system::CheckWeight::::new(), + pallet_transaction_payment::ChargeTransactionPayment::::from(0), + pallet_grandpa::ValidateEquivocationReport::::new(), + ); + let raw_payload = SignedPayload::new(call, extra) + .map_err(|e| { + debug::warn!("Unable to create signed payload: {:?}", e); + }) + .ok()?; let signature = raw_payload .using_encoded(|payload| { C::sign(payload, public) diff --git a/bin/utils/subkey/src/lib.rs b/bin/utils/subkey/src/lib.rs index c17cadc80f425..bd7b89002eb25 100644 --- a/bin/utils/subkey/src/lib.rs +++ b/bin/utils/subkey/src/lib.rs @@ -22,7 +22,6 @@ use sc_cli::{ GenerateNodeKeyCmd, GenerateCmd, InspectCmd, InspectNodeKeyCmd }; use substrate_frame_cli::ModuleIdCmd; -use frame_system::extras::HashFor; use sp_core::crypto::Ss58Codec; #[derive(Debug, StructOpt)] @@ -71,7 +70,7 @@ pub fn run() -> Result<(), Error> Subkey::Generate(cmd) => cmd.run()?, Subkey::InspectKey(cmd) => cmd.run()?, Subkey::InspectNodeKey(cmd) => cmd.run()?, - Subkey::Insert(cmd) => cmd.run::>()?, + Subkey::Insert(cmd) => cmd.run()?, Subkey::ModuleId(cmd) => cmd.run::()?, Subkey::Vanity(cmd) => cmd.run()?, Subkey::Verify(cmd) => cmd.run()?, diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 1f7e59654430d..11617ba2dd075 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -26,17 +26,13 @@ fdlimit = "0.1.4" libp2p = "0.18.1" parity-scale-codec = "1.3.0" hex = "0.4.2" -jsonrpc-core-client = { version = "14.0.3", features = ["http"] } -hyper = "0.12.35" rand = "0.7.3" bip39 = "0.6.0-beta.1" serde_json = "1.0.41" -zeroize = "1.1.0" -secrecy = "0.7.0" sc-informant = { version = "0.8.0-rc4", path = "../informant" } sp-panic-handler = { version = "2.0.0-rc4", path = "../../primitives/panic-handler" } sc-client-api = { version = "2.0.0-rc4", path = "../api" } -sc-rpc = { version = "2.0.0-rc4", path = "../rpc" } +sc-keystore = { version = "2.0.0-rc4", path = "../keystore" } sp-blockchain = { version = "2.0.0-rc4", path = "../../primitives/blockchain" } sc-network = { version = "0.8.0-rc4", path = "../network" } sp-runtime = { version = "2.0.0-rc4", path = "../../primitives/runtime" } @@ -52,7 +48,6 @@ names = "0.11.0" structopt = "0.3.8" sc-tracing = { version = "2.0.0-rc4", path = "../tracing" } chrono = "0.4.10" -futures01 = { package = "futures", version = "0.1.29" } parity-util-mem = { version = "0.7.0", default-features = false, features = ["primitive-types"] } serde = "1.0.111" diff --git a/client/cli/src/commands/insert.rs b/client/cli/src/commands/insert.rs index 06d264225de39..e4068c0c9176c 100644 --- a/client/cli/src/commands/insert.rs +++ b/client/cli/src/commands/insert.rs @@ -19,14 +19,11 @@ use crate::{Error, CliConfiguration, KeystoreParams, with_crypto_scheme, CryptoSchemeFlag, SharedParams, utils}; use structopt::StructOpt; -use sp_core::{crypto::KeyTypeId, Bytes}; +use sp_core::{crypto::KeyTypeId, traits::BareCryptoStore}; use std::convert::TryFrom; -use futures01::Future; -use hyper::rt; -use sc_rpc::author::AuthorClient; -use jsonrpc_core_client::transports::http; -use serde::{de::DeserializeOwned, Serialize}; -use sp_core::crypto::ExposeSecret; +use sc_service::config::KeystoreConfig; +use sc_keystore::Store as KeyStore; +use sp_core::crypto::SecretString; /// The `insert` command #[derive(Debug, StructOpt)] @@ -45,10 +42,6 @@ pub struct InsertCmd { #[structopt(long)] key_type: String, - /// Node JSON-RPC endpoint, default "http://localhost:9933" - #[structopt(long)] - node_url: Option, - #[allow(missing_docs)] #[structopt(flatten)] pub keystore_params: KeystoreParams, @@ -64,37 +57,31 @@ pub struct InsertCmd { impl InsertCmd { /// Run the command - pub fn run(&self) -> Result<(), Error> - where - H: DeserializeOwned + Serialize + Send + Sync + 'static, - { + pub fn run(&self) -> Result<(), Error> { let suri = utils::read_uri(self.suri.as_ref())?; - let password = self.keystore_params.read_password()?; - let password = password.as_ref().map(|s| s.expose_secret().as_str()); - - let public = with_crypto_scheme!( - self.crypto_scheme.scheme, - to_vec(&suri, password) - )?; - - let node_url = self.node_url.as_ref() - .map(String::as_str) - .unwrap_or("http://localhost:9933"); - let key_type = &self.key_type; - - // Just checking - let _key_type_id = KeyTypeId::try_from(key_type.as_str()) + let base_path = self.shared_params.base_path.as_ref() + .ok_or_else(|| Error::Other("please supply base path".into()))?; + + let (keystore, public) = match self.keystore_params.keystore_config(base_path)? { + KeystoreConfig::Path { path, password } => { + let public = with_crypto_scheme!( + self.crypto_scheme.scheme, + to_vec(&suri, password.clone()) + )?; + let keystore = KeyStore::open(path, password) + .map_err(|e| format!("{}", e))?; + (keystore, public) + }, + _ => unreachable!("keystore_config always returns path and password; qed") + }; + + let key_type = KeyTypeId::try_from(self.key_type.as_str()) .map_err(|_| { Error::Other("Cannot convert argument to keytype: argument should be 4-character string".into()) })?; - - insert_key::( - &node_url, - key_type.to_string(), - suri, - sp_core::Bytes(public), - ); + keystore.write().insert_unknown(key_type, &suri, &public[..]) + .map_err(|e| Error::Other(format!("{:?}", e)))?; Ok(()) } @@ -110,23 +97,7 @@ impl CliConfiguration for InsertCmd { } } -fn to_vec(uri: &str, pass: Option<&str>) -> Result, Error> { +fn to_vec(uri: &str, pass: Option) -> Result, Error> { let p = utils::pair_from_suri::

(uri, pass)?; Ok(p.public().as_ref().to_vec()) } - -fn insert_key(url: &str, key_type: String, suri: String, public: Bytes) - where - H: DeserializeOwned + Serialize + Send + Sync + 'static, -{ - rt::run( - http::connect(&url) - .and_then(|client: AuthorClient| { - client.insert_key(key_type, suri, public).map(|_| ()) - }) - .map_err(|e| { - println!("Error inserting key: {:?}", e); - }) - ); -} - diff --git a/client/cli/src/commands/key.rs b/client/cli/src/commands/key.rs index 13a59c527188e..eff2cf687e30c 100644 --- a/client/cli/src/commands/key.rs +++ b/client/cli/src/commands/key.rs @@ -19,7 +19,6 @@ use crate::{Error, substrate_cli_subcommands}; use structopt::StructOpt; -use serde::{de::DeserializeOwned, Serialize}; use super::{ insert::InsertCmd, @@ -50,15 +49,12 @@ pub enum KeySubcommand { impl KeySubcommand { /// run the key subcommands - pub fn run(&self) -> Result<(), Error> - where - Hash: DeserializeOwned + Serialize + Send + Sync + 'static, - { + pub fn run(&self) -> Result<(), Error> { match self { KeySubcommand::GenerateNodeKey(cmd) => cmd.run(), KeySubcommand::Generate(cmd) => cmd.run(), KeySubcommand::InspectKey(cmd) => cmd.run(), - KeySubcommand::Insert(cmd) => cmd.run::(), + KeySubcommand::Insert(cmd) => cmd.run(), KeySubcommand::InspectNodeKey(cmd) => cmd.run(), } } diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs index cf0b8eb760335..1e79044c55092 100644 --- a/client/cli/src/commands/sign.rs +++ b/client/cli/src/commands/sign.rs @@ -20,7 +20,7 @@ use crate::{error, utils, CliConfiguration, KeystoreParams, with_crypto_scheme, CryptoSchemeFlag}; use super::SharedParams; use structopt::StructOpt; -use sp_core::crypto::ExposeSecret; +use sp_core::crypto::SecretString; /// The `sign` command #[derive(Debug, StructOpt)] @@ -64,7 +64,6 @@ impl SignCmd { let message = utils::read_message(self.message.as_ref(), self.hex)?; let suri = utils::read_uri(self.suri.as_ref())?; let password = self.keystore_params.read_password()?; - let password = password.as_ref().map(|s| s.expose_secret().as_str()); let signature = with_crypto_scheme!( self.crypto_scheme.scheme, @@ -86,7 +85,7 @@ impl CliConfiguration for SignCmd { } } -fn sign(suri: &str, password: Option<&str>, message: Vec) -> error::Result { +fn sign(suri: &str, password: Option, message: Vec) -> error::Result { let pair = utils::pair_from_suri::

(suri, password)?; Ok(format!("{}", hex::encode(pair.sign(&message)))) } diff --git a/client/cli/src/commands/utils.rs b/client/cli/src/commands/utils.rs index 359b7f257b4a6..96b6128057a6e 100644 --- a/client/cli/src/commands/utils.rs +++ b/client/cli/src/commands/utils.rs @@ -25,7 +25,7 @@ use sp_core::{ use sp_runtime::{MultiSigner, traits::IdentifyAccount}; use crate::{OutputType, error::{self, Error}}; use serde_json::json; -use sp_core::crypto::{SecretString, ExposeSecret}; +use sp_core::crypto::{SecretString, Zeroize, ExposeSecret}; /// Public key type for Runtime pub type PublicFor

=

::Public; @@ -152,10 +152,17 @@ pub fn print_from_uri( } /// generate a pair from suri -pub fn pair_from_suri(suri: &str, password: Option<&str>) -> Result { - let pair = P::from_string(suri, password) - .map_err(|err| format!("Invalid phrase {:?}", err))?; - Ok(pair) +pub fn pair_from_suri(suri: &str, password: Option) -> Result { + let result = if let Some(pass) = password { + let mut pass_str = pass.expose_secret().clone(); + let pair = P::from_string(suri, Some(&pass_str)); + pass_str.zeroize(); + pair + } else { + P::from_string(suri, None) + }; + + Ok(result.map_err(|err| format!("Invalid phrase {:?}", err))?) } /// formats seed as hex diff --git a/client/cli/src/params/keystore_params.rs b/client/cli/src/params/keystore_params.rs index 751bba57e7a12..2ecbe6d9d4b95 100644 --- a/client/cli/src/params/keystore_params.rs +++ b/client/cli/src/params/keystore_params.rs @@ -22,9 +22,8 @@ use std::fs; use std::path::PathBuf; use structopt::StructOpt; use crate::error; -use sp_core::crypto::SecretString; +use sp_core::crypto::{SecretString, Zeroize}; use std::str::FromStr; -use zeroize::Zeroize; /// default sub directory for the key store const DEFAULT_KEYSTORE_CONFIG_PATH: &'static str = "keystore"; diff --git a/frame/system/src/extras.rs b/frame/system/src/extras.rs deleted file mode 100644 index 95df5d0fa7abe..0000000000000 --- a/frame/system/src/extras.rs +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2018-2020 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -//! Strongly typed interface for SignedExtensions -//! - -use sp_runtime::traits::{StaticLookup, SignedExtension}; -use sp_runtime::generic::Era; - -/// AccountIndex type for Runtime -pub type IndexFor = ::Index; -/// Call type for Runtime -pub type CallFor = ::Call; -/// Address type for runtime. -pub type AddressFor = <::Lookup as StaticLookup>::Source; -/// Hash for runtime. -pub type HashFor = ::Hash; -/// AccountId type for runtime. -pub type AccountIdFor = ::AccountId; - -/// Strongly typed interface for the `SignedExtensions` that should be included in extrinsics -/// for them to valid for your runtime. -pub trait SignedExtensionProvider: crate::Trait { - /// Concrete SignedExtension type. - type Extra: SignedExtension; - - /// Concrete type for params used to construct the `SignedExtension`-Data - type Builder: ExtrasParamsBuilder; - - /// Retrieve an instance of the builder. - fn extras_params_builder() -> Self::Builder; - - /// Construct extras and optionally additional_signed data for inclusion in extrinsics. - fn construct_extras(input: >::ExtrasParams) -> - SignedExtensionData; -} - - -/// Extras that should be included in extrinsics, -/// additional data is provided for call sites that don't have access to storage. -pub struct SignedExtensionData { - /// Signed extras - pub extra: S, - /// Additional data for the signed extras. - pub additional: Option, -} - -/// Builder for `ExtrasParams`, used by runtimes to define data required for constructing signed extras -pub trait ExtrasParamsBuilder { - /// Concrete type passed to `construct_extras`. - type ExtrasParams; - - /// Sets the tip - fn set_tip(self, tip: u128) -> Self; - - /// Sets the block hash for the start of the era this transaction is valid for. - /// this is an additional signed data and is therefore **optional** - /// only provide it you know `construct_extras` will be called outside of an externalities environment. - fn set_starting_era_hash(self, hash: T::Hash) -> Self; - - /// Sets the genesis hash - /// this is an additional signed data and is therefore **optional** - /// only provide it you know `construct_extras` will be called outside of an externalities environment. - fn set_genesis_hash(self, hash: T::Hash) -> Self; - - /// build the extras params - fn build(self, nonce: T::Index, era: Era) -> Self::ExtrasParams; -} diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index 55ed3509b2a75..ad68e97d462ad 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -132,7 +132,6 @@ use codec::{Encode, Decode, FullCodec, EncodeLike}; use sp_io::TestExternalities; pub mod offchain; -pub mod extras; #[cfg(test)] pub(crate) mod mock; From cc7542cfbf6d889ce6f6e256e7a0fae1ce45aba0 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 14 Jul 2020 18:03:28 +0100 Subject: [PATCH 69/77] remove unnecessary SharedParams --- client/cli/src/commands/generate.rs | 16 +--------------- client/cli/src/commands/generate_node_key.rs | 12 +----------- client/cli/src/commands/insert.rs | 12 +----------- client/cli/src/commands/inspect.rs | 18 ++---------------- client/cli/src/commands/inspect_node_key.rs | 12 +----------- client/cli/src/commands/key.rs | 12 +----------- 6 files changed, 7 insertions(+), 75 deletions(-) diff --git a/client/cli/src/commands/generate.rs b/client/cli/src/commands/generate.rs index a343db370513d..9eeca55a2ee25 100644 --- a/client/cli/src/commands/generate.rs +++ b/client/cli/src/commands/generate.rs @@ -19,7 +19,7 @@ use bip39::{MnemonicType, Mnemonic, Language}; use structopt::StructOpt; use crate::{ - utils::print_from_uri, CliConfiguration, KeystoreParams, SharedParams, Error, + utils::print_from_uri, KeystoreParams, Error, with_crypto_scheme, NetworkSchemeFlag, OutputTypeFlag, CryptoSchemeFlag, }; @@ -35,10 +35,6 @@ pub struct GenerateCmd { #[structopt(flatten)] pub keystore_params: KeystoreParams, - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - #[allow(missing_docs)] #[structopt(flatten)] pub network_scheme: NetworkSchemeFlag, @@ -82,16 +78,6 @@ impl GenerateCmd { } } -impl CliConfiguration for GenerateCmd { - fn shared_params(&self) -> &SharedParams { - &self.shared_params - } - - fn keystore_params(&self) -> Option<&KeystoreParams> { - Some(&self.keystore_params) - } -} - #[cfg(test)] mod tests { use super::GenerateCmd; diff --git a/client/cli/src/commands/generate_node_key.rs b/client/cli/src/commands/generate_node_key.rs index c01406508c367..9ee04d23e3416 100644 --- a/client/cli/src/commands/generate_node_key.rs +++ b/client/cli/src/commands/generate_node_key.rs @@ -17,7 +17,7 @@ //! Implementation of the `generate-node-key` subcommand -use crate::{Error, SharedParams, CliConfiguration}; +use crate::Error; use structopt::StructOpt; use std::{path::PathBuf, fs}; use libp2p::identity::{ed25519 as libp2p_ed25519, PublicKey}; @@ -32,10 +32,6 @@ pub struct GenerateNodeKeyCmd { /// Name of file to save secret key to. #[structopt(long)] file: PathBuf, - - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, } impl GenerateNodeKeyCmd { @@ -55,12 +51,6 @@ impl GenerateNodeKeyCmd { } } -impl CliConfiguration for GenerateNodeKeyCmd { - fn shared_params(&self) -> &SharedParams { - &self.shared_params - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/client/cli/src/commands/insert.rs b/client/cli/src/commands/insert.rs index e4068c0c9176c..0625f9bb89e4a 100644 --- a/client/cli/src/commands/insert.rs +++ b/client/cli/src/commands/insert.rs @@ -17,7 +17,7 @@ //! Implementation of the `insert` subcommand -use crate::{Error, CliConfiguration, KeystoreParams, with_crypto_scheme, CryptoSchemeFlag, SharedParams, utils}; +use crate::{Error, KeystoreParams, CryptoSchemeFlag, SharedParams, utils, with_crypto_scheme}; use structopt::StructOpt; use sp_core::{crypto::KeyTypeId, traits::BareCryptoStore}; use std::convert::TryFrom; @@ -87,16 +87,6 @@ impl InsertCmd { } } -impl CliConfiguration for InsertCmd { - fn shared_params(&self) -> &SharedParams { - &self.shared_params - } - - fn keystore_params(&self) -> Option<&KeystoreParams> { - Some(&self.keystore_params) - } -} - fn to_vec(uri: &str, pass: Option) -> Result, Error> { let p = utils::pair_from_suri::

(uri, pass)?; Ok(p.public().as_ref().to_vec()) diff --git a/client/cli/src/commands/inspect.rs b/client/cli/src/commands/inspect.rs index 09dfafb5c2086..3356d7ca07ad8 100644 --- a/client/cli/src/commands/inspect.rs +++ b/client/cli/src/commands/inspect.rs @@ -18,8 +18,8 @@ //! Implementation of the `inspect` subcommand use crate::{ - utils, CliConfiguration, KeystoreParams, SharedParams, - with_crypto_scheme, NetworkSchemeFlag, OutputTypeFlag, CryptoSchemeFlag, Error, + utils, KeystoreParams, with_crypto_scheme, NetworkSchemeFlag, + OutputTypeFlag, CryptoSchemeFlag, Error, }; use structopt::StructOpt; /// The `inspect` command @@ -40,10 +40,6 @@ pub struct InspectCmd { #[structopt(flatten)] pub keystore_params: KeystoreParams, - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - #[allow(missing_docs)] #[structopt(flatten)] pub network_scheme: NetworkSchemeFlag, @@ -78,16 +74,6 @@ impl InspectCmd { } } -impl CliConfiguration for InspectCmd { - fn shared_params(&self) -> &SharedParams { - &self.shared_params - } - - fn keystore_params(&self) -> Option<&KeystoreParams> { - Some(&self.keystore_params) - } -} - #[cfg(test)] mod tests { use super::InspectCmd; diff --git a/client/cli/src/commands/inspect_node_key.rs b/client/cli/src/commands/inspect_node_key.rs index a574b3a9de0d0..be0b88589d5e9 100644 --- a/client/cli/src/commands/inspect_node_key.rs +++ b/client/cli/src/commands/inspect_node_key.rs @@ -17,7 +17,7 @@ //! Implementation of the `inspect-node-key` subcommand -use crate::{Error, SharedParams, NetworkSchemeFlag, CliConfiguration}; +use crate::{Error, NetworkSchemeFlag}; use std::fs; use libp2p::identity::{PublicKey, ed25519}; use std::path::PathBuf; @@ -34,10 +34,6 @@ pub struct InspectNodeKeyCmd { #[structopt(long)] file: PathBuf, - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - #[allow(missing_docs)] #[structopt(flatten)] pub network_scheme: NetworkSchemeFlag, @@ -60,12 +56,6 @@ impl InspectNodeKeyCmd { } } -impl CliConfiguration for InspectNodeKeyCmd { - fn shared_params(&self) -> &SharedParams { - &self.shared_params - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/client/cli/src/commands/key.rs b/client/cli/src/commands/key.rs index eff2cf687e30c..61145eace1071 100644 --- a/client/cli/src/commands/key.rs +++ b/client/cli/src/commands/key.rs @@ -17,7 +17,7 @@ //! Key related CLI utilities -use crate::{Error, substrate_cli_subcommands}; +use crate::Error; use structopt::StructOpt; use super::{ @@ -59,13 +59,3 @@ impl KeySubcommand { } } } - -// CliConfiguration implementation -substrate_cli_subcommands!( - KeySubcommand => - GenerateNodeKey, - InspectNodeKey, - Generate, - InspectKey, - Insert -); From f4af111a185df987a92403761df27576aff2a290 Mon Sep 17 00:00:00 2001 From: Seun Date: Wed, 22 Jul 2020 13:39:59 +0100 Subject: [PATCH 70/77] add validation to vanity pattern, remove unused arg --- bin/utils/subkey/src/lib.rs | 2 +- client/cli/src/commands/insert.rs | 3 ++- client/cli/src/commands/vanity.rs | 26 ++++++++++++-------------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/bin/utils/subkey/src/lib.rs b/bin/utils/subkey/src/lib.rs index bd7b89002eb25..2e4c7a350fe3e 100644 --- a/bin/utils/subkey/src/lib.rs +++ b/bin/utils/subkey/src/lib.rs @@ -78,4 +78,4 @@ pub fn run() -> Result<(), Error> }; Ok(()) -} \ No newline at end of file +} diff --git a/client/cli/src/commands/insert.rs b/client/cli/src/commands/insert.rs index 0625f9bb89e4a..cb5b274c1ed8d 100644 --- a/client/cli/src/commands/insert.rs +++ b/client/cli/src/commands/insert.rs @@ -80,7 +80,8 @@ impl InsertCmd { Error::Other("Cannot convert argument to keytype: argument should be 4-character string".into()) })?; - keystore.write().insert_unknown(key_type, &suri, &public[..]) + keystore.write() + .insert_unknown(key_type, &suri, &public[..]) .map_err(|e| Error::Other(format!("{:?}", e)))?; Ok(()) diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index 7998c2ab84d17..c413b803f1315 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -34,13 +34,9 @@ use sp_runtime::traits::IdentifyAccount; about = "Generate a seed that provides a vanity address" )] pub struct VanityCmd { - /// Number of keys to generate - #[structopt(long, short)] - number: String, - /// Desired pattern - #[structopt(long)] - pattern: Option, + #[structopt(long, parse(try_from_str = assert_non_empty_string))] + pattern: String, #[allow(missing_docs)] #[structopt(flatten)] @@ -62,10 +58,7 @@ pub struct VanityCmd { impl VanityCmd { /// Run the command pub fn run(&self) -> error::Result<()> { - let desired: &str = self.pattern.as_ref() - .map(String::as_str) - .unwrap_or(""); - let formated_seed = with_crypto_scheme!(self.crypto_scheme.scheme, generate_key(desired))?; + let formated_seed = with_crypto_scheme!(self.crypto_scheme.scheme, generate_key(&self.pattern))?; use utils::print_from_uri; with_crypto_scheme!( self.crypto_scheme.scheme, @@ -93,10 +86,6 @@ fn generate_key(desired: &str) -> Result Pair::Public: IdentifyAccount, ::AccountId: Ss58Codec, { - if desired.is_empty() { - return Err("Pattern must not be empty"); - } - println!("Generating key containing pattern '{}'", desired); let top = 45 + (desired.len() * 48); @@ -165,6 +154,15 @@ fn calculate_score(_desired: &str, key: &str) -> usize { 0 } +/// checks that `pattern` is non-empty +fn assert_non_empty_string(pattern: &str) -> Result { + if pattern.is_empty() { + Err("Pattern must not be empty") + } else { + Ok(pattern.to_string()) + } +} + #[cfg(test)] mod tests { From cd0f083ada803b581a0e7595cac1dcff8ff5d7f3 Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 10 Aug 2020 23:23:24 +0100 Subject: [PATCH 71/77] remove SharedParams from Sign, Vanity, Verify --- client/cli/src/commands/mod.rs | 15 +-------------- client/cli/src/commands/sign.rs | 17 +---------------- client/cli/src/commands/vanity.rs | 14 ++------------ client/cli/src/commands/verify.rs | 16 +--------------- client/cli/src/runner.rs | 3 --- 5 files changed, 5 insertions(+), 60 deletions(-) diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 4cfe5a81b16ee..f5aa0c53d51e9 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -39,7 +39,6 @@ pub mod tests; use std::fmt::Debug; use structopt::StructOpt; -use crate::params::SharedParams; pub use self::{ build_spec_cmd::BuildSpecCmd, @@ -88,15 +87,6 @@ pub enum Subcommand { /// Remove the whole chain data. PurgeChain(PurgeChainCmd), - - /// Sign a message, with a given (secret) key - Sign(SignCmd), - - /// Verify a signature for a message, provided on STDIN, with a given (public or secret) key. - Verify(VerifyCmd), - - /// Generate a seed that provides a vanity address. - Vanity(VanityCmd), } // TODO: move to config.rs? @@ -455,8 +445,5 @@ substrate_cli_subcommands!( ImportBlocks, CheckBlock, Revert, - PurgeChain, - Sign, - Verify, - Vanity + PurgeChain ); diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs index 1e79044c55092..51013daa29a9a 100644 --- a/client/cli/src/commands/sign.rs +++ b/client/cli/src/commands/sign.rs @@ -17,8 +17,7 @@ // along with this program. If not, see . //! Implementation of the `sign` subcommand -use crate::{error, utils, CliConfiguration, KeystoreParams, with_crypto_scheme, CryptoSchemeFlag}; -use super::SharedParams; +use crate::{error, utils, with_crypto_scheme, CryptoSchemeFlag, KeystoreParams}; use structopt::StructOpt; use sp_core::crypto::SecretString; @@ -48,10 +47,6 @@ pub struct SignCmd { #[structopt(flatten)] pub keystore_params: KeystoreParams, - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - #[allow(missing_docs)] #[structopt(flatten)] pub crypto_scheme: CryptoSchemeFlag, @@ -75,16 +70,6 @@ impl SignCmd { } } -impl CliConfiguration for SignCmd { - fn shared_params(&self) -> &SharedParams { - &self.shared_params - } - - fn keystore_params(&self) -> Option<&KeystoreParams> { - Some(&self.keystore_params) - } -} - fn sign(suri: &str, password: Option, message: Vec) -> error::Result { let pair = utils::pair_from_suri::

(suri, password)?; Ok(format!("{}", hex::encode(pair.sign(&message)))) diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index c413b803f1315..948a7f506e4e4 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -19,8 +19,8 @@ //! implementation of the `vanity` subcommand use crate::{ - error, utils, CliConfiguration, with_crypto_scheme, - CryptoSchemeFlag, NetworkSchemeFlag, OutputTypeFlag, SharedParams, + error, utils, with_crypto_scheme, + CryptoSchemeFlag, NetworkSchemeFlag, OutputTypeFlag, }; use sp_core::crypto::Ss58Codec; use structopt::StructOpt; @@ -38,10 +38,6 @@ pub struct VanityCmd { #[structopt(long, parse(try_from_str = assert_non_empty_string))] pattern: String, - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - #[allow(missing_docs)] #[structopt(flatten)] pub network_scheme: NetworkSchemeFlag, @@ -73,12 +69,6 @@ impl VanityCmd { } } -impl CliConfiguration for VanityCmd { - fn shared_params(&self) -> &SharedParams { - &self.shared_params - } -} - /// genertae a key based on given pattern fn generate_key(desired: &str) -> Result where diff --git a/client/cli/src/commands/verify.rs b/client/cli/src/commands/verify.rs index 9cfb65d142203..5b1512c5dd423 100644 --- a/client/cli/src/commands/verify.rs +++ b/client/cli/src/commands/verify.rs @@ -18,10 +18,7 @@ //! implementation of the `verify` subcommand -use crate::{ - error, utils, with_crypto_scheme, - CliConfiguration, CryptoSchemeFlag, SharedParams, -}; +use crate::{error, utils, with_crypto_scheme, CryptoSchemeFlag}; use sp_core::{Public, crypto::Ss58Codec}; use structopt::StructOpt; @@ -49,10 +46,6 @@ pub struct VerifyCmd { #[structopt(long)] hex: bool, - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - #[allow(missing_docs)] #[structopt(flatten)] pub crypto_scheme: CryptoSchemeFlag, @@ -77,13 +70,6 @@ impl VerifyCmd { } } -impl CliConfiguration for VerifyCmd { - fn shared_params(&self) -> &SharedParams { - &self.shared_params - } -} - - fn verify(sig_data: Vec, message: Vec, uri: &str) -> error::Result<()> where Pair: sp_core::Pair, diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index b3756ea824a32..bdbf55eb8326a 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -218,9 +218,6 @@ impl Runner { let (client, _, _, task_manager) = builder(self.config)?; run_until_exit(self.tokio_runtime, cmd.run(client, chain_spec), task_manager) }, - Subcommand::Sign(cmd) => cmd.run(), - Subcommand::Verify(cmd) => cmd.run(), - Subcommand::Vanity(cmd) => cmd.run() } } From 4dc44e7b56d3f19e1d71241a18d1468216dcdd05 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 11 Aug 2020 13:07:22 +0100 Subject: [PATCH 72/77] remove SharedParams from ModuleIdCmd, remove expect from Verify, new line to Cargo.toml --- bin/node/cli/Cargo.toml | 1 + bin/node/cli/src/cli.rs | 11 ++++++++++- bin/node/cli/src/command.rs | 3 +++ client/cli/src/commands/verify.rs | 5 +++-- .../frame/frame-utilities-cli/src/module_id.rs | 17 ++--------------- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index c67cc7e0f1169..ec2a5fce32854 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -100,6 +100,7 @@ node-executor = { version = "2.0.0-rc5", path = "../executor" } sc-cli = { version = "0.8.0-rc5", optional = true, path = "../../../client/cli" } frame-benchmarking-cli = { version = "2.0.0-rc5", optional = true, path = "../../../utils/frame/benchmarking-cli" } node-inspect = { version = "0.8.0-rc5", optional = true, path = "../inspect" } + # WASM-specific dependencies wasm-bindgen = { version = "0.2.57", optional = true } wasm-bindgen-futures = { version = "0.4.7", optional = true } diff --git a/bin/node/cli/src/cli.rs b/bin/node/cli/src/cli.rs index f26483301e12a..42a13fcb39070 100644 --- a/bin/node/cli/src/cli.rs +++ b/bin/node/cli/src/cli.rs @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use sc_cli::{RunCmd, KeySubcommand}; +use sc_cli::{RunCmd, KeySubcommand, SignCmd, VanityCmd, VerifyCmd}; use structopt::StructOpt; /// An overarching CLI command definition. @@ -50,4 +50,13 @@ pub enum Subcommand { /// The custom benchmark subcommmand benchmarking runtime pallets. #[structopt(name = "benchmark", about = "Benchmark runtime pallets.")] Benchmark(frame_benchmarking_cli::BenchmarkCmd), + + /// Verify a signature for a message, provided on STDIN, with a given (public or secret) key. + Verify(VerifyCmd), + + /// Generate a seed that provides a vanity address. + Vanity(VanityCmd), + + /// Sign a message, with a given (secret) key. + Sign(SignCmd), } diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index 9c07a5df49a0f..10e9413702b81 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -94,6 +94,9 @@ pub fn run() -> Result<()> { } } Some(Subcommand::Key(cmd)) => cmd.run(), + Some(Subcommand::Sign(cmd)) => cmd.run(), + Some(Subcommand::Verify(cmd)) => cmd.run(), + Some(Subcommand::Vanity(cmd)) => cmd.run(), Some(Subcommand::Base(subcommand)) => { let runner = cli.create_runner(subcommand)?; runner.run_subcommand(subcommand, |config| { diff --git a/client/cli/src/commands/verify.rs b/client/cli/src/commands/verify.rs index 5b1512c5dd423..ad16c11d5e441 100644 --- a/client/cli/src/commands/verify.rs +++ b/client/cli/src/commands/verify.rs @@ -89,8 +89,9 @@ fn verify(sig_data: Vec, message: Vec, uri: &str) -> error::Result Pair::Public::from_slice(pubkey_vec.as_slice()) } else { Pair::Public::from_string(uri) - .ok() - .expect("Invalid URI; expecting either a secret URI or a public URI.") + .map_err(|_| { + error::Error::Other(format!("Invalid URI; expecting either a secret URI or a public URI.")) + })? }; if Pair::verify(&signature, &message, &pubkey) { diff --git a/utils/frame/frame-utilities-cli/src/module_id.rs b/utils/frame/frame-utilities-cli/src/module_id.rs index 2967507edcff2..3739d668e3d12 100644 --- a/utils/frame/frame-utilities-cli/src/module_id.rs +++ b/utils/frame/frame-utilities-cli/src/module_id.rs @@ -18,8 +18,8 @@ //! Implementation of the `moduleid` subcommand use sc_cli::{ - Error, SharedParams, utils::print_from_uri, CryptoSchemeFlag, - OutputTypeFlag, KeystoreParams, CliConfiguration, with_crypto_scheme, + Error, utils::print_from_uri, CryptoSchemeFlag, + OutputTypeFlag, KeystoreParams, with_crypto_scheme, }; use sp_runtime::ModuleId; use sp_runtime::traits::AccountIdConversion; @@ -48,10 +48,6 @@ pub struct ModuleIdCmd { )] pub network: Ss58AddressFormat, - #[allow(missing_docs)] - #[structopt(flatten)] - pub shared_params: SharedParams, - #[allow(missing_docs)] #[structopt(flatten)] pub output_scheme: OutputTypeFlag, @@ -98,12 +94,3 @@ impl ModuleIdCmd { } } -impl CliConfiguration for ModuleIdCmd { - fn shared_params(&self) -> &SharedParams { - &self.shared_params - } - - fn keystore_params(&self) -> Option<&KeystoreParams> { - Some(&self.keystore_params) - } -} From 3bb63c0a5353ec8a918e64c75403408094a3530d Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 11 Aug 2020 13:11:56 +0100 Subject: [PATCH 73/77] remove SharedParams from InsertCmd --- client/cli/src/commands/insert.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/client/cli/src/commands/insert.rs b/client/cli/src/commands/insert.rs index cb5b274c1ed8d..d70671024f548 100644 --- a/client/cli/src/commands/insert.rs +++ b/client/cli/src/commands/insert.rs @@ -42,10 +42,6 @@ pub struct InsertCmd { #[structopt(long)] key_type: String, - #[allow(missing_docs)] - #[structopt(flatten)] - pub keystore_params: KeystoreParams, - #[allow(missing_docs)] #[structopt(flatten)] pub shared_params: SharedParams, @@ -82,9 +78,7 @@ impl InsertCmd { keystore.write() .insert_unknown(key_type, &suri, &public[..]) - .map_err(|e| Error::Other(format!("{:?}", e)))?; - - Ok(()) + .map_err(|e| Error::Other(format!("{:?}", e))) } } From 30b49fd4c3e289e77bbd8f24dc1883d5180116fb Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 11 Aug 2020 14:52:03 +0100 Subject: [PATCH 74/77] =?UTF-8?q?=F0=9F=A4=A6=F0=9F=8F=BE=E2=80=8D?= =?UTF-8?q?=E2=99=82=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/cli/src/commands/insert.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client/cli/src/commands/insert.rs b/client/cli/src/commands/insert.rs index d70671024f548..5e4a0d42ffefc 100644 --- a/client/cli/src/commands/insert.rs +++ b/client/cli/src/commands/insert.rs @@ -46,6 +46,10 @@ pub struct InsertCmd { #[structopt(flatten)] pub shared_params: SharedParams, + #[allow(missing_docs)] + #[structopt(flatten)] + pub keystore_params: KeystoreParams, + #[allow(missing_docs)] #[structopt(flatten)] pub crypto_scheme: CryptoSchemeFlag, @@ -78,7 +82,9 @@ impl InsertCmd { keystore.write() .insert_unknown(key_type, &suri, &public[..]) - .map_err(|e| Error::Other(format!("{:?}", e))) + .map_err(|e| Error::Other(format!("{:?}", e)))?; + + Ok(()) } } From f145c8e4c45da56254c0dfe55b5057b530c0a5e2 Mon Sep 17 00:00:00 2001 From: Seun Date: Tue, 11 Aug 2020 14:54:07 +0100 Subject: [PATCH 75/77] deleted prometheus.yml --- .maintain/prometheus.yml | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .maintain/prometheus.yml diff --git a/.maintain/prometheus.yml b/.maintain/prometheus.yml deleted file mode 100644 index 4ab045ac3210c..0000000000000 --- a/.maintain/prometheus.yml +++ /dev/null @@ -1,5 +0,0 @@ -scrape_configs: - - job_name: 'polkadot' - scrape_interval: 5s - static_configs: - - targets: ['localhost:9615'] \ No newline at end of file From 94511ab7e138b246575a4545fb88d607be75e59f Mon Sep 17 00:00:00 2001 From: Seun Date: Mon, 17 Aug 2020 10:00:27 +0100 Subject: [PATCH 76/77] move a few things around --- client/cli/src/commands/mod.rs | 3 -- client/cli/src/commands/sign.rs | 22 ++++++++++++ client/cli/src/commands/tests.rs | 42 ---------------------- client/cli/src/commands/vanity.rs | 7 ++++ client/cli/src/params/mod.rs | 49 +++++++++++++++++++++++++- client/cli/src/params/shared_params.rs | 46 ------------------------ 6 files changed, 77 insertions(+), 92 deletions(-) delete mode 100644 client/cli/src/commands/tests.rs diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index f5aa0c53d51e9..4271c39867353 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -34,9 +34,6 @@ mod inspect; mod key; pub mod utils; -#[cfg(test)] -pub mod tests; - use std::fmt::Debug; use structopt::StructOpt; diff --git a/client/cli/src/commands/sign.rs b/client/cli/src/commands/sign.rs index 51013daa29a9a..605fd5b12313f 100644 --- a/client/cli/src/commands/sign.rs +++ b/client/cli/src/commands/sign.rs @@ -74,3 +74,25 @@ fn sign(suri: &str, password: Option, message: V let pair = utils::pair_from_suri::

(suri, password)?; Ok(format!("{}", hex::encode(pair.sign(&message)))) } + +#[cfg(test)] +mod test { + use super::SignCmd; + use structopt::StructOpt; + + #[test] + fn sign() { + let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; + + let sign = SignCmd::from_iter(&[ + "sign", + "--suri", + seed, + "--message", + &seed[2..], + "--password", + "12345" + ]); + assert!(sign.run().is_ok()); + } +} diff --git a/client/cli/src/commands/tests.rs b/client/cli/src/commands/tests.rs deleted file mode 100644 index f05014c475349..0000000000000 --- a/client/cli/src/commands/tests.rs +++ /dev/null @@ -1,42 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -use super::{SignCmd, VanityCmd}; -use structopt::StructOpt; - -#[test] -fn sign() { - let seed = "0xad1fb77243b536b90cfe5f0d351ab1b1ac40e3890b41dc64f766ee56340cfca5"; - - let sign = SignCmd::from_iter(&[ - "sign", - "--suri", - seed, - "--message", - &seed[2..], - "--password", - "12345" - ]); - assert!(sign.run().is_ok()); -} - -#[test] -fn vanity() { - let vanity = VanityCmd::from_iter(&["vanity", "--number", "1", "--pattern", "j"]); - assert!(vanity.run().is_ok()); -} diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index 948a7f506e4e4..3e31bcc0a3e32 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -161,6 +161,13 @@ mod tests { use sp_core::sr25519; #[cfg(feature = "bench")] use test::Bencher; + use structopt::StructOpt; + + #[test] + fn vanity() { + let vanity = VanityCmd::from_iter(&["vanity", "--number", "1", "--pattern", "j"]); + assert!(vanity.run().is_ok()); + } #[test] fn test_generation_with_single_char() { diff --git a/client/cli/src/params/mod.rs b/client/cli/src/params/mod.rs index 5c08241169fc9..5245c1220fb19 100644 --- a/client/cli/src/params/mod.rs +++ b/client/cli/src/params/mod.rs @@ -25,8 +25,11 @@ mod pruning_params; mod shared_params; mod transaction_pool_params; -use std::{fmt::Debug, str::FromStr}; +use std::{fmt::Debug, str::FromStr, convert::TryFrom}; use sp_runtime::{generic::BlockId, traits::{Block as BlockT, NumberFor}}; +use sp_core::crypto::Ss58AddressFormat; +use crate::arg_enums::{OutputType, CryptoScheme}; +use structopt::StructOpt; pub use crate::params::database_params::*; pub use crate::params::import_params::*; @@ -114,6 +117,50 @@ impl BlockNumberOrHash { } } + +/// Optional flag for specifying crypto algorithm +#[derive(Debug, StructOpt)] +pub struct CryptoSchemeFlag { + /// cryptography scheme + #[structopt( + long, + value_name = "SCHEME", + possible_values = &CryptoScheme::variants(), + case_insensitive = true, + default_value = "Sr25519" + )] + pub scheme: CryptoScheme, +} + +/// Optional flag for specifying output type +#[derive(Debug, StructOpt)] +pub struct OutputTypeFlag { + /// output format + #[structopt( + long, + value_name = "FORMAT", + possible_values = &OutputType::variants(), + case_insensitive = true, + default_value = "Text" + )] + pub output_type: OutputType, +} + +/// Optional flag for specifying network scheme +#[derive(Debug, StructOpt)] +pub struct NetworkSchemeFlag { + /// network address format + #[structopt( + long, + value_name = "NETWORK", + possible_values = &Ss58AddressFormat::all_names()[..], + parse(try_from_str = Ss58AddressFormat::try_from), + case_insensitive = true, + default_value = "polkadot" + )] + pub network: Ss58AddressFormat, +} + #[cfg(test)] mod tests { use super::*; diff --git a/client/cli/src/params/shared_params.rs b/client/cli/src/params/shared_params.rs index ec6cc280c912c..ad9ab04070563 100644 --- a/client/cli/src/params/shared_params.rs +++ b/client/cli/src/params/shared_params.rs @@ -19,9 +19,6 @@ use sc_service::config::BasePath; use std::path::PathBuf; use structopt::StructOpt; -use sp_core::crypto::Ss58AddressFormat; -use crate::arg_enums::{OutputType, CryptoScheme}; -use std::convert::TryFrom; /// Shared parameters used by all `CoreParams`. #[derive(Debug, StructOpt)] @@ -46,49 +43,6 @@ pub struct SharedParams { pub log: Vec, } -/// Optional flag for specifying crypto algorithm -#[derive(Debug, StructOpt)] -pub struct CryptoSchemeFlag { - /// cryptography scheme - #[structopt( - long, - value_name = "SCHEME", - possible_values = &CryptoScheme::variants(), - case_insensitive = true, - default_value = "Sr25519" - )] - pub scheme: CryptoScheme, -} - -/// Optional flag for specifying output type -#[derive(Debug, StructOpt)] -pub struct OutputTypeFlag { - /// output format - #[structopt( - long, - value_name = "FORMAT", - possible_values = &OutputType::variants(), - case_insensitive = true, - default_value = "Text" - )] - pub output_type: OutputType, -} - -/// Optional flag for specifying network scheme -#[derive(Debug, StructOpt)] -pub struct NetworkSchemeFlag { - /// network address format - #[structopt( - long, - value_name = "NETWORK", - possible_values = &Ss58AddressFormat::all_names()[..], - parse(try_from_str = Ss58AddressFormat::try_from), - case_insensitive = true, - default_value = "polkadot" - )] - pub network: Ss58AddressFormat, -} - impl SharedParams { /// Specify custom base path. pub fn base_path(&self) -> Option { From 0a50728ce4b00006d4897ac7e95d212d47adc880 Mon Sep 17 00:00:00 2001 From: Seun Date: Thu, 20 Aug 2020 10:01:04 +0100 Subject: [PATCH 77/77] fix vanity test --- client/cli/src/commands/vanity.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/cli/src/commands/vanity.rs b/client/cli/src/commands/vanity.rs index 3e31bcc0a3e32..e6f923f73c45c 100644 --- a/client/cli/src/commands/vanity.rs +++ b/client/cli/src/commands/vanity.rs @@ -40,15 +40,15 @@ pub struct VanityCmd { #[allow(missing_docs)] #[structopt(flatten)] - pub network_scheme: NetworkSchemeFlag, + network_scheme: NetworkSchemeFlag, #[allow(missing_docs)] #[structopt(flatten)] - pub output_scheme: OutputTypeFlag, + output_scheme: OutputTypeFlag, #[allow(missing_docs)] #[structopt(flatten)] - pub crypto_scheme: CryptoSchemeFlag, + crypto_scheme: CryptoSchemeFlag, } impl VanityCmd { @@ -165,7 +165,7 @@ mod tests { #[test] fn vanity() { - let vanity = VanityCmd::from_iter(&["vanity", "--number", "1", "--pattern", "j"]); + let vanity = VanityCmd::from_iter(&["vanity", "--pattern", "j"]); assert!(vanity.run().is_ok()); }