Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Merge Subkey into sc-cli #4954

Merged
111 commits merged into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
73b899b
draft
seunlanlege Feb 17, 2020
3c6d4fd
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege Mar 4, 2020
742df00
revert
seunlanlege Mar 4, 2020
f118c3a
WIP
seunlanlege Mar 10, 2020
0490b61
Merge branch 'seun-merge-sc-cli-and-subkey' of github.com:paritytech/…
seunlanlege Mar 10, 2020
0a1df9c
all that remains is tests
seunlanlege Mar 11, 2020
fa92dfa
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege Mar 13, 2020
386cfcf
update Cargo.lock
seunlanlege Mar 13, 2020
fccf7ba
tests WIP
seunlanlege Mar 13, 2020
26e21da
WIP refactor node-template-runtime and node-runtime
seunlanlege Mar 16, 2020
aea449b
implments sc_cli::RuntimeAdapter for node_template_runtime::Runtime
seunlanlege Mar 17, 2020
f96d007
final draft
seunlanlege Mar 17, 2020
ddbf1a8
fix update_config for subcommands
seunlanlege Mar 18, 2020
fa4feb1
proper AccountId decoding
seunlanlege Mar 18, 2020
4815f3d
test-runtime tests
seunlanlege Mar 18, 2020
f8a6728
revert
seunlanlege Mar 20, 2020
d186457
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege Mar 20, 2020
70d1dbe
move RuntimeAdapter to cli-utils
seunlanlege Mar 20, 2020
aa71995
use &'static str for TryFrom::<&'a str>::Error for Ss58AddressFormat
seunlanlege Mar 20, 2020
65eeefc
tests
seunlanlege Mar 20, 2020
1ee33bb
add frame-system to sc-cli dev-dependencies
seunlanlege Mar 20, 2020
e5336b6
add frame-system to sc-cli dev-dependencies
seunlanlege Mar 20, 2020
643ba68
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege Apr 14, 2020
cf6f0b9
fix ui test
seunlanlege Apr 15, 2020
428d7aa
merge with master
seunlanlege Apr 30, 2020
6a4d66a
wip
seunlanlege May 5, 2020
8536991
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege May 5, 2020
e23b87b
fixed inspect test
seunlanlege May 6, 2020
62e9e0d
bump impl version
seunlanlege May 6, 2020
03ca897
bump impl version, fixx spaces remove todos
seunlanlege May 6, 2020
cd4cad5
pallet-balances-cli, rustc for some reason cannot resolve pallet_bala…
seunlanlege May 7, 2020
5e351b9
wip
seunlanlege May 8, 2020
07413ef
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege May 8, 2020
de123f2
Subcommand::run takes &self
seunlanlege May 8, 2020
c1a5b31
can't believe i missed that 🤦🏾‍♂️
seunlanlege May 8, 2020
57228de
bump wasm-bindgen for some reason
seunlanlege May 8, 2020
9a49f10
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege May 11, 2020
1c84698
adds key subcommand, rename generate-node-key to generate-node-id
seunlanlege May 11, 2020
66d1494
cargo update and crossed fingers 🤞🏽
seunlanlege May 11, 2020
fa4de23
update ui test
seunlanlege May 11, 2020
000b4ad
update more ui tests
seunlanlege May 11, 2020
1c4048a
should be all good now
seunlanlege May 12, 2020
93c38bf
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege May 12, 2020
fce2b0d
revert subkey change
seunlanlege May 12, 2020
cc46757
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege May 12, 2020
f06ce66
revert subkey change
seunlanlege May 12, 2020
f279e14
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege May 15, 2020
7ac9a2e
adds frame-utilities-cli
seunlanlege May 18, 2020
ce642a2
Apply suggestions from code review
seunlanlege May 18, 2020
de582ee
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege May 18, 2020
2937b8c
removes frame from sc-cli, fix license
seunlanlege May 18, 2020
a9d25a3
my editor and ci disagrees on line width
seunlanlege May 18, 2020
f5d0e46
bump spec version
seunlanlege May 18, 2020
1a556ca
turn off default features for parity-scale-codec
seunlanlege May 18, 2020
5a0616b
enable full_crypto feature for sp-core in cli-utils
seunlanlege May 18, 2020
ec22841
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege May 18, 2020
69ab3ee
merge frame-utilities-cli with pallet-balances-cli
seunlanlege May 18, 2020
5f670a6
remove full_crypto feature from sp_core in cli-utils
seunlanlege May 19, 2020
627aa69
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege May 19, 2020
0ad4d48
bump Cargo.lock
seunlanlege May 19, 2020
7b4cd95
cli-utils -> frame-utils
seunlanlege May 21, 2020
6f12be9
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege May 21, 2020
aa8ecb9
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege May 21, 2020
a0fe47d
rename BlockNumber to GenericNumber, fix spaces
seunlanlege May 25, 2020
1ee5967
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege May 25, 2020
2573c91
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege May 25, 2020
762ed30
fix spaces
seunlanlege May 25, 2020
9130156
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege May 29, 2020
8c19813
construct additional_signed manually
seunlanlege Jun 1, 2020
b0d21d8
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege Jun 2, 2020
753f5eb
sign test
seunlanlege Jun 2, 2020
2a4374b
remove unused vars
seunlanlege Jun 2, 2020
3342d06
implement subkey with frame-utilities-cli and sc_cli
seunlanlege Jun 2, 2020
0590bbf
fix moduleid test
seunlanlege Jun 2, 2020
5ac0694
CI and clion disagree on line widths
seunlanlege Jun 2, 2020
daeed15
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege Jun 8, 2020
aa16d9c
adds associated Params type to SignedExtensionProvider
seunlanlege Jun 9, 2020
83d9487
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege Jun 11, 2020
54277a7
Apply suggestions from code review
seunlanlege Jun 11, 2020
22049d3
move some code around
seunlanlege Jun 11, 2020
c683181
removes unneccesary generic params
seunlanlege Jun 11, 2020
a1535f6
moves module_id back to frame_utilities_cli
seunlanlege Jun 15, 2020
655e53a
Apply suggestions from code review
seunlanlege Jun 15, 2020
974ef0a
remove print_ext
seunlanlege Jun 15, 2020
c78e838
Merge branch 'seun-sc-cli-subkey' of github.com:paritytech/substrate …
seunlanlege Jun 15, 2020
86f149a
remove MaybeDisplay from pallet_balances::Trait::Balance
seunlanlege Jun 15, 2020
e7f732b
a lot of stuff tbh
seunlanlege Jun 15, 2020
2be821f
adds ExtrasParamsBuilder
seunlanlege Jun 15, 2020
a7dd087
remove tests for ModuleIdCmd
seunlanlege Jun 15, 2020
51c35c4
address comments from PR
seunlanlege Jun 16, 2020
cddc46d
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege Jun 16, 2020
20d695a
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege Jun 18, 2020
e5e8b59
bump Cargo.lock
seunlanlege Jun 18, 2020
08d4f24
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege Jun 19, 2020
e7820c7
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege Jun 22, 2020
faab8db
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege Jul 14, 2020
bbb9079
manually insert key into keystore
seunlanlege Jul 14, 2020
cc7542c
remove unnecessary SharedParams
seunlanlege Jul 14, 2020
f4af111
add validation to vanity pattern, remove unused arg
seunlanlege Jul 22, 2020
2553e0e
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege Jul 22, 2020
e24b0c5
Merge remote-tracking branch 'origin/master' into seun-sc-cli-subkey
gnunicorn Aug 10, 2020
cd0f083
remove SharedParams from Sign, Vanity, Verify
seunlanlege Aug 10, 2020
153c346
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege Aug 11, 2020
4dc44e7
remove SharedParams from ModuleIdCmd, remove expect from Verify, new …
seunlanlege Aug 11, 2020
3bb63c0
remove SharedParams from InsertCmd
seunlanlege Aug 11, 2020
30b49fd
🤦🏾‍♂️
seunlanlege Aug 11, 2020
9598c0b
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege Aug 11, 2020
f145c8e
deleted prometheus.yml
seunlanlege Aug 11, 2020
94511ab
move a few things around
seunlanlege Aug 17, 2020
b342028
Merge branch 'master' of github.com:paritytech/substrate into seun-sc…
seunlanlege Aug 17, 2020
0a50728
fix vanity test
seunlanlege Aug 20, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
655 changes: 582 additions & 73 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion bin/node-template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
33 changes: 28 additions & 5 deletions bin/node-template/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,33 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

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 = <pallet_indices::Module<Runtime> 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<()> {
Expand All @@ -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::<Adapter, _, _, _>(
config,
|config: _| Ok(new_full_start!(config).0),
)
Expand Down
4 changes: 2 additions & 2 deletions bin/node/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

fn main() {
#[cfg(feature = "cli")]
cli::main();
// #[cfg(feature = "cli")]
// cli::main();
}

#[cfg(feature = "cli")]
Expand Down
74 changes: 37 additions & 37 deletions bin/utils/subkey/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!({
Expand All @@ -99,11 +99,11 @@ trait Crypto: Sized {
Public key (hex): {}\n \
Account ID: {}\n \
SS58 Address: {}",
uri,
format_seed::<Self>(seed),
format_public_key::<Self>(public_key.clone()),
format_account_id::<Self>(public_key),
Self::ss58_from_pair(&pair),
uri,
seunlanlege marked this conversation as resolved.
Show resolved Hide resolved
format_seed::<Self>(seed),
format_public_key::<Self>(public_key.clone()),
format_account_id::<Self>(public_key),
Self::ss58_from_pair(&pair),
);
},
}
Expand All @@ -127,17 +127,17 @@ trait Crypto: Sized {
Public key (hex): {}\n \
Account ID: {}\n \
SS58 Address: {}",
uri,
if let Some(seed) = seed { format_seed::<Self>(seed) } else { "n/a".into() },
format_public_key::<Self>(public_key.clone()),
format_account_id::<Self>(public_key),
Self::ss58_from_pair(&pair),
uri,
seunlanlege marked this conversation as resolved.
Show resolved Hide resolved
if let Some(seed) = seed { format_seed::<Self>(seed) } else { "n/a".into() },
format_public_key::<Self>(public_key.clone()),
format_account_id::<Self>(public_key),
Self::ss58_from_pair(&pair),
);
},
}

} else if let Ok((public_key, v)) =
<Self::Pair as Pair>::Public::from_string_with_version(uri)
<Self::Pair as Pair>::Public::from_string_with_version(uri)
{
let v = network_override.unwrap_or(v);

Expand All @@ -158,11 +158,11 @@ trait Crypto: Sized {
Public key (hex): {}\n \
Account ID: {}\n \
SS58 Address: {}",
uri,
String::from(v),
format_public_key::<Self>(public_key.clone()),
format_account_id::<Self>(public_key.clone()),
public_key.to_ss58check_with_version(v),
uri,
String::from(v),
format_public_key::<Self>(public_key.clone()),
format_account_id::<Self>(public_key.clone()),
public_key.to_ss58check_with_version(v),
);
},
}
Expand Down Expand Up @@ -369,9 +369,9 @@ fn static_err(msg: &'static str) -> Result<(), Error> {
}

