From 7f6a807270de8d2f7f8a483fb775be4d7076b0d4 Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Mon, 2 Dec 2024 16:25:36 -0800 Subject: [PATCH 1/7] adapt umbrella crate to pallet-indices --- Cargo.lock | 7 +------ substrate/frame/indices/Cargo.toml | 23 ++++----------------- substrate/frame/indices/src/benchmarking.rs | 5 +---- substrate/frame/indices/src/lib.rs | 19 ++++++++++------- substrate/frame/indices/src/mock.rs | 15 +++++++++----- substrate/frame/indices/src/tests.rs | 6 ++++-- substrate/frame/indices/src/weights.rs | 2 +- 7 files changed, 32 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc2ebb2a057d..f42f348f9bc2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13620,16 +13620,11 @@ dependencies = [ name = "pallet-indices" version = "28.0.0" dependencies = [ - "frame-benchmarking 28.0.0", - "frame-support 28.0.0", - "frame-system 28.0.0", "pallet-balances 28.0.0", "parity-scale-codec", + "polkadot-sdk-frame 0.1.0", "scale-info", - "sp-core 28.0.0", - "sp-io 30.0.0", "sp-keyring 31.0.0", - "sp-runtime 31.0.1", ] [[package]] diff --git a/substrate/frame/indices/Cargo.toml b/substrate/frame/indices/Cargo.toml index d81b2d5cabf1..59f5a9641748 100644 --- a/substrate/frame/indices/Cargo.toml +++ b/substrate/frame/indices/Cargo.toml @@ -18,13 +18,8 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } -sp-core = { workspace = true } -sp-io = { workspace = true } +frame = { workspace = true, features = ["experimental", "runtime"] } sp-keyring = { optional = true, workspace = true } -sp-runtime = { workspace = true } [dev-dependencies] pallet-balances = { workspace = true, default-features = true } @@ -33,27 +28,17 @@ pallet-balances = { workspace = true, default-features = true } default = ["std"] std = [ "codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", + "frame/std", "pallet-balances/std", "scale-info/std", - "sp-core/std", - "sp-io/std", "sp-keyring", "sp-keyring?/std", - "sp-runtime/std", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", + "frame/runtime-benchmarks", "pallet-balances/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", + "frame/try-runtime", "pallet-balances/try-runtime", - "sp-runtime/try-runtime", ] diff --git a/substrate/frame/indices/src/benchmarking.rs b/substrate/frame/indices/src/benchmarking.rs index 28f5e3bf5cf0..52c9e1db1be0 100644 --- a/substrate/frame/indices/src/benchmarking.rs +++ b/substrate/frame/indices/src/benchmarking.rs @@ -20,10 +20,7 @@ #![cfg(feature = "runtime-benchmarks")] use crate::*; -use frame_benchmarking::v2::*; -use frame_system::RawOrigin; -use sp_runtime::traits::Bounded; - +use frame::{benchmarking::prelude::*, prelude::Bounded}; const SEED: u32 = 0; #[benchmarks] diff --git a/substrate/frame/indices/src/lib.rs b/substrate/frame/indices/src/lib.rs index 740d69365df3..1f07a132833a 100644 --- a/substrate/frame/indices/src/lib.rs +++ b/substrate/frame/indices/src/lib.rs @@ -29,10 +29,13 @@ extern crate alloc; use alloc::vec::Vec; use codec::Codec; -use frame_support::traits::{BalanceStatus::Reserved, Currency, ReservableCurrency}; -use sp_runtime::{ - traits::{AtLeast32Bit, LookupError, Saturating, StaticLookup, Zero}, - MultiAddress, +use frame::{ + deps::sp_runtime::MultiAddress, + prelude::*, + traits::{ + AtLeast32Bit, BalanceStatus::Reserved, Currency, LookupError, ReservableCurrency, + Saturating, StaticLookup, Zero, + }, }; pub use weights::WeightInfo; @@ -42,11 +45,11 @@ type AccountIdLookupOf = <::Lookup as StaticLookup pub use pallet::*; -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; + //use frame_support::pallet_prelude::*; + //use frame_system::pallet_prelude::*; /// The module's config trait. #[pallet::config] @@ -265,7 +268,7 @@ pub mod pallet { StorageMap<_, Blake2_128Concat, T::AccountIndex, (T::AccountId, BalanceOf, bool)>; #[pallet::genesis_config] - #[derive(frame_support::DefaultNoBound)] + #[derive(frame::deps::frame_support::DefaultNoBound)] pub struct GenesisConfig { pub indices: Vec<(T::AccountIndex, T::AccountId)>, } diff --git a/substrate/frame/indices/src/mock.rs b/substrate/frame/indices/src/mock.rs index 72bbc6dab4a4..be667b71025e 100644 --- a/substrate/frame/indices/src/mock.rs +++ b/substrate/frame/indices/src/mock.rs @@ -20,12 +20,17 @@ #![cfg(test)] use crate::{self as pallet_indices, Config}; -use frame_support::{derive_impl, traits::ConstU64}; -use sp_runtime::BuildStorage; - +use frame::{ + runtime::{ + prelude::{construct_runtime, derive_impl}, + testing_prelude::BuildStorage, + }, + testing_prelude::frame_system, + traits::ConstU64, +}; type Block = frame_system::mocking::MockBlock; -frame_support::construct_runtime!( +construct_runtime!( pub enum Test { System: frame_system, @@ -55,7 +60,7 @@ impl Config for Test { type WeightInfo = (); } -pub fn new_test_ext() -> sp_io::TestExternalities { +pub fn new_test_ext() -> frame::deps::sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); pallet_balances::GenesisConfig:: { balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)], diff --git a/substrate/frame/indices/src/tests.rs b/substrate/frame/indices/src/tests.rs index 56b101900038..d37691c9c58f 100644 --- a/substrate/frame/indices/src/tests.rs +++ b/substrate/frame/indices/src/tests.rs @@ -20,9 +20,11 @@ #![cfg(test)] use super::{mock::*, *}; -use frame_support::{assert_noop, assert_ok}; +use frame::{ + deps::sp_runtime::MultiAddress::Id, + testing_prelude::{assert_noop, assert_ok}, +}; use pallet_balances::Error as BalancesError; -use sp_runtime::MultiAddress::Id; #[test] fn claiming_should_work() { diff --git a/substrate/frame/indices/src/weights.rs b/substrate/frame/indices/src/weights.rs index 567e9bab54bd..5ba1ffc8b5d1 100644 --- a/substrate/frame/indices/src/weights.rs +++ b/substrate/frame/indices/src/weights.rs @@ -46,7 +46,7 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use frame::weights_prelude::*; use core::marker::PhantomData; /// Weight functions needed for `pallet_indices`. From 1c7a26b3487ba1707f3aec4a4b72a0545657f87f Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Thu, 12 Dec 2024 17:29:47 -0800 Subject: [PATCH 2/7] prelude add --- substrate/frame/indices/src/benchmarking.rs | 2 +- substrate/frame/indices/src/lib.rs | 11 +------- substrate/frame/indices/src/mock.rs | 10 ++------ substrate/frame/indices/src/tests.rs | 5 +--- substrate/frame/src/lib.rs | 28 ++++++++++++++++++++- 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/substrate/frame/indices/src/benchmarking.rs b/substrate/frame/indices/src/benchmarking.rs index 52c9e1db1be0..85a3243ff9ec 100644 --- a/substrate/frame/indices/src/benchmarking.rs +++ b/substrate/frame/indices/src/benchmarking.rs @@ -20,7 +20,7 @@ #![cfg(feature = "runtime-benchmarks")] use crate::*; -use frame::{benchmarking::prelude::*, prelude::Bounded}; +use frame::benchmarking::prelude::*; const SEED: u32 = 0; #[benchmarks] diff --git a/substrate/frame/indices/src/lib.rs b/substrate/frame/indices/src/lib.rs index 1f07a132833a..cf7f83305590 100644 --- a/substrate/frame/indices/src/lib.rs +++ b/substrate/frame/indices/src/lib.rs @@ -29,14 +29,7 @@ extern crate alloc; use alloc::vec::Vec; use codec::Codec; -use frame::{ - deps::sp_runtime::MultiAddress, - prelude::*, - traits::{ - AtLeast32Bit, BalanceStatus::Reserved, Currency, LookupError, ReservableCurrency, - Saturating, StaticLookup, Zero, - }, -}; +use frame::prelude::*; pub use weights::WeightInfo; type BalanceOf = @@ -48,8 +41,6 @@ pub use pallet::*; #[frame::pallet] pub mod pallet { use super::*; - //use frame_support::pallet_prelude::*; - //use frame_system::pallet_prelude::*; /// The module's config trait. #[pallet::config] diff --git a/substrate/frame/indices/src/mock.rs b/substrate/frame/indices/src/mock.rs index be667b71025e..c1a55003bfc9 100644 --- a/substrate/frame/indices/src/mock.rs +++ b/substrate/frame/indices/src/mock.rs @@ -20,14 +20,8 @@ #![cfg(test)] use crate::{self as pallet_indices, Config}; -use frame::{ - runtime::{ - prelude::{construct_runtime, derive_impl}, - testing_prelude::BuildStorage, - }, - testing_prelude::frame_system, - traits::ConstU64, -}; +use frame::testing_prelude::*; + type Block = frame_system::mocking::MockBlock; construct_runtime!( diff --git a/substrate/frame/indices/src/tests.rs b/substrate/frame/indices/src/tests.rs index d37691c9c58f..8b1651f632cb 100644 --- a/substrate/frame/indices/src/tests.rs +++ b/substrate/frame/indices/src/tests.rs @@ -20,10 +20,7 @@ #![cfg(test)] use super::{mock::*, *}; -use frame::{ - deps::sp_runtime::MultiAddress::Id, - testing_prelude::{assert_noop, assert_ok}, -}; +use frame::testing_prelude::*; use pallet_balances::Error as BalancesError; #[test] diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 03d815e349df..eeb2c56d1da5 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -216,6 +216,9 @@ pub mod prelude { /// All hashing related things pub use super::hashing::*; + /// All arithmetic types used for safe math. + pub use super::arithmetic::*; + /// Runtime traits #[doc(no_inline)] pub use sp_runtime::traits::{ @@ -223,9 +226,25 @@ pub mod prelude { Saturating, StaticLookup, TrailingZeroInput, }; + /// Bounded storage related types. + pub use sp_runtime::{BoundedSlice, BoundedVec}; + + /// Currency related traits and types. + pub use frame_support::traits::{ + BalanceStatus::{self, Reserved}, + Currency, + ExistenceRequirement::KeepAlive, + ReservableCurrency, + }; + + pub use super::address::*; + /// Other error/result types for runtime #[doc(no_inline)] - pub use sp_runtime::{DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError}; + pub use sp_runtime::{ + DispatchError::{self, BadOrigin}, + DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError, + }; } #[cfg(any(feature = "try-runtime", test))] @@ -532,6 +551,13 @@ pub mod hashing { pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256}; } +pub mod address { + pub use sp_runtime::{ + traits::LookupError, + MultiAddress::{self, Id}, + }; +} + /// Access to all of the dependencies of this crate. In case the prelude re-exports are not enough, /// this module can be used. /// From 05d719bd0685d1eac2dc96b66f1739132a541011 Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Thu, 12 Dec 2024 17:42:29 -0800 Subject: [PATCH 3/7] nit import adjust macro DefaultNoBound --- substrate/frame/indices/src/lib.rs | 2 +- substrate/frame/indices/src/mock.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/frame/indices/src/lib.rs b/substrate/frame/indices/src/lib.rs index cf7f83305590..6dfc062e9c3b 100644 --- a/substrate/frame/indices/src/lib.rs +++ b/substrate/frame/indices/src/lib.rs @@ -259,7 +259,7 @@ pub mod pallet { StorageMap<_, Blake2_128Concat, T::AccountIndex, (T::AccountId, BalanceOf, bool)>; #[pallet::genesis_config] - #[derive(frame::deps::frame_support::DefaultNoBound)] + #[derive(DefaultNoBound)] pub struct GenesisConfig { pub indices: Vec<(T::AccountIndex, T::AccountId)>, } diff --git a/substrate/frame/indices/src/mock.rs b/substrate/frame/indices/src/mock.rs index c1a55003bfc9..e99fc875e755 100644 --- a/substrate/frame/indices/src/mock.rs +++ b/substrate/frame/indices/src/mock.rs @@ -54,7 +54,7 @@ impl Config for Test { type WeightInfo = (); } -pub fn new_test_ext() -> frame::deps::sp_io::TestExternalities { +pub fn new_test_ext() -> TestExternalities { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); pallet_balances::GenesisConfig:: { balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)], From 3e13f0616df5c3c0f291751f0e96dba0a6fdbbf7 Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Thu, 2 Jan 2025 14:33:15 +0100 Subject: [PATCH 4/7] address out account mod in --- substrate/frame/indices/src/mock.rs | 2 +- substrate/frame/src/lib.rs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/substrate/frame/indices/src/mock.rs b/substrate/frame/indices/src/mock.rs index e99fc875e755..2748b9722ac2 100644 --- a/substrate/frame/indices/src/mock.rs +++ b/substrate/frame/indices/src/mock.rs @@ -22,7 +22,7 @@ use crate::{self as pallet_indices, Config}; use frame::testing_prelude::*; -type Block = frame_system::mocking::MockBlock; +type Block = MockBlock; construct_runtime!( pub enum Test diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index b039d2d57994..c4277ac2ebe7 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -237,7 +237,7 @@ pub mod prelude { ReservableCurrency, }; - pub use super::address::*; + pub use super::account::*; /// Other error/result types for runtime #[doc(no_inline)] @@ -551,9 +551,15 @@ pub mod hashing { pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256}; } -pub mod address { +/// All account management related traits & types. +/// +/// This is already part of the [`prelude`]. +pub mod account { + pub use frame_support::traits::{ + AsEnsureOriginWithArg, ChangeMembers, EitherOfDiverse, FindAuthor, InitializeMembers, + }; pub use sp_runtime::{ - traits::LookupError, + traits::{IdentifyAccount, IdentityLookup, LookupError}, MultiAddress::{self, Id}, }; } From 081e880b4b22febbda1e4d29ba749b59d8cbfc29 Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Thu, 2 Jan 2025 17:11:34 +0100 Subject: [PATCH 5/7] take out sp-keyring --- Cargo.lock | 1 - substrate/frame/indices/Cargo.toml | 3 --- 2 files changed, 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 999d476aa78c..8d9087a855a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13804,7 +13804,6 @@ dependencies = [ "parity-scale-codec", "polkadot-sdk-frame 0.1.0", "scale-info", - "sp-keyring 31.0.0", ] [[package]] diff --git a/substrate/frame/indices/Cargo.toml b/substrate/frame/indices/Cargo.toml index 59f5a9641748..0ef8bdeb18ef 100644 --- a/substrate/frame/indices/Cargo.toml +++ b/substrate/frame/indices/Cargo.toml @@ -19,7 +19,6 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } frame = { workspace = true, features = ["experimental", "runtime"] } -sp-keyring = { optional = true, workspace = true } [dev-dependencies] pallet-balances = { workspace = true, default-features = true } @@ -31,8 +30,6 @@ std = [ "frame/std", "pallet-balances/std", "scale-info/std", - "sp-keyring", - "sp-keyring?/std", ] runtime-benchmarks = [ "frame/runtime-benchmarks", From a60935e840e2458b9b04a146061961cda0141932 Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Sun, 5 Jan 2025 00:06:52 +0100 Subject: [PATCH 6/7] update WIP --- substrate/frame/indices/src/lib.rs | 2 +- substrate/frame/src/lib.rs | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/substrate/frame/indices/src/lib.rs b/substrate/frame/indices/src/lib.rs index 6dfc062e9c3b..d17009fbb06f 100644 --- a/substrate/frame/indices/src/lib.rs +++ b/substrate/frame/indices/src/lib.rs @@ -29,7 +29,7 @@ extern crate alloc; use alloc::vec::Vec; use codec::Codec; -use frame::prelude::*; +use frame::{prelude::*, traits::{BalanceStatus::Reserved, Currency, ReservableCurrency}}; pub use weights::WeightInfo; type BalanceOf = diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index c4277ac2ebe7..c4286325fbe7 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -229,14 +229,6 @@ pub mod prelude { /// Bounded storage related types. pub use sp_runtime::{BoundedSlice, BoundedVec}; - /// Currency related traits and types. - pub use frame_support::traits::{ - BalanceStatus::{self, Reserved}, - Currency, - ExistenceRequirement::KeepAlive, - ReservableCurrency, - }; - pub use super::account::*; /// Other error/result types for runtime From 2d7f33c694897deec6c605d524b82a927db54a58 Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Sun, 5 Jan 2025 01:09:00 +0100 Subject: [PATCH 7/7] nit merge --- substrate/frame/indices/src/lib.rs | 5 ++++- substrate/frame/src/lib.rs | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/substrate/frame/indices/src/lib.rs b/substrate/frame/indices/src/lib.rs index d17009fbb06f..16cd3f45374a 100644 --- a/substrate/frame/indices/src/lib.rs +++ b/substrate/frame/indices/src/lib.rs @@ -29,7 +29,10 @@ extern crate alloc; use alloc::vec::Vec; use codec::Codec; -use frame::{prelude::*, traits::{BalanceStatus::Reserved, Currency, ReservableCurrency}}; +use frame::{ + prelude::*, + traits::{BalanceStatus::Reserved, Currency, ReservableCurrency}, +}; pub use weights::WeightInfo; type BalanceOf = diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 48ad737d1c70..ce0dcddf906a 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -240,8 +240,9 @@ pub mod prelude { /// Other runtime types and traits #[doc(no_inline)] pub use sp_runtime::{ + BoundToRuntimeAppPublic, DispatchError::{self, BadOrigin}, - BoundToRuntimeAppPublic, DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError, + DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError, }; }