From d8e623368d40a9d0114f6d851108b9c63d29e7d1 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 22 Mar 2024 10:48:29 +0530 Subject: [PATCH 01/29] Initial changes --- Cargo.lock | 70 +++++++++---------- docs/sdk/Cargo.toml | 2 +- substrate/frame/Cargo.toml | 4 +- .../frame/examples/frame-crate/Cargo.toml | 4 +- .../frame/examples/frame-crate/src/lib.rs | 6 +- substrate/frame/support/procedural/src/lib.rs | 8 +-- .../frame/support/procedural/tools/src/lib.rs | 4 +- .../support/test/stg_frame_crate/Cargo.toml | 4 +- .../support/test/stg_frame_crate/src/lib.rs | 2 +- .../primitives/api/proc-macro/src/utils.rs | 2 +- templates/minimal/node/Cargo.toml | 2 +- templates/minimal/node/src/chain_spec.rs | 2 +- templates/minimal/pallets/template/Cargo.toml | 4 +- templates/minimal/pallets/template/src/lib.rs | 8 +-- templates/minimal/runtime/Cargo.toml | 4 +- templates/minimal/runtime/src/lib.rs | 8 +-- 16 files changed, 67 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bdbf6ddac268..4a72f4de3b16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5449,35 +5449,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" -[[package]] -name = "frame" -version = "0.0.1-dev" -dependencies = [ - "docify 0.2.7", - "frame-executive", - "frame-support", - "frame-system", - "frame-system-rpc-runtime-api", - "log", - "pallet-examples", - "parity-scale-codec", - "scale-info", - "sp-api", - "sp-arithmetic", - "sp-block-builder", - "sp-consensus-aura", - "sp-consensus-grandpa", - "sp-core", - "sp-inherents", - "sp-io", - "sp-offchain", - "sp-runtime", - "sp-session", - "sp-std 14.0.0", - "sp-transaction-pool", - "sp-version", -] - [[package]] name = "frame-benchmarking" version = "28.0.0" @@ -5815,8 +5786,8 @@ dependencies = [ name = "frame-support-test-stg-frame-crate" version = "0.1.0" dependencies = [ - "frame", "parity-scale-codec", + "polkadot-sdk-frame", "scale-info", ] @@ -8127,11 +8098,11 @@ name = "minimal-template-node" version = "0.0.0" dependencies = [ "clap 4.5.3", - "frame", "futures", "futures-timer", "jsonrpsee", "minimal-template-runtime", + "polkadot-sdk-frame", "sc-basic-authorship", "sc-cli", "sc-client-api", @@ -8161,7 +8132,6 @@ dependencies = [ name = "minimal-template-runtime" version = "0.0.0" dependencies = [ - "frame", "pallet-balances", "pallet-minimal-template", "pallet-sudo", @@ -8169,6 +8139,7 @@ dependencies = [ "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "parity-scale-codec", + "polkadot-sdk-frame", "scale-info", "sp-genesis-builder", "substrate-wasm-builder", @@ -9838,8 +9809,8 @@ dependencies = [ name = "pallet-example-frame-crate" version = "0.0.1" dependencies = [ - "frame", "parity-scale-codec", + "polkadot-sdk-frame", "scale-info", ] @@ -10172,8 +10143,8 @@ dependencies = [ name = "pallet-minimal-template" version = "0.0.0" dependencies = [ - "frame", "parity-scale-codec", + "polkadot-sdk-frame", "scale-info", ] @@ -13368,7 +13339,6 @@ dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", "docify 0.2.7", - "frame", "frame-executive", "frame-support", "frame-system", @@ -13393,6 +13363,7 @@ dependencies = [ "pallet-transaction-payment", "pallet-utility", "parity-scale-codec", + "polkadot-sdk-frame", "sc-cli", "sc-client-db", "sc-consensus-aura", @@ -13422,6 +13393,35 @@ dependencies = [ "substrate-wasm-builder", ] +[[package]] +name = "polkadot-sdk-frame" +version = "0.1.0" +dependencies = [ + "docify 0.2.7", + "frame-executive", + "frame-support", + "frame-system", + "frame-system-rpc-runtime-api", + "log", + "pallet-examples", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-arithmetic", + "sp-block-builder", + "sp-consensus-aura", + "sp-consensus-grandpa", + "sp-core", + "sp-inherents", + "sp-io", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-std 14.0.0", + "sp-transaction-pool", + "sp-version", +] + [[package]] name = "polkadot-service" version = "7.0.0" diff --git a/docs/sdk/Cargo.toml b/docs/sdk/Cargo.toml index 3f84d45640f9..75894bbd8b06 100644 --- a/docs/sdk/Cargo.toml +++ b/docs/sdk/Cargo.toml @@ -17,7 +17,7 @@ workspace = true # Needed for all FRAME-based code parity-scale-codec = { version = "3.0.0", default-features = false } scale-info = { version = "2.6.0", default-features = false } -frame = { path = "../../substrate/frame", features = [ +polkadot-sdk-frame = { path = "../../substrate/frame", features = [ "experimental", "runtime", ] } diff --git a/substrate/frame/Cargo.toml b/substrate/frame/Cargo.toml index 6746723e72f7..742eab4e1ba3 100644 --- a/substrate/frame/Cargo.toml +++ b/substrate/frame/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "frame" -version = "0.0.1-dev" +name = "polkadot-sdk-frame" +version = "0.1.0" authors = ["Parity Technologies "] edition = "2021" license = "Apache-2.0" diff --git a/substrate/frame/examples/frame-crate/Cargo.toml b/substrate/frame/examples/frame-crate/Cargo.toml index 93a46ba7b249..e07b7fb9a3c4 100644 --- a/substrate/frame/examples/frame-crate/Cargo.toml +++ b/substrate/frame/examples/frame-crate/Cargo.toml @@ -19,9 +19,9 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false } scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } -frame = { path = "../..", default-features = false, features = ["experimental", "runtime"] } +polkadot-sdk-frame = { path = "../..", default-features = false, features = ["experimental", "runtime"] } [features] default = ["std"] -std = ["codec/std", "frame/std", "scale-info/std"] +std = ["codec/std", "polkadot-sdk-frame/std", "scale-info/std"] diff --git a/substrate/frame/examples/frame-crate/src/lib.rs b/substrate/frame/examples/frame-crate/src/lib.rs index 781cba5658d7..32e092b3393c 100644 --- a/substrate/frame/examples/frame-crate/src/lib.rs +++ b/substrate/frame/examples/frame-crate/src/lib.rs @@ -15,9 +15,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use frame::prelude::*; +use polkadot_sdk_frame::prelude::*; -#[frame::pallet(dev_mode)] +#[polkadot_sdk_frame::pallet(dev_mode)] pub mod pallet { use super::*; @@ -46,7 +46,7 @@ pub mod pallet { #[cfg(test)] mod tests { use crate::pallet as my_pallet; - use frame::testing_prelude::*; + use polkadot_sdk_frame::testing_prelude::*; construct_runtime!( pub enum Runtime { diff --git a/substrate/frame/support/procedural/src/lib.rs b/substrate/frame/support/procedural/src/lib.rs index dee6d522d25c..6ae63f846ad4 100644 --- a/substrate/frame/support/procedural/src/lib.rs +++ b/substrate/frame/support/procedural/src/lib.rs @@ -665,9 +665,9 @@ pub fn storage_alias(attributes: TokenStream, input: TokenStream) -> TokenStream "{}::macro_magic", match generate_access_from_frame_or_crate("frame-support") { Ok(path) => Ok(path), - Err(_) => generate_access_from_frame_or_crate("frame"), + Err(_) => generate_access_from_frame_or_crate("polkadot-sdk-frame"), } - .expect("Failed to find either `frame-support` or `frame` in `Cargo.toml` dependencies.") + .expect("Failed to find either `frame-support` or `polkadot-sdk-frame` in `Cargo.toml` dependencies.") .to_token_stream() .to_string() ) @@ -1181,9 +1181,9 @@ pub fn pallet_section(attr: TokenStream, tokens: TokenStream) -> TokenStream { "{}::macro_magic", match generate_access_from_frame_or_crate("frame-support") { Ok(path) => Ok(path), - Err(_) => generate_access_from_frame_or_crate("frame"), + Err(_) => generate_access_from_frame_or_crate("polkadot-sdk-frame"), } - .expect("Failed to find either `frame-support` or `frame` in `Cargo.toml` dependencies.") + .expect("Failed to find either `frame-support` or `polkadot-sdk-frame` in `Cargo.toml` dependencies.") .to_token_stream() .to_string() ) diff --git a/substrate/frame/support/procedural/tools/src/lib.rs b/substrate/frame/support/procedural/tools/src/lib.rs index be4396133628..acc307f6c88d 100644 --- a/substrate/frame/support/procedural/tools/src/lib.rs +++ b/substrate/frame/support/procedural/tools/src/lib.rs @@ -56,7 +56,7 @@ pub fn generate_crate_access(unique_id: &str, def_crate: &str) -> TokenStream { /// We want to know if whatever the `path` takes us to, is exported from `frame` or not. In that /// case `path` would start with `frame`, something like `frame::x::y:z`. pub fn is_using_frame_crate(path: &syn::Path) -> bool { - path.segments.first().map(|s| s.ident == "frame").unwrap_or(false) + path.segments.first().map(|s| s.ident == "polkadot-sdk-frame").unwrap_or(false) } /// Generate the crate access for the crate using 2018 syntax. @@ -114,7 +114,7 @@ pub fn generate_hidden_includes(unique_id: &str, def_crate: &str) -> TokenStream /// Generates the path to the frame crate deps. fn get_frame_crate_path(def_crate: &str) -> Option { // This does not work if the frame crate is renamed. - if let Ok(FoundCrate::Name(name)) = crate_name(&"frame") { + if let Ok(FoundCrate::Name(name)) = crate_name(&"polkadot-sdk-frame") { let path = format!("{}::deps::{}", name, def_crate.to_string().replace("-", "_")); Some(syn::parse_str::(&path).expect("is a valid path; qed")) } else { diff --git a/substrate/frame/support/test/stg_frame_crate/Cargo.toml b/substrate/frame/support/test/stg_frame_crate/Cargo.toml index 632ea4e794f6..45953187ff5c 100644 --- a/substrate/frame/support/test/stg_frame_crate/Cargo.toml +++ b/substrate/frame/support/test/stg_frame_crate/Cargo.toml @@ -16,9 +16,9 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] } -frame = { path = "../../..", default-features = false, features = ["experimental", "runtime"] } +polkadot-sdk-frame = { path = "../../..", default-features = false, features = ["experimental", "runtime"] } scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } [features] default = ["std"] -std = ["codec/std", "frame/std", "scale-info/std"] +std = ["codec/std", "polkadot-sdk-frame/std", "scale-info/std"] diff --git a/substrate/frame/support/test/stg_frame_crate/src/lib.rs b/substrate/frame/support/test/stg_frame_crate/src/lib.rs index dc5fff65510e..aaf482d7f729 100644 --- a/substrate/frame/support/test/stg_frame_crate/src/lib.rs +++ b/substrate/frame/support/test/stg_frame_crate/src/lib.rs @@ -18,7 +18,7 @@ // ! A basic pallet to test it compiles along with a runtime using it when `frame_system` and // `frame_support` are reexported by a `frame` crate. -use frame::deps::{frame_support, frame_system}; +use polkadot_sdk_frame::deps::{frame_support, frame_system}; #[frame_support::pallet] pub mod pallet { diff --git a/substrate/primitives/api/proc-macro/src/utils.rs b/substrate/primitives/api/proc-macro/src/utils.rs index c8c1f12d90a1..b031f3ed42af 100644 --- a/substrate/primitives/api/proc-macro/src/utils.rs +++ b/substrate/primitives/api/proc-macro/src/utils.rs @@ -34,7 +34,7 @@ pub fn generate_crate_access() -> TokenStream { quote!(#renamed_name::__private) }, Err(e) => - if let Ok(FoundCrate::Name(name)) = crate_name(&"frame") { + if let Ok(FoundCrate::Name(name)) = crate_name(&"polkadot-sdk-frame") { let path = format!("{}::deps::sp_api::__private", name); let path = syn::parse_str::(&path).expect("is a valid path; qed"); quote!( #path ) diff --git a/templates/minimal/node/Cargo.toml b/templates/minimal/node/Cargo.toml index 65aa1e207520..417a138eaca5 100644 --- a/templates/minimal/node/Cargo.toml +++ b/templates/minimal/node/Cargo.toml @@ -49,7 +49,7 @@ substrate-frame-rpc-system = { path = "../../../substrate/utils/frame/rpc/system # Once the native runtime is gone, there should be little to no dependency on FRAME here, and # certainly no dependency on the runtime. -frame = { path = "../../../substrate/frame", features = [ +polkadot-sdk-frame = { path = "../../../substrate/frame", features = [ "experimental", "runtime", ] } diff --git a/templates/minimal/node/src/chain_spec.rs b/templates/minimal/node/src/chain_spec.rs index 6b721deb6d1d..7ad80251bf1d 100644 --- a/templates/minimal/node/src/chain_spec.rs +++ b/templates/minimal/node/src/chain_spec.rs @@ -42,7 +42,7 @@ pub fn development_config() -> Result { /// Configure initial storage state for FRAME pallets. fn testnet_genesis() -> Value { - use frame::traits::Get; + use polkadot_sdk_frame::traits::Get; use runtime::interface::{Balance, MinimumBalance}; let endowment = >::get().max(1) * 1000; let balances = AccountKeyring::iter() diff --git a/templates/minimal/pallets/template/Cargo.toml b/templates/minimal/pallets/template/Cargo.toml index 9982e5ea53bc..82a33b359182 100644 --- a/templates/minimal/pallets/template/Cargo.toml +++ b/templates/minimal/pallets/template/Cargo.toml @@ -22,7 +22,7 @@ codec = { package = "parity-scale-codec", version = "3.0.0", features = [ scale-info = { version = "2.10.0", default-features = false, features = [ "derive", ] } -frame = { path = "../../../../substrate/frame", default-features = false, features = [ +polkadot-sdk-frame = { path = "../../../../substrate/frame", default-features = false, features = [ "experimental", "runtime", ] } @@ -30,4 +30,4 @@ frame = { path = "../../../../substrate/frame", default-features = false, featur [features] default = ["std"] -std = ["codec/std", "frame/std", "scale-info/std"] +std = ["codec/std", "polkadot-sdk-frame/std", "scale-info/std"] diff --git a/templates/minimal/pallets/template/src/lib.rs b/templates/minimal/pallets/template/src/lib.rs index 713f014bbe61..1e91f7bd87e8 100644 --- a/templates/minimal/pallets/template/src/lib.rs +++ b/templates/minimal/pallets/template/src/lib.rs @@ -1,18 +1,18 @@ -//! A shell pallet built with [`frame`]. +//! A shell pallet built with [`polkadot_sdk_frame`]. #![cfg_attr(not(feature = "std"), no_std)] -use frame::prelude::*; +use polkadot_sdk_frame::deps::frame_support; // Re-export all pallet parts, this is needed to properly import the pallet into the runtime. pub use pallet::*; -#[frame::pallet] +#[frame_support::pallet] pub mod pallet { use super::*; #[pallet::config] - pub trait Config: frame_system::Config {} + pub trait Config: polkadot_sdk_frame::deps::frame_system::Config {} #[pallet::pallet] pub struct Pallet(_); diff --git a/templates/minimal/runtime/Cargo.toml b/templates/minimal/runtime/Cargo.toml index 20ffb706eb49..8742741a03b6 100644 --- a/templates/minimal/runtime/Cargo.toml +++ b/templates/minimal/runtime/Cargo.toml @@ -17,7 +17,7 @@ parity-scale-codec = { version = "3.0.0", default-features = false } scale-info = { version = "2.6.0", default-features = false } # this is a frame-based runtime, thus importing `frame` with runtime feature enabled. -frame = { path = "../../../substrate/frame", default-features = false, features = [ +polkadot-sdk-frame = { path = "../../../substrate/frame", default-features = false, features = [ "experimental", "runtime", ] } @@ -44,7 +44,7 @@ std = [ "parity-scale-codec/std", "scale-info/std", - "frame/std", + "polkadot-sdk-frame/std", "pallet-balances/std", "pallet-sudo/std", diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index 00fcaf1cec76..f8628a68ddc3 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -21,7 +21,7 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -use frame::{ +use polkadot_sdk_frame::{ deps::frame_support::{ genesis_builder_helper::{build_config, create_default_config}, weights::{FixedFee, NoFee}, @@ -111,7 +111,7 @@ impl pallet_transaction_payment::Config for Runtime { impl pallet_minimal_template::Config for Runtime {} -type Block = frame::runtime::types_common::BlockOf; +type Block = polkadot_sdk_frame::runtime::types_common::BlockOf; type Header = HeaderFor; type RuntimeExecutive = @@ -238,10 +238,10 @@ impl_runtime_apis! { // https://github.com/paritytech/substrate/issues/10579#issuecomment-1600537558 pub mod interface { use super::Runtime; - use frame::deps::frame_system; + use polkadot_sdk_frame::deps::frame_system; pub type Block = super::Block; - pub use frame::runtime::types_common::OpaqueBlock; + pub use polkadot_sdk_frame::runtime::types_common::OpaqueBlock; pub type AccountId = ::AccountId; pub type Nonce = ::Nonce; pub type Hash = ::Hash; From 0e2f694a990f4d4c27081532c9300d795fdddcc5 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:30:01 +0530 Subject: [PATCH 02/29] Further changes --- docs/sdk/src/guides/your_first_pallet/mod.rs | 76 +++++++++---------- .../guides/your_first_pallet/with_event.rs | 4 +- docs/sdk/src/meta_contributing.rs | 8 +- docs/sdk/src/polkadot_sdk/cumulus.rs | 8 +- docs/sdk/src/polkadot_sdk/frame_runtime.rs | 28 +++---- docs/sdk/src/polkadot_sdk/substrate.rs | 4 +- .../reference_docs/defensive_programming.rs | 18 ++--- .../src/reference_docs/extrinsic_encoding.rs | 16 ++-- .../reference_docs/frame_offchain_workers.rs | 10 +-- docs/sdk/src/reference_docs/frame_origin.rs | 24 +++--- .../reference_docs/frame_pallet_coupling.rs | 18 ++--- .../src/reference_docs/frame_runtime_types.rs | 28 +++---- .../frame_runtime_upgrades_and_migrations.rs | 2 +- .../reference_docs/trait_based_programming.rs | 28 +++---- substrate/client/chain-spec/src/lib.rs | 2 +- substrate/frame/src/lib.rs | 18 ++--- .../procedural/src/pallet/parse/config.rs | 24 +++--- .../frame/support/procedural/tools/src/lib.rs | 4 +- .../support/test/stg_frame_crate/src/lib.rs | 2 +- ...event_type_invalid_bound_no_frame_crate.rs | 6 +- ...t_type_invalid_bound_no_frame_crate.stderr | 2 +- .../benchmarking-cli/src/pallet/command.rs | 2 +- substrate/utils/frame/rpc/support/src/lib.rs | 2 +- 23 files changed, 167 insertions(+), 167 deletions(-) diff --git a/docs/sdk/src/guides/your_first_pallet/mod.rs b/docs/sdk/src/guides/your_first_pallet/mod.rs index c6e0dd0edf89..557caa3cac79 100644 --- a/docs/sdk/src/guides/your_first_pallet/mod.rs +++ b/docs/sdk/src/guides/your_first_pallet/mod.rs @@ -18,12 +18,12 @@ //! //! The following FRAME topics are covered in this guide: //! -//! - [Storage](frame::pallet_macros::storage) -//! - [Call](frame::pallet_macros::call) -//! - [Event](frame::pallet_macros::event) -//! - [Error](frame::pallet_macros::error) +//! - [Storage](polkadot_sdk_frame::pallet_macros::storage) +//! - [Call](polkadot_sdk_frame::pallet_macros::call) +//! - [Event](polkadot_sdk_frame::pallet_macros::event) +//! - [Error](polkadot_sdk_frame::pallet_macros::error) //! - Basics of testing a pallet -//! - [Constructing a runtime](frame::runtime::prelude::construct_runtime) +//! - [Constructing a runtime](polkadot_sdk_frame::runtime::prelude::construct_runtime) //! //! ## Writing Your First Pallet //! @@ -38,8 +38,8 @@ //! Consider the following as a "shell pallet". We continue building the rest of this pallet based //! on this template. //! -//! [`pallet::config`](frame::pallet_macros::config) and -//! [`pallet::pallet`](frame::pallet_macros::pallet) are both mandatory parts of any pallet. Refer +//! [`pallet::config`](polkadot_sdk_frame::pallet_macros::config) and +//! [`pallet::pallet`](polkadot_sdk_frame::pallet_macros::pallet) are both mandatory parts of any pallet. Refer //! to the documentation of each to get an overview of what they do. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", shell_pallet)] //! @@ -55,14 +55,14 @@ //! > generic bounded type in the `Config` trait, and then specify it in the implementation. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", Balance)] //! -//! The definition of these two storage items, based on [`frame::pallet_macros::storage`] details, +//! The definition of these two storage items, based on [`polkadot_sdk_frame::pallet_macros::storage`] details, //! is as follows: #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", TotalIssuance)] #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", Balances)] //! //! ### Dispatchables //! -//! Next, we will define the dispatchable functions. As per [`frame::pallet_macros::call`], these +//! Next, we will define the dispatchable functions. As per [`polkadot_sdk_frame::pallet_macros::call`], these //! will be defined as normal `fn`s attached to `struct Pallet`. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", impl_pallet)] //! @@ -70,7 +70,7 @@ //! details: //! //! - Where do `T::AccountId` and `T::RuntimeOrigin` come from? These are both defined in -//! [`frame::prelude::frame_system::Config`], therefore we can access them in `T`. +//! [`polkadot_sdk_frame::prelude::frame_system::Config`], therefore we can access them in `T`. //! - What is `ensure_signed`, and what does it do with the aforementioned `T::RuntimeOrigin`? This //! is outside the scope of this guide, and you can learn more about it in the origin reference //! document ([`crate::reference_docs::frame_origin`]). For now, you should only know the @@ -82,32 +82,32 @@ //! //! - Where does `mutate`, `get` and `insert` and other storage APIs come from? All of them are //! explained in the corresponding `type`, for example, for `Balances::::insert`, you can look -//! into [`frame::prelude::StorageMap::insert`]. +//! into [`polkadot_sdk_frame::prelude::StorageMap::insert`]. //! -//! - The return type of all dispatchable functions is [`frame::prelude::DispatchResult`]: +//! - The return type of all dispatchable functions is [`polkadot_sdk_frame::prelude::DispatchResult`]: #![doc = docify::embed!("../../substrate/frame/support/src/dispatch.rs", DispatchResult)] //! -//! Which is more or less a normal Rust `Result`, with a custom [`frame::prelude::DispatchError`] as +//! Which is more or less a normal Rust `Result`, with a custom [`polkadot_sdk_frame::prelude::DispatchError`] as //! the `Err` variant. We won't cover this error in detail here, but importantly you should know //! that there is an `impl From<&'static string> for DispatchError` provided (see -//! [here](`frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError`)). Therefore, +//! [here](`polkadot_sdk_frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError`)). Therefore, //! we can use basic string literals as our error type and `.into()` them into `DispatchError`. //! //! - Why are all `get` and `mutate` functions returning an `Option`? This is the default behavior //! of FRAME storage APIs. You can learn more about how to override this by looking into -//! [`frame::pallet_macros::storage`], and -//! [`frame::prelude::ValueQuery`]/[`frame::prelude::OptionQuery`] +//! [`polkadot_sdk_frame::pallet_macros::storage`], and +//! [`polkadot_sdk_frame::prelude::ValueQuery`]/[`polkadot_sdk_frame::prelude::OptionQuery`] //! //! ### Improving Errors //! //! How we handle error in the above snippets is fairly rudimentary. Let's look at how this can be -//! improved. First, we can use [`frame::prelude::ensure`] to express the error slightly better. +//! improved. First, we can use [`polkadot_sdk_frame::prelude::ensure`] to express the error slightly better. //! This macro will call `.into()` under the hood. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", transfer_better)] //! //! Moreover, you will learn in the [Defensive Programming //! section](crate::reference_docs::defensive_programming) that it is always recommended to use -//! safe arithmetic operations in your runtime. By using [`frame::traits::CheckedSub`], we can not +//! safe arithmetic operations in your runtime. By using [`polkadot_sdk_frame::traits::CheckedSub`], we can not //! only take a step in that direction, but also improve the error handing and make it slightly more //! ergonomic. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", transfer_better_checked)] @@ -118,12 +118,12 @@ //! //! Next, we create a "test runtime" in order to test our pallet. Recall from //! [`crate::polkadot_sdk::frame_runtime`] that a runtime is a collection of pallets, expressed -//! through [`frame::runtime::prelude::construct_runtime`]. All runtimes also have to include -//! [`frame::prelude::frame_system`]. So we expect to see a runtime with two pallet, `frame_system` +//! through [`polkadot_sdk_frame::runtime::prelude::construct_runtime`]. All runtimes also have to include +//! [`polkadot_sdk_frame::prelude::frame_system`]. So we expect to see a runtime with two pallet, `frame_system` //! and the one we just wrote. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", runtime)] //! -//! > [`frame::pallet_macros::derive_impl`] is a FRAME feature that enables developers to have +//! > [`polkadot_sdk_frame::pallet_macros::derive_impl`] is a FRAME feature that enables developers to have //! > defaults for associated types. //! //! Recall that within our pallet, (almost) all blocks of code are generic over ``. And, @@ -156,7 +156,7 @@ //! //! The above is all you need to execute the dispatchables of your pallet. The last thing you need //! to learn is that all of your pallet testing code should be wrapped in -//! [`frame::testing_prelude::TestState`]. This is a type that provides access to an in-memory state +//! [`polkadot_sdk_frame::testing_prelude::TestState`]. This is a type that provides access to an in-memory state //! to be used in our tests. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", first_test)] //! @@ -237,7 +237,7 @@ //! the drawbacks mentioned. In short, we use an enum to represent different variants of our //! error. These variants are then mapped in an efficient way (using only `u8` indices) to //! [`sp_runtime::DispatchError::Module`]. Read more about this in -//! [`frame::pallet_macros::error`]. +//! [`polkadot_sdk_frame::pallet_macros::error`]. //! //! - **Event**: Events are akin to the return type of dispatchables. They are mostly data blobs //! emitted by the runtime to let outside world know what is happening inside the pallet. Since @@ -251,13 +251,13 @@ //! //! With the explanation out of the way, let's see how these components can be added. Both follow a //! fairly familiar syntax: normal Rust enums, with extra -//! [`#[frame::event]`](frame::pallet_macros::event) and -//! [`#[frame::error]`](frame::pallet_macros::error) attributes attached. +//! [`#[polkadot_sdk_frame::event]`](polkadot_sdk_frame::pallet_macros::event) and +//! [`#[polkadot_sdk_frame::error]`](polkadot_sdk_frame::pallet_macros::error) attributes attached. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", Event)] #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", Error)] //! //! One slightly custom part of this is the [`#[pallet::generate_deposit(pub(super) fn -//! deposit_event)]`](frame::pallet_macros::generate_deposit) part. Without going into too +//! deposit_event)]`](polkadot_sdk_frame::pallet_macros::generate_deposit) part. Without going into too //! much detail, in order for a pallet to emit events to the rest of the system, it needs to do two //! things: //! @@ -269,7 +269,7 @@ //! //! 2. But, doing this conversion and storing is too much to expect each pallet to define. FRAME //! provides a default way of storing events, and this is what -//! [`pallet::generate_deposit`](frame::pallet_macros::generate_deposit) is doing. +//! [`pallet::generate_deposit`](polkadot_sdk_frame::pallet_macros::generate_deposit) is doing. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", config_v2)] //! //! > These `Runtime*` types are better explained in @@ -284,7 +284,7 @@ //! //! In this snippet, the actual `RuntimeEvent` type (right hand side of `type RuntimeEvent = //! RuntimeEvent`) is generated by -//! [`construct_runtime`](frame::runtime::prelude::construct_runtime). An interesting way to inspect +//! [`construct_runtime`](polkadot_sdk_frame::runtime::prelude::construct_runtime). An interesting way to inspect //! this type is to see its definition in rust-docs: //! [`crate::guides::your_first_pallet::pallet_v2::tests::runtime_v2::RuntimeEvent`]. //! @@ -298,14 +298,14 @@ //! - [`crate::reference_docs::frame_origin`]. //! - [`crate::reference_docs::frame_runtime_types`]. //! - The pallet we wrote in this guide was using `dev_mode`, learn more in -//! [`frame::pallet_macros::config`]. +//! [`polkadot_sdk_frame::pallet_macros::config`]. //! - Learn more about the individual pallet items/macros, such as event and errors and call, in -//! [`frame::pallet_macros`]. +//! [`polkadot_sdk_frame::pallet_macros`]. #[docify::export] -#[frame::pallet(dev_mode)] +#[polkadot_sdk_frame::pallet(dev_mode)] pub mod shell_pallet { - use frame::prelude::*; + use polkadot_sdk_frame::prelude::*; #[pallet::config] pub trait Config: frame_system::Config {} @@ -314,9 +314,9 @@ pub mod shell_pallet { pub struct Pallet(_); } -#[frame::pallet(dev_mode)] +#[polkadot_sdk_frame::pallet(dev_mode)] pub mod pallet { - use frame::prelude::*; + use polkadot_sdk_frame::prelude::*; #[docify::export] pub type Balance = u128; @@ -418,7 +418,7 @@ pub mod pallet { #[cfg(any(test, doc))] pub(crate) mod tests { use crate::guides::your_first_pallet::pallet::*; - use frame::testing_prelude::*; + use polkadot_sdk_frame::testing_prelude::*; const ALICE: u64 = 1; const BOB: u64 = 2; const CHARLIE: u64 = 3; @@ -633,10 +633,10 @@ pub mod pallet { } } -#[frame::pallet(dev_mode)] +#[polkadot_sdk_frame::pallet(dev_mode)] pub mod pallet_v2 { use super::pallet::Balance; - use frame::prelude::*; + use polkadot_sdk_frame::prelude::*; #[docify::export(config_v2)] #[pallet::config] @@ -701,7 +701,7 @@ pub mod pallet_v2 { #[cfg(any(test, doc))] pub mod tests { use super::{super::pallet::tests::StateBuilder, *}; - use frame::testing_prelude::*; + use polkadot_sdk_frame::testing_prelude::*; const ALICE: u64 = 1; const BOB: u64 = 2; diff --git a/docs/sdk/src/guides/your_first_pallet/with_event.rs b/docs/sdk/src/guides/your_first_pallet/with_event.rs index a65aac324f07..c3efb91dd081 100644 --- a/docs/sdk/src/guides/your_first_pallet/with_event.rs +++ b/docs/sdk/src/guides/your_first_pallet/with_event.rs @@ -1,6 +1,6 @@ -#[frame::pallet(dev_mode)] +#[polkadot_sdk_frame::pallet(dev_mode)] pub mod pallet { - use frame::prelude::*; + use polkadot_sdk_frame::prelude::*; #[docify::export] pub type Balance = u128; diff --git a/docs/sdk/src/meta_contributing.rs b/docs/sdk/src/meta_contributing.rs index fcdcea9934bb..f57ef9880637 100644 --- a/docs/sdk/src/meta_contributing.rs +++ b/docs/sdk/src/meta_contributing.rs @@ -81,9 +81,9 @@ //! //! //! ``` -//! #[frame::pallet(dev_mode)] +//! #[polkadot_sdk_frame::pallet(dev_mode)] //! pub mod pallet { -//! # use frame::prelude::*; +//! # use polkadot_sdk_frame::prelude::*; //! # #[pallet::config] //! # pub trait Config: frame_system::Config {} //! # #[pallet::pallet] @@ -104,9 +104,9 @@ //! explained in [`crate::reference_docs::frame_runtime_types`]. Build on top of this! //! * Then, what is `origin`? Just an account id? [`crate::reference_docs::frame_origin`]. //! * Then, what is `DispatchResult`? Why is this called *dispatch*? Probably something that can be -//! explained in the documentation of [`frame::prelude::DispatchResult`]. +//! explained in the documentation of [`polkadot_sdk_frame::prelude::DispatchResult`]. //! * Why is `"SomeStaticString"` a valid error? Because there is implementation for it that you can -//! see [here](frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError). +//! see [here](polkadot_sdk_frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError). //! //! //! All of these are examples of underlying information that a contributor should: diff --git a/docs/sdk/src/polkadot_sdk/cumulus.rs b/docs/sdk/src/polkadot_sdk/cumulus.rs index 9bd957c7c1c0..0802658839eb 100644 --- a/docs/sdk/src/polkadot_sdk/cumulus.rs +++ b/docs/sdk/src/polkadot_sdk/cumulus.rs @@ -17,7 +17,7 @@ //! A parachain runtime should use a number of pallets that are provided by Cumulus and Substrate. //! Notably: //! -//! - [`frame-system`](frame::prelude::frame_system), like all FRAME-based runtimes. +//! - [`frame-system`](polkadot_sdk_frame::prelude::frame_system), like all FRAME-based runtimes. //! - [`cumulus_pallet_parachain_system`] //! - [`parachain_info`] #![doc = docify::embed!("./src/polkadot_sdk/cumulus.rs", system_pallets)] @@ -32,7 +32,7 @@ //! //! //! Finally, a separate macro, similar to -//! [`impl_runtime_api`](frame::runtime::prelude::impl_runtime_apis), which creates the default set +//! [`impl_runtime_api`](polkadot_sdk_frame::runtime::prelude::impl_runtime_apis), which creates the default set //! of runtime APIs, will generate the parachain runtime's validation runtime API, also known as //! parachain validation function (PVF). Without this API, the relay chain is unable to validate //! blocks produced by our parachain. @@ -48,7 +48,7 @@ #[cfg(test)] mod tests { mod runtime { - pub use frame::{ + pub use polkadot_sdk_frame::{ deps::sp_consensus_aura::sr25519::AuthorityId as AuraId, prelude::*, runtime::prelude::*, testing_prelude::*, }; @@ -95,7 +95,7 @@ mod tests { 1, >; type WeightInfo = (); - type DmpQueue = frame::traits::EnqueueWithOrigin<(), sp_core::ConstU8<0>>; + type DmpQueue = polkadot_sdk_frame::traits::EnqueueWithOrigin<(), sp_core::ConstU8<0>>; } impl parachain_info::Config for Runtime {} diff --git a/docs/sdk/src/polkadot_sdk/frame_runtime.rs b/docs/sdk/src/polkadot_sdk/frame_runtime.rs index f9b8a381365c..369ed658c20e 100644 --- a/docs/sdk/src/polkadot_sdk/frame_runtime.rs +++ b/docs/sdk/src/polkadot_sdk/frame_runtime.rs @@ -34,23 +34,23 @@ //! about its own responsibilities and make as few assumptions about the general runtime as //! possible. A pallet is analogous to a _module_ in the runtime. //! -//! A pallet is defined as a `mod pallet` wrapped by the [`frame::pallet`] macro. Within this macro, +//! A pallet is defined as a `mod pallet` wrapped by the [`polkadot_sdk_frame::pallet`] macro. Within this macro, //! pallet components/parts can be defined. Most notable of these parts are: //! -//! - [Config](frame::pallet_macros::config), allowing a pallet to make itself configurable and +//! - [Config](polkadot_sdk_frame::pallet_macros::config), allowing a pallet to make itself configurable and //! generic over types, values and such. -//! - [Storage](frame::pallet_macros::storage), allowing a pallet to define onchain storage. -//! - [Dispatchable function](frame::pallet_macros::call), allowing a pallet to define extrinsics +//! - [Storage](polkadot_sdk_frame::pallet_macros::storage), allowing a pallet to define onchain storage. +//! - [Dispatchable function](polkadot_sdk_frame::pallet_macros::call), allowing a pallet to define extrinsics //! that are callable by end users, from the outer world. -//! - [Events](frame::pallet_macros::event), allowing a pallet to emit events. -//! - [Errors](frame::pallet_macros::error), allowing a pallet to emit well-formed errors. +//! - [Events](polkadot_sdk_frame::pallet_macros::event), allowing a pallet to emit events. +//! - [Errors](polkadot_sdk_frame::pallet_macros::error), allowing a pallet to emit well-formed errors. //! //! Some of these pallet components resemble the building blocks of a smart contract. While both //! models are programming state transition functions of blockchains, there are crucial differences //! between the two. See [`crate::reference_docs::runtime_vs_smart_contract`] for more. //! //! Most of these components are defined using macros, the full list of which can be found in -//! [`frame::pallet_macros`]. +//! [`polkadot_sdk_frame::pallet_macros`]. //! //! ### Example //! @@ -60,16 +60,16 @@ //! //! A runtime is a collection of pallets that are amalgamated together. Each pallet typically has //! some configurations (exposed as a `trait Config`) that needs to be *specified* in the runtime. -//! This is done with [`frame::runtime::prelude::construct_runtime`]. +//! This is done with [`polkadot_sdk_frame::runtime::prelude::construct_runtime`]. //! //! A (real) runtime that actually wishes to compile to WASM needs to also implement a set of //! runtime-apis. These implementation can be specified using the -//! [`frame::runtime::prelude::impl_runtime_apis`] macro. +//! [`polkadot_sdk_frame::runtime::prelude::impl_runtime_apis`] macro. //! //! ### Example //! //! The following example shows a (test) runtime that is composing the pallet demonstrated above, -//! next to the [`frame::prelude::frame_system`] pallet, into a runtime. +//! next to the [`polkadot_sdk_frame::prelude::frame_system`] pallet, into a runtime. #![doc = docify::embed!("src/polkadot_sdk/frame_runtime.rs", runtime)] //! //! ## More Examples @@ -87,14 +87,14 @@ //! * writing a runtime in pure Rust, as done in [this template](https://github.com/JoshOrndorff/frameless-node-template). //! * writing a runtime in AssemblyScript,as explored in [this project](https://github.com/LimeChain/subsembly). -use frame::prelude::*; +use polkadot_sdk_frame::prelude::*; /// A FRAME based pallet. This `mod` is the entry point for everything else. All /// `#[pallet::xxx]` macros must be defined in this `mod`. Although, frame also provides an /// experimental feature to break these parts into different `mod`s. See [`pallet_examples`] for /// more. #[docify::export] -#[frame::pallet(dev_mode)] +#[polkadot_sdk_frame::pallet(dev_mode)] pub mod pallet { use super::*; @@ -116,7 +116,7 @@ pub mod pallet { } /// A mandatory struct in each pallet. All functions callable by external users (aka. - /// transactions) must be attached to this type (see [`frame::pallet_macros::call`]). For + /// transactions) must be attached to this type (see [`polkadot_sdk_frame::pallet_macros::call`]). For /// convenience, internal (private) functions can also be attached to this type. #[pallet::pallet] pub struct Pallet(PhantomData); @@ -151,7 +151,7 @@ pub mod pallet { #[docify::export] pub mod runtime { use super::pallet as pallet_example; - use frame::{prelude::*, testing_prelude::*}; + use polkadot_sdk_frame::{prelude::*, testing_prelude::*}; // The major macro that amalgamates pallets into `enum Runtime` construct_runtime!( diff --git a/docs/sdk/src/polkadot_sdk/substrate.rs b/docs/sdk/src/polkadot_sdk/substrate.rs index 5021c55e581f..cd9158042ab8 100644 --- a/docs/sdk/src/polkadot_sdk/substrate.rs +++ b/docs/sdk/src/polkadot_sdk/substrate.rs @@ -111,8 +111,8 @@ //! Substrate-based project typically contains the following: //! //! * Under `./runtime`, a `./runtime/src/lib.rs` which is the top level runtime amalgamator file. -//! This file typically contains the [`frame::runtime::prelude::construct_runtime`] and -//! [`frame::runtime::prelude::impl_runtime_apis`] macro calls, which is the final definition of a +//! This file typically contains the [`polkadot_sdk_frame::runtime::prelude::construct_runtime`] and +//! [`polkadot_sdk_frame::runtime::prelude::impl_runtime_apis`] macro calls, which is the final definition of a //! runtime. //! //! * Under `./node`, a `main.rs`, which is the starting point, and a `./service.rs`, which contains diff --git a/docs/sdk/src/reference_docs/defensive_programming.rs b/docs/sdk/src/reference_docs/defensive_programming.rs index 9828e1b50918..004868397d00 100644 --- a/docs/sdk/src/reference_docs/defensive_programming.rs +++ b/docs/sdk/src/reference_docs/defensive_programming.rs @@ -70,18 +70,18 @@ //! //! ### Defensive Traits //! -//! The [`Defensive`](frame::traits::Defensive) trait provides a number of functions, all of which +//! The [`Defensive`](polkadot_sdk_frame::traits::Defensive) trait provides a number of functions, all of which //! provide an alternative to 'vanilla' Rust functions, e.g.,: //! -//! - [`defensive_unwrap_or()`](frame::traits::Defensive::defensive_unwrap_or) instead of +//! - [`defensive_unwrap_or()`](polkadot_sdk_frame::traits::Defensive::defensive_unwrap_or) instead of //! `unwrap_or()` -//! - [`defensive_ok_or()`](frame::traits::DefensiveOption::defensive_ok_or) instead of `ok_or()` +//! - [`defensive_ok_or()`](polkadot_sdk_frame::traits::DefensiveOption::defensive_ok_or) instead of `ok_or()` //! //! Defensive methods use [`debug_assertions`](https://doc.rust-lang.org/reference/conditional-compilation.html#debug_assertions), which panic in development, but in //! production/release, they will merely log an error (i.e., `log::error`). //! -//! The [`Defensive`](frame::traits::Defensive) trait and its various implementations can be found -//! [here](frame::traits::Defensive). +//! The [`Defensive`](polkadot_sdk_frame::traits::Defensive) trait and its various implementations can be found +//! [here](polkadot_sdk_frame::traits::Defensive). //! //! ## Integer Overflow //! @@ -187,8 +187,8 @@ //! to avoid introducing the notion of any potential-panic or wrapping behavior. //! //! There is also a series of defensive alternatives via -//! [`DefensiveSaturating`](frame::traits::DefensiveSaturating), which introduces the same behavior -//! of the [`Defensive`](frame::traits::Defensive) trait, only with saturating, mathematical +//! [`DefensiveSaturating`](polkadot_sdk_frame::traits::DefensiveSaturating), which introduces the same behavior +//! of the [`Defensive`](polkadot_sdk_frame::traits::Defensive) trait, only with saturating, mathematical //! operations: #![doc = docify::embed!( "./src/reference_docs/defensive_programming.rs", @@ -277,7 +277,7 @@ //! actually cause harm to the network, and thus stalling would be the better option. //! //! Take the example of the BABE pallet ([`pallet_babe`]), which doesn't allow for a validator to -//! participate if it is disabled (see: [`frame::traits::DisabledValidators`]): +//! participate if it is disabled (see: [`polkadot_sdk_frame::traits::DisabledValidators`]): //! //! ```ignore //! if T::DisabledValidators::is_disabled(authority_index) { @@ -358,7 +358,7 @@ mod fake_runtime_types { #[cfg(test)] mod tests { - use frame::traits::DefensiveSaturating; + use polkadot_sdk_frame::traits::DefensiveSaturating; #[docify::export] #[test] fn checked_add_example() { diff --git a/docs/sdk/src/reference_docs/extrinsic_encoding.rs b/docs/sdk/src/reference_docs/extrinsic_encoding.rs index 8c8568a228fa..037c86e9f2e4 100644 --- a/docs/sdk/src/reference_docs/extrinsic_encoding.rs +++ b/docs/sdk/src/reference_docs/extrinsic_encoding.rs @@ -36,7 +36,7 @@ //! //! ## compact_encoded_length //! -//! This is a [SCALE compact encoded][frame::deps::codec::Compact] integer which is equal to the +//! This is a [SCALE compact encoded][polkadot_sdk_frame::deps::codec::Compact] integer which is equal to the //! length, in bytes, of the rest of the extrinsic details. //! //! To obtain this value, we must encode and concatenate together the rest of the extrinsic details @@ -69,7 +69,7 @@ //! //! ### from_address //! -//! This is the [SCALE encoded][frame::deps::codec] address of the sender of the extrinsic. The +//! This is the [SCALE encoded][polkadot_sdk_frame::deps::codec] address of the sender of the extrinsic. The //! address is the first generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`], and so //! can vary from chain to chain. //! @@ -80,7 +80,7 @@ //! //! ### signature //! -//! This is the [SCALE encoded][frame::deps::codec] signature. The signature type is configured via +//! This is the [SCALE encoded][polkadot_sdk_frame::deps::codec] signature. The signature type is configured via //! the third generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`], which determines the //! shape of the signature and signing algorithm that should be used. //! @@ -92,7 +92,7 @@ //! //! ### signed_extensions_extra //! -//! This is the concatenation of the [SCALE encoded][frame::deps::codec] bytes representing each of +//! This is the concatenation of the [SCALE encoded][polkadot_sdk_frame::deps::codec] bytes representing each of //! the [_signed extensions_][sp_runtime::traits::SignedExtension], and are configured by the //! fourth generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`]. Learn more about //! signed extensions [here][crate::reference_docs::signed_extensions]. @@ -111,11 +111,11 @@ //! At the time of writing, Polkadot configures them //! [here](https://github.com/polkadot-fellows/runtimes/blob/1dc04eb954eadf8aadb5d83990b89662dbb5a074/relay/polkadot/src/lib.rs#L1432C25-L1432C25). //! Some of the common signed extensions are defined -//! [here][frame::deps::frame_system#signed-extensions]. +//! [here][polkadot_sdk_frame::deps::frame_system#signed-extensions]. //! //! Information about exactly which signed extensions are present on a chain and in what order is //! also a part of the metadata for the chain. For V15 metadata, it can be -//! [found here][frame::deps::frame_support::__private::metadata::v15::ExtrinsicMetadata]. +//! [found here][polkadot_sdk_frame::deps::frame_support::__private::metadata::v15::ExtrinsicMetadata]. //! //! ## call_data //! @@ -123,7 +123,7 @@ //! altered. This is defined by the second generic parameter of //! [`sp_runtime::generic::UncheckedExtrinsic`]. //! -//! A call can be anything that implements [`Encode`][frame::deps::codec::Encode]. In FRAME-based +//! A call can be anything that implements [`Encode`][polkadot_sdk_frame::deps::codec::Encode]. In FRAME-based //! runtimes, a call is represented as an enum of enums, where the outer enum represents the FRAME //! pallet being called, and the inner enum represents the call being made within that pallet, and //! any arguments to it. Read more about the call enum @@ -152,7 +152,7 @@ //! Information about the pallets that exist for a chain (including their indexes), the calls //! available in each pallet (including their indexes), and the arguments required for each call //! can be found in the metadata for the chain. For V15 metadata, this information -//! [is here][frame::deps::frame_support::__private::metadata::v15::PalletMetadata]. +//! [is here][polkadot_sdk_frame::deps::frame_support::__private::metadata::v15::PalletMetadata]. //! //! # The Signed Payload Format //! diff --git a/docs/sdk/src/reference_docs/frame_offchain_workers.rs b/docs/sdk/src/reference_docs/frame_offchain_workers.rs index 7999707e5ee0..6e4d9527e5c7 100644 --- a/docs/sdk/src/reference_docs/frame_offchain_workers.rs +++ b/docs/sdk/src/reference_docs/frame_offchain_workers.rs @@ -54,14 +54,14 @@ //! ## FRAME's API //! //! [`frame`] provides a simple API through which pallets can define offchain worker functions. This -//! is part of [`frame::traits::Hooks`], which is implemented as a part of -//! [`frame::pallet_macros::hooks`]. +//! is part of [`polkadot_sdk_frame::traits::Hooks`], which is implemented as a part of +//! [`polkadot_sdk_frame::pallet_macros::hooks`]. //! //! ``` //! -//! #[frame::pallet] +//! #[polkadot_sdk_frame::pallet] //! pub mod pallet { -//! use frame::prelude::*; +//! use polkadot_sdk_frame::prelude::*; //! //! #[pallet::config] //! pub trait Config: frame_system::Config {} @@ -96,7 +96,7 @@ //! API into the WASM blob are: //! //! * Accessing the state is easier within the `offchain_worker` function, as it is already a part -//! of the runtime, and [`frame::pallet_macros::storage`] provides all the tools needed to read +//! of the runtime, and [`polkadot_sdk_frame::pallet_macros::storage`] provides all the tools needed to read //! the state. Other client libraries might provide varying degrees of capability here. //! * It will be updated in synchrony with the runtime. A Substrate's offchain application is part //! of the same WASM blob, and is therefore guaranteed to be up to date. diff --git a/docs/sdk/src/reference_docs/frame_origin.rs b/docs/sdk/src/reference_docs/frame_origin.rs index a2aac7dd3554..5b6cf1abcc9b 100644 --- a/docs/sdk/src/reference_docs/frame_origin.rs +++ b/docs/sdk/src/reference_docs/frame_origin.rs @@ -93,13 +93,13 @@ //! Then, within the pallet, we can simply use this "unknown" origin check type: #![doc = docify::embed!("./src/reference_docs/frame_origin.rs", external_origin_usage)] //! -//! Finally, at the runtime, any implementation of [`frame::traits::EnsureOrigin`] can be passed. +//! Finally, at the runtime, any implementation of [`polkadot_sdk_frame::traits::EnsureOrigin`] can be passed. #![doc = docify::embed!("./src/reference_docs/frame_origin.rs", external_origin_provide)] //! -//! Indeed, some of these implementations of [`frame::traits::EnsureOrigin`] are similar to the ones -//! that we know about: [`frame::runtime::prelude::EnsureSigned`], -//! [`frame::runtime::prelude::EnsureSignedBy`], [`frame::runtime::prelude::EnsureRoot`], -//! [`frame::runtime::prelude::EnsureNone`], etc. But, there are also many more that are not known +//! Indeed, some of these implementations of [`polkadot_sdk_frame::traits::EnsureOrigin`] are similar to the ones +//! that we know about: [`polkadot_sdk_frame::runtime::prelude::EnsureSigned`], +//! [`polkadot_sdk_frame::runtime::prelude::EnsureSignedBy`], [`polkadot_sdk_frame::runtime::prelude::EnsureRoot`], +//! [`polkadot_sdk_frame::runtime::prelude::EnsureNone`], etc. But, there are also many more that are not known //! to us, and are defined in other pallets. //! //! For example, [`pallet_collective`] defines [`pallet_collective::EnsureMember`] and @@ -107,7 +107,7 @@ //! to earlier in this document. //! //! Make sure to check the full list of [implementors of -//! `EnsureOrigin`](frame::traits::EnsureOrigin#implementors) for more inspiration. +//! `EnsureOrigin`](polkadot_sdk_frame::traits::EnsureOrigin#implementors) for more inspiration. //! //! ## Obtaining Abstract Origins //! @@ -128,9 +128,9 @@ //! [^1]: Inherents are essentially unsigned extrinsics that need an [`frame_system::ensure_none`] //! origin check, and through the virtue of being an inherent, are agreed upon by all validators. -use frame::prelude::*; +use polkadot_sdk_frame::prelude::*; -#[frame::pallet(dev_mode)] +#[polkadot_sdk_frame::pallet(dev_mode)] pub mod pallet_for_origin { use super::*; @@ -150,7 +150,7 @@ pub mod pallet_for_origin { } } -#[frame::pallet(dev_mode)] +#[polkadot_sdk_frame::pallet(dev_mode)] pub mod pallet_with_custom_origin { use super::*; @@ -195,7 +195,7 @@ pub mod pallet_with_custom_origin { pub mod runtime_for_origin { use super::pallet_with_custom_origin; - use frame::{runtime::prelude::*, testing_prelude::*}; + use polkadot_sdk_frame::{runtime::prelude::*, testing_prelude::*}; #[docify::export(runtime_exp)] construct_runtime!( @@ -215,7 +215,7 @@ pub mod runtime_for_origin { } } -#[frame::pallet(dev_mode)] +#[polkadot_sdk_frame::pallet(dev_mode)] pub mod pallet_with_external_origin { use super::*; #[docify::export(external_origin_def)] @@ -239,7 +239,7 @@ pub mod pallet_with_external_origin { pub mod runtime_for_external_origin { use super::*; - use frame::{runtime::prelude::*, testing_prelude::*}; + use polkadot_sdk_frame::{runtime::prelude::*, testing_prelude::*}; construct_runtime!( pub struct Runtime { diff --git a/docs/sdk/src/reference_docs/frame_pallet_coupling.rs b/docs/sdk/src/reference_docs/frame_pallet_coupling.rs index cca7f9feb3f4..41d525656ee0 100644 --- a/docs/sdk/src/reference_docs/frame_pallet_coupling.rs +++ b/docs/sdk/src/reference_docs/frame_pallet_coupling.rs @@ -3,7 +3,7 @@ //! This reference document explains how FRAME pallets can be combined to interact together. //! //! It is suggested to re-read [`crate::polkadot_sdk::frame_runtime`], notably the information -//! around [`frame::pallet_macros::config`]. Recall that: +//! around [`polkadot_sdk_frame::pallet_macros::config`]. Recall that: //! //! > Configuration trait of a pallet: It allows a pallet to receive types at a later //! > point from the runtime that wishes to contain it. It allows the pallet to be parameterized @@ -123,8 +123,8 @@ //! With the above information in context, we can conclude that **`frame_system` is a special pallet //! that is tightly coupled with every other pallet**. This is because it provides the fundamental //! system functionality that every pallet needs, such as some types like -//! [`frame::prelude::frame_system::Config::AccountId`], -//! [`frame::prelude::frame_system::Config::Hash`], and some functionality such as block number, +//! [`polkadot_sdk_frame::prelude::frame_system::Config::AccountId`], +//! [`polkadot_sdk_frame::prelude::frame_system::Config::Hash`], and some functionality such as block number, //! etc. //! //! ## Recap @@ -155,10 +155,10 @@ #![allow(unused)] -use frame::prelude::*; +use polkadot_sdk_frame::prelude::*; #[docify::export] -#[frame::pallet] +#[polkadot_sdk_frame::pallet] pub mod pallet_foo { use super::*; @@ -176,7 +176,7 @@ pub mod pallet_foo { } #[docify::export] -#[frame::pallet] +#[polkadot_sdk_frame::pallet] pub mod pallet_author { use super::*; @@ -193,7 +193,7 @@ pub mod pallet_author { } } -#[frame::pallet] +#[polkadot_sdk_frame::pallet] pub mod pallet_foo_tight { use super::*; @@ -221,7 +221,7 @@ pub trait AuthorProvider { fn author() -> AccountId; } -#[frame::pallet] +#[polkadot_sdk_frame::pallet] pub mod pallet_foo_loose { use super::*; @@ -270,7 +270,7 @@ impl AuthorProvider for () { pub mod runtime { use super::*; use cumulus_pallet_aura_ext::pallet; - use frame::{runtime::prelude::*, testing_prelude::*}; + use polkadot_sdk_frame::{runtime::prelude::*, testing_prelude::*}; construct_runtime!( pub struct Runtime { diff --git a/docs/sdk/src/reference_docs/frame_runtime_types.rs b/docs/sdk/src/reference_docs/frame_runtime_types.rs index 32cda5bc5345..dc40ad6f900f 100644 --- a/docs/sdk/src/reference_docs/frame_runtime_types.rs +++ b/docs/sdk/src/reference_docs/frame_runtime_types.rs @@ -43,7 +43,7 @@ //! type in each pallet, for example [`pallet_foo::Call`]. //! //! [`RuntimeOrigin`]'s [`OriginCaller`] has two variants, one for system, and one for `pallet_foo` -//! which utilized [`frame::pallet_macros::origin`]. +//! which utilized [`polkadot_sdk_frame::pallet_macros::origin`]. //! //! Finally, [`RuntimeGenesisConfig`] is composed of `frame_system` and a variant for `pallet_bar`'s //! [`pallet_bar::GenesisConfig`]. @@ -80,7 +80,7 @@ //! The only way to express this using Rust's associated types is for the pallet to **define its own //! associated type `RuntimeCall`, and further specify what it thinks `RuntimeCall` should be**. //! -//! In this case, we will want to assert the existence of [`frame::traits::IsSubType`], which is +//! In this case, we will want to assert the existence of [`polkadot_sdk_frame::traits::IsSubType`], which is //! very similar to [`TryFrom`]. #![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", custom_runtime_call)] //! @@ -99,7 +99,7 @@ //! is being constructed. //! //! Now, within this pallet, this new `RuntimeCall` can be used, and it can use its new trait -//! bounds, such as being [`frame::traits::IsSubType`]: +//! bounds, such as being [`polkadot_sdk_frame::traits::IsSubType`]: #![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", custom_runtime_call_usages)] //! //! ### Asserting Equality of Multiple Runtime Composite Enums @@ -111,9 +111,9 @@ //! runtime is constructed? The following snippet exactly does that: #![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", assert_equality)] //! -//! We leave it to the reader to further explore what [`frame::traits::Hooks::integrity_test`] is, +//! We leave it to the reader to further explore what [`polkadot_sdk_frame::traits::Hooks::integrity_test`] is, //! and what [`core::any::TypeId`] is. Another way to assert this is using -//! [`frame::traits::IsType`]. +//! [`polkadot_sdk_frame::traits::IsType`]. //! //! ## Type Aliases //! @@ -123,7 +123,7 @@ //! `System` //! * [`runtime::AllPalletsWithSystem`] is an alias for a tuple of all of the above. This type is //! important to FRAME internals such as `executive`, as it implements traits such as -//! [`frame::traits::Hooks`]. +//! [`polkadot_sdk_frame::traits::Hooks`]. //! //! ## Further Details //! @@ -135,7 +135,7 @@ //! * See the corresponding lecture in the [pba-book](https://polkadot-blockchain-academy.github.io/pba-book/frame/outer-enum/page.html). //! //! -//! [`construct_runtime`]: frame::runtime::prelude::construct_runtime +//! [`construct_runtime`]: polkadot_sdk_frame::runtime::prelude::construct_runtime //! [`runtime::PalletFoo`]: crate::reference_docs::frame_runtime_types::runtime::PalletFoo //! [`runtime::AllPalletsWithSystem`]: crate::reference_docs::frame_runtime_types::runtime::AllPalletsWithSystem //! [`runtime`]: crate::reference_docs::frame_runtime_types::runtime @@ -153,10 +153,10 @@ //! [`RuntimeCall`]: crate::reference_docs::frame_runtime_types::runtime::RuntimeCall //! [`RuntimeHoldReason`]: crate::reference_docs::frame_runtime_types::runtime::RuntimeHoldReason -use frame::prelude::*; +use polkadot_sdk_frame::prelude::*; #[docify::export] -#[frame::pallet(dev_mode)] +#[polkadot_sdk_frame::pallet(dev_mode)] pub mod pallet_foo { use super::*; @@ -186,7 +186,7 @@ pub mod pallet_foo { } #[docify::export] -#[frame::pallet(dev_mode)] +#[polkadot_sdk_frame::pallet(dev_mode)] pub mod pallet_bar { use super::*; @@ -217,7 +217,7 @@ pub mod pallet_bar { pub mod runtime { use super::{pallet_bar, pallet_foo}; - use frame::{runtime::prelude::*, testing_prelude::*}; + use polkadot_sdk_frame::{runtime::prelude::*, testing_prelude::*}; #[docify::export(runtime_exp)] construct_runtime!( @@ -237,10 +237,10 @@ pub mod runtime { impl pallet_bar::Config for Runtime {} } -#[frame::pallet(dev_mode)] +#[polkadot_sdk_frame::pallet(dev_mode)] pub mod pallet_with_specific_runtime_call { use super::*; - use frame::traits::IsSubType; + use polkadot_sdk_frame::traits::IsSubType; #[docify::export(custom_runtime_call)] /// A pallet that wants to further narrow down what `RuntimeCall` is. @@ -284,7 +284,7 @@ pub mod pallet_with_specific_runtime_call { pub mod runtime_with_specific_runtime_call { use super::pallet_with_specific_runtime_call; - use frame::{runtime::prelude::*, testing_prelude::*}; + use polkadot_sdk_frame::{runtime::prelude::*, testing_prelude::*}; construct_runtime!( pub struct Runtime { diff --git a/docs/sdk/src/reference_docs/frame_runtime_upgrades_and_migrations.rs b/docs/sdk/src/reference_docs/frame_runtime_upgrades_and_migrations.rs index 7d870b432218..92ecce0e3763 100644 --- a/docs/sdk/src/reference_docs/frame_runtime_upgrades_and_migrations.rs +++ b/docs/sdk/src/reference_docs/frame_runtime_upgrades_and_migrations.rs @@ -35,7 +35,7 @@ //! # Migrations //! //! It is often desirable to define logic to execute immediately after runtime upgrades (see -//! [this diagram](frame::traits::Hooks)). +//! [this diagram](polkadot_sdk_frame::traits::Hooks)). //! //! Self-contained pieces of logic that execute after a runtime upgrade are called "Migrations". //! diff --git a/docs/sdk/src/reference_docs/trait_based_programming.rs b/docs/sdk/src/reference_docs/trait_based_programming.rs index ace313880707..5408a8546f49 100644 --- a/docs/sdk/src/reference_docs/trait_based_programming.rs +++ b/docs/sdk/src/reference_docs/trait_based_programming.rs @@ -7,12 +7,12 @@ //! The rest of this document assumes familiarity with the //! [Rust book's Advanced Traits](https://doc.rust-lang.org/book/ch19-03-advanced-traits.html) //! section. -//! Moreover, we use the [`frame::traits::Get`]. +//! Moreover, we use the [`polkadot_sdk_frame::traits::Get`]. //! //! First, imagine we are writing a FRAME pallet. We represent this pallet with a `struct Pallet`, //! and this pallet wants to implement the functionalities of that pallet, for example a simple //! `transfer` function. For the sake of education, we are interested in having a `MinTransfer` -//! amount, expressed as a [`frame::traits::Get`], which will dictate what is the minimum amount +//! amount, expressed as a [`polkadot_sdk_frame::traits::Get`], which will dictate what is the minimum amount //! that can be transferred. //! //! We can foremost write this as simple as the following snippet: @@ -84,7 +84,7 @@ //! having individual `trait Configs` declare a shared `trait SystemConfig` as their //! [supertrait](https://doc.rust-lang.org/rust-by-example/trait/supertraits.html). #![doc = docify::embed!("./src/reference_docs/trait_based_programming.rs", with_system)] -//! In FRAME, this shared supertrait is [`frame::prelude::frame_system`]. +//! In FRAME, this shared supertrait is [`polkadot_sdk_frame::prelude::frame_system`]. //! //! Notice how this made no difference in the syntax of the rest of the code. `T::AccountId` is //! still a valid type, since `T` implements `Config` and `Config` implies `SystemConfig`, which @@ -103,7 +103,7 @@ //! length of fully qualified syntax is a common pattern in FRAME. //! //! The above example is almost identical to the well-known (and somewhat notorious) `type -//! BalanceOf` that is often used in the context of [`frame::traits::fungible`]. +//! BalanceOf` that is often used in the context of [`polkadot_sdk_frame::traits::fungible`]. #![doc = docify::embed!("../../substrate/frame/fast-unstake/src/types.rs", BalanceOf)] //! //! ## Additional Resources @@ -113,15 +113,15 @@ //! - #![allow(unused)] -use frame::traits::Get; +use polkadot_sdk_frame::traits::Get; #[docify::export] mod basic { struct Pallet; - type AccountId = frame::deps::sp_runtime::AccountId32; + type AccountId = polkadot_sdk_frame::deps::sp_runtime::AccountId32; type Balance = u128; - type MinTransfer = frame::traits::ConstU128<10>; + type MinTransfer = polkadot_sdk_frame::traits::ConstU128<10>; impl Pallet { fn transfer(_from: AccountId, _to: AccountId, _amount: Balance) { @@ -140,8 +140,8 @@ mod generic { impl Pallet where - Balance: frame::traits::AtLeast32BitUnsigned, - MinTransfer: frame::traits::Get, + Balance: polkadot_sdk_frame::traits::AtLeast32BitUnsigned, + MinTransfer: polkadot_sdk_frame::traits::Get, AccountId: From<[u8; 32]>, { fn transfer(_from: AccountId, _to: AccountId, amount: Balance) { @@ -157,8 +157,8 @@ mod trait_based { trait Config { type AccountId: From<[u8; 32]>; - type Balance: frame::traits::AtLeast32BitUnsigned; - type MinTransfer: frame::traits::Get; + type Balance: polkadot_sdk_frame::traits::AtLeast32BitUnsigned; + type MinTransfer: polkadot_sdk_frame::traits::Get; } struct Pallet(std::marker::PhantomData); @@ -179,8 +179,8 @@ mod with_system { } pub trait Config: SystemConfig { - type Balance: frame::traits::AtLeast32BitUnsigned; - type MinTransfer: frame::traits::Get; + type Balance: polkadot_sdk_frame::traits::AtLeast32BitUnsigned; + type MinTransfer: polkadot_sdk_frame::traits::Get; } pub struct Pallet(std::marker::PhantomData); @@ -205,7 +205,7 @@ mod fully_qualified_complicated { use super::with_system::*; trait CurrencyTrait { - type Balance: frame::traits::AtLeast32BitUnsigned; + type Balance: polkadot_sdk_frame::traits::AtLeast32BitUnsigned; fn more_stuff() {} } diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index eab5f789f29a..6a8e0f9bc33f 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -140,7 +140,7 @@ //! A JSON object that provides an explicit and comprehensive representation of the //! RuntimeGenesisConfig struct, which is generated by frame::runtime::prelude::construct_runtime macro (polkadot_sdk_frame::runtime::prelude::construct_runtime macro (example of generated struct). Must contain all the keys of //! the genesis config, no defaults will be used. diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 52db7c34bfdc..ac665d4e7497 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -50,10 +50,10 @@ #![cfg(feature = "experimental")] /// Exports the main pallet macro. This can wrap a `mod pallet` and will transform it into -/// being a pallet, eg `#[frame::pallet] mod pallet { .. }`. +/// being a pallet, eg `#[polkadot_sdk_frame::pallet] mod pallet { .. }`. /// /// Note that this is not part of the prelude, in order to make it such that the common way to -/// define a macro is `#[frame::pallet] mod pallet { .. }`, followed by `#[pallet::foo]`, +/// define a macro is `#[polkadot_sdk_frame::pallet] mod pallet { .. }`, followed by `#[pallet::foo]`, /// `#[pallet::bar]` inside the mod. pub use frame_support::pallet; @@ -75,7 +75,7 @@ pub mod pallet_macros { /// This prelude should almost always be the first line of code in any pallet or runtime. /// /// ``` -/// use frame::prelude::*; +/// use polkadot_sdk_frame::prelude::*; /// /// // rest of your pallet.. /// mod pallet {} @@ -84,7 +84,7 @@ pub mod prelude { /// `frame_system`'s parent crate, which is mandatory in all pallets build with this crate. /// /// Conveniently, the keyword `frame_system` is in scope as one uses `use - /// frame::prelude::*` + /// polkadot_sdk_frame::prelude::*` #[doc(inline)] pub use frame_system; @@ -112,7 +112,7 @@ pub mod prelude { /// A test setup typically starts with: /// /// ``` -/// use frame::testing_prelude::*; +/// use polkadot_sdk_frame::testing_prelude::*; /// // rest of your test setup. /// ``` #[cfg(feature = "std")] @@ -141,7 +141,7 @@ pub mod runtime { /// A runtime typically starts with: /// /// ``` - /// use frame::{prelude::*, runtime::prelude::*}; + /// use polkadot_sdk_frame::{prelude::*, runtime::prelude::*}; /// ``` pub mod prelude { /// All of the types related to the FRAME runtime executive. @@ -186,7 +186,7 @@ pub mod runtime { /// A non-testing runtime should have this enabled, as such: /// /// ``` - /// use frame::runtime::{prelude::*, apis::{*,}}; + /// use polkadot_sdk_frame::runtime::{prelude::*, apis::{*,}}; /// ``` // TODO: This is because of wildcard imports, and it should be not needed once we can avoid // that. Imports like that are needed because we seem to need some unknown types in the macro @@ -330,8 +330,8 @@ pub mod derive { /// In most cases, hopefully the answer is yes. pub mod deps { // TODO: It would be great to somehow instruct RA to prefer *not* suggesting auto-imports from - // these. For example, we prefer `frame::derive::CloneNoBound` rather than - // `frame::deps::frame_support::CloneNoBound`. + // these. For example, we prefer `polkadot_sdk_frame::derive::CloneNoBound` rather than + // `polkadot_sdk_frame::deps::frame_support::CloneNoBound`. pub use frame_support; pub use frame_system; diff --git a/substrate/frame/support/procedural/src/pallet/parse/config.rs b/substrate/frame/support/procedural/src/pallet/parse/config.rs index fbab92db196c..a21ecbcd993a 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/config.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/config.rs @@ -275,7 +275,7 @@ fn check_event_type( } /// Check that the path to `frame_system::Config` is valid, this is that the path is just -/// `frame_system::Config` or when using the `frame` crate it is `frame::xyz::frame_system::Config`. +/// `frame_system::Config` or when using the `frame` crate it is `polkadot_sdk_frame::xyz::frame_system::Config`. fn has_expected_system_config(path: syn::Path, frame_system: &syn::Path) -> bool { // Check if `frame_system` is actually 'frame_system'. if path.segments.iter().all(|s| s.ident != "frame_system") { @@ -293,7 +293,7 @@ fn has_expected_system_config(path: syn::Path, frame_system: &syn::Path) -> bool // `frame` re-exports it as such. syn::parse2::(quote::quote!(frame_system)).expect("is a valid path; qed"), (_, _) => - // They are either both `frame_system` or both `frame::xyz::frame_system`. + // They are either both `frame_system` or both `polkadot_sdk_frame::xyz::frame_system`. frame_system.clone(), }; @@ -517,7 +517,7 @@ mod tests { #[test] fn has_expected_system_config_works_with_frame() { let frame_system = - syn::parse2::(quote::quote!(frame::deps::frame_system)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system)).unwrap(); let path = syn::parse2::(quote::quote!(frame_system::Config)).unwrap(); assert!(has_expected_system_config(path, &frame_system)); } @@ -525,36 +525,36 @@ mod tests { #[test] fn has_expected_system_config_works_with_frame_full_path() { let frame_system = - syn::parse2::(quote::quote!(frame::deps::frame_system)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system)).unwrap(); let path = - syn::parse2::(quote::quote!(frame::deps::frame_system::Config)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system::Config)).unwrap(); assert!(has_expected_system_config(path, &frame_system)); } #[test] fn has_expected_system_config_works_with_other_frame_full_path() { let frame_system = - syn::parse2::(quote::quote!(frame::xyz::frame_system)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::xyz::frame_system)).unwrap(); let path = - syn::parse2::(quote::quote!(frame::xyz::frame_system::Config)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::xyz::frame_system::Config)).unwrap(); assert!(has_expected_system_config(path, &frame_system)); } #[test] fn has_expected_system_config_does_not_works_with_mixed_frame_full_path() { let frame_system = - syn::parse2::(quote::quote!(frame::xyz::frame_system)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::xyz::frame_system)).unwrap(); let path = - syn::parse2::(quote::quote!(frame::deps::frame_system::Config)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system::Config)).unwrap(); assert!(!has_expected_system_config(path, &frame_system)); } #[test] fn has_expected_system_config_does_not_works_with_other_mixed_frame_full_path() { let frame_system = - syn::parse2::(quote::quote!(frame::deps::frame_system)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system)).unwrap(); let path = - syn::parse2::(quote::quote!(frame::xyz::frame_system::Config)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::xyz::frame_system::Config)).unwrap(); assert!(!has_expected_system_config(path, &frame_system)); } @@ -562,7 +562,7 @@ mod tests { fn has_expected_system_config_does_not_work_with_frame_full_path_if_not_frame_crate() { let frame_system = syn::parse2::(quote::quote!(frame_system)).unwrap(); let path = - syn::parse2::(quote::quote!(frame::deps::frame_system::Config)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system::Config)).unwrap(); assert!(!has_expected_system_config(path, &frame_system)); } diff --git a/substrate/frame/support/procedural/tools/src/lib.rs b/substrate/frame/support/procedural/tools/src/lib.rs index acc307f6c88d..4b6b6dc912bf 100644 --- a/substrate/frame/support/procedural/tools/src/lib.rs +++ b/substrate/frame/support/procedural/tools/src/lib.rs @@ -54,14 +54,14 @@ pub fn generate_crate_access(unique_id: &str, def_crate: &str) -> TokenStream { /// /// This will usually check the output of [`generate_access_from_frame_or_crate`]. /// We want to know if whatever the `path` takes us to, is exported from `frame` or not. In that -/// case `path` would start with `frame`, something like `frame::x::y:z`. +/// case `path` would start with `frame`, something like `polkadot_sdk_frame::x::y:z`. pub fn is_using_frame_crate(path: &syn::Path) -> bool { path.segments.first().map(|s| s.ident == "polkadot-sdk-frame").unwrap_or(false) } /// Generate the crate access for the crate using 2018 syntax. /// -/// If `frame` is in scope, it will use `frame::deps::`. Else, it will try and find +/// If `frame` is in scope, it will use `polkadot_sdk_frame::deps::`. Else, it will try and find /// `` directly. pub fn generate_access_from_frame_or_crate(def_crate: &str) -> Result { if let Some(path) = get_frame_crate_path(def_crate) { diff --git a/substrate/frame/support/test/stg_frame_crate/src/lib.rs b/substrate/frame/support/test/stg_frame_crate/src/lib.rs index aaf482d7f729..7e9b502b6207 100644 --- a/substrate/frame/support/test/stg_frame_crate/src/lib.rs +++ b/substrate/frame/support/test/stg_frame_crate/src/lib.rs @@ -31,7 +31,7 @@ pub mod pallet { #[pallet::config] // The only valid syntax here is the following or // ``` - // pub trait Config: frame::deps::frame_system::Config {} + // pub trait Config: polkadot_sdk_frame::deps::frame_system::Config {} // ``` pub trait Config: frame_system::Config {} diff --git a/substrate/frame/support/test/tests/pallet_ui/event_type_invalid_bound_no_frame_crate.rs b/substrate/frame/support/test/tests/pallet_ui/event_type_invalid_bound_no_frame_crate.rs index 573ceb6dfab7..b510beb54dda 100644 --- a/substrate/frame/support/test/tests/pallet_ui/event_type_invalid_bound_no_frame_crate.rs +++ b/substrate/frame/support/test/tests/pallet_ui/event_type_invalid_bound_no_frame_crate.rs @@ -17,13 +17,13 @@ #[frame_support::pallet] mod pallet { - use frame::deps::frame_system::pallet_prelude::BlockNumberFor; + use polkadot_sdk_frame::deps::frame_system::pallet_prelude::BlockNumberFor; use frame_support::pallet_prelude::{Hooks, IsType}; #[pallet::config] - pub trait Config: frame::deps::frame_system::Config { + pub trait Config: polkadot_sdk_frame::deps::frame_system::Config { type Bar: Clone + std::fmt::Debug + Eq; - type RuntimeEvent: IsType<::RuntimeEvent> + type RuntimeEvent: IsType<::RuntimeEvent> + From>; } diff --git a/substrate/frame/support/test/tests/pallet_ui/event_type_invalid_bound_no_frame_crate.stderr b/substrate/frame/support/test/tests/pallet_ui/event_type_invalid_bound_no_frame_crate.stderr index 0f805c972e4d..384e44d97a61 100644 --- a/substrate/frame/support/test/tests/pallet_ui/event_type_invalid_bound_no_frame_crate.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/event_type_invalid_bound_no_frame_crate.stderr @@ -1,5 +1,5 @@ error: Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must bound: `IsType<::RuntimeEvent>` --> tests/pallet_ui/event_type_invalid_bound_no_frame_crate.rs:26:3 | -26 | type RuntimeEvent: IsType<::RuntimeEvent> +26 | type RuntimeEvent: IsType<::RuntimeEvent> | ^^^^ diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs index c6ba28240167..d6ceb6f00c5d 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -48,7 +48,7 @@ use std::{ }; /// Logging target -const LOG_TARGET: &'static str = "frame::benchmark::pallet"; +const LOG_TARGET: &'static str = "polkadot_sdk_frame::benchmark::pallet"; /// The inclusive range of a component. #[derive(Serialize, Debug, Clone, Eq, PartialEq)] diff --git a/substrate/utils/frame/rpc/support/src/lib.rs b/substrate/utils/frame/rpc/support/src/lib.rs index a839bbc34021..be47691f8c87 100644 --- a/substrate/utils/frame/rpc/support/src/lib.rs +++ b/substrate/utils/frame/rpc/support/src/lib.rs @@ -161,7 +161,7 @@ impl StorageQuery { /// Send this query over RPC, await the typed result. /// - /// Hash should be `::Hash`. + /// Hash should be `::Hash`. /// /// # Arguments /// From 5a2ec92b37ce0eb8eeeb263d26b6baf84fb962fe Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:34:22 +0530 Subject: [PATCH 03/29] Adds PrDoc --- prdoc/pr_3813.prdoc | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 prdoc/pr_3813.prdoc diff --git a/prdoc/pr_3813.prdoc b/prdoc/pr_3813.prdoc new file mode 100644 index 000000000000..b67b570aca14 --- /dev/null +++ b/prdoc/pr_3813.prdoc @@ -0,0 +1,12 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Renames `frame` crate to `polkadot-sdk-frame` + +doc: + - audience: Runtime Dev + description: | + This PR renames `frame` crate to `polkadot-sdk-frame` as `frame` is not available on crates.io + +crates: + - name: polkadot-sdk-frame From 458205dabe22e7389dec0f1673ad7647db5508c2 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:37:38 +0530 Subject: [PATCH 04/29] Fmt --- docs/sdk/src/guides/your_first_pallet/mod.rs | 60 ++++++++++--------- docs/sdk/src/meta_contributing.rs | 3 +- docs/sdk/src/polkadot_sdk/cumulus.rs | 11 ++-- docs/sdk/src/polkadot_sdk/frame_runtime.rs | 25 ++++---- docs/sdk/src/polkadot_sdk/substrate.rs | 6 +- .../reference_docs/defensive_programming.rs | 21 +++---- .../src/reference_docs/extrinsic_encoding.rs | 32 +++++----- .../reference_docs/frame_offchain_workers.rs | 5 +- docs/sdk/src/reference_docs/frame_origin.rs | 14 +++-- .../reference_docs/frame_pallet_coupling.rs | 4 +- .../src/reference_docs/frame_runtime_types.rs | 10 ++-- .../reference_docs/trait_based_programming.rs | 4 +- substrate/frame/src/lib.rs | 4 +- .../procedural/src/pallet/parse/config.rs | 27 ++++++--- .../frame/support/procedural/tools/src/lib.rs | 4 +- 15 files changed, 126 insertions(+), 104 deletions(-) diff --git a/docs/sdk/src/guides/your_first_pallet/mod.rs b/docs/sdk/src/guides/your_first_pallet/mod.rs index 557caa3cac79..26ac325318fc 100644 --- a/docs/sdk/src/guides/your_first_pallet/mod.rs +++ b/docs/sdk/src/guides/your_first_pallet/mod.rs @@ -39,8 +39,8 @@ //! on this template. //! //! [`pallet::config`](polkadot_sdk_frame::pallet_macros::config) and -//! [`pallet::pallet`](polkadot_sdk_frame::pallet_macros::pallet) are both mandatory parts of any pallet. Refer -//! to the documentation of each to get an overview of what they do. +//! [`pallet::pallet`](polkadot_sdk_frame::pallet_macros::pallet) are both mandatory parts of any +//! pallet. Refer to the documentation of each to get an overview of what they do. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", shell_pallet)] //! //! ### Storage @@ -55,15 +55,16 @@ //! > generic bounded type in the `Config` trait, and then specify it in the implementation. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", Balance)] //! -//! The definition of these two storage items, based on [`polkadot_sdk_frame::pallet_macros::storage`] details, -//! is as follows: +//! The definition of these two storage items, based on +//! [`polkadot_sdk_frame::pallet_macros::storage`] details, is as follows: #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", TotalIssuance)] #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", Balances)] //! //! ### Dispatchables //! -//! Next, we will define the dispatchable functions. As per [`polkadot_sdk_frame::pallet_macros::call`], these -//! will be defined as normal `fn`s attached to `struct Pallet`. +//! Next, we will define the dispatchable functions. As per +//! [`polkadot_sdk_frame::pallet_macros::call`], these will be defined as normal `fn`s attached to +//! `struct Pallet`. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", impl_pallet)] //! //! The logic of the functions is self-explanatory. Instead, we will focus on the FRAME-related @@ -84,14 +85,16 @@ //! explained in the corresponding `type`, for example, for `Balances::::insert`, you can look //! into [`polkadot_sdk_frame::prelude::StorageMap::insert`]. //! -//! - The return type of all dispatchable functions is [`polkadot_sdk_frame::prelude::DispatchResult`]: +//! - The return type of all dispatchable functions is +//! [`polkadot_sdk_frame::prelude::DispatchResult`]: #![doc = docify::embed!("../../substrate/frame/support/src/dispatch.rs", DispatchResult)] //! -//! Which is more or less a normal Rust `Result`, with a custom [`polkadot_sdk_frame::prelude::DispatchError`] as -//! the `Err` variant. We won't cover this error in detail here, but importantly you should know -//! that there is an `impl From<&'static string> for DispatchError` provided (see -//! [here](`polkadot_sdk_frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError`)). Therefore, -//! we can use basic string literals as our error type and `.into()` them into `DispatchError`. +//! Which is more or less a normal Rust `Result`, with a custom +//! [`polkadot_sdk_frame::prelude::DispatchError`] as the `Err` variant. We won't cover this error +//! in detail here, but importantly you should know that there is an `impl From<&'static string> for +//! DispatchError` provided (see [here](`polkadot_sdk_frame::prelude::DispatchError#impl-From<%26' +//! static+str>-for-DispatchError`)). Therefore, we can use basic string literals as our error type +//! and `.into()` them into `DispatchError`. //! //! - Why are all `get` and `mutate` functions returning an `Option`? This is the default behavior //! of FRAME storage APIs. You can learn more about how to override this by looking into @@ -101,15 +104,15 @@ //! ### Improving Errors //! //! How we handle error in the above snippets is fairly rudimentary. Let's look at how this can be -//! improved. First, we can use [`polkadot_sdk_frame::prelude::ensure`] to express the error slightly better. -//! This macro will call `.into()` under the hood. +//! improved. First, we can use [`polkadot_sdk_frame::prelude::ensure`] to express the error +//! slightly better. This macro will call `.into()` under the hood. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", transfer_better)] //! //! Moreover, you will learn in the [Defensive Programming //! section](crate::reference_docs::defensive_programming) that it is always recommended to use -//! safe arithmetic operations in your runtime. By using [`polkadot_sdk_frame::traits::CheckedSub`], we can not -//! only take a step in that direction, but also improve the error handing and make it slightly more -//! ergonomic. +//! safe arithmetic operations in your runtime. By using [`polkadot_sdk_frame::traits::CheckedSub`], +//! we can not only take a step in that direction, but also improve the error handing and make it +//! slightly more ergonomic. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", transfer_better_checked)] //! //! This is more or less all the logic that there is this basic currency pallet! @@ -118,12 +121,13 @@ //! //! Next, we create a "test runtime" in order to test our pallet. Recall from //! [`crate::polkadot_sdk::frame_runtime`] that a runtime is a collection of pallets, expressed -//! through [`polkadot_sdk_frame::runtime::prelude::construct_runtime`]. All runtimes also have to include -//! [`polkadot_sdk_frame::prelude::frame_system`]. So we expect to see a runtime with two pallet, `frame_system` -//! and the one we just wrote. +//! through [`polkadot_sdk_frame::runtime::prelude::construct_runtime`]. All runtimes also have to +//! include [`polkadot_sdk_frame::prelude::frame_system`]. So we expect to see a runtime with two +//! pallet, `frame_system` and the one we just wrote. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", runtime)] //! -//! > [`polkadot_sdk_frame::pallet_macros::derive_impl`] is a FRAME feature that enables developers to have +//! > [`polkadot_sdk_frame::pallet_macros::derive_impl`] is a FRAME feature that enables developers +//! > to have //! > defaults for associated types. //! //! Recall that within our pallet, (almost) all blocks of code are generic over ``. And, @@ -156,8 +160,8 @@ //! //! The above is all you need to execute the dispatchables of your pallet. The last thing you need //! to learn is that all of your pallet testing code should be wrapped in -//! [`polkadot_sdk_frame::testing_prelude::TestState`]. This is a type that provides access to an in-memory state -//! to be used in our tests. +//! [`polkadot_sdk_frame::testing_prelude::TestState`]. This is a type that provides access to an +//! in-memory state to be used in our tests. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", first_test)] //! //! In the first test, we simply assert that there is no total issuance, and no balance associated @@ -257,9 +261,9 @@ #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", Error)] //! //! One slightly custom part of this is the [`#[pallet::generate_deposit(pub(super) fn -//! deposit_event)]`](polkadot_sdk_frame::pallet_macros::generate_deposit) part. Without going into too -//! much detail, in order for a pallet to emit events to the rest of the system, it needs to do two -//! things: +//! deposit_event)]`](polkadot_sdk_frame::pallet_macros::generate_deposit) part. Without going into +//! too much detail, in order for a pallet to emit events to the rest of the system, it needs to do +//! two things: //! //! 1. Declare a type in its `Config` that refers to the overarching event type of the runtime. In //! short, by doing this, the pallet is expressing an important bound: `type RuntimeEvent: @@ -284,8 +288,8 @@ //! //! In this snippet, the actual `RuntimeEvent` type (right hand side of `type RuntimeEvent = //! RuntimeEvent`) is generated by -//! [`construct_runtime`](polkadot_sdk_frame::runtime::prelude::construct_runtime). An interesting way to inspect -//! this type is to see its definition in rust-docs: +//! [`construct_runtime`](polkadot_sdk_frame::runtime::prelude::construct_runtime). An interesting +//! way to inspect this type is to see its definition in rust-docs: //! [`crate::guides::your_first_pallet::pallet_v2::tests::runtime_v2::RuntimeEvent`]. //! //! diff --git a/docs/sdk/src/meta_contributing.rs b/docs/sdk/src/meta_contributing.rs index f57ef9880637..a84a2ae437e8 100644 --- a/docs/sdk/src/meta_contributing.rs +++ b/docs/sdk/src/meta_contributing.rs @@ -106,7 +106,8 @@ //! * Then, what is `DispatchResult`? Why is this called *dispatch*? Probably something that can be //! explained in the documentation of [`polkadot_sdk_frame::prelude::DispatchResult`]. //! * Why is `"SomeStaticString"` a valid error? Because there is implementation for it that you can -//! see [here](polkadot_sdk_frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError). +//! see [here](polkadot_sdk_frame::prelude::DispatchError#impl-From<%26' +//! static+str>-for-DispatchError). //! //! //! All of these are examples of underlying information that a contributor should: diff --git a/docs/sdk/src/polkadot_sdk/cumulus.rs b/docs/sdk/src/polkadot_sdk/cumulus.rs index 0802658839eb..f3ee0f1fc7a2 100644 --- a/docs/sdk/src/polkadot_sdk/cumulus.rs +++ b/docs/sdk/src/polkadot_sdk/cumulus.rs @@ -32,10 +32,10 @@ //! //! //! Finally, a separate macro, similar to -//! [`impl_runtime_api`](polkadot_sdk_frame::runtime::prelude::impl_runtime_apis), which creates the default set -//! of runtime APIs, will generate the parachain runtime's validation runtime API, also known as -//! parachain validation function (PVF). Without this API, the relay chain is unable to validate -//! blocks produced by our parachain. +//! [`impl_runtime_api`](polkadot_sdk_frame::runtime::prelude::impl_runtime_apis), which creates the +//! default set of runtime APIs, will generate the parachain runtime's validation runtime API, also +//! known as parachain validation function (PVF). Without this API, the relay chain is unable to +//! validate blocks produced by our parachain. #![doc = docify::embed!("./src/polkadot_sdk/cumulus.rs", validate_block)] //! //! --- @@ -95,7 +95,8 @@ mod tests { 1, >; type WeightInfo = (); - type DmpQueue = polkadot_sdk_frame::traits::EnqueueWithOrigin<(), sp_core::ConstU8<0>>; + type DmpQueue = + polkadot_sdk_frame::traits::EnqueueWithOrigin<(), sp_core::ConstU8<0>>; } impl parachain_info::Config for Runtime {} diff --git a/docs/sdk/src/polkadot_sdk/frame_runtime.rs b/docs/sdk/src/polkadot_sdk/frame_runtime.rs index 369ed658c20e..8f13fe5587d0 100644 --- a/docs/sdk/src/polkadot_sdk/frame_runtime.rs +++ b/docs/sdk/src/polkadot_sdk/frame_runtime.rs @@ -34,16 +34,18 @@ //! about its own responsibilities and make as few assumptions about the general runtime as //! possible. A pallet is analogous to a _module_ in the runtime. //! -//! A pallet is defined as a `mod pallet` wrapped by the [`polkadot_sdk_frame::pallet`] macro. Within this macro, -//! pallet components/parts can be defined. Most notable of these parts are: -//! -//! - [Config](polkadot_sdk_frame::pallet_macros::config), allowing a pallet to make itself configurable and -//! generic over types, values and such. -//! - [Storage](polkadot_sdk_frame::pallet_macros::storage), allowing a pallet to define onchain storage. -//! - [Dispatchable function](polkadot_sdk_frame::pallet_macros::call), allowing a pallet to define extrinsics -//! that are callable by end users, from the outer world. +//! A pallet is defined as a `mod pallet` wrapped by the [`polkadot_sdk_frame::pallet`] macro. +//! Within this macro, pallet components/parts can be defined. Most notable of these parts are: +//! +//! - [Config](polkadot_sdk_frame::pallet_macros::config), allowing a pallet to make itself +//! configurable and generic over types, values and such. +//! - [Storage](polkadot_sdk_frame::pallet_macros::storage), allowing a pallet to define onchain +//! storage. +//! - [Dispatchable function](polkadot_sdk_frame::pallet_macros::call), allowing a pallet to define +//! extrinsics that are callable by end users, from the outer world. //! - [Events](polkadot_sdk_frame::pallet_macros::event), allowing a pallet to emit events. -//! - [Errors](polkadot_sdk_frame::pallet_macros::error), allowing a pallet to emit well-formed errors. +//! - [Errors](polkadot_sdk_frame::pallet_macros::error), allowing a pallet to emit well-formed +//! errors. //! //! Some of these pallet components resemble the building blocks of a smart contract. While both //! models are programming state transition functions of blockchains, there are crucial differences @@ -116,8 +118,9 @@ pub mod pallet { } /// A mandatory struct in each pallet. All functions callable by external users (aka. - /// transactions) must be attached to this type (see [`polkadot_sdk_frame::pallet_macros::call`]). For - /// convenience, internal (private) functions can also be attached to this type. + /// transactions) must be attached to this type (see + /// [`polkadot_sdk_frame::pallet_macros::call`]). For convenience, internal (private) functions + /// can also be attached to this type. #[pallet::pallet] pub struct Pallet(PhantomData); diff --git a/docs/sdk/src/polkadot_sdk/substrate.rs b/docs/sdk/src/polkadot_sdk/substrate.rs index cd9158042ab8..f6c5230c906a 100644 --- a/docs/sdk/src/polkadot_sdk/substrate.rs +++ b/docs/sdk/src/polkadot_sdk/substrate.rs @@ -111,9 +111,9 @@ //! Substrate-based project typically contains the following: //! //! * Under `./runtime`, a `./runtime/src/lib.rs` which is the top level runtime amalgamator file. -//! This file typically contains the [`polkadot_sdk_frame::runtime::prelude::construct_runtime`] and -//! [`polkadot_sdk_frame::runtime::prelude::impl_runtime_apis`] macro calls, which is the final definition of a -//! runtime. +//! This file typically contains the [`polkadot_sdk_frame::runtime::prelude::construct_runtime`] +//! and [`polkadot_sdk_frame::runtime::prelude::impl_runtime_apis`] macro calls, which is the +//! final definition of a runtime. //! //! * Under `./node`, a `main.rs`, which is the starting point, and a `./service.rs`, which contains //! all the node side components. Skimming this file yields an overview of the networking, diff --git a/docs/sdk/src/reference_docs/defensive_programming.rs b/docs/sdk/src/reference_docs/defensive_programming.rs index 004868397d00..58b9b9f3cf6a 100644 --- a/docs/sdk/src/reference_docs/defensive_programming.rs +++ b/docs/sdk/src/reference_docs/defensive_programming.rs @@ -70,18 +70,19 @@ //! //! ### Defensive Traits //! -//! The [`Defensive`](polkadot_sdk_frame::traits::Defensive) trait provides a number of functions, all of which -//! provide an alternative to 'vanilla' Rust functions, e.g.,: +//! The [`Defensive`](polkadot_sdk_frame::traits::Defensive) trait provides a number of functions, +//! all of which provide an alternative to 'vanilla' Rust functions, e.g.,: //! -//! - [`defensive_unwrap_or()`](polkadot_sdk_frame::traits::Defensive::defensive_unwrap_or) instead of -//! `unwrap_or()` -//! - [`defensive_ok_or()`](polkadot_sdk_frame::traits::DefensiveOption::defensive_ok_or) instead of `ok_or()` +//! - [`defensive_unwrap_or()`](polkadot_sdk_frame::traits::Defensive::defensive_unwrap_or) instead +//! of `unwrap_or()` +//! - [`defensive_ok_or()`](polkadot_sdk_frame::traits::DefensiveOption::defensive_ok_or) instead of +//! `ok_or()` //! //! Defensive methods use [`debug_assertions`](https://doc.rust-lang.org/reference/conditional-compilation.html#debug_assertions), which panic in development, but in //! production/release, they will merely log an error (i.e., `log::error`). //! -//! The [`Defensive`](polkadot_sdk_frame::traits::Defensive) trait and its various implementations can be found -//! [here](polkadot_sdk_frame::traits::Defensive). +//! The [`Defensive`](polkadot_sdk_frame::traits::Defensive) trait and its various implementations +//! can be found [here](polkadot_sdk_frame::traits::Defensive). //! //! ## Integer Overflow //! @@ -187,9 +188,9 @@ //! to avoid introducing the notion of any potential-panic or wrapping behavior. //! //! There is also a series of defensive alternatives via -//! [`DefensiveSaturating`](polkadot_sdk_frame::traits::DefensiveSaturating), which introduces the same behavior -//! of the [`Defensive`](polkadot_sdk_frame::traits::Defensive) trait, only with saturating, mathematical -//! operations: +//! [`DefensiveSaturating`](polkadot_sdk_frame::traits::DefensiveSaturating), which introduces the +//! same behavior of the [`Defensive`](polkadot_sdk_frame::traits::Defensive) trait, only with +//! saturating, mathematical operations: #![doc = docify::embed!( "./src/reference_docs/defensive_programming.rs", saturated_defensive_example diff --git a/docs/sdk/src/reference_docs/extrinsic_encoding.rs b/docs/sdk/src/reference_docs/extrinsic_encoding.rs index 037c86e9f2e4..c214b87b4c4d 100644 --- a/docs/sdk/src/reference_docs/extrinsic_encoding.rs +++ b/docs/sdk/src/reference_docs/extrinsic_encoding.rs @@ -36,8 +36,8 @@ //! //! ## compact_encoded_length //! -//! This is a [SCALE compact encoded][polkadot_sdk_frame::deps::codec::Compact] integer which is equal to the -//! length, in bytes, of the rest of the extrinsic details. +//! This is a [SCALE compact encoded][polkadot_sdk_frame::deps::codec::Compact] integer which is +//! equal to the length, in bytes, of the rest of the extrinsic details. //! //! To obtain this value, we must encode and concatenate together the rest of the extrinsic details //! first, and then obtain the byte length of these. We can then compact encode that length, and @@ -69,9 +69,9 @@ //! //! ### from_address //! -//! This is the [SCALE encoded][polkadot_sdk_frame::deps::codec] address of the sender of the extrinsic. The -//! address is the first generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`], and so -//! can vary from chain to chain. +//! This is the [SCALE encoded][polkadot_sdk_frame::deps::codec] address of the sender of the +//! extrinsic. The address is the first generic parameter of +//! [`sp_runtime::generic::UncheckedExtrinsic`], and so can vary from chain to chain. //! //! The address type used on the Polkadot relay chain is [`sp_runtime::MultiAddress`], //! where `AccountId32` is defined [here][`sp_core::crypto::AccountId32`]. When constructing a @@ -80,9 +80,9 @@ //! //! ### signature //! -//! This is the [SCALE encoded][polkadot_sdk_frame::deps::codec] signature. The signature type is configured via -//! the third generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`], which determines the -//! shape of the signature and signing algorithm that should be used. +//! This is the [SCALE encoded][polkadot_sdk_frame::deps::codec] signature. The signature type is +//! configured via the third generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`], which +//! determines the shape of the signature and signing algorithm that should be used. //! //! The signature is obtained by signing the _signed payload_ bytes (see below on how this is //! constructed) using the private key associated with the address and correct algorithm. @@ -92,10 +92,10 @@ //! //! ### signed_extensions_extra //! -//! This is the concatenation of the [SCALE encoded][polkadot_sdk_frame::deps::codec] bytes representing each of -//! the [_signed extensions_][sp_runtime::traits::SignedExtension], and are configured by the -//! fourth generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`]. Learn more about -//! signed extensions [here][crate::reference_docs::signed_extensions]. +//! This is the concatenation of the [SCALE encoded][polkadot_sdk_frame::deps::codec] bytes +//! representing each of the [_signed extensions_][sp_runtime::traits::SignedExtension], and are +//! configured by the fourth generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`]. Learn +//! more about signed extensions [here][crate::reference_docs::signed_extensions]. //! //! When it comes to constructing an extrinsic, each signed extension has two things that we are //! interested in here: @@ -123,10 +123,10 @@ //! altered. This is defined by the second generic parameter of //! [`sp_runtime::generic::UncheckedExtrinsic`]. //! -//! A call can be anything that implements [`Encode`][polkadot_sdk_frame::deps::codec::Encode]. In FRAME-based -//! runtimes, a call is represented as an enum of enums, where the outer enum represents the FRAME -//! pallet being called, and the inner enum represents the call being made within that pallet, and -//! any arguments to it. Read more about the call enum +//! A call can be anything that implements [`Encode`][polkadot_sdk_frame::deps::codec::Encode]. In +//! FRAME-based runtimes, a call is represented as an enum of enums, where the outer enum represents +//! the FRAME pallet being called, and the inner enum represents the call being made within that +//! pallet, and any arguments to it. Read more about the call enum //! [here][crate::reference_docs::frame_runtime_types]. //! //! FRAME `Call` enums are automatically generated, and end up looking something like this: diff --git a/docs/sdk/src/reference_docs/frame_offchain_workers.rs b/docs/sdk/src/reference_docs/frame_offchain_workers.rs index 6e4d9527e5c7..051f30ab96fb 100644 --- a/docs/sdk/src/reference_docs/frame_offchain_workers.rs +++ b/docs/sdk/src/reference_docs/frame_offchain_workers.rs @@ -96,8 +96,9 @@ //! API into the WASM blob are: //! //! * Accessing the state is easier within the `offchain_worker` function, as it is already a part -//! of the runtime, and [`polkadot_sdk_frame::pallet_macros::storage`] provides all the tools needed to read -//! the state. Other client libraries might provide varying degrees of capability here. +//! of the runtime, and [`polkadot_sdk_frame::pallet_macros::storage`] provides all the tools +//! needed to read the state. Other client libraries might provide varying degrees of capability +//! here. //! * It will be updated in synchrony with the runtime. A Substrate's offchain application is part //! of the same WASM blob, and is therefore guaranteed to be up to date. //! diff --git a/docs/sdk/src/reference_docs/frame_origin.rs b/docs/sdk/src/reference_docs/frame_origin.rs index 5b6cf1abcc9b..ad3207424180 100644 --- a/docs/sdk/src/reference_docs/frame_origin.rs +++ b/docs/sdk/src/reference_docs/frame_origin.rs @@ -93,14 +93,16 @@ //! Then, within the pallet, we can simply use this "unknown" origin check type: #![doc = docify::embed!("./src/reference_docs/frame_origin.rs", external_origin_usage)] //! -//! Finally, at the runtime, any implementation of [`polkadot_sdk_frame::traits::EnsureOrigin`] can be passed. +//! Finally, at the runtime, any implementation of [`polkadot_sdk_frame::traits::EnsureOrigin`] can +//! be passed. #![doc = docify::embed!("./src/reference_docs/frame_origin.rs", external_origin_provide)] //! -//! Indeed, some of these implementations of [`polkadot_sdk_frame::traits::EnsureOrigin`] are similar to the ones -//! that we know about: [`polkadot_sdk_frame::runtime::prelude::EnsureSigned`], -//! [`polkadot_sdk_frame::runtime::prelude::EnsureSignedBy`], [`polkadot_sdk_frame::runtime::prelude::EnsureRoot`], -//! [`polkadot_sdk_frame::runtime::prelude::EnsureNone`], etc. But, there are also many more that are not known -//! to us, and are defined in other pallets. +//! Indeed, some of these implementations of [`polkadot_sdk_frame::traits::EnsureOrigin`] are +//! similar to the ones that we know about: [`polkadot_sdk_frame::runtime::prelude::EnsureSigned`], +//! [`polkadot_sdk_frame::runtime::prelude::EnsureSignedBy`], +//! [`polkadot_sdk_frame::runtime::prelude::EnsureRoot`], +//! [`polkadot_sdk_frame::runtime::prelude::EnsureNone`], etc. But, there are also many more that +//! are not known to us, and are defined in other pallets. //! //! For example, [`pallet_collective`] defines [`pallet_collective::EnsureMember`] and //! [`pallet_collective::EnsureProportionMoreThan`] and many more, which is exactly what we alluded diff --git a/docs/sdk/src/reference_docs/frame_pallet_coupling.rs b/docs/sdk/src/reference_docs/frame_pallet_coupling.rs index 41d525656ee0..740aaddc78c3 100644 --- a/docs/sdk/src/reference_docs/frame_pallet_coupling.rs +++ b/docs/sdk/src/reference_docs/frame_pallet_coupling.rs @@ -124,8 +124,8 @@ //! that is tightly coupled with every other pallet**. This is because it provides the fundamental //! system functionality that every pallet needs, such as some types like //! [`polkadot_sdk_frame::prelude::frame_system::Config::AccountId`], -//! [`polkadot_sdk_frame::prelude::frame_system::Config::Hash`], and some functionality such as block number, -//! etc. +//! [`polkadot_sdk_frame::prelude::frame_system::Config::Hash`], and some functionality such as +//! block number, etc. //! //! ## Recap //! diff --git a/docs/sdk/src/reference_docs/frame_runtime_types.rs b/docs/sdk/src/reference_docs/frame_runtime_types.rs index dc40ad6f900f..a4561c7a1a07 100644 --- a/docs/sdk/src/reference_docs/frame_runtime_types.rs +++ b/docs/sdk/src/reference_docs/frame_runtime_types.rs @@ -80,8 +80,8 @@ //! The only way to express this using Rust's associated types is for the pallet to **define its own //! associated type `RuntimeCall`, and further specify what it thinks `RuntimeCall` should be**. //! -//! In this case, we will want to assert the existence of [`polkadot_sdk_frame::traits::IsSubType`], which is -//! very similar to [`TryFrom`]. +//! In this case, we will want to assert the existence of [`polkadot_sdk_frame::traits::IsSubType`], +//! which is very similar to [`TryFrom`]. #![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", custom_runtime_call)] //! //! And indeed, at the runtime level, this associated type would be the same `RuntimeCall` that is @@ -111,9 +111,9 @@ //! runtime is constructed? The following snippet exactly does that: #![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", assert_equality)] //! -//! We leave it to the reader to further explore what [`polkadot_sdk_frame::traits::Hooks::integrity_test`] is, -//! and what [`core::any::TypeId`] is. Another way to assert this is using -//! [`polkadot_sdk_frame::traits::IsType`]. +//! We leave it to the reader to further explore what +//! [`polkadot_sdk_frame::traits::Hooks::integrity_test`] is, and what [`core::any::TypeId`] is. +//! Another way to assert this is using [`polkadot_sdk_frame::traits::IsType`]. //! //! ## Type Aliases //! diff --git a/docs/sdk/src/reference_docs/trait_based_programming.rs b/docs/sdk/src/reference_docs/trait_based_programming.rs index 5408a8546f49..5f972180c4eb 100644 --- a/docs/sdk/src/reference_docs/trait_based_programming.rs +++ b/docs/sdk/src/reference_docs/trait_based_programming.rs @@ -12,8 +12,8 @@ //! First, imagine we are writing a FRAME pallet. We represent this pallet with a `struct Pallet`, //! and this pallet wants to implement the functionalities of that pallet, for example a simple //! `transfer` function. For the sake of education, we are interested in having a `MinTransfer` -//! amount, expressed as a [`polkadot_sdk_frame::traits::Get`], which will dictate what is the minimum amount -//! that can be transferred. +//! amount, expressed as a [`polkadot_sdk_frame::traits::Get`], which will dictate what is the +//! minimum amount that can be transferred. //! //! We can foremost write this as simple as the following snippet: #![doc = docify::embed!("./src/reference_docs/trait_based_programming.rs", basic)] diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index ac665d4e7497..cb19bb61d714 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -53,8 +53,8 @@ /// being a pallet, eg `#[polkadot_sdk_frame::pallet] mod pallet { .. }`. /// /// Note that this is not part of the prelude, in order to make it such that the common way to -/// define a macro is `#[polkadot_sdk_frame::pallet] mod pallet { .. }`, followed by `#[pallet::foo]`, -/// `#[pallet::bar]` inside the mod. +/// define a macro is `#[polkadot_sdk_frame::pallet] mod pallet { .. }`, followed by +/// `#[pallet::foo]`, `#[pallet::bar]` inside the mod. pub use frame_support::pallet; pub use frame_support::pallet_macros::{import_section, pallet_section}; diff --git a/substrate/frame/support/procedural/src/pallet/parse/config.rs b/substrate/frame/support/procedural/src/pallet/parse/config.rs index a21ecbcd993a..45618e5528bd 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/config.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/config.rs @@ -275,7 +275,8 @@ fn check_event_type( } /// Check that the path to `frame_system::Config` is valid, this is that the path is just -/// `frame_system::Config` or when using the `frame` crate it is `polkadot_sdk_frame::xyz::frame_system::Config`. +/// `frame_system::Config` or when using the `frame` crate it is +/// `polkadot_sdk_frame::xyz::frame_system::Config`. fn has_expected_system_config(path: syn::Path, frame_system: &syn::Path) -> bool { // Check if `frame_system` is actually 'frame_system'. if path.segments.iter().all(|s| s.ident != "frame_system") { @@ -517,7 +518,8 @@ mod tests { #[test] fn has_expected_system_config_works_with_frame() { let frame_system = - syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system)) + .unwrap(); let path = syn::parse2::(quote::quote!(frame_system::Config)).unwrap(); assert!(has_expected_system_config(path, &frame_system)); } @@ -525,9 +527,11 @@ mod tests { #[test] fn has_expected_system_config_works_with_frame_full_path() { let frame_system = - syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system)) + .unwrap(); let path = - syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system::Config)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system::Config)) + .unwrap(); assert!(has_expected_system_config(path, &frame_system)); } @@ -536,7 +540,8 @@ mod tests { let frame_system = syn::parse2::(quote::quote!(polkadot_sdk_frame::xyz::frame_system)).unwrap(); let path = - syn::parse2::(quote::quote!(polkadot_sdk_frame::xyz::frame_system::Config)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::xyz::frame_system::Config)) + .unwrap(); assert!(has_expected_system_config(path, &frame_system)); } @@ -545,16 +550,19 @@ mod tests { let frame_system = syn::parse2::(quote::quote!(polkadot_sdk_frame::xyz::frame_system)).unwrap(); let path = - syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system::Config)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system::Config)) + .unwrap(); assert!(!has_expected_system_config(path, &frame_system)); } #[test] fn has_expected_system_config_does_not_works_with_other_mixed_frame_full_path() { let frame_system = - syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system)) + .unwrap(); let path = - syn::parse2::(quote::quote!(polkadot_sdk_frame::xyz::frame_system::Config)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::xyz::frame_system::Config)) + .unwrap(); assert!(!has_expected_system_config(path, &frame_system)); } @@ -562,7 +570,8 @@ mod tests { fn has_expected_system_config_does_not_work_with_frame_full_path_if_not_frame_crate() { let frame_system = syn::parse2::(quote::quote!(frame_system)).unwrap(); let path = - syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system::Config)).unwrap(); + syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system::Config)) + .unwrap(); assert!(!has_expected_system_config(path, &frame_system)); } diff --git a/substrate/frame/support/procedural/tools/src/lib.rs b/substrate/frame/support/procedural/tools/src/lib.rs index 4b6b6dc912bf..805b0011ee75 100644 --- a/substrate/frame/support/procedural/tools/src/lib.rs +++ b/substrate/frame/support/procedural/tools/src/lib.rs @@ -61,8 +61,8 @@ pub fn is_using_frame_crate(path: &syn::Path) -> bool { /// Generate the crate access for the crate using 2018 syntax. /// -/// If `frame` is in scope, it will use `polkadot_sdk_frame::deps::`. Else, it will try and find -/// `` directly. +/// If `frame` is in scope, it will use `polkadot_sdk_frame::deps::`. Else, it will try +/// and find `` directly. pub fn generate_access_from_frame_or_crate(def_crate: &str) -> Result { if let Some(path) = get_frame_crate_path(def_crate) { Ok(path) From ca90b7f86333433e065492ce4384e88d6af6deb2 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:42:37 +0530 Subject: [PATCH 05/29] Fixes frame example --- substrate/frame/examples/frame-crate/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/substrate/frame/examples/frame-crate/src/lib.rs b/substrate/frame/examples/frame-crate/src/lib.rs index 32e092b3393c..c2b6788c59f0 100644 --- a/substrate/frame/examples/frame-crate/src/lib.rs +++ b/substrate/frame/examples/frame-crate/src/lib.rs @@ -22,8 +22,9 @@ pub mod pallet { use super::*; #[pallet::config] - pub trait Config: frame_system::Config { - type RuntimeEvent: IsType<::RuntimeEvent> + From>; + pub trait Config: polkadot_sdk_frame::deps::frame_system::Config { + type RuntimeEvent: IsType<::RuntimeEvent> + + From>; } #[pallet::pallet] From 550ab7087428f9218d28cbae0fed6dd5c8ec73f5 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:07:39 +0530 Subject: [PATCH 06/29] Fixes stg --- .../frame/support/test/stg_frame_crate/src/lib.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/substrate/frame/support/test/stg_frame_crate/src/lib.rs b/substrate/frame/support/test/stg_frame_crate/src/lib.rs index 7e9b502b6207..69a44a1fe517 100644 --- a/substrate/frame/support/test/stg_frame_crate/src/lib.rs +++ b/substrate/frame/support/test/stg_frame_crate/src/lib.rs @@ -18,7 +18,7 @@ // ! A basic pallet to test it compiles along with a runtime using it when `frame_system` and // `frame_support` are reexported by a `frame` crate. -use polkadot_sdk_frame::deps::{frame_support, frame_system}; +use polkadot_sdk_frame::deps::frame_support; #[frame_support::pallet] pub mod pallet { @@ -29,11 +29,7 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - // The only valid syntax here is the following or - // ``` - // pub trait Config: polkadot_sdk_frame::deps::frame_system::Config {} - // ``` - pub trait Config: frame_system::Config {} + pub trait Config: polkadot_sdk_frame::deps::frame_system::Config {} #[pallet::genesis_config] #[derive(frame_support::DefaultNoBound)] @@ -53,8 +49,9 @@ pub mod pallet { mod tests { use super::{ frame_support::{construct_runtime, derive_impl}, - frame_system, pallet, + pallet, }; + use polkadot_sdk_frame::deps::frame_system; type Block = frame_system::mocking::MockBlock; From 6c9cb60699573d595860044f30fcf404223828a7 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:32:21 +0530 Subject: [PATCH 07/29] Fixes path --- substrate/frame/examples/frame-crate/src/lib.rs | 5 ++--- substrate/frame/support/procedural/tools/src/lib.rs | 2 +- .../frame/support/test/stg_frame_crate/src/lib.rs | 11 +++++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/substrate/frame/examples/frame-crate/src/lib.rs b/substrate/frame/examples/frame-crate/src/lib.rs index c2b6788c59f0..32e092b3393c 100644 --- a/substrate/frame/examples/frame-crate/src/lib.rs +++ b/substrate/frame/examples/frame-crate/src/lib.rs @@ -22,9 +22,8 @@ pub mod pallet { use super::*; #[pallet::config] - pub trait Config: polkadot_sdk_frame::deps::frame_system::Config { - type RuntimeEvent: IsType<::RuntimeEvent> - + From>; + pub trait Config: frame_system::Config { + type RuntimeEvent: IsType<::RuntimeEvent> + From>; } #[pallet::pallet] diff --git a/substrate/frame/support/procedural/tools/src/lib.rs b/substrate/frame/support/procedural/tools/src/lib.rs index 805b0011ee75..418bdf744531 100644 --- a/substrate/frame/support/procedural/tools/src/lib.rs +++ b/substrate/frame/support/procedural/tools/src/lib.rs @@ -56,7 +56,7 @@ pub fn generate_crate_access(unique_id: &str, def_crate: &str) -> TokenStream { /// We want to know if whatever the `path` takes us to, is exported from `frame` or not. In that /// case `path` would start with `frame`, something like `polkadot_sdk_frame::x::y:z`. pub fn is_using_frame_crate(path: &syn::Path) -> bool { - path.segments.first().map(|s| s.ident == "polkadot-sdk-frame").unwrap_or(false) + path.segments.first().map(|s| s.ident == "polkadot_sdk_frame").unwrap_or(false) } /// Generate the crate access for the crate using 2018 syntax. diff --git a/substrate/frame/support/test/stg_frame_crate/src/lib.rs b/substrate/frame/support/test/stg_frame_crate/src/lib.rs index 69a44a1fe517..7e9b502b6207 100644 --- a/substrate/frame/support/test/stg_frame_crate/src/lib.rs +++ b/substrate/frame/support/test/stg_frame_crate/src/lib.rs @@ -18,7 +18,7 @@ // ! A basic pallet to test it compiles along with a runtime using it when `frame_system` and // `frame_support` are reexported by a `frame` crate. -use polkadot_sdk_frame::deps::frame_support; +use polkadot_sdk_frame::deps::{frame_support, frame_system}; #[frame_support::pallet] pub mod pallet { @@ -29,7 +29,11 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: polkadot_sdk_frame::deps::frame_system::Config {} + // The only valid syntax here is the following or + // ``` + // pub trait Config: polkadot_sdk_frame::deps::frame_system::Config {} + // ``` + pub trait Config: frame_system::Config {} #[pallet::genesis_config] #[derive(frame_support::DefaultNoBound)] @@ -49,9 +53,8 @@ pub mod pallet { mod tests { use super::{ frame_support::{construct_runtime, derive_impl}, - pallet, + frame_system, pallet, }; - use polkadot_sdk_frame::deps::frame_system; type Block = frame_system::mocking::MockBlock; From 9cc892fe09f8a6bb0b1c94396c680debdcb14f7f Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:34:25 +0530 Subject: [PATCH 08/29] Fixes template --- templates/minimal/pallets/template/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/minimal/pallets/template/src/lib.rs b/templates/minimal/pallets/template/src/lib.rs index 1e91f7bd87e8..a965f386210f 100644 --- a/templates/minimal/pallets/template/src/lib.rs +++ b/templates/minimal/pallets/template/src/lib.rs @@ -2,17 +2,17 @@ #![cfg_attr(not(feature = "std"), no_std)] -use polkadot_sdk_frame::deps::frame_support; +use polkadot_sdk_frame::prelude::*; // Re-export all pallet parts, this is needed to properly import the pallet into the runtime. pub use pallet::*; -#[frame_support::pallet] +#[polkadot_sdk_frame::pallet] pub mod pallet { use super::*; #[pallet::config] - pub trait Config: polkadot_sdk_frame::deps::frame_system::Config {} + pub trait Config: frame_system::Config {} #[pallet::pallet] pub struct Pallet(_); From 1eb6cfcdca01cc4893a793d5a37a8e1cc3f3ccc8 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:44:56 +0530 Subject: [PATCH 09/29] Updates doc links --- docs/sdk/src/polkadot_sdk/mod.rs | 10 +++++----- docs/sdk/src/polkadot_sdk/substrate.rs | 12 ++++++------ .../sdk/src/reference_docs/frame_offchain_workers.rs | 9 +++++---- docs/sdk/src/reference_docs/mod.rs | 6 +++--- .../src/reference_docs/trait_based_programming.rs | 4 ++-- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/docs/sdk/src/polkadot_sdk/mod.rs b/docs/sdk/src/polkadot_sdk/mod.rs index 124d391421b9..a393451a1928 100644 --- a/docs/sdk/src/polkadot_sdk/mod.rs +++ b/docs/sdk/src/polkadot_sdk/mod.rs @@ -22,7 +22,7 @@ //! * [`polkadot`], to understand what is Polkadot as a development platform. //! * [`substrate`], for an overview of what Substrate as the main blockchain framework of Polkadot //! SDK. -//! * [`frame`], to learn about how to write blockchain applications aka. "App Chains". +//! * [`polkadot_sdk_frame`], to learn about how to write blockchain applications aka. "App Chains". //! * Continue with the [`polkadot_sdk_docs`'s "getting started"](crate#getting-started). //! //! ## Components @@ -43,8 +43,8 @@ //! [![GitHub //! Repo](https://img.shields.io/badge/github-frame-2324CC85)](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame) //! -//! [`frame`] is the framework used to create Substrate-based application logic, aka. runtimes. -//! Learn more about the distinction of a runtime and node in +//! [`polkadot_sdk_frame`] is the framework used to create Substrate-based application logic, aka. +//! runtimes. Learn more about the distinction of a runtime and node in //! [`reference_docs::wasm_meta_protocol`]. //! //! #### Cumulus @@ -83,7 +83,7 @@ //! A Substrate-based chain is a blockchain composed of a runtime and a node. As noted above, the //! runtime is the application logic of the blockchain, and the node is everything else. //! See [`crate::reference_docs::wasm_meta_protocol`] for an in-depth explanation of this. The -//! former is built with [`frame`], and the latter is built with rest of Substrate. +//! former is built with [`polkadot_sdk_frame`], and the latter is built with rest of Substrate. //! //! > You can think of a Substrate-based chain as a white-labeled blockchain. #![doc = simple_mermaid::mermaid!("../../../mermaid/polkadot_sdk_polkadot.mmd")] @@ -111,7 +111,7 @@ //! * [Starknet's Madara Sequencer](https://github.com/keep-starknet-strange/madara) //! //! [`substrate`]: crate::polkadot_sdk::substrate -//! [`frame`]: crate::polkadot_sdk::frame_runtime +//! [`polkadot_sdk_frame`]: crate::polkadot_sdk::frame_runtime //! [`cumulus`]: crate::polkadot_sdk::cumulus //! [`polkadot`]: crate::polkadot_sdk::polkadot //! [`xcm`]: crate::polkadot_sdk::xcm diff --git a/docs/sdk/src/polkadot_sdk/substrate.rs b/docs/sdk/src/polkadot_sdk/substrate.rs index f6c5230c906a..835ba4dbe391 100644 --- a/docs/sdk/src/polkadot_sdk/substrate.rs +++ b/docs/sdk/src/polkadot_sdk/substrate.rs @@ -35,10 +35,10 @@ //! > A great analogy for substrate is the following: Substrate node is a gaming console, and a WASM //! > runtime, possibly created with FRAME is the game being inserted into the console. //! -//! [`frame`], Substrate's default runtime development library, takes the above safety practices -//! even further by embracing a declarative programming model whereby correctness is enhanced and -//! the system is highly configurable through parameterization. Learn more about this in -//! [`crate::reference_docs::trait_based_programming`]. +//! [`polkadot_sdk_frame`], Substrate's default runtime development library, takes the above safety +//! practices even further by embracing a declarative programming model whereby correctness is +//! enhanced and the system is highly configurable through parameterization. Learn more about this +//! in [`crate::reference_docs::trait_based_programming`]. //! //! ## How to Get Started //! @@ -48,7 +48,7 @@ //! [`crate::polkadot_sdk::templates`]) and only tweak the parameters of the runtime or node. This //! allows you to launch a blockchain in minutes, but is limited in technical freedom. //! * Next, most developers wish to develop their custom runtime modules, for which the de-facto way -//! is [`frame`](crate::polkadot_sdk::frame_runtime). +//! is [`polkadot_sdk_frame`](crate::polkadot_sdk::frame_runtime). //! * Finally, Substrate is highly configurable at the node side as well, but this is the most //! technically demanding. //! @@ -71,7 +71,7 @@ //! framework is using for building the runtime. Notable examples are [`sp_api`] and [`sp_io`], //! which form the communication bridge between the node and runtime. //! * `pallet-*` and `frame-*` crates, located under `./frame` folder. These are the crates related -//! to FRAME. See [`frame`] for more information. +//! to FRAME. See [`polkadot_sdk_frame`] for more information. //! //! ### WASM Build //! diff --git a/docs/sdk/src/reference_docs/frame_offchain_workers.rs b/docs/sdk/src/reference_docs/frame_offchain_workers.rs index 051f30ab96fb..30c8150e31ca 100644 --- a/docs/sdk/src/reference_docs/frame_offchain_workers.rs +++ b/docs/sdk/src/reference_docs/frame_offchain_workers.rs @@ -2,7 +2,8 @@ //! //! This reference document explains how offchain workers work in Substrate and FRAME. The main //! focus is upon FRAME's implementation of this functionality. Nonetheless, offchain workers are a -//! Substrate-provided feature and can be used with possible alternatives to [`frame`] as well. +//! Substrate-provided feature and can be used with possible alternatives to [`polkadot_sdk_frame`] +//! as well. //! //! Offchain workers are a commonly misunderstood topic, therefore we explain them bottom-up, //! starting at the fundamentals and then describing the developer interface. @@ -53,9 +54,9 @@ //! //! ## FRAME's API //! -//! [`frame`] provides a simple API through which pallets can define offchain worker functions. This -//! is part of [`polkadot_sdk_frame::traits::Hooks`], which is implemented as a part of -//! [`polkadot_sdk_frame::pallet_macros::hooks`]. +//! [`polkadot_sdk_frame`] provides a simple API through which pallets can define offchain worker +//! functions. This is part of [`polkadot_sdk_frame::traits::Hooks`], which is implemented as a part +//! of [`polkadot_sdk_frame::pallet_macros::hooks`]. //! //! ``` //! diff --git a/docs/sdk/src/reference_docs/mod.rs b/docs/sdk/src/reference_docs/mod.rs index a0d8d05b4492..5cf8887e8f43 100644 --- a/docs/sdk/src/reference_docs/mod.rs +++ b/docs/sdk/src/reference_docs/mod.rs @@ -100,9 +100,9 @@ pub mod frame_runtime_upgrades_and_migrations; pub mod light_nodes; /// Learn about the offchain workers, how they function, and how to use them, as provided by the -/// [`frame`] APIs. +/// [`polkadot_sdk_frame`] APIs. pub mod frame_offchain_workers; -/// Learn about the different ways through which multiple [`frame`] pallets can be combined to work -/// together. +/// Learn about the different ways through which multiple [`polkadot_sdk_frame`] pallets can be +/// combined to work together. pub mod frame_pallet_coupling; diff --git a/docs/sdk/src/reference_docs/trait_based_programming.rs b/docs/sdk/src/reference_docs/trait_based_programming.rs index 5f972180c4eb..5c96b25798ae 100644 --- a/docs/sdk/src/reference_docs/trait_based_programming.rs +++ b/docs/sdk/src/reference_docs/trait_based_programming.rs @@ -1,8 +1,8 @@ //! # Trait-based Programming //! //! This document walks you over a peculiar way of using Rust's `trait` items. This pattern is -//! abundantly used within [`frame`] and is therefore paramount important for a smooth transition -//! into it. +//! abundantly used within [`polkadot_sdk_frame`] and is therefore paramount important for a smooth +//! transition into it. //! //! The rest of this document assumes familiarity with the //! [Rust book's Advanced Traits](https://doc.rust-lang.org/book/ch19-03-advanced-traits.html) From 33a65908d3508424dc942b3c64a1fd4030702034 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:55:03 +0530 Subject: [PATCH 10/29] Updates doc links --- docs/sdk/src/reference_docs/glossary.rs | 4 ++-- docs/sdk/src/reference_docs/runtime_vs_smart_contract.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/sdk/src/reference_docs/glossary.rs b/docs/sdk/src/reference_docs/glossary.rs index 56f5ef5aeb58..12da0a3fb845 100644 --- a/docs/sdk/src/reference_docs/glossary.rs +++ b/docs/sdk/src/reference_docs/glossary.rs @@ -54,7 +54,7 @@ //! #### Dispatchable: //! //! Dispatchables are [function objects](https://en.wikipedia.org/wiki/Function_object) that act as -//! the entry points in [FRAME](frame) pallets. They can be called by internal or external entities +//! the entry points in [FRAME](polkadot_sdk_frame) pallets. They can be called by internal or external entities //! to interact with the blockchain's state. They are a core aspect of the runtime logic, handling //! transactions and other state-changing operations. //! @@ -68,7 +68,7 @@ //! //! #### Pallet //! -//! Similar to software modules in traditional programming, [FRAME](frame) pallets in Substrate are +//! Similar to software modules in traditional programming, [FRAME](polkadot_sdk_frame) pallets in Substrate are //! modular components that encapsulate distinct functionalities or business logic. Just as //! libraries or modules are used to build and extend the capabilities of a software application, //! pallets are the foundational building blocks for constructing a blockchain's runtime with frame. diff --git a/docs/sdk/src/reference_docs/runtime_vs_smart_contract.rs b/docs/sdk/src/reference_docs/runtime_vs_smart_contract.rs index 099512cf4ee1..06b47ef3d86d 100644 --- a/docs/sdk/src/reference_docs/runtime_vs_smart_contract.rs +++ b/docs/sdk/src/reference_docs/runtime_vs_smart_contract.rs @@ -19,7 +19,7 @@ //! //! #### Smart Contracts in Substrate //! Smart Contracts are autonomous, programmable constructs deployed on the blockchain. -//! In [FRAME](frame), Smart Contracts infrastructure is implemented by the +//! In [FRAME](polkadot_sdk_frame), Smart Contracts infrastructure is implemented by the //! [`pallet_contracts`](../../../pallet_contracts/index.html) for WASM-based contracts or the //! [`pallet_evm`](../../../pallet_evm/index.html) for EVM-compatible contracts. These pallets //! enable Smart Contract developers to build applications and systems on top of a Substrate-based From 0866b5fff9ca823465092d1c5768045ababc7cd5 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:58:27 +0530 Subject: [PATCH 11/29] Fmt --- docs/sdk/src/reference_docs/glossary.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/sdk/src/reference_docs/glossary.rs b/docs/sdk/src/reference_docs/glossary.rs index 12da0a3fb845..ae51db21821d 100644 --- a/docs/sdk/src/reference_docs/glossary.rs +++ b/docs/sdk/src/reference_docs/glossary.rs @@ -54,9 +54,9 @@ //! #### Dispatchable: //! //! Dispatchables are [function objects](https://en.wikipedia.org/wiki/Function_object) that act as -//! the entry points in [FRAME](polkadot_sdk_frame) pallets. They can be called by internal or external entities -//! to interact with the blockchain's state. They are a core aspect of the runtime logic, handling -//! transactions and other state-changing operations. +//! the entry points in [FRAME](polkadot_sdk_frame) pallets. They can be called by internal or +//! external entities to interact with the blockchain's state. They are a core aspect of the runtime +//! logic, handling transactions and other state-changing operations. //! //! **Synonyms**: Callable //! @@ -68,13 +68,14 @@ //! //! #### Pallet //! -//! Similar to software modules in traditional programming, [FRAME](polkadot_sdk_frame) pallets in Substrate are -//! modular components that encapsulate distinct functionalities or business logic. Just as -//! libraries or modules are used to build and extend the capabilities of a software application, -//! pallets are the foundational building blocks for constructing a blockchain's runtime with frame. -//! They enable the creation of customizable and upgradeable networks, offering a composable -//! framework for a Substrate-based blockchain. Each pallet can be thought of as a plug-and-play -//! module, enhancing the blockchain's functionality in a cohesive and integrated manner. +//! Similar to software modules in traditional programming, [FRAME](polkadot_sdk_frame) pallets in +//! Substrate are modular components that encapsulate distinct functionalities or business logic. +//! Just as libraries or modules are used to build and extend the capabilities of a software +//! application, pallets are the foundational building blocks for constructing a blockchain's +//! runtime with frame. They enable the creation of customizable and upgradeable networks, offering +//! a composable framework for a Substrate-based blockchain. Each pallet can be thought of as a +//! plug-and-play module, enhancing the blockchain's functionality in a cohesive and integrated +//! manner. //! //! #### Full Node //! From 42df1ac18ade8e4200d2c14a488ea7dd2cddff3a Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:47:09 +0530 Subject: [PATCH 12/29] Fixes doc link --- docs/sdk/src/guides/your_first_pallet/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/sdk/src/guides/your_first_pallet/mod.rs b/docs/sdk/src/guides/your_first_pallet/mod.rs index 26ac325318fc..e8994d0bc4ec 100644 --- a/docs/sdk/src/guides/your_first_pallet/mod.rs +++ b/docs/sdk/src/guides/your_first_pallet/mod.rs @@ -92,9 +92,10 @@ //! Which is more or less a normal Rust `Result`, with a custom //! [`polkadot_sdk_frame::prelude::DispatchError`] as the `Err` variant. We won't cover this error //! in detail here, but importantly you should know that there is an `impl From<&'static string> for -//! DispatchError` provided (see [here](`polkadot_sdk_frame::prelude::DispatchError#impl-From<%26' -//! static+str>-for-DispatchError`)). Therefore, we can use basic string literals as our error type -//! and `.into()` them into `DispatchError`. +//! DispatchError` provided (see [here]( +//! `polkadot_sdk_frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError` +//! ). Therefore, we can use basic string literals as our error type and `.into()` them into +//! `DispatchError`. //! //! - Why are all `get` and `mutate` functions returning an `Option`? This is the default behavior //! of FRAME storage APIs. You can learn more about how to override this by looking into From fd6bad2b2d33988acd2ecdd96addecd829242336 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 26 Mar 2024 12:03:31 +0530 Subject: [PATCH 13/29] Fixes doc link --- docs/sdk/src/guides/your_first_pallet/mod.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/sdk/src/guides/your_first_pallet/mod.rs b/docs/sdk/src/guides/your_first_pallet/mod.rs index e8994d0bc4ec..2c3c2b2b24cc 100644 --- a/docs/sdk/src/guides/your_first_pallet/mod.rs +++ b/docs/sdk/src/guides/your_first_pallet/mod.rs @@ -92,10 +92,8 @@ //! Which is more or less a normal Rust `Result`, with a custom //! [`polkadot_sdk_frame::prelude::DispatchError`] as the `Err` variant. We won't cover this error //! in detail here, but importantly you should know that there is an `impl From<&'static string> for -//! DispatchError` provided (see [here]( -//! `polkadot_sdk_frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError` -//! ). Therefore, we can use basic string literals as our error type and `.into()` them into -//! `DispatchError`. +//! DispatchError` provided. Therefore, we can use basic string literals as our error type and +//! `.into()` them into `DispatchError`. //! //! - Why are all `get` and `mutate` functions returning an `Option`? This is the default behavior //! of FRAME storage APIs. You can learn more about how to override this by looking into From 7bdb934e4b0d2d61e900bc23fcba774c012b0bac Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 26 Mar 2024 12:13:46 +0530 Subject: [PATCH 14/29] Fixes doc link and taplo --- docs/sdk/src/guides/your_first_pallet/mod.rs | 6 ++++-- docs/sdk/src/meta_contributing.rs | 4 ++-- polkadot/node/subsystem-bench/Cargo.toml | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/sdk/src/guides/your_first_pallet/mod.rs b/docs/sdk/src/guides/your_first_pallet/mod.rs index 2c3c2b2b24cc..e8994d0bc4ec 100644 --- a/docs/sdk/src/guides/your_first_pallet/mod.rs +++ b/docs/sdk/src/guides/your_first_pallet/mod.rs @@ -92,8 +92,10 @@ //! Which is more or less a normal Rust `Result`, with a custom //! [`polkadot_sdk_frame::prelude::DispatchError`] as the `Err` variant. We won't cover this error //! in detail here, but importantly you should know that there is an `impl From<&'static string> for -//! DispatchError` provided. Therefore, we can use basic string literals as our error type and -//! `.into()` them into `DispatchError`. +//! DispatchError` provided (see [here]( +//! `polkadot_sdk_frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError` +//! ). Therefore, we can use basic string literals as our error type and `.into()` them into +//! `DispatchError`. //! //! - Why are all `get` and `mutate` functions returning an `Option`? This is the default behavior //! of FRAME storage APIs. You can learn more about how to override this by looking into diff --git a/docs/sdk/src/meta_contributing.rs b/docs/sdk/src/meta_contributing.rs index a84a2ae437e8..74f7df1edda0 100644 --- a/docs/sdk/src/meta_contributing.rs +++ b/docs/sdk/src/meta_contributing.rs @@ -106,8 +106,8 @@ //! * Then, what is `DispatchResult`? Why is this called *dispatch*? Probably something that can be //! explained in the documentation of [`polkadot_sdk_frame::prelude::DispatchResult`]. //! * Why is `"SomeStaticString"` a valid error? Because there is implementation for it that you can -//! see [here](polkadot_sdk_frame::prelude::DispatchError#impl-From<%26' -//! static+str>-for-DispatchError). +//! see [here]( +//! `polkadot_sdk_frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError`). //! //! //! All of these are examples of underlying information that a contributor should: diff --git a/polkadot/node/subsystem-bench/Cargo.toml b/polkadot/node/subsystem-bench/Cargo.toml index 2570fe9cfa23..05907e428f92 100644 --- a/polkadot/node/subsystem-bench/Cargo.toml +++ b/polkadot/node/subsystem-bench/Cargo.toml @@ -56,7 +56,7 @@ bitvec = "1.0.1" kvdb-memorydb = "0.13.0" parity-scale-codec = { version = "3.6.1", features = ["derive", "std"] } -tokio = { version = "1.24.2", features = ["rt-multi-thread", "parking_lot"] } +tokio = { version = "1.24.2", features = ["parking_lot", "rt-multi-thread"] } clap-num = "1.0.2" polkadot-node-subsystem-test-helpers = { path = "../subsystem-test-helpers" } sp-keyring = { path = "../../../substrate/primitives/keyring" } From 2cf4e20e34a03a90352c65f39acbd29599830bbe Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:42:29 +0530 Subject: [PATCH 15/29] Adds ability to use either frame or polkadot-sdk-frame --- substrate/frame/support/procedural/tools/src/lib.rs | 4 ++-- templates/minimal/pallets/template/Cargo.toml | 4 ++-- templates/minimal/pallets/template/src/lib.rs | 6 +++--- templates/minimal/runtime/Cargo.toml | 4 ++-- templates/minimal/runtime/src/lib.rs | 8 ++++---- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/substrate/frame/support/procedural/tools/src/lib.rs b/substrate/frame/support/procedural/tools/src/lib.rs index 418bdf744531..3ed00c80b123 100644 --- a/substrate/frame/support/procedural/tools/src/lib.rs +++ b/substrate/frame/support/procedural/tools/src/lib.rs @@ -56,7 +56,7 @@ pub fn generate_crate_access(unique_id: &str, def_crate: &str) -> TokenStream { /// We want to know if whatever the `path` takes us to, is exported from `frame` or not. In that /// case `path` would start with `frame`, something like `polkadot_sdk_frame::x::y:z`. pub fn is_using_frame_crate(path: &syn::Path) -> bool { - path.segments.first().map(|s| s.ident == "polkadot_sdk_frame").unwrap_or(false) + path.segments.first().map(|s| s.ident == "polkadot_sdk_frame" || s.ident == "frame").unwrap_or(false) } /// Generate the crate access for the crate using 2018 syntax. @@ -114,7 +114,7 @@ pub fn generate_hidden_includes(unique_id: &str, def_crate: &str) -> TokenStream /// Generates the path to the frame crate deps. fn get_frame_crate_path(def_crate: &str) -> Option { // This does not work if the frame crate is renamed. - if let Ok(FoundCrate::Name(name)) = crate_name(&"polkadot-sdk-frame") { + if let Ok(FoundCrate::Name(name)) = crate_name(&"polkadot-sdk-frame").map_err(|_| crate_name(&"frame")){ let path = format!("{}::deps::{}", name, def_crate.to_string().replace("-", "_")); Some(syn::parse_str::(&path).expect("is a valid path; qed")) } else { diff --git a/templates/minimal/pallets/template/Cargo.toml b/templates/minimal/pallets/template/Cargo.toml index 82a33b359182..338084cebca4 100644 --- a/templates/minimal/pallets/template/Cargo.toml +++ b/templates/minimal/pallets/template/Cargo.toml @@ -22,7 +22,7 @@ codec = { package = "parity-scale-codec", version = "3.0.0", features = [ scale-info = { version = "2.10.0", default-features = false, features = [ "derive", ] } -polkadot-sdk-frame = { path = "../../../../substrate/frame", default-features = false, features = [ +frame = { package = "polkadot-sdk-frame", path = "../../../../substrate/frame", default-features = false, features = [ "experimental", "runtime", ] } @@ -30,4 +30,4 @@ polkadot-sdk-frame = { path = "../../../../substrate/frame", default-features = [features] default = ["std"] -std = ["codec/std", "polkadot-sdk-frame/std", "scale-info/std"] +std = ["codec/std", "frame/std", "scale-info/std"] diff --git a/templates/minimal/pallets/template/src/lib.rs b/templates/minimal/pallets/template/src/lib.rs index a965f386210f..713f014bbe61 100644 --- a/templates/minimal/pallets/template/src/lib.rs +++ b/templates/minimal/pallets/template/src/lib.rs @@ -1,13 +1,13 @@ -//! A shell pallet built with [`polkadot_sdk_frame`]. +//! A shell pallet built with [`frame`]. #![cfg_attr(not(feature = "std"), no_std)] -use polkadot_sdk_frame::prelude::*; +use frame::prelude::*; // Re-export all pallet parts, this is needed to properly import the pallet into the runtime. pub use pallet::*; -#[polkadot_sdk_frame::pallet] +#[frame::pallet] pub mod pallet { use super::*; diff --git a/templates/minimal/runtime/Cargo.toml b/templates/minimal/runtime/Cargo.toml index 8742741a03b6..5c98d5cfdde8 100644 --- a/templates/minimal/runtime/Cargo.toml +++ b/templates/minimal/runtime/Cargo.toml @@ -17,7 +17,7 @@ parity-scale-codec = { version = "3.0.0", default-features = false } scale-info = { version = "2.6.0", default-features = false } # this is a frame-based runtime, thus importing `frame` with runtime feature enabled. -polkadot-sdk-frame = { path = "../../../substrate/frame", default-features = false, features = [ +frame = { package = "polkadot-sdk-frame", path = "../../../substrate/frame", default-features = false, features = [ "experimental", "runtime", ] } @@ -44,7 +44,7 @@ std = [ "parity-scale-codec/std", "scale-info/std", - "polkadot-sdk-frame/std", + "frame/std", "pallet-balances/std", "pallet-sudo/std", diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index f8628a68ddc3..00fcaf1cec76 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -21,7 +21,7 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -use polkadot_sdk_frame::{ +use frame::{ deps::frame_support::{ genesis_builder_helper::{build_config, create_default_config}, weights::{FixedFee, NoFee}, @@ -111,7 +111,7 @@ impl pallet_transaction_payment::Config for Runtime { impl pallet_minimal_template::Config for Runtime {} -type Block = polkadot_sdk_frame::runtime::types_common::BlockOf; +type Block = frame::runtime::types_common::BlockOf; type Header = HeaderFor; type RuntimeExecutive = @@ -238,10 +238,10 @@ impl_runtime_apis! { // https://github.com/paritytech/substrate/issues/10579#issuecomment-1600537558 pub mod interface { use super::Runtime; - use polkadot_sdk_frame::deps::frame_system; + use frame::deps::frame_system; pub type Block = super::Block; - pub use polkadot_sdk_frame::runtime::types_common::OpaqueBlock; + pub use frame::runtime::types_common::OpaqueBlock; pub type AccountId = ::AccountId; pub type Nonce = ::Nonce; pub type Hash = ::Hash; From 7192bcc6c9e66d5d03b2c928b3615d6d07ab075a Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:50:32 +0530 Subject: [PATCH 16/29] Uses renamed crate in docs --- docs/sdk/Cargo.toml | 2 +- docs/sdk/src/guides/your_first_pallet/mod.rs | 77 +++++++++---------- .../guides/your_first_pallet/with_event.rs | 4 +- docs/sdk/src/meta_contributing.rs | 9 +-- docs/sdk/src/polkadot_sdk/cumulus.rs | 9 +-- docs/sdk/src/polkadot_sdk/frame_runtime.rs | 34 ++++---- docs/sdk/src/polkadot_sdk/mod.rs | 8 +- docs/sdk/src/polkadot_sdk/substrate.rs | 12 +-- .../reference_docs/defensive_programming.rs | 21 +++-- .../src/reference_docs/extrinsic_encoding.rs | 16 ++-- .../reference_docs/frame_offchain_workers.rs | 17 ++-- docs/sdk/src/reference_docs/frame_origin.rs | 26 +++---- .../reference_docs/frame_pallet_coupling.rs | 18 ++--- .../src/reference_docs/frame_runtime_types.rs | 28 +++---- .../frame_runtime_upgrades_and_migrations.rs | 2 +- docs/sdk/src/reference_docs/glossary.rs | 4 +- docs/sdk/src/reference_docs/mod.rs | 4 +- .../runtime_vs_smart_contract.rs | 2 +- .../reference_docs/trait_based_programming.rs | 30 ++++---- .../frame/support/procedural/tools/src/lib.rs | 9 ++- 20 files changed, 165 insertions(+), 167 deletions(-) diff --git a/docs/sdk/Cargo.toml b/docs/sdk/Cargo.toml index 75894bbd8b06..c3ade97dba3f 100644 --- a/docs/sdk/Cargo.toml +++ b/docs/sdk/Cargo.toml @@ -17,7 +17,7 @@ workspace = true # Needed for all FRAME-based code parity-scale-codec = { version = "3.0.0", default-features = false } scale-info = { version = "2.6.0", default-features = false } -polkadot-sdk-frame = { path = "../../substrate/frame", features = [ +frame = { package = "polkadot-sdk-frame", path = "../../substrate/frame", features = [ "experimental", "runtime", ] } diff --git a/docs/sdk/src/guides/your_first_pallet/mod.rs b/docs/sdk/src/guides/your_first_pallet/mod.rs index e8994d0bc4ec..6ccaaed884a1 100644 --- a/docs/sdk/src/guides/your_first_pallet/mod.rs +++ b/docs/sdk/src/guides/your_first_pallet/mod.rs @@ -18,12 +18,12 @@ //! //! The following FRAME topics are covered in this guide: //! -//! - [Storage](polkadot_sdk_frame::pallet_macros::storage) -//! - [Call](polkadot_sdk_frame::pallet_macros::call) -//! - [Event](polkadot_sdk_frame::pallet_macros::event) -//! - [Error](polkadot_sdk_frame::pallet_macros::error) +//! - [Storage](frame::pallet_macros::storage) +//! - [Call](frame::pallet_macros::call) +//! - [Event](frame::pallet_macros::event) +//! - [Error](frame::pallet_macros::error) //! - Basics of testing a pallet -//! - [Constructing a runtime](polkadot_sdk_frame::runtime::prelude::construct_runtime) +//! - [Constructing a runtime](frame::runtime::prelude::construct_runtime) //! //! ## Writing Your First Pallet //! @@ -38,8 +38,8 @@ //! Consider the following as a "shell pallet". We continue building the rest of this pallet based //! on this template. //! -//! [`pallet::config`](polkadot_sdk_frame::pallet_macros::config) and -//! [`pallet::pallet`](polkadot_sdk_frame::pallet_macros::pallet) are both mandatory parts of any +//! [`pallet::config`](frame::pallet_macros::config) and +//! [`pallet::pallet`](frame::pallet_macros::pallet) are both mandatory parts of any //! pallet. Refer to the documentation of each to get an overview of what they do. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", shell_pallet)] //! @@ -56,14 +56,14 @@ #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", Balance)] //! //! The definition of these two storage items, based on -//! [`polkadot_sdk_frame::pallet_macros::storage`] details, is as follows: +//! [`frame::pallet_macros::storage`] details, is as follows: #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", TotalIssuance)] #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", Balances)] //! //! ### Dispatchables //! //! Next, we will define the dispatchable functions. As per -//! [`polkadot_sdk_frame::pallet_macros::call`], these will be defined as normal `fn`s attached to +//! [`frame::pallet_macros::call`], these will be defined as normal `fn`s attached to //! `struct Pallet`. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", impl_pallet)] //! @@ -71,7 +71,7 @@ //! details: //! //! - Where do `T::AccountId` and `T::RuntimeOrigin` come from? These are both defined in -//! [`polkadot_sdk_frame::prelude::frame_system::Config`], therefore we can access them in `T`. +//! [`frame::prelude::frame_system::Config`], therefore we can access them in `T`. //! - What is `ensure_signed`, and what does it do with the aforementioned `T::RuntimeOrigin`? This //! is outside the scope of this guide, and you can learn more about it in the origin reference //! document ([`crate::reference_docs::frame_origin`]). For now, you should only know the @@ -83,35 +83,34 @@ //! //! - Where does `mutate`, `get` and `insert` and other storage APIs come from? All of them are //! explained in the corresponding `type`, for example, for `Balances::::insert`, you can look -//! into [`polkadot_sdk_frame::prelude::StorageMap::insert`]. +//! into [`frame::prelude::StorageMap::insert`]. //! -//! - The return type of all dispatchable functions is -//! [`polkadot_sdk_frame::prelude::DispatchResult`]: +//! - The return type of all dispatchable functions is [`frame::prelude::DispatchResult`]: #![doc = docify::embed!("../../substrate/frame/support/src/dispatch.rs", DispatchResult)] //! //! Which is more or less a normal Rust `Result`, with a custom -//! [`polkadot_sdk_frame::prelude::DispatchError`] as the `Err` variant. We won't cover this error +//! [`frame::prelude::DispatchError`] as the `Err` variant. We won't cover this error //! in detail here, but importantly you should know that there is an `impl From<&'static string> for //! DispatchError` provided (see [here]( -//! `polkadot_sdk_frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError` +//! `frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError` //! ). Therefore, we can use basic string literals as our error type and `.into()` them into //! `DispatchError`. //! //! - Why are all `get` and `mutate` functions returning an `Option`? This is the default behavior //! of FRAME storage APIs. You can learn more about how to override this by looking into -//! [`polkadot_sdk_frame::pallet_macros::storage`], and -//! [`polkadot_sdk_frame::prelude::ValueQuery`]/[`polkadot_sdk_frame::prelude::OptionQuery`] +//! [`frame::pallet_macros::storage`], and +//! [`frame::prelude::ValueQuery`]/[`frame::prelude::OptionQuery`] //! //! ### Improving Errors //! //! How we handle error in the above snippets is fairly rudimentary. Let's look at how this can be -//! improved. First, we can use [`polkadot_sdk_frame::prelude::ensure`] to express the error +//! improved. First, we can use [`frame::prelude::ensure`] to express the error //! slightly better. This macro will call `.into()` under the hood. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", transfer_better)] //! //! Moreover, you will learn in the [Defensive Programming //! section](crate::reference_docs::defensive_programming) that it is always recommended to use -//! safe arithmetic operations in your runtime. By using [`polkadot_sdk_frame::traits::CheckedSub`], +//! safe arithmetic operations in your runtime. By using [`frame::traits::CheckedSub`], //! we can not only take a step in that direction, but also improve the error handing and make it //! slightly more ergonomic. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", transfer_better_checked)] @@ -122,12 +121,12 @@ //! //! Next, we create a "test runtime" in order to test our pallet. Recall from //! [`crate::polkadot_sdk::frame_runtime`] that a runtime is a collection of pallets, expressed -//! through [`polkadot_sdk_frame::runtime::prelude::construct_runtime`]. All runtimes also have to -//! include [`polkadot_sdk_frame::prelude::frame_system`]. So we expect to see a runtime with two +//! through [`frame::runtime::prelude::construct_runtime`]. All runtimes also have to +//! include [`frame::prelude::frame_system`]. So we expect to see a runtime with two //! pallet, `frame_system` and the one we just wrote. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", runtime)] //! -//! > [`polkadot_sdk_frame::pallet_macros::derive_impl`] is a FRAME feature that enables developers +//! > [`frame::pallet_macros::derive_impl`] is a FRAME feature that enables developers //! > to have //! > defaults for associated types. //! @@ -161,7 +160,7 @@ //! //! The above is all you need to execute the dispatchables of your pallet. The last thing you need //! to learn is that all of your pallet testing code should be wrapped in -//! [`polkadot_sdk_frame::testing_prelude::TestState`]. This is a type that provides access to an +//! [`frame::testing_prelude::TestState`]. This is a type that provides access to an //! in-memory state to be used in our tests. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", first_test)] //! @@ -242,7 +241,7 @@ //! the drawbacks mentioned. In short, we use an enum to represent different variants of our //! error. These variants are then mapped in an efficient way (using only `u8` indices) to //! [`sp_runtime::DispatchError::Module`]. Read more about this in -//! [`polkadot_sdk_frame::pallet_macros::error`]. +//! [`frame::pallet_macros::error`]. //! //! - **Event**: Events are akin to the return type of dispatchables. They are mostly data blobs //! emitted by the runtime to let outside world know what is happening inside the pallet. Since @@ -256,13 +255,13 @@ //! //! With the explanation out of the way, let's see how these components can be added. Both follow a //! fairly familiar syntax: normal Rust enums, with extra -//! [`#[polkadot_sdk_frame::event]`](polkadot_sdk_frame::pallet_macros::event) and -//! [`#[polkadot_sdk_frame::error]`](polkadot_sdk_frame::pallet_macros::error) attributes attached. +//! [`#[frame::event]`](frame::pallet_macros::event) and +//! [`#[frame::error]`](frame::pallet_macros::error) attributes attached. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", Event)] #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", Error)] //! //! One slightly custom part of this is the [`#[pallet::generate_deposit(pub(super) fn -//! deposit_event)]`](polkadot_sdk_frame::pallet_macros::generate_deposit) part. Without going into +//! deposit_event)]`](frame::pallet_macros::generate_deposit) part. Without going into //! too much detail, in order for a pallet to emit events to the rest of the system, it needs to do //! two things: //! @@ -274,7 +273,7 @@ //! //! 2. But, doing this conversion and storing is too much to expect each pallet to define. FRAME //! provides a default way of storing events, and this is what -//! [`pallet::generate_deposit`](polkadot_sdk_frame::pallet_macros::generate_deposit) is doing. +//! [`pallet::generate_deposit`](frame::pallet_macros::generate_deposit) is doing. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", config_v2)] //! //! > These `Runtime*` types are better explained in @@ -289,7 +288,7 @@ //! //! In this snippet, the actual `RuntimeEvent` type (right hand side of `type RuntimeEvent = //! RuntimeEvent`) is generated by -//! [`construct_runtime`](polkadot_sdk_frame::runtime::prelude::construct_runtime). An interesting +//! [`construct_runtime`](frame::runtime::prelude::construct_runtime). An interesting //! way to inspect this type is to see its definition in rust-docs: //! [`crate::guides::your_first_pallet::pallet_v2::tests::runtime_v2::RuntimeEvent`]. //! @@ -303,14 +302,14 @@ //! - [`crate::reference_docs::frame_origin`]. //! - [`crate::reference_docs::frame_runtime_types`]. //! - The pallet we wrote in this guide was using `dev_mode`, learn more in -//! [`polkadot_sdk_frame::pallet_macros::config`]. +//! [`frame::pallet_macros::config`]. //! - Learn more about the individual pallet items/macros, such as event and errors and call, in -//! [`polkadot_sdk_frame::pallet_macros`]. +//! [`frame::pallet_macros`]. #[docify::export] -#[polkadot_sdk_frame::pallet(dev_mode)] +#[frame::pallet(dev_mode)] pub mod shell_pallet { - use polkadot_sdk_frame::prelude::*; + use frame::prelude::*; #[pallet::config] pub trait Config: frame_system::Config {} @@ -319,9 +318,9 @@ pub mod shell_pallet { pub struct Pallet(_); } -#[polkadot_sdk_frame::pallet(dev_mode)] +#[frame::pallet(dev_mode)] pub mod pallet { - use polkadot_sdk_frame::prelude::*; + use frame::prelude::*; #[docify::export] pub type Balance = u128; @@ -423,7 +422,7 @@ pub mod pallet { #[cfg(any(test, doc))] pub(crate) mod tests { use crate::guides::your_first_pallet::pallet::*; - use polkadot_sdk_frame::testing_prelude::*; + use frame::testing_prelude::*; const ALICE: u64 = 1; const BOB: u64 = 2; const CHARLIE: u64 = 3; @@ -638,10 +637,10 @@ pub mod pallet { } } -#[polkadot_sdk_frame::pallet(dev_mode)] +#[frame::pallet(dev_mode)] pub mod pallet_v2 { use super::pallet::Balance; - use polkadot_sdk_frame::prelude::*; + use frame::prelude::*; #[docify::export(config_v2)] #[pallet::config] @@ -706,7 +705,7 @@ pub mod pallet_v2 { #[cfg(any(test, doc))] pub mod tests { use super::{super::pallet::tests::StateBuilder, *}; - use polkadot_sdk_frame::testing_prelude::*; + use frame::testing_prelude::*; const ALICE: u64 = 1; const BOB: u64 = 2; diff --git a/docs/sdk/src/guides/your_first_pallet/with_event.rs b/docs/sdk/src/guides/your_first_pallet/with_event.rs index c3efb91dd081..a65aac324f07 100644 --- a/docs/sdk/src/guides/your_first_pallet/with_event.rs +++ b/docs/sdk/src/guides/your_first_pallet/with_event.rs @@ -1,6 +1,6 @@ -#[polkadot_sdk_frame::pallet(dev_mode)] +#[frame::pallet(dev_mode)] pub mod pallet { - use polkadot_sdk_frame::prelude::*; + use frame::prelude::*; #[docify::export] pub type Balance = u128; diff --git a/docs/sdk/src/meta_contributing.rs b/docs/sdk/src/meta_contributing.rs index 74f7df1edda0..c36bf83816db 100644 --- a/docs/sdk/src/meta_contributing.rs +++ b/docs/sdk/src/meta_contributing.rs @@ -81,9 +81,9 @@ //! //! //! ``` -//! #[polkadot_sdk_frame::pallet(dev_mode)] +//! #[frame::pallet(dev_mode)] //! pub mod pallet { -//! # use polkadot_sdk_frame::prelude::*; +//! # use frame::prelude::*; //! # #[pallet::config] //! # pub trait Config: frame_system::Config {} //! # #[pallet::pallet] @@ -104,10 +104,9 @@ //! explained in [`crate::reference_docs::frame_runtime_types`]. Build on top of this! //! * Then, what is `origin`? Just an account id? [`crate::reference_docs::frame_origin`]. //! * Then, what is `DispatchResult`? Why is this called *dispatch*? Probably something that can be -//! explained in the documentation of [`polkadot_sdk_frame::prelude::DispatchResult`]. +//! explained in the documentation of [`frame::prelude::DispatchResult`]. //! * Why is `"SomeStaticString"` a valid error? Because there is implementation for it that you can -//! see [here]( -//! `polkadot_sdk_frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError`). +//! see [here]( `frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError`). //! //! //! All of these are examples of underlying information that a contributor should: diff --git a/docs/sdk/src/polkadot_sdk/cumulus.rs b/docs/sdk/src/polkadot_sdk/cumulus.rs index f3ee0f1fc7a2..60be00116da0 100644 --- a/docs/sdk/src/polkadot_sdk/cumulus.rs +++ b/docs/sdk/src/polkadot_sdk/cumulus.rs @@ -17,7 +17,7 @@ //! A parachain runtime should use a number of pallets that are provided by Cumulus and Substrate. //! Notably: //! -//! - [`frame-system`](polkadot_sdk_frame::prelude::frame_system), like all FRAME-based runtimes. +//! - [`frame-system`](frame::prelude::frame_system), like all FRAME-based runtimes. //! - [`cumulus_pallet_parachain_system`] //! - [`parachain_info`] #![doc = docify::embed!("./src/polkadot_sdk/cumulus.rs", system_pallets)] @@ -32,7 +32,7 @@ //! //! //! Finally, a separate macro, similar to -//! [`impl_runtime_api`](polkadot_sdk_frame::runtime::prelude::impl_runtime_apis), which creates the +//! [`impl_runtime_api`](frame::runtime::prelude::impl_runtime_apis), which creates the //! default set of runtime APIs, will generate the parachain runtime's validation runtime API, also //! known as parachain validation function (PVF). Without this API, the relay chain is unable to //! validate blocks produced by our parachain. @@ -48,7 +48,7 @@ #[cfg(test)] mod tests { mod runtime { - pub use polkadot_sdk_frame::{ + pub use frame::{ deps::sp_consensus_aura::sr25519::AuthorityId as AuraId, prelude::*, runtime::prelude::*, testing_prelude::*, }; @@ -95,8 +95,7 @@ mod tests { 1, >; type WeightInfo = (); - type DmpQueue = - polkadot_sdk_frame::traits::EnqueueWithOrigin<(), sp_core::ConstU8<0>>; + type DmpQueue = frame::traits::EnqueueWithOrigin<(), sp_core::ConstU8<0>>; } impl parachain_info::Config for Runtime {} diff --git a/docs/sdk/src/polkadot_sdk/frame_runtime.rs b/docs/sdk/src/polkadot_sdk/frame_runtime.rs index 8f13fe5587d0..b13f415f860f 100644 --- a/docs/sdk/src/polkadot_sdk/frame_runtime.rs +++ b/docs/sdk/src/polkadot_sdk/frame_runtime.rs @@ -34,25 +34,23 @@ //! about its own responsibilities and make as few assumptions about the general runtime as //! possible. A pallet is analogous to a _module_ in the runtime. //! -//! A pallet is defined as a `mod pallet` wrapped by the [`polkadot_sdk_frame::pallet`] macro. +//! A pallet is defined as a `mod pallet` wrapped by the [`frame::pallet`] macro. //! Within this macro, pallet components/parts can be defined. Most notable of these parts are: //! -//! - [Config](polkadot_sdk_frame::pallet_macros::config), allowing a pallet to make itself -//! configurable and generic over types, values and such. -//! - [Storage](polkadot_sdk_frame::pallet_macros::storage), allowing a pallet to define onchain -//! storage. -//! - [Dispatchable function](polkadot_sdk_frame::pallet_macros::call), allowing a pallet to define -//! extrinsics that are callable by end users, from the outer world. -//! - [Events](polkadot_sdk_frame::pallet_macros::event), allowing a pallet to emit events. -//! - [Errors](polkadot_sdk_frame::pallet_macros::error), allowing a pallet to emit well-formed -//! errors. +//! - [Config](frame::pallet_macros::config), allowing a pallet to make itself configurable and +//! generic over types, values and such. +//! - [Storage](frame::pallet_macros::storage), allowing a pallet to define onchain storage. +//! - [Dispatchable function](frame::pallet_macros::call), allowing a pallet to define extrinsics +//! that are callable by end users, from the outer world. +//! - [Events](frame::pallet_macros::event), allowing a pallet to emit events. +//! - [Errors](frame::pallet_macros::error), allowing a pallet to emit well-formed errors. //! //! Some of these pallet components resemble the building blocks of a smart contract. While both //! models are programming state transition functions of blockchains, there are crucial differences //! between the two. See [`crate::reference_docs::runtime_vs_smart_contract`] for more. //! //! Most of these components are defined using macros, the full list of which can be found in -//! [`polkadot_sdk_frame::pallet_macros`]. +//! [`frame::pallet_macros`]. //! //! ### Example //! @@ -62,16 +60,16 @@ //! //! A runtime is a collection of pallets that are amalgamated together. Each pallet typically has //! some configurations (exposed as a `trait Config`) that needs to be *specified* in the runtime. -//! This is done with [`polkadot_sdk_frame::runtime::prelude::construct_runtime`]. +//! This is done with [`frame::runtime::prelude::construct_runtime`]. //! //! A (real) runtime that actually wishes to compile to WASM needs to also implement a set of //! runtime-apis. These implementation can be specified using the -//! [`polkadot_sdk_frame::runtime::prelude::impl_runtime_apis`] macro. +//! [`frame::runtime::prelude::impl_runtime_apis`] macro. //! //! ### Example //! //! The following example shows a (test) runtime that is composing the pallet demonstrated above, -//! next to the [`polkadot_sdk_frame::prelude::frame_system`] pallet, into a runtime. +//! next to the [`frame::prelude::frame_system`] pallet, into a runtime. #![doc = docify::embed!("src/polkadot_sdk/frame_runtime.rs", runtime)] //! //! ## More Examples @@ -89,14 +87,14 @@ //! * writing a runtime in pure Rust, as done in [this template](https://github.com/JoshOrndorff/frameless-node-template). //! * writing a runtime in AssemblyScript,as explored in [this project](https://github.com/LimeChain/subsembly). -use polkadot_sdk_frame::prelude::*; +use frame::prelude::*; /// A FRAME based pallet. This `mod` is the entry point for everything else. All /// `#[pallet::xxx]` macros must be defined in this `mod`. Although, frame also provides an /// experimental feature to break these parts into different `mod`s. See [`pallet_examples`] for /// more. #[docify::export] -#[polkadot_sdk_frame::pallet(dev_mode)] +#[frame::pallet(dev_mode)] pub mod pallet { use super::*; @@ -119,7 +117,7 @@ pub mod pallet { /// A mandatory struct in each pallet. All functions callable by external users (aka. /// transactions) must be attached to this type (see - /// [`polkadot_sdk_frame::pallet_macros::call`]). For convenience, internal (private) functions + /// [`frame::pallet_macros::call`]). For convenience, internal (private) functions /// can also be attached to this type. #[pallet::pallet] pub struct Pallet(PhantomData); @@ -154,7 +152,7 @@ pub mod pallet { #[docify::export] pub mod runtime { use super::pallet as pallet_example; - use polkadot_sdk_frame::{prelude::*, testing_prelude::*}; + use frame::{prelude::*, testing_prelude::*}; // The major macro that amalgamates pallets into `enum Runtime` construct_runtime!( diff --git a/docs/sdk/src/polkadot_sdk/mod.rs b/docs/sdk/src/polkadot_sdk/mod.rs index a393451a1928..4c9593d5ebb1 100644 --- a/docs/sdk/src/polkadot_sdk/mod.rs +++ b/docs/sdk/src/polkadot_sdk/mod.rs @@ -22,7 +22,7 @@ //! * [`polkadot`], to understand what is Polkadot as a development platform. //! * [`substrate`], for an overview of what Substrate as the main blockchain framework of Polkadot //! SDK. -//! * [`polkadot_sdk_frame`], to learn about how to write blockchain applications aka. "App Chains". +//! * [`frame`], to learn about how to write blockchain applications aka. "App Chains". //! * Continue with the [`polkadot_sdk_docs`'s "getting started"](crate#getting-started). //! //! ## Components @@ -43,7 +43,7 @@ //! [![GitHub //! Repo](https://img.shields.io/badge/github-frame-2324CC85)](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame) //! -//! [`polkadot_sdk_frame`] is the framework used to create Substrate-based application logic, aka. +//! [`frame`] is the framework used to create Substrate-based application logic, aka. //! runtimes. Learn more about the distinction of a runtime and node in //! [`reference_docs::wasm_meta_protocol`]. //! @@ -83,7 +83,7 @@ //! A Substrate-based chain is a blockchain composed of a runtime and a node. As noted above, the //! runtime is the application logic of the blockchain, and the node is everything else. //! See [`crate::reference_docs::wasm_meta_protocol`] for an in-depth explanation of this. The -//! former is built with [`polkadot_sdk_frame`], and the latter is built with rest of Substrate. +//! former is built with [`frame`], and the latter is built with rest of Substrate. //! //! > You can think of a Substrate-based chain as a white-labeled blockchain. #![doc = simple_mermaid::mermaid!("../../../mermaid/polkadot_sdk_polkadot.mmd")] @@ -111,7 +111,7 @@ //! * [Starknet's Madara Sequencer](https://github.com/keep-starknet-strange/madara) //! //! [`substrate`]: crate::polkadot_sdk::substrate -//! [`polkadot_sdk_frame`]: crate::polkadot_sdk::frame_runtime +//! [`frame`]: crate::polkadot_sdk::frame_runtime //! [`cumulus`]: crate::polkadot_sdk::cumulus //! [`polkadot`]: crate::polkadot_sdk::polkadot //! [`xcm`]: crate::polkadot_sdk::xcm diff --git a/docs/sdk/src/polkadot_sdk/substrate.rs b/docs/sdk/src/polkadot_sdk/substrate.rs index 835ba4dbe391..b96bedb5d842 100644 --- a/docs/sdk/src/polkadot_sdk/substrate.rs +++ b/docs/sdk/src/polkadot_sdk/substrate.rs @@ -35,7 +35,7 @@ //! > A great analogy for substrate is the following: Substrate node is a gaming console, and a WASM //! > runtime, possibly created with FRAME is the game being inserted into the console. //! -//! [`polkadot_sdk_frame`], Substrate's default runtime development library, takes the above safety +//! [`frame`], Substrate's default runtime development library, takes the above safety //! practices even further by embracing a declarative programming model whereby correctness is //! enhanced and the system is highly configurable through parameterization. Learn more about this //! in [`crate::reference_docs::trait_based_programming`]. @@ -48,7 +48,7 @@ //! [`crate::polkadot_sdk::templates`]) and only tweak the parameters of the runtime or node. This //! allows you to launch a blockchain in minutes, but is limited in technical freedom. //! * Next, most developers wish to develop their custom runtime modules, for which the de-facto way -//! is [`polkadot_sdk_frame`](crate::polkadot_sdk::frame_runtime). +//! is [`frame`](crate::polkadot_sdk::frame_runtime). //! * Finally, Substrate is highly configurable at the node side as well, but this is the most //! technically demanding. //! @@ -71,7 +71,7 @@ //! framework is using for building the runtime. Notable examples are [`sp_api`] and [`sp_io`], //! which form the communication bridge between the node and runtime. //! * `pallet-*` and `frame-*` crates, located under `./frame` folder. These are the crates related -//! to FRAME. See [`polkadot_sdk_frame`] for more information. +//! to FRAME. See [`frame`] for more information. //! //! ### WASM Build //! @@ -111,9 +111,9 @@ //! Substrate-based project typically contains the following: //! //! * Under `./runtime`, a `./runtime/src/lib.rs` which is the top level runtime amalgamator file. -//! This file typically contains the [`polkadot_sdk_frame::runtime::prelude::construct_runtime`] -//! and [`polkadot_sdk_frame::runtime::prelude::impl_runtime_apis`] macro calls, which is the -//! final definition of a runtime. +//! This file typically contains the [`frame::runtime::prelude::construct_runtime`] and +//! [`frame::runtime::prelude::impl_runtime_apis`] macro calls, which is the final definition of a +//! runtime. //! //! * Under `./node`, a `main.rs`, which is the starting point, and a `./service.rs`, which contains //! all the node side components. Skimming this file yields an overview of the networking, diff --git a/docs/sdk/src/reference_docs/defensive_programming.rs b/docs/sdk/src/reference_docs/defensive_programming.rs index 58b9b9f3cf6a..e4fac9a9b13c 100644 --- a/docs/sdk/src/reference_docs/defensive_programming.rs +++ b/docs/sdk/src/reference_docs/defensive_programming.rs @@ -70,19 +70,18 @@ //! //! ### Defensive Traits //! -//! The [`Defensive`](polkadot_sdk_frame::traits::Defensive) trait provides a number of functions, +//! The [`Defensive`](frame::traits::Defensive) trait provides a number of functions, //! all of which provide an alternative to 'vanilla' Rust functions, e.g.,: //! -//! - [`defensive_unwrap_or()`](polkadot_sdk_frame::traits::Defensive::defensive_unwrap_or) instead -//! of `unwrap_or()` -//! - [`defensive_ok_or()`](polkadot_sdk_frame::traits::DefensiveOption::defensive_ok_or) instead of -//! `ok_or()` +//! - [`defensive_unwrap_or()`](frame::traits::Defensive::defensive_unwrap_or) instead of +//! `unwrap_or()` +//! - [`defensive_ok_or()`](frame::traits::DefensiveOption::defensive_ok_or) instead of `ok_or()` //! //! Defensive methods use [`debug_assertions`](https://doc.rust-lang.org/reference/conditional-compilation.html#debug_assertions), which panic in development, but in //! production/release, they will merely log an error (i.e., `log::error`). //! -//! The [`Defensive`](polkadot_sdk_frame::traits::Defensive) trait and its various implementations -//! can be found [here](polkadot_sdk_frame::traits::Defensive). +//! The [`Defensive`](frame::traits::Defensive) trait and its various implementations +//! can be found [here](frame::traits::Defensive). //! //! ## Integer Overflow //! @@ -188,8 +187,8 @@ //! to avoid introducing the notion of any potential-panic or wrapping behavior. //! //! There is also a series of defensive alternatives via -//! [`DefensiveSaturating`](polkadot_sdk_frame::traits::DefensiveSaturating), which introduces the -//! same behavior of the [`Defensive`](polkadot_sdk_frame::traits::Defensive) trait, only with +//! [`DefensiveSaturating`](frame::traits::DefensiveSaturating), which introduces the +//! same behavior of the [`Defensive`](frame::traits::Defensive) trait, only with //! saturating, mathematical operations: #![doc = docify::embed!( "./src/reference_docs/defensive_programming.rs", @@ -278,7 +277,7 @@ //! actually cause harm to the network, and thus stalling would be the better option. //! //! Take the example of the BABE pallet ([`pallet_babe`]), which doesn't allow for a validator to -//! participate if it is disabled (see: [`polkadot_sdk_frame::traits::DisabledValidators`]): +//! participate if it is disabled (see: [`frame::traits::DisabledValidators`]): //! //! ```ignore //! if T::DisabledValidators::is_disabled(authority_index) { @@ -359,7 +358,7 @@ mod fake_runtime_types { #[cfg(test)] mod tests { - use polkadot_sdk_frame::traits::DefensiveSaturating; + use frame::traits::DefensiveSaturating; #[docify::export] #[test] fn checked_add_example() { diff --git a/docs/sdk/src/reference_docs/extrinsic_encoding.rs b/docs/sdk/src/reference_docs/extrinsic_encoding.rs index c214b87b4c4d..98ddb93fc88a 100644 --- a/docs/sdk/src/reference_docs/extrinsic_encoding.rs +++ b/docs/sdk/src/reference_docs/extrinsic_encoding.rs @@ -36,7 +36,7 @@ //! //! ## compact_encoded_length //! -//! This is a [SCALE compact encoded][polkadot_sdk_frame::deps::codec::Compact] integer which is +//! This is a [SCALE compact encoded][frame::deps::codec::Compact] integer which is //! equal to the length, in bytes, of the rest of the extrinsic details. //! //! To obtain this value, we must encode and concatenate together the rest of the extrinsic details @@ -69,7 +69,7 @@ //! //! ### from_address //! -//! This is the [SCALE encoded][polkadot_sdk_frame::deps::codec] address of the sender of the +//! This is the [SCALE encoded][frame::deps::codec] address of the sender of the //! extrinsic. The address is the first generic parameter of //! [`sp_runtime::generic::UncheckedExtrinsic`], and so can vary from chain to chain. //! @@ -80,7 +80,7 @@ //! //! ### signature //! -//! This is the [SCALE encoded][polkadot_sdk_frame::deps::codec] signature. The signature type is +//! This is the [SCALE encoded][frame::deps::codec] signature. The signature type is //! configured via the third generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`], which //! determines the shape of the signature and signing algorithm that should be used. //! @@ -92,7 +92,7 @@ //! //! ### signed_extensions_extra //! -//! This is the concatenation of the [SCALE encoded][polkadot_sdk_frame::deps::codec] bytes +//! This is the concatenation of the [SCALE encoded][frame::deps::codec] bytes //! representing each of the [_signed extensions_][sp_runtime::traits::SignedExtension], and are //! configured by the fourth generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`]. Learn //! more about signed extensions [here][crate::reference_docs::signed_extensions]. @@ -111,11 +111,11 @@ //! At the time of writing, Polkadot configures them //! [here](https://github.com/polkadot-fellows/runtimes/blob/1dc04eb954eadf8aadb5d83990b89662dbb5a074/relay/polkadot/src/lib.rs#L1432C25-L1432C25). //! Some of the common signed extensions are defined -//! [here][polkadot_sdk_frame::deps::frame_system#signed-extensions]. +//! [here][frame::deps::frame_system#signed-extensions]. //! //! Information about exactly which signed extensions are present on a chain and in what order is //! also a part of the metadata for the chain. For V15 metadata, it can be -//! [found here][polkadot_sdk_frame::deps::frame_support::__private::metadata::v15::ExtrinsicMetadata]. +//! [found here][frame::deps::frame_support::__private::metadata::v15::ExtrinsicMetadata]. //! //! ## call_data //! @@ -123,7 +123,7 @@ //! altered. This is defined by the second generic parameter of //! [`sp_runtime::generic::UncheckedExtrinsic`]. //! -//! A call can be anything that implements [`Encode`][polkadot_sdk_frame::deps::codec::Encode]. In +//! A call can be anything that implements [`Encode`][frame::deps::codec::Encode]. In //! FRAME-based runtimes, a call is represented as an enum of enums, where the outer enum represents //! the FRAME pallet being called, and the inner enum represents the call being made within that //! pallet, and any arguments to it. Read more about the call enum @@ -152,7 +152,7 @@ //! Information about the pallets that exist for a chain (including their indexes), the calls //! available in each pallet (including their indexes), and the arguments required for each call //! can be found in the metadata for the chain. For V15 metadata, this information -//! [is here][polkadot_sdk_frame::deps::frame_support::__private::metadata::v15::PalletMetadata]. +//! [is here][frame::deps::frame_support::__private::metadata::v15::PalletMetadata]. //! //! # The Signed Payload Format //! diff --git a/docs/sdk/src/reference_docs/frame_offchain_workers.rs b/docs/sdk/src/reference_docs/frame_offchain_workers.rs index 30c8150e31ca..79f44c832fe9 100644 --- a/docs/sdk/src/reference_docs/frame_offchain_workers.rs +++ b/docs/sdk/src/reference_docs/frame_offchain_workers.rs @@ -2,7 +2,7 @@ //! //! This reference document explains how offchain workers work in Substrate and FRAME. The main //! focus is upon FRAME's implementation of this functionality. Nonetheless, offchain workers are a -//! Substrate-provided feature and can be used with possible alternatives to [`polkadot_sdk_frame`] +//! Substrate-provided feature and can be used with possible alternatives to [`frame`] //! as well. //! //! Offchain workers are a commonly misunderstood topic, therefore we explain them bottom-up, @@ -54,15 +54,15 @@ //! //! ## FRAME's API //! -//! [`polkadot_sdk_frame`] provides a simple API through which pallets can define offchain worker -//! functions. This is part of [`polkadot_sdk_frame::traits::Hooks`], which is implemented as a part -//! of [`polkadot_sdk_frame::pallet_macros::hooks`]. +//! [`frame`] provides a simple API through which pallets can define offchain worker +//! functions. This is part of [`frame::traits::Hooks`], which is implemented as a part +//! of [`frame::pallet_macros::hooks`]. //! //! ``` //! -//! #[polkadot_sdk_frame::pallet] +//! #[frame::pallet] //! pub mod pallet { -//! use polkadot_sdk_frame::prelude::*; +//! use frame::prelude::*; //! //! #[pallet::config] //! pub trait Config: frame_system::Config {} @@ -97,9 +97,8 @@ //! API into the WASM blob are: //! //! * Accessing the state is easier within the `offchain_worker` function, as it is already a part -//! of the runtime, and [`polkadot_sdk_frame::pallet_macros::storage`] provides all the tools -//! needed to read the state. Other client libraries might provide varying degrees of capability -//! here. +//! of the runtime, and [`frame::pallet_macros::storage`] provides all the tools needed to read +//! the state. Other client libraries might provide varying degrees of capability here. //! * It will be updated in synchrony with the runtime. A Substrate's offchain application is part //! of the same WASM blob, and is therefore guaranteed to be up to date. //! diff --git a/docs/sdk/src/reference_docs/frame_origin.rs b/docs/sdk/src/reference_docs/frame_origin.rs index ad3207424180..52d507e28c42 100644 --- a/docs/sdk/src/reference_docs/frame_origin.rs +++ b/docs/sdk/src/reference_docs/frame_origin.rs @@ -93,15 +93,15 @@ //! Then, within the pallet, we can simply use this "unknown" origin check type: #![doc = docify::embed!("./src/reference_docs/frame_origin.rs", external_origin_usage)] //! -//! Finally, at the runtime, any implementation of [`polkadot_sdk_frame::traits::EnsureOrigin`] can +//! Finally, at the runtime, any implementation of [`frame::traits::EnsureOrigin`] can //! be passed. #![doc = docify::embed!("./src/reference_docs/frame_origin.rs", external_origin_provide)] //! -//! Indeed, some of these implementations of [`polkadot_sdk_frame::traits::EnsureOrigin`] are -//! similar to the ones that we know about: [`polkadot_sdk_frame::runtime::prelude::EnsureSigned`], -//! [`polkadot_sdk_frame::runtime::prelude::EnsureSignedBy`], -//! [`polkadot_sdk_frame::runtime::prelude::EnsureRoot`], -//! [`polkadot_sdk_frame::runtime::prelude::EnsureNone`], etc. But, there are also many more that +//! Indeed, some of these implementations of [`frame::traits::EnsureOrigin`] are +//! similar to the ones that we know about: [`frame::runtime::prelude::EnsureSigned`], +//! [`frame::runtime::prelude::EnsureSignedBy`], +//! [`frame::runtime::prelude::EnsureRoot`], +//! [`frame::runtime::prelude::EnsureNone`], etc. But, there are also many more that //! are not known to us, and are defined in other pallets. //! //! For example, [`pallet_collective`] defines [`pallet_collective::EnsureMember`] and @@ -109,7 +109,7 @@ //! to earlier in this document. //! //! Make sure to check the full list of [implementors of -//! `EnsureOrigin`](polkadot_sdk_frame::traits::EnsureOrigin#implementors) for more inspiration. +//! `EnsureOrigin`](frame::traits::EnsureOrigin#implementors) for more inspiration. //! //! ## Obtaining Abstract Origins //! @@ -130,9 +130,9 @@ //! [^1]: Inherents are essentially unsigned extrinsics that need an [`frame_system::ensure_none`] //! origin check, and through the virtue of being an inherent, are agreed upon by all validators. -use polkadot_sdk_frame::prelude::*; +use frame::prelude::*; -#[polkadot_sdk_frame::pallet(dev_mode)] +#[frame::pallet(dev_mode)] pub mod pallet_for_origin { use super::*; @@ -152,7 +152,7 @@ pub mod pallet_for_origin { } } -#[polkadot_sdk_frame::pallet(dev_mode)] +#[frame::pallet(dev_mode)] pub mod pallet_with_custom_origin { use super::*; @@ -197,7 +197,7 @@ pub mod pallet_with_custom_origin { pub mod runtime_for_origin { use super::pallet_with_custom_origin; - use polkadot_sdk_frame::{runtime::prelude::*, testing_prelude::*}; + use frame::{runtime::prelude::*, testing_prelude::*}; #[docify::export(runtime_exp)] construct_runtime!( @@ -217,7 +217,7 @@ pub mod runtime_for_origin { } } -#[polkadot_sdk_frame::pallet(dev_mode)] +#[frame::pallet(dev_mode)] pub mod pallet_with_external_origin { use super::*; #[docify::export(external_origin_def)] @@ -241,7 +241,7 @@ pub mod pallet_with_external_origin { pub mod runtime_for_external_origin { use super::*; - use polkadot_sdk_frame::{runtime::prelude::*, testing_prelude::*}; + use frame::{runtime::prelude::*, testing_prelude::*}; construct_runtime!( pub struct Runtime { diff --git a/docs/sdk/src/reference_docs/frame_pallet_coupling.rs b/docs/sdk/src/reference_docs/frame_pallet_coupling.rs index 740aaddc78c3..87de2b4d2ed2 100644 --- a/docs/sdk/src/reference_docs/frame_pallet_coupling.rs +++ b/docs/sdk/src/reference_docs/frame_pallet_coupling.rs @@ -3,7 +3,7 @@ //! This reference document explains how FRAME pallets can be combined to interact together. //! //! It is suggested to re-read [`crate::polkadot_sdk::frame_runtime`], notably the information -//! around [`polkadot_sdk_frame::pallet_macros::config`]. Recall that: +//! around [`frame::pallet_macros::config`]. Recall that: //! //! > Configuration trait of a pallet: It allows a pallet to receive types at a later //! > point from the runtime that wishes to contain it. It allows the pallet to be parameterized @@ -123,8 +123,8 @@ //! With the above information in context, we can conclude that **`frame_system` is a special pallet //! that is tightly coupled with every other pallet**. This is because it provides the fundamental //! system functionality that every pallet needs, such as some types like -//! [`polkadot_sdk_frame::prelude::frame_system::Config::AccountId`], -//! [`polkadot_sdk_frame::prelude::frame_system::Config::Hash`], and some functionality such as +//! [`frame::prelude::frame_system::Config::AccountId`], +//! [`frame::prelude::frame_system::Config::Hash`], and some functionality such as //! block number, etc. //! //! ## Recap @@ -155,10 +155,10 @@ #![allow(unused)] -use polkadot_sdk_frame::prelude::*; +use frame::prelude::*; #[docify::export] -#[polkadot_sdk_frame::pallet] +#[frame::pallet] pub mod pallet_foo { use super::*; @@ -176,7 +176,7 @@ pub mod pallet_foo { } #[docify::export] -#[polkadot_sdk_frame::pallet] +#[frame::pallet] pub mod pallet_author { use super::*; @@ -193,7 +193,7 @@ pub mod pallet_author { } } -#[polkadot_sdk_frame::pallet] +#[frame::pallet] pub mod pallet_foo_tight { use super::*; @@ -221,7 +221,7 @@ pub trait AuthorProvider { fn author() -> AccountId; } -#[polkadot_sdk_frame::pallet] +#[frame::pallet] pub mod pallet_foo_loose { use super::*; @@ -270,7 +270,7 @@ impl AuthorProvider for () { pub mod runtime { use super::*; use cumulus_pallet_aura_ext::pallet; - use polkadot_sdk_frame::{runtime::prelude::*, testing_prelude::*}; + use frame::{runtime::prelude::*, testing_prelude::*}; construct_runtime!( pub struct Runtime { diff --git a/docs/sdk/src/reference_docs/frame_runtime_types.rs b/docs/sdk/src/reference_docs/frame_runtime_types.rs index a4561c7a1a07..d4a4e028c6b6 100644 --- a/docs/sdk/src/reference_docs/frame_runtime_types.rs +++ b/docs/sdk/src/reference_docs/frame_runtime_types.rs @@ -43,7 +43,7 @@ //! type in each pallet, for example [`pallet_foo::Call`]. //! //! [`RuntimeOrigin`]'s [`OriginCaller`] has two variants, one for system, and one for `pallet_foo` -//! which utilized [`polkadot_sdk_frame::pallet_macros::origin`]. +//! which utilized [`frame::pallet_macros::origin`]. //! //! Finally, [`RuntimeGenesisConfig`] is composed of `frame_system` and a variant for `pallet_bar`'s //! [`pallet_bar::GenesisConfig`]. @@ -80,7 +80,7 @@ //! The only way to express this using Rust's associated types is for the pallet to **define its own //! associated type `RuntimeCall`, and further specify what it thinks `RuntimeCall` should be**. //! -//! In this case, we will want to assert the existence of [`polkadot_sdk_frame::traits::IsSubType`], +//! In this case, we will want to assert the existence of [`frame::traits::IsSubType`], //! which is very similar to [`TryFrom`]. #![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", custom_runtime_call)] //! @@ -99,7 +99,7 @@ //! is being constructed. //! //! Now, within this pallet, this new `RuntimeCall` can be used, and it can use its new trait -//! bounds, such as being [`polkadot_sdk_frame::traits::IsSubType`]: +//! bounds, such as being [`frame::traits::IsSubType`]: #![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", custom_runtime_call_usages)] //! //! ### Asserting Equality of Multiple Runtime Composite Enums @@ -112,8 +112,8 @@ #![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", assert_equality)] //! //! We leave it to the reader to further explore what -//! [`polkadot_sdk_frame::traits::Hooks::integrity_test`] is, and what [`core::any::TypeId`] is. -//! Another way to assert this is using [`polkadot_sdk_frame::traits::IsType`]. +//! [`frame::traits::Hooks::integrity_test`] is, and what [`core::any::TypeId`] is. +//! Another way to assert this is using [`frame::traits::IsType`]. //! //! ## Type Aliases //! @@ -123,7 +123,7 @@ //! `System` //! * [`runtime::AllPalletsWithSystem`] is an alias for a tuple of all of the above. This type is //! important to FRAME internals such as `executive`, as it implements traits such as -//! [`polkadot_sdk_frame::traits::Hooks`]. +//! [`frame::traits::Hooks`]. //! //! ## Further Details //! @@ -135,7 +135,7 @@ //! * See the corresponding lecture in the [pba-book](https://polkadot-blockchain-academy.github.io/pba-book/frame/outer-enum/page.html). //! //! -//! [`construct_runtime`]: polkadot_sdk_frame::runtime::prelude::construct_runtime +//! [`construct_runtime`]: frame::runtime::prelude::construct_runtime //! [`runtime::PalletFoo`]: crate::reference_docs::frame_runtime_types::runtime::PalletFoo //! [`runtime::AllPalletsWithSystem`]: crate::reference_docs::frame_runtime_types::runtime::AllPalletsWithSystem //! [`runtime`]: crate::reference_docs::frame_runtime_types::runtime @@ -153,10 +153,10 @@ //! [`RuntimeCall`]: crate::reference_docs::frame_runtime_types::runtime::RuntimeCall //! [`RuntimeHoldReason`]: crate::reference_docs::frame_runtime_types::runtime::RuntimeHoldReason -use polkadot_sdk_frame::prelude::*; +use frame::prelude::*; #[docify::export] -#[polkadot_sdk_frame::pallet(dev_mode)] +#[frame::pallet(dev_mode)] pub mod pallet_foo { use super::*; @@ -186,7 +186,7 @@ pub mod pallet_foo { } #[docify::export] -#[polkadot_sdk_frame::pallet(dev_mode)] +#[frame::pallet(dev_mode)] pub mod pallet_bar { use super::*; @@ -217,7 +217,7 @@ pub mod pallet_bar { pub mod runtime { use super::{pallet_bar, pallet_foo}; - use polkadot_sdk_frame::{runtime::prelude::*, testing_prelude::*}; + use frame::{runtime::prelude::*, testing_prelude::*}; #[docify::export(runtime_exp)] construct_runtime!( @@ -237,10 +237,10 @@ pub mod runtime { impl pallet_bar::Config for Runtime {} } -#[polkadot_sdk_frame::pallet(dev_mode)] +#[frame::pallet(dev_mode)] pub mod pallet_with_specific_runtime_call { use super::*; - use polkadot_sdk_frame::traits::IsSubType; + use frame::traits::IsSubType; #[docify::export(custom_runtime_call)] /// A pallet that wants to further narrow down what `RuntimeCall` is. @@ -284,7 +284,7 @@ pub mod pallet_with_specific_runtime_call { pub mod runtime_with_specific_runtime_call { use super::pallet_with_specific_runtime_call; - use polkadot_sdk_frame::{runtime::prelude::*, testing_prelude::*}; + use frame::{runtime::prelude::*, testing_prelude::*}; construct_runtime!( pub struct Runtime { diff --git a/docs/sdk/src/reference_docs/frame_runtime_upgrades_and_migrations.rs b/docs/sdk/src/reference_docs/frame_runtime_upgrades_and_migrations.rs index 92ecce0e3763..7d870b432218 100644 --- a/docs/sdk/src/reference_docs/frame_runtime_upgrades_and_migrations.rs +++ b/docs/sdk/src/reference_docs/frame_runtime_upgrades_and_migrations.rs @@ -35,7 +35,7 @@ //! # Migrations //! //! It is often desirable to define logic to execute immediately after runtime upgrades (see -//! [this diagram](polkadot_sdk_frame::traits::Hooks)). +//! [this diagram](frame::traits::Hooks)). //! //! Self-contained pieces of logic that execute after a runtime upgrade are called "Migrations". //! diff --git a/docs/sdk/src/reference_docs/glossary.rs b/docs/sdk/src/reference_docs/glossary.rs index ae51db21821d..2ec6dd420ad9 100644 --- a/docs/sdk/src/reference_docs/glossary.rs +++ b/docs/sdk/src/reference_docs/glossary.rs @@ -54,7 +54,7 @@ //! #### Dispatchable: //! //! Dispatchables are [function objects](https://en.wikipedia.org/wiki/Function_object) that act as -//! the entry points in [FRAME](polkadot_sdk_frame) pallets. They can be called by internal or +//! the entry points in [FRAME](frame) pallets. They can be called by internal or //! external entities to interact with the blockchain's state. They are a core aspect of the runtime //! logic, handling transactions and other state-changing operations. //! @@ -68,7 +68,7 @@ //! //! #### Pallet //! -//! Similar to software modules in traditional programming, [FRAME](polkadot_sdk_frame) pallets in +//! Similar to software modules in traditional programming, [FRAME](frame) pallets in //! Substrate are modular components that encapsulate distinct functionalities or business logic. //! Just as libraries or modules are used to build and extend the capabilities of a software //! application, pallets are the foundational building blocks for constructing a blockchain's diff --git a/docs/sdk/src/reference_docs/mod.rs b/docs/sdk/src/reference_docs/mod.rs index 5cf8887e8f43..7695b5e6ceaf 100644 --- a/docs/sdk/src/reference_docs/mod.rs +++ b/docs/sdk/src/reference_docs/mod.rs @@ -100,9 +100,9 @@ pub mod frame_runtime_upgrades_and_migrations; pub mod light_nodes; /// Learn about the offchain workers, how they function, and how to use them, as provided by the -/// [`polkadot_sdk_frame`] APIs. +/// [`frame`] APIs. pub mod frame_offchain_workers; -/// Learn about the different ways through which multiple [`polkadot_sdk_frame`] pallets can be +/// Learn about the different ways through which multiple [`frame`] pallets can be /// combined to work together. pub mod frame_pallet_coupling; diff --git a/docs/sdk/src/reference_docs/runtime_vs_smart_contract.rs b/docs/sdk/src/reference_docs/runtime_vs_smart_contract.rs index 06b47ef3d86d..099512cf4ee1 100644 --- a/docs/sdk/src/reference_docs/runtime_vs_smart_contract.rs +++ b/docs/sdk/src/reference_docs/runtime_vs_smart_contract.rs @@ -19,7 +19,7 @@ //! //! #### Smart Contracts in Substrate //! Smart Contracts are autonomous, programmable constructs deployed on the blockchain. -//! In [FRAME](polkadot_sdk_frame), Smart Contracts infrastructure is implemented by the +//! In [FRAME](frame), Smart Contracts infrastructure is implemented by the //! [`pallet_contracts`](../../../pallet_contracts/index.html) for WASM-based contracts or the //! [`pallet_evm`](../../../pallet_evm/index.html) for EVM-compatible contracts. These pallets //! enable Smart Contract developers to build applications and systems on top of a Substrate-based diff --git a/docs/sdk/src/reference_docs/trait_based_programming.rs b/docs/sdk/src/reference_docs/trait_based_programming.rs index 5c96b25798ae..7841edd8c12f 100644 --- a/docs/sdk/src/reference_docs/trait_based_programming.rs +++ b/docs/sdk/src/reference_docs/trait_based_programming.rs @@ -1,18 +1,18 @@ //! # Trait-based Programming //! //! This document walks you over a peculiar way of using Rust's `trait` items. This pattern is -//! abundantly used within [`polkadot_sdk_frame`] and is therefore paramount important for a smooth +//! abundantly used within [`frame`] and is therefore paramount important for a smooth //! transition into it. //! //! The rest of this document assumes familiarity with the //! [Rust book's Advanced Traits](https://doc.rust-lang.org/book/ch19-03-advanced-traits.html) //! section. -//! Moreover, we use the [`polkadot_sdk_frame::traits::Get`]. +//! Moreover, we use the [`frame::traits::Get`]. //! //! First, imagine we are writing a FRAME pallet. We represent this pallet with a `struct Pallet`, //! and this pallet wants to implement the functionalities of that pallet, for example a simple //! `transfer` function. For the sake of education, we are interested in having a `MinTransfer` -//! amount, expressed as a [`polkadot_sdk_frame::traits::Get`], which will dictate what is the +//! amount, expressed as a [`frame::traits::Get`], which will dictate what is the //! minimum amount that can be transferred. //! //! We can foremost write this as simple as the following snippet: @@ -84,7 +84,7 @@ //! having individual `trait Configs` declare a shared `trait SystemConfig` as their //! [supertrait](https://doc.rust-lang.org/rust-by-example/trait/supertraits.html). #![doc = docify::embed!("./src/reference_docs/trait_based_programming.rs", with_system)] -//! In FRAME, this shared supertrait is [`polkadot_sdk_frame::prelude::frame_system`]. +//! In FRAME, this shared supertrait is [`frame::prelude::frame_system`]. //! //! Notice how this made no difference in the syntax of the rest of the code. `T::AccountId` is //! still a valid type, since `T` implements `Config` and `Config` implies `SystemConfig`, which @@ -103,7 +103,7 @@ //! length of fully qualified syntax is a common pattern in FRAME. //! //! The above example is almost identical to the well-known (and somewhat notorious) `type -//! BalanceOf` that is often used in the context of [`polkadot_sdk_frame::traits::fungible`]. +//! BalanceOf` that is often used in the context of [`frame::traits::fungible`]. #![doc = docify::embed!("../../substrate/frame/fast-unstake/src/types.rs", BalanceOf)] //! //! ## Additional Resources @@ -113,15 +113,15 @@ //! - #![allow(unused)] -use polkadot_sdk_frame::traits::Get; +use frame::traits::Get; #[docify::export] mod basic { struct Pallet; - type AccountId = polkadot_sdk_frame::deps::sp_runtime::AccountId32; + type AccountId = frame::deps::sp_runtime::AccountId32; type Balance = u128; - type MinTransfer = polkadot_sdk_frame::traits::ConstU128<10>; + type MinTransfer = frame::traits::ConstU128<10>; impl Pallet { fn transfer(_from: AccountId, _to: AccountId, _amount: Balance) { @@ -140,8 +140,8 @@ mod generic { impl Pallet where - Balance: polkadot_sdk_frame::traits::AtLeast32BitUnsigned, - MinTransfer: polkadot_sdk_frame::traits::Get, + Balance: frame::traits::AtLeast32BitUnsigned, + MinTransfer: frame::traits::Get, AccountId: From<[u8; 32]>, { fn transfer(_from: AccountId, _to: AccountId, amount: Balance) { @@ -157,8 +157,8 @@ mod trait_based { trait Config { type AccountId: From<[u8; 32]>; - type Balance: polkadot_sdk_frame::traits::AtLeast32BitUnsigned; - type MinTransfer: polkadot_sdk_frame::traits::Get; + type Balance: frame::traits::AtLeast32BitUnsigned; + type MinTransfer: frame::traits::Get; } struct Pallet(std::marker::PhantomData); @@ -179,8 +179,8 @@ mod with_system { } pub trait Config: SystemConfig { - type Balance: polkadot_sdk_frame::traits::AtLeast32BitUnsigned; - type MinTransfer: polkadot_sdk_frame::traits::Get; + type Balance: frame::traits::AtLeast32BitUnsigned; + type MinTransfer: frame::traits::Get; } pub struct Pallet(std::marker::PhantomData); @@ -205,7 +205,7 @@ mod fully_qualified_complicated { use super::with_system::*; trait CurrencyTrait { - type Balance: polkadot_sdk_frame::traits::AtLeast32BitUnsigned; + type Balance: frame::traits::AtLeast32BitUnsigned; fn more_stuff() {} } diff --git a/substrate/frame/support/procedural/tools/src/lib.rs b/substrate/frame/support/procedural/tools/src/lib.rs index 3ed00c80b123..e91d683f05f5 100644 --- a/substrate/frame/support/procedural/tools/src/lib.rs +++ b/substrate/frame/support/procedural/tools/src/lib.rs @@ -56,7 +56,10 @@ pub fn generate_crate_access(unique_id: &str, def_crate: &str) -> TokenStream { /// We want to know if whatever the `path` takes us to, is exported from `frame` or not. In that /// case `path` would start with `frame`, something like `polkadot_sdk_frame::x::y:z`. pub fn is_using_frame_crate(path: &syn::Path) -> bool { - path.segments.first().map(|s| s.ident == "polkadot_sdk_frame" || s.ident == "frame").unwrap_or(false) + path.segments + .first() + .map(|s| s.ident == "polkadot_sdk_frame" || s.ident == "frame") + .unwrap_or(false) } /// Generate the crate access for the crate using 2018 syntax. @@ -114,7 +117,9 @@ pub fn generate_hidden_includes(unique_id: &str, def_crate: &str) -> TokenStream /// Generates the path to the frame crate deps. fn get_frame_crate_path(def_crate: &str) -> Option { // This does not work if the frame crate is renamed. - if let Ok(FoundCrate::Name(name)) = crate_name(&"polkadot-sdk-frame").map_err(|_| crate_name(&"frame")){ + if let Ok(FoundCrate::Name(name)) = + crate_name(&"polkadot-sdk-frame").map_err(|_| crate_name(&"frame")) + { let path = format!("{}::deps::{}", name, def_crate.to_string().replace("-", "_")); Some(syn::parse_str::(&path).expect("is a valid path; qed")) } else { From 77912f9a6745ab491f2391ede2318ea1853f9ccd Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:53:23 +0530 Subject: [PATCH 17/29] Uses renamed crate in template --- substrate/frame/examples/frame-crate/Cargo.toml | 4 ++-- substrate/frame/support/test/stg_frame_crate/Cargo.toml | 4 ++-- substrate/primitives/api/proc-macro/src/utils.rs | 4 +++- templates/minimal/node/Cargo.toml | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/substrate/frame/examples/frame-crate/Cargo.toml b/substrate/frame/examples/frame-crate/Cargo.toml index e07b7fb9a3c4..47abaf051f20 100644 --- a/substrate/frame/examples/frame-crate/Cargo.toml +++ b/substrate/frame/examples/frame-crate/Cargo.toml @@ -19,9 +19,9 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false } scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } -polkadot-sdk-frame = { path = "../..", default-features = false, features = ["experimental", "runtime"] } +frame = { package = "polkadot-sdk-frame", path = "../..", default-features = false, features = ["experimental", "runtime"] } [features] default = ["std"] -std = ["codec/std", "polkadot-sdk-frame/std", "scale-info/std"] +std = ["codec/std", "frame/std", "scale-info/std"] diff --git a/substrate/frame/support/test/stg_frame_crate/Cargo.toml b/substrate/frame/support/test/stg_frame_crate/Cargo.toml index 45953187ff5c..5a77b6df20c1 100644 --- a/substrate/frame/support/test/stg_frame_crate/Cargo.toml +++ b/substrate/frame/support/test/stg_frame_crate/Cargo.toml @@ -16,9 +16,9 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] } -polkadot-sdk-frame = { path = "../../..", default-features = false, features = ["experimental", "runtime"] } +frame = { package = "polkadot-sdk-frame", path = "../../..", default-features = false, features = ["experimental", "runtime"] } scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } [features] default = ["std"] -std = ["codec/std", "polkadot-sdk-frame/std", "scale-info/std"] +std = ["codec/std", "frame/std", "scale-info/std"] diff --git a/substrate/primitives/api/proc-macro/src/utils.rs b/substrate/primitives/api/proc-macro/src/utils.rs index b031f3ed42af..945c5c026ed8 100644 --- a/substrate/primitives/api/proc-macro/src/utils.rs +++ b/substrate/primitives/api/proc-macro/src/utils.rs @@ -34,7 +34,9 @@ pub fn generate_crate_access() -> TokenStream { quote!(#renamed_name::__private) }, Err(e) => - if let Ok(FoundCrate::Name(name)) = crate_name(&"polkadot-sdk-frame") { + if let Ok(FoundCrate::Name(name)) = + crate_name(&"polkadot-sdk-frame").map_err(|_| crate_name(&"frame")) + { let path = format!("{}::deps::sp_api::__private", name); let path = syn::parse_str::(&path).expect("is a valid path; qed"); quote!( #path ) diff --git a/templates/minimal/node/Cargo.toml b/templates/minimal/node/Cargo.toml index 417a138eaca5..6ab7092d87e6 100644 --- a/templates/minimal/node/Cargo.toml +++ b/templates/minimal/node/Cargo.toml @@ -49,7 +49,7 @@ substrate-frame-rpc-system = { path = "../../../substrate/utils/frame/rpc/system # Once the native runtime is gone, there should be little to no dependency on FRAME here, and # certainly no dependency on the runtime. -polkadot-sdk-frame = { path = "../../../substrate/frame", features = [ +frame = { package = "polkadot-sdk-frame", path = "../../../substrate/frame", features = [ "experimental", "runtime", ] } From ba183b31f1a64fc899e3e5958090f422ba138133 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:54:47 +0530 Subject: [PATCH 18/29] Removes changes in docs --- docs/sdk/src/guides/your_first_pallet/mod.rs | 58 +++++++++---------- docs/sdk/src/meta_contributing.rs | 2 +- docs/sdk/src/polkadot_sdk/cumulus.rs | 8 +-- docs/sdk/src/polkadot_sdk/frame_runtime.rs | 9 ++- docs/sdk/src/polkadot_sdk/mod.rs | 4 +- docs/sdk/src/polkadot_sdk/substrate.rs | 8 +-- .../reference_docs/defensive_programming.rs | 14 ++--- .../src/reference_docs/extrinsic_encoding.rs | 32 +++++----- .../reference_docs/frame_offchain_workers.rs | 9 ++- docs/sdk/src/reference_docs/frame_origin.rs | 14 ++--- .../reference_docs/frame_pallet_coupling.rs | 4 +- .../src/reference_docs/frame_runtime_types.rs | 10 ++-- docs/sdk/src/reference_docs/glossary.rs | 21 ++++--- docs/sdk/src/reference_docs/mod.rs | 4 +- .../reference_docs/trait_based_programming.rs | 8 +-- 15 files changed, 98 insertions(+), 107 deletions(-) diff --git a/docs/sdk/src/guides/your_first_pallet/mod.rs b/docs/sdk/src/guides/your_first_pallet/mod.rs index 6ccaaed884a1..c6e0dd0edf89 100644 --- a/docs/sdk/src/guides/your_first_pallet/mod.rs +++ b/docs/sdk/src/guides/your_first_pallet/mod.rs @@ -39,8 +39,8 @@ //! on this template. //! //! [`pallet::config`](frame::pallet_macros::config) and -//! [`pallet::pallet`](frame::pallet_macros::pallet) are both mandatory parts of any -//! pallet. Refer to the documentation of each to get an overview of what they do. +//! [`pallet::pallet`](frame::pallet_macros::pallet) are both mandatory parts of any pallet. Refer +//! to the documentation of each to get an overview of what they do. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", shell_pallet)] //! //! ### Storage @@ -55,16 +55,15 @@ //! > generic bounded type in the `Config` trait, and then specify it in the implementation. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", Balance)] //! -//! The definition of these two storage items, based on -//! [`frame::pallet_macros::storage`] details, is as follows: +//! The definition of these two storage items, based on [`frame::pallet_macros::storage`] details, +//! is as follows: #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", TotalIssuance)] #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", Balances)] //! //! ### Dispatchables //! -//! Next, we will define the dispatchable functions. As per -//! [`frame::pallet_macros::call`], these will be defined as normal `fn`s attached to -//! `struct Pallet`. +//! Next, we will define the dispatchable functions. As per [`frame::pallet_macros::call`], these +//! will be defined as normal `fn`s attached to `struct Pallet`. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", impl_pallet)] //! //! The logic of the functions is self-explanatory. Instead, we will focus on the FRAME-related @@ -88,13 +87,11 @@ //! - The return type of all dispatchable functions is [`frame::prelude::DispatchResult`]: #![doc = docify::embed!("../../substrate/frame/support/src/dispatch.rs", DispatchResult)] //! -//! Which is more or less a normal Rust `Result`, with a custom -//! [`frame::prelude::DispatchError`] as the `Err` variant. We won't cover this error -//! in detail here, but importantly you should know that there is an `impl From<&'static string> for -//! DispatchError` provided (see [here]( -//! `frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError` -//! ). Therefore, we can use basic string literals as our error type and `.into()` them into -//! `DispatchError`. +//! Which is more or less a normal Rust `Result`, with a custom [`frame::prelude::DispatchError`] as +//! the `Err` variant. We won't cover this error in detail here, but importantly you should know +//! that there is an `impl From<&'static string> for DispatchError` provided (see +//! [here](`frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError`)). Therefore, +//! we can use basic string literals as our error type and `.into()` them into `DispatchError`. //! //! - Why are all `get` and `mutate` functions returning an `Option`? This is the default behavior //! of FRAME storage APIs. You can learn more about how to override this by looking into @@ -104,15 +101,15 @@ //! ### Improving Errors //! //! How we handle error in the above snippets is fairly rudimentary. Let's look at how this can be -//! improved. First, we can use [`frame::prelude::ensure`] to express the error -//! slightly better. This macro will call `.into()` under the hood. +//! improved. First, we can use [`frame::prelude::ensure`] to express the error slightly better. +//! This macro will call `.into()` under the hood. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", transfer_better)] //! //! Moreover, you will learn in the [Defensive Programming //! section](crate::reference_docs::defensive_programming) that it is always recommended to use -//! safe arithmetic operations in your runtime. By using [`frame::traits::CheckedSub`], -//! we can not only take a step in that direction, but also improve the error handing and make it -//! slightly more ergonomic. +//! safe arithmetic operations in your runtime. By using [`frame::traits::CheckedSub`], we can not +//! only take a step in that direction, but also improve the error handing and make it slightly more +//! ergonomic. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", transfer_better_checked)] //! //! This is more or less all the logic that there is this basic currency pallet! @@ -121,13 +118,12 @@ //! //! Next, we create a "test runtime" in order to test our pallet. Recall from //! [`crate::polkadot_sdk::frame_runtime`] that a runtime is a collection of pallets, expressed -//! through [`frame::runtime::prelude::construct_runtime`]. All runtimes also have to -//! include [`frame::prelude::frame_system`]. So we expect to see a runtime with two -//! pallet, `frame_system` and the one we just wrote. +//! through [`frame::runtime::prelude::construct_runtime`]. All runtimes also have to include +//! [`frame::prelude::frame_system`]. So we expect to see a runtime with two pallet, `frame_system` +//! and the one we just wrote. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", runtime)] //! -//! > [`frame::pallet_macros::derive_impl`] is a FRAME feature that enables developers -//! > to have +//! > [`frame::pallet_macros::derive_impl`] is a FRAME feature that enables developers to have //! > defaults for associated types. //! //! Recall that within our pallet, (almost) all blocks of code are generic over ``. And, @@ -160,8 +156,8 @@ //! //! The above is all you need to execute the dispatchables of your pallet. The last thing you need //! to learn is that all of your pallet testing code should be wrapped in -//! [`frame::testing_prelude::TestState`]. This is a type that provides access to an -//! in-memory state to be used in our tests. +//! [`frame::testing_prelude::TestState`]. This is a type that provides access to an in-memory state +//! to be used in our tests. #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", first_test)] //! //! In the first test, we simply assert that there is no total issuance, and no balance associated @@ -261,9 +257,9 @@ #![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", Error)] //! //! One slightly custom part of this is the [`#[pallet::generate_deposit(pub(super) fn -//! deposit_event)]`](frame::pallet_macros::generate_deposit) part. Without going into -//! too much detail, in order for a pallet to emit events to the rest of the system, it needs to do -//! two things: +//! deposit_event)]`](frame::pallet_macros::generate_deposit) part. Without going into too +//! much detail, in order for a pallet to emit events to the rest of the system, it needs to do two +//! things: //! //! 1. Declare a type in its `Config` that refers to the overarching event type of the runtime. In //! short, by doing this, the pallet is expressing an important bound: `type RuntimeEvent: @@ -288,8 +284,8 @@ //! //! In this snippet, the actual `RuntimeEvent` type (right hand side of `type RuntimeEvent = //! RuntimeEvent`) is generated by -//! [`construct_runtime`](frame::runtime::prelude::construct_runtime). An interesting -//! way to inspect this type is to see its definition in rust-docs: +//! [`construct_runtime`](frame::runtime::prelude::construct_runtime). An interesting way to inspect +//! this type is to see its definition in rust-docs: //! [`crate::guides::your_first_pallet::pallet_v2::tests::runtime_v2::RuntimeEvent`]. //! //! diff --git a/docs/sdk/src/meta_contributing.rs b/docs/sdk/src/meta_contributing.rs index c36bf83816db..fcdcea9934bb 100644 --- a/docs/sdk/src/meta_contributing.rs +++ b/docs/sdk/src/meta_contributing.rs @@ -106,7 +106,7 @@ //! * Then, what is `DispatchResult`? Why is this called *dispatch*? Probably something that can be //! explained in the documentation of [`frame::prelude::DispatchResult`]. //! * Why is `"SomeStaticString"` a valid error? Because there is implementation for it that you can -//! see [here]( `frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError`). +//! see [here](frame::prelude::DispatchError#impl-From<%26'static+str>-for-DispatchError). //! //! //! All of these are examples of underlying information that a contributor should: diff --git a/docs/sdk/src/polkadot_sdk/cumulus.rs b/docs/sdk/src/polkadot_sdk/cumulus.rs index 60be00116da0..9bd957c7c1c0 100644 --- a/docs/sdk/src/polkadot_sdk/cumulus.rs +++ b/docs/sdk/src/polkadot_sdk/cumulus.rs @@ -32,10 +32,10 @@ //! //! //! Finally, a separate macro, similar to -//! [`impl_runtime_api`](frame::runtime::prelude::impl_runtime_apis), which creates the -//! default set of runtime APIs, will generate the parachain runtime's validation runtime API, also -//! known as parachain validation function (PVF). Without this API, the relay chain is unable to -//! validate blocks produced by our parachain. +//! [`impl_runtime_api`](frame::runtime::prelude::impl_runtime_apis), which creates the default set +//! of runtime APIs, will generate the parachain runtime's validation runtime API, also known as +//! parachain validation function (PVF). Without this API, the relay chain is unable to validate +//! blocks produced by our parachain. #![doc = docify::embed!("./src/polkadot_sdk/cumulus.rs", validate_block)] //! //! --- diff --git a/docs/sdk/src/polkadot_sdk/frame_runtime.rs b/docs/sdk/src/polkadot_sdk/frame_runtime.rs index b13f415f860f..f9b8a381365c 100644 --- a/docs/sdk/src/polkadot_sdk/frame_runtime.rs +++ b/docs/sdk/src/polkadot_sdk/frame_runtime.rs @@ -34,8 +34,8 @@ //! about its own responsibilities and make as few assumptions about the general runtime as //! possible. A pallet is analogous to a _module_ in the runtime. //! -//! A pallet is defined as a `mod pallet` wrapped by the [`frame::pallet`] macro. -//! Within this macro, pallet components/parts can be defined. Most notable of these parts are: +//! A pallet is defined as a `mod pallet` wrapped by the [`frame::pallet`] macro. Within this macro, +//! pallet components/parts can be defined. Most notable of these parts are: //! //! - [Config](frame::pallet_macros::config), allowing a pallet to make itself configurable and //! generic over types, values and such. @@ -116,9 +116,8 @@ pub mod pallet { } /// A mandatory struct in each pallet. All functions callable by external users (aka. - /// transactions) must be attached to this type (see - /// [`frame::pallet_macros::call`]). For convenience, internal (private) functions - /// can also be attached to this type. + /// transactions) must be attached to this type (see [`frame::pallet_macros::call`]). For + /// convenience, internal (private) functions can also be attached to this type. #[pallet::pallet] pub struct Pallet(PhantomData); diff --git a/docs/sdk/src/polkadot_sdk/mod.rs b/docs/sdk/src/polkadot_sdk/mod.rs index 4c9593d5ebb1..124d391421b9 100644 --- a/docs/sdk/src/polkadot_sdk/mod.rs +++ b/docs/sdk/src/polkadot_sdk/mod.rs @@ -43,8 +43,8 @@ //! [![GitHub //! Repo](https://img.shields.io/badge/github-frame-2324CC85)](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame) //! -//! [`frame`] is the framework used to create Substrate-based application logic, aka. -//! runtimes. Learn more about the distinction of a runtime and node in +//! [`frame`] is the framework used to create Substrate-based application logic, aka. runtimes. +//! Learn more about the distinction of a runtime and node in //! [`reference_docs::wasm_meta_protocol`]. //! //! #### Cumulus diff --git a/docs/sdk/src/polkadot_sdk/substrate.rs b/docs/sdk/src/polkadot_sdk/substrate.rs index b96bedb5d842..5021c55e581f 100644 --- a/docs/sdk/src/polkadot_sdk/substrate.rs +++ b/docs/sdk/src/polkadot_sdk/substrate.rs @@ -35,10 +35,10 @@ //! > A great analogy for substrate is the following: Substrate node is a gaming console, and a WASM //! > runtime, possibly created with FRAME is the game being inserted into the console. //! -//! [`frame`], Substrate's default runtime development library, takes the above safety -//! practices even further by embracing a declarative programming model whereby correctness is -//! enhanced and the system is highly configurable through parameterization. Learn more about this -//! in [`crate::reference_docs::trait_based_programming`]. +//! [`frame`], Substrate's default runtime development library, takes the above safety practices +//! even further by embracing a declarative programming model whereby correctness is enhanced and +//! the system is highly configurable through parameterization. Learn more about this in +//! [`crate::reference_docs::trait_based_programming`]. //! //! ## How to Get Started //! diff --git a/docs/sdk/src/reference_docs/defensive_programming.rs b/docs/sdk/src/reference_docs/defensive_programming.rs index e4fac9a9b13c..9828e1b50918 100644 --- a/docs/sdk/src/reference_docs/defensive_programming.rs +++ b/docs/sdk/src/reference_docs/defensive_programming.rs @@ -70,8 +70,8 @@ //! //! ### Defensive Traits //! -//! The [`Defensive`](frame::traits::Defensive) trait provides a number of functions, -//! all of which provide an alternative to 'vanilla' Rust functions, e.g.,: +//! The [`Defensive`](frame::traits::Defensive) trait provides a number of functions, all of which +//! provide an alternative to 'vanilla' Rust functions, e.g.,: //! //! - [`defensive_unwrap_or()`](frame::traits::Defensive::defensive_unwrap_or) instead of //! `unwrap_or()` @@ -80,8 +80,8 @@ //! Defensive methods use [`debug_assertions`](https://doc.rust-lang.org/reference/conditional-compilation.html#debug_assertions), which panic in development, but in //! production/release, they will merely log an error (i.e., `log::error`). //! -//! The [`Defensive`](frame::traits::Defensive) trait and its various implementations -//! can be found [here](frame::traits::Defensive). +//! The [`Defensive`](frame::traits::Defensive) trait and its various implementations can be found +//! [here](frame::traits::Defensive). //! //! ## Integer Overflow //! @@ -187,9 +187,9 @@ //! to avoid introducing the notion of any potential-panic or wrapping behavior. //! //! There is also a series of defensive alternatives via -//! [`DefensiveSaturating`](frame::traits::DefensiveSaturating), which introduces the -//! same behavior of the [`Defensive`](frame::traits::Defensive) trait, only with -//! saturating, mathematical operations: +//! [`DefensiveSaturating`](frame::traits::DefensiveSaturating), which introduces the same behavior +//! of the [`Defensive`](frame::traits::Defensive) trait, only with saturating, mathematical +//! operations: #![doc = docify::embed!( "./src/reference_docs/defensive_programming.rs", saturated_defensive_example diff --git a/docs/sdk/src/reference_docs/extrinsic_encoding.rs b/docs/sdk/src/reference_docs/extrinsic_encoding.rs index 98ddb93fc88a..8c8568a228fa 100644 --- a/docs/sdk/src/reference_docs/extrinsic_encoding.rs +++ b/docs/sdk/src/reference_docs/extrinsic_encoding.rs @@ -36,8 +36,8 @@ //! //! ## compact_encoded_length //! -//! This is a [SCALE compact encoded][frame::deps::codec::Compact] integer which is -//! equal to the length, in bytes, of the rest of the extrinsic details. +//! This is a [SCALE compact encoded][frame::deps::codec::Compact] integer which is equal to the +//! length, in bytes, of the rest of the extrinsic details. //! //! To obtain this value, we must encode and concatenate together the rest of the extrinsic details //! first, and then obtain the byte length of these. We can then compact encode that length, and @@ -69,9 +69,9 @@ //! //! ### from_address //! -//! This is the [SCALE encoded][frame::deps::codec] address of the sender of the -//! extrinsic. The address is the first generic parameter of -//! [`sp_runtime::generic::UncheckedExtrinsic`], and so can vary from chain to chain. +//! This is the [SCALE encoded][frame::deps::codec] address of the sender of the extrinsic. The +//! address is the first generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`], and so +//! can vary from chain to chain. //! //! The address type used on the Polkadot relay chain is [`sp_runtime::MultiAddress`], //! where `AccountId32` is defined [here][`sp_core::crypto::AccountId32`]. When constructing a @@ -80,9 +80,9 @@ //! //! ### signature //! -//! This is the [SCALE encoded][frame::deps::codec] signature. The signature type is -//! configured via the third generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`], which -//! determines the shape of the signature and signing algorithm that should be used. +//! This is the [SCALE encoded][frame::deps::codec] signature. The signature type is configured via +//! the third generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`], which determines the +//! shape of the signature and signing algorithm that should be used. //! //! The signature is obtained by signing the _signed payload_ bytes (see below on how this is //! constructed) using the private key associated with the address and correct algorithm. @@ -92,10 +92,10 @@ //! //! ### signed_extensions_extra //! -//! This is the concatenation of the [SCALE encoded][frame::deps::codec] bytes -//! representing each of the [_signed extensions_][sp_runtime::traits::SignedExtension], and are -//! configured by the fourth generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`]. Learn -//! more about signed extensions [here][crate::reference_docs::signed_extensions]. +//! This is the concatenation of the [SCALE encoded][frame::deps::codec] bytes representing each of +//! the [_signed extensions_][sp_runtime::traits::SignedExtension], and are configured by the +//! fourth generic parameter of [`sp_runtime::generic::UncheckedExtrinsic`]. Learn more about +//! signed extensions [here][crate::reference_docs::signed_extensions]. //! //! When it comes to constructing an extrinsic, each signed extension has two things that we are //! interested in here: @@ -123,10 +123,10 @@ //! altered. This is defined by the second generic parameter of //! [`sp_runtime::generic::UncheckedExtrinsic`]. //! -//! A call can be anything that implements [`Encode`][frame::deps::codec::Encode]. In -//! FRAME-based runtimes, a call is represented as an enum of enums, where the outer enum represents -//! the FRAME pallet being called, and the inner enum represents the call being made within that -//! pallet, and any arguments to it. Read more about the call enum +//! A call can be anything that implements [`Encode`][frame::deps::codec::Encode]. In FRAME-based +//! runtimes, a call is represented as an enum of enums, where the outer enum represents the FRAME +//! pallet being called, and the inner enum represents the call being made within that pallet, and +//! any arguments to it. Read more about the call enum //! [here][crate::reference_docs::frame_runtime_types]. //! //! FRAME `Call` enums are automatically generated, and end up looking something like this: diff --git a/docs/sdk/src/reference_docs/frame_offchain_workers.rs b/docs/sdk/src/reference_docs/frame_offchain_workers.rs index 79f44c832fe9..7999707e5ee0 100644 --- a/docs/sdk/src/reference_docs/frame_offchain_workers.rs +++ b/docs/sdk/src/reference_docs/frame_offchain_workers.rs @@ -2,8 +2,7 @@ //! //! This reference document explains how offchain workers work in Substrate and FRAME. The main //! focus is upon FRAME's implementation of this functionality. Nonetheless, offchain workers are a -//! Substrate-provided feature and can be used with possible alternatives to [`frame`] -//! as well. +//! Substrate-provided feature and can be used with possible alternatives to [`frame`] as well. //! //! Offchain workers are a commonly misunderstood topic, therefore we explain them bottom-up, //! starting at the fundamentals and then describing the developer interface. @@ -54,9 +53,9 @@ //! //! ## FRAME's API //! -//! [`frame`] provides a simple API through which pallets can define offchain worker -//! functions. This is part of [`frame::traits::Hooks`], which is implemented as a part -//! of [`frame::pallet_macros::hooks`]. +//! [`frame`] provides a simple API through which pallets can define offchain worker functions. This +//! is part of [`frame::traits::Hooks`], which is implemented as a part of +//! [`frame::pallet_macros::hooks`]. //! //! ``` //! diff --git a/docs/sdk/src/reference_docs/frame_origin.rs b/docs/sdk/src/reference_docs/frame_origin.rs index 52d507e28c42..a2aac7dd3554 100644 --- a/docs/sdk/src/reference_docs/frame_origin.rs +++ b/docs/sdk/src/reference_docs/frame_origin.rs @@ -93,16 +93,14 @@ //! Then, within the pallet, we can simply use this "unknown" origin check type: #![doc = docify::embed!("./src/reference_docs/frame_origin.rs", external_origin_usage)] //! -//! Finally, at the runtime, any implementation of [`frame::traits::EnsureOrigin`] can -//! be passed. +//! Finally, at the runtime, any implementation of [`frame::traits::EnsureOrigin`] can be passed. #![doc = docify::embed!("./src/reference_docs/frame_origin.rs", external_origin_provide)] //! -//! Indeed, some of these implementations of [`frame::traits::EnsureOrigin`] are -//! similar to the ones that we know about: [`frame::runtime::prelude::EnsureSigned`], -//! [`frame::runtime::prelude::EnsureSignedBy`], -//! [`frame::runtime::prelude::EnsureRoot`], -//! [`frame::runtime::prelude::EnsureNone`], etc. But, there are also many more that -//! are not known to us, and are defined in other pallets. +//! Indeed, some of these implementations of [`frame::traits::EnsureOrigin`] are similar to the ones +//! that we know about: [`frame::runtime::prelude::EnsureSigned`], +//! [`frame::runtime::prelude::EnsureSignedBy`], [`frame::runtime::prelude::EnsureRoot`], +//! [`frame::runtime::prelude::EnsureNone`], etc. But, there are also many more that are not known +//! to us, and are defined in other pallets. //! //! For example, [`pallet_collective`] defines [`pallet_collective::EnsureMember`] and //! [`pallet_collective::EnsureProportionMoreThan`] and many more, which is exactly what we alluded diff --git a/docs/sdk/src/reference_docs/frame_pallet_coupling.rs b/docs/sdk/src/reference_docs/frame_pallet_coupling.rs index 2d46ebe990c9..be464bbbf835 100644 --- a/docs/sdk/src/reference_docs/frame_pallet_coupling.rs +++ b/docs/sdk/src/reference_docs/frame_pallet_coupling.rs @@ -124,8 +124,8 @@ //! that is tightly coupled with every other pallet**. This is because it provides the fundamental //! system functionality that every pallet needs, such as some types like //! [`frame::prelude::frame_system::Config::AccountId`], -//! [`frame::prelude::frame_system::Config::Hash`], and some functionality such as -//! block number, etc. +//! [`frame::prelude::frame_system::Config::Hash`], and some functionality such as block number, +//! etc. //! //! ## Recap //! diff --git a/docs/sdk/src/reference_docs/frame_runtime_types.rs b/docs/sdk/src/reference_docs/frame_runtime_types.rs index d4a4e028c6b6..32cda5bc5345 100644 --- a/docs/sdk/src/reference_docs/frame_runtime_types.rs +++ b/docs/sdk/src/reference_docs/frame_runtime_types.rs @@ -80,8 +80,8 @@ //! The only way to express this using Rust's associated types is for the pallet to **define its own //! associated type `RuntimeCall`, and further specify what it thinks `RuntimeCall` should be**. //! -//! In this case, we will want to assert the existence of [`frame::traits::IsSubType`], -//! which is very similar to [`TryFrom`]. +//! In this case, we will want to assert the existence of [`frame::traits::IsSubType`], which is +//! very similar to [`TryFrom`]. #![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", custom_runtime_call)] //! //! And indeed, at the runtime level, this associated type would be the same `RuntimeCall` that is @@ -111,9 +111,9 @@ //! runtime is constructed? The following snippet exactly does that: #![doc = docify::embed!("./src/reference_docs/frame_runtime_types.rs", assert_equality)] //! -//! We leave it to the reader to further explore what -//! [`frame::traits::Hooks::integrity_test`] is, and what [`core::any::TypeId`] is. -//! Another way to assert this is using [`frame::traits::IsType`]. +//! We leave it to the reader to further explore what [`frame::traits::Hooks::integrity_test`] is, +//! and what [`core::any::TypeId`] is. Another way to assert this is using +//! [`frame::traits::IsType`]. //! //! ## Type Aliases //! diff --git a/docs/sdk/src/reference_docs/glossary.rs b/docs/sdk/src/reference_docs/glossary.rs index 2ec6dd420ad9..56f5ef5aeb58 100644 --- a/docs/sdk/src/reference_docs/glossary.rs +++ b/docs/sdk/src/reference_docs/glossary.rs @@ -54,9 +54,9 @@ //! #### Dispatchable: //! //! Dispatchables are [function objects](https://en.wikipedia.org/wiki/Function_object) that act as -//! the entry points in [FRAME](frame) pallets. They can be called by internal or -//! external entities to interact with the blockchain's state. They are a core aspect of the runtime -//! logic, handling transactions and other state-changing operations. +//! the entry points in [FRAME](frame) pallets. They can be called by internal or external entities +//! to interact with the blockchain's state. They are a core aspect of the runtime logic, handling +//! transactions and other state-changing operations. //! //! **Synonyms**: Callable //! @@ -68,14 +68,13 @@ //! //! #### Pallet //! -//! Similar to software modules in traditional programming, [FRAME](frame) pallets in -//! Substrate are modular components that encapsulate distinct functionalities or business logic. -//! Just as libraries or modules are used to build and extend the capabilities of a software -//! application, pallets are the foundational building blocks for constructing a blockchain's -//! runtime with frame. They enable the creation of customizable and upgradeable networks, offering -//! a composable framework for a Substrate-based blockchain. Each pallet can be thought of as a -//! plug-and-play module, enhancing the blockchain's functionality in a cohesive and integrated -//! manner. +//! Similar to software modules in traditional programming, [FRAME](frame) pallets in Substrate are +//! modular components that encapsulate distinct functionalities or business logic. Just as +//! libraries or modules are used to build and extend the capabilities of a software application, +//! pallets are the foundational building blocks for constructing a blockchain's runtime with frame. +//! They enable the creation of customizable and upgradeable networks, offering a composable +//! framework for a Substrate-based blockchain. Each pallet can be thought of as a plug-and-play +//! module, enhancing the blockchain's functionality in a cohesive and integrated manner. //! //! #### Full Node //! diff --git a/docs/sdk/src/reference_docs/mod.rs b/docs/sdk/src/reference_docs/mod.rs index fa02c8e5867c..145df8844f26 100644 --- a/docs/sdk/src/reference_docs/mod.rs +++ b/docs/sdk/src/reference_docs/mod.rs @@ -103,6 +103,6 @@ pub mod light_nodes; /// [`frame`] APIs. pub mod frame_offchain_workers; -/// Learn about the different ways through which multiple [`frame`] pallets can be -/// combined to work together. +/// Learn about the different ways through which multiple [`frame`] pallets can be combined to work +/// together. pub mod frame_pallet_coupling; diff --git a/docs/sdk/src/reference_docs/trait_based_programming.rs b/docs/sdk/src/reference_docs/trait_based_programming.rs index 7841edd8c12f..ace313880707 100644 --- a/docs/sdk/src/reference_docs/trait_based_programming.rs +++ b/docs/sdk/src/reference_docs/trait_based_programming.rs @@ -1,8 +1,8 @@ //! # Trait-based Programming //! //! This document walks you over a peculiar way of using Rust's `trait` items. This pattern is -//! abundantly used within [`frame`] and is therefore paramount important for a smooth -//! transition into it. +//! abundantly used within [`frame`] and is therefore paramount important for a smooth transition +//! into it. //! //! The rest of this document assumes familiarity with the //! [Rust book's Advanced Traits](https://doc.rust-lang.org/book/ch19-03-advanced-traits.html) @@ -12,8 +12,8 @@ //! First, imagine we are writing a FRAME pallet. We represent this pallet with a `struct Pallet`, //! and this pallet wants to implement the functionalities of that pallet, for example a simple //! `transfer` function. For the sake of education, we are interested in having a `MinTransfer` -//! amount, expressed as a [`frame::traits::Get`], which will dictate what is the -//! minimum amount that can be transferred. +//! amount, expressed as a [`frame::traits::Get`], which will dictate what is the minimum amount +//! that can be transferred. //! //! We can foremost write this as simple as the following snippet: #![doc = docify::embed!("./src/reference_docs/trait_based_programming.rs", basic)] From 01cd2c89be73574a330c2ebf37483772a828a4e5 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:57:05 +0530 Subject: [PATCH 19/29] Removes changes in example --- substrate/frame/examples/frame-crate/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/substrate/frame/examples/frame-crate/src/lib.rs b/substrate/frame/examples/frame-crate/src/lib.rs index 32e092b3393c..781cba5658d7 100644 --- a/substrate/frame/examples/frame-crate/src/lib.rs +++ b/substrate/frame/examples/frame-crate/src/lib.rs @@ -15,9 +15,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use polkadot_sdk_frame::prelude::*; +use frame::prelude::*; -#[polkadot_sdk_frame::pallet(dev_mode)] +#[frame::pallet(dev_mode)] pub mod pallet { use super::*; @@ -46,7 +46,7 @@ pub mod pallet { #[cfg(test)] mod tests { use crate::pallet as my_pallet; - use polkadot_sdk_frame::testing_prelude::*; + use frame::testing_prelude::*; construct_runtime!( pub enum Runtime { From 23f9c122dc15b181f97c5db60e0642ed8be2ce76 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:57:49 +0530 Subject: [PATCH 20/29] Removes changes in template node --- templates/minimal/node/src/chain_spec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/minimal/node/src/chain_spec.rs b/templates/minimal/node/src/chain_spec.rs index 7ad80251bf1d..6b721deb6d1d 100644 --- a/templates/minimal/node/src/chain_spec.rs +++ b/templates/minimal/node/src/chain_spec.rs @@ -42,7 +42,7 @@ pub fn development_config() -> Result { /// Configure initial storage state for FRAME pallets. fn testnet_genesis() -> Value { - use polkadot_sdk_frame::traits::Get; + use frame::traits::Get; use runtime::interface::{Balance, MinimumBalance}; let endowment = >::get().max(1) * 1000; let balances = AccountKeyring::iter() From 8161793b808b1c37c812e876e984b8716b765eff Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:59:21 +0530 Subject: [PATCH 21/29] Removes changes in stg --- substrate/frame/support/test/stg_frame_crate/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/frame/support/test/stg_frame_crate/src/lib.rs b/substrate/frame/support/test/stg_frame_crate/src/lib.rs index 7e9b502b6207..dc5fff65510e 100644 --- a/substrate/frame/support/test/stg_frame_crate/src/lib.rs +++ b/substrate/frame/support/test/stg_frame_crate/src/lib.rs @@ -18,7 +18,7 @@ // ! A basic pallet to test it compiles along with a runtime using it when `frame_system` and // `frame_support` are reexported by a `frame` crate. -use polkadot_sdk_frame::deps::{frame_support, frame_system}; +use frame::deps::{frame_support, frame_system}; #[frame_support::pallet] pub mod pallet { @@ -31,7 +31,7 @@ pub mod pallet { #[pallet::config] // The only valid syntax here is the following or // ``` - // pub trait Config: polkadot_sdk_frame::deps::frame_system::Config {} + // pub trait Config: frame::deps::frame_system::Config {} // ``` pub trait Config: frame_system::Config {} From 3971887af28b4f24920c309e0c018ead0752d5d8 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:29:34 +0530 Subject: [PATCH 22/29] Adds bump in prdoc --- prdoc/pr_3813.prdoc | 1 + 1 file changed, 1 insertion(+) diff --git a/prdoc/pr_3813.prdoc b/prdoc/pr_3813.prdoc index b67b570aca14..41214eb51602 100644 --- a/prdoc/pr_3813.prdoc +++ b/prdoc/pr_3813.prdoc @@ -10,3 +10,4 @@ doc: crates: - name: polkadot-sdk-frame + bump: major From c6333bec0c0c9141ff86802378f6134c7c8678ee Mon Sep 17 00:00:00 2001 From: gupnik Date: Mon, 1 Apr 2024 13:48:52 +0200 Subject: [PATCH 23/29] Update substrate/frame/support/procedural/tools/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- substrate/frame/support/procedural/tools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/support/procedural/tools/src/lib.rs b/substrate/frame/support/procedural/tools/src/lib.rs index e91d683f05f5..cd56689026d5 100644 --- a/substrate/frame/support/procedural/tools/src/lib.rs +++ b/substrate/frame/support/procedural/tools/src/lib.rs @@ -54,7 +54,7 @@ pub fn generate_crate_access(unique_id: &str, def_crate: &str) -> TokenStream { /// /// This will usually check the output of [`generate_access_from_frame_or_crate`]. /// We want to know if whatever the `path` takes us to, is exported from `frame` or not. In that -/// case `path` would start with `frame`, something like `polkadot_sdk_frame::x::y:z`. +/// case `path` would start with `frame`, something like `polkadot_sdk_frame::x::y:z` or frame::x::y:z. pub fn is_using_frame_crate(path: &syn::Path) -> bool { path.segments .first() From 2dbd88da68153ccdf216949d34165faffd13c74b Mon Sep 17 00:00:00 2001 From: gupnik Date: Mon, 1 Apr 2024 13:57:45 +0200 Subject: [PATCH 24/29] Update substrate/frame/support/procedural/tools/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- substrate/frame/support/procedural/tools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/support/procedural/tools/src/lib.rs b/substrate/frame/support/procedural/tools/src/lib.rs index cd56689026d5..e413c70606ce 100644 --- a/substrate/frame/support/procedural/tools/src/lib.rs +++ b/substrate/frame/support/procedural/tools/src/lib.rs @@ -118,7 +118,7 @@ pub fn generate_hidden_includes(unique_id: &str, def_crate: &str) -> TokenStream fn get_frame_crate_path(def_crate: &str) -> Option { // This does not work if the frame crate is renamed. if let Ok(FoundCrate::Name(name)) = - crate_name(&"polkadot-sdk-frame").map_err(|_| crate_name(&"frame")) + crate_name(&"polkadot-sdk-frame").or_else(|_| crate_name(&"frame")) { let path = format!("{}::deps::{}", name, def_crate.to_string().replace("-", "_")); Some(syn::parse_str::(&path).expect("is a valid path; qed")) From f81bacbe4c7ef6b0ded50dcd3cb70f20ac0638cc Mon Sep 17 00:00:00 2001 From: gupnik Date: Mon, 1 Apr 2024 13:58:18 +0200 Subject: [PATCH 25/29] Update substrate/utils/frame/rpc/support/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- substrate/utils/frame/rpc/support/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/utils/frame/rpc/support/src/lib.rs b/substrate/utils/frame/rpc/support/src/lib.rs index be47691f8c87..dea822167ff3 100644 --- a/substrate/utils/frame/rpc/support/src/lib.rs +++ b/substrate/utils/frame/rpc/support/src/lib.rs @@ -161,7 +161,7 @@ impl StorageQuery { /// Send this query over RPC, await the typed result. /// - /// Hash should be `::Hash`. + /// Hash should be `::Hash`. /// /// # Arguments /// From c117a8736d7a5d26a81ba4f236eeddaf5faf3d96 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Mon, 1 Apr 2024 17:29:40 +0530 Subject: [PATCH 26/29] Addresses review comments --- prdoc/pr_3813.prdoc | 3 ++- substrate/primitives/api/proc-macro/src/utils.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/prdoc/pr_3813.prdoc b/prdoc/pr_3813.prdoc index 41214eb51602..66dfd70e1b17 100644 --- a/prdoc/pr_3813.prdoc +++ b/prdoc/pr_3813.prdoc @@ -6,7 +6,8 @@ title: Renames `frame` crate to `polkadot-sdk-frame` doc: - audience: Runtime Dev description: | - This PR renames `frame` crate to `polkadot-sdk-frame` as `frame` is not available on crates.io + This PR renames `frame` crate to `polkadot-sdk-frame` as `frame` is not available on crates.io. + Please note that this crate can only be imported as `polkadot-sdk-frame` or `frame`. crates: - name: polkadot-sdk-frame diff --git a/substrate/primitives/api/proc-macro/src/utils.rs b/substrate/primitives/api/proc-macro/src/utils.rs index 945c5c026ed8..a6570a98f1f7 100644 --- a/substrate/primitives/api/proc-macro/src/utils.rs +++ b/substrate/primitives/api/proc-macro/src/utils.rs @@ -35,7 +35,7 @@ pub fn generate_crate_access() -> TokenStream { }, Err(e) => if let Ok(FoundCrate::Name(name)) = - crate_name(&"polkadot-sdk-frame").map_err(|_| crate_name(&"frame")) + crate_name(&"polkadot-sdk-frame").or_else(|_| crate_name(&"frame")) { let path = format!("{}::deps::sp_api::__private", name); let path = syn::parse_str::(&path).expect("is a valid path; qed"); From 174bd64ddb2b3a3a1e76568ce3d237f0be1bedf4 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Mon, 1 Apr 2024 17:31:42 +0530 Subject: [PATCH 27/29] Fmt --- substrate/frame/support/procedural/tools/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/substrate/frame/support/procedural/tools/src/lib.rs b/substrate/frame/support/procedural/tools/src/lib.rs index e413c70606ce..8952cd6011ff 100644 --- a/substrate/frame/support/procedural/tools/src/lib.rs +++ b/substrate/frame/support/procedural/tools/src/lib.rs @@ -54,7 +54,8 @@ pub fn generate_crate_access(unique_id: &str, def_crate: &str) -> TokenStream { /// /// This will usually check the output of [`generate_access_from_frame_or_crate`]. /// We want to know if whatever the `path` takes us to, is exported from `frame` or not. In that -/// case `path` would start with `frame`, something like `polkadot_sdk_frame::x::y:z` or frame::x::y:z. +/// case `path` would start with `frame`, something like `polkadot_sdk_frame::x::y:z` or +/// frame::x::y:z. pub fn is_using_frame_crate(path: &syn::Path) -> bool { path.segments .first() From 749eec3d344e514f39a95628f5a52a558c717de3 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Wed, 3 Apr 2024 11:13:38 +0530 Subject: [PATCH 28/29] Adds test and updates docs --- substrate/frame/src/lib.rs | 4 ++++ .../procedural/src/pallet/parse/config.rs | 23 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index cb19bb61d714..410b7025f99f 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -45,6 +45,10 @@ //! //! In short, this crate only re-exports types and traits from multiple sources. All of these //! sources are listed (and re-exported again) in [`deps`]. +//! +//! ## Usage +//! +//! Please note that this crate can only be imported as `polkadot-sdk-frame` or `frame`. #![cfg_attr(not(feature = "std"), no_std)] #![cfg(feature = "experimental")] diff --git a/substrate/frame/support/procedural/src/pallet/parse/config.rs b/substrate/frame/support/procedural/src/pallet/parse/config.rs index 45618e5528bd..695802038a15 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/config.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/config.rs @@ -517,10 +517,16 @@ mod tests { #[test] fn has_expected_system_config_works_with_frame() { + let path = syn::parse2::(quote::quote!(frame_system::Config)).unwrap(); + let frame_system = syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system)) .unwrap(); - let path = syn::parse2::(quote::quote!(frame_system::Config)).unwrap(); + assert!(has_expected_system_config(path.clone(), &frame_system)); + + let frame_system = + syn::parse2::(quote::quote!(frame::deps::frame_system)) + .unwrap(); assert!(has_expected_system_config(path, &frame_system)); } @@ -533,6 +539,14 @@ mod tests { syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system::Config)) .unwrap(); assert!(has_expected_system_config(path, &frame_system)); + + let frame_system = + syn::parse2::(quote::quote!(frame::deps::frame_system)) + .unwrap(); + let path = + syn::parse2::(quote::quote!(frame::deps::frame_system::Config)) + .unwrap(); + assert!(has_expected_system_config(path, &frame_system)); } #[test] @@ -543,6 +557,13 @@ mod tests { syn::parse2::(quote::quote!(polkadot_sdk_frame::xyz::frame_system::Config)) .unwrap(); assert!(has_expected_system_config(path, &frame_system)); + + let frame_system = + syn::parse2::(quote::quote!(frame::xyz::frame_system)).unwrap(); + let path = + syn::parse2::(quote::quote!(frame::xyz::frame_system::Config)) + .unwrap(); + assert!(has_expected_system_config(path, &frame_system)); } #[test] From 8af848ea92a7d7e380c79ea19fd2a4a1a6b86b1f Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Wed, 3 Apr 2024 11:23:34 +0530 Subject: [PATCH 29/29] Fmt --- substrate/frame/src/lib.rs | 4 ++-- .../support/procedural/src/pallet/parse/config.rs | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 410b7025f99f..d395b4c1902b 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -45,9 +45,9 @@ //! //! In short, this crate only re-exports types and traits from multiple sources. All of these //! sources are listed (and re-exported again) in [`deps`]. -//! +//! //! ## Usage -//! +//! //! Please note that this crate can only be imported as `polkadot-sdk-frame` or `frame`. #![cfg_attr(not(feature = "std"), no_std)] diff --git a/substrate/frame/support/procedural/src/pallet/parse/config.rs b/substrate/frame/support/procedural/src/pallet/parse/config.rs index 695802038a15..406072df4b9d 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/config.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/config.rs @@ -525,8 +525,7 @@ mod tests { assert!(has_expected_system_config(path.clone(), &frame_system)); let frame_system = - syn::parse2::(quote::quote!(frame::deps::frame_system)) - .unwrap(); + syn::parse2::(quote::quote!(frame::deps::frame_system)).unwrap(); assert!(has_expected_system_config(path, &frame_system)); } @@ -541,11 +540,9 @@ mod tests { assert!(has_expected_system_config(path, &frame_system)); let frame_system = - syn::parse2::(quote::quote!(frame::deps::frame_system)) - .unwrap(); + syn::parse2::(quote::quote!(frame::deps::frame_system)).unwrap(); let path = - syn::parse2::(quote::quote!(frame::deps::frame_system::Config)) - .unwrap(); + syn::parse2::(quote::quote!(frame::deps::frame_system::Config)).unwrap(); assert!(has_expected_system_config(path, &frame_system)); } @@ -561,8 +558,7 @@ mod tests { let frame_system = syn::parse2::(quote::quote!(frame::xyz::frame_system)).unwrap(); let path = - syn::parse2::(quote::quote!(frame::xyz::frame_system::Config)) - .unwrap(); + syn::parse2::(quote::quote!(frame::xyz::frame_system::Config)).unwrap(); assert!(has_expected_system_config(path, &frame_system)); }