Struct Amount
pub struct Amount(/* private fields */);Expand description
A Bitcoin amount, internally represented as a satoshi [Decimal], which
provides the following properties:
- The contained value is non-negative.
- The contained value is no greater than
Amount::MAX. - Converting to sats, bits, or BTC and back via divisions and multiplications by 1000 doesn’t lose any precision beyond msat.
- The contained value is always rounded to the nearest msat.
Implementations§
§impl Amount
impl Amount
pub const MAX_BITCOIN_SUPPLY: Amount
pub const MAX_BITCOIN_SUPPLY: Amount
The maximum supply of Bitcoin that can ever exist. Analogous to
[bitcoin::Amount::MAX_MONEY]; primarily useful as a sanity check.
pub const MAX_BITCOIN_SUPPLY_SATS_U64: u64 = 2_100_000_000_000_000u64
pub const MAX_BITCOIN_SUPPLY_MSATS_U64: u64 = 2_100_000_000_000_000_000u64
pub const INVOICE_MAX_AMOUNT_MSATS_U64: u64 = 1_844_674_407_370_955_161u64
pub const INVOICE_MAX_AMOUNT_MSATS_U64: u64 = 1_844_674_407_370_955_161u64
The maximum amount we can set in a BOLT11 invoice via the LDK
[lightning_invoice::InvoiceBuilder::amount_milli_satoshis] API.
Setting above this value will overflow!
pub fn from_sats_u32(sats_u32: u32) -> Amount
pub fn from_sats_u32(sats_u32: u32) -> Amount
pub fn try_from_sats_u64(sats_u64: u64) -> Result<Amount, Error>
pub fn try_from_sats_u64(sats_u64: u64) -> Result<Amount, Error>
pub fn try_from_sats(sats: Decimal) -> Result<Amount, Error>
pub fn try_from_sats(sats: Decimal) -> Result<Amount, Error>
Construct an Amount from a satoshi [Decimal] value.
pub fn try_from_btc(btc: Decimal) -> Result<Amount, Error>
pub fn try_from_btc(btc: Decimal) -> Result<Amount, Error>
Construct an Amount from a BTC [Decimal] value.
pub fn invoice_safe_msat(&self) -> Result<u64, Error>
pub fn invoice_safe_msat(&self) -> Result<u64, Error>
pub fn abs_diff(self, other: Amount) -> Amount
pub fn abs_diff(self, other: Amount) -> Amount
Returns the absolute difference |x-y| between two Amounts.
pub fn approx_eq(self, other: Amount, epsilon: Amount) -> bool
pub fn approx_eq(self, other: Amount, epsilon: Amount) -> bool
Returns true if two amounts are approximately equal, up to some
epsilon max difference.
pub fn checked_add(self, rhs: Amount) -> Option<Amount>
pub fn checked_sub(self, rhs: Amount) -> Option<Amount>
pub fn checked_mul(self, rhs: Decimal) -> Option<Amount>
pub fn checked_div(self, rhs: Decimal) -> Option<Amount>
pub fn saturating_add(self, rhs: Amount) -> Amount
pub fn saturating_sub(self, rhs: Amount) -> Amount
pub fn saturating_mul(self, rhs: Decimal) -> Amount
Trait Implementations§
§impl AddAssign for Amount
impl AddAssign for Amount
§fn add_assign(&mut self, rhs: Amount)
fn add_assign(&mut self, rhs: Amount)
Performs the
+= operation. Read more§impl<'de> Deserialize<'de> for Amount
impl<'de> Deserialize<'de> for Amount
§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
§impl Ord for Amount
impl Ord for Amount
§impl PartialOrd for Amount
impl PartialOrd for Amount
§impl Serialize for Amount
impl Serialize for Amount
§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 UnwindSafe for Amount
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.