Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce setting a first admin when creating a community #400

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pallets/communities-manager/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ mod benchmarks {
setup_account::<T>(&first_member)?;

let community_id: CommunityIdOf<T> = 1.into();
let admin_origin: RuntimeOriginFor<T> = frame_system::Origin::<T>::Signed(first_member.clone()).into();
let admin_origin_caller: PalletsOriginOf<T> = admin_origin.into_caller();
let first_admin = T::Lookup::unlookup(first_member.clone());

#[extrinsic_call]
_(
RawOrigin::Root,
community_id,
BoundedVec::truncate_from(b"Test Community".into()),
Some(admin_origin_caller.clone()),
first_admin,
None,
None,
);
Expand Down
18 changes: 12 additions & 6 deletions pallets/communities-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ use pallet_communities::{
use pallet_nfts::{CollectionConfig, ItemConfig};
use pallet_referenda::{TrackInfo, TracksInfo};
use parity_scale_codec::Decode;
use sp_runtime::{str_array, traits::Get};
use sp_runtime::{
str_array,
traits::{Get, StaticLookup},
};

type TrackInfoOf<T> = TrackInfo<NativeBalanceOf<T>, BlockNumberFor<T>>;

Expand Down Expand Up @@ -135,22 +138,24 @@ pub mod pallet {
origin: OriginFor<T>,
community_id: CommunityIdOf<T>,
name: CommunityName,
maybe_admin_origin: Option<PalletsOriginOf<T>>,
first_admin: pallet_communities::AccountIdLookupOf<T>,
maybe_decision_method: Option<DecisionMethodFor<T>>,
maybe_track_info: Option<TrackInfoOf<T>>,
// _maybe_first_member: Option<AccountIdLookupOf<T>>,
) -> DispatchResult {
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();
let admin_origin = maybe_admin_origin.unwrap_or(community_origin.clone().into_caller());

let first_admin_account_id = T::Lookup::lookup(first_admin)?;
let admin_origin = frame_system::Origin::<T>::Signed(first_admin_account_id);

// Register first to check if community exists
pallet_communities::Pallet::<T>::register(&admin_origin, &community_id, maybe_deposit)?;
pallet_communities::Pallet::<T>::register(&admin_origin.clone().into(), &community_id, maybe_deposit)?;

if let Some(decision_method) = maybe_decision_method {
pallet_communities::Pallet::<T>::set_decision_method(
admin_origin.clone().into(),
admin_origin.into(),
community_id,
decision_method,
)?;
Expand All @@ -171,6 +176,7 @@ pub mod pallet {
)?;

// Create governance track for community
let community_origin: RuntimeOriginFor<T> = CommunityOrigin::<T>::new(community_id).into();
T::Tracks::insert(
community_id,
maybe_track_info.unwrap_or_else(|| Self::default_tack(community_name)),
Expand Down