pub struct Amount(/* private fields */);Expand description
A non-negative Bitcoin amount in satoshis. Serialized as a string-encoded
decimal to avoid floating-point precision loss (e.g. "1234.567").
Sub-satoshi precision down to the millisatoshi is supported.
Implementations§
Source§impl Amount
impl Amount
Sourcepub const MAX_BITCOIN_SUPPLY: Self
pub const MAX_BITCOIN_SUPPLY: Self
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 = 21_000_000_0000_0000
pub const MAX_BITCOIN_SUPPLY_MSATS_U64: u64 = 21_000_000_0000_0000_000
Sourcepub const INVOICE_MAX_AMOUNT_MSATS_U64: u64
pub const INVOICE_MAX_AMOUNT_MSATS_U64: u64
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!
Sourcepub fn from_sats_u32(sats_u32: u32) -> Self
pub fn from_sats_u32(sats_u32: u32) -> Self
Sourcepub fn try_from_sats_u64(sats_u64: u64) -> Result<Self, Error>
pub fn try_from_sats_u64(sats_u64: u64) -> Result<Self, Error>
Sourcepub fn try_from_sats(sats: Decimal) -> Result<Self, Error>
pub fn try_from_sats(sats: Decimal) -> Result<Self, Error>
Sourcepub fn try_from_btc(btc: Decimal) -> Result<Self, Error>
pub fn try_from_btc(btc: Decimal) -> Result<Self, Error>
Sourcepub fn invoice_safe_msat(&self) -> Result<u64, Error>
pub fn invoice_safe_msat(&self) -> Result<u64, Error>
Sourcepub fn abs_diff(self, other: Self) -> Amount
pub fn abs_diff(self, other: Self) -> Amount
Returns the absolute difference |x-y| between two Amounts.
Sourcepub fn approx_eq(self, other: Self, epsilon: Self) -> bool
pub fn approx_eq(self, other: Self, epsilon: Self) -> bool
Returns true if two amounts are approximately equal, up to some
epsilon max difference.
pub fn checked_add(self, rhs: Self) -> Option<Self>
pub fn checked_sub(self, rhs: Self) -> Option<Self>
pub fn checked_mul(self, rhs: Decimal) -> Option<Self>
pub fn checked_div(self, rhs: Decimal) -> Option<Self>
pub fn saturating_add(self, rhs: Self) -> Self
pub fn saturating_sub(self, rhs: Self) -> Self
pub fn saturating_mul(self, rhs: Decimal) -> Self
Trait Implementations§
Source§impl AddAssign for Amount
impl AddAssign for Amount
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+= operation. Read moreSource§impl<'de> Deserialize<'de> for Amount
impl<'de> Deserialize<'de> for Amount
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for Amount
impl Ord for Amount
Source§impl PartialOrd for Amount
impl PartialOrd for Amount
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