Rename pallet trait Trait to Config (#7599)

* rename Trait to Config

* add test asserting using Trait is still valid.

* fix ui tests
This commit is contained in:
Guillaume Thiolliere
2020-11-30 15:34:54 +01:00
committed by GitHub
parent dd3c84c362
commit 1cbfc9257f
200 changed files with 1767 additions and 1607 deletions
@@ -39,10 +39,10 @@
//! ```
//! use frame_support::{decl_module, dispatch, traits::Randomness};
//!
//! pub trait Trait: frame_system::Trait {}
//! pub trait Config: frame_system::Config {}
//!
//! decl_module! {
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin {
//! pub struct Module<T: Config> for enum Call where origin: T::Origin {
//! #[weight = 0]
//! pub fn random_module_example(origin) -> dispatch::DispatchResult {
//! let _random_value = <pallet_randomness_collective_flip::Module<T>>::random(&b"my context"[..]);
@@ -63,18 +63,18 @@ use frame_support::{
};
use safe_mix::TripletMix;
use codec::Encode;
use frame_system::Trait;
use frame_system::Config;
const RANDOM_MATERIAL_LEN: u32 = 81;
fn block_number_to_index<T: Trait>(block_number: T::BlockNumber) -> usize {
fn block_number_to_index<T: Config>(block_number: T::BlockNumber) -> usize {
// on_initialize is called on the first block after genesis
let index = (block_number - 1u32.into()) % RANDOM_MATERIAL_LEN.into();
index.try_into().ok().expect("Something % 81 is always smaller than usize; qed")
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
fn on_initialize(block_number: T::BlockNumber) -> Weight {
let parent_hash = <frame_system::Module<T>>::parent_hash();
@@ -91,7 +91,7 @@ decl_module! {
}
decl_storage! {
trait Store for Module<T: Trait> as RandomnessCollectiveFlip {
trait Store for Module<T: Config> as RandomnessCollectiveFlip {
/// Series of block headers from the last 81 blocks that acts as random seed material. This
/// is arranged as a ring buffer with `block_number % 81` being the index into the `Vec` of
/// the oldest hash.
@@ -99,7 +99,7 @@ decl_storage! {
}
}
impl<T: Trait> Randomness<T::Hash> for Module<T> {
impl<T: Config> Randomness<T::Hash> for Module<T> {
/// This randomness uses a low-influence function, drawing upon the block hashes from the
/// previous 81 blocks. Its result for any given subject will be known far in advance by anyone
/// observing the chain. Any block producer has significant influence over their block hashes
@@ -157,7 +157,7 @@ mod tests {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;