mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 18:07:58 +00:00
Per-things trait. (#4904)
* Give perthigns the trait it always deserved.
* Make staking and phragmen work with the new generic per_thing
* Make everything work together 🔨
* a bit of cleanup
* Clean usage
* Bump.
* Fix name
* fix grumbles
* hopefully fix the ui test
* Some grumbles
* revamp traits again
* Better naming again.
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Provides some utilities to define a piecewise linear function.
|
||||
|
||||
use crate::{Perbill, traits::{SimpleArithmetic, SaturatedConversion}};
|
||||
use crate::{Perbill, PerThing, traits::{AtLeast32Bit, SaturatedConversion}};
|
||||
use core::ops::Sub;
|
||||
|
||||
/// Piecewise Linear function in [0, 1] -> [0, 1].
|
||||
@@ -35,7 +35,7 @@ fn abs_sub<N: Ord + Sub<Output=N> + Clone>(a: N, b: N) -> N where {
|
||||
impl<'a> PiecewiseLinear<'a> {
|
||||
/// Compute `f(n/d)*d` with `n <= d`. This is useful to avoid loss of precision.
|
||||
pub fn calculate_for_fraction_times_denominator<N>(&self, n: N, d: N) -> N where
|
||||
N: SimpleArithmetic + Clone
|
||||
N: AtLeast32Bit + Clone
|
||||
{
|
||||
let n = n.min(d.clone());
|
||||
|
||||
@@ -79,7 +79,7 @@ impl<'a> PiecewiseLinear<'a> {
|
||||
// This is guaranteed not to overflow on whatever values nor lose precision.
|
||||
// `q` must be superior to zero.
|
||||
fn multiply_by_rational_saturating<N>(value: N, p: u32, q: u32) -> N
|
||||
where N: SimpleArithmetic + Clone
|
||||
where N: AtLeast32Bit + Clone
|
||||
{
|
||||
let q = q.max(1);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::codec::{Decode, Encode, Codec, Input, Output, HasCompact, EncodeAsRef, Error};
|
||||
use crate::traits::{
|
||||
self, Member, SimpleArithmetic, SimpleBitOps, Hash as HashT,
|
||||
self, Member, AtLeast32Bit, SimpleBitOps, Hash as HashT,
|
||||
MaybeSerializeDeserialize, MaybeSerialize, MaybeDisplay,
|
||||
MaybeMallocSizeOf,
|
||||
};
|
||||
@@ -122,7 +122,7 @@ impl<Number, Hash> codec::EncodeLike for Header<Number, Hash> where
|
||||
|
||||
impl<Number, Hash> traits::Header for Header<Number, Hash> where
|
||||
Number: Member + MaybeSerializeDeserialize + Debug + sp_std::hash::Hash + MaybeDisplay +
|
||||
SimpleArithmetic + Codec + Copy + Into<U256> + TryFrom<U256> + sp_std::str::FromStr +
|
||||
AtLeast32Bit + Codec + Copy + Into<U256> + TryFrom<U256> + sp_std::str::FromStr +
|
||||
MaybeMallocSizeOf,
|
||||
Hash: HashT,
|
||||
Hash::Output: Default + sp_std::hash::Hash + Copy + Member + Ord +
|
||||
@@ -170,7 +170,7 @@ impl<Number, Hash> traits::Header for Header<Number, Hash> where
|
||||
}
|
||||
|
||||
impl<Number, Hash> Header<Number, Hash> where
|
||||
Number: Member + sp_std::hash::Hash + Copy + MaybeDisplay + SimpleArithmetic + Codec + Into<U256> + TryFrom<U256>,
|
||||
Number: Member + sp_std::hash::Hash + Copy + MaybeDisplay + AtLeast32Bit + Codec + Into<U256> + TryFrom<U256>,
|
||||
Hash: HashT,
|
||||
Hash::Output: Default + sp_std::hash::Hash + Copy + Member + MaybeDisplay + SimpleBitOps + Codec,
|
||||
{
|
||||
|
||||
@@ -68,7 +68,7 @@ pub use sp_application_crypto::{RuntimeAppPublic, BoundToRuntimeAppPublic};
|
||||
pub use sp_core::RuntimeDebug;
|
||||
|
||||
/// Re-export top-level arithmetic stuff.
|
||||
pub use sp_arithmetic::{Perquintill, Perbill, Permill, Percent, Rational128, Fixed64};
|
||||
pub use sp_arithmetic::{Perquintill, Perbill, Permill, Percent, Rational128, Fixed64, PerThing};
|
||||
/// Re-export 128 bit helpers.
|
||||
pub use sp_arithmetic::helpers_128bit;
|
||||
/// Re-export big_uint stuff.
|
||||
|
||||
@@ -33,7 +33,7 @@ use crate::transaction_validity::{
|
||||
};
|
||||
use crate::generic::{Digest, DigestItem};
|
||||
pub use sp_arithmetic::traits::{
|
||||
SimpleArithmetic, UniqueSaturatedInto, UniqueSaturatedFrom, Saturating, SaturatedConversion,
|
||||
AtLeast32Bit, UniqueSaturatedInto, UniqueSaturatedFrom, Saturating, SaturatedConversion,
|
||||
Zero, One, Bounded, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv,
|
||||
CheckedShl, CheckedShr, IntegerSquareRoot
|
||||
};
|
||||
@@ -502,7 +502,7 @@ pub trait Header:
|
||||
{
|
||||
/// Header number.
|
||||
type Number: Member + MaybeSerializeDeserialize + Debug + sp_std::hash::Hash
|
||||
+ Copy + MaybeDisplay + SimpleArithmetic + Codec + sp_std::str::FromStr
|
||||
+ Copy + MaybeDisplay + AtLeast32Bit + Codec + sp_std::str::FromStr
|
||||
+ MaybeMallocSizeOf;
|
||||
/// Header hash type
|
||||
type Hash: Member + MaybeSerializeDeserialize + Debug + sp_std::hash::Hash + Ord
|
||||
|
||||
Reference in New Issue
Block a user