mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 08:11:04 +00:00
Add tty password input (#2503)
* Add tty password input * Move password from core/service to core/cli * Fix test build error * Password should be entered only once if it's for decoding * Update Cargo.lock from rebuild
This commit is contained in:
Generated
+12
@@ -2910,6 +2910,16 @@ dependencies = [
|
||||
"librocksdb-sys 5.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rpassword"
|
||||
version = "3.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.14"
|
||||
@@ -3912,6 +3922,7 @@ dependencies = [
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"names 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rpassword 3.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-primitives 2.0.0",
|
||||
"structopt 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -5787,6 +5798,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c"
|
||||
"checksum ripemd160 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad5112e0dbbb87577bfbc56c42450235e3012ce336e29c5befd7807bd626da4a"
|
||||
"checksum rocksdb 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f1651697fefd273bfb4fd69466cc2a9d20de557a0213b97233b22b5e95924b5e"
|
||||
"checksum rpassword 3.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c34fa7bcae7fca3c8471e8417088bbc3ad9af8066b0ecf4f3c0d98a0d772716e"
|
||||
"checksum rustc-demangle 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "ccc78bfd5acd7bf3e89cffcf899e5cb1a52d6fafa8dec2739ad70c9577a57288"
|
||||
"checksum rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "403bb3a286107a04825a5f82e1270acc1e14028d3d554d7a1e08914549575ab8"
|
||||
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
|
||||
@@ -33,6 +33,7 @@ substrate-telemetry = { path = "../../core/telemetry" }
|
||||
keyring = { package = "substrate-keyring", path = "../keyring" }
|
||||
names = "0.11.0"
|
||||
structopt = "0.2"
|
||||
rpassword = "3.0"
|
||||
|
||||
[dev-dependencies]
|
||||
tempdir = "0.3"
|
||||
|
||||
@@ -365,6 +365,11 @@ fn fill_network_configuration(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn input_keystore_password() -> Result<String, String> {
|
||||
rpassword::read_password_from_tty(Some("Keystore password: "))
|
||||
.map_err(|e| format!("{:?}", e))
|
||||
}
|
||||
|
||||
fn create_run_node_config<F, S>(
|
||||
cli: RunCmd, spec_factory: S, impl_name: &'static str, version: &VersionInfo
|
||||
) -> error::Result<FactoryFullConfiguration<F>>
|
||||
@@ -374,6 +379,9 @@ where
|
||||
{
|
||||
let spec = load_spec(&cli.shared_params, spec_factory)?;
|
||||
let mut config = service::Configuration::default_with_spec(spec.clone());
|
||||
if cli.interactive_password {
|
||||
config.password = input_keystore_password()?
|
||||
}
|
||||
|
||||
config.impl_name = impl_name;
|
||||
config.impl_commit = version.commit;
|
||||
|
||||
@@ -395,6 +395,10 @@ pub struct RunCmd {
|
||||
/// Enable authoring even when offline.
|
||||
#[structopt(long = "force-authoring")]
|
||||
pub force_authoring: bool,
|
||||
|
||||
/// Interactive password for validator key.
|
||||
#[structopt(short = "i")]
|
||||
pub interactive_password: bool,
|
||||
}
|
||||
|
||||
/// Stores all required Cli values for a keyring test account.
|
||||
|
||||
@@ -78,6 +78,8 @@ pub struct Configuration<C, G: Serialize + DeserializeOwned + BuildStorage> {
|
||||
pub force_authoring: bool,
|
||||
/// Disable GRANDPA when running in validator mode
|
||||
pub disable_grandpa: bool,
|
||||
/// Node keystore's password
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
impl<C: Default, G: Serialize + DeserializeOwned + BuildStorage> Configuration<C, G> {
|
||||
@@ -108,6 +110,7 @@ impl<C: Default, G: Serialize + DeserializeOwned + BuildStorage> Configuration<C
|
||||
offchain_worker: Default::default(),
|
||||
force_authoring: false,
|
||||
disable_grandpa: false,
|
||||
password: "".to_string(),
|
||||
};
|
||||
configuration.network.boot_nodes = configuration.chain_spec.boot_nodes().to_vec();
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ impl<Components: components::Components> Service<Components> {
|
||||
let public_key = match keystore.contents()?.get(0) {
|
||||
Some(public_key) => public_key.clone(),
|
||||
None => {
|
||||
let key = keystore.generate("")?;
|
||||
let key = keystore.generate(&config.password)?;
|
||||
let public_key = key.public();
|
||||
info!("Generated a new keypair: {:?}", public_key);
|
||||
|
||||
@@ -382,7 +382,7 @@ impl<Components: components::Components> Service<Components> {
|
||||
if self.config.roles != Roles::AUTHORITY { return None }
|
||||
let keystore = &self.keystore;
|
||||
if let Ok(Some(Ok(key))) = keystore.contents().map(|keys| keys.get(0)
|
||||
.map(|k| keystore.load(k, "")))
|
||||
.map(|k| keystore.load(k, &self.config.password)))
|
||||
{
|
||||
Some(key)
|
||||
} else {
|
||||
|
||||
@@ -127,6 +127,7 @@ fn node_config<F: ServiceFactory> (
|
||||
offchain_worker: false,
|
||||
force_authoring: false,
|
||||
disable_grandpa: false,
|
||||
password: "".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user