Skip to content

Commit

Permalink
chore(pallets/communities): split governance functionalities
Browse files Browse the repository at this point in the history
  • Loading branch information
pandres95 committed Nov 16, 2023
1 parent 8ec6cf9 commit fd3a34c
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 52 deletions.
4 changes: 4 additions & 0 deletions pallets/communities/src/functions/governance/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use super::*;

mod tally;
mod tracks;
27 changes: 27 additions & 0 deletions pallets/communities/src/functions/governance/tally.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use super::*;

use frame_support::traits::VoteTally;

impl<A, B> From<Vote<A, B>> for VoteWeight {
fn from(_value: Vote<A, B>) -> Self {
todo!()
}
}

impl<T: Config> VoteTally<VoteWeight, CommunityIdOf<T>> for Tally<T> {
fn new(_: CommunityIdOf<T>) -> Self {
todo!()
}

fn ayes(&self, _cid: CommunityIdOf<T>) -> VoteWeight {
todo!()
}

fn support(&self, _cid: CommunityIdOf<T>) -> sp_runtime::Perbill {
todo!()
}

fn approval(&self, _cid: CommunityIdOf<T>) -> sp_runtime::Perbill {
todo!()
}
}
43 changes: 43 additions & 0 deletions pallets/communities/src/functions/governance/tracks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use super::*;

use pallet_referenda::{Track, TracksInfo};
use sp_std::borrow::Cow;

// #[cfg(feature = "referenda")]
impl<T: Config> TracksInfo<VoteWeight, BlockNumberFor<T>> for CommunityTracks<T> {
type Id = T::CommunityId;
type RuntimeOrigin = RuntimeOriginOf<T>;

fn tracks() -> impl Iterator<Item = Cow<'static, Track<Self::Id, types::VoteWeight, BlockNumberFor<T>>>> {
//TODO: Convert from a list of community IDs to list of tracks"

// Info::<T>::iter_keys().map(|community_id| Track {
// id: community_id,
// info: TrackInfo {
// name: "".into(),
// max_deciding: 0,
// decision_deposit: 0,
// prepare_period: 100,
// decision_period: 100,
// confirm_period: 100,
// min_enactment_period: 100,
// min_approval: pallet_referenda::Curve::LinearDecreasing {
// length: 1.into(),
// floor: 1.into(),
// ceil: 1.into(),
// },
// min_support: pallet_referenda::Curve::LinearDecreasing {
// length: 1.into(),
// floor: 1.into(),
// ceil: 1.into(),
// },
// },
// })

vec![].into_iter()
}

fn track_for(_origin: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
todo!("Convert the signed as community account id into the track Id for the community track")
}
}
1 change: 1 addition & 0 deletions pallets/communities/src/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ pub(self) use types::*;

mod challenges;
mod getters;
mod governance;
mod membership;
mod registry;
7 changes: 4 additions & 3 deletions pallets/communities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {
/// This type represents an unique ID for the community
type CommunityId: Default + Parameter + MaxEncodedLen;
type CommunityId: Default + Parameter + MaxEncodedLen + Sync + Send + Ord + Copy;

/// This type represents a rank for a member in a community
type Membership: Default + Parameter + MaxEncodedLen + MemberRank<u8>;
Expand Down Expand Up @@ -456,8 +456,9 @@ pub mod pallet {
_vote: VoteOf<T>,
) -> DispatchResult {
let _ = ensure_signed(origin)?;
// TODO
Ok(())
// let poll_index = Self::get_poll_index(&community_id);

todo!("Implement vote extrinsic")
}
}
}
1 change: 0 additions & 1 deletion pallets/communities/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const COMMUNITY: CommunityId = 1;
const COMMUNITY_ADMIN: AccountId = 42;

mod membership;
mod mock_poll;
mod registry;

fn setup() {
Expand Down
File renamed without changes.
43 changes: 0 additions & 43 deletions pallets/communities/src/types/governance.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use core::marker::PhantomData;

use frame_support::traits::VoteTally;
use frame_system::pallet_prelude::BlockNumberFor;
use pallet_referenda::{Track, TracksInfo};
use sp_std::borrow::Cow;

use super::*;

pub type VoteWeight = sp_runtime::Perbill;
Expand Down Expand Up @@ -50,50 +45,12 @@ pub enum Vote<AssetId, AssetBalance> {
Standard(bool),
}

impl<A, B> From<Vote<A, B>> for VoteWeight {
fn from(value: Vote<A, B>) -> Self {
todo!()
}
}

///
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Tally<T> {
_dummy: PhantomData<T>,
}

impl<T: Config> VoteTally<VoteWeight, CommunityIdOf<T>> for Tally<T> {
fn new(_: CommunityIdOf<T>) -> Self {
todo!()
}

fn ayes(&self, _cid: CommunityIdOf<T>) -> VoteWeight {
todo!()
}

fn support(&self, _cid: CommunityIdOf<T>) -> sp_runtime::Perbill {
todo!()
}

fn approval(&self, _cid: CommunityIdOf<T>) -> sp_runtime::Perbill {
todo!()
}
}

///
// #[cfg(feature = "referenda")]
pub struct CommunityTracks<T>(PhantomData<T>);

// #[cfg(feature = "referenda")]
impl<T: Config> TracksInfo<VoteWeight, BlockNumberFor<T>> for CommunityTracks<T> {
type Id = u16;
type RuntimeOrigin = RuntimeOriginOf<T>;

fn tracks() -> impl Iterator<Item = Cow<'static, Track<Self::Id, VoteWeight, BlockNumberFor<T>>>> {
todo!()
}

fn track_for(origin: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
todo!()
}
}
2 changes: 1 addition & 1 deletion pallets/communities/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use parity_scale_codec::MaxEncodedLen;
use scale_info::{prelude::vec::Vec, TypeInfo};
use sp_runtime::traits::StaticLookup;

use crate::Config;
use crate::*;
pub(crate) use frame_system::Config as SystemConfig;

pub use governance::*;
Expand Down
8 changes: 4 additions & 4 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "nightly-2023-10-30"
components = [ "rustfmt" ]
targets = [ "wasm32-unknown-unknown" ]
profile = "minimal"
channel = "nightly"
components = ["rustfmt"]
targets = ["wasm32-unknown-unknown"]
profile = "minimal"

0 comments on commit fd3a34c

Please sign in to comment.