Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tadeohepperle committed Jun 1, 2023
1 parent faeb8db commit df00dd5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
3 changes: 2 additions & 1 deletion cli/src/commands/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ fn codegen(
crate_path,
should_gen_docs,
runtime_types_only,
).map_err(|code_gen_err| eyre!("{code_gen_err}"))?;
)
.map_err(|code_gen_err| eyre!("{code_gen_err}"))?;
writeln!(output, "{runtime_api}")?;
Ok(())
}
20 changes: 14 additions & 6 deletions cli/src/commands/compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ pub struct Opts {
pub async fn run(opts: Opts, output: &mut impl std::io::Write) -> color_eyre::Result<()> {
match opts.pallet {
Some(pallet) => {
handle_pallet_metadata(opts.nodes.as_slice(), pallet.as_str(), opts.version, output).await
handle_pallet_metadata(opts.nodes.as_slice(), pallet.as_str(), opts.version, output)
.await
}
None => handle_full_metadata(opts.nodes.as_slice(), opts.version, output).await,
}
Expand All @@ -50,8 +51,8 @@ pub async fn run(opts: Opts, output: &mut impl std::io::Write) -> color_eyre::Re
async fn handle_pallet_metadata(
nodes: &[Uri],
name: &str,
version: MetadataVersion
, output: &mut impl std::io::Write,
version: MetadataVersion,
output: &mut impl std::io::Write,
) -> color_eyre::Result<()> {
#[derive(Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
Expand All @@ -68,7 +69,10 @@ async fn handle_pallet_metadata(
Some(pallet_metadata) => {
let hash = pallet_metadata.hash();
let hex_hash = hex::encode(hash);
writeln!(output, "Node {node:?} has pallet metadata hash {hex_hash:?}")?;
writeln!(
output,
"Node {node:?} has pallet metadata hash {hex_hash:?}"
)?;

compatibility
.pallet_present
Expand All @@ -92,13 +96,17 @@ async fn handle_pallet_metadata(
Ok(())
}

async fn handle_full_metadata(nodes: &[Uri], version: MetadataVersion, output: &mut impl std::io::Write) -> color_eyre::Result<()> {
async fn handle_full_metadata(
nodes: &[Uri],
version: MetadataVersion,
output: &mut impl std::io::Write,
) -> color_eyre::Result<()> {
let mut compatibility_map: HashMap<String, Vec<String>> = HashMap::new();
for node in nodes.iter() {
let metadata = fetch_runtime_metadata(node, version).await?;
let hash = metadata.hasher().hash();
let hex_hash = hex::encode(hash);
writeln!(output, "Node {node:?} has metadata hash {hex_hash:?}", )?;
writeln!(output, "Node {node:?} has metadata hash {hex_hash:?}",)?;

compatibility_map
.entry(hex_hash)
Expand Down
11 changes: 6 additions & 5 deletions cli/src/commands/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ pub struct Opts {}

pub fn run(_opts: Opts, output: &mut impl std::io::Write) -> color_eyre::Result<()> {
let git_hash = env!("GIT_HASH");
writeln!(output,
"{} {}-{}",
clap::crate_name!(),
clap::crate_version!(),
git_hash
writeln!(
output,
"{} {}-{}",
clap::crate_name!(),
clap::crate_version!(),
git_hash
)?;
Ok(())
}
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ async fn main() -> color_eyre::Result<()> {
Command::Codegen(opts) => commands::codegen::run(opts, &mut output).await,
Command::Compatibility(opts) => commands::compatibility::run(opts, &mut output).await,
Command::Version(opts) => commands::version::run(opts, &mut output),
Command::Explore(opts) => commands::explore::run(opts, &mut output).await
Command::Explore(opts) => commands::explore::run(opts, &mut output).await,
}
}
5 changes: 2 additions & 3 deletions cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl FileOrUrl {
uri,
version.unwrap_or_default(),
)
.await?),
.await?),
// Default if neither is provided; fetch from local url
(None, None, version) => {
let uri = Uri::from_static("ws://localhost:9944");
Expand Down Expand Up @@ -95,7 +95,6 @@ pub fn with_indent(s: String, indent: usize) -> String {
.join("\n")
}


/// Given a type definition, return type ID and registry representing it.
#[allow(dead_code)]
pub fn make_type<T: scale_info::TypeInfo + 'static>() -> (u32, scale_info::PortableRegistry) {
Expand All @@ -104,4 +103,4 @@ pub fn make_type<T: scale_info::TypeInfo + 'static>() -> (u32, scale_info::Porta
let id = types.register_type(&m);
let portable_registry: scale_info::PortableRegistry = types.into();
(id.id, portable_registry)
}
}
16 changes: 7 additions & 9 deletions cli/src/utils/type_description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use scale_info::{

/// pretty formatted type description
pub fn print_type_description<T>(ty: &T, registry: &PortableRegistry) -> color_eyre::Result<String>
where
T: TypeDescription,
where
T: TypeDescription,
{
let type_description = ty.type_description(registry)?;
let type_description = format_type_description(&type_description);
Expand Down Expand Up @@ -125,7 +125,7 @@ impl TypeDescription for TypeDefPrimitive {
TypeDefPrimitive::I128 => "i128",
TypeDefPrimitive::I256 => "i256",
}
.into())
.into())
}
}

Expand Down Expand Up @@ -266,13 +266,12 @@ fn format_type_description(input: &str) -> String {
output
}


#[cfg(test)]
mod test {
use crate::utils::make_type;
use crate::utils::type_description::print_type_description;
use scale_info::scale::{Decode, Encode};
use scale_info::TypeInfo;
use crate::utils::make_type;
use crate::utils::type_description::{print_type_description};
use std::fmt::Write;
use std::write;

Expand All @@ -285,13 +284,12 @@ mod test {
#[test]
fn test_type_description() {
let (foo_type_id, foo_registry) = make_type::<Foo>();
let description =
print_type_description(&foo_type_id, &foo_registry).unwrap();
let description = print_type_description(&foo_type_id, &foo_registry).unwrap();
let mut output = String::new();
writeln!(output, "struct Foo {{").unwrap();
writeln!(output, " hello: String,").unwrap();
writeln!(output, " num: i32").unwrap();
write!(output, "}}").unwrap();
assert_eq!(description, output);
}
}
}

0 comments on commit df00dd5

Please sign in to comment.