diff --git a/pallets/dapp-staking/src/types.rs b/pallets/dapp-staking/src/types.rs index cd73826d25..d10fc32538 100644 --- a/pallets/dapp-staking/src/types.rs +++ b/pallets/dapp-staking/src/types.rs @@ -64,7 +64,7 @@ //! * `DAppTierRewards` - composite of `DAppTier` objects, describing the entire reward distribution for a particular era. //! -use frame_support::{pallet_prelude::*, BoundedBTreeMap, BoundedVec}; +use frame_support::{pallet_prelude::*, BoundedBTreeMap, BoundedVec, DefaultNoBound}; use parity_scale_codec::{Decode, Encode}; use serde::{Deserialize, Serialize}; use sp_arithmetic::fixed_point::FixedU128; @@ -351,6 +351,7 @@ pub struct UnlockingChunk { MaxEncodedLen, RuntimeDebugNoBound, PartialEqNoBound, + DefaultNoBound, EqNoBound, CloneNoBound, TypeInfo, @@ -375,21 +376,6 @@ pub struct AccountLedger> { pub(crate) contract_stake_count: u32, } -impl Default for AccountLedger -where - UnlockingLen: Get, -{ - fn default() -> Self { - Self { - locked: Balance::zero(), - unlocking: BoundedVec::default(), - staked: StakeAmount::default(), - staked_future: None, - contract_stake_count: Zero::zero(), - } - } -} - impl AccountLedger where UnlockingLen: Get, @@ -1011,7 +997,7 @@ impl SingularStakingInfo { /// /// `period` - period number for which this entry is relevant. /// `subperiod` - subperiod during which this entry is created. - pub fn new(period: PeriodNumber, subperiod: Subperiod) -> Self { + pub(crate) fn new(period: PeriodNumber, subperiod: Subperiod) -> Self { Self { previous_staked: Default::default(), staked: StakeAmount { @@ -1393,6 +1379,7 @@ pub enum EraRewardSpanError { MaxEncodedLen, RuntimeDebugNoBound, PartialEqNoBound, + DefaultNoBound, EqNoBound, CloneNoBound, TypeInfo, @@ -1414,7 +1401,7 @@ where SL: Get, { /// Create new instance of the `EraRewardSpan` - pub fn new() -> Self { + pub(crate) fn new() -> Self { Self { span: Default::default(), first_era: 0, @@ -1527,6 +1514,7 @@ impl TierThreshold { MaxEncodedLen, RuntimeDebugNoBound, PartialEqNoBound, + DefaultNoBound, EqNoBound, CloneNoBound, TypeInfo, @@ -1585,16 +1573,6 @@ impl> TierParameters { } } -impl> Default for TierParameters { - fn default() -> Self { - Self { - reward_portion: BoundedVec::default(), - slot_distribution: BoundedVec::default(), - tier_thresholds: BoundedVec::default(), - } - } -} - /// Configuration of dApp tiers. #[derive( Encode, @@ -1602,6 +1580,7 @@ impl> Default for TierParameters { MaxEncodedLen, RuntimeDebugNoBound, PartialEqNoBound, + DefaultNoBound, EqNoBound, CloneNoBound, TypeInfo, @@ -1623,17 +1602,6 @@ pub struct TiersConfiguration, T: TierSlotsFunc, P: Get> pub(crate) _phantom: PhantomData<(T, P)>, } -impl, T: TierSlotsFunc, P: Get> Default for TiersConfiguration { - fn default() -> Self { - Self { - slots_per_tier: BoundedVec::default(), - reward_portion: BoundedVec::default(), - tier_thresholds: BoundedVec::default(), - _phantom: Default::default(), - } - } -} - // Some TODOs: // Some parts regarding tiers should be refactored. // * There's no need to keep thresholds in two separate storage items since the calculation can always be done compared to the @@ -1760,6 +1728,7 @@ impl, T: TierSlotsFunc, P: Get> TiersConfiguration, NT: Get> { pub(crate) rank_rewards: BoundedVec, } -impl, NT: Get> Default for DAppTierRewards { - fn default() -> Self { - Self { - dapps: BoundedBTreeMap::default(), - rewards: BoundedVec::default(), - period: 0, - rank_rewards: BoundedVec::default(), - } - } -} - impl, NT: Get> DAppTierRewards { /// Attempt to construct `DAppTierRewards` struct. /// If the provided arguments exceed the allowed capacity, return an error. - pub fn new( + pub(crate) fn new( dapps: BTreeMap, rewards: Vec, period: PeriodNumber, diff --git a/precompiles/dapp-staking/src/lib.rs b/precompiles/dapp-staking/src/lib.rs index 475d5b8877..b60a8270ee 100644 --- a/precompiles/dapp-staking/src/lib.rs +++ b/precompiles/dapp-staking/src/lib.rs @@ -160,8 +160,7 @@ where // Get the appropriate era reward span let era_span_index = DAppStaking::::era_reward_span_index(era); - let reward_span = - EraRewards::::get(&era_span_index).unwrap_or(EraRewardSpanFor::::new()); + let reward_span = EraRewards::::get(&era_span_index).unwrap_or_default(); // Sum up staker & dApp reward pools for the era let reward = reward_span.get(era).map_or(Zero::zero(), |r| { @@ -198,8 +197,7 @@ where handle.record_db_read::(20 + EraRewardSpanFor::::max_encoded_len())?; let era_span_index = DAppStaking::::era_reward_span_index(era); - let reward_span = - EraRewards::::get(&era_span_index).unwrap_or(EraRewardSpanFor::::new()); + let reward_span = EraRewards::::get(&era_span_index).unwrap_or_default(); let staked = reward_span.get(era).map_or(Zero::zero(), |r| r.staked());