mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 15:37:56 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -18,22 +18,18 @@
|
||||
//! Implementation of the `insert` subcommand
|
||||
|
||||
use crate::{
|
||||
Error, KeystoreParams, CryptoSchemeFlag, SharedParams, utils, with_crypto_scheme,
|
||||
SubstrateCli,
|
||||
utils, with_crypto_scheme, CryptoSchemeFlag, Error, KeystoreParams, SharedParams, SubstrateCli,
|
||||
};
|
||||
use std::{sync::Arc, convert::TryFrom};
|
||||
use structopt::StructOpt;
|
||||
use sp_core::{crypto::KeyTypeId, crypto::SecretString};
|
||||
use sp_keystore::{SyncCryptoStorePtr, SyncCryptoStore};
|
||||
use sc_keystore::LocalKeystore;
|
||||
use sc_service::config::{KeystoreConfig, BasePath};
|
||||
use sc_service::config::{BasePath, KeystoreConfig};
|
||||
use sp_core::crypto::{KeyTypeId, SecretString};
|
||||
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
|
||||
use std::{convert::TryFrom, sync::Arc};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `insert` command
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[structopt(
|
||||
name = "insert",
|
||||
about = "Insert a key to the keystore of a node."
|
||||
)]
|
||||
#[structopt(name = "insert", about = "Insert a key to the keystore of a node.")]
|
||||
pub struct InsertKeyCmd {
|
||||
/// The secret key URI.
|
||||
/// If the value is a file, the file content is used as URI.
|
||||
@@ -62,7 +58,8 @@ impl InsertKeyCmd {
|
||||
/// Run the command
|
||||
pub fn run<C: SubstrateCli>(&self, cli: &C) -> Result<(), Error> {
|
||||
let suri = utils::read_uri(self.suri.as_ref())?;
|
||||
let base_path = self.shared_params
|
||||
let base_path = self
|
||||
.shared_params
|
||||
.base_path()
|
||||
.unwrap_or_else(|| BasePath::from_project("", "", &C::executable_name()));
|
||||
let chain_id = self.shared_params.chain_id(self.shared_params.is_dev());
|
||||
@@ -78,10 +75,11 @@ impl InsertKeyCmd {
|
||||
let keystore: SyncCryptoStorePtr = Arc::new(LocalKeystore::open(path, password)?);
|
||||
(keystore, public)
|
||||
},
|
||||
_ => unreachable!("keystore_config always returns path and password; qed")
|
||||
_ => unreachable!("keystore_config always returns path and password; qed"),
|
||||
};
|
||||
|
||||
let key_type = KeyTypeId::try_from(self.key_type.as_str()).map_err(|_| Error::KeyTypeInvalid)?;
|
||||
let key_type =
|
||||
KeyTypeId::try_from(self.key_type.as_str()).map_err(|_| Error::KeyTypeInvalid)?;
|
||||
|
||||
SyncCryptoStore::insert_unknown(&*keystore, key_type, &suri, &public[..])
|
||||
.map_err(|_| Error::KeyStoreOperation)?;
|
||||
@@ -98,10 +96,10 @@ fn to_vec<P: sp_core::Pair>(uri: &str, pass: Option<SecretString>) -> Result<Vec
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sc_service::{ChainSpec, ChainType, GenericChainSpec, NoExtension};
|
||||
use sp_core::{sr25519::Pair, Pair as _, Public};
|
||||
use structopt::StructOpt;
|
||||
use tempfile::TempDir;
|
||||
use sp_core::{sr25519::Pair, Pair as _, Public};
|
||||
use sc_service::{ChainSpec, GenericChainSpec, ChainType, NoExtension};
|
||||
|
||||
struct Cli;
|
||||
|
||||
@@ -135,21 +133,17 @@ mod tests {
|
||||
}
|
||||
|
||||
fn load_spec(&self, _: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
|
||||
Ok(
|
||||
Box::new(
|
||||
GenericChainSpec::from_genesis(
|
||||
"test",
|
||||
"test_id",
|
||||
ChainType::Development,
|
||||
|| unimplemented!("Not required in tests"),
|
||||
Vec::new(),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
NoExtension::None,
|
||||
),
|
||||
),
|
||||
)
|
||||
Ok(Box::new(GenericChainSpec::from_genesis(
|
||||
"test",
|
||||
"test_id",
|
||||
ChainType::Development,
|
||||
|| unimplemented!("Not required in tests"),
|
||||
Vec::new(),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
NoExtension::None,
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,15 +153,20 @@ mod tests {
|
||||
let path_str = format!("{}", path.path().display());
|
||||
let (key, uri, _) = Pair::generate_with_phrase(None);
|
||||
|
||||
let inspect = InsertKeyCmd::from_iter(
|
||||
&["insert-key", "-d", &path_str, "--key-type", "test", "--suri", &uri],
|
||||
);
|
||||
let inspect = InsertKeyCmd::from_iter(&[
|
||||
"insert-key",
|
||||
"-d",
|
||||
&path_str,
|
||||
"--key-type",
|
||||
"test",
|
||||
"--suri",
|
||||
&uri,
|
||||
]);
|
||||
assert!(inspect.run(&Cli).is_ok());
|
||||
|
||||
let keystore = LocalKeystore::open(
|
||||
path.path().join("chains").join("test_id").join("keystore"),
|
||||
None,
|
||||
).unwrap();
|
||||
let keystore =
|
||||
LocalKeystore::open(path.path().join("chains").join("test_id").join("keystore"), None)
|
||||
.unwrap();
|
||||
assert!(keystore.has_keys(&[(key.public().to_raw_vec(), KeyTypeId(*b"test"))]));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user