Skip to content

Commit

Permalink
refac: resolved suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Honza committed Jan 2, 2025
1 parent a6a14ce commit cc61914
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pallets/emission0/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub mod pallet {
<Self::Currency as Currency<Self::AccountId>>::NegativeImbalance,
>;

type Governance: GovernanceApi<Self::AccountId, OriginFor<Self>>;
type Governance: GovernanceApi<Self::AccountId>;
}

#[pallet::pallet]
Expand Down
12 changes: 6 additions & 6 deletions pallets/emission0/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ pub fn set_weights<T: crate::Config>(
origin: OriginFor<T>,
mut weights: sp_std::vec::Vec<(T::AccountId, u16)>,
) -> DispatchResult {
let acc_id = ensure_signed(origin.clone())?;
let acc_id = ensure_signed(origin)?;

<T::Governance>::ensure_allocator(origin)?;
<T::Governance>::ensure_allocator(&acc_id)?;

ensure!(
!crate::WeightControlDelegation::<T>::contains_key(&acc_id),
crate::Error::<T>::CannotSetWeightsWhileDelegating
);

ensure!(
<T::Torus>::is_agent_registered(&acc_id),
crate::Error::<T>::AgentIsNotRegistered
weights.len() <= crate::MaxAllowedWeights::<T>::get() as usize,
crate::Error::<T>::WeightSetTooLarge
);

ensure!(
weights.len() <= crate::MaxAllowedWeights::<T>::get() as usize,
crate::Error::<T>::WeightSetTooLarge
<T::Torus>::is_agent_registered(&acc_id),
crate::Error::<T>::AgentIsNotRegistered
);

let total_stake: u128 = <T::Torus>::staked_by(&acc_id)
Expand Down
4 changes: 2 additions & 2 deletions pallets/governance/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

use polkadot_sdk::{frame_support::dispatch::DispatchResult, sp_runtime::Percent};

pub trait GovernanceApi<AccountId, Origin> {
pub trait GovernanceApi<AccountId> {
fn dao_treasury_address() -> AccountId;

fn treasury_emission_fee() -> Percent;

fn is_whitelisted(key: &AccountId) -> bool;

fn ensure_allocator(key: Origin) -> DispatchResult;
fn ensure_allocator(key: &AccountId) -> DispatchResult;
}
6 changes: 3 additions & 3 deletions pallets/governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ pub mod pallet {
}
}

impl<T: Config> pallet_governance_api::GovernanceApi<T::AccountId, OriginFor<T>> for Pallet<T> {
impl<T: Config> pallet_governance_api::GovernanceApi<T::AccountId> for Pallet<T> {
fn dao_treasury_address() -> T::AccountId {
DaoTreasuryAddress::<T>::get()
}
Expand All @@ -410,7 +410,7 @@ impl<T: Config> pallet_governance_api::GovernanceApi<T::AccountId, OriginFor<T>>
whitelist::is_whitelisted::<T>(key)
}

fn ensure_allocator(origin: OriginFor<T>) -> DispatchResult {
crate::roles::ensure_allocator::<T>(origin)
fn ensure_allocator(key: &T::AccountId) -> DispatchResult {
crate::roles::ensure_allocator::<T>(key)
}
}
3 changes: 1 addition & 2 deletions pallets/governance/src/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ pub fn ensure_curator<T: Config>(origin: OriginFor<T>) -> DispatchResult {
Ok(())
}

pub fn ensure_allocator<T: Config>(origin: OriginFor<T>) -> DispatchResult {
let key: AccountIdOf<T> = ensure_signed(origin)?;
pub fn ensure_allocator<T: Config>(key: &AccountIdOf<T>) -> DispatchResult {
if !crate::Allocators::<T>::contains_key(key) {
return Err(Error::<T>::NotAllocator.into());
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/torus0/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub mod pallet {

type Currency: Currency<Self::AccountId, Balance = u128> + Send + Sync;

type Governance: GovernanceApi<Self::AccountId, Self::RuntimeOrigin>;
type Governance: GovernanceApi<Self::AccountId>;

type Emission: Emission0Api<Self::AccountId>;
}
Expand Down

0 comments on commit cc61914

Please sign in to comment.