mirror of
https://github.com/serai-dex/serai.git
synced 2025-01-11 05:14:41 +00:00
40 lines
1,013 B
Rust
40 lines
1,013 B
Rust
use core::ops::{Add, Sub, Mul};
|
|
|
|
#[cfg(feature = "std")]
|
|
use zeroize::Zeroize;
|
|
|
|
use scale::{Encode, Decode, MaxEncodedLen};
|
|
use scale_info::TypeInfo;
|
|
#[cfg(feature = "std")]
|
|
use serde::{Serialize, Deserialize};
|
|
|
|
use crate::{Coin, Amount};
|
|
|
|
/// The type used for balances (a Coin and Balance).
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
|
|
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
|
|
pub struct Balance {
|
|
pub coin: Coin,
|
|
pub amount: Amount,
|
|
}
|
|
|
|
impl Add<Amount> for Balance {
|
|
type Output = Balance;
|
|
fn add(self, other: Amount) -> Balance {
|
|
Balance { coin: self.coin, amount: self.amount + other }
|
|
}
|
|
}
|
|
|
|
impl Sub<Amount> for Balance {
|
|
type Output = Balance;
|
|
fn sub(self, other: Amount) -> Balance {
|
|
Balance { coin: self.coin, amount: self.amount - other }
|
|
}
|
|
}
|
|
|
|
impl Mul<Amount> for Balance {
|
|
type Output = Balance;
|
|
fn mul(self, other: Amount) -> Balance {
|
|
Balance { coin: self.coin, amount: self.amount * other }
|
|
}
|
|
}
|