pub struct Currency(/* private fields */);Expand description
Represents a Mina currency amount stored internally as nanomina (atomic units).
§Examples
use mina_sdk::Currency;
let one_mina = Currency::from_mina("1.5").unwrap();
assert_eq!(one_mina.nanomina(), 1_500_000_000);
assert_eq!(one_mina.mina(), "1.500000000");Implementations§
Source§impl Currency
impl Currency
Sourcepub fn from_nanomina(nanomina: u64) -> Self
pub fn from_nanomina(nanomina: u64) -> Self
Create from a nanomina (atomic unit) value.
Sourcepub fn from_mina(s: &str) -> Result<Self>
pub fn from_mina(s: &str) -> Result<Self>
Create from a whole MINA decimal string (e.g. “1.5”, “100”, “0.000000001”).
Sourcepub fn from_graphql(s: &str) -> Result<Self>
pub fn from_graphql(s: &str) -> Result<Self>
Create from a GraphQL response value (nanomina as string).
Sourcepub fn to_nanomina_str(&self) -> String
pub fn to_nanomina_str(&self) -> String
Convert to nanomina string for GraphQL API submission.
Sourcepub fn checked_add(self, rhs: Currency) -> Option<Currency>
pub fn checked_add(self, rhs: Currency) -> Option<Currency>
Checked addition. Returns None on overflow.
Sourcepub fn checked_sub(self, rhs: Currency) -> Result<Currency>
pub fn checked_sub(self, rhs: Currency) -> Result<Currency>
Checked subtraction. Returns Err(CurrencyUnderflow) if result would be negative.
Sourcepub fn checked_mul(self, rhs: u64) -> Option<Currency>
pub fn checked_mul(self, rhs: u64) -> Option<Currency>
Multiply by a scalar.
Trait Implementations§
Source§impl Ord for Currency
impl Ord for Currency
Source§impl PartialOrd for Currency
impl PartialOrd for Currency
impl Copy for Currency
impl Eq for Currency
impl StructuralPartialEq for Currency
Auto Trait Implementations§
impl Freeze for Currency
impl RefUnwindSafe for Currency
impl Send for Currency
impl Sync for Currency
impl Unpin for Currency
impl UnsafeUnpin for Currency
impl UnwindSafe for Currency
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.