Better error for when origin filter prevent the call to be dispatched (#10134)

* better error

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* remove unused

* fix error

* fmt

* fix tests

* fmt

* Update frame/contracts/src/exec.rs

Co-authored-by: Alexander Theißen <alex.theissen@me.com>

* fix typo

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
This commit is contained in:
Guillaume Thiolliere
2021-11-02 15:20:00 +01:00
committed by GitHub
parent 977cf450b3
commit 20c9afcdc1
9 changed files with 67 additions and 37 deletions
@@ -22,6 +22,7 @@ use syn::Ident;
pub fn expand_outer_dispatch(
runtime: &Ident,
system_pallet: &Pallet,
pallet_decls: &[Pallet],
scrate: &TokenStream,
) -> TokenStream {
@@ -29,6 +30,7 @@ pub fn expand_outer_dispatch(
let mut variant_patterns = Vec::new();
let mut query_call_part_macros = Vec::new();
let mut pallet_names = Vec::new();
let system_path = &system_pallet.path;
let pallets_with_call = pallet_decls.iter().filter(|decl| decl.exists_part("Call"));
@@ -106,7 +108,9 @@ pub fn expand_outer_dispatch(
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());
return #scrate::sp_std::result::Result::Err(
#system_path::Error::<#runtime>::CallFiltered.into()
);
}
#scrate::traits::UnfilteredDispatchable::dispatch_bypass_filter(self, origin)
@@ -18,23 +18,14 @@
use crate::construct_runtime::{Pallet, SYSTEM_PALLET_NAME};
use proc_macro2::TokenStream;
use quote::quote;
use syn::{token, Generics, Ident};
use syn::{Generics, Ident};
pub fn expand_outer_origin(
runtime: &Ident,
system_pallet: &Pallet,
pallets: &[Pallet],
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. \
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();
let mut query_origin_part_macros = Vec::new();