|
@@ -31,7 +31,7 @@ use codec::Codec;
|
|
|
use runtime_primitives::traits::Zero;
|
|
|
use runtime_primitives::traits::{MaybeSerialize, Member, One, SimpleArithmetic};
|
|
|
|
|
|
-use srml_support::traits::{Currency, Get};
|
|
|
+use srml_support::traits::Currency;
|
|
|
use srml_support::{decl_module, decl_storage, ensure, Parameter};
|
|
|
|
|
|
use rstd::collections::btree_map::BTreeMap;
|
|
@@ -79,9 +79,6 @@ pub trait Trait: system::Trait + stake::Trait + Sized {
|
|
|
|
|
|
/// Marker type for Stake module handler. Indicates that hiring module uses stake module mock.
|
|
|
type StakeHandlerProvider: StakeHandlerProvider<Self>;
|
|
|
-
|
|
|
- /// Defines min application or role stake balance.
|
|
|
- type MinimumStakeBalance: Get<stake::BalanceOf<Self>>;
|
|
|
}
|
|
|
|
|
|
decl_storage! {
|
|
@@ -108,9 +105,6 @@ decl_module! {
|
|
|
/// Main hiring module definition
|
|
|
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
|
|
|
|
|
- /// Exports const - min application or role stake balance.
|
|
|
- const MinimumStakeBalance: stake::BalanceOf<T> = T::MinimumStakeBalance::get();
|
|
|
-
|
|
|
fn on_finalize(now: T::BlockNumber) {
|
|
|
|
|
|
//
|
|
@@ -190,10 +184,10 @@ impl<T: Trait> Module<T> {
|
|
|
) -> Result<T::OpeningId, AddOpeningError> {
|
|
|
let current_block_height = <system::Module<T>>::block_number();
|
|
|
|
|
|
- Opening::<BalanceOf<T>, T::BlockNumber, T::ApplicationId>::ensure_can_add_opening(
|
|
|
+ Self::ensure_can_add_opening(
|
|
|
current_block_height,
|
|
|
activate_at.clone(),
|
|
|
- T::MinimumStakeBalance::get(),
|
|
|
+ T::Currency::minimum_balance(),
|
|
|
application_rationing_policy.clone(),
|
|
|
application_staking_policy.clone(),
|
|
|
role_staking_policy.clone(),
|
|
@@ -1412,6 +1406,69 @@ impl<T: Trait> Module<T> {
|
|
|
None
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /// Performs all necessary check before adding an opening
|
|
|
+ pub(crate) fn ensure_can_add_opening(
|
|
|
+ current_block_height: T::BlockNumber,
|
|
|
+ activate_at: ActivateOpeningAt<T::BlockNumber>,
|
|
|
+ minimum_stake_balance: BalanceOf<T>,
|
|
|
+ application_rationing_policy: Option<ApplicationRationingPolicy>,
|
|
|
+ application_staking_policy: Option<StakingPolicy<BalanceOf<T>, T::BlockNumber>>,
|
|
|
+ role_staking_policy: Option<StakingPolicy<BalanceOf<T>, T::BlockNumber>>,
|
|
|
+ ) -> Result<(), AddOpeningError> {
|
|
|
+ // Check that exact activation is actually in the future
|
|
|
+ ensure!(
|
|
|
+ match activate_at {
|
|
|
+ ActivateOpeningAt::ExactBlock(block_number) => block_number > current_block_height,
|
|
|
+ _ => true,
|
|
|
+ },
|
|
|
+ AddOpeningError::OpeningMustActivateInTheFuture
|
|
|
+ );
|
|
|
+
|
|
|
+ if let Some(app_rationing_policy) = application_rationing_policy {
|
|
|
+ ensure!(
|
|
|
+ app_rationing_policy.max_active_applicants > 0,
|
|
|
+ AddOpeningError::ApplicationRationingZeroMaxApplicants
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // Check that staking amounts clear minimum balance required.
|
|
|
+ Self::ensure_amount_valid_in_opt_staking_policy(
|
|
|
+ application_staking_policy,
|
|
|
+ minimum_stake_balance,
|
|
|
+ StakePurpose::Application,
|
|
|
+ )?;
|
|
|
+
|
|
|
+ // Check that staking amounts clear minimum balance required.
|
|
|
+ Self::ensure_amount_valid_in_opt_staking_policy(
|
|
|
+ role_staking_policy,
|
|
|
+ minimum_stake_balance,
|
|
|
+ StakePurpose::Role,
|
|
|
+ )?;
|
|
|
+
|
|
|
+ Ok(())
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Ensures that optional staking policy prescribes value that clears minimum balance requirement
|
|
|
+ pub(crate) fn ensure_amount_valid_in_opt_staking_policy(
|
|
|
+ opt_staking_policy: Option<StakingPolicy<BalanceOf<T>, T::BlockNumber>>,
|
|
|
+ minimum_stake_balance: BalanceOf<T>,
|
|
|
+ stake_purpose: StakePurpose,
|
|
|
+ ) -> Result<(), AddOpeningError> {
|
|
|
+ if let Some(ref staking_policy) = opt_staking_policy {
|
|
|
+ ensure!(
|
|
|
+ staking_policy.amount > Zero::zero(),
|
|
|
+ AddOpeningError::StakeAmountCannotBeZero(stake_purpose)
|
|
|
+ );
|
|
|
+
|
|
|
+ ensure!(
|
|
|
+ staking_policy.amount >= minimum_stake_balance,
|
|
|
+ AddOpeningError::StakeAmountLessThanMinimumStakeBalance(stake_purpose)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ Ok(())
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/*
|