From d0ee7a99615cc75b581472e00febe86509f44897 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Sat, 15 Aug 2020 22:00:57 -0700 Subject: [PATCH] chain: amount::AmountConstraint -> amount::Constraint --- zebra-chain/src/amount.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/zebra-chain/src/amount.rs b/zebra-chain/src/amount.rs index 8cc96ea3c..24cd28c37 100644 --- a/zebra-chain/src/amount.rs +++ b/zebra-chain/src/amount.rs @@ -13,14 +13,14 @@ type Result = std::result::Result; /// A runtime validated type for representing amounts of zatoshis #[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize, Deserialize)] #[serde(try_from = "i64")] -#[serde(bound = "C: AmountConstraint")] +#[serde(bound = "C: Constraint")] pub struct Amount(i64, PhantomData); impl Amount { /// Convert this amount to a different Amount type if it satisfies the new constraint pub fn constrain(self) -> Result> where - C2: AmountConstraint, + C2: Constraint, { self.0.try_into() } @@ -35,7 +35,7 @@ impl Amount { impl std::ops::Add> for Amount where - C: AmountConstraint, + C: Constraint, { type Output = Result>; @@ -47,7 +47,7 @@ where impl std::ops::Add> for Result> where - C: AmountConstraint, + C: Constraint, { type Output = Result>; @@ -58,7 +58,7 @@ where impl std::ops::Add>> for Amount where - C: AmountConstraint, + C: Constraint, { type Output = Result>; @@ -70,7 +70,7 @@ where impl std::ops::AddAssign> for Result> where Amount: Copy, - C: AmountConstraint, + C: Constraint, { fn add_assign(&mut self, rhs: Amount) { if let Ok(lhs) = *self { @@ -81,7 +81,7 @@ where impl std::ops::Sub> for Amount where - C: AmountConstraint, + C: Constraint, { type Output = Result>; @@ -93,7 +93,7 @@ where impl std::ops::Sub> for Result> where - C: AmountConstraint, + C: Constraint, { type Output = Result>; @@ -104,7 +104,7 @@ where impl std::ops::Sub>> for Amount where - C: AmountConstraint, + C: Constraint, { type Output = Result>; @@ -116,7 +116,7 @@ where impl std::ops::SubAssign> for Result> where Amount: Copy, - C: AmountConstraint, + C: Constraint, { fn sub_assign(&mut self, rhs: Amount) { if let Ok(lhs) = *self { @@ -150,7 +150,7 @@ impl From> for jubjub::Fr { impl TryFrom for Amount where - C: AmountConstraint, + C: Constraint, { type Error = Error; @@ -161,7 +161,7 @@ where impl TryFrom for Amount where - C: AmountConstraint, + C: Constraint, { type Error = Error; @@ -172,7 +172,7 @@ where impl TryFrom for Amount where - C: AmountConstraint, + C: Constraint, { type Error = Error; @@ -205,7 +205,7 @@ pub enum Error { /// Marker type for `Amount` that restricts the values to `-MAX_MONEY..=MAX_MONEY` pub enum NegativeAllowed {} -impl AmountConstraint for NegativeAllowed { +impl Constraint for NegativeAllowed { fn valid_range() -> RangeInclusive { -MAX_MONEY..=MAX_MONEY } @@ -215,7 +215,7 @@ impl AmountConstraint for NegativeAllowed { /// Marker type for `Amount` that restricts the value to positive numbers `0..=MAX_MONEY` pub enum NonNegative {} -impl AmountConstraint for NonNegative { +impl Constraint for NonNegative { fn valid_range() -> RangeInclusive { 0..=MAX_MONEY } @@ -225,7 +225,7 @@ impl AmountConstraint for NonNegative { pub const MAX_MONEY: i64 = 21_000_000 * 100_000_000; /// A trait for defining constraints on `Amount` -pub trait AmountConstraint { +pub trait Constraint { /// Returns the range of values that are valid under this constraint fn valid_range() -> RangeInclusive; @@ -250,7 +250,7 @@ mod test { impl Arbitrary for Amount where - C: AmountConstraint + fmt::Debug, + C: Constraint + fmt::Debug, { type Parameters = ();