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

Alliance pallet: retirement notice call #11970

Merged
merged 17 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions frame/alliance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub mod weights;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use sp_runtime::{
traits::{StaticLookup, Zero},
traits::{Saturating, StaticLookup, Zero},
RuntimeDebug,
};
use sp_std::{convert::TryInto, prelude::*};
Expand Down Expand Up @@ -315,7 +315,7 @@ pub mod pallet {
/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;

/// The period required to pass from retirement notice for a member to retire.
/// The number of blocks a member must wait between giving a retirement notice and retiring.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: wait for*

/// Supposed to be greater than time required to `kick_member`.
type RetirementPeriod: Get<Self::BlockNumber>;
bkontur marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down Expand Up @@ -806,13 +806,14 @@ pub mod pallet {
pub fn give_retirement_notice(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
let role = Self::member_role_of(&who).ok_or(Error::<T, I>::NotMember)?;
ensure!(!role.eq(&MemberRole::Retiring), Error::<T, I>::AlreadyRetiring);
ensure!(role.ne(&MemberRole::Retiring), Error::<T, I>::AlreadyRetiring);

Self::remove_member(&who, role)?;
Self::add_member(&who, MemberRole::Retiring)?;
<RetiringMembers<T, I>>::insert(
&who,
frame_system::Pallet::<T>::block_number() + T::RetirementPeriod::get(),
frame_system::Pallet::<T>::block_number()
.saturating_add(T::RetirementPeriod::get()),
);

Self::deposit_event(Event::MemberRetirementPeriodStarted { member: who });
Expand Down
12 changes: 7 additions & 5 deletions frame/alliance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ pub use crate as pallet_alliance;

use super::*;

type BlockNumber = u64;

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const BlockHashCount: BlockNumber = 250;
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
Expand All @@ -47,7 +49,7 @@ impl frame_system::Config for Test {
type Origin = Origin;
type Call = Call;
type Index = u64;
type BlockNumber = u64;
type BlockNumber = BlockNumber;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
Expand Down Expand Up @@ -83,10 +85,10 @@ impl pallet_balances::Config for Test {
type ReserveIdentifier = [u8; 8];
}

const MOTION_DURATION: u64 = 3;
const MOTION_DURATION: BlockNumber = 3;

parameter_types! {
pub const MotionDuration: u64 = MOTION_DURATION;
pub const MotionDuration: BlockNumber = MOTION_DURATION;
pub const MaxProposals: u32 = 100;
pub const MaxMembers: u32 = 100;
}
Expand Down Expand Up @@ -201,7 +203,7 @@ parameter_types! {
pub const MaxFellows: u32 = MaxMembers::get() - MaxFounders::get();
pub const MaxAllies: u32 = 100;
pub const AllyDeposit: u64 = 25;
pub const RetirementPeriod: u64 = MOTION_DURATION + 1;
pub const RetirementPeriod: BlockNumber = MOTION_DURATION + 1;
}
impl Config for Test {
type Event = Event;
Expand Down