Skip to content

Commit

Permalink
department funding
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Nov 23, 2023
1 parent 107106e commit 983a19a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
39 changes: 37 additions & 2 deletions pallets/department-funding/src/extras.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::*;
use types::{TIME_FOR_STAKING_FUNDING_STATUS_FAILED, TIME_FOR_STAKING_FUNDING_STATUS_PASSED};

impl<T: Config> DepartmentRequiredFund<T> {
pub fn new(
Expand All @@ -24,7 +25,7 @@ impl<T: Config> Pallet<T> {
T::SchellingGameSharedSource::create_phase_data(50, 5, 3, 100, (100, 100))
}

pub fn ensure_validation_on_positive_externality(
pub fn ensure_validation_to_do(
department_required_fund_id: DepartmentRequiredFundId,
) -> DispatchResult {
let bool_data = ValidateDepartmentRequiredFund::<T>::get(department_required_fund_id);
Expand All @@ -36,7 +37,41 @@ impl<T: Config> Pallet<T> {
pub fn get_department_id_from_department_required_fund_id(
department_required_fund_id: DepartmentRequiredFundId,
) -> Result<DepartmentId, DispatchError> {
Ok(1)
let department_required_fund_option =
DepartmentRequiredFunds::<T>::get(department_required_fund_id);

match department_required_fund_option {
Some(department_required_fund) => Ok(department_required_fund.department_id),
None => Err(Error::<T>::DepartmentRequiredFundDontExits)?,
}
}

pub fn ensure_can_stake_using_status(
department_id: DepartmentId,
) -> Result<DepartmentFundingStatus<BlockNumberOf<T>, FundingStatus>, DispatchError> {
let department_status_option =
DepartmentFundingStatusForDepartmentId::<T>::get(department_id);
match department_status_option {
Some(department_status) => {
let funding_status = department_status.status;
if funding_status == FundingStatus::Processing {
Err(Error::<T>::FundingStatusProcessing.into())
} else {
// else check 3 month or 6 months passed then return new department_status
let three_month_number = TIME_FOR_STAKING_FUNDING_STATUS_FAILED;
let three_month_block = Self::u64_to_block_saturated(three_month_number);
Ok(department_status)
}
},
None => {
let now = <frame_system::Pallet<T>>::block_number();
let department_funding_status = DepartmentFundingStatus {
block_number: now,
status: FundingStatus::Processing,
};
Ok(department_funding_status)
},
}
}

// pub fn ensure_user_is_project_creator_and_project_exists(
Expand Down
15 changes: 13 additions & 2 deletions pallets/department-funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use schelling_game_shared_link::SchellingGameSharedLink;
use shared_storage_link::SharedStorageLink;
use sortition_sum_game::types::SumTreeName;
pub use types::DEPARTMENT_REQUIRED_FUND_ID;
use types::{DepartmentRequiredFund, TippingName, TippingValue};
use types::{DepartmentFundingStatus, DepartmentRequiredFund, TippingName, TippingValue, FundingStatus};

type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
type BalanceOf<T> = <<T as Config>::Currency as Currency<AccountIdOf<T>>>::Balance;
Expand Down Expand Up @@ -125,6 +125,15 @@ pub mod pallet {
pub type ValidationDepartmentRequiredFundsBlock<T: Config> =
StorageMap<_, Blake2_128Concat, DepartmentRequiredFundId, BlockNumberOf<T>>;

#[pallet::storage]
#[pallet::getter(fn department_funding_status)]
pub type DepartmentFundingStatusForDepartmentId<T: Config> = StorageMap<
_,
Blake2_128Concat,
DepartmentId,
DepartmentFundingStatus<BlockNumberOf<T>, FundingStatus>,
>;

// Pallets use events to inform users when important changes are made.
// https://docs.substrate.io/main-docs/build/events-errors/
#[pallet::event]
Expand Down Expand Up @@ -162,6 +171,7 @@ pub mod pallet {
DepartmentRequiredFundDontExits,
BlockDepartmentRequiredFundIdNotExists,
ValidationForDepartmentRequiredFundIdIsOff,
FundingStatusProcessing,
}

// Check deparment exists, it will done using loose coupling
Expand Down Expand Up @@ -214,8 +224,9 @@ pub mod pallet {
origin: OriginFor<T>,
department_required_fund_id: DepartmentRequiredFundId,
) -> DispatchResult {
Self::ensure_validation_to_do(department_required_fund_id)?;
let department_id = Self::get_department_id_from_department_required_fund_id(department_required_fund_id)?;


Ok(())
}

Expand Down
17 changes: 17 additions & 0 deletions pallets/department-funding/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use scale_info::TypeInfo;

pub const DEPARTMENT_REQUIRED_FUND_ID: DepartmentRequiredFundId = 1;

pub const TIME_FOR_STAKING_FUNDING_STATUS_FAILED: u64 = (3 * 30 * 24 * 60 * 60) / 6; // 3 months time

pub const TIME_FOR_STAKING_FUNDING_STATUS_PASSED: u64 = (6 * 30 * 24 * 60 * 60) / 6; // 6 months time


#[derive(Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug, TypeInfo)]
Expand Down Expand Up @@ -35,4 +37,19 @@ pub struct DepartmentRequiredFund<T: Config> {
}


#[derive(Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub enum FundingStatus {
Processing,
Success,
Failed,
}

#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub struct DepartmentFundingStatus<BlockNumber, FundingStatus> {
pub block_number: BlockNumber,
pub status: FundingStatus,
}




0 comments on commit 983a19a

Please sign in to comment.