Skip to content
4 changes: 2 additions & 2 deletions srml/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ impl<T: Trait> Module<T> {
ledger
}

// TODO: doc
// update the ledger while bonding ring and compute the kton should return
fn bond_helper_in_ring(
stash: &T::AccountId,
controller: &T::AccountId,
Expand Down Expand Up @@ -1217,7 +1217,7 @@ impl<T: Trait> Module<T> {
Self::update_ledger(&controller, &mut ledger, StakingBalances::RingBalance(value));
}

// TODO: doc
// update the ledger while bonding controller with kton
fn bond_helper_in_kton(
controller: &T::AccountId,
value: KtonBalance<T>,
Expand Down
13 changes: 13 additions & 0 deletions srml/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,19 @@ pub fn current_total_payout_for_duration(duration: u64) -> Balance {
).0
}

pub fn compute_power(ring_amount: u128, kton_amount: u128) -> Power {
fn calc_power<S: rstd::convert::TryInto<u128>>(active: S, pool: S) -> Power {
const HALF_POWER_COUNT: u128 = 1_000_000_000 / 2;

Perquintill::from_rational_approximation(
active.saturated_into::<Power>(),
pool.saturated_into::<Power>().max(1),
) * HALF_POWER_COUNT
}

calc_power(ring_amount, Staking::ring_pool()) + calc_power(kton_amount, Staking::kton_pool())
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate with power_of to some extend.

pub fn reward_all_elected() {
let rewards = <Module<Test>>::current_elected()
.iter()
Expand Down
Loading