Skip to content

Commit

Permalink
Extract membership management to use external non-funginle memberships
Browse files Browse the repository at this point in the history
Use dedicated origins for all extrinsics
Refactor and remove unused functionalities
  • Loading branch information
olanod committed Dec 4, 2023
1 parent 8ae6124 commit 190f5db
Show file tree
Hide file tree
Showing 18 changed files with 1,143 additions and 1,136 deletions.
984 changes: 562 additions & 422 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ frame-system-benchmarking = { default-features = false, git = "https://github.c
frame-system-rpc-runtime-api = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }

## Substrate Pallet Dependencies
pallet-assets = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-asset-tx-payment = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-assets = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-aura = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-authorship = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-balances = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
Expand All @@ -129,13 +129,14 @@ pallet-democracy = { default-features = false, git = "https://github.com/virto-
pallet-identity = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-insecure-randomness-collective-flip = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-multisig = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-proxy = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-nfts = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-preimage = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-proxy = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-referenda = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-referenda-tracks = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-remark = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-session = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-scheduler = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-session = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-sudo = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-timestamp = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-transaction-payment = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
Expand Down
8 changes: 6 additions & 2 deletions pallets/communities/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,35 @@ frame-support = { workspace = true }
frame-system = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
xcm = { workspace = true, optional = true }

[dev-dependencies]
sp-core = { workspace = true }
sp-io = { workspace = true }

pallet-assets = { workspace = true }
pallet-balances = { workspace = true }
pallet-nfts = { workspace = true }
pallet-preimage = { workspace = true }
pallet-referenda = { workspace = true }
pallet-referenda-tracks = { workspace = true }
pallet-scheduler = { workspace = true }

[features]
default = ["std"]
default = ["std", "xcm"]
std = [
"parity-scale-codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"pallet-assets/std",
"pallet-balances/std",
"pallet-nfts/std",
"pallet-referenda/std",
"parity-scale-codec/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
"xcm?/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
72 changes: 72 additions & 0 deletions pallets/communities/src/functions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use crate::{
types::{
AccountIdOf, CommunityIdOf, CommunityInfo, CommunityMetadata, CommunityState, ConstSizedField, MembershipId,
PalletsOriginOf,
},
CommunityIdFor, Config, Error, Info, Metadata, Pallet,
};
use frame_support::{
pallet_prelude::*,
traits::{GenericRank, MembershipInspect, RankedMembership},
};
use sp_runtime::traits::AccountIdConversion;
use sp_std::vec::Vec;

impl<T: Config> Pallet<T> {
#[inline]
pub fn community_account(community_id: &T::CommunityId) -> AccountIdOf<T> {
T::PalletId::get().into_sub_account_truncating(community_id)
}

pub fn community_exists(community_id: &T::CommunityId) -> bool {
Self::community(community_id).is_some()
}

pub fn has_membership(who: &AccountIdOf<T>, m: MembershipId<T::CommunityId>) -> bool {
T::Memberships::has_membership(m, who)
}

pub fn member_rank(who: &AccountIdOf<T>, m: MembershipId<T::CommunityId>) -> Option<GenericRank> {
T::Memberships::get_membership(m, who).map(|m| *m.rank())
}

pub fn get_memberships(who: &AccountIdOf<T>, community_id: &T::CommunityId) -> Vec<MembershipId<T::CommunityId>> {
T::Memberships::account_memberships(who)
.filter(|m| &m.0 == community_id)
.collect()
}

pub fn force_state(community_id: &CommunityIdOf<T>, state: CommunityState) {
Info::<T>::mutate(community_id, |c| c.as_mut().map(|c| c.state = state));
}

/// Stores an initial info about the community
/// Sets the caller as the community admin, the initial community state
/// to its default value(awaiting)
pub(crate) fn do_register_community(admin: &PalletsOriginOf<T>, community_id: &T::CommunityId) -> DispatchResult {
if Self::community_exists(community_id) {
return Err(Error::<T>::CommunityAlreadyExists.into());
}

CommunityIdFor::<T>::insert(admin, community_id);
Info::<T>::insert(community_id, CommunityInfo::default());
frame_system::Pallet::<T>::inc_providers(&Self::community_account(community_id));

Ok(())
}

pub(crate) fn do_set_metadata(
community_id: &CommunityIdOf<T>,
name: &Option<ConstSizedField<64>>,
description: &Option<ConstSizedField<256>>,
url: &Option<ConstSizedField<256>>,
) {
Metadata::<T>::mutate(community_id, |metadata| {
*metadata = CommunityMetadata {
name: name.as_ref().unwrap_or(&metadata.name).clone(),
description: description.as_ref().unwrap_or(&metadata.description).clone(),
main_url: url.as_ref().unwrap_or(&metadata.main_url).clone(),
};
})
}
}
30 changes: 0 additions & 30 deletions pallets/communities/src/functions/challenges.rs

This file was deleted.

18 changes: 0 additions & 18 deletions pallets/communities/src/functions/getters.rs

This file was deleted.

86 changes: 0 additions & 86 deletions pallets/communities/src/functions/membership.rs

This file was deleted.

4 changes: 0 additions & 4 deletions pallets/communities/src/functions/mod.rs

This file was deleted.

41 changes: 0 additions & 41 deletions pallets/communities/src/functions/registry.rs

This file was deleted.

Loading

0 comments on commit 190f5db

Please sign in to comment.