pub struct BitcoinAmount {
    pub satoshi: u64,
}
Expand description

Contains a field representing the amount of satoshis in the amount. Has functions to convert to and from the main unit (BTC) and the smallest unit (satoshi).

Fields§

§satoshi: u64

The number of satoshis (the smallest unit of the bitcoin currency) in the amount.

There are 100 million satoshis per bitcoin (BTC).

Implementations§

source§

impl BitcoinAmount

source

pub fn from_btc(btc_amount: f64) -> Self

Returns a BitcoinAmount struct from a decimal value representing the amount in BTC.

source

pub fn from_satoshi(satoshi_amount: u64) -> Self

Returns a BitcoinAmount struct from an integer value representing the amount in satoshis.

source

pub fn btc(&self) -> f64

Returns the amount in BTC as a f64.

source

pub fn satoshi(&self) -> u64

Returns the amount in satoshis as a u64.

Trait Implementations§

source§

impl Add<BitcoinAmount> for BitcoinAmount

§

type Output = Result<BitcoinAmount, Error>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Result<Self, Error>

Performs the + operation. Read more
source§

impl Clone for BitcoinAmount

source§

fn clone(&self) -> BitcoinAmount

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl CryptoAmount for BitcoinAmount

source§

fn from_main_unit_decimal_value(value: f64) -> Self

In the units of main “big” unit (a floating point number, not an integer subdivision) using decimal value, for bitcoin BTC, ethereum ETH, etc. The CryptoAmount is a wrapper around a floating point number and the default integer value stored is in the smallest unit of the coin. For example this would be satoshi for bitcoin, wei for ethereum, etc. The decimal value is the floating point number representation in the main unit of the coin, for example BTC, ETH, etc.
source§

fn from_smallest_unit_integer_value(value: u64) -> Self

Creates a new CryptoAmount from the smallest unit of the coin, for example satoshi for bitcoin, wei for ethereum, etc.
source§

fn to_main_unit_decimal_value(&self) -> f64

Returns the decimal value of the CryptoAmount, this is the floating point number representation in the main unit of the coin, for example BTC, ETH, etc.
source§

fn to_smallest_unit_integer_value(&self) -> u64

Returns the integer value of the CryptoAmount, this is the integer representation in the smallest unit of the coin, for example satoshi for bitcoin, wei for ethereum, etc.
source§

fn new() -> Selfwhere Self: Sized,

Constructs a new CryptoAmount with a value of 0.0
source§

impl Default for BitcoinAmount

source§

fn default() -> BitcoinAmount

Returns the “default value” for a type. Read more
source§

impl Mul<f64> for BitcoinAmount

§

type Output = Result<BitcoinAmount, Error>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: f64) -> Self::Output

Performs the * operation. Read more
source§

impl Ord for BitcoinAmount

source§

fn cmp(&self, other: &BitcoinAmount) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<BitcoinAmount> for BitcoinAmount

source§

fn eq(&self, other: &BitcoinAmount) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<BitcoinAmount> for BitcoinAmount

source§

fn partial_cmp(&self, other: &BitcoinAmount) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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 more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub<BitcoinAmount> for BitcoinAmount

§

type Output = Result<BitcoinAmount, Error>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Result<Self, Error>

Performs the - operation. Read more
source§

impl Copy for BitcoinAmount

source§

impl Eq for BitcoinAmount

source§

impl StructuralEq for BitcoinAmount

source§

impl StructuralPartialEq for BitcoinAmount

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

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,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more