use super::*; use frame_support::{ dispatch::DispatchResultWithPostInfo, traits::PrivilegeCmp, }; use pallet_alliance::{ProposalIndex, ProposalProvider}; use sp_runtime::DispatchError; use sp_std::{cmp::Ordering, marker::PhantomData}; type AccountIdOf = ::AccountId; type ProposalOf = >::Proposal; type HashOf = ::Hash; /// Proposal provider for alliance pallet. /// Adapter from collective pallet to alliance proposal provider trait. pub struct AllianceProposalProvider(PhantomData<(T, I)>); impl ProposalProvider, HashOf, ProposalOf> for AllianceProposalProvider where T: pallet_collective::Config + frame_system::Config, I: 'static, { fn propose_proposal( who: AccountIdOf, threshold: u32, proposal: Box>, length_bound: u32, ) -> Result<(u32, u32), DispatchError> { pallet_collective::Pallet::::do_propose_proposed(who, threshold, proposal, length_bound) } fn vote_proposal( who: AccountIdOf, proposal: HashOf, index: ProposalIndex, approve: bool, ) -> Result { pallet_collective::Pallet::::do_vote(who, proposal, index, approve) } fn close_proposal( proposal_hash: HashOf, proposal_index: ProposalIndex, proposal_weight_bound: Weight, length_bound: u32, ) -> DispatchResultWithPostInfo { pallet_collective::Pallet::::do_close( proposal_hash, proposal_index, proposal_weight_bound, length_bound, ) } fn proposal_of(proposal_hash: HashOf) -> Option> { pallet_collective::ProposalOf::::get(proposal_hash) } } /// Used the compare the privilege of an origin inside the scheduler. pub struct EqualOrGreatestRootCmp; impl PrivilegeCmp for EqualOrGreatestRootCmp { fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option { if left == right { return Some(Ordering::Equal) } match (left, right) { // Root is greater than anything (OriginCaller::system(frame_system::RawOrigin::Root), _) => Some(Ordering::Greater), // For every other we don't care, as they are not used for `ScheduleOrigin`. _ => None, } } } #[cfg(feature = "runtime-benchmarks")] pub mod benchmarks { use super::*; use frame_support::traits::fungible; use pallet_ranked_collective::Rank; use sp_runtime::traits::Convert; /// Rank to salary conversion helper type pub struct RankToSalary(PhantomData); impl Convert for RankToSalary where Fungible: fungible::Inspect, { fn convert(r: Rank) -> Balance { Balance::from(r).saturating_mul(Fungible::minimum_balance()) } } }