mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 05:11:09 +00:00
Add documentation around FRAME Origin (#3362)
Does the following: - Add a reference doc page named `frame_runtime_types`, which explains what types like `RuntimeOrigin`, `RuntimeCall` etc are. - On top of it, it adds a reference doc page called `frame_origin` which explains a few important patterns that we use around origins - And finally brushes up `#[frame::origin]` docs. - Updates the theme, sidebar and favicon to look like: <img width="1728" alt="Screenshot 2024-02-20 at 12 16 00" src="https://github.com/paritytech/polkadot-sdk/assets/5588131/6d60a16b-2081-411b-8869-43b91920cca9"> All of this was inspired by https://substrate.stackexchange.com/questions/10992/how-do-you-find-the-public-key-for-the-medium-spender-track-origin/10993 closes https://github.com/paritytech/polkadot-sdk-docs/issues/45 closes https://github.com/paritytech/polkadot-sdk-docs/issues/43 contributes / overlaps with https://github.com/paritytech/polkadot-sdk/pull/2638 cc @liamaharon deprecation companion: https://github.com/substrate-developer-hub/substrate-docs/pull/2131 pba-content companion: https://github.com/Polkadot-Blockchain-Academy/pba-content/pull/977 --------- Co-authored-by: Radha <86818441+DrW3RK@users.noreply.github.com> Co-authored-by: Sebastian Kunert <skunert49@gmail.com> Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com> Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
This commit is contained in:
@@ -163,6 +163,12 @@ pub mod runtime {
|
||||
ConstU32, ConstU64, ConstU8,
|
||||
};
|
||||
|
||||
/// Primary types used to parameterize `EnsureOrigin` and `EnsureRootWithArg`.
|
||||
pub use frame_system::{
|
||||
EnsureNever, EnsureNone, EnsureRoot, EnsureRootWithSuccess, EnsureSigned,
|
||||
EnsureSignedBy,
|
||||
};
|
||||
|
||||
/// Types to define your runtime version.
|
||||
pub use sp_version::{create_runtime_str, runtime_version, RuntimeVersion};
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ pub fn expand_outer_origin(
|
||||
#[doc = #doc_string]
|
||||
#[derive(Clone)]
|
||||
pub struct RuntimeOrigin {
|
||||
caller: OriginCaller,
|
||||
pub caller: OriginCaller,
|
||||
filter: #scrate::__private::sp_std::rc::Rc<Box<dyn Fn(&<#runtime as #system_path::Config>::RuntimeCall) -> bool>>,
|
||||
}
|
||||
|
||||
|
||||
@@ -1480,22 +1480,11 @@ pub fn validate_unsigned(_: TokenStream, _: TokenStream) -> TokenStream {
|
||||
pallet_macro_stub()
|
||||
}
|
||||
|
||||
/// The `#[pallet::origin]` attribute allows you to define some origin for the pallet.
|
||||
///
|
||||
/// Item must be either a type alias, an enum, or a struct. It needs to be public.
|
||||
/// ---
|
||||
///
|
||||
/// E.g.:
|
||||
///
|
||||
/// ```ignore
|
||||
/// #[pallet::origin]
|
||||
/// pub struct Origin<T>(PhantomData<(T)>);
|
||||
/// ```
|
||||
///
|
||||
/// **WARNING**: modifying origin changes the outer runtime origin. This outer runtime origin
|
||||
/// can be stored on-chain (e.g. in `pallet-scheduler`), thus any change must be done with care
|
||||
/// as it might require some migration.
|
||||
///
|
||||
/// NOTE: for instantiable pallets, the origin must be generic over `T` and `I`.
|
||||
/// **Rust-Analyzer users**: See the documentation of the Rust item in
|
||||
/// `frame_support::pallet_macros::origin`.
|
||||
#[proc_macro_attribute]
|
||||
pub fn origin(_: TokenStream, _: TokenStream) -> TokenStream {
|
||||
pallet_macro_stub()
|
||||
|
||||
@@ -2274,9 +2274,8 @@ pub mod pallet_macros {
|
||||
pub use frame_support_procedural::{
|
||||
composite_enum, config, disable_frame_system_supertrait_check, error, event,
|
||||
extra_constants, feeless_if, generate_deposit, generate_store, getter, hooks,
|
||||
import_section, inherent, no_default, no_default_bounds, origin, pallet_section,
|
||||
storage_prefix, storage_version, type_value, unbounded, validate_unsigned, weight,
|
||||
whitelist_storage,
|
||||
import_section, inherent, no_default, no_default_bounds, pallet_section, storage_prefix,
|
||||
storage_version, type_value, unbounded, validate_unsigned, weight, whitelist_storage,
|
||||
};
|
||||
|
||||
/// Allows a pallet to declare a set of functions as a *dispatchable extrinsic*. In
|
||||
@@ -2718,7 +2717,7 @@ pub mod pallet_macros {
|
||||
/// }
|
||||
/// ```
|
||||
pub use frame_support_procedural::storage;
|
||||
/// This attribute is attached to a function inside an `impl` block annoated with
|
||||
/// This attribute is attached to a function inside an `impl` block annotated with
|
||||
/// [`pallet::tasks_experimental`](`tasks_experimental`) to define the conditions for a
|
||||
/// given work item to be valid.
|
||||
///
|
||||
@@ -2726,21 +2725,21 @@ pub mod pallet_macros {
|
||||
/// should have the same signature as the function it is attached to, except that it should
|
||||
/// return a `bool` instead.
|
||||
pub use frame_support_procedural::task_condition;
|
||||
/// This attribute is attached to a function inside an `impl` block annoated with
|
||||
/// This attribute is attached to a function inside an `impl` block annotated with
|
||||
/// [`pallet::tasks_experimental`](`tasks_experimental`) to define the index of a given
|
||||
/// work item.
|
||||
///
|
||||
/// It takes an integer literal as input, which is then used to define the index. This
|
||||
/// index should be unique for each function in the `impl` block.
|
||||
pub use frame_support_procedural::task_index;
|
||||
/// This attribute is attached to a function inside an `impl` block annoated with
|
||||
/// This attribute is attached to a function inside an `impl` block annotated with
|
||||
/// [`pallet::tasks_experimental`](`tasks_experimental`) to define an iterator over the
|
||||
/// available work items for a task.
|
||||
///
|
||||
/// It takes an iterator as input that yields a tuple with same types as the function
|
||||
/// arguments.
|
||||
pub use frame_support_procedural::task_list;
|
||||
/// This attribute is attached to a function inside an `impl` block annoated with
|
||||
/// This attribute is attached to a function inside an `impl` block annotated with
|
||||
/// [`pallet::tasks_experimental`](`tasks_experimental`) define the weight of a given work
|
||||
/// item.
|
||||
///
|
||||
@@ -2773,6 +2772,61 @@ pub mod pallet_macros {
|
||||
/// Now, this can be executed as follows:
|
||||
#[doc = docify::embed!("src/tests/tasks.rs", tasks_work)]
|
||||
pub use frame_support_procedural::tasks_experimental;
|
||||
|
||||
/// Allows a pallet to declare a type as an origin.
|
||||
///
|
||||
/// If defined as such, this type will be amalgamated at the runtime level into
|
||||
/// `RuntimeOrigin`, very similar to [`call`], [`error`] and [`event`]. See
|
||||
/// [`composite_enum`] for similar cases.
|
||||
///
|
||||
/// Origin is a complex FRAME topics and is further explained in `polkadot_sdk_docs`.
|
||||
///
|
||||
/// ## Syntax Variants
|
||||
///
|
||||
/// ```
|
||||
/// #[frame_support::pallet]
|
||||
/// mod pallet {
|
||||
/// # use frame_support::pallet_prelude::*;
|
||||
/// # #[pallet::config]
|
||||
/// # pub trait Config: frame_system::Config {}
|
||||
/// # #[pallet::pallet]
|
||||
/// # pub struct Pallet<T>(_);
|
||||
/// /// On the spot declaration.
|
||||
/// #[pallet::origin]
|
||||
/// #[derive(PartialEq, Eq, Clone, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)]
|
||||
/// pub enum Origin {
|
||||
/// Foo,
|
||||
/// Bar,
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Or, more commonly used:/
|
||||
///
|
||||
/// ```
|
||||
/// #[frame_support::pallet]
|
||||
/// mod pallet {
|
||||
/// # use frame_support::pallet_prelude::*;
|
||||
/// # #[pallet::config]
|
||||
/// # pub trait Config: frame_system::Config {}
|
||||
/// # #[pallet::pallet]
|
||||
/// # pub struct Pallet<T>(_);
|
||||
/// #[derive(PartialEq, Eq, Clone, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)]
|
||||
/// pub enum RawOrigin {
|
||||
/// Foo,
|
||||
/// Bar,
|
||||
/// }
|
||||
///
|
||||
/// #[pallet::origin]
|
||||
/// pub type Origin = RawOrigin;
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// ## Warning
|
||||
///
|
||||
/// Modifying any pallet's origin type will cause the runtime level origin type to also
|
||||
/// change in encoding. If stored anywhere on-chain, this will require a data migration.
|
||||
pub use frame_support_procedural::origin;
|
||||
}
|
||||
|
||||
#[deprecated(note = "Will be removed after July 2023; Use `sp_runtime::traits` directly instead.")]
|
||||
|
||||
@@ -452,6 +452,7 @@ pub mod pallet {
|
||||
+ Clone
|
||||
+ OriginTrait<Call = Self::RuntimeCall, AccountId = Self::AccountId>;
|
||||
|
||||
#[docify::export(system_runtime_call)]
|
||||
/// The aggregated `RuntimeCall` type.
|
||||
#[pallet::no_default_bounds]
|
||||
type RuntimeCall: Parameter
|
||||
|
||||
Reference in New Issue
Block a user