Skip to content

Commit

Permalink
cargo fmt with stable defaults (#876)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsdw authored Mar 21, 2023
1 parent c63ff6e commit 7c252fc
Show file tree
Hide file tree
Showing 110 changed files with 663 additions and 1,949 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
toolchain: stable
override: true
components: rustfmt

Expand Down
64 changes: 0 additions & 64 deletions .rustfmt.toml

This file was deleted.

5 changes: 1 addition & 4 deletions cli/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
borrow::Cow,
process::Command,
};
use std::{borrow::Cow, process::Command};

fn main() {
// Make git hash available via GIT_HASH build-time env var:
Expand Down
11 changes: 2 additions & 9 deletions cli/src/commands/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@
use clap::Parser as ClapParser;
use color_eyre::eyre;
use jsonrpsee::client_transport::ws::Uri;
use std::{
fs,
io::Read,
path::PathBuf,
};
use subxt_codegen::{
DerivesRegistry,
TypeSubstitutes,
};
use std::{fs, io::Read, path::PathBuf};
use subxt_codegen::{DerivesRegistry, TypeSubstitutes};

/// Generate runtime API client code from metadata.
///
Expand Down
40 changes: 11 additions & 29 deletions cli/src/commands/compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,13 @@
// see LICENSE for license details.

use clap::Parser as ClapParser;
use color_eyre::eyre::{
self,
WrapErr,
};
use frame_metadata::{
RuntimeMetadata,
RuntimeMetadataPrefixed,
RuntimeMetadataV14,
META_RESERVED,
};
use color_eyre::eyre::{self, WrapErr};
use frame_metadata::{RuntimeMetadata, RuntimeMetadataPrefixed, RuntimeMetadataV14, META_RESERVED};
use jsonrpsee::client_transport::ws::Uri;
use scale::Decode;
use serde::{
Deserialize,
Serialize,
};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use subxt_metadata::{
get_metadata_hash,
get_pallet_hash,
};
use subxt_metadata::{get_metadata_hash, get_pallet_hash};

/// Verify metadata compatibility between substrate nodes.
#[derive(Debug, ClapParser)]
Expand All @@ -41,9 +27,7 @@ pub struct Opts {

pub async fn run(opts: Opts) -> color_eyre::Result<()> {
match opts.pallet {
Some(pallet) => {
handle_pallet_metadata(opts.nodes.as_slice(), pallet.as_str()).await
}
Some(pallet) => handle_pallet_metadata(opts.nodes.as_slice(), pallet.as_str()).await,
None => handle_full_metadata(opts.nodes.as_slice()).await,
}
}
Expand Down Expand Up @@ -120,17 +104,15 @@ async fn fetch_runtime_metadata(url: &Uri) -> color_eyre::Result<RuntimeMetadata
url,
metadata.0,
META_RESERVED
))
));
}

match metadata.1 {
RuntimeMetadata::V14(v14) => Ok(v14),
_ => {
Err(eyre::eyre!(
"Node {:?} with unsupported metadata version: {:?}",
url,
metadata.1
))
}
_ => Err(eyre::eyre!(
"Node {:?} with unsupported metadata version: {:?}",
url,
metadata.1
)),
}
}
15 changes: 5 additions & 10 deletions cli/src/commands/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use color_eyre::eyre;
use frame_metadata::RuntimeMetadataPrefixed;
use jsonrpsee::client_transport::ws::Uri;
use scale::Decode;
use std::io::{
self,
Write,
};
use std::io::{self, Write};
use subxt_codegen::utils::fetch_metadata_hex;

/// Download metadata from a substrate node, for use with `subxt` codegen.
Expand Down Expand Up @@ -48,11 +45,9 @@ pub async fn run(opts: Opts) -> color_eyre::Result<()> {
let bytes = hex::decode(hex_data.trim_start_matches("0x"))?;
Ok(io::stdout().write_all(&bytes)?)
}
_ => {
Err(eyre::eyre!(
"Unsupported format `{}`, expected `json`, `hex` or `bytes`",
opts.format
))
}
_ => Err(eyre::eyre!(
"Unsupported format `{}`, expected `json`, `hex` or `bytes`",
opts.format
)),
}
}
46 changes: 16 additions & 30 deletions codegen/src/api/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,13 @@

use super::CodegenError;
use crate::{
types::{
CompositeDefFields,
TypeGenerator,
},
types::{CompositeDefFields, TypeGenerator},
CratePath,
};
use frame_metadata::{
v14::RuntimeMetadataV14,
PalletMetadata,
};
use heck::{
ToSnakeCase as _,
ToUpperCamelCase as _,
};
use frame_metadata::{v14::RuntimeMetadataV14, PalletMetadata};
use heck::{ToSnakeCase as _, ToUpperCamelCase as _};
use proc_macro2::TokenStream as TokenStream2;
use quote::{
format_ident,
quote,
};
use quote::{format_ident, quote};
use scale_info::form::PortableForm;

/// Generate calls from the provided pallet's metadata. Each call returns a `StaticTxPayload`
Expand Down Expand Up @@ -59,20 +47,18 @@ pub fn generate_calls(
.iter_mut()
.map(|(variant_name, struct_def)| {
let (call_fn_args, call_args): (Vec<_>, Vec<_>) = match struct_def.fields {
CompositeDefFields::Named(ref named_fields) => {
named_fields
.iter()
.map(|(name, field)| {
let fn_arg_type = &field.type_path;
let call_arg = if field.is_boxed() {
quote! { #name: ::std::boxed::Box::new(#name) }
} else {
quote! { #name }
};
(quote!( #name: #fn_arg_type ), call_arg)
})
.unzip()
}
CompositeDefFields::Named(ref named_fields) => named_fields
.iter()
.map(|(name, field)| {
let fn_arg_type = &field.type_path;
let call_arg = if field.is_boxed() {
quote! { #name: ::std::boxed::Box::new(#name) }
} else {
quote! { #name }
};
(quote!( #name: #fn_arg_type ), call_arg)
})
.unzip(),
CompositeDefFields::NoFields => Default::default(),
CompositeDefFields::Unnamed(_) => {
return Err(CodegenError::InvalidCallVariant(call.ty.id()))
Expand Down
17 changes: 4 additions & 13 deletions codegen/src/api/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,11 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.

use crate::{
types::TypeGenerator,
CratePath,
};
use frame_metadata::{
v14::RuntimeMetadataV14,
PalletMetadata,
};
use crate::{types::TypeGenerator, CratePath};
use frame_metadata::{v14::RuntimeMetadataV14, PalletMetadata};
use heck::ToSnakeCase as _;
use proc_macro2::TokenStream as TokenStream2;
use quote::{
format_ident,
quote,
};
use quote::{format_ident, quote};
use scale_info::form::PortableForm;

use super::CodegenError;
Expand Down Expand Up @@ -53,7 +44,7 @@ pub fn generate_constants(
) -> Result<TokenStream2, CodegenError> {
// Early return if the pallet has no constants.
if pallet.constants.is_empty() {
return Ok(quote!())
return Ok(quote!());
}
let constants = &pallet.constants;

Expand Down
5 changes: 1 addition & 4 deletions codegen/src/api/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.

use crate::{
types::TypeGenerator,
CratePath,
};
use crate::{types::TypeGenerator, CratePath};
use frame_metadata::PalletMetadata;
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
Expand Down
44 changes: 10 additions & 34 deletions codegen/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,16 @@ use subxt_metadata::get_metadata_per_pallet_hash;
use super::DerivesRegistry;
use crate::{
ir,
types::{
CompositeDef,
CompositeDefFields,
TypeGenerator,
TypeSubstitutes,
},
utils::{
fetch_metadata_bytes_blocking,
FetchMetadataError,
Uri,
},
types::{CompositeDef, CompositeDefFields, TypeGenerator, TypeSubstitutes},
utils::{fetch_metadata_bytes_blocking, FetchMetadataError, Uri},
CratePath,
};
use codec::Decode;
use frame_metadata::{
v14::RuntimeMetadataV14,
RuntimeMetadata,
RuntimeMetadataPrefixed,
};
use frame_metadata::{v14::RuntimeMetadataV14, RuntimeMetadata, RuntimeMetadataPrefixed};
use heck::ToSnakeCase as _;
use proc_macro2::{
Span,
TokenStream as TokenStream2,
};
use quote::{
format_ident,
quote,
};
use std::{
fs,
io::Read,
path,
string::ToString,
};
use proc_macro2::{Span, TokenStream as TokenStream2};
use quote::{format_ident, quote};
use std::{fs, io::Read, path, string::ToString};
use syn::parse_quote;

/// Error returned when the Codegen cannot generate the runtime API.
Expand Down Expand Up @@ -90,7 +66,9 @@ pub enum CodegenError {
#[error("Call variant for type {0} must have all named fields. Make sure you are providing a valid metadata V14")]
InvalidCallVariant(u32),
/// Type should be an variant/enum.
#[error("{0} type should be an variant/enum type. Make sure you are providing a valid metadata V14")]
#[error(
"{0} type should be an variant/enum type. Make sure you are providing a valid metadata V14"
)]
InvalidType(String),
}

Expand Down Expand Up @@ -460,9 +438,7 @@ impl RuntimeGenerator {

let pallets_with_calls: Vec<_> = pallets_with_mod_names
.iter()
.filter_map(|(pallet, pallet_mod_name)| {
pallet.calls.as_ref().map(|_| pallet_mod_name)
})
.filter_map(|(pallet, pallet_mod_name)| pallet.calls.as_ref().map(|_| pallet_mod_name))
.collect();

let rust_items = item_mod_ir.rust_items();
Expand Down
Loading

0 comments on commit 7c252fc

Please sign in to comment.