From 8283aa115bb6719116a848fc4e465cb1742000c2 Mon Sep 17 00:00:00 2001 From: Daniel Olano Date: Thu, 9 May 2024 03:40:31 +0200 Subject: [PATCH] Create communities only via the manager (#392) --- pallets/communities-manager/src/lib.rs | 7 ++++++- pallets/communities-manager/src/mock/mod.rs | 8 +++++--- runtime/kreivo/src/communities/mod.rs | 9 ++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pallets/communities-manager/src/lib.rs b/pallets/communities-manager/src/lib.rs index c03c4ea6..77134226 100644 --- a/pallets/communities-manager/src/lib.rs +++ b/pallets/communities-manager/src/lib.rs @@ -69,6 +69,11 @@ pub mod pallet { /// Type representing the weight of this pallet type WeightInfo: WeightInfo; + type RegisterOrigin: EnsureOrigin< + OriginFor, + Success = Option<(NativeBalanceOf, AccountIdOf, AccountIdOf)>, + >; + type CreateMembershipsOrigin: EnsureOrigin>; type MembershipId: Parameter + Decode + Incrementable + HasCompact; @@ -135,7 +140,7 @@ pub mod pallet { maybe_track_info: Option>, // _maybe_first_member: Option>, ) -> 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::::InvalidCommunityName)?; let community_origin: RuntimeOriginFor = CommunityOrigin::::new(community_id).into(); diff --git a/pallets/communities-manager/src/mock/mod.rs b/pallets/communities-manager/src/mock/mod.rs index c738c039..c9354418 100644 --- a/pallets/communities-manager/src/mock/mod.rs +++ b/pallets/communities-manager/src/mock/mod.rs @@ -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; @@ -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 { @@ -221,7 +222,7 @@ impl pallet_communities::Config for Test { type Balances = Balances; type MemberMgmt = Memberships; type Polls = Referenda; - type CreateOrigin = EnsureRootWithSuccess; + type CreateOrigin = EnsureNever; type AdminOrigin = EnsureCommunity; type MemberMgmtOrigin = EnsureCommunity; type RuntimeCall = RuntimeCall; @@ -239,6 +240,7 @@ impl Config for Test { type CreateCollection = Memberships; type Tracks = Tracks; type RankedCollective = Collective; + type RegisterOrigin = EnsureRootWithSuccess; // Types to support memberships creation type CreateMembershipsOrigin = EnsureRoot; type MembershipId = MembershipId; diff --git a/runtime/kreivo/src/communities/mod.rs b/runtime/kreivo/src/communities/mod.rs index cd1d54e3..3b60cd21 100644 --- a/runtime/kreivo/src/communities/mod.rs +++ b/runtime/kreivo/src/communities/mod.rs @@ -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}; @@ -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! { @@ -51,7 +53,7 @@ type AnyoneElsePays = EnsureSignedPays; + type CreateOrigin = EnsureNever; type AdminOrigin = EitherOf, EnsureCommunityAccount>; type MemberMgmtOrigin = EitherOf, EnsureCommunityAccount>; type MemberMgmt = CommunityMemberships; @@ -79,6 +81,7 @@ impl pallet_communities_manager::Config for Runtime { type CreateCollection = CommunityMemberships; type Tracks = CommunityTracks; type RankedCollective = KreivoCollective; + type RegisterOrigin = EitherOf; type CreateMembershipsOrigin = EnsureRoot; type MembershipId = MembershipId;