Skip to content

Commit

Permalink
fix(pallets/communities): cleanup governance codebase + lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pandres95 committed Nov 16, 2023
1 parent fd3a34c commit 12f2f6b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 83 deletions.
12 changes: 8 additions & 4 deletions pallets/communities/src/functions/membership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ impl<T: Config> Pallet<T> {
community_id: &CommunityIdOf<T>,
) -> Result<Option<AccountIdOf<T>>, DispatchError> {
if let Some(caller) = ensure_signed_or_root(origin)? {
if let Some(admin) = Self::get_community_admin(community_id) && admin == caller {
return Ok(Some(admin))
if let Some(admin) = Self::get_community_admin(community_id)
&& admin == caller
{
return Ok(Some(admin));
} else {
return Err(DispatchError::BadOrigin)
return Err(DispatchError::BadOrigin);
}
}

Expand Down Expand Up @@ -58,7 +60,9 @@ impl<T: Config> Pallet<T> {
return Err(Error::<T>::NotAMember.into());
}

if let Some(community_admin) = Self::get_community_admin(community_id) && community_admin == *who {
if let Some(community_admin) = Self::get_community_admin(community_id)
&& community_admin == *who
{
return Err(Error::<T>::CannotRemoveAdmin.into());
}

Expand Down
8 changes: 4 additions & 4 deletions pallets/communities/src/functions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub(self) use crate::*;
pub(self) use frame_support::pallet_prelude::*;
pub(self) use frame_system::pallet_prelude::*;
pub(self) use types::*;
use crate::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use types::*;

mod challenges;
mod getters;
Expand Down
4 changes: 2 additions & 2 deletions pallets/communities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ pub mod pallet {
// Ensures caller is a privileged origin
Self::ensure_origin_privileged(origin, &community_id)?;

let metadata = Self::metadata(&community_id).unwrap_or_default();
let metadata = Self::metadata(community_id).unwrap_or_default();

// Deposits metadata
Self::do_set_metadata(
Expand Down Expand Up @@ -452,7 +452,7 @@ pub mod pallet {
#[pallet::call_index(4)]
pub fn vote(
origin: OriginFor<T>,
#[pallet::compact] poll_index: PollIndexOf<T>,
#[pallet::compact] _poll_index: PollIndexOf<T>,
_vote: VoteOf<T>,
) -> DispatchResult {
let _ = ensure_signed(origin)?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod poll;

use frame_support::{
parameter_types,
traits::{
Expand All @@ -17,7 +19,7 @@ use sp_runtime::{

use crate as pallet_communities;

use super::mock_poll::TestPolls;
use poll::TestPolls;

type Block = frame_system::mocking::MockBlock<Test>;
type WeightInfo = ();
Expand Down
File renamed without changes.
75 changes: 3 additions & 72 deletions pallets/communities/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ pub trait WeightInfo {
fn set_metadata() -> Weight;
fn add_member() -> Weight;
fn remove_member() -> Weight;
fn assets_transfer() -> Weight;
fn balance_transfer() -> Weight;
fn open_proposal() -> Weight;
fn execute() -> Weight;
fn vote() -> Weight;
}

/// Weights for pallet_communities using the Substrate node and recommended hardware.
Expand Down Expand Up @@ -93,40 +90,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {

/// Storage: Communities Something (r:0 w:1)
/// Proof: Communities Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn assets_transfer() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 8_000_000 picoseconds.
Weight::from_parts(9_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}

/// Storage: Communities Something (r:0 w:1)
/// Proof: Communities Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn balance_transfer() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 8_000_000 picoseconds.
Weight::from_parts(9_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}

/// Storage: Communities Something (r:0 w:1)
/// Proof: Communities Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn open_proposal() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 8_000_000 picoseconds.
Weight::from_parts(9_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}

/// Storage: Communities Something (r:0 w:1)
/// Proof: Communities Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn execute() -> Weight {
fn vote() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
Expand Down Expand Up @@ -184,40 +148,7 @@ impl WeightInfo for () {

/// Storage: Communities Something (r:0 w:1)
/// Proof: Communities Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn assets_transfer() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 8_000_000 picoseconds.
Weight::from_parts(9_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}

/// Storage: Communities Something (r:0 w:1)
/// Proof: Communities Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn balance_transfer() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 8_000_000 picoseconds.
Weight::from_parts(9_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}

/// Storage: Communities Something (r:0 w:1)
/// Proof: Communities Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn open_proposal() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 8_000_000 picoseconds.
Weight::from_parts(9_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}

/// Storage: Communities Something (r:0 w:1)
/// Proof: Communities Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn execute() -> Weight {
fn vote() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
Expand Down

0 comments on commit 12f2f6b

Please sign in to comment.