fn execute<C: Crypto>(matches: ArgMatches) -> Result<(), Error>
where
SignatureOf<C>: SignatureT,
PublicOf<C>: PublicT,
where
SignatureOf<C>: SignatureT,
PublicOf<C>: PublicT,
{
let password_interactive = matches.is_present("password-interactive");
let password = matches.value_of("password");
Expand All @@ -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);
Expand All @@ -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)) => {
Expand Down Expand Up @@ -521,19 +521,19 @@ fn generate_mnemonic(matches: &ArgMatches) -> Result<Mnemonic, Error> {
}

fn do_sign<C: Crypto>(suri: &str, message: Vec<u8>, password: Option<&str>) -> Result<String, Error>
where
SignatureOf<C>: SignatureT,
PublicOf<C>: PublicT,
where
SignatureOf<C>: SignatureT,
PublicOf<C>: PublicT,
{
let pair = read_pair::<C>(Some(suri), password)?;
let signature = pair.sign(&message);
Ok(format_signature::<C>(&signature))
}

fn do_verify<C: Crypto>(matches: &ArgMatches, uri: &str, message: Vec<u8>) -> Result<bool, Error>
where
SignatureOf<C>: SignatureT,
PublicOf<C>: PublicT,
where
SignatureOf<C>: SignatureT,
PublicOf<C>: PublicT,
{

let signature = read_signature::<C>(matches)?;
Expand Down Expand Up @@ -582,9 +582,9 @@ fn read_genesis_hash(matches: &ArgMatches) -> Result<H256, Error> {
}

fn read_signature<C: Crypto>(matches: &ArgMatches) -> Result<SignatureOf<C>, Error>
where
SignatureOf<C>: SignatureT,
PublicOf<C>: PublicT,
where
SignatureOf<C>: SignatureT,
PublicOf<C>: PublicT,
{
let sig_data = matches
.value_of("sig")
Expand All @@ -603,8 +603,8 @@ where
}

fn read_public_key<C: Crypto>(matched_uri: Option<&str>) -> PublicOf<C>
where
PublicOf<C>: PublicT,
where
PublicOf<C>: PublicT,
{
let uri = matched_uri.expect("parameter is required; thus it can't be None; qed");
let uri = if uri.starts_with("0x") {
Expand Down Expand Up @@ -724,9 +724,9 @@ mod tests {
use super::*;

fn test_generate_sign_verify<CryptoType: Crypto>()
where
SignatureOf<CryptoType>: SignatureT,
PublicOf<CryptoType>: PublicT,
where
SignatureOf<CryptoType>: SignatureT,
PublicOf<CryptoType>: PublicT,
{
let usage = get_usage();
let app = get_app(&usage);
Expand Down
22 changes: 21 additions & 1 deletion client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@ 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" }
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" }
Expand All @@ -36,16 +45,27 @@ 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"
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"] }
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"

[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 = [
Expand Down
9 changes: 9 additions & 0 deletions client/cli/src/arg_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ arg_enum! {
}
}

arg_enum! {
#[allow(missing_docs)]
cecton marked this conversation as resolved.
Show resolved Hide resolved
cecton marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum OutputType {
Json,
Text,
}
}

arg_enum! {
/// How to execute blocks
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
84 changes: 84 additions & 0 deletions client/cli/src/commands/generate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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 <http://www.gnu.org/licenses/>.
seunlanlege marked this conversation as resolved.
Show resolved Hide resolved

//! Implementation of the `generate` subcommand

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)]
#[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.
seunlanlege marked this conversation as resolved.
Show resolved Hide resolved
#[structopt(long, short = "w", value_name = "WORDS")]
words: Option<usize>,

#[allow(missing_docs)]
#[structopt(flatten)]
pub shared_params: SharedParams,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what way we require the shared params here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in order to impl CliConfiguration for it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shared params is a requirement for it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can not just mark this as solved because CliConfiguration requires it! I know that CliConfiguration requires it. But this is a really shitty CLI experience. If you don't need this, you need to adapt CliConfiguration.

}

impl GenerateCmd {
/// Run the command
pub fn run<RA: RuntimeAdapter>(self) -> error::Result<()>
where
AccountIdFor<RA>: Ss58Codec + Derive,
{
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;

RA::print_from_uri(
mnemonic.phrase(),
Some(password.as_str()),
maybe_network,
output
);

Ok(())
}

/// Update and prepare a `Configuration` with command line parameters
pub fn update_config<F>(
&self,
mut config: &mut Configuration,
spec_factory: F,
version: &VersionInfo,
) -> error::Result<()> where
F: FnOnce(&str) -> Result<Box<dyn ChainSpec>, String>,
{
self.shared_params.update_config(&mut config, spec_factory, version)?;
config.use_in_memory_keystore()?;

Ok(())
}
}
Loading