diff --git a/pallets/department-funding/src/lib.rs b/pallets/department-funding/src/lib.rs index b0997f4..07f0deb 100644 --- a/pallets/department-funding/src/lib.rs +++ b/pallets/department-funding/src/lib.rs @@ -32,7 +32,7 @@ use frame_support::{ PalletId, }; use pallet_support::{ - ensure_content_is_valid, new_who_and_when, remove_from_vec, Content, PositiveExternalityPostId, + ensure_content_is_valid, new_who_and_when, remove_from_vec, Content, PostId, WhoAndWhen, WhoAndWhenOf, }; use schelling_game_shared::types::{Period, PhaseData, RangePoint, SchellingGameType}; diff --git a/pallets/positive-externality/src/extras.rs b/pallets/positive-externality/src/extras.rs index 3b891e3..710f3f8 100644 --- a/pallets/positive-externality/src/extras.rs +++ b/pallets/positive-externality/src/extras.rs @@ -2,9 +2,9 @@ use frame_support::dispatch::DispatchResult; use super::*; -impl PositiveExternalityPost { - pub fn new(id: PositiveExternalityPostId, created_by: T::AccountId, content: Content) -> Self { - PositiveExternalityPost { +impl Post { + pub fn new(id: PostId, created_by: T::AccountId, content: Content) -> Self { + Post { id, created: new_who_and_when::(created_by.clone()), edited: false, @@ -32,15 +32,15 @@ impl Pallet { } pub fn ensure_validation_on_positive_externality(account: T::AccountId) -> DispatchResult { - let bool_data = ValidatePositiveExternality::::get(account); + let bool_data = Validate::::get(account); ensure!(bool_data == true, Error::::ValidationPositiveExternalityIsOff); Ok(()) } pub fn ensure_min_stake_positive_externality(account: T::AccountId) -> DispatchResult { - let stake = PositiveExternalityStakeBalance::::get(account); - let min_stake = MinimumPositiveExternalityStake::::get(); + let stake = StakeBalance::::get(account); + let min_stake = MinimumStake::::get(); // println!("stake {:?}", stake); // println!("min stake {:?}", min_stake); ensure!(stake >= min_stake, Error::::LessThanMinStake); @@ -58,7 +58,7 @@ impl Pallet { pub(super) fn get_drawn_jurors(user_to_calculate: T::AccountId) -> Vec<(T::AccountId, u64)> { let pe_block_number = - >::get(user_to_calculate.clone()); + >::get(user_to_calculate.clone()); let key = SumTreeName::PositiveExternality { user_address: user_to_calculate, @@ -74,7 +74,7 @@ impl Pallet { let now = >::block_number(); let pe_block_number = - >::get(user_to_calculate.clone()); + >::get(user_to_calculate.clone()); let key = SumTreeName::PositiveExternality { user_address: user_to_calculate, @@ -93,7 +93,7 @@ impl Pallet { let now = >::block_number(); let pe_block_number = - >::get(user_to_calculate.clone()); + >::get(user_to_calculate.clone()); let key = SumTreeName::PositiveExternality { user_address: user_to_calculate, @@ -110,7 +110,7 @@ impl Pallet { pub fn get_drawing_period_end(user_to_calculate: T::AccountId) -> (u64, u64, bool) { let pe_block_number = - >::get(user_to_calculate.clone()); + >::get(user_to_calculate.clone()); let key = SumTreeName::PositiveExternality { user_address: user_to_calculate, @@ -127,7 +127,7 @@ impl Pallet { let now = >::block_number(); let pe_block_number = - >::get(user_to_calculate.clone()); + >::get(user_to_calculate.clone()); let key = SumTreeName::PositiveExternality { user_address: user_to_calculate, @@ -146,7 +146,7 @@ impl Pallet { let now = >::block_number(); let pe_block_number = - >::get(user_to_calculate.clone()); + >::get(user_to_calculate.clone()); let key = SumTreeName::PositiveExternality { user_address: user_to_calculate, @@ -163,7 +163,7 @@ impl Pallet { pub fn selected_as_juror(user_to_calculate: T::AccountId, who: T::AccountId) -> bool { let pe_block_number = - >::get(user_to_calculate.clone()); + >::get(user_to_calculate.clone()); let key = SumTreeName::PositiveExternality { user_address: user_to_calculate, diff --git a/pallets/positive-externality/src/lib.rs b/pallets/positive-externality/src/lib.rs index e05c55b..0f32a1e 100644 --- a/pallets/positive-externality/src/lib.rs +++ b/pallets/positive-externality/src/lib.rs @@ -18,7 +18,7 @@ pub use weights::*; mod extras; pub mod types; -pub use types::{PositiveExternalityPost, FIRST_POST_ID}; +pub use types::{Post, FIRST_POST_ID}; use frame_support::sp_runtime::traits::Saturating; use frame_support::sp_runtime::SaturatedConversion; @@ -32,7 +32,7 @@ use frame_support::{ PalletId, }; use pallet_support::{ - ensure_content_is_valid, new_who_and_when, remove_from_vec, Content, PositiveExternalityPostId, + ensure_content_is_valid, new_who_and_when, remove_from_vec, Content, PostId, WhoAndWhen, WhoAndWhenOf, }; use schelling_game_shared::types::{Period, PhaseData, RangePoint, SchellingGameType}; @@ -87,49 +87,49 @@ pub mod pallet { pub type Something = StorageValue<_, u32>; #[pallet::type_value] - pub fn DefaultForNextPositiveExternalityPostId() -> PositiveExternalityPostId { + pub fn DefaultForNextPostId() -> PostId { FIRST_POST_ID } /// The next post id. #[pallet::storage] - #[pallet::getter(fn next_positive_externality_post_id)] - pub type NextPositiveExternalityPostId = StorageValue< + #[pallet::getter(fn next_post_id)] + pub type NextPostId = StorageValue< _, - PositiveExternalityPostId, + PostId, ValueQuery, - DefaultForNextPositiveExternalityPostId, + DefaultForNextPostId, >; /// Get the details of a post by its' id. #[pallet::storage] - #[pallet::getter(fn positive_externality_post_by_id)] - pub type PositiveExternalityPostById = - StorageMap<_, Twox64Concat, PositiveExternalityPostId, PositiveExternalityPost>; + #[pallet::getter(fn post_by_id)] + pub type PostById = + StorageMap<_, Twox64Concat, PostId, Post>; #[pallet::storage] - #[pallet::getter(fn positive_externality_evidence)] - pub type PositiveExternalityEvidence = - StorageMap<_, Blake2_128Concat, T::AccountId, Vec, ValueQuery>; + #[pallet::getter(fn evidence)] + pub type Evidence = + StorageMap<_, Blake2_128Concat, T::AccountId, Vec, ValueQuery>; #[pallet::type_value] - pub fn MinimumPositiveExternalityStake() -> BalanceOf { + pub fn MinimumStake() -> BalanceOf { 10000u128.saturated_into::>() } #[pallet::storage] - #[pallet::getter(fn positive_externality_user_stake)] - pub type PositiveExternalityStakeBalance = + #[pallet::getter(fn user_stake)] + pub type StakeBalance = StorageMap<_, Twox64Concat, T::AccountId, BalanceOf, ValueQuery>; #[pallet::storage] - #[pallet::getter(fn validate_positive_externality)] - pub type ValidatePositiveExternality = + #[pallet::getter(fn validate)] + pub type Validate = StorageMap<_, Twox64Concat, T::AccountId, bool, ValueQuery>; #[pallet::storage] - #[pallet::getter(fn validation_positive_externality_block_number)] - pub type ValidationPositiveExternalityBlock = + #[pallet::getter(fn validation_block)] + pub type ValidationBlock = StorageMap<_, Blake2_128Concat, T::AccountId, BlockNumberOf, ValueQuery>; // Pallets use events to inform users when important changes are made. @@ -175,15 +175,15 @@ pub mod pallet { // T::SharedStorageSource::check_citizen_is_approved_link(creator.clone())?; - let new_post_id = Self::next_positive_externality_post_id(); + let new_post_id = Self::next_post_id(); - let new_post: PositiveExternalityPost = - PositiveExternalityPost::new(new_post_id, creator.clone(), content.clone()); + let new_post: Post = + Post::new(new_post_id, creator.clone(), content.clone()); - PositiveExternalityEvidence::::mutate(creator, |ids| ids.push(new_post_id)); + Evidence::::mutate(creator, |ids| ids.push(new_post_id)); - PositiveExternalityPostById::insert(new_post_id, new_post); - NextPositiveExternalityPostId::::mutate(|n| { + PostById::insert(new_post_id, new_post); + NextPostId::::mutate(|n| { *n += 1; }); @@ -206,9 +206,9 @@ pub mod pallet { WithdrawReasons::TRANSFER, ExistenceRequirement::AllowDeath, )?; - let stake = PositiveExternalityStakeBalance::::get(&who); + let stake = StakeBalance::::get(&who); let total_balance = stake.saturating_add(deposit); - PositiveExternalityStakeBalance::::insert(&who, total_balance); + StakeBalance::::insert(&who, total_balance); // emit event @@ -224,7 +224,7 @@ pub mod pallet { let who = ensure_signed(origin)?; // Check user has done kyc - ValidatePositiveExternality::::insert(&who, value); + Validate::::insert(&who, value); // emit event Ok(()) } @@ -241,7 +241,7 @@ pub mod pallet { Self::ensure_min_stake_positive_externality(user_to_calculate.clone())?; let pe_block_number = - >::get(user_to_calculate.clone()); + >::get(user_to_calculate.clone()); let now = >::block_number(); let three_month_number = (3 * 30 * 24 * 60 * 60) / 6; let three_month_block = Self::u64_to_block_saturated(three_month_number); @@ -260,7 +260,7 @@ pub mod pallet { // let game_type = SchellingGameType::PositiveExternality; if storage_main_block > pe_block_number { - >::insert( + >::insert( user_to_calculate.clone(), storage_main_block, ); @@ -289,7 +289,7 @@ pub mod pallet { Self::ensure_min_stake_positive_externality(user_to_calculate.clone())?; let pe_block_number = - >::get(user_to_calculate.clone()); + >::get(user_to_calculate.clone()); let key = SumTreeName::PositiveExternality { user_address: user_to_calculate, @@ -312,7 +312,7 @@ pub mod pallet { let _who = ensure_signed(origin)?; let pe_block_number = - >::get(user_to_calculate.clone()); + >::get(user_to_calculate.clone()); let key = SumTreeName::PositiveExternality { user_address: user_to_calculate, @@ -336,7 +336,7 @@ pub mod pallet { let _who = ensure_signed(origin)?; let pe_block_number = - >::get(user_to_calculate.clone()); + >::get(user_to_calculate.clone()); let key = SumTreeName::PositiveExternality { user_address: user_to_calculate, @@ -357,7 +357,7 @@ pub mod pallet { pub fn unstaking(origin: OriginFor, user_to_calculate: T::AccountId) -> DispatchResult { let who = ensure_signed(origin)?; let pe_block_number = - >::get(user_to_calculate.clone()); + >::get(user_to_calculate.clone()); let key = SumTreeName::PositiveExternality { user_address: user_to_calculate, @@ -377,7 +377,7 @@ pub mod pallet { ) -> DispatchResult { let who = ensure_signed(origin)?; let pe_block_number = - >::get(user_to_calculate.clone()); + >::get(user_to_calculate.clone()); let key = SumTreeName::PositiveExternality { user_address: user_to_calculate, @@ -401,7 +401,7 @@ pub mod pallet { ensure!(choice <= 5 && choice >= 1, Error::::ChoiceOutOfRange); let pe_block_number = - >::get(user_to_calculate.clone()); + >::get(user_to_calculate.clone()); let key = SumTreeName::PositiveExternality { user_address: user_to_calculate, @@ -420,7 +420,7 @@ pub mod pallet { ) -> DispatchResult { let _who = ensure_signed(origin)?; let pe_block_number = - >::get(user_to_calculate.clone()); + >::get(user_to_calculate.clone()); let key = SumTreeName::PositiveExternality { user_address: user_to_calculate.clone(), diff --git a/pallets/positive-externality/src/tests.rs b/pallets/positive-externality/src/tests.rs index 30b565a..93a10f8 100644 --- a/pallets/positive-externality/src/tests.rs +++ b/pallets/positive-externality/src/tests.rs @@ -1,4 +1,4 @@ -use crate::types::PositiveExternalityPost; +use crate::types::Post; use crate::{mock::*, Error, Event}; use frame_support::{assert_noop, assert_ok}; use pallet_support::{Content, WhoAndWhen}; @@ -10,8 +10,8 @@ fn test_positive_externality_post() { RuntimeOrigin::signed(1), Content::None )); - let post = TemplateModule::positive_externality_post_by_id(1); - let post_compare = Some(PositiveExternalityPost { + let post = TemplateModule::post_by_id(1); + let post_compare = Some(Post { id: 1, created: WhoAndWhen { account: 1, block: 0, time: 0 }, edited: false, @@ -35,7 +35,7 @@ fn test_adding_positive_externality_stake() { // assert_eq!(post, post_compare); assert_ok!(TemplateModule::add_positive_externality_stake(RuntimeOrigin::signed(1), 10000)); - let stake = TemplateModule::positive_externality_user_stake(1); + let stake = TemplateModule::user_stake(1); assert_eq!(stake, 10000); }); } @@ -47,7 +47,7 @@ fn test_setting_positive_externality_validation() { RuntimeOrigin::signed(1), true )); - let value = TemplateModule::validate_positive_externality(1); + let value = TemplateModule::validate(1); assert_eq!(value, true); }); } diff --git a/pallets/positive-externality/src/types.rs b/pallets/positive-externality/src/types.rs index deb8f67..9f3ebaa 100644 --- a/pallets/positive-externality/src/types.rs +++ b/pallets/positive-externality/src/types.rs @@ -10,8 +10,8 @@ pub const FIRST_POST_ID: u64 = 1; /// Information about a post's owner, its' related space, content, and visibility. #[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)] #[scale_info(skip_type_params(T))] -pub struct PositiveExternalityPost { - pub id: PositiveExternalityPostId, +pub struct Post { + pub id: PostId, pub created: WhoAndWhenOf, diff --git a/pallets/project-tips/src/lib.rs b/pallets/project-tips/src/lib.rs index 0633691..ec1dab4 100644 --- a/pallets/project-tips/src/lib.rs +++ b/pallets/project-tips/src/lib.rs @@ -32,7 +32,7 @@ use frame_support::{ PalletId, }; use pallet_support::{ - ensure_content_is_valid, new_who_and_when, remove_from_vec, Content, PositiveExternalityPostId, + ensure_content_is_valid, new_who_and_when, remove_from_vec, Content, WhoAndWhen, WhoAndWhenOf, }; use schelling_game_shared::types::{Period, PhaseData, RangePoint, SchellingGameType}; diff --git a/pallets/support/src/lib.rs b/pallets/support/src/lib.rs index f1c9d27..546815b 100644 --- a/pallets/support/src/lib.rs +++ b/pallets/support/src/lib.rs @@ -9,7 +9,6 @@ use sp_std::{collections::btree_set::BTreeSet, vec, vec::Vec}; pub type SpaceId = u64; pub type PostId = u64; -pub type PositiveExternalityPostId = u64; #[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)] pub struct WhoAndWhen {