Struct linera_base::data_types::Amount
source · pub struct Amount(/* private fields */);Expand description
A non-negative amount of tokens.
This is a fixed-point fraction, with Amount::DECIMAL_PLACES digits after the point.
Amount::ONE is one whole token, divisible into 10.pow(Amount::DECIMAL_PLACES) parts.
Implementations§
source§impl Amount
impl Amount
pub const ZERO: Self = _
pub const MAX: Self = _
pub fn try_add(self, other: Self) -> Result<Self, ArithmeticError>
pub fn try_add_one(self) -> Result<Self, ArithmeticError>
pub fn saturating_add(self, other: Self) -> Self
pub fn try_sub(self, other: Self) -> Result<Self, ArithmeticError>
pub fn try_sub_one(self) -> Result<Self, ArithmeticError>
pub fn saturating_sub(self, other: Self) -> Self
pub fn try_add_assign(&mut self, other: Self) -> Result<(), ArithmeticError>
pub fn try_add_assign_one(&mut self) -> Result<(), ArithmeticError>
pub fn saturating_add_assign(&mut self, other: Self)
pub fn try_sub_assign(&mut self, other: Self) -> Result<(), ArithmeticError>
pub fn saturating_mul(&self, other: u128) -> Self
pub fn try_mul(self, other: u128) -> Result<Self, ArithmeticError>
pub fn try_mul_assign(&mut self, other: u128) -> Result<(), ArithmeticError>
source§impl Amount
impl Amount
pub const DECIMAL_PLACES: u8 = 18u8
pub const ONE: Amount = _
sourcepub fn from_tokens(tokens: u128) -> Amount
pub fn from_tokens(tokens: u128) -> Amount
Returns an Amount corresponding to that many tokens, or Amount::MAX if saturated.
sourcepub fn from_milli(millitokens: u128) -> Amount
pub fn from_milli(millitokens: u128) -> Amount
Returns an Amount corresponding to that many millitokens, or Amount::MAX if saturated.
sourcepub fn from_atto(attotokens: u128) -> Amount
pub fn from_atto(attotokens: u128) -> Amount
Returns an Amount corresponding to that many attotokens.
sourcepub fn upper_half(self) -> u64
pub fn upper_half(self) -> u64
Helper function to obtain the 64 most significant bits of the balance.
sourcepub fn lower_half(self) -> u64
pub fn lower_half(self) -> u64
Helper function to obtain the 64 least significant bits of the balance.
sourcepub fn saturating_div(self, other: Amount) -> u128
pub fn saturating_div(self, other: Amount) -> u128
Divides this by the other amount. If the other is 0, it returns u128::MAX.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Amount
impl<'de> Deserialize<'de> for Amount
source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
source§impl InputType for Amount
impl InputType for Amount
§type RawValueType = Amount
type RawValueType = Amount
The raw type used for validator. Read more
source§fn create_type_info(registry: &mut Registry) -> String
fn create_type_info(registry: &mut Registry) -> String
Create type information in the registry and return qualified typename.
source§fn parse(value: Option<Value>) -> InputValueResult<Self>
fn parse(value: Option<Value>) -> InputValueResult<Self>
Parse from
Value. None represents undefined.source§fn as_raw_value(&self) -> Option<&Self::RawValueType>
fn as_raw_value(&self) -> Option<&Self::RawValueType>
Returns a reference to the raw value.
source§fn qualified_type_name() -> String
fn qualified_type_name() -> String
Qualified typename.
source§impl Ord for Amount
impl Ord for Amount
source§impl OutputType for Amount
impl OutputType for Amount
source§fn create_type_info(registry: &mut Registry) -> String
fn create_type_info(registry: &mut Registry) -> String
Create type information in the registry and return qualified typename.
source§fn resolve<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_: &'life1 ContextSelectionSet<'life2>,
_field: &'life3 Positioned<Field>
) -> Pin<Box<dyn Future<Output = ServerResult<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn resolve<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _: &'life1 ContextSelectionSet<'life2>, _field: &'life3 Positioned<Field> ) -> Pin<Box<dyn Future<Output = ServerResult<Value>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,
Resolve an output value to
async_graphql::Value.source§fn qualified_type_name() -> String
fn qualified_type_name() -> String
Qualified typename.
source§impl PartialEq for Amount
impl PartialEq for Amount
source§impl PartialOrd for Amount
impl PartialOrd for Amount
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moresource§impl ScalarType for Amount
impl ScalarType for Amount
impl Copy for Amount
impl Eq for Amount
impl StructuralEq for Amount
impl StructuralPartialEq for Amount
Auto Trait Implementations§
impl RefUnwindSafe for Amount
impl Send for Amount
impl Sync for Amount
impl Unpin 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<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.