mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 10:27:59 +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:
@@ -30,16 +30,16 @@ pub fn expand_outer_dispatch(
|
||||
let mut query_call_part_macros = Vec::new();
|
||||
let mut pallet_names = Vec::new();
|
||||
|
||||
let pallets_with_call = pallet_decls
|
||||
.iter()
|
||||
.filter(|decl| decl.exists_part("Call"));
|
||||
let pallets_with_call = pallet_decls.iter().filter(|decl| decl.exists_part("Call"));
|
||||
|
||||
for pallet_declaration in pallets_with_call {
|
||||
let name = &pallet_declaration.name;
|
||||
let path = &pallet_declaration.path;
|
||||
let index = pallet_declaration.index;
|
||||
|
||||
variant_defs.extend(quote!(#[codec(index = #index)] #name( #scrate::dispatch::CallableCallFor<#name, #runtime> ),));
|
||||
variant_defs.extend(
|
||||
quote!(#[codec(index = #index)] #name( #scrate::dispatch::CallableCallFor<#name, #runtime> ),),
|
||||
);
|
||||
variant_patterns.push(quote!(Call::#name(call)));
|
||||
pallet_names.push(name);
|
||||
query_call_part_macros.push(quote! {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
use crate::construct_runtime::Pallet;
|
||||
use inflector::Inflector;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{ToTokens, format_ident, quote};
|
||||
use quote::{format_ident, quote, ToTokens};
|
||||
use syn::Ident;
|
||||
|
||||
pub fn expand_outer_config(
|
||||
@@ -37,15 +37,18 @@ pub fn expand_outer_config(
|
||||
let pallet_name = &decl.name;
|
||||
let path_str = path.into_token_stream().to_string();
|
||||
let config = format_ident!("{}Config", pallet_name);
|
||||
let field_name = &Ident::new(
|
||||
&pallet_name.to_string().to_snake_case(),
|
||||
decl.name.span(),
|
||||
);
|
||||
let field_name =
|
||||
&Ident::new(&pallet_name.to_string().to_snake_case(), decl.name.span());
|
||||
let part_is_generic = !pallet_entry.generics.params.is_empty();
|
||||
|
||||
types.extend(expand_config_types(runtime, decl, &config, part_is_generic));
|
||||
fields.extend(quote!(pub #field_name: #config,));
|
||||
build_storage_calls.extend(expand_config_build_storage_call(scrate, runtime, decl, &field_name));
|
||||
build_storage_calls.extend(expand_config_build_storage_call(
|
||||
scrate,
|
||||
runtime,
|
||||
decl,
|
||||
&field_name,
|
||||
));
|
||||
query_genesis_config_part_macros.push(quote! {
|
||||
#path::__substrate_genesis_config_check::is_genesis_config_defined!(#pallet_name);
|
||||
#[cfg(feature = "std")]
|
||||
@@ -97,15 +100,15 @@ fn expand_config_types(
|
||||
let path = &decl.path;
|
||||
|
||||
match (decl.instance.as_ref(), part_is_generic) {
|
||||
(Some(inst), true) => quote!{
|
||||
(Some(inst), true) => quote! {
|
||||
#[cfg(any(feature = "std", test))]
|
||||
pub type #config = #path::GenesisConfig<#runtime, #path::#inst>;
|
||||
},
|
||||
(None, true) => quote!{
|
||||
(None, true) => quote! {
|
||||
#[cfg(any(feature = "std", test))]
|
||||
pub type #config = #path::GenesisConfig<#runtime>;
|
||||
},
|
||||
(_, false) => quote!{
|
||||
(_, false) => quote! {
|
||||
#[cfg(any(feature = "std", test))]
|
||||
pub type #config = #path::GenesisConfig;
|
||||
},
|
||||
@@ -125,7 +128,7 @@ fn expand_config_build_storage_call(
|
||||
quote!(#path::__InherentHiddenInstance)
|
||||
};
|
||||
|
||||
quote!{
|
||||
quote! {
|
||||
#scrate::sp_runtime::BuildModuleGenesisStorage::
|
||||
<#runtime, #instance>::build_module_genesis_storage(&self.#field_name, storage)?;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ pub fn expand_outer_event(
|
||||
be constructed: pallet `{}` must have generic `Event`",
|
||||
pallet_name,
|
||||
);
|
||||
return Err(syn::Error::new(pallet_name.span(), msg));
|
||||
return Err(syn::Error::new(pallet_name.span(), msg))
|
||||
}
|
||||
|
||||
let part_is_generic = !generics.params.is_empty();
|
||||
@@ -54,7 +54,13 @@ pub fn expand_outer_event(
|
||||
(None, false) => quote!(#path::Event),
|
||||
};
|
||||
|
||||
event_variants.extend(expand_event_variant(runtime, pallet_decl, index, instance, generics));
|
||||
event_variants.extend(expand_event_variant(
|
||||
runtime,
|
||||
pallet_decl,
|
||||
index,
|
||||
instance,
|
||||
generics,
|
||||
));
|
||||
event_conversions.extend(expand_event_conversion(scrate, pallet_decl, &pallet_event));
|
||||
query_event_part_macros.push(quote! {
|
||||
#path::__substrate_event_check::is_event_part_defined!(#pallet_name);
|
||||
@@ -94,16 +100,16 @@ fn expand_event_variant(
|
||||
match instance {
|
||||
Some(inst) if part_is_generic => {
|
||||
quote!(#[codec(index = #index)] #variant_name(#path::Event<#runtime, #path::#inst>),)
|
||||
}
|
||||
},
|
||||
Some(inst) => {
|
||||
quote!(#[codec(index = #index)] #variant_name(#path::Event<#path::#inst>),)
|
||||
}
|
||||
},
|
||||
None if part_is_generic => {
|
||||
quote!(#[codec(index = #index)] #variant_name(#path::Event<#runtime>),)
|
||||
}
|
||||
},
|
||||
None => {
|
||||
quote!(#[codec(index = #index)] #variant_name(#path::Event),)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +120,7 @@ fn expand_event_conversion(
|
||||
) -> TokenStream {
|
||||
let variant_name = &pallet.name;
|
||||
|
||||
quote!{
|
||||
quote! {
|
||||
impl From<#pallet_event> for Event {
|
||||
fn from(x: #pallet_event) -> Self {
|
||||
Event::#variant_name(x)
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License
|
||||
|
||||
use proc_macro2::TokenStream;
|
||||
use crate::construct_runtime::Pallet;
|
||||
use syn::{Ident, TypePath};
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{Ident, TypePath};
|
||||
|
||||
pub fn expand_runtime_metadata(
|
||||
runtime: &Ident,
|
||||
@@ -48,7 +48,7 @@ pub fn expand_runtime_metadata(
|
||||
let constants = expand_pallet_metadata_constants(runtime, scrate, decl);
|
||||
let errors = expand_pallet_metadata_errors(runtime, scrate, decl);
|
||||
|
||||
quote!{
|
||||
quote! {
|
||||
#scrate::metadata::ModuleMetadata {
|
||||
name: #scrate::metadata::DecodeDifferent::Encode(stringify!(#name)),
|
||||
index: #index,
|
||||
@@ -62,7 +62,7 @@ pub fn expand_runtime_metadata(
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
quote!{
|
||||
quote! {
|
||||
impl #runtime {
|
||||
pub fn metadata() -> #scrate::metadata::RuntimeMetadataPrefixed {
|
||||
#scrate::metadata::RuntimeMetadataLastVersion {
|
||||
@@ -94,7 +94,7 @@ fn expand_pallet_metadata_storage(
|
||||
let instance = decl.instance.as_ref().into_iter();
|
||||
let path = &decl.path;
|
||||
|
||||
quote!{
|
||||
quote! {
|
||||
Some(#scrate::metadata::DecodeDifferent::Encode(
|
||||
#scrate::metadata::FnEncode(
|
||||
#path::Pallet::<#runtime #(, #path::#instance)*>::storage_metadata
|
||||
@@ -116,7 +116,7 @@ fn expand_pallet_metadata_calls(
|
||||
let instance = decl.instance.as_ref().into_iter();
|
||||
let path = &decl.path;
|
||||
|
||||
quote!{
|
||||
quote! {
|
||||
Some(#scrate::metadata::DecodeDifferent::Encode(
|
||||
#scrate::metadata::FnEncode(
|
||||
#path::Pallet::<#runtime #(, #path::#instance)*>::call_functions
|
||||
@@ -136,8 +136,12 @@ fn expand_pallet_metadata_events(
|
||||
) -> TokenStream {
|
||||
if filtered_names.contains(&"Event") {
|
||||
let path = &decl.path;
|
||||
let part_is_generic =
|
||||
!decl.find_part("Event").expect("Event part exists; qed").generics.params.is_empty();
|
||||
let part_is_generic = !decl
|
||||
.find_part("Event")
|
||||
.expect("Event part exists; qed")
|
||||
.generics
|
||||
.params
|
||||
.is_empty();
|
||||
let pallet_event = match (decl.instance.as_ref(), part_is_generic) {
|
||||
(Some(inst), true) => quote!(#path::Event::<#runtime, #path::#inst>),
|
||||
(Some(inst), false) => quote!(#path::Event::<#path::#inst>),
|
||||
@@ -145,7 +149,7 @@ fn expand_pallet_metadata_events(
|
||||
(None, false) => quote!(#path::Event),
|
||||
};
|
||||
|
||||
quote!{
|
||||
quote! {
|
||||
Some(#scrate::metadata::DecodeDifferent::Encode(
|
||||
#scrate::metadata::FnEncode(#pallet_event::metadata)
|
||||
))
|
||||
@@ -163,7 +167,7 @@ fn expand_pallet_metadata_constants(
|
||||
let path = &decl.path;
|
||||
let instance = decl.instance.as_ref().into_iter();
|
||||
|
||||
quote!{
|
||||
quote! {
|
||||
#scrate::metadata::DecodeDifferent::Encode(
|
||||
#scrate::metadata::FnEncode(
|
||||
#path::Pallet::<#runtime #(, #path::#instance)*>::module_constants_metadata
|
||||
@@ -180,7 +184,7 @@ fn expand_pallet_metadata_errors(
|
||||
let path = &decl.path;
|
||||
let instance = decl.instance.as_ref().into_iter();
|
||||
|
||||
quote!{
|
||||
quote! {
|
||||
#scrate::metadata::DecodeDifferent::Encode(
|
||||
#scrate::metadata::FnEncode(
|
||||
<#path::Pallet::<#runtime #(, #path::#instance)*> as #scrate::metadata::ModuleErrorMetadata>::metadata
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
use crate::construct_runtime::{Pallet, SYSTEM_PALLET_NAME};
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{token, Ident, Generics};
|
||||
use syn::{token, Generics, Ident};
|
||||
|
||||
pub fn expand_outer_origin(
|
||||
runtime: &Ident,
|
||||
@@ -26,13 +26,14 @@ pub fn expand_outer_origin(
|
||||
pallets_token: token::Brace,
|
||||
scrate: &TokenStream,
|
||||
) -> syn::Result<TokenStream> {
|
||||
let system_pallet = pallets.iter()
|
||||
.find(|decl| decl.name == SYSTEM_PALLET_NAME)
|
||||
.ok_or_else(|| syn::Error::new(
|
||||
pallets_token.span,
|
||||
"`System` pallet declaration is missing. \
|
||||
let system_pallet =
|
||||
pallets.iter().find(|decl| decl.name == SYSTEM_PALLET_NAME).ok_or_else(|| {
|
||||
syn::Error::new(
|
||||
pallets_token.span,
|
||||
"`System` pallet declaration is missing. \
|
||||
Please add this line: `System: frame_system::{Pallet, Call, Storage, Config, Event<T>},`",
|
||||
))?;
|
||||
)
|
||||
})?;
|
||||
|
||||
let mut caller_variants = TokenStream::new();
|
||||
let mut pallet_conversions = TokenStream::new();
|
||||
@@ -52,15 +53,23 @@ pub fn expand_outer_origin(
|
||||
be constructed: pallet `{}` must have generic `Origin`",
|
||||
name
|
||||
);
|
||||
return Err(syn::Error::new(name.span(), msg));
|
||||
return Err(syn::Error::new(name.span(), msg))
|
||||
}
|
||||
|
||||
caller_variants.extend(
|
||||
expand_origin_caller_variant(runtime, pallet_decl, index, instance, generics),
|
||||
);
|
||||
pallet_conversions.extend(
|
||||
expand_origin_pallet_conversions(scrate, runtime, pallet_decl, instance, generics),
|
||||
);
|
||||
caller_variants.extend(expand_origin_caller_variant(
|
||||
runtime,
|
||||
pallet_decl,
|
||||
index,
|
||||
instance,
|
||||
generics,
|
||||
));
|
||||
pallet_conversions.extend(expand_origin_pallet_conversions(
|
||||
scrate,
|
||||
runtime,
|
||||
pallet_decl,
|
||||
instance,
|
||||
generics,
|
||||
));
|
||||
query_origin_part_macros.push(quote! {
|
||||
#path::__substrate_origin_check::is_origin_part_defined!(#name);
|
||||
});
|
||||
@@ -270,16 +279,16 @@ fn expand_origin_caller_variant(
|
||||
match instance {
|
||||
Some(inst) if part_is_generic => {
|
||||
quote!(#[codec(index = #index)] #variant_name(#path::Origin<#runtime, #path::#inst>),)
|
||||
}
|
||||
},
|
||||
Some(inst) => {
|
||||
quote!(#[codec(index = #index)] #variant_name(#path::Origin<#path::#inst>),)
|
||||
}
|
||||
},
|
||||
None if part_is_generic => {
|
||||
quote!(#[codec(index = #index)] #variant_name(#path::Origin<#runtime>),)
|
||||
}
|
||||
},
|
||||
None => {
|
||||
quote!(#[codec(index = #index)] #variant_name(#path::Origin),)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,7 +310,7 @@ fn expand_origin_pallet_conversions(
|
||||
None => quote!(#path::Origin),
|
||||
};
|
||||
|
||||
quote!{
|
||||
quote! {
|
||||
impl From<#pallet_origin> for OriginCaller {
|
||||
fn from(x: #pallet_origin) -> Self {
|
||||
OriginCaller::#variant_name(x)
|
||||
|
||||
@@ -18,14 +18,15 @@
|
||||
mod expand;
|
||||
mod parse;
|
||||
|
||||
use frame_support_procedural_tools::syn_ext as ext;
|
||||
use frame_support_procedural_tools::{generate_crate_access, generate_hidden_includes};
|
||||
use frame_support_procedural_tools::{
|
||||
generate_crate_access, generate_hidden_includes, syn_ext as ext,
|
||||
};
|
||||
use parse::{PalletDeclaration, PalletPart, PalletPath, RuntimeDefinition, WhereSection};
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::quote;
|
||||
use syn::{Ident, Result};
|
||||
use std::collections::HashMap;
|
||||
use syn::{Ident, Result};
|
||||
|
||||
/// The fixed name of the system pallet.
|
||||
const SYSTEM_PALLET_NAME: &str = "System";
|
||||
@@ -65,48 +66,44 @@ fn complete_pallets(decl: impl Iterator<Item = PalletDeclaration>) -> syn::Resul
|
||||
let mut last_index: Option<u8> = None;
|
||||
let mut names = HashMap::new();
|
||||
|
||||
decl
|
||||
.map(|pallet| {
|
||||
let final_index = match pallet.index {
|
||||
Some(i) => i,
|
||||
None => last_index.map_or(Some(0), |i| i.checked_add(1))
|
||||
.ok_or_else(|| {
|
||||
let msg = "Pallet index doesn't fit into u8, index is 256";
|
||||
syn::Error::new(pallet.name.span(), msg)
|
||||
})?,
|
||||
};
|
||||
decl.map(|pallet| {
|
||||
let final_index = match pallet.index {
|
||||
Some(i) => i,
|
||||
None => last_index.map_or(Some(0), |i| i.checked_add(1)).ok_or_else(|| {
|
||||
let msg = "Pallet index doesn't fit into u8, index is 256";
|
||||
syn::Error::new(pallet.name.span(), msg)
|
||||
})?,
|
||||
};
|
||||
|
||||
last_index = Some(final_index);
|
||||
last_index = Some(final_index);
|
||||
|
||||
if let Some(used_pallet) = indices.insert(final_index, pallet.name.clone()) {
|
||||
let msg = format!(
|
||||
"Pallet indices are conflicting: Both pallets {} and {} are at index {}",
|
||||
used_pallet,
|
||||
pallet.name,
|
||||
final_index,
|
||||
);
|
||||
let mut err = syn::Error::new(used_pallet.span(), &msg);
|
||||
err.combine(syn::Error::new(pallet.name.span(), msg));
|
||||
return Err(err);
|
||||
}
|
||||
if let Some(used_pallet) = indices.insert(final_index, pallet.name.clone()) {
|
||||
let msg = format!(
|
||||
"Pallet indices are conflicting: Both pallets {} and {} are at index {}",
|
||||
used_pallet, pallet.name, final_index,
|
||||
);
|
||||
let mut err = syn::Error::new(used_pallet.span(), &msg);
|
||||
err.combine(syn::Error::new(pallet.name.span(), msg));
|
||||
return Err(err)
|
||||
}
|
||||
|
||||
if let Some(used_pallet) = names.insert(pallet.name.clone(), pallet.name.span()) {
|
||||
let msg = "Two pallets with the same name!";
|
||||
if let Some(used_pallet) = names.insert(pallet.name.clone(), pallet.name.span()) {
|
||||
let msg = "Two pallets with the same name!";
|
||||
|
||||
let mut err = syn::Error::new(used_pallet, &msg);
|
||||
err.combine(syn::Error::new(pallet.name.span(), &msg));
|
||||
return Err(err);
|
||||
}
|
||||
let mut err = syn::Error::new(used_pallet, &msg);
|
||||
err.combine(syn::Error::new(pallet.name.span(), &msg));
|
||||
return Err(err)
|
||||
}
|
||||
|
||||
Ok(Pallet {
|
||||
name: pallet.name,
|
||||
index: final_index,
|
||||
path: pallet.path,
|
||||
instance: pallet.instance,
|
||||
pallet_parts: pallet.pallet_parts,
|
||||
})
|
||||
Ok(Pallet {
|
||||
name: pallet.name,
|
||||
index: final_index,
|
||||
path: pallet.path,
|
||||
instance: pallet.instance,
|
||||
pallet_parts: pallet.pallet_parts,
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn construct_runtime(input: TokenStream) -> TokenStream {
|
||||
@@ -119,17 +116,9 @@ pub fn construct_runtime(input: TokenStream) -> TokenStream {
|
||||
fn construct_runtime_parsed(definition: RuntimeDefinition) -> Result<TokenStream2> {
|
||||
let RuntimeDefinition {
|
||||
name,
|
||||
where_section: WhereSection {
|
||||
block,
|
||||
node_block,
|
||||
unchecked_extrinsic,
|
||||
..
|
||||
},
|
||||
where_section: WhereSection { block, node_block, unchecked_extrinsic, .. },
|
||||
pallets:
|
||||
ext::Braces {
|
||||
content: ext::Punctuated { inner: pallets, .. },
|
||||
token: pallets_token,
|
||||
},
|
||||
ext::Braces { content: ext::Punctuated { inner: pallets, .. }, token: pallets_token },
|
||||
..
|
||||
} = definition;
|
||||
|
||||
@@ -148,13 +137,8 @@ fn construct_runtime_parsed(definition: RuntimeDefinition) -> Result<TokenStream
|
||||
let dispatch = expand::expand_outer_dispatch(&name, &pallets, &scrate);
|
||||
let metadata = expand::expand_runtime_metadata(&name, &pallets, &scrate, &unchecked_extrinsic);
|
||||
let outer_config = expand::expand_outer_config(&name, &pallets, &scrate);
|
||||
let inherent = expand::expand_outer_inherent(
|
||||
&name,
|
||||
&block,
|
||||
&unchecked_extrinsic,
|
||||
&pallets,
|
||||
&scrate,
|
||||
);
|
||||
let inherent =
|
||||
expand::expand_outer_inherent(&name, &block, &unchecked_extrinsic, &pallets, &scrate);
|
||||
let validate_unsigned = expand::expand_outer_validate_unsigned(&name, &pallets, &scrate);
|
||||
let integrity_test = decl_integrity_test(&scrate);
|
||||
|
||||
@@ -210,12 +194,7 @@ fn decl_all_pallets<'a>(
|
||||
let type_name = &pallet_declaration.name;
|
||||
let pallet = &pallet_declaration.path;
|
||||
let mut generics = vec![quote!(#runtime)];
|
||||
generics.extend(
|
||||
pallet_declaration
|
||||
.instance
|
||||
.iter()
|
||||
.map(|name| quote!(#pallet::#name)),
|
||||
);
|
||||
generics.extend(pallet_declaration.instance.iter().map(|name| quote!(#pallet::#name)));
|
||||
let type_decl = quote!(
|
||||
pub type #type_name = #pallet::Pallet <#(#generics),*>;
|
||||
);
|
||||
@@ -224,11 +203,13 @@ fn decl_all_pallets<'a>(
|
||||
}
|
||||
// Make nested tuple structure like (((Babe, Consensus), Grandpa), ...)
|
||||
// But ignore the system pallet.
|
||||
let all_pallets = names.iter()
|
||||
let all_pallets = names
|
||||
.iter()
|
||||
.filter(|n| **n != SYSTEM_PALLET_NAME)
|
||||
.fold(TokenStream2::default(), |combined, name| quote!((#name, #combined)));
|
||||
|
||||
let all_pallets_with_system = names.iter()
|
||||
let all_pallets_with_system = names
|
||||
.iter()
|
||||
.fold(TokenStream2::default(), |combined, name| quote!((#name, #combined)));
|
||||
|
||||
quote!(
|
||||
@@ -258,8 +239,7 @@ fn decl_pallet_runtime_setup(
|
||||
let names = pallet_declarations.iter().map(|d| &d.name);
|
||||
let names2 = pallet_declarations.iter().map(|d| &d.name);
|
||||
let name_strings = pallet_declarations.iter().map(|d| d.name.to_string());
|
||||
let indices = pallet_declarations.iter()
|
||||
.map(|pallet| pallet.index as usize);
|
||||
let indices = pallet_declarations.iter().map(|pallet| pallet.index as usize);
|
||||
|
||||
quote!(
|
||||
/// Provides an implementation of `PalletInfo` to provide information
|
||||
|
||||
@@ -77,9 +77,9 @@ impl Parse for WhereSection {
|
||||
definitions.push(definition);
|
||||
if !input.peek(Token![,]) {
|
||||
if !input.peek(token::Brace) {
|
||||
return Err(input.error("Expected `,` or `{`"));
|
||||
return Err(input.error("Expected `,` or `{`"))
|
||||
}
|
||||
break;
|
||||
break
|
||||
}
|
||||
input.parse::<Token![,]>()?;
|
||||
}
|
||||
@@ -87,23 +87,14 @@ impl Parse for WhereSection {
|
||||
let node_block = remove_kind(input, WhereKind::NodeBlock, &mut definitions)?.value;
|
||||
let unchecked_extrinsic =
|
||||
remove_kind(input, WhereKind::UncheckedExtrinsic, &mut definitions)?.value;
|
||||
if let Some(WhereDefinition {
|
||||
ref kind_span,
|
||||
ref kind,
|
||||
..
|
||||
}) = definitions.first()
|
||||
{
|
||||
if let Some(WhereDefinition { ref kind_span, ref kind, .. }) = definitions.first() {
|
||||
let msg = format!(
|
||||
"`{:?}` was declared above. Please use exactly one declaration for `{:?}`.",
|
||||
kind, kind
|
||||
);
|
||||
return Err(Error::new(*kind_span, msg));
|
||||
return Err(Error::new(*kind_span, msg))
|
||||
}
|
||||
Ok(Self {
|
||||
block,
|
||||
node_block,
|
||||
unchecked_extrinsic,
|
||||
})
|
||||
Ok(Self { block, node_block, unchecked_extrinsic })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,17 +118,11 @@ impl Parse for WhereDefinition {
|
||||
let (kind_span, kind) = if lookahead.peek(keyword::Block) {
|
||||
(input.parse::<keyword::Block>()?.span(), WhereKind::Block)
|
||||
} else if lookahead.peek(keyword::NodeBlock) {
|
||||
(
|
||||
input.parse::<keyword::NodeBlock>()?.span(),
|
||||
WhereKind::NodeBlock,
|
||||
)
|
||||
(input.parse::<keyword::NodeBlock>()?.span(), WhereKind::NodeBlock)
|
||||
} else if lookahead.peek(keyword::UncheckedExtrinsic) {
|
||||
(
|
||||
input.parse::<keyword::UncheckedExtrinsic>()?.span(),
|
||||
WhereKind::UncheckedExtrinsic,
|
||||
)
|
||||
(input.parse::<keyword::UncheckedExtrinsic>()?.span(), WhereKind::UncheckedExtrinsic)
|
||||
} else {
|
||||
return Err(lookahead.error());
|
||||
return Err(lookahead.error())
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
@@ -187,13 +172,7 @@ impl Parse for PalletDeclaration {
|
||||
None
|
||||
};
|
||||
|
||||
let parsed = Self {
|
||||
name,
|
||||
path,
|
||||
instance,
|
||||
pallet_parts,
|
||||
index,
|
||||
};
|
||||
let parsed = Self { name, path, instance, pallet_parts, index };
|
||||
|
||||
Ok(parsed)
|
||||
}
|
||||
@@ -214,17 +193,17 @@ impl Parse for PalletPath {
|
||||
let mut lookahead = input.lookahead1();
|
||||
let mut segments = Punctuated::new();
|
||||
|
||||
if lookahead.peek(Token![crate])
|
||||
|| lookahead.peek(Token![self])
|
||||
|| lookahead.peek(Token![super])
|
||||
|| lookahead.peek(Ident)
|
||||
if lookahead.peek(Token![crate]) ||
|
||||
lookahead.peek(Token![self]) ||
|
||||
lookahead.peek(Token![super]) ||
|
||||
lookahead.peek(Ident)
|
||||
{
|
||||
let ident = input.call(Ident::parse_any)?;
|
||||
segments.push(PathSegment { ident, arguments: PathArguments::None });
|
||||
let _: Token![::] = input.parse()?;
|
||||
lookahead = input.lookahead1();
|
||||
} else {
|
||||
return Err(lookahead.error());
|
||||
return Err(lookahead.error())
|
||||
}
|
||||
|
||||
while lookahead.peek(Ident) {
|
||||
@@ -235,15 +214,10 @@ impl Parse for PalletPath {
|
||||
}
|
||||
|
||||
if !lookahead.peek(token::Brace) && !lookahead.peek(Token![<]) {
|
||||
return Err(lookahead.error());
|
||||
return Err(lookahead.error())
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
inner: Path {
|
||||
leading_colon: None,
|
||||
segments,
|
||||
}
|
||||
})
|
||||
Ok(Self { inner: Path { leading_colon: None, segments } })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,7 +231,7 @@ impl quote::ToTokens for PalletPath {
|
||||
///
|
||||
/// `{ Call, Event }`
|
||||
fn parse_pallet_parts(input: ParseStream) -> Result<Vec<PalletPart>> {
|
||||
let pallet_parts :ext::Braces<ext::Punctuated<PalletPart, Token![,]>> = input.parse()?;
|
||||
let pallet_parts: ext::Braces<ext::Punctuated<PalletPart, Token![,]>> = input.parse()?;
|
||||
|
||||
let mut resolved = HashSet::new();
|
||||
for part in pallet_parts.content.inner.iter() {
|
||||
@@ -266,7 +240,7 @@ fn parse_pallet_parts(input: ParseStream) -> Result<Vec<PalletPart>> {
|
||||
"`{}` was already declared before. Please remove the duplicate declaration",
|
||||
part.name(),
|
||||
);
|
||||
return Err(Error::new(part.keyword.span(), msg));
|
||||
return Err(Error::new(part.keyword.span(), msg))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,13 +345,10 @@ impl Parse for PalletPart {
|
||||
keyword.name(),
|
||||
valid_generics,
|
||||
);
|
||||
return Err(syn::Error::new(keyword.span(), msg));
|
||||
return Err(syn::Error::new(keyword.span(), msg))
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
keyword,
|
||||
generics,
|
||||
})
|
||||
Ok(Self { keyword, generics })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user