-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handling a community-governed treasury account (#300)
* chore(communities:tests): remove qualified references to sp_runtime::DispatchError * refactor(communities:functions): simplify qualified references to types and traits * feat(pallets/communities): implement assets_transfer * feat(pallets/communities): implement balance_transfer * chore(pallets/communities): update docs * fix(communities:functions/tokens): apply fmt * refactor(communities:functions/tokens): rename mod to treasury * refactor(communities:functions): move do_create_community_account to treasury module * chore(communities:functions/registration): rename as registry * m:change(communities:registry): directly override value on do_set_metadata
- Loading branch information
Showing
12 changed files
with
402 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
pub(self) use crate::*; | ||
pub(self) use frame_support::pallet_prelude::*; | ||
pub(self) use frame_support::traits::tokens::{ | ||
fungible::{Inspect, Mutate, MutateFreeze}, | ||
fungibles::Mutate as MutateFuns, | ||
}; | ||
pub(self) use frame_system::pallet_prelude::*; | ||
pub(self) use types::*; | ||
|
||
mod challenges; | ||
mod getters; | ||
mod membership; | ||
mod registration; | ||
mod registry; | ||
mod treasury; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use super::*; | ||
|
||
impl<T: Config> Pallet<T> { | ||
pub(crate) fn community_exists(community_id: &CommunityIdOf<T>) -> bool { | ||
Self::community(community_id).is_some() | ||
} | ||
|
||
/// 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(who: &AccountIdOf<T>, community_id: &CommunityIdOf<T>) -> DispatchResult { | ||
// Check that the community doesn't exist | ||
if Self::community_exists(community_id) { | ||
return Err(Error::<T>::CommunityAlreadyExists.into()); | ||
} | ||
|
||
<CommunityInfo<T>>::insert( | ||
community_id.clone(), | ||
Community { | ||
admin: who.clone(), | ||
state: Default::default(), | ||
sufficient_asset_id: None, | ||
}, | ||
); | ||
|
||
Self::do_insert_member(community_id, who)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub(crate) fn do_set_metadata( | ||
community_id: &CommunityIdOf<T>, | ||
value: types::CommunityMetadata<T>, | ||
) -> DispatchResult { | ||
<pallet::CommunityMetadata<T>>::try_mutate(community_id, |metadata| { | ||
*metadata = Some(value); | ||
|
||
Ok(()) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use super::*; | ||
use frame_support::traits::tokens::Preservation; | ||
|
||
impl<T: Config> Pallet<T> { | ||
/// Takes a deposit from the caller and | ||
pub(crate) fn do_create_community_account( | ||
caller: &AccountIdOf<T>, | ||
community_id: &CommunityIdOf<T>, | ||
) -> DispatchResult { | ||
let community_account_id = Self::get_community_account_id(community_id); | ||
let minimum_balance = T::Balances::minimum_balance(); | ||
|
||
T::Balances::transfer( | ||
caller, | ||
&community_account_id, | ||
minimum_balance, | ||
frame_support::traits::tokens::Preservation::Preserve, | ||
)?; | ||
|
||
// Lock funds so the account can exist at all times | ||
T::Balances::set_freeze(&T::FreezeIdentifier::get(), &community_account_id, minimum_balance)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub(crate) fn do_assets_transfer( | ||
community_id: &CommunityIdOf<T>, | ||
asset_id: AssetIdOf<T>, | ||
dest: &AccountIdOf<T>, | ||
amount: BalanceOf<T>, | ||
) -> DispatchResult { | ||
let community_account_id = Self::get_community_account_id(community_id); | ||
T::Assets::transfer(asset_id, &community_account_id, dest, amount, Preservation::Preserve)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub(crate) fn do_balance_transfer( | ||
community_id: &CommunityIdOf<T>, | ||
dest: &AccountIdOf<T>, | ||
amount: NativeBalanceOf<T>, | ||
) -> DispatchResult { | ||
let community_account_id = Self::get_community_account_id(community_id); | ||
T::Balances::transfer(&community_account_id, dest, amount, Preservation::Preserve)?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.