mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +00:00
Refactor CurrencyToVote (#6896)
* Refactor CurrencyToVote to avoid calls to total_issuance. * Update frame/support/src/traits.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Some grumbles * Fix last grumbles. * Fix comment * Final fix Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
@@ -17,8 +17,6 @@
|
||||
|
||||
//! Some configurable implementations as associated type for the substrate runtime.
|
||||
|
||||
use node_primitives::Balance;
|
||||
use sp_runtime::traits::Convert;
|
||||
use frame_support::traits::{OnUnbalanced, Currency};
|
||||
use crate::{Balances, Authorship, NegativeImbalance};
|
||||
|
||||
@@ -29,26 +27,9 @@ impl OnUnbalanced<NegativeImbalance> for Author {
|
||||
}
|
||||
}
|
||||
|
||||
/// Struct that handles the conversion of Balance -> `u64`. This is used for staking's election
|
||||
/// calculation.
|
||||
pub struct CurrencyToVoteHandler;
|
||||
|
||||
impl CurrencyToVoteHandler {
|
||||
fn factor() -> Balance { (Balances::total_issuance() / u64::max_value() as Balance).max(1) }
|
||||
}
|
||||
|
||||
impl Convert<Balance, u64> for CurrencyToVoteHandler {
|
||||
fn convert(x: Balance) -> u64 { (x / Self::factor()) as u64 }
|
||||
}
|
||||
|
||||
impl Convert<u128, Balance> for CurrencyToVoteHandler {
|
||||
fn convert(x: u128) -> Balance { x * Self::factor() }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod multiplier_tests {
|
||||
use super::*;
|
||||
use sp_runtime::{assert_eq_error_rate, FixedPointNumber};
|
||||
use sp_runtime::{assert_eq_error_rate, FixedPointNumber, traits::Convert};
|
||||
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
|
||||
|
||||
use crate::{
|
||||
|
||||
Reference in New Issue
Block a user