mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 14:37:57 +00:00
Introduce Polkadot-Sdk developer_hub (#2102)
This PR introduces the new crate `developer_hub` into the polkadot-sdk repo. The vision for the developer-hub crate is detailed in [this document](https://docs.google.com/document/d/1XLLkFNE8v8HLvZpI2rzsa8N2IN1FcKntc8q-Sc4xBAk/edit?usp=sharing). <img width="1128" alt="Screenshot 2023-11-02 at 10 45 48" src="https://github.com/paritytech/polkadot-sdk/assets/5588131/1e12b60f-fef5-42c4-8503-a3ba234077c3"> Other than adding the new crate, it also does the following: * Remove the `substrate` crate, as there is now a unique umbrella crate for multiple things in `developer_hub::polkadot_sdk`. * (backport candidate) A minor change to `frame-support` macros that allows `T::RuntimeOrigin` to also be acceptable as the origin type. * (backport candidate) A minor change to `frame-system` that allows us to deposit events at genesis because now the real genesis config is generated via wasm, and we can safely assume `cfg!(feature = "std")` means only testing. related to #62. * (backport candidate) Introduces a small `read_events_for_pallet` to `frame_system` for easier event reading in tests. * From https://github.com/paritytech/polkadot-sdk-docs/issues/31, it takes action on improving the `pallet::call` docs. * From https://github.com/paritytech/polkadot-sdk-docs/issues/31, it takes action on improving the `UncheckedExtrinsic` docs. ## Way Forward First, a version of this is deployed temporarily [here](https://blog.kianenigma.nl/polkadot-sdk/developer_hub/index.html). I will keep it up to date on a daily basis. ### This Pull Request I see two ways forward: 1. We acknowledge that everything in `developer-hub` is going to be WIP, and merge this asap. We should not yet use links to this crate anywhere. 2. We make this be the feature branch, make PRs against this, and either gradually backport it, or only merge to master once it is done. I am personally in favor of option 1. If we stick to option 2, we need a better way to deploy a staging version of this to gh-pages. ### Issue Tracking The main issues related to the future of `developer_hub` are: - https://github.com/paritytech/polkadot-sdk-docs/issues/31 - https://github.com/paritytech/polkadot-sdk-docs/issues/4 - https://github.com/paritytech/polkadot-sdk-docs/issues/26 - https://github.com/paritytech/polkadot-sdk-docs/issues/32 - https://github.com/paritytech/polkadot-sdk-docs/issues/36 ### After This Pull Request - [ ] create a redirect for https://paritytech.github.io/polkadot-sdk/master/substrate/ - [x] analytics - [ ] link checker - [ ] the matter of publishing, and how all of these relative links for when we do, that is still an open question. There is section on this in the landing page. - [ ] updated https://paritytech.github.io/ --------- Co-authored-by: Liam Aharon <liam.aharon@hotmail.com> Co-authored-by: Juan Girini <juangirini@gmail.com> Co-authored-by: bader y <ibnbassem@gmail.com> Co-authored-by: Sebastian Kunert <skunert49@gmail.com> Co-authored-by: James Wilson <james@jsdw.me> Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
This commit is contained in:
@@ -47,6 +47,8 @@ pub mod __private {
|
||||
pub use sp_core::{OpaqueMetadata, Void};
|
||||
pub use sp_core_hashing_proc_macro;
|
||||
pub use sp_inherents;
|
||||
#[cfg(feature = "std")]
|
||||
pub use sp_io::TestExternalities;
|
||||
pub use sp_io::{self, hashing, storage::root as storage_root};
|
||||
pub use sp_metadata_ir as metadata_ir;
|
||||
#[cfg(feature = "std")]
|
||||
@@ -2226,13 +2228,159 @@ pub use frame_support_procedural::pallet;
|
||||
/// Contains macro stubs for all of the pallet:: macros
|
||||
pub mod pallet_macros {
|
||||
pub use frame_support_procedural::{
|
||||
call_index, compact, composite_enum, config, disable_frame_system_supertrait_check, error,
|
||||
event, extra_constants, feeless_if, generate_deposit, generate_store, getter, hooks,
|
||||
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,
|
||||
};
|
||||
|
||||
/// Allows a pallet to declare a set of functions as a *dispatchable extrinsic*. In
|
||||
/// slightly simplified terms, this macro declares the set of "transactions" of a pallet.
|
||||
///
|
||||
/// > The exact definition of **extrinsic** can be found in
|
||||
/// > [`sp_runtime::generic::UncheckedExtrinsic`].
|
||||
///
|
||||
/// A **dispatchable** is a common term in FRAME, referring to process of constructing a
|
||||
/// function, and dispatching it with the correct inputs. This is commonly used with
|
||||
/// extrinsics, for example "an extrinsic has been dispatched". See
|
||||
/// [`sp_runtime::traits::Dispatchable`] and [`crate::traits::UnfilteredDispatchable`].
|
||||
///
|
||||
/// ## Call Enum
|
||||
///
|
||||
/// The macro is called `call` (rather than `#[pallet::extrinsics]`) because of the
|
||||
/// generation of a `enum Call`. This enum contains only the encoding of the function
|
||||
/// arguments of the dispatchable, alongside the information needed to route it to the
|
||||
/// correct function.
|
||||
///
|
||||
/// ```
|
||||
/// #[frame_support::pallet(dev_mode)]
|
||||
/// pub mod custom_pallet {
|
||||
/// # use frame_support::pallet_prelude::*;
|
||||
/// # use frame_system::pallet_prelude::*;
|
||||
/// # #[pallet::config]
|
||||
/// # pub trait Config: frame_system::Config {}
|
||||
/// # #[pallet::pallet]
|
||||
/// # pub struct Pallet<T>(_);
|
||||
/// # use frame_support::traits::BuildGenesisConfig;
|
||||
/// #[pallet::call]
|
||||
/// impl<T: Config> Pallet<T> {
|
||||
/// pub fn some_dispatchable(_origin: OriginFor<T>, _input: u32) -> DispatchResult {
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// pub fn other(_origin: OriginFor<T>, _input: u64) -> DispatchResult {
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// // generates something like:
|
||||
/// // enum Call<T: Config> {
|
||||
/// // some_dispatchable { input: u32 }
|
||||
/// // other { input: u64 }
|
||||
/// // }
|
||||
/// }
|
||||
///
|
||||
/// fn main() {
|
||||
/// # use frame_support::{derive_impl, construct_runtime};
|
||||
/// # use frame_support::__private::codec::Encode;
|
||||
/// # use frame_support::__private::TestExternalities;
|
||||
/// # use frame_support::traits::UnfilteredDispatchable;
|
||||
/// # impl custom_pallet::Config for Runtime {}
|
||||
/// # #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
|
||||
/// # impl frame_system::Config for Runtime {
|
||||
/// # type Block = frame_system::mocking::MockBlock<Self>;
|
||||
/// # }
|
||||
/// construct_runtime! {
|
||||
/// pub struct Runtime {
|
||||
/// System: frame_system,
|
||||
/// Custom: custom_pallet
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// # TestExternalities::new_empty().execute_with(|| {
|
||||
/// let origin: RuntimeOrigin = frame_system::RawOrigin::Signed(10).into();
|
||||
/// // calling into a dispatchable from within the runtime is simply a function call.
|
||||
/// let _ = custom_pallet::Pallet::<Runtime>::some_dispatchable(origin.clone(), 10);
|
||||
///
|
||||
/// // calling into a dispatchable from the outer world involves constructing the bytes of
|
||||
/// let call = custom_pallet::Call::<Runtime>::some_dispatchable { input: 10 };
|
||||
/// let _ = call.clone().dispatch_bypass_filter(origin);
|
||||
///
|
||||
/// // the routing of a dispatchable is simply done through encoding of the `Call` enum,
|
||||
/// // which is the index of the variant, followed by the arguments.
|
||||
/// assert_eq!(call.encode(), vec![0u8, 10, 0, 0, 0]);
|
||||
///
|
||||
/// // notice how in the encoding of the second function, the first byte is different and
|
||||
/// // referring to the second variant of `enum Call`.
|
||||
/// let call = custom_pallet::Call::<Runtime>::other { input: 10 };
|
||||
/// assert_eq!(call.encode(), vec![1u8, 10, 0, 0, 0, 0, 0, 0, 0]);
|
||||
/// # });
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Further properties of dispatchable functions are as follows:
|
||||
///
|
||||
/// - Unless if annotated by `dev_mode`, it must contain [`weight`] to denote the
|
||||
/// pre-dispatch weight consumed.
|
||||
/// - The dispatchable must declare its index via [`call_index`], which can override the
|
||||
/// position of a function in `enum Call`.
|
||||
/// - The first argument is always an `OriginFor` (or `T::RuntimeOrigin`).
|
||||
/// - The return type is always [`crate::dispatch::DispatchResult`] (or
|
||||
/// [`crate::dispatch::DispatchResultWithPostInfo`]).
|
||||
///
|
||||
/// **WARNING**: modifying dispatchables, changing their order (i.e. using [`call_index`]),
|
||||
/// removing some, etc., must be done with care. This will change the encoding of the , and
|
||||
/// the call can be stored on-chain (e.g. in `pallet-scheduler`). Thus, migration might be
|
||||
/// needed. This is why the use of `call_index` is mandatory by default in FRAME.
|
||||
///
|
||||
/// ## Default Behavior
|
||||
///
|
||||
/// If no `#[pallet::call]` exists, then a default implementation corresponding to the
|
||||
/// following code is automatically generated:
|
||||
///
|
||||
/// ```ignore
|
||||
/// #[pallet::call]
|
||||
/// impl<T: Config> Pallet<T> {}
|
||||
/// ```
|
||||
pub use frame_support_procedural::call;
|
||||
|
||||
/// Enforce the index of a variant in the generated `enum Call`. See [`call`] for more
|
||||
/// information.
|
||||
///
|
||||
/// All call indexes start from 0, until it encounters a dispatchable function with a
|
||||
/// defined call index. The dispatchable function that lexically follows the function with
|
||||
/// a defined call index will have that call index, but incremented by 1, e.g. if there are
|
||||
/// 3 dispatchable functions `fn foo`, `fn bar` and `fn qux` in that order, and only `fn
|
||||
/// bar` has a call index of 10, then `fn qux` will have an index of 11, instead of 1.
|
||||
pub use frame_support_procedural::call_index;
|
||||
|
||||
/// Declares the arguments of a [`call`] function to be encoded using
|
||||
/// [`codec::Compact`]. This will results in smaller extrinsic encoding.
|
||||
///
|
||||
/// A common example of `compact` is for numeric values that are often times far far away
|
||||
/// from their theoretical maximum. For example, in the context of a crypto-currency, the
|
||||
/// balance of an individual account is oftentimes way less than what the numeric type
|
||||
/// allows. In all such cases, using `compact` is sensible.
|
||||
///
|
||||
/// ```
|
||||
/// #[frame_support::pallet(dev_mode)]
|
||||
/// pub mod custom_pallet {
|
||||
/// # use frame_support::pallet_prelude::*;
|
||||
/// # use frame_system::pallet_prelude::*;
|
||||
/// # #[pallet::config]
|
||||
/// # pub trait Config: frame_system::Config {}
|
||||
/// # #[pallet::pallet]
|
||||
/// # pub struct Pallet<T>(_);
|
||||
/// # use frame_support::traits::BuildGenesisConfig;
|
||||
/// #[pallet::call]
|
||||
/// impl<T: Config> Pallet<T> {
|
||||
/// pub fn some_dispatchable(_origin: OriginFor<T>, #[pallet::compact] _input: u32) -> DispatchResult {
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
pub use frame_support_procedural::compact;
|
||||
|
||||
/// Allows you to define the genesis configuration for the pallet.
|
||||
///
|
||||
/// Item is defined as either an enum or a struct. It needs to be public and implement the
|
||||
|
||||
Reference in New Issue
Block a user