pub struct Amount { /* private fields */ }Expand description
Re-export common types A token amount with associated decimal precision.
Stores the raw (smallest-unit) value plus the number of decimals, avoiding floating-point imprecision.
Implementations§
Source§impl Amount
impl Amount
Sourcepub fn from_raw(raw: u128, decimals: u8) -> Amount
pub fn from_raw(raw: u128, decimals: u8) -> Amount
Create from the raw (smallest-unit) integer value.
Sourcepub fn from_human(s: &str, decimals: u8) -> Result<Amount, KmsError>
pub fn from_human(s: &str, decimals: u8) -> Result<Amount, KmsError>
Parse a human-readable decimal string (e.g. "1.5") into an Amount.
Sourcepub fn to_u256(&self) -> (Felt, Felt)
pub fn to_u256(&self) -> (Felt, Felt)
Encode as a Starknet u256 (low, high) Felt pair.
Since the raw value is u128, it fits entirely in the low limb.
Sourcepub fn checked_add(&self, other: &Amount) -> Result<Amount, KmsError>
pub fn checked_add(&self, other: &Amount) -> Result<Amount, KmsError>
Checked addition (decimals must match).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Amount
impl<'de> Deserialize<'de> for Amount
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Amount, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Amount, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for Amount
impl Serialize for Amount
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Copy for Amount
impl Eq for Amount
impl StructuralPartialEq for Amount
Auto Trait Implementations§
impl Freeze for Amount
impl RefUnwindSafe for Amount
impl Send for Amount
impl Sync for Amount
impl Unpin for Amount
impl UnsafeUnpin for Amount
impl UnwindSafe for Amount
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more