mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Move substrate/serai/* to substrate/*
This commit is contained in:
40
substrate/primitives/src/balance.rs
Normal file
40
substrate/primitives/src/balance.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
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 }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user