Allow pallet::call to return DispatchResult (#8241)

* allow dispatch result

* remove custom error message

* format

* add forgotten UI test

* fix test

* fix tests
This commit is contained in:
Guillaume Thiolliere
2021-03-03 13:14:07 +01:00
committed by GitHub
parent 4de4662480
commit fb8da7ea92
6 changed files with 71 additions and 6 deletions
@@ -27,6 +27,8 @@ mod keyword {
syn::custom_keyword!(T);
syn::custom_keyword!(Pallet);
syn::custom_keyword!(origin);
syn::custom_keyword!(DispatchResult);
syn::custom_keyword!(DispatchResultWithPostInfo);
}
/// A usage of instance, either the trait `Config` has been used with instance or without instance.
@@ -596,3 +598,26 @@ pub fn check_type_value_gen(
Ok(i)
}
/// Check the keyword `DispatchResultWithPostInfo` or `DispatchResult`.
pub fn check_pallet_call_return_type(
type_: &syn::Type,
) -> syn::Result<()> {
pub struct Checker;
impl syn::parse::Parse for Checker {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
let lookahead = input.lookahead1();
if lookahead.peek(keyword::DispatchResultWithPostInfo) {
input.parse::<keyword::DispatchResultWithPostInfo>()?;
Ok(Self)
} else if lookahead.peek(keyword::DispatchResult) {
input.parse::<keyword::DispatchResult>()?;
Ok(Self)
} else {
Err(lookahead.error())
}
}
}
syn::parse2::<Checker>(type_.to_token_stream()).map(|_| ())
}