mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-08 05:28:01 +00:00
Keystore overhaul (iter 2) (#13634)
* Remove bloat about remote keystore * Update docs and remove unused 'KeystoreRef' trait * Use wherever possible, MemoryKeystore for testing * Remove unrequired fully qualified method syntax for Keystore
This commit is contained in:
@@ -24,8 +24,7 @@ use clap::Parser;
|
||||
use sc_keystore::LocalKeystore;
|
||||
use sc_service::config::{BasePath, KeystoreConfig};
|
||||
use sp_core::crypto::{KeyTypeId, SecretString};
|
||||
use sp_keystore::{Keystore, KeystorePtr};
|
||||
use std::sync::Arc;
|
||||
use sp_keystore::KeystorePtr;
|
||||
|
||||
/// The `insert` command
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
@@ -67,9 +66,9 @@ impl InsertKeyCmd {
|
||||
let config_dir = base_path.config_dir(chain_spec.id());
|
||||
|
||||
let (keystore, public) = match self.keystore_params.keystore_config(&config_dir)? {
|
||||
(_, KeystoreConfig::Path { path, password }) => {
|
||||
KeystoreConfig::Path { path, password } => {
|
||||
let public = with_crypto_scheme!(self.scheme, to_vec(&suri, password.clone()))?;
|
||||
let keystore: KeystorePtr = Arc::new(LocalKeystore::open(path, password)?);
|
||||
let keystore: KeystorePtr = LocalKeystore::open(path, password)?.into();
|
||||
(keystore, public)
|
||||
},
|
||||
_ => unreachable!("keystore_config always returns path and password; qed"),
|
||||
@@ -78,7 +77,8 @@ impl InsertKeyCmd {
|
||||
let key_type =
|
||||
KeyTypeId::try_from(self.key_type.as_str()).map_err(|_| Error::KeyTypeInvalid)?;
|
||||
|
||||
Keystore::insert(&*keystore, key_type, &suri, &public[..])
|
||||
keystore
|
||||
.insert(key_type, &suri, &public[..])
|
||||
.map_err(|_| Error::KeystoreOperation)?;
|
||||
|
||||
Ok(())
|
||||
@@ -95,6 +95,7 @@ mod tests {
|
||||
use super::*;
|
||||
use sc_service::{ChainSpec, ChainType, GenericChainSpec, NoExtension};
|
||||
use sp_core::{sr25519::Pair, ByteArray, Pair as _};
|
||||
use sp_keystore::Keystore;
|
||||
use tempfile::TempDir;
|
||||
|
||||
struct Cli;
|
||||
|
||||
@@ -185,10 +185,10 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
|
||||
///
|
||||
/// By default this is retrieved from `KeystoreParams` if it is available. Otherwise it uses
|
||||
/// `KeystoreConfig::InMemory`.
|
||||
fn keystore_config(&self, config_dir: &PathBuf) -> Result<(Option<String>, KeystoreConfig)> {
|
||||
fn keystore_config(&self, config_dir: &PathBuf) -> Result<KeystoreConfig> {
|
||||
self.keystore_params()
|
||||
.map(|x| x.keystore_config(config_dir))
|
||||
.unwrap_or_else(|| Ok((None, KeystoreConfig::InMemory)))
|
||||
.unwrap_or_else(|| Ok(KeystoreConfig::InMemory))
|
||||
}
|
||||
|
||||
/// Get the database cache size.
|
||||
@@ -505,7 +505,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
|
||||
let role = self.role(is_dev)?;
|
||||
let max_runtime_instances = self.max_runtime_instances()?.unwrap_or(8);
|
||||
let is_validator = role.is_authority();
|
||||
let (keystore_remote, keystore) = self.keystore_config(&config_dir)?;
|
||||
let keystore = self.keystore_config(&config_dir)?;
|
||||
let telemetry_endpoints = self.telemetry_endpoints(&chain_spec)?;
|
||||
let runtime_cache_size = self.runtime_cache_size()?;
|
||||
|
||||
@@ -524,7 +524,6 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
|
||||
node_key,
|
||||
DCV::p2p_listen_port(),
|
||||
)?,
|
||||
keystore_remote,
|
||||
keystore,
|
||||
database: self.database_config(&config_dir, database_cache_size, database)?,
|
||||
trie_cache_maximum_size: self.trie_cache_maximum_size()?,
|
||||
|
||||
@@ -68,9 +68,7 @@ pub fn secret_string_from_str(s: &str) -> std::result::Result<SecretString, Stri
|
||||
|
||||
impl KeystoreParams {
|
||||
/// Get the keystore configuration for the parameters
|
||||
///
|
||||
/// Returns a vector of remote-urls and the local Keystore configuration
|
||||
pub fn keystore_config(&self, config_dir: &Path) -> Result<(Option<String>, KeystoreConfig)> {
|
||||
pub fn keystore_config(&self, config_dir: &Path) -> Result<KeystoreConfig> {
|
||||
let password = if self.password_interactive {
|
||||
Some(SecretString::new(input_keystore_password()?))
|
||||
} else if let Some(ref file) = self.password_filename {
|
||||
@@ -85,7 +83,7 @@ impl KeystoreParams {
|
||||
.clone()
|
||||
.unwrap_or_else(|| config_dir.join(DEFAULT_KEYSTORE_CONFIG_PATH));
|
||||
|
||||
Ok((self.keystore_uri.clone(), KeystoreConfig::Path { path, password }))
|
||||
Ok(KeystoreConfig::Path { path, password })
|
||||
}
|
||||
|
||||
/// helper method to fetch password from `KeyParams` or read from stdin
|
||||
|
||||
@@ -345,7 +345,6 @@ mod tests {
|
||||
transaction_pool: Default::default(),
|
||||
network: NetworkConfiguration::new_memory(),
|
||||
keystore: sc_service::config::KeystoreConfig::InMemory,
|
||||
keystore_remote: None,
|
||||
database: sc_client_db::DatabaseSource::ParityDb { path: PathBuf::from("db") },
|
||||
trie_cache_maximum_size: None,
|
||||
state_pruning: None,
|
||||
|
||||
Reference in New Issue
Block a user