mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 09:51:10 +00:00
BREAKING: Rename Call & Event (#11981)
* rename Event to RuntimeEvent * rename Call * rename in runtimes * small fix * rename Event * small fix & rename RuntimeCall back to Call for now * small fixes * more renaming * a bit more renaming * fmt * small fix * commit * prep for renaming associated types * fix * rename associated Event type * rename to RuntimeEvent * commit * merge conflict fixes & fmt * additional renaming * fix. * fix decl_event * rename in tests * remove warnings * remove accidental rename * . * commit * update .stderr * fix in test * update .stderr * TRYBUILD=overwrite * docs * fmt * small change in docs * rename PalletEvent to Event * rename Call to RuntimeCall * renamed at wrong places :P * rename Call * rename * rename associated type * fix * fix & fmt * commit * frame-support-test * passing tests * update docs * rustdoc fix * update .stderr * wrong code in docs * merge fix * fix in error message * update .stderr * docs & error message * . * merge fix * merge fix * fmt * fmt * merge fix * more fixing * fmt * remove unused * fmt * fix Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -55,7 +55,7 @@ pub fn expand_outer_dispatch(
|
||||
#[codec(index = #index)]
|
||||
#name( #scrate::dispatch::CallableCallFor<#name, #runtime> ),
|
||||
});
|
||||
variant_patterns.push(quote!(Call::#name(call)));
|
||||
variant_patterns.push(quote!(RuntimeCall::#name(call)));
|
||||
pallet_names.push(name);
|
||||
pallet_attrs.push(attr);
|
||||
query_call_part_macros.push(quote! {
|
||||
@@ -73,11 +73,11 @@ pub fn expand_outer_dispatch(
|
||||
#scrate::scale_info::TypeInfo,
|
||||
#scrate::RuntimeDebug,
|
||||
)]
|
||||
pub enum Call {
|
||||
pub enum RuntimeCall {
|
||||
#variant_defs
|
||||
}
|
||||
#[cfg(test)]
|
||||
impl Call {
|
||||
impl RuntimeCall {
|
||||
/// Return a list of the module names together with their size in memory.
|
||||
pub const fn sizes() -> &'static [( &'static str, usize )] {
|
||||
use #scrate::dispatch::Callable;
|
||||
@@ -86,7 +86,7 @@ pub fn expand_outer_dispatch(
|
||||
#pallet_attrs
|
||||
(
|
||||
stringify!(#pallet_names),
|
||||
size_of::< <#pallet_names as Callable<#runtime>>::Call >(),
|
||||
size_of::< <#pallet_names as Callable<#runtime>>::RuntimeCall >(),
|
||||
),
|
||||
)*]
|
||||
}
|
||||
@@ -113,7 +113,7 @@ pub fn expand_outer_dispatch(
|
||||
}
|
||||
}
|
||||
}
|
||||
impl #scrate::dispatch::GetDispatchInfo for Call {
|
||||
impl #scrate::dispatch::GetDispatchInfo for RuntimeCall {
|
||||
fn get_dispatch_info(&self) -> #scrate::dispatch::DispatchInfo {
|
||||
match self {
|
||||
#(
|
||||
@@ -123,7 +123,7 @@ pub fn expand_outer_dispatch(
|
||||
}
|
||||
}
|
||||
}
|
||||
impl #scrate::dispatch::GetCallMetadata for Call {
|
||||
impl #scrate::dispatch::GetCallMetadata for RuntimeCall {
|
||||
fn get_call_metadata(&self) -> #scrate::dispatch::CallMetadata {
|
||||
use #scrate::dispatch::GetCallName;
|
||||
match self {
|
||||
@@ -151,16 +151,16 @@ pub fn expand_outer_dispatch(
|
||||
#(
|
||||
#pallet_attrs
|
||||
stringify!(#pallet_names) =>
|
||||
<<#pallet_names as Callable<#runtime>>::Call
|
||||
<<#pallet_names as Callable<#runtime>>::RuntimeCall
|
||||
as GetCallName>::get_call_names(),
|
||||
)*
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl #scrate::dispatch::Dispatchable for Call {
|
||||
impl #scrate::dispatch::Dispatchable for RuntimeCall {
|
||||
type Origin = Origin;
|
||||
type Config = Call;
|
||||
type Config = RuntimeCall;
|
||||
type Info = #scrate::weights::DispatchInfo;
|
||||
type PostInfo = #scrate::weights::PostDispatchInfo;
|
||||
fn dispatch(self, origin: Origin) -> #scrate::dispatch::DispatchResultWithPostInfo {
|
||||
@@ -173,7 +173,7 @@ pub fn expand_outer_dispatch(
|
||||
#scrate::traits::UnfilteredDispatchable::dispatch_bypass_filter(self, origin)
|
||||
}
|
||||
}
|
||||
impl #scrate::traits::UnfilteredDispatchable for Call {
|
||||
impl #scrate::traits::UnfilteredDispatchable for RuntimeCall {
|
||||
type Origin = Origin;
|
||||
fn dispatch_bypass_filter(self, origin: Origin) -> #scrate::dispatch::DispatchResultWithPostInfo {
|
||||
match self {
|
||||
@@ -188,7 +188,7 @@ pub fn expand_outer_dispatch(
|
||||
|
||||
#(
|
||||
#pallet_attrs
|
||||
impl #scrate::traits::IsSubType<#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> for Call {
|
||||
impl #scrate::traits::IsSubType<#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> for RuntimeCall {
|
||||
#[allow(unreachable_patterns)]
|
||||
fn is_sub_type(&self) -> Option<&#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> {
|
||||
match self {
|
||||
@@ -200,7 +200,7 @@ pub fn expand_outer_dispatch(
|
||||
}
|
||||
|
||||
#pallet_attrs
|
||||
impl From<#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> for Call {
|
||||
impl From<#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> for RuntimeCall {
|
||||
fn from(call: #scrate::dispatch::CallableCallFor<#pallet_names, #runtime>) -> Self {
|
||||
#variant_patterns
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ pub fn expand_outer_event(
|
||||
#scrate::RuntimeDebug,
|
||||
)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum Event {
|
||||
pub enum RuntimeEvent {
|
||||
#event_variants
|
||||
}
|
||||
|
||||
@@ -148,13 +148,13 @@ fn expand_event_conversion(
|
||||
|
||||
quote! {
|
||||
#attr
|
||||
impl From<#pallet_event> for Event {
|
||||
impl From<#pallet_event> for RuntimeEvent {
|
||||
fn from(x: #pallet_event) -> Self {
|
||||
Event::#variant_name(x)
|
||||
RuntimeEvent::#variant_name(x)
|
||||
}
|
||||
}
|
||||
#attr
|
||||
impl TryInto<#pallet_event> for Event {
|
||||
impl TryInto<#pallet_event> for RuntimeEvent {
|
||||
type Error = ();
|
||||
|
||||
fn try_into(self) -> #scrate::sp_std::result::Result<#pallet_event, Self::Error> {
|
||||
|
||||
@@ -105,7 +105,7 @@ pub fn expand_outer_origin(
|
||||
#[derive(Clone)]
|
||||
pub struct Origin {
|
||||
caller: OriginCaller,
|
||||
filter: #scrate::sp_std::rc::Rc<Box<dyn Fn(&<#runtime as #system_path::Config>::Call) -> bool>>,
|
||||
filter: #scrate::sp_std::rc::Rc<Box<dyn Fn(&<#runtime as #system_path::Config>::RuntimeCall) -> bool>>,
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
@@ -132,7 +132,7 @@ pub fn expand_outer_origin(
|
||||
}
|
||||
|
||||
impl #scrate::traits::OriginTrait for Origin {
|
||||
type Call = <#runtime as #system_path::Config>::Call;
|
||||
type Call = <#runtime as #system_path::Config>::RuntimeCall;
|
||||
type PalletsOrigin = OriginCaller;
|
||||
type AccountId = <#runtime as #system_path::Config>::AccountId;
|
||||
|
||||
@@ -147,7 +147,7 @@ pub fn expand_outer_origin(
|
||||
fn reset_filter(&mut self) {
|
||||
let filter = <
|
||||
<#runtime as #system_path::Config>::BaseCallFilter
|
||||
as #scrate::traits::Contains<<#runtime as #system_path::Config>::Call>
|
||||
as #scrate::traits::Contains<<#runtime as #system_path::Config>::RuntimeCall>
|
||||
>::contains;
|
||||
|
||||
self.filter = #scrate::sp_std::rc::Rc::new(Box::new(filter));
|
||||
|
||||
@@ -55,14 +55,14 @@ pub fn expand_outer_validate_unsigned(
|
||||
#( #query_validate_unsigned_part_macros )*
|
||||
|
||||
impl #scrate::unsigned::ValidateUnsigned for #runtime {
|
||||
type Call = Call;
|
||||
type Call = RuntimeCall;
|
||||
|
||||
fn pre_dispatch(call: &Self::Call) -> Result<(), #scrate::unsigned::TransactionValidityError> {
|
||||
#[allow(unreachable_patterns)]
|
||||
match call {
|
||||
#(
|
||||
#pallet_attrs
|
||||
Call::#pallet_names(inner_call) => #pallet_names::pre_dispatch(inner_call),
|
||||
RuntimeCall::#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.
|
||||
@@ -79,7 +79,7 @@ pub fn expand_outer_validate_unsigned(
|
||||
match call {
|
||||
#(
|
||||
#pallet_attrs
|
||||
Call::#pallet_names(inner_call) => #pallet_names::validate_unsigned(source, inner_call),
|
||||
RuntimeCall::#pallet_names(inner_call) => #pallet_names::validate_unsigned(source, inner_call),
|
||||
)*
|
||||
_ => #scrate::unsigned::UnknownTransaction::NoUnsignedValidator.into(),
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ pub fn decl_storage(input: TokenStream) -> TokenStream {
|
||||
/// System: frame_system::{Pallet, Call, Event<T>, Config<T>} = 0,
|
||||
/// Test: path::to::test::{Pallet, Call} = 1,
|
||||
///
|
||||
/// // Pallets with instances
|
||||
/// // Pallets with instances.
|
||||
/// Test2_Instance1: test2::<Instance1>::{Pallet, Call, Storage, Event<T, I>, Config<T, I>, Origin<T, I>},
|
||||
/// Test2_DefaultInstance: test2::{Pallet, Call, Storage, Event<T>, Config<T>, Origin<T>} = 4,
|
||||
///
|
||||
|
||||
@@ -300,7 +300,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
impl<#type_impl_gen> #frame_support::dispatch::Callable<T> for #pallet_ident<#type_use_gen>
|
||||
#where_clause
|
||||
{
|
||||
type Call = #call_ident<#type_use_gen>;
|
||||
type RuntimeCall = #call_ident<#type_use_gen>;
|
||||
}
|
||||
|
||||
impl<#type_impl_gen> #pallet_ident<#type_use_gen> #where_clause {
|
||||
|
||||
@@ -61,7 +61,8 @@ pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
let event_where_clause = &event.where_clause;
|
||||
|
||||
// NOTE: actually event where clause must be a subset of config where clause because of
|
||||
// `type Event: From<Event<Self>>`. But we merge either way for potential better error message
|
||||
// `type RuntimeEvent: From<Event<Self>>`. But we merge either way for potential better error
|
||||
// message
|
||||
let completed_where_clause =
|
||||
super::merge_where_clauses(&[&event.where_clause, &def.config.where_clause]);
|
||||
|
||||
@@ -136,13 +137,13 @@ pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
impl<#type_impl_gen> Pallet<#type_use_gen> #completed_where_clause {
|
||||
#fn_vis fn deposit_event(event: Event<#event_use_gen>) {
|
||||
let event = <
|
||||
<T as Config #trait_use_gen>::Event as
|
||||
<T as Config #trait_use_gen>::RuntimeEvent as
|
||||
From<Event<#event_use_gen>>
|
||||
>::from(event);
|
||||
|
||||
let event = <
|
||||
<T as Config #trait_use_gen>::Event as
|
||||
Into<<T as #frame_system::Config>::Event>
|
||||
<T as Config #trait_use_gen>::RuntimeEvent as
|
||||
Into<<T as #frame_system::Config>::RuntimeEvent>
|
||||
>::into(event);
|
||||
|
||||
<#frame_system::Pallet<T>>::deposit_event(event)
|
||||
|
||||
@@ -28,6 +28,7 @@ mod keyword {
|
||||
syn::custom_keyword!(I);
|
||||
syn::custom_keyword!(config);
|
||||
syn::custom_keyword!(IsType);
|
||||
syn::custom_keyword!(RuntimeEvent);
|
||||
syn::custom_keyword!(Event);
|
||||
syn::custom_keyword!(constant);
|
||||
syn::custom_keyword!(frame_system);
|
||||
@@ -42,8 +43,9 @@ pub struct ConfigDef {
|
||||
pub has_instance: bool,
|
||||
/// Const associated type.
|
||||
pub consts_metadata: Vec<ConstMetadataDef>,
|
||||
/// Whether the trait has the associated type `Event`, note that those bounds are checked:
|
||||
/// * `IsType<Self as frame_system::Config>::Event`
|
||||
/// Whether the trait has the associated type `Event`, note that those bounds are
|
||||
/// checked:
|
||||
/// * `IsType<Self as frame_system::Config>::RuntimeEvent`
|
||||
/// * `From<Event>` or `From<Event<T>>` or `From<Event<T, I>>`
|
||||
pub has_event_type: bool,
|
||||
/// The where clause on trait definition but modified so `Self` is `T`.
|
||||
@@ -159,7 +161,7 @@ impl syn::parse::Parse for ConfigBoundParse {
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse for `IsType<<Sef as $ident::Config>::Event>` and retrieve `$ident`
|
||||
/// Parse for `IsType<<Sef as $ident::Config>::RuntimeEvent>` and retrieve `$ident`
|
||||
pub struct IsTypeBoundEventParse(syn::Ident);
|
||||
|
||||
impl syn::parse::Parse for IsTypeBoundEventParse {
|
||||
@@ -174,7 +176,7 @@ impl syn::parse::Parse for IsTypeBoundEventParse {
|
||||
input.parse::<keyword::Config>()?;
|
||||
input.parse::<syn::Token![>]>()?;
|
||||
input.parse::<syn::Token![::]>()?;
|
||||
input.parse::<keyword::Event>()?;
|
||||
input.parse::<keyword::RuntimeEvent>()?;
|
||||
input.parse::<syn::Token![>]>()?;
|
||||
|
||||
Ok(Self(ident))
|
||||
@@ -212,7 +214,7 @@ impl syn::parse::Parse for FromEventParse {
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if trait_item is `type Event`, if so checks its bounds are those expected.
|
||||
/// Check if trait_item is `type RuntimeEvent`, if so checks its bounds are those expected.
|
||||
/// (Event type is reserved type)
|
||||
fn check_event_type(
|
||||
frame_system: &syn::Ident,
|
||||
@@ -220,10 +222,10 @@ fn check_event_type(
|
||||
trait_has_instance: bool,
|
||||
) -> syn::Result<bool> {
|
||||
if let syn::TraitItem::Type(type_) = trait_item {
|
||||
if type_.ident == "Event" {
|
||||
if type_.ident == "RuntimeEvent" {
|
||||
// Check event has no generics
|
||||
if !type_.generics.params.is_empty() || type_.generics.where_clause.is_some() {
|
||||
let msg = "Invalid `type Event`, associated type `Event` is reserved and must have\
|
||||
let msg = "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must have\
|
||||
no generics nor where_clause";
|
||||
return Err(syn::Error::new(trait_item.span(), msg))
|
||||
}
|
||||
@@ -236,8 +238,8 @@ fn check_event_type(
|
||||
|
||||
if !has_is_type_bound {
|
||||
let msg = format!(
|
||||
"Invalid `type Event`, associated type `Event` is reserved and must \
|
||||
bound: `IsType<<Self as {}::Config>::Event>`",
|
||||
"Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must \
|
||||
bound: `IsType<<Self as {}::Config>::RuntimeEvent>`",
|
||||
frame_system,
|
||||
);
|
||||
return Err(syn::Error::new(type_.span(), msg))
|
||||
@@ -251,14 +253,14 @@ fn check_event_type(
|
||||
let from_event_bound = if let Some(b) = from_event_bound {
|
||||
b
|
||||
} else {
|
||||
let msg = "Invalid `type Event`, associated type `Event` is reserved and must \
|
||||
let msg = "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must \
|
||||
bound: `From<Event>` or `From<Event<Self>>` or `From<Event<Self, I>>`";
|
||||
return Err(syn::Error::new(type_.span(), msg))
|
||||
};
|
||||
|
||||
if from_event_bound.is_generic && (from_event_bound.has_instance != trait_has_instance)
|
||||
{
|
||||
let msg = "Invalid `type Event`, associated type `Event` bounds inconsistent \
|
||||
let msg = "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` bounds inconsistent \
|
||||
`From<Event..>`. Config and generic Event must be both with instance or \
|
||||
without instance";
|
||||
return Err(syn::Error::new(type_.span(), msg))
|
||||
|
||||
@@ -105,11 +105,11 @@ impl Def {
|
||||
let m = hooks::HooksDef::try_from(span, index, item)?;
|
||||
hooks = Some(m);
|
||||
},
|
||||
Some(PalletAttr::Call(span)) if call.is_none() =>
|
||||
Some(PalletAttr::RuntimeCall(span)) if call.is_none() =>
|
||||
call = Some(call::CallDef::try_from(span, index, item)?),
|
||||
Some(PalletAttr::Error(span)) if error.is_none() =>
|
||||
error = Some(error::ErrorDef::try_from(span, index, item)?),
|
||||
Some(PalletAttr::Event(span)) if event.is_none() =>
|
||||
Some(PalletAttr::RuntimeEvent(span)) if event.is_none() =>
|
||||
event = Some(event::EventDef::try_from(span, index, item)?),
|
||||
Some(PalletAttr::GenesisConfig(_)) if genesis_config.is_none() => {
|
||||
let g = genesis_config::GenesisConfigDef::try_from(index, item)?;
|
||||
@@ -182,19 +182,19 @@ impl Def {
|
||||
}
|
||||
|
||||
/// Check that usage of trait `Event` is consistent with the definition, i.e. it is declared
|
||||
/// and trait defines type Event, or not declared and no trait associated type.
|
||||
/// and trait defines type RuntimeEvent, or not declared and no trait associated type.
|
||||
fn check_event_usage(&self) -> syn::Result<()> {
|
||||
match (self.config.has_event_type, self.event.is_some()) {
|
||||
(true, false) => {
|
||||
let msg = "Invalid usage of Event, `Config` contains associated type `Event`, \
|
||||
let msg = "Invalid usage of RuntimeEvent, `Config` contains associated type `RuntimeEvent`, \
|
||||
but enum `Event` is not declared (i.e. no use of `#[pallet::event]`). \
|
||||
Note that type `Event` in trait is reserved to work alongside pallet event.";
|
||||
Note that type `RuntimeEvent` in trait is reserved to work alongside pallet event.";
|
||||
Err(syn::Error::new(proc_macro2::Span::call_site(), msg))
|
||||
},
|
||||
(false, true) => {
|
||||
let msg = "Invalid usage of Event, `Config` contains no associated type \
|
||||
`Event`, but enum `Event` is declared (in use of `#[pallet::event]`). \
|
||||
An Event associated type must be declare on trait `Config`.";
|
||||
let msg = "Invalid usage of RuntimeEvent, `Config` contains no associated type \
|
||||
`RuntimeEvent`, but enum `Event` is declared (in use of `#[pallet::event]`). \
|
||||
An RuntimeEvent associated type must be declare on trait `Config`.";
|
||||
Err(syn::Error::new(proc_macro2::Span::call_site(), msg))
|
||||
},
|
||||
_ => Ok(()),
|
||||
@@ -391,9 +391,9 @@ enum PalletAttr {
|
||||
Config(proc_macro2::Span),
|
||||
Pallet(proc_macro2::Span),
|
||||
Hooks(proc_macro2::Span),
|
||||
Call(proc_macro2::Span),
|
||||
RuntimeCall(proc_macro2::Span),
|
||||
Error(proc_macro2::Span),
|
||||
Event(proc_macro2::Span),
|
||||
RuntimeEvent(proc_macro2::Span),
|
||||
Origin(proc_macro2::Span),
|
||||
Inherent(proc_macro2::Span),
|
||||
Storage(proc_macro2::Span),
|
||||
@@ -410,9 +410,9 @@ impl PalletAttr {
|
||||
Self::Config(span) => *span,
|
||||
Self::Pallet(span) => *span,
|
||||
Self::Hooks(span) => *span,
|
||||
Self::Call(span) => *span,
|
||||
Self::RuntimeCall(span) => *span,
|
||||
Self::Error(span) => *span,
|
||||
Self::Event(span) => *span,
|
||||
Self::RuntimeEvent(span) => *span,
|
||||
Self::Origin(span) => *span,
|
||||
Self::Inherent(span) => *span,
|
||||
Self::Storage(span) => *span,
|
||||
@@ -441,11 +441,11 @@ impl syn::parse::Parse for PalletAttr {
|
||||
} else if lookahead.peek(keyword::hooks) {
|
||||
Ok(PalletAttr::Hooks(content.parse::<keyword::hooks>()?.span()))
|
||||
} else if lookahead.peek(keyword::call) {
|
||||
Ok(PalletAttr::Call(content.parse::<keyword::call>()?.span()))
|
||||
Ok(PalletAttr::RuntimeCall(content.parse::<keyword::call>()?.span()))
|
||||
} else if lookahead.peek(keyword::error) {
|
||||
Ok(PalletAttr::Error(content.parse::<keyword::error>()?.span()))
|
||||
} else if lookahead.peek(keyword::event) {
|
||||
Ok(PalletAttr::Event(content.parse::<keyword::event>()?.span()))
|
||||
Ok(PalletAttr::RuntimeEvent(content.parse::<keyword::event>()?.span()))
|
||||
} else if lookahead.peek(keyword::origin) {
|
||||
Ok(PalletAttr::Origin(content.parse::<keyword::origin>()?.span()))
|
||||
} else if lookahead.peek(keyword::inherent) {
|
||||
|
||||
Reference in New Issue
Block a user