mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Ensure Amount uses checked ops
This commit is contained in:
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user