Skip to content

Commit

Permalink
Create communities only via the manager
Browse files Browse the repository at this point in the history
  • Loading branch information
olanod committed May 9, 2024
1 parent 6e0b325 commit 9b7c349
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
7 changes: 6 additions & 1 deletion pallets/communities-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ pub mod pallet {
/// Type representing the weight of this pallet
type WeightInfo: WeightInfo;

type RegisterOrigin: EnsureOrigin<
OriginFor<Self>,
Success = Option<(NativeBalanceOf<Self>, AccountIdOf<Self>, AccountIdOf<Self>)>,
>;

type CreateMembershipsOrigin: EnsureOrigin<OriginFor<Self>>;

type MembershipId: Parameter + Decode + Incrementable + HasCompact;
Expand Down Expand Up @@ -135,7 +140,7 @@ pub mod pallet {
maybe_track_info: Option<TrackInfoOf<T>>,
// _maybe_first_member: Option<AccountIdLookupOf<T>>,
) -> DispatchResult {
let maybe_deposit = T::CreateOrigin::ensure_origin(origin)?;
let maybe_deposit = T::RegisterOrigin::ensure_origin(origin)?;

let community_name = core::str::from_utf8(&name).map_err(|_| Error::<T>::InvalidCommunityName)?;
let community_origin: RuntimeOriginFor<T> = CommunityOrigin::<T>::new(community_id).into();
Expand Down
8 changes: 5 additions & 3 deletions pallets/communities-manager/src/mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use frame_support::{
},
PalletId,
};
use frame_system::{EnsureRoot, EnsureRootWithSuccess, EnsureSigned};
use frame_system::{EnsureNever, EnsureRoot, EnsureRootWithSuccess, EnsureSigned};
use pallet_communities::{origin::EnsureCommunity, Tally, VoteWeight};
use parity_scale_codec::Compact;
use sp_core::H256;
Expand Down Expand Up @@ -175,12 +175,13 @@ impl pallet_referenda_tracks::Config for Test {
type BenchmarkHelper = TracksBenchmarkHelper;
}

type Deposit = Option<(Balance, AccountId, AccountId)>;
parameter_types! {
pub const CommunitiesPalletId: PalletId = PalletId(*b"kv/comms");
pub const MembershipsManagerCollectionId: CommunityId = 0;
pub const MembershipNftAttr: &'static [u8; 10] = b"membership";
pub const TestCommunity: CommunityId = 1;
pub const NoDepositOnRootRegistration: Option<(Balance, AccountId, AccountId)> = None;
pub const NoDepositOnRootRegistration: Deposit = None;
}

impl pallet_nfts::Config for Test {
Expand Down Expand Up @@ -221,7 +222,7 @@ impl pallet_communities::Config for Test {
type Balances = Balances;
type MemberMgmt = Memberships;
type Polls = Referenda;
type CreateOrigin = EnsureRootWithSuccess<AccountId, NoDepositOnRootRegistration>;
type CreateOrigin = EnsureNever<Deposit>;
type AdminOrigin = EnsureCommunity<Self>;
type MemberMgmtOrigin = EnsureCommunity<Self>;
type RuntimeCall = RuntimeCall;
Expand All @@ -239,6 +240,7 @@ impl Config for Test {
type CreateCollection = Memberships;
type Tracks = Tracks;
type RankedCollective = Collective;
type RegisterOrigin = EnsureRootWithSuccess<AccountId, NoDepositOnRootRegistration>;
// Types to support memberships creation
type CreateMembershipsOrigin = EnsureRoot<AccountId>;
type MembershipId = MembershipId;
Expand Down
9 changes: 6 additions & 3 deletions runtime/kreivo/src/communities/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;

use frame_support::traits::TryMapSuccess;
use frame_system::{EnsureRootWithSuccess, EnsureSigned};
use frame_system::{EnsureNever, EnsureRootWithSuccess, EnsureSigned};
use pallet_communities::origin::{EnsureCommunity, EnsureSignedPays};
use sp_runtime::{morph_types, traits::AccountIdConversion};
use virto_common::{CommunityId, MembershipId};
Expand Down Expand Up @@ -31,12 +31,14 @@ use {
sp_runtime::Perbill,
};

type CreationPayment = Option<(Balance, AccountId, AccountId)>;

parameter_types! {
pub const CommunityPalletId: PalletId = PalletId(*b"kv/cmtys");
pub const MembershipsCollectionId: CommunityId = 0;
pub const MembershipNftAttr: &'static [u8; 10] = b"membership";
pub const CommunityDepositAmount: Balance = UNITS / 2;
pub const NoPay: Option<(Balance, AccountId, AccountId)> = None;
pub const NoPay: CreationPayment = None;
}

morph_types! {
Expand All @@ -51,7 +53,7 @@ type AnyoneElsePays = EnsureSignedPays<Runtime, CommunityDepositAmount, Treasury

impl pallet_communities::Config for Runtime {
type CommunityId = CommunityId;
type CreateOrigin = EitherOf<RootCreatesCommunitiesForFree, AnyoneElsePays>;
type CreateOrigin = EnsureNever<CreationPayment>;
type AdminOrigin = EitherOf<EnsureCommunity<Self>, EnsureCommunityAccount>;
type MemberMgmtOrigin = EitherOf<EnsureCommunity<Self>, EnsureCommunityAccount>;
type MemberMgmt = CommunityMemberships;
Expand Down Expand Up @@ -79,6 +81,7 @@ impl pallet_communities_manager::Config for Runtime {
type CreateCollection = CommunityMemberships;
type Tracks = CommunityTracks;
type RankedCollective = KreivoCollective;
type RegisterOrigin = EitherOf<RootCreatesCommunitiesForFree, AnyoneElsePays>;

type CreateMembershipsOrigin = EnsureRoot<AccountId>;
type MembershipId = MembershipId;
Expand Down

0 comments on commit 9b7c349

Please sign in to comment.