mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-23 03:59:22 +00:00
Ensure Amount uses checked ops
This commit is contained in:
parent
8ca90e7905
commit
27f5881553
1 changed files with 11 additions and 5 deletions
|
@ -1,6 +1,4 @@
|
|||
use core::{
|
||||
ops::{Add, Mul},
|
||||
};
|
||||
use core::ops::{Add, Sub, Mul};
|
||||
|
||||
use scale::{Encode, Decode, MaxEncodedLen};
|
||||
use scale_info::TypeInfo;
|
||||
|
@ -21,13 +19,21 @@ pub const COIN: Amount = Amount(1_000_000_00);
|
|||
impl Add for Amount {
|
||||
type Output = Amount;
|
||||
fn add(self, other: Amount) -> Amount {
|
||||
Amount(self.0 + other.0)
|
||||
// Explicitly use checked_add so even if range checks are disabled, this is still checked
|
||||
Amount(self.0.checked_add(other.0).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl Sub for Amount {
|
||||
type Output = Amount;
|
||||
fn sub(self, other: Amount) -> Amount {
|
||||
Amount(self.0.checked_sub(other.0).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul for Amount {
|
||||
type Output = Amount;
|
||||
fn mul(self, other: Amount) -> Amount {
|
||||
Amount(self.0 * other.0)
|
||||
Amount(self.0.checked_mul(other.0).unwrap())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue