Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
getter fixes for pallet-staking
Browse files Browse the repository at this point in the history
Signed-off-by: muraca <[email protected]>
  • Loading branch information
muraca committed Feb 11, 2023
1 parent 278b29c commit 9bad78b
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 112 deletions.
6 changes: 3 additions & 3 deletions frame/root-offences/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod mock;
mod tests;

use pallet_session::historical::IdentificationTuple;
use pallet_staking::{BalanceOf, Exposure, ExposureOf, Pallet as Staking};
use pallet_staking::{BalanceOf, Exposure, ExposureOf};
use sp_runtime::Perbill;
use sp_staking::offence::{DisableStrategy, OnOffenceHandler};

Expand Down Expand Up @@ -104,15 +104,15 @@ pub mod pallet {
fn get_offence_details(
offenders: Vec<(T::AccountId, Perbill)>,
) -> Result<Vec<OffenceDetails<T>>, DispatchError> {
let now = Staking::<T>::active_era()
let now = pallet_staking::ActiveEra::<T>::get()
.map(|e| e.index)
.ok_or(Error::<T>::FailedToGetActiveEra)?;

Ok(offenders
.clone()
.into_iter()
.map(|(o, _)| OffenceDetails::<T> {
offender: (o.clone(), Staking::<T>::eras_stakers(now, o)),
offender: (o.clone(), pallet_staking::ErasStakers::<T>::get(now, o)),
reporters: vec![],
})
.collect())
Expand Down
2 changes: 1 addition & 1 deletion frame/root-offences/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,5 +350,5 @@ pub(crate) fn run_to_block(n: BlockNumber) {
}

pub(crate) fn active_era() -> EraIndex {
Staking::active_era().unwrap().index
pallet_staking::ActiveEra::<Test>::get().unwrap().index
}
8 changes: 4 additions & 4 deletions frame/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ pub(crate) fn start_active_era(era_index: EraIndex) {

pub(crate) fn current_total_payout_for_duration(duration: u64) -> Balance {
let (payout, _rest) = <Test as Config>::EraPayout::era_payout(
Staking::eras_total_stake(active_era()),
ErasTotalStake::<Test>::get(active_era()),
Balances::total_issuance(),
duration,
);
Expand All @@ -654,7 +654,7 @@ pub(crate) fn current_total_payout_for_duration(duration: u64) -> Balance {

pub(crate) fn maximum_payout_for_duration(duration: u64) -> Balance {
let (payout, rest) = <Test as Config>::EraPayout::era_payout(
Staking::eras_total_stake(active_era()),
ErasTotalStake::<Test>::get(active_era()),
Balances::total_issuance(),
duration,
);
Expand Down Expand Up @@ -718,7 +718,7 @@ pub(crate) fn on_offence_in_era(
let _ = Staking::on_offence(
offenders,
slash_fraction,
Staking::eras_start_session_index(era).unwrap(),
ErasStartSessionIndex::<Test>::get(era).unwrap(),
disable_strategy,
);
} else {
Expand All @@ -740,7 +740,7 @@ pub(crate) fn on_offence_now(
pub(crate) fn add_slash(who: &AccountId) {
on_offence_now(
&[OffenceDetails {
offender: (*who, Staking::eras_stakers(active_era(), *who)),
offender: (*who, ErasStakers::<Test>::get(active_era(), *who)),
reporters: vec![],
}],
&[Perbill::from_percent(10)],
Expand Down
Loading

0 comments on commit 9bad78b

Please sign in to comment.