Restructure dispatch macro related exports (#1162)

* restructure dispatch macro related exports

* moved Dispatchable to lib.rs

* fix .gitignore final newline

* ".git/.scripts/commands/fmt/fmt.sh"

* fix rustdocs

* wip

---------

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: command-bot <>
Co-authored-by: ordian <write@reusable.software>
This commit is contained in:
Juan
2023-08-31 13:08:44 +02:00
committed by GitHub
parent d6af073aa5
commit bdbe982970
84 changed files with 195 additions and 244 deletions
@@ -124,16 +124,16 @@ pub fn expand_outer_dispatch(
}
}
impl #scrate::dispatch::GetCallMetadata for RuntimeCall {
fn get_call_metadata(&self) -> #scrate::dispatch::CallMetadata {
use #scrate::dispatch::GetCallName;
impl #scrate::traits::GetCallMetadata for RuntimeCall {
fn get_call_metadata(&self) -> #scrate::traits::CallMetadata {
use #scrate::traits::GetCallName;
match self {
#(
#pallet_attrs
#variant_patterns => {
let function_name = call.get_call_name();
let pallet_name = stringify!(#pallet_names);
#scrate::dispatch::CallMetadata { function_name, pallet_name }
#scrate::traits::CallMetadata { function_name, pallet_name }
}
)*
}
@@ -147,7 +147,7 @@ pub fn expand_outer_dispatch(
}
fn get_call_names(module: &str) -> &'static [&'static str] {
use #scrate::dispatch::{Callable, GetCallName};
use #scrate::{dispatch::Callable, traits::GetCallName};
match module {
#(
#pallet_attrs
@@ -159,7 +159,7 @@ pub fn expand_outer_dispatch(
}
}
}
impl #scrate::dispatch::Dispatchable for RuntimeCall {
impl #scrate::__private::Dispatchable for RuntimeCall {
type RuntimeOrigin = RuntimeOrigin;
type Config = RuntimeCall;
type Info = #scrate::dispatch::DispatchInfo;
@@ -351,7 +351,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
}
}
impl<#type_impl_gen> #frame_support::dispatch::GetCallName for #call_ident<#type_use_gen>
impl<#type_impl_gen> #frame_support::traits::GetCallName for #call_ident<#type_use_gen>
#where_clause
{
fn get_call_name(&self) -> &'static str {
@@ -366,7 +366,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
}
}
impl<#type_impl_gen> #frame_support::dispatch::GetCallIndex for #call_ident<#type_use_gen>
impl<#type_impl_gen> #frame_support::traits::GetCallIndex for #call_ident<#type_use_gen>
#where_clause
{
fn get_call_index(&self) -> u8 {
+6 -18
View File
@@ -18,30 +18,18 @@
//! Dispatch system. Contains a macro for defining runtime modules and
//! generating values representing lazy module function calls.
pub use crate::traits::{
CallMetadata, GetCallIndex, GetCallMetadata, GetCallName, GetStorageVersion,
UnfilteredDispatchable,
};
pub use codec::{
Codec, Decode, Encode, EncodeAsRef, EncodeLike, HasCompact, Input, MaxEncodedLen, Output,
};
pub use scale_info::TypeInfo;
pub use sp_runtime::{
traits::Dispatchable, transaction_validity::TransactionPriority, DispatchError, RuntimeDebug,
};
pub use sp_std::{
fmt, marker,
prelude::{Clone, Eq, PartialEq, Vec},
result,
};
pub use sp_weights::Weight;
use crate::traits::UnfilteredDispatchable;
use codec::{Codec, Decode, Encode, EncodeLike, MaxEncodedLen};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_runtime::{
generic::{CheckedExtrinsic, UncheckedExtrinsic},
traits::SignedExtension,
DispatchError, RuntimeDebug,
};
use sp_std::fmt;
use sp_weights::Weight;
/// The return type of a `Dispatchable` in frame. When returned explicitly from
/// a dispatchable function it allows overriding the default `PostDispatchInfo`
@@ -26,11 +26,11 @@
//!
//! # FRAME integration
//!
//! The FRAME macros implement [`UnfilteredDispatchable`](crate::traits::UnfilteredDispatchable) for
//! each pallet `Call` enum. Part of this implementation is the call to [`run_in_context`], so that
//! each call to
//! The FRAME macros implement
//! [`UnfilteredDispatchable`](frame_support::traits::UnfilteredDispatchable) for each pallet `Call`
//! enum. Part of this implementation is the call to [`run_in_context`], so that each call to
//! [`UnfilteredDispatchable::dispatch_bypass_filter`](crate::traits::UnfilteredDispatchable::dispatch_bypass_filter)
//! or [`Dispatchable::dispatch`](crate::dispatch::Dispatchable::dispatch) will run in a dispatch
//! or [`Dispatchable::dispatch`](sp_runtime::traits::Dispatchable::dispatch) will run in a dispatch
//! context.
//!
//! # Example
+6 -8
View File
@@ -49,7 +49,7 @@ pub mod __private {
pub use sp_metadata_ir as metadata_ir;
#[cfg(feature = "std")]
pub use sp_runtime::{bounded_btree_map, bounded_vec};
pub use sp_runtime::{RuntimeDebug, StateVersion};
pub use sp_runtime::{traits::Dispatchable, RuntimeDebug, StateVersion};
#[cfg(feature = "std")]
pub use sp_state_machine::BasicExternalities;
pub use sp_std;
@@ -806,10 +806,7 @@ pub mod testing_prelude {
/// Prelude to be used alongside pallet macro, for ease of use.
pub mod pallet_prelude {
pub use crate::{
dispatch::{
DispatchClass, DispatchError, DispatchResult, DispatchResultWithPostInfo, Parameter,
Pays,
},
dispatch::{DispatchClass, DispatchResult, DispatchResultWithPostInfo, Parameter, Pays},
ensure,
inherent::{InherentData, InherentIdentifier, ProvideInherent},
storage,
@@ -855,7 +852,7 @@ pub mod pallet_prelude {
TransactionTag, TransactionValidity, TransactionValidityError, UnknownTransaction,
ValidTransaction,
},
RuntimeDebug, MAX_MODULE_ERROR_ENCODED_SIZE,
DispatchError, RuntimeDebug, MAX_MODULE_ERROR_ENCODED_SIZE,
};
pub use sp_std::marker::PhantomData;
pub use sp_weights::Weight;
@@ -1266,8 +1263,9 @@ pub mod pallet_prelude {
/// Field types in enum variants must also implement [`PalletError`](traits::PalletError),
/// otherwise the pallet will fail to compile. Rust primitive types have already implemented
/// the [`PalletError`](traits::PalletError) trait along with some commonly used stdlib types
/// such as [`Option`] and [`PhantomData`](`frame_support::dispatch::marker::PhantomData`), and
/// hence in most use cases, a manual implementation is not necessary and is discouraged.
/// such as [`Option`] and
/// [`PhantomData`](`frame_support::__private::sp_std::marker::PhantomData`), and hence in most
/// use cases, a manual implementation is not necessary and is discouraged.
///
/// The generic `T` must not bound anything and a `where` clause is not allowed. That said,
/// bounds and/or a where clause should not needed for any use-case.
@@ -21,11 +21,8 @@ use super::{
imbalance::{Imbalance, SignedImbalance},
misc::{Balance, ExistenceRequirement, WithdrawReasons},
};
use crate::{
dispatch::{DispatchError, DispatchResult},
traits::Get,
};
use sp_runtime::traits::MaybeSerializeDeserialize;
use crate::{dispatch::DispatchResult, traits::Get};
use sp_runtime::{traits::MaybeSerializeDeserialize, DispatchError};
mod reservable;
pub use reservable::{NamedReservableCurrency, ReservableCurrency};
@@ -22,9 +22,10 @@ use sp_core::Get;
use super::{super::misc::BalanceStatus, Currency};
use crate::{
dispatch::{DispatchError, DispatchResult},
dispatch::DispatchResult,
traits::{ExistenceRequirement, SignedImbalance, WithdrawReasons},
};
use sp_runtime::DispatchError;
/// A currency where funds can be reserved from the user.
pub trait ReservableCurrency<AccountId>: Currency<AccountId> {
@@ -18,7 +18,6 @@
//! `Inspect` and `Mutate` traits for working with regular balances.
use crate::{
dispatch::DispatchError,
ensure,
traits::{
tokens::{
@@ -36,7 +35,7 @@ use crate::{
},
};
use sp_arithmetic::traits::{CheckedAdd, CheckedSub, One};
use sp_runtime::{traits::Saturating, ArithmeticError, TokenError};
use sp_runtime::{traits::Saturating, ArithmeticError, DispatchError, TokenError};
use sp_std::marker::PhantomData;
use super::{Credit, Debt, HandleImbalanceDrop, Imbalance};
@@ -20,7 +20,6 @@
use sp_std::marker::PhantomData;
use crate::{
dispatch::DispatchError,
ensure,
traits::{
tokens::{
@@ -38,7 +37,7 @@ use crate::{
},
};
use sp_arithmetic::traits::{CheckedAdd, CheckedSub, One};
use sp_runtime::{traits::Saturating, ArithmeticError, TokenError};
use sp_runtime::{traits::Saturating, ArithmeticError, DispatchError, TokenError};
use super::{Credit, Debt, HandleImbalanceDrop, Imbalance};
@@ -27,9 +27,9 @@
//! Implementations of these traits may be converted to implementations of corresponding
//! `nonfungible` traits by using the `nonfungible::ItemOf` type adapter.
use crate::dispatch::{DispatchError, DispatchResult};
use crate::dispatch::DispatchResult;
use codec::{Decode, Encode};
use sp_runtime::TokenError;
use sp_runtime::{DispatchError, TokenError};
use sp_std::prelude::*;
/// Trait for providing an interface to many read-only NFT-like sets of items.
@@ -27,9 +27,9 @@
//! Implementations of these traits may be converted to implementations of corresponding
//! `nonfungible` traits by using the `nonfungible::ItemOf` type adapter.
use crate::dispatch::{DispatchError, DispatchResult, Parameter};
use crate::dispatch::{DispatchResult, Parameter};
use codec::{Decode, Encode};
use sp_runtime::TokenError;
use sp_runtime::{DispatchError, TokenError};
use sp_std::prelude::*;
/// Trait for providing an interface to many read-only NFT-like sets of items.
+2 -2
View File
@@ -18,10 +18,10 @@
//! Traits and associated data structures concerned with voting, and moving between tokens and
//! votes.
use crate::dispatch::{DispatchError, Parameter};
use crate::dispatch::Parameter;
use codec::{HasCompact, MaxEncodedLen};
use sp_arithmetic::Perbill;
use sp_runtime::traits::Member;
use sp_runtime::{traits::Member, DispatchError};
use sp_std::prelude::*;
pub trait VoteTally<Votes, Class> {
@@ -578,14 +578,14 @@ fn call_weight_should_attach_to_call_enum() {
#[test]
fn call_name() {
use frame_support::dispatch::GetCallName;
use frame_support::traits::GetCallName;
let name = module3::Call::<Runtime>::aux_4 {}.get_call_name();
assert_eq!("aux_4", name);
}
#[test]
fn call_metadata() {
use frame_support::dispatch::{CallMetadata, GetCallMetadata};
use frame_support::traits::{CallMetadata, GetCallMetadata};
let call = RuntimeCall::Module3(module3::Call::<Runtime>::aux_4 {});
let metadata = call.get_call_metadata();
let expected = CallMetadata { function_name: "aux_4".into(), pallet_name: "Module3".into() };
@@ -594,14 +594,14 @@ fn call_metadata() {
#[test]
fn get_call_names() {
use frame_support::dispatch::GetCallName;
use frame_support::traits::GetCallName;
let call_names = module3::Call::<Runtime>::get_call_names();
assert_eq!(["fail", "aux_1", "aux_2", "aux_3", "aux_4", "operational"], call_names);
}
#[test]
fn get_module_names() {
use frame_support::dispatch::GetCallMetadata;
use frame_support::traits::GetCallMetadata;
let module_names = RuntimeCall::get_module_names();
assert_eq!(
[
+3 -5
View File
@@ -17,10 +17,7 @@
use frame_support::{
assert_ok,
dispatch::{
DispatchClass, DispatchInfo, Dispatchable, GetDispatchInfo, Parameter, Pays,
UnfilteredDispatchable,
},
dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Parameter, Pays},
dispatch_context::with_context,
pallet_prelude::{StorageInfoTrait, ValueQuery},
parameter_types,
@@ -28,6 +25,7 @@ use frame_support::{
traits::{
ConstU32, GetCallIndex, GetCallName, GetStorageVersion, OnFinalize, OnGenesis,
OnInitialize, OnRuntimeUpgrade, PalletError, PalletInfoAccess, StorageVersion,
UnfilteredDispatchable,
},
weights::{RuntimeDbWeight, Weight},
};
@@ -37,7 +35,7 @@ use sp_io::{
TestExternalities,
};
use sp_runtime::{
traits::{Extrinsic as ExtrinsicT, SignaturePayload as SignaturePayloadT},
traits::{Dispatchable, Extrinsic as ExtrinsicT, SignaturePayload as SignaturePayloadT},
DispatchError, ModuleError,
};
@@ -16,11 +16,14 @@
// limitations under the License.
use frame_support::{
dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays, UnfilteredDispatchable},
dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays},
pallet_prelude::ValueQuery,
parameter_types,
storage::unhashed,
traits::{ConstU32, GetCallName, OnFinalize, OnGenesis, OnInitialize, OnRuntimeUpgrade},
traits::{
ConstU32, GetCallName, OnFinalize, OnGenesis, OnInitialize, OnRuntimeUpgrade,
UnfilteredDispatchable,
},
weights::Weight,
};
use sp_io::{