Bound Unsigned when signed is not supported. (#6367)

* bound unsigned when necessary

* convert more type to AtLeast32BitUnsigned

* Update primitives/arithmetic/src/traits.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* doc refactor

* line reorganize

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Guillaume Thiolliere
2020-06-25 11:30:20 +02:00
committed by GitHub
parent b17ccf24a8
commit 44fb311f1f
16 changed files with 84 additions and 74 deletions
+4 -3
View File
@@ -25,7 +25,7 @@ use sp_core::u32_trait::Value as U32;
use sp_runtime::{
RuntimeDebug, ConsensusEngineId, DispatchResult, DispatchError, traits::{
MaybeSerializeDeserialize, AtLeast32Bit, Saturating, TrailingZeroInput, Bounded, Zero,
BadOrigin
BadOrigin, AtLeast32BitUnsigned
},
};
use crate::dispatch::Parameter;
@@ -788,7 +788,7 @@ pub enum SignedImbalance<B, P: Imbalance<B>>{
impl<
P: Imbalance<B, Opposite=N>,
N: Imbalance<B, Opposite=P>,
B: AtLeast32Bit + FullCodec + Copy + MaybeSerializeDeserialize + Debug + Default,
B: AtLeast32BitUnsigned + FullCodec + Copy + MaybeSerializeDeserialize + Debug + Default,
> SignedImbalance<B, P> {
pub fn zero() -> Self {
SignedImbalance::Positive(P::zero())
@@ -851,7 +851,8 @@ impl<
/// Abstraction over a fungible assets system.
pub trait Currency<AccountId> {
/// The balance of an account.
type Balance: AtLeast32Bit + FullCodec + Copy + MaybeSerializeDeserialize + Debug + Default;
type Balance: AtLeast32BitUnsigned + FullCodec + Copy + MaybeSerializeDeserialize + Debug +
Default;
/// The opaque token type for an imbalance. This is returned by unbalanced operations
/// and must be dealt with. It may be dropped but cannot be cloned.
+3 -3
View File
@@ -136,7 +136,7 @@ use sp_runtime::{
};
use crate::dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo, DispatchError};
use sp_runtime::traits::SaturatedConversion;
use sp_arithmetic::{Perbill, traits::{BaseArithmetic, Saturating}};
use sp_arithmetic::{Perbill, traits::{BaseArithmetic, Saturating, Unsigned}};
use smallvec::{smallvec, SmallVec};
/// Re-export priority as type
@@ -571,7 +571,7 @@ pub type WeightToFeeCoefficients<T> = SmallVec<[WeightToFeeCoefficient<T>; 4]>;
/// An implementor should only implement the `polynomial` function.
pub trait WeightToFeePolynomial {
/// The type that is returned as result from polynomial evaluation.
type Balance: BaseArithmetic + From<u32> + Copy;
type Balance: BaseArithmetic + From<u32> + Copy + Unsigned;
/// Returns a polynomial that describes the weight to fee conversion.
///
@@ -611,7 +611,7 @@ pub trait WeightToFeePolynomial {
pub struct IdentityFee<T>(sp_std::marker::PhantomData<T>);
impl<T> WeightToFeePolynomial for IdentityFee<T> where
T: BaseArithmetic + From<u32> + Copy
T: BaseArithmetic + From<u32> + Copy + Unsigned
{
type Balance = T;