Skip to content

Commit

Permalink
Rename is_active & add some more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Dec 4, 2023
1 parent 27c6f3d commit 6b4b84a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
15 changes: 9 additions & 6 deletions pallets/dapp-staking-v3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ pub mod pallet {
pub type NextDAppId<T: Config> = StorageValue<_, DAppId, ValueQuery>;

/// Map of all dApps integrated into dApp staking protocol.
///
/// Even though dApp is integrated, it does not mean it's still actively participating in dApp staking.
/// It might have been unregistered at some point in history.
#[pallet::storage]
pub type IntegratedDApps<T: Config> = CountedStorageMap<
Hasher = Blake2_128Concat,
Expand Down Expand Up @@ -891,7 +894,7 @@ pub mod pallet {

let dapp_info =
IntegratedDApps::<T>::get(&smart_contract).ok_or(Error::<T>::NotOperatedDApp)?;
ensure!(dapp_info.is_active(), Error::<T>::NotOperatedDApp);
ensure!(dapp_info.is_registered(), Error::<T>::NotOperatedDApp);

let protocol_state = ActiveProtocolState::<T>::get();
let current_era = protocol_state.era;
Expand Down Expand Up @@ -1018,7 +1021,7 @@ pub mod pallet {

let dapp_info =
IntegratedDApps::<T>::get(&smart_contract).ok_or(Error::<T>::NotOperatedDApp)?;
ensure!(dapp_info.is_active(), Error::<T>::NotOperatedDApp);
ensure!(dapp_info.is_registered(), Error::<T>::NotOperatedDApp);

let protocol_state = ActiveProtocolState::<T>::get();
let current_era = protocol_state.era;
Expand Down Expand Up @@ -1328,7 +1331,7 @@ pub mod pallet {
let account = ensure_signed(origin)?;

ensure!(
!Self::is_active(&smart_contract),
!Self::is_registered(&smart_contract),
Error::<T>::ContractStillActive
);

Expand Down Expand Up @@ -1526,10 +1529,10 @@ pub mod pallet {
.saturating_mul(T::CycleConfiguration::eras_per_voting_subperiod().into())
}

/// `true` if smart contract is active, `false` if it has been unregistered.
pub(crate) fn is_active(smart_contract: &T::SmartContract) -> bool {
/// `true` if smart contract is registered, `false` otherwise.
pub(crate) fn is_registered(smart_contract: &T::SmartContract) -> bool {
IntegratedDApps::<T>::get(smart_contract)
.map_or(false, |dapp_info| dapp_info.is_active())
.map_or(false, |dapp_info| dapp_info.is_registered())
}

/// Calculates the `EraRewardSpan` index for the specified era.
Expand Down
6 changes: 3 additions & 3 deletions pallets/dapp-staking-v3/src/test/tests_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ fn dapp_info_basic_checks() {
dapp_info.reward_destination = Some(beneficiary);
assert_eq!(*dapp_info.reward_beneficiary(), beneficiary);

// Check if dApp is active
assert!(dapp_info.is_active());
// Check if dApp is registered
assert!(dapp_info.is_registered());

dapp_info.state = DAppState::Unregistered(10);
assert!(!dapp_info.is_active());
assert!(!dapp_info.is_registered());
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions pallets/dapp-staking-v3/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ impl<AccountId> DAppInfo<AccountId> {
}
}

/// `true` if dApp is still active (registered), `false` otherwise.
pub fn is_active(&self) -> bool {
/// `true` if dApp is registered, `false` otherwise.
pub fn is_registered(&self) -> bool {
self.state == DAppState::Registered
}
}
Expand Down
5 changes: 1 addition & 4 deletions pallets/inflation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
//! These are paid out at the begininng of each block & are fixed amounts.
//!
//! ### Staker Rewards
//!
//!
//! Staker rewards are paid out per staker, _on-demand_.
//! However, reward pool for an era is calculated at the end of each era.
//!
Expand All @@ -94,9 +94,6 @@
//! This pallet implements `StakingRewardHandler` trait, which is used by the dApp staking protocol to get reward pools & distribute rewards.
//!




#![cfg_attr(not(feature = "std"), no_std)]

pub use pallet::*;
Expand Down

0 comments on commit 6b4b84a

Please sign in to comment.