Skip to content

Commit

Permalink
added parameter types period length
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Jan 30, 2025
1 parent e06dcf7 commit 3189e68
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 2 deletions.
15 changes: 14 additions & 1 deletion custom-pallets/positive-externality/src/extras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@ impl<T: Config> Post<T> {

impl<T: Config> Pallet<T> {
pub(super) fn get_phase_data() -> PhaseData<T> {
T::SchellingGameSharedSource::create_phase_data(50, 5, 3, 100, (100, 100))

let evidence_length: u64 = T::EvidenceLength::get();
let end_of_staking_time: u64 = T::EndOfStakingTime::get();
let staking_length: u64 = T::StakingLength::get();
let drawing_length: u64 = T::DrawingLength::get();
let commit_length: u64 = T::CommitLength::get();
let vote_length: u64 = T::VoteLength::get();
let appeal_length: u64 = T::AppealLength::get();
let max_draws: u64 = T::MaxDraws::get();
let min_number_juror_staked: u64 = T::MinNumberJurorStaked::get();
let min_juror_stake: u64 = T::MinJurorStake::get();
let juror_incentives: (u64, u64) = T::JurorIncentives::get();

T::SchellingGameSharedSource::create_phase_with_all_data(evidence_length, end_of_staking_time, staking_length, drawing_length, commit_length, vote_length, appeal_length, max_draws, min_number_juror_staked, min_juror_stake, juror_incentives)
}

pub fn ensure_validation_on_positive_externality(account: T::AccountId) -> DispatchResult {
Expand Down
36 changes: 35 additions & 1 deletion custom-pallets/positive-externality/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,40 @@ pub mod pallet {
type Currency: ReservableCurrency<Self::AccountId>;
/// Handler for the unbalanced increment when rewarding (minting rewards)
type Reward: OnUnbalanced<PositiveImbalanceOf<Self>>;

#[pallet::constant]
type EvidenceLength: Get<u64>;

#[pallet::constant]
type EndOfStakingTime: Get<u64>;


#[pallet::constant]
type StakingLength: Get<u64>;

#[pallet::constant]
type DrawingLength: Get<u64>;

#[pallet::constant]
type CommitLength: Get<u64>;

#[pallet::constant]
type VoteLength: Get<u64>;

#[pallet::constant]
type AppealLength: Get<u64>;

#[pallet::constant]
type MaxDraws: Get<u64>;

#[pallet::constant]
type MinNumberJurorStaked : Get<u64>;

#[pallet::constant]
type MinJurorStake: Get<u64>;

#[pallet::constant]
type JurorIncentives: Get<(u64, u64)>;
}

// The pallet's runtime storage items.
Expand Down Expand Up @@ -245,7 +279,7 @@ pub mod pallet {
user_to_calculate: T::AccountId,
) -> DispatchResult {
let who = ensure_signed(origin)?;
ensure!(who == user_to_calculate, Error::<T>::UserDontMatch);
// ensure!(who == user_to_calculate, Error::<T>::UserDontMatch);

Self::ensure_validation_on_positive_externality(user_to_calculate.clone())?;

Expand Down
27 changes: 27 additions & 0 deletions custom-pallets/positive-externality/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ use sp_runtime::{

type Block = frame_system::mocking::MockBlock<Test>;

// Positive Externality
parameter_types! {
pub const EvidenceLengthPositiveExternality: u64 = 50;
pub const EndOfStakingTimePositiveExternality: u64 = 50;
pub const StakingLengthPositiveExternality: u64 = 50;
pub const DrawingLengthPositiveExternality: u64 = 50;
pub const CommitLengthPositiveExternality: u64 = 50;
pub const VoteLengthPositiveExternality: u64 = 50;
pub const AppealLengthPositiveExternality: u64 = 50 ;
pub const MaxDrawsPositiveExternality: u64 = 5;
pub const MinNumberJurorStakedPositiveExternality: u64 = 3;
pub const MinJurorStakePositiveExternality: u64 = 100;
pub const JurorIncentivesPositiveExternality: (u64, u64) = (100, 100);
}

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test
Expand Down Expand Up @@ -103,6 +118,18 @@ impl pallet_template::Config for Test {
type Currency = Balances; // New code
type SchellingGameSharedSource = SchellingGameShared;
type Reward = ();
type EvidenceLength = EvidenceLengthPositiveExternality;
type EndOfStakingTime = EndOfStakingTimePositiveExternality;
type StakingLength = StakingLengthPositiveExternality;
type DrawingLength = DrawingLengthPositiveExternality;
type CommitLength = CommitLengthPositiveExternality;
type VoteLength = VoteLengthPositiveExternality;
type AppealLength = AppealLengthPositiveExternality;
type MaxDraws = MaxDrawsPositiveExternality;
type MinNumberJurorStaked = MinNumberJurorStakedPositiveExternality;
type MinJurorStake = MinJurorStakePositiveExternality;
type JurorIncentives = JurorIncentivesPositiveExternality;

}

// Build genesis storage according to the mock runtime.
Expand Down
29 changes: 29 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@ parameter_types! {
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u8 = 42;
pub const AnonymousAccountImageId: [u32; 8] = [957845215, 2138764848, 3436027531, 926522363, 4221982768, 3434214646, 699310563, 1063924749];


}

// Positive Externality
parameter_types! {
pub const EvidenceLengthPositiveExternality: u64 = 50;
pub const EndOfStakingTimePositiveExternality: u64 = 50;
pub const StakingLengthPositiveExternality: u64 = 50;
pub const DrawingLengthPositiveExternality: u64 = 50;
pub const CommitLengthPositiveExternality: u64 = 50;
pub const VoteLengthPositiveExternality: u64 = 50;
pub const AppealLengthPositiveExternality: u64 = 50 ;
pub const MaxDrawsPositiveExternality: u64 = 5;
pub const MinNumberJurorStakedPositiveExternality: u64 = 3;
pub const MinJurorStakePositiveExternality: u64 = 100;
pub const JurorIncentivesPositiveExternality: (u64, u64) = (100, 100);
}

/// The default types are being injected by [`derive_impl`](`frame_support::derive_impl`) from
Expand Down Expand Up @@ -294,6 +311,18 @@ impl pallet_positive_externality::Config for Runtime {
type Currency = Balances;
type SchellingGameSharedSource = SchellingGameShared;
type Reward = ();
type EvidenceLength = EvidenceLengthPositiveExternality;
type EndOfStakingTime = EndOfStakingTimePositiveExternality;
type StakingLength = StakingLengthPositiveExternality;
type DrawingLength = DrawingLengthPositiveExternality;
type CommitLength = CommitLengthPositiveExternality;
type VoteLength = VoteLengthPositiveExternality;
type AppealLength = AppealLengthPositiveExternality;
type MaxDraws = MaxDrawsPositiveExternality;
type MinNumberJurorStaked = MinNumberJurorStakedPositiveExternality;
type MinJurorStake = MinJurorStakePositiveExternality;
type JurorIncentives = JurorIncentivesPositiveExternality;

}

impl pallet_departments::Config for Runtime {
Expand Down

0 comments on commit 3189e68

Please sign in to comment.