mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 11:31:05 +00:00
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:
committed by
GitHub
parent
dd3c84c362
commit
1cbfc9257f
@@ -33,9 +33,9 @@ const SEED: u32 = 0;
|
||||
|
||||
const MAX_BYTES: u32 = 1_024;
|
||||
|
||||
fn assert_last_event<T: Trait<I>, I: Instance>(generic_event: <T as Trait<I>>::Event) {
|
||||
fn assert_last_event<T: Config<I>, I: Instance>(generic_event: <T as Config<I>>::Event) {
|
||||
let events = System::<T>::events();
|
||||
let system_event: <T as frame_system::Trait>::Event = generic_event.into();
|
||||
let system_event: <T as frame_system::Config>::Event = generic_event.into();
|
||||
// compare to the last event record
|
||||
let EventRecord { event, .. } = &events[events.len() - 1];
|
||||
assert_eq!(event, &system_event);
|
||||
|
||||
@@ -121,18 +121,18 @@ impl DefaultVote for MoreThanMajorityThenPrimeDefaultVote {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Trait<I: Instance=DefaultInstance>: frame_system::Trait {
|
||||
pub trait Config<I: Instance=DefaultInstance>: frame_system::Config {
|
||||
/// The outer origin type.
|
||||
type Origin: From<RawOrigin<Self::AccountId, I>>;
|
||||
|
||||
/// The outer call dispatch type.
|
||||
type Proposal: Parameter
|
||||
+ Dispatchable<Origin=<Self as Trait<I>>::Origin, PostInfo=PostDispatchInfo>
|
||||
+ Dispatchable<Origin=<Self as Config<I>>::Origin, PostInfo=PostDispatchInfo>
|
||||
+ From<frame_system::Call<Self>>
|
||||
+ GetDispatchInfo;
|
||||
|
||||
/// The outer event type.
|
||||
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Trait>::Event>;
|
||||
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Config>::Event>;
|
||||
|
||||
/// The time-out for council motions.
|
||||
type MotionDuration: Get<Self::BlockNumber>;
|
||||
@@ -166,7 +166,7 @@ pub enum RawOrigin<AccountId, I> {
|
||||
}
|
||||
|
||||
/// Origin for the collective module.
|
||||
pub type Origin<T, I=DefaultInstance> = RawOrigin<<T as frame_system::Trait>::AccountId, I>;
|
||||
pub type Origin<T, I=DefaultInstance> = RawOrigin<<T as frame_system::Config>::AccountId, I>;
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
|
||||
/// Info for keeping track of a motion being voted on.
|
||||
@@ -184,12 +184,12 @@ pub struct Votes<AccountId, BlockNumber> {
|
||||
}
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait<I>, I: Instance=DefaultInstance> as Collective {
|
||||
trait Store for Module<T: Config<I>, I: Instance=DefaultInstance> as Collective {
|
||||
/// The hashes of the active proposals.
|
||||
pub Proposals get(fn proposals): Vec<T::Hash>;
|
||||
/// Actual proposal for a given hash, if it's current.
|
||||
pub ProposalOf get(fn proposal_of):
|
||||
map hasher(identity) T::Hash => Option<<T as Trait<I>>::Proposal>;
|
||||
map hasher(identity) T::Hash => Option<<T as Config<I>>::Proposal>;
|
||||
/// Votes on a given proposal, if it is ongoing.
|
||||
pub Voting get(fn voting):
|
||||
map hasher(identity) T::Hash => Option<Votes<T::AccountId, T::BlockNumber>>;
|
||||
@@ -209,8 +209,8 @@ decl_storage! {
|
||||
|
||||
decl_event! {
|
||||
pub enum Event<T, I=DefaultInstance> where
|
||||
<T as frame_system::Trait>::Hash,
|
||||
<T as frame_system::Trait>::AccountId,
|
||||
<T as frame_system::Config>::Hash,
|
||||
<T as frame_system::Config>::AccountId,
|
||||
{
|
||||
/// A motion (given hash) has been proposed (by given account) with a threshold (given
|
||||
/// `MemberCount`).
|
||||
@@ -239,7 +239,7 @@ decl_event! {
|
||||
}
|
||||
|
||||
decl_error! {
|
||||
pub enum Error for Module<T: Trait<I>, I: Instance> {
|
||||
pub enum Error for Module<T: Config<I>, I: Instance> {
|
||||
/// Account is not a member
|
||||
NotMember,
|
||||
/// Duplicate proposals not allowed
|
||||
@@ -276,7 +276,7 @@ fn get_result_weight(result: DispatchResultWithPostInfo) -> Option<Weight> {
|
||||
|
||||
// Note that councillor operations are assigned to the operational class.
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait<I>, I: Instance=DefaultInstance> for enum Call where origin: <T as frame_system::Trait>::Origin {
|
||||
pub struct Module<T: Config<I>, I: Instance=DefaultInstance> for enum Call where origin: <T as frame_system::Config>::Origin {
|
||||
type Error = Error<T, I>;
|
||||
|
||||
fn deposit_event() = default;
|
||||
@@ -365,7 +365,7 @@ decl_module! {
|
||||
DispatchClass::Operational
|
||||
)]
|
||||
fn execute(origin,
|
||||
proposal: Box<<T as Trait<I>>::Proposal>,
|
||||
proposal: Box<<T as Config<I>>::Proposal>,
|
||||
#[compact] length_bound: u32,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
let who = ensure_signed(origin)?;
|
||||
@@ -432,7 +432,7 @@ decl_module! {
|
||||
)]
|
||||
fn propose(origin,
|
||||
#[compact] threshold: MemberCount,
|
||||
proposal: Box<<T as Trait<I>>::Proposal>,
|
||||
proposal: Box<<T as Config<I>>::Proposal>,
|
||||
#[compact] length_bound: u32
|
||||
) -> DispatchResultWithPostInfo {
|
||||
let who = ensure_signed(origin)?;
|
||||
@@ -682,7 +682,7 @@ decl_module! {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait<I>, I: Instance> Module<T, I> {
|
||||
impl<T: Config<I>, I: Instance> Module<T, I> {
|
||||
/// Check whether `who` is a member of the collective.
|
||||
pub fn is_member(who: &T::AccountId) -> bool {
|
||||
// Note: The dispatchables *do not* use this to check membership so make sure
|
||||
@@ -698,7 +698,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
|
||||
hash: &T::Hash,
|
||||
length_bound: u32,
|
||||
weight_bound: Weight
|
||||
) -> Result<(<T as Trait<I>>::Proposal, usize), DispatchError> {
|
||||
) -> Result<(<T as Config<I>>::Proposal, usize), DispatchError> {
|
||||
let key = ProposalOf::<T, I>::hashed_key_for(hash);
|
||||
// read the length of the proposal storage entry directly
|
||||
let proposal_len = storage::read(&key, &mut [0; 0], 0)
|
||||
@@ -728,7 +728,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
|
||||
seats: MemberCount,
|
||||
voting: Votes<T::AccountId, T::BlockNumber>,
|
||||
proposal_hash: T::Hash,
|
||||
proposal: <T as Trait<I>>::Proposal,
|
||||
proposal: <T as Config<I>>::Proposal,
|
||||
) -> (Weight, u32) {
|
||||
Self::deposit_event(RawEvent::Approved(proposal_hash));
|
||||
|
||||
@@ -764,7 +764,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait<I>, I: Instance> ChangeMembers<T::AccountId> for Module<T, I> {
|
||||
impl<T: Config<I>, I: Instance> ChangeMembers<T::AccountId> for Module<T, I> {
|
||||
/// Update the members of the collective. Votes are updated and the prime is reset.
|
||||
///
|
||||
/// NOTE: Does not enforce the expected `MaxMembers` limit on the amount of members, but
|
||||
@@ -819,7 +819,7 @@ impl<T: Trait<I>, I: Instance> ChangeMembers<T::AccountId> for Module<T, I> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait<I>, I: Instance> InitializeMembers<T::AccountId> for Module<T, I> {
|
||||
impl<T: Config<I>, I: Instance> InitializeMembers<T::AccountId> for Module<T, I> {
|
||||
fn initialize_members(members: &[T::AccountId]) {
|
||||
if !members.is_empty() {
|
||||
assert!(<Members<T, I>>::get().is_empty(), "Members are already initialized!");
|
||||
@@ -952,7 +952,7 @@ mod tests {
|
||||
pub const MaxProposals: u32 = 100;
|
||||
pub const MaxMembers: u32 = 100;
|
||||
}
|
||||
impl frame_system::Trait for Test {
|
||||
impl frame_system::Config for Test {
|
||||
type BaseCallFilter = ();
|
||||
type Origin = Origin;
|
||||
type Index = u64;
|
||||
@@ -979,7 +979,7 @@ mod tests {
|
||||
type OnKilledAccount = ();
|
||||
type SystemWeightInfo = ();
|
||||
}
|
||||
impl Trait<Instance1> for Test {
|
||||
impl Config<Instance1> for Test {
|
||||
type Origin = Origin;
|
||||
type Proposal = Call;
|
||||
type Event = Event;
|
||||
@@ -989,7 +989,7 @@ mod tests {
|
||||
type DefaultVote = PrimeDefaultVote;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
impl Trait<Instance2> for Test {
|
||||
impl Config<Instance2> for Test {
|
||||
type Origin = Origin;
|
||||
type Proposal = Call;
|
||||
type Event = Event;
|
||||
@@ -999,7 +999,7 @@ mod tests {
|
||||
type DefaultVote = MoreThanMajorityThenPrimeDefaultVote;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
impl Trait for Test {
|
||||
impl Config for Test {
|
||||
type Origin = Origin;
|
||||
type Proposal = Call;
|
||||
type Event = Event;
|
||||
|
||||
@@ -58,7 +58,7 @@ pub trait WeightInfo {
|
||||
|
||||
/// Weights for pallet_collective using the Substrate node and recommended hardware.
|
||||
pub struct SubstrateWeight<T>(PhantomData<T>);
|
||||
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
|
||||
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
fn set_members(m: u32, n: u32, p: u32, ) -> Weight {
|
||||
(0 as Weight)
|
||||
.saturating_add((20_933_000 as Weight).saturating_mul(m as Weight))
|
||||
|
||||
Reference in New Issue
Block a user