Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
frame_support::pallet_prelude: reexport StorageVersion (#11408)
Browse files Browse the repository at this point in the history
* frame_support::pallet_prelude: reexport StorageVersion

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* cargo fmt

Signed-off-by: koushiro <koushiro.cqx@gmail.com>
  • Loading branch information
koushiro authored May 17, 2022
1 parent 6a7af64 commit 88abf20
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 51 deletions.
4 changes: 1 addition & 3 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ use frame_support::{
codec::{Decode, Encode},
dispatch::{DispatchError, DispatchResultWithPostInfo, Dispatchable, PostDispatchInfo},
ensure,
traits::{
Backing, ChangeMembers, EnsureOrigin, Get, GetBacking, InitializeMembers, StorageVersion,
},
traits::{Backing, ChangeMembers, EnsureOrigin, Get, GetBacking, InitializeMembers},
weights::{GetDispatchInfo, Weight},
};

Expand Down
2 changes: 1 addition & 1 deletion frame/collective/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::{Event as CollectiveEvent, *};
use crate as pallet_collective;
use frame_support::{
assert_noop, assert_ok, parameter_types,
traits::{ConstU32, ConstU64, GenesisBuild},
traits::{ConstU32, ConstU64, GenesisBuild, StorageVersion},
weights::Pays,
Hashable,
};
Expand Down
18 changes: 9 additions & 9 deletions frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ use codec::{Encode, HasCompact};
use frame_support::{
dispatch::Dispatchable,
ensure,
traits::{Contains, Currency, Get, Randomness, ReservableCurrency, StorageVersion, Time},
traits::{Contains, Currency, Get, Randomness, ReservableCurrency, Time},
weights::{DispatchClass, GetDispatchInfo, Pays, PostDispatchInfo, Weight},
};
use frame_system::{limits::BlockWeights, Pallet as System};
Expand All @@ -133,9 +133,6 @@ type TrieId = Vec<u8>;
type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(7);

/// Used as a sentinel value when reading and writing contract memory.
///
/// It is usually used to signal `None` to a contract when only a primitive is allowed
Expand Down Expand Up @@ -222,6 +219,14 @@ pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(7);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T>(PhantomData<T>);

#[pallet::config]
pub trait Config: frame_system::Config {
/// The time implementation used to supply timestamps to conntracts through `seal_now`.
Expand Down Expand Up @@ -353,11 +358,6 @@ pub mod pallet {
type AddressGenerator: AddressGenerator<Self>;
}

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T>(PhantomData<T>);

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T>
where
Expand Down
2 changes: 0 additions & 2 deletions frame/contracts/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ use sp_std::{marker::PhantomData, prelude::*};

/// Wrapper for all migrations of this pallet, based on `StorageVersion`.
pub fn migrate<T: Config>() -> Weight {
use frame_support::traits::StorageVersion;

let version = StorageVersion::get::<Pallet<T>>();
let mut weight: Weight = 0;

Expand Down
20 changes: 10 additions & 10 deletions frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ use frame_support::{
traits::{
defensive_prelude::*, ChangeMembers, Contains, ContainsLengthBound, Currency,
CurrencyToVote, Get, InitializeMembers, LockIdentifier, LockableCurrency, OnUnbalanced,
ReservableCurrency, SortedMembers, StorageVersion, WithdrawReasons,
ReservableCurrency, SortedMembers, WithdrawReasons,
},
weights::Weight,
};
Expand All @@ -123,9 +123,6 @@ pub use weights::WeightInfo;
/// All migrations.
pub mod migrations;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(4);

/// The maximum votes allowed per voter.
pub const MAXIMUM_VOTE: usize = 16;

Expand Down Expand Up @@ -186,6 +183,15 @@ pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(4);

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T>(PhantomData<T>);

#[pallet::config]
pub trait Config: frame_system::Config {
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
Expand Down Expand Up @@ -247,12 +253,6 @@ pub mod pallet {
type WeightInfo: WeightInfo;
}

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T>(PhantomData<T>);

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
/// What to do at the end of each block.
Expand Down
11 changes: 5 additions & 6 deletions frame/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ use frame_support::{
dispatch::DispatchResultWithPostInfo,
pallet_prelude::Get,
storage,
traits::{KeyOwnerProofSystem, OneSessionHandler, StorageVersion},
traits::{KeyOwnerProofSystem, OneSessionHandler},
weights::{Pays, Weight},
WeakBoundedVec,
};
use scale_info::TypeInfo;
use sp_runtime::{generic::DigestItem, traits::Zero, DispatchResult, KeyTypeId};
use sp_session::{GetSessionNumber, GetValidatorCount};
use sp_staking::SessionIndex;
Expand All @@ -69,17 +70,15 @@ pub use equivocation::{

pub use pallet::*;

use scale_info::TypeInfo;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(4);

#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::{dispatch::DispatchResult, pallet_prelude::*};
use frame_system::pallet_prelude::*;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(4);

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::storage_version(STORAGE_VERSION)]
Expand Down
6 changes: 2 additions & 4 deletions frame/membership/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
// Ensure we're `no_std` when compiling for Wasm.
#![cfg_attr(not(feature = "std"), no_std)]

use frame_support::traits::{
ChangeMembers, Contains, Get, InitializeMembers, SortedMembers, StorageVersion,
};
use frame_support::traits::{ChangeMembers, Contains, Get, InitializeMembers, SortedMembers};
use sp_std::prelude::*;

pub mod migrations;
Expand Down Expand Up @@ -507,7 +505,7 @@ mod tests {

use frame_support::{
assert_noop, assert_ok, ord_parameter_types, parameter_types,
traits::{ConstU32, ConstU64, GenesisBuild},
traits::{ConstU32, ConstU64, GenesisBuild, StorageVersion},
};
use frame_system::EnsureSignedBy;

Expand Down
2 changes: 1 addition & 1 deletion frame/session/src/historical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use sp_trie::{

use frame_support::{
print,
traits::{KeyOwnerProofSystem, StorageVersion, ValidatorSet, ValidatorSetWithIdentification},
traits::{KeyOwnerProofSystem, ValidatorSet, ValidatorSetWithIdentification},
Parameter,
};

Expand Down
2 changes: 1 addition & 1 deletion frame/session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ use frame_support::{
ensure,
traits::{
EstimateNextNewSession, EstimateNextSessionRotation, FindAuthor, Get, OneSessionHandler,
StorageVersion, ValidatorRegistration, ValidatorSet,
ValidatorRegistration, ValidatorSet,
},
weights::Weight,
Parameter,
Expand Down
2 changes: 1 addition & 1 deletion frame/session/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ fn test_migration_v1() {
historical::{HistoricalSessions, StoredRange},
mock::Historical,
};
use frame_support::traits::PalletInfoAccess;
use frame_support::traits::{PalletInfoAccess, StorageVersion};

new_test_ext().execute_with(|| {
assert!(<HistoricalSessions<Test>>::iter_values().count() > 0);
Expand Down
2 changes: 1 addition & 1 deletion frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ pub mod pallet_prelude {
},
traits::{
ConstU32, EnsureOrigin, Get, GetDefault, GetStorageVersion, Hooks, IsType,
PalletInfoAccess, StorageInfoTrait,
PalletInfoAccess, StorageInfoTrait, StorageVersion,
},
weights::{DispatchClass, Pays, Weight},
Blake2_128, Blake2_128Concat, Blake2_256, CloneNoBound, DebugNoBound, EqNoBound, Identity,
Expand Down
6 changes: 1 addition & 5 deletions frame/support/test/tests/pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,9 @@ impl SomeAssociation2 for u64 {

#[frame_support::pallet]
pub mod pallet {
use super::{
SomeAssociation1, SomeAssociation2, SomeType1, SomeType2, SomeType3, SomeType4, SomeType5,
SomeType6, SomeType7, StorageVersion,
};
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use scale_info::TypeInfo;

type BalanceOf<T> = <T as Config>::Balance;

Expand Down
2 changes: 1 addition & 1 deletion frame/tips/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ use codec::{Decode, Encode};
use frame_support::{
traits::{
ContainsLengthBound, Currency, EnsureOrigin, ExistenceRequirement::KeepAlive, Get,
OnUnbalanced, ReservableCurrency, SortedMembers, StorageVersion,
OnUnbalanced, ReservableCurrency, SortedMembers,
},
Parameter,
};
Expand Down
2 changes: 1 addition & 1 deletion frame/tips/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use frame_support::{
pallet_prelude::GenesisBuild,
parameter_types,
storage::StoragePrefixedMap,
traits::{ConstU32, ConstU64, SortedMembers},
traits::{ConstU32, ConstU64, SortedMembers, StorageVersion},
PalletId,
};

Expand Down
12 changes: 8 additions & 4 deletions frame/vesting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ pub mod weights;

use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{
dispatch::{DispatchError, DispatchResult},
ensure,
pallet_prelude::*,
storage::bounded_vec::BoundedVec,
traits::{
Currency, ExistenceRequirement, Get, LockIdentifier, LockableCurrency, VestingSchedule,
WithdrawReasons,
},
weights::Weight,
};
use frame_system::{ensure_root, ensure_signed, pallet_prelude::*};
pub use pallet::*;
use scale_info::TypeInfo;
use sp_runtime::{
traits::{
Expand All @@ -74,7 +74,9 @@ use sp_runtime::{
},
RuntimeDebug,
};
use sp_std::{fmt::Debug, prelude::*};
use sp_std::{fmt::Debug, marker::PhantomData, prelude::*};

pub use pallet::*;
pub use vesting_info::*;
pub use weights::WeightInfo;

Expand Down Expand Up @@ -146,6 +148,8 @@ impl<T: Config> Get<u32> for MaxVestingSchedulesGet<T> {
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

#[pallet::config]
pub trait Config: frame_system::Config {
Expand Down
2 changes: 1 addition & 1 deletion frame/vesting/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use frame_support::{
parameter_types,
traits::{ConstU32, ConstU64},
traits::{ConstU32, ConstU64, GenesisBuild},
};
use sp_core::H256;
use sp_runtime::{
Expand Down

0 comments on commit 88abf20

Please sign in to comment.