use default in-memory for commands that don't use keystore (#4634)

This commit is contained in:
Nikolay Volf
2020-01-16 12:08:05 +03:00
committed by Bastian Köcher
parent 28fada7daf
commit 058e98ef34
2 changed files with 18 additions and 4 deletions
+18 -3
View File
@@ -401,7 +401,8 @@ impl<'a> ParseAndPrepareExport<'a> {
E: ChainSpecExtension,
Exit: IntoExit
{
let config = create_config_with_db_path(spec_factory, &self.params.shared_params, self.version)?;
let mut config = create_config_with_db_path(spec_factory, &self.params.shared_params, self.version)?;
fill_config_keystore_in_memory(&mut config)?;
if let DatabaseConfig::Path { ref path, .. } = &config.database {
info!("DB path: {}", path.display());
@@ -523,6 +524,7 @@ impl<'a> CheckBlock<'a> {
{
let mut config = create_config_with_db_path(spec_factory, &self.params.shared_params, self.version)?;
fill_import_params(&mut config, &self.params.import_params, sc_service::Roles::FULL)?;
fill_config_keystore_in_memory(&mut config)?;
let input = if self.params.input.starts_with("0x") { &self.params.input[2..] } else { &self.params.input[..] };
let block_id = match FromStr::from_str(input) {
@@ -559,9 +561,10 @@ impl<'a> ParseAndPreparePurge<'a> {
G: RuntimeGenesis,
E: ChainSpecExtension,
{
let config = create_config_with_db_path::<(), _, _, _>(
let mut config = create_config_with_db_path::<(), _, _, _>(
spec_factory, &self.params.shared_params, self.version
)?;
fill_config_keystore_in_memory(&mut config)?;
let db_path = match config.database {
DatabaseConfig::Path { path, .. } => path,
_ => {
@@ -623,9 +626,11 @@ impl<'a> ParseAndPrepareRevert<'a> {
G: RuntimeGenesis,
E: ChainSpecExtension,
{
let config = create_config_with_db_path(
let mut config = create_config_with_db_path(
spec_factory, &self.params.shared_params, self.version
)?;
fill_config_keystore_in_memory(&mut config)?;
let blocks = self.params.num.parse()?;
builder(config)?.revert_chain(blocks)?;
Ok(())
@@ -749,6 +754,16 @@ fn input_keystore_password() -> Result<String, String> {
.map_err(|e| format!("{:?}", e))
}
/// Use in memory keystore config when it is not required at all.
fn fill_config_keystore_in_memory<C, G, E>(config: &mut sc_service::Configuration<C, G, E>)
-> Result<(), String>
{
match &mut config.keystore {
cfg @ KeystoreConfig::None => { *cfg = KeystoreConfig::InMemory; Ok(()) },
_ => Err("Keystore config specified when it should not be!".into()),
}
}
/// Fill the password field of the given config instance.
fn fill_config_keystore_password_and_path<C, G, E>(
config: &mut sc_service::Configuration<C, G, E>,