Skip to content

Commit

Permalink
variable change
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed May 1, 2024
1 parent 3fd0236 commit 74c468d
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 61 deletions.
2 changes: 1 addition & 1 deletion pallets/department-funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
26 changes: 13 additions & 13 deletions pallets/positive-externality/src/extras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use frame_support::dispatch::DispatchResult;

use super::*;

impl<T: Config> PositiveExternalityPost<T> {
pub fn new(id: PositiveExternalityPostId, created_by: T::AccountId, content: Content) -> Self {
PositiveExternalityPost {
impl<T: Config> Post<T> {
pub fn new(id: PostId, created_by: T::AccountId, content: Content) -> Self {
Post {
id,
created: new_who_and_when::<T>(created_by.clone()),
edited: false,
Expand Down Expand Up @@ -32,15 +32,15 @@ impl<T: Config> Pallet<T> {
}

pub fn ensure_validation_on_positive_externality(account: T::AccountId) -> DispatchResult {
let bool_data = ValidatePositiveExternality::<T>::get(account);
let bool_data = Validate::<T>::get(account);
ensure!(bool_data == true, Error::<T>::ValidationPositiveExternalityIsOff);

Ok(())
}

pub fn ensure_min_stake_positive_externality(account: T::AccountId) -> DispatchResult {
let stake = PositiveExternalityStakeBalance::<T>::get(account);
let min_stake = MinimumPositiveExternalityStake::<T>::get();
let stake = StakeBalance::<T>::get(account);
let min_stake = MinimumStake::<T>::get();
// println!("stake {:?}", stake);
// println!("min stake {:?}", min_stake);
ensure!(stake >= min_stake, Error::<T>::LessThanMinStake);
Expand All @@ -58,7 +58,7 @@ impl<T: Config> Pallet<T> {

pub(super) fn get_drawn_jurors(user_to_calculate: T::AccountId) -> Vec<(T::AccountId, u64)> {
let pe_block_number =
<ValidationPositiveExternalityBlock<T>>::get(user_to_calculate.clone());
<ValidationBlock<T>>::get(user_to_calculate.clone());

let key = SumTreeName::PositiveExternality {
user_address: user_to_calculate,
Expand All @@ -74,7 +74,7 @@ impl<T: Config> Pallet<T> {
let now = <frame_system::Pallet<T>>::block_number();

let pe_block_number =
<ValidationPositiveExternalityBlock<T>>::get(user_to_calculate.clone());
<ValidationBlock<T>>::get(user_to_calculate.clone());

let key = SumTreeName::PositiveExternality {
user_address: user_to_calculate,
Expand All @@ -93,7 +93,7 @@ impl<T: Config> Pallet<T> {
let now = <frame_system::Pallet<T>>::block_number();

let pe_block_number =
<ValidationPositiveExternalityBlock<T>>::get(user_to_calculate.clone());
<ValidationBlock<T>>::get(user_to_calculate.clone());

let key = SumTreeName::PositiveExternality {
user_address: user_to_calculate,
Expand All @@ -110,7 +110,7 @@ impl<T: Config> Pallet<T> {

pub fn get_drawing_period_end(user_to_calculate: T::AccountId) -> (u64, u64, bool) {
let pe_block_number =
<ValidationPositiveExternalityBlock<T>>::get(user_to_calculate.clone());
<ValidationBlock<T>>::get(user_to_calculate.clone());

let key = SumTreeName::PositiveExternality {
user_address: user_to_calculate,
Expand All @@ -127,7 +127,7 @@ impl<T: Config> Pallet<T> {
let now = <frame_system::Pallet<T>>::block_number();

let pe_block_number =
<ValidationPositiveExternalityBlock<T>>::get(user_to_calculate.clone());
<ValidationBlock<T>>::get(user_to_calculate.clone());

let key = SumTreeName::PositiveExternality {
user_address: user_to_calculate,
Expand All @@ -146,7 +146,7 @@ impl<T: Config> Pallet<T> {
let now = <frame_system::Pallet<T>>::block_number();

let pe_block_number =
<ValidationPositiveExternalityBlock<T>>::get(user_to_calculate.clone());
<ValidationBlock<T>>::get(user_to_calculate.clone());

let key = SumTreeName::PositiveExternality {
user_address: user_to_calculate,
Expand All @@ -163,7 +163,7 @@ impl<T: Config> Pallet<T> {

pub fn selected_as_juror(user_to_calculate: T::AccountId, who: T::AccountId) -> bool {
let pe_block_number =
<ValidationPositiveExternalityBlock<T>>::get(user_to_calculate.clone());
<ValidationBlock<T>>::get(user_to_calculate.clone());

let key = SumTreeName::PositiveExternality {
user_address: user_to_calculate,
Expand Down
76 changes: 38 additions & 38 deletions pallets/positive-externality/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -87,49 +87,49 @@ pub mod pallet {
pub type Something<T> = 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<T: Config> = StorageValue<
#[pallet::getter(fn next_post_id)]
pub type NextPostId<T: Config> = 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<T: Config> =
StorageMap<_, Twox64Concat, PositiveExternalityPostId, PositiveExternalityPost<T>>;
#[pallet::getter(fn post_by_id)]
pub type PostById<T: Config> =
StorageMap<_, Twox64Concat, PostId, Post<T>>;

#[pallet::storage]
#[pallet::getter(fn positive_externality_evidence)]
pub type PositiveExternalityEvidence<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, Vec<PositiveExternalityPostId>, ValueQuery>;
#[pallet::getter(fn evidence)]
pub type Evidence<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, Vec<PostId>, ValueQuery>;

#[pallet::type_value]
pub fn MinimumPositiveExternalityStake<T: Config>() -> BalanceOf<T> {
pub fn MinimumStake<T: Config>() -> BalanceOf<T> {
10000u128.saturated_into::<BalanceOf<T>>()
}

#[pallet::storage]
#[pallet::getter(fn positive_externality_user_stake)]
pub type PositiveExternalityStakeBalance<T: Config> =
#[pallet::getter(fn user_stake)]
pub type StakeBalance<T: Config> =
StorageMap<_, Twox64Concat, T::AccountId, BalanceOf<T>, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn validate_positive_externality)]
pub type ValidatePositiveExternality<T: Config> =
#[pallet::getter(fn validate)]
pub type Validate<T: Config> =
StorageMap<_, Twox64Concat, T::AccountId, bool, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn validation_positive_externality_block_number)]
pub type ValidationPositiveExternalityBlock<T: Config> =
#[pallet::getter(fn validation_block)]
pub type ValidationBlock<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, BlockNumberOf<T>, ValueQuery>;

// Pallets use events to inform users when important changes are made.
Expand Down Expand Up @@ -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<T> =
PositiveExternalityPost::new(new_post_id, creator.clone(), content.clone());
let new_post: Post<T> =
Post::new(new_post_id, creator.clone(), content.clone());

PositiveExternalityEvidence::<T>::mutate(creator, |ids| ids.push(new_post_id));
Evidence::<T>::mutate(creator, |ids| ids.push(new_post_id));

PositiveExternalityPostById::insert(new_post_id, new_post);
NextPositiveExternalityPostId::<T>::mutate(|n| {
PostById::insert(new_post_id, new_post);
NextPostId::<T>::mutate(|n| {
*n += 1;
});

Expand All @@ -206,9 +206,9 @@ pub mod pallet {
WithdrawReasons::TRANSFER,
ExistenceRequirement::AllowDeath,
)?;
let stake = PositiveExternalityStakeBalance::<T>::get(&who);
let stake = StakeBalance::<T>::get(&who);
let total_balance = stake.saturating_add(deposit);
PositiveExternalityStakeBalance::<T>::insert(&who, total_balance);
StakeBalance::<T>::insert(&who, total_balance);


// emit event
Expand All @@ -224,7 +224,7 @@ pub mod pallet {
let who = ensure_signed(origin)?;
// Check user has done kyc

ValidatePositiveExternality::<T>::insert(&who, value);
Validate::<T>::insert(&who, value);
// emit event
Ok(())
}
Expand All @@ -241,7 +241,7 @@ pub mod pallet {
Self::ensure_min_stake_positive_externality(user_to_calculate.clone())?;

let pe_block_number =
<ValidationPositiveExternalityBlock<T>>::get(user_to_calculate.clone());
<ValidationBlock<T>>::get(user_to_calculate.clone());
let now = <frame_system::Pallet<T>>::block_number();
let three_month_number = (3 * 30 * 24 * 60 * 60) / 6;
let three_month_block = Self::u64_to_block_saturated(three_month_number);
Expand All @@ -260,7 +260,7 @@ pub mod pallet {
// let game_type = SchellingGameType::PositiveExternality;

if storage_main_block > pe_block_number {
<ValidationPositiveExternalityBlock<T>>::insert(
<ValidationBlock<T>>::insert(
user_to_calculate.clone(),
storage_main_block,
);
Expand Down Expand Up @@ -289,7 +289,7 @@ pub mod pallet {
Self::ensure_min_stake_positive_externality(user_to_calculate.clone())?;

let pe_block_number =
<ValidationPositiveExternalityBlock<T>>::get(user_to_calculate.clone());
<ValidationBlock<T>>::get(user_to_calculate.clone());

let key = SumTreeName::PositiveExternality {
user_address: user_to_calculate,
Expand All @@ -312,7 +312,7 @@ pub mod pallet {
let _who = ensure_signed(origin)?;

let pe_block_number =
<ValidationPositiveExternalityBlock<T>>::get(user_to_calculate.clone());
<ValidationBlock<T>>::get(user_to_calculate.clone());

let key = SumTreeName::PositiveExternality {
user_address: user_to_calculate,
Expand All @@ -336,7 +336,7 @@ pub mod pallet {
let _who = ensure_signed(origin)?;

let pe_block_number =
<ValidationPositiveExternalityBlock<T>>::get(user_to_calculate.clone());
<ValidationBlock<T>>::get(user_to_calculate.clone());

let key = SumTreeName::PositiveExternality {
user_address: user_to_calculate,
Expand All @@ -357,7 +357,7 @@ pub mod pallet {
pub fn unstaking(origin: OriginFor<T>, user_to_calculate: T::AccountId) -> DispatchResult {
let who = ensure_signed(origin)?;
let pe_block_number =
<ValidationPositiveExternalityBlock<T>>::get(user_to_calculate.clone());
<ValidationBlock<T>>::get(user_to_calculate.clone());

let key = SumTreeName::PositiveExternality {
user_address: user_to_calculate,
Expand All @@ -377,7 +377,7 @@ pub mod pallet {
) -> DispatchResult {
let who = ensure_signed(origin)?;
let pe_block_number =
<ValidationPositiveExternalityBlock<T>>::get(user_to_calculate.clone());
<ValidationBlock<T>>::get(user_to_calculate.clone());

let key = SumTreeName::PositiveExternality {
user_address: user_to_calculate,
Expand All @@ -401,7 +401,7 @@ pub mod pallet {
ensure!(choice <= 5 && choice >= 1, Error::<T>::ChoiceOutOfRange);

let pe_block_number =
<ValidationPositiveExternalityBlock<T>>::get(user_to_calculate.clone());
<ValidationBlock<T>>::get(user_to_calculate.clone());

let key = SumTreeName::PositiveExternality {
user_address: user_to_calculate,
Expand All @@ -420,7 +420,7 @@ pub mod pallet {
) -> DispatchResult {
let _who = ensure_signed(origin)?;
let pe_block_number =
<ValidationPositiveExternalityBlock<T>>::get(user_to_calculate.clone());
<ValidationBlock<T>>::get(user_to_calculate.clone());

let key = SumTreeName::PositiveExternality {
user_address: user_to_calculate.clone(),
Expand Down
10 changes: 5 additions & 5 deletions pallets/positive-externality/src/tests.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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,
Expand All @@ -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);
});
}
Expand All @@ -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);
});
}
Expand Down
4 changes: 2 additions & 2 deletions pallets/positive-externality/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config> {
pub id: PositiveExternalityPostId,
pub struct Post<T: Config> {
pub id: PostId,

pub created: WhoAndWhenOf<T>,

Expand Down
2 changes: 1 addition & 1 deletion pallets/project-tips/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
1 change: 0 additions & 1 deletion pallets/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountId, BlockNumber, Moment> {
Expand Down

0 comments on commit 74c468d

Please sign in to comment.