mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 12:48:00 +00:00
Emit error when construct_runtime imports a non-existent pallet part (#8949)
* Emit error when construct_runtime imports a non-existent Call part * Reword and display pallet name when emitting part not found error * Migrate decl_outer_dispatch to a proc macro * Rename calls.rs to call.rs * Create new construct_runtime_v2 macro * Add UI test for importing non-existent call part in construct_runtime * Emit error when construct_runtime imports a non-existent Config part * Emit error when construct_runtime imports a non-existent Event part * Migrate decl_outer_inherent to a proc macro * Emit error when construct_runtime imports a non-existent Inherent part * Migrate decl_outer_validate_unsigned to a proc macro * Emit error when construct_runtime imports a non-existent ValidateUnsigned part * impl for old macro * fix line width * add doc * hide macroes and use unique counter everywhere * Remove construct_runtime_v2 * Encapsulate pallet part check macros in a module * Fix macro definitions in dummy part checker * Tag ProvideInherent impl with #[pallet::inherent] properly for authorship pallet * Remove Call part from pallets that do not define it * Add Call part unit tests * Remove undefined Call part import from offences pallet * Add tests for expand_outer_inherent * Remove Call part from pallets that do not define them * Remove Call part imports from pallets that do not have it defined * Remove Call part import of the offences pallet from grandpa pallet mocks * Update frame/support/test/tests/pallet.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Remove Call part imports for pallets that do not define them * Move inherent tests to inherent_expand * Add unit tests for expand_outer_validate_unsigned * Add newline at the end of file * fix ui test * Small prayer to RNGsus for fixing CI * Remove Call part from construct_runtime for randomness collective flip pallet * Remove Call part import for randomness collective flip pallet * Summon Laplace's demon instead of praying to RNGsus * Update test expectations * fix ui test and make sure it's flaky * Revert "fix ui test and make sure it's flaky" This reverts commit 362b6881389c911ef8d9ef85d71c9463f5694b20. * Comment out test instead of putting it in conditional compilation * Update UI test expectations * Update UI test expectations * Emit error when construct_runtime imports a non-existent Origin part Co-authored-by: thiolliere <gui.thiolliere@gmail.com> Co-authored-by: Denis P <denis.pisarev@parity.io>
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2021 Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License
|
||||
|
||||
use crate::construct_runtime::Pallet;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::Ident;
|
||||
|
||||
pub fn expand_outer_dispatch(
|
||||
runtime: &Ident,
|
||||
pallet_decls: &[Pallet],
|
||||
scrate: &TokenStream,
|
||||
) -> TokenStream {
|
||||
let mut variant_defs = TokenStream::new();
|
||||
let mut variant_patterns = Vec::new();
|
||||
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"));
|
||||
|
||||
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_patterns.push(quote!(Call::#name(call)));
|
||||
pallet_names.push(name);
|
||||
query_call_part_macros.push(quote! {
|
||||
#path::__substrate_call_check::is_call_part_defined!(#name);
|
||||
});
|
||||
}
|
||||
|
||||
quote! {
|
||||
#( #query_call_part_macros )*
|
||||
|
||||
#[derive(
|
||||
Clone, PartialEq, Eq,
|
||||
#scrate::codec::Encode,
|
||||
#scrate::codec::Decode,
|
||||
#scrate::RuntimeDebug,
|
||||
)]
|
||||
pub enum Call {
|
||||
#variant_defs
|
||||
}
|
||||
impl #scrate::dispatch::GetDispatchInfo for Call {
|
||||
fn get_dispatch_info(&self) -> #scrate::dispatch::DispatchInfo {
|
||||
match self {
|
||||
#( #variant_patterns => call.get_dispatch_info(), )*
|
||||
}
|
||||
}
|
||||
}
|
||||
impl #scrate::dispatch::GetCallMetadata for Call {
|
||||
fn get_call_metadata(&self) -> #scrate::dispatch::CallMetadata {
|
||||
use #scrate::dispatch::GetCallName;
|
||||
match self {
|
||||
#(
|
||||
#variant_patterns => {
|
||||
let function_name = call.get_call_name();
|
||||
let pallet_name = stringify!(#pallet_names);
|
||||
#scrate::dispatch::CallMetadata { function_name, pallet_name }
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
fn get_module_names() -> &'static [&'static str] {
|
||||
&[#(
|
||||
stringify!(#pallet_names),
|
||||
)*]
|
||||
}
|
||||
|
||||
fn get_call_names(module: &str) -> &'static [&'static str] {
|
||||
use #scrate::dispatch::{Callable, GetCallName};
|
||||
match module {
|
||||
#(
|
||||
stringify!(#pallet_names) =>
|
||||
<<#pallet_names as Callable<#runtime>>::Call
|
||||
as GetCallName>::get_call_names(),
|
||||
)*
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl #scrate::dispatch::Dispatchable for Call {
|
||||
type Origin = Origin;
|
||||
type Config = Call;
|
||||
type Info = #scrate::weights::DispatchInfo;
|
||||
type PostInfo = #scrate::weights::PostDispatchInfo;
|
||||
fn dispatch(self, origin: Origin) -> #scrate::dispatch::DispatchResultWithPostInfo {
|
||||
if !<Self::Origin as #scrate::traits::OriginTrait>::filter_call(&origin, &self) {
|
||||
return #scrate::sp_std::result::Result::Err(#scrate::dispatch::DispatchError::BadOrigin.into());
|
||||
}
|
||||
|
||||
#scrate::traits::UnfilteredDispatchable::dispatch_bypass_filter(self, origin)
|
||||
}
|
||||
}
|
||||
impl #scrate::traits::UnfilteredDispatchable for Call {
|
||||
type Origin = Origin;
|
||||
fn dispatch_bypass_filter(self, origin: Origin) -> #scrate::dispatch::DispatchResultWithPostInfo {
|
||||
match self {
|
||||
#(
|
||||
#variant_patterns =>
|
||||
#scrate::traits::UnfilteredDispatchable::dispatch_bypass_filter(call, origin),
|
||||
)*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#(
|
||||
impl #scrate::traits::IsSubType<#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> for Call {
|
||||
#[allow(unreachable_patterns)]
|
||||
fn is_sub_type(&self) -> Option<&#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> {
|
||||
match self {
|
||||
#variant_patterns => Some(call),
|
||||
// May be unreachable
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> for Call {
|
||||
fn from(call: #scrate::dispatch::CallableCallFor<#pallet_names, #runtime>) -> Self {
|
||||
#variant_patterns
|
||||
}
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
@@ -29,21 +29,31 @@ pub fn expand_outer_config(
|
||||
let mut types = TokenStream::new();
|
||||
let mut fields = TokenStream::new();
|
||||
let mut build_storage_calls = TokenStream::new();
|
||||
let mut query_genesis_config_part_macros = Vec::new();
|
||||
|
||||
for decl in pallet_decls {
|
||||
if let Some(pallet_entry) = decl.find_part("Config") {
|
||||
let config = format_ident!("{}Config", decl.name);
|
||||
let pallet_name = &decl.name.to_string().to_snake_case();
|
||||
let field_name = &Ident::new(pallet_name, decl.name.span());
|
||||
let path = &decl.path;
|
||||
let pallet_name = &decl.name;
|
||||
let config = format_ident!("{}Config", pallet_name);
|
||||
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));
|
||||
query_genesis_config_part_macros.push(quote! {
|
||||
#path::__substrate_genesis_config_check::is_genesis_config_defined!(#pallet_name);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
quote!{
|
||||
quote! {
|
||||
#( #query_genesis_config_part_macros )*
|
||||
|
||||
#types
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
|
||||
@@ -27,10 +27,12 @@ pub fn expand_outer_event(
|
||||
) -> syn::Result<TokenStream> {
|
||||
let mut event_variants = TokenStream::new();
|
||||
let mut event_conversions = TokenStream::new();
|
||||
let mut query_event_part_macros = Vec::new();
|
||||
|
||||
for pallet_decl in pallet_decls {
|
||||
if let Some(pallet_entry) = pallet_decl.find_part("Event") {
|
||||
let path = &pallet_decl.path;
|
||||
let pallet_name = &pallet_decl.name;
|
||||
let index = pallet_decl.index;
|
||||
let instance = pallet_decl.instance.as_ref();
|
||||
let generics = &pallet_entry.generics;
|
||||
@@ -39,9 +41,9 @@ pub fn expand_outer_event(
|
||||
let msg = format!(
|
||||
"Instantiable pallet with no generic `Event` cannot \
|
||||
be constructed: pallet `{}` must have generic `Event`",
|
||||
pallet_decl.name,
|
||||
pallet_name,
|
||||
);
|
||||
return Err(syn::Error::new(pallet_decl.name.span(), msg));
|
||||
return Err(syn::Error::new(pallet_name.span(), msg));
|
||||
}
|
||||
|
||||
let part_is_generic = !generics.params.is_empty();
|
||||
@@ -54,10 +56,15 @@ pub fn expand_outer_event(
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Ok(quote!{
|
||||
Ok(quote! {
|
||||
#( #query_event_part_macros )*
|
||||
|
||||
#[derive(
|
||||
Clone, PartialEq, Eq,
|
||||
#scrate::codec::Encode,
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2021 Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License
|
||||
|
||||
use crate::construct_runtime::Pallet;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{Ident, TypePath};
|
||||
|
||||
pub fn expand_outer_inherent(
|
||||
runtime: &Ident,
|
||||
block: &TypePath,
|
||||
unchecked_extrinsic: &TypePath,
|
||||
pallet_decls: &[Pallet],
|
||||
scrate: &TokenStream,
|
||||
) -> TokenStream {
|
||||
let mut pallet_names = Vec::new();
|
||||
let mut query_inherent_part_macros = Vec::new();
|
||||
|
||||
for pallet_decl in pallet_decls {
|
||||
if pallet_decl.exists_part("Inherent") {
|
||||
let name = &pallet_decl.name;
|
||||
let path = &pallet_decl.path;
|
||||
|
||||
pallet_names.push(name);
|
||||
query_inherent_part_macros.push(quote! {
|
||||
#path::__substrate_inherent_check::is_inherent_part_defined!(#name);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
quote! {
|
||||
#( #query_inherent_part_macros )*
|
||||
|
||||
trait InherentDataExt {
|
||||
fn create_extrinsics(&self) ->
|
||||
#scrate::inherent::Vec<<#block as #scrate::inherent::BlockT>::Extrinsic>;
|
||||
fn check_extrinsics(&self, block: &#block) -> #scrate::inherent::CheckInherentsResult;
|
||||
}
|
||||
|
||||
impl InherentDataExt for #scrate::inherent::InherentData {
|
||||
fn create_extrinsics(&self) ->
|
||||
#scrate::inherent::Vec<<#block as #scrate::inherent::BlockT>::Extrinsic>
|
||||
{
|
||||
use #scrate::inherent::ProvideInherent;
|
||||
|
||||
let mut inherents = Vec::new();
|
||||
|
||||
#(
|
||||
if let Some(inherent) = #pallet_names::create_inherent(self) {
|
||||
let inherent = <#unchecked_extrinsic as #scrate::inherent::Extrinsic>::new(
|
||||
inherent.into(),
|
||||
None,
|
||||
).expect("Runtime UncheckedExtrinsic is not Opaque, so it has to return \
|
||||
`Some`; qed");
|
||||
|
||||
inherents.push(inherent);
|
||||
}
|
||||
)*
|
||||
|
||||
inherents
|
||||
}
|
||||
|
||||
fn check_extrinsics(&self, block: &#block) -> #scrate::inherent::CheckInherentsResult {
|
||||
use #scrate::inherent::{ProvideInherent, IsFatalError};
|
||||
use #scrate::traits::{IsSubType, ExtrinsicCall};
|
||||
use #scrate::sp_runtime::traits::Block as _;
|
||||
|
||||
let mut result = #scrate::inherent::CheckInherentsResult::new();
|
||||
|
||||
for xt in block.extrinsics() {
|
||||
// Inherents are before any other extrinsics.
|
||||
// And signed extrinsics are not inherents.
|
||||
if #scrate::inherent::Extrinsic::is_signed(xt).unwrap_or(false) {
|
||||
break
|
||||
}
|
||||
|
||||
let mut is_inherent = false;
|
||||
|
||||
#({
|
||||
let call = <#unchecked_extrinsic as ExtrinsicCall>::call(xt);
|
||||
if let Some(call) = IsSubType::<_>::is_sub_type(call) {
|
||||
if #pallet_names::is_inherent(call) {
|
||||
is_inherent = true;
|
||||
if let Err(e) = #pallet_names::check_inherent(call, self) {
|
||||
result.put_error(
|
||||
#pallet_names::INHERENT_IDENTIFIER, &e
|
||||
).expect("There is only one fatal error; qed");
|
||||
if e.is_fatal_error() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})*
|
||||
|
||||
// Inherents are before any other extrinsics.
|
||||
// No module marked it as inherent thus it is not.
|
||||
if !is_inherent {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
#(
|
||||
match #pallet_names::is_inherent_required(self) {
|
||||
Ok(Some(e)) => {
|
||||
let found = block.extrinsics().iter().any(|xt| {
|
||||
let is_signed = #scrate::inherent::Extrinsic::is_signed(xt)
|
||||
.unwrap_or(false);
|
||||
|
||||
if !is_signed {
|
||||
let call = <
|
||||
#unchecked_extrinsic as ExtrinsicCall
|
||||
>::call(xt);
|
||||
if let Some(call) = IsSubType::<_>::is_sub_type(call) {
|
||||
#pallet_names::is_inherent(&call)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
// Signed extrinsics are not inherents.
|
||||
false
|
||||
}
|
||||
});
|
||||
|
||||
if !found {
|
||||
result.put_error(
|
||||
#pallet_names::INHERENT_IDENTIFIER, &e
|
||||
).expect("There is only one fatal error; qed");
|
||||
if e.is_fatal_error() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
},
|
||||
Ok(None) => (),
|
||||
Err(e) => {
|
||||
result.put_error(
|
||||
#pallet_names::INHERENT_IDENTIFIER, &e
|
||||
).expect("There is only one fatal error; qed");
|
||||
if e.is_fatal_error() {
|
||||
return result;
|
||||
}
|
||||
},
|
||||
}
|
||||
)*
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl #scrate::traits::EnsureInherentsAreFirst<#block> for #runtime {
|
||||
fn ensure_inherents_are_first(block: &#block) -> Result<(), u32> {
|
||||
use #scrate::inherent::ProvideInherent;
|
||||
use #scrate::traits::{IsSubType, ExtrinsicCall};
|
||||
use #scrate::sp_runtime::traits::Block as _;
|
||||
|
||||
let mut first_signed_observed = false;
|
||||
|
||||
for (i, xt) in block.extrinsics().iter().enumerate() {
|
||||
let is_signed = #scrate::inherent::Extrinsic::is_signed(xt).unwrap_or(false);
|
||||
|
||||
let is_inherent = if is_signed {
|
||||
// Signed extrinsics are not inherents.
|
||||
false
|
||||
} else {
|
||||
let mut is_inherent = false;
|
||||
#({
|
||||
let call = <#unchecked_extrinsic as ExtrinsicCall>::call(xt);
|
||||
if let Some(call) = IsSubType::<_>::is_sub_type(call) {
|
||||
if #pallet_names::is_inherent(&call) {
|
||||
is_inherent = true;
|
||||
}
|
||||
}
|
||||
})*
|
||||
is_inherent
|
||||
};
|
||||
|
||||
if !is_inherent {
|
||||
first_signed_observed = true;
|
||||
}
|
||||
|
||||
if first_signed_observed && is_inherent {
|
||||
return Err(i as u32)
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,18 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License
|
||||
|
||||
mod call;
|
||||
mod config;
|
||||
mod event;
|
||||
mod inherent;
|
||||
mod metadata;
|
||||
mod origin;
|
||||
mod unsigned;
|
||||
|
||||
pub use call::expand_outer_dispatch;
|
||||
pub use config::expand_outer_config;
|
||||
pub use event::expand_outer_event;
|
||||
pub use inherent::expand_outer_inherent;
|
||||
pub use metadata::expand_runtime_metadata;
|
||||
pub use origin::expand_outer_origin;
|
||||
pub use unsigned::expand_outer_validate_unsigned;
|
||||
|
||||
@@ -36,20 +36,23 @@ pub fn expand_outer_origin(
|
||||
|
||||
let mut caller_variants = TokenStream::new();
|
||||
let mut pallet_conversions = TokenStream::new();
|
||||
let mut query_origin_part_macros = Vec::new();
|
||||
|
||||
for pallet_decl in pallets.iter().filter(|pallet| pallet.name != SYSTEM_PALLET_NAME) {
|
||||
if let Some(pallet_entry) = pallet_decl.find_part("Origin") {
|
||||
let instance = pallet_decl.instance.as_ref();
|
||||
let index = pallet_decl.index;
|
||||
let generics = &pallet_entry.generics;
|
||||
let name = &pallet_decl.name;
|
||||
let path = &pallet_decl.path;
|
||||
|
||||
if instance.is_some() && generics.params.is_empty() {
|
||||
let msg = format!(
|
||||
"Instantiable pallet with no generic `Origin` cannot \
|
||||
be constructed: pallet `{}` must have generic `Origin`",
|
||||
pallet_decl.name
|
||||
name
|
||||
);
|
||||
return Err(syn::Error::new(pallet_decl.name.span(), msg));
|
||||
return Err(syn::Error::new(name.span(), msg));
|
||||
}
|
||||
|
||||
caller_variants.extend(
|
||||
@@ -58,13 +61,18 @@ pub fn expand_outer_origin(
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let system_path = &system_pallet.path;
|
||||
let system_index = system_pallet.index;
|
||||
|
||||
Ok(quote!{
|
||||
Ok(quote! {
|
||||
#( #query_origin_part_macros )*
|
||||
|
||||
// WARNING: All instance must hold the filter `frame_system::Config::BaseCallFilter`, except
|
||||
// when caller is system Root. One can use `OriginTrait::reset_filter` to do so.
|
||||
#[derive(Clone)]
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2021 Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License
|
||||
|
||||
use crate::construct_runtime::Pallet;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::Ident;
|
||||
|
||||
pub fn expand_outer_validate_unsigned(
|
||||
runtime: &Ident,
|
||||
pallet_decls: &[Pallet],
|
||||
scrate: &TokenStream,
|
||||
) -> TokenStream {
|
||||
let mut pallet_names = Vec::new();
|
||||
let mut query_validate_unsigned_part_macros = Vec::new();
|
||||
|
||||
for pallet_decl in pallet_decls {
|
||||
if pallet_decl.exists_part("ValidateUnsigned") {
|
||||
let name = &pallet_decl.name;
|
||||
let path = &pallet_decl.path;
|
||||
|
||||
pallet_names.push(name);
|
||||
query_validate_unsigned_part_macros.push(quote! {
|
||||
#path::__substrate_validate_unsigned_check::is_validate_unsigned_part_defined!(#name);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
quote! {
|
||||
#( #query_validate_unsigned_part_macros )*
|
||||
|
||||
impl #scrate::unsigned::ValidateUnsigned for #runtime {
|
||||
type Call = Call;
|
||||
|
||||
fn pre_dispatch(call: &Self::Call) -> Result<(), #scrate::unsigned::TransactionValidityError> {
|
||||
#[allow(unreachable_patterns)]
|
||||
match call {
|
||||
#( Call::#pallet_names(inner_call) => #pallet_names::pre_dispatch(inner_call), )*
|
||||
// pre-dispatch should not stop inherent extrinsics, validation should prevent
|
||||
// including arbitrary (non-inherent) extrinsics to blocks.
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_unsigned(
|
||||
#[allow(unused_variables)]
|
||||
source: #scrate::unsigned::TransactionSource,
|
||||
call: &Self::Call,
|
||||
) -> #scrate::unsigned::TransactionValidity {
|
||||
#[allow(unreachable_patterns)]
|
||||
match call {
|
||||
#( Call::#pallet_names(inner_call) => #pallet_names::validate_unsigned(source, inner_call), )*
|
||||
_ => #scrate::unsigned::UnknownTransaction::NoUnsignedValidator.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,17 +145,17 @@ fn construct_runtime_parsed(definition: RuntimeDefinition) -> Result<TokenStream
|
||||
let all_pallets = decl_all_pallets(&name, pallets.iter());
|
||||
let pallet_to_index = decl_pallet_runtime_setup(&pallets, &scrate);
|
||||
|
||||
let dispatch = decl_outer_dispatch(&name, pallets.iter(), &scrate);
|
||||
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 = decl_outer_inherent(
|
||||
let inherent = expand::expand_outer_inherent(
|
||||
&name,
|
||||
&block,
|
||||
&unchecked_extrinsic,
|
||||
pallets.iter(),
|
||||
&pallets,
|
||||
&scrate,
|
||||
);
|
||||
let validate_unsigned = decl_validate_unsigned(&name, pallets.iter(), &scrate);
|
||||
let validate_unsigned = expand::expand_outer_validate_unsigned(&name, &pallets, &scrate);
|
||||
let integrity_test = decl_integrity_test(&scrate);
|
||||
|
||||
let res = quote!(
|
||||
@@ -200,73 +200,6 @@ fn construct_runtime_parsed(definition: RuntimeDefinition) -> Result<TokenStream
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
fn decl_validate_unsigned<'a>(
|
||||
runtime: &'a Ident,
|
||||
pallet_declarations: impl Iterator<Item = &'a Pallet>,
|
||||
scrate: &'a TokenStream2,
|
||||
) -> TokenStream2 {
|
||||
let pallets_tokens = pallet_declarations
|
||||
.filter(|pallet_declaration| pallet_declaration.exists_part("ValidateUnsigned"))
|
||||
.map(|pallet_declaration| &pallet_declaration.name);
|
||||
quote!(
|
||||
#scrate::impl_outer_validate_unsigned!(
|
||||
impl ValidateUnsigned for #runtime {
|
||||
#( #pallets_tokens )*
|
||||
}
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
fn decl_outer_inherent<'a>(
|
||||
runtime: &'a Ident,
|
||||
block: &'a syn::TypePath,
|
||||
unchecked_extrinsic: &'a syn::TypePath,
|
||||
pallet_declarations: impl Iterator<Item = &'a Pallet>,
|
||||
scrate: &'a TokenStream2,
|
||||
) -> TokenStream2 {
|
||||
let pallets_tokens = pallet_declarations.filter_map(|pallet_declaration| {
|
||||
let maybe_config_part = pallet_declaration.find_part("Inherent");
|
||||
maybe_config_part.map(|_| {
|
||||
let name = &pallet_declaration.name;
|
||||
quote!(#name,)
|
||||
})
|
||||
});
|
||||
quote!(
|
||||
#scrate::impl_outer_inherent!(
|
||||
impl Inherents where
|
||||
Block = #block,
|
||||
UncheckedExtrinsic = #unchecked_extrinsic,
|
||||
Runtime = #runtime,
|
||||
{
|
||||
#(#pallets_tokens)*
|
||||
}
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
fn decl_outer_dispatch<'a>(
|
||||
runtime: &'a Ident,
|
||||
pallet_declarations: impl Iterator<Item = &'a Pallet>,
|
||||
scrate: &'a TokenStream2,
|
||||
) -> TokenStream2 {
|
||||
let pallets_tokens = pallet_declarations
|
||||
.filter(|pallet_declaration| pallet_declaration.exists_part("Call"))
|
||||
.map(|pallet_declaration| {
|
||||
let pallet = &pallet_declaration.path.inner.segments.last().unwrap();
|
||||
let name = &pallet_declaration.name;
|
||||
let index = pallet_declaration.index;
|
||||
quote!(#[codec(index = #index)] #pallet::#name)
|
||||
});
|
||||
|
||||
quote!(
|
||||
#scrate::impl_outer_dispatch! {
|
||||
pub enum Call for #runtime where origin: Origin {
|
||||
#(#pallets_tokens,)*
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fn decl_all_pallets<'a>(
|
||||
runtime: &'a Ident,
|
||||
pallet_declarations: impl Iterator<Item = &'a Pallet>,
|
||||
|
||||
Reference in New Issue
Block a user