pub struct Amount(/* private fields */);Expand description
Number of millisatoshis.
This type represents a number of millisatoshis (thousands of satoshi) which is the base unit of the lightning network. It provides ordinary arithmetic and conversion methods.
§Invariants
This type guarantees that the amount stays less than or equal to 21 million bitcoins.
However unsafe code must not rely on this, at least for now.
This implies that arithmetic operations always panic on overflow.
§Display implementation
To avoid confusion, the amount is displayed with msat suffix - e.g. 42 msat.
No other representations are supported yet, feel free to contribute!
Implementations§
Source§impl Amount
impl Amount
Sourcepub fn from_msat(msat: u64) -> Result<Self, OverflowError>
pub fn from_msat(msat: u64) -> Result<Self, OverflowError>
Sourcepub fn from_sat(sat: u64) -> Result<Self, OverflowError>
pub fn from_sat(sat: u64) -> Result<Self, OverflowError>
Sourcepub fn to_msat(self) -> u64
pub fn to_msat(self) -> u64
Converts the value to raw millisatoshis.
§Example
let msat = ln_types::Amount::ONE_SAT.to_msat();
assert_eq!(msat, 1000);Sourcepub fn to_sat(self) -> Result<u64, FractionError>
pub fn to_sat(self) -> Result<u64, FractionError>
Sourcepub fn to_sat_floor(self) -> u64
pub fn to_sat_floor(self) -> u64
Converts to satoshis rounding down.
§Example
let msat = ln_types::Amount::ONE_MSAT.to_sat_floor();
assert_eq!(msat, 0);Sourcepub fn to_sat_ceiling(self) -> u64
pub fn to_sat_ceiling(self) -> u64
Converts to satoshis rounding up.
§Example
let msat = ln_types::Amount::ONE_MSAT.to_sat_ceiling();
assert_eq!(msat, 1);Sourcepub fn to_sat_round(self) -> u64
pub fn to_sat_round(self) -> u64
Converts to satoshis rounding.
§Example
let msat = ln_types::Amount::ONE_MSAT.to_sat_round();
assert_eq!(msat, 0);Trait Implementations§
Source§impl AddAssign for Amount
Panics on overflow
impl AddAssign for Amount
Panics on overflow
Source§fn add_assign(&mut self, rhs: Amount)
fn add_assign(&mut self, rhs: Amount)
+= operation. Read moreSource§impl<'de> Deserialize<'de> for Amount
Available on crate feature serde only.The value is deserialized as u64 msats.
impl<'de> Deserialize<'de> for Amount
serde only.The value is deserialized as u64 msats.
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>,
Source§impl DivAssign<u64> for Amount
impl DivAssign<u64> for Amount
Source§fn div_assign(&mut self, rhs: u64)
fn div_assign(&mut self, rhs: u64)
/= operation. Read moreSource§impl<'a> FromSql<'a> for Amount
Available on crate feature postgres-types only.Retrieved as i64 msats with range check
impl<'a> FromSql<'a> for Amount
postgres-types only.Retrieved as i64 msats with range check
Source§fn from_sql(
ty: &Type,
raw: &'a [u8],
) -> Result<Self, Box<dyn Error + Send + Sync + 'static>>
fn from_sql( ty: &Type, raw: &'a [u8], ) -> Result<Self, Box<dyn Error + Send + Sync + 'static>>
Type in its binary format. Read moreSource§fn accepts(ty: &Type) -> bool
fn accepts(ty: &Type) -> bool
Type.Source§impl FromStr for Amount
Accepts an unsigned integer up to 21 000 000 BTC
The amount may optionally be followed by denomination msat.
impl FromStr for Amount
Accepts an unsigned integer up to 21 000 000 BTC
The amount may optionally be followed by denomination msat.
Source§impl MulAssign<u64> for Amount
Panics on overflow
impl MulAssign<u64> for Amount
Panics on overflow
Source§fn mul_assign(&mut self, rhs: u64)
fn mul_assign(&mut self, rhs: u64)
*= operation. Read moreSource§impl Ord for Amount
impl Ord for Amount
Source§impl ParseArgFromStr for Amount
Available on crate feature parse_arg only.
impl ParseArgFromStr for Amount
parse_arg only.Source§impl PartialOrd for Amount
impl PartialOrd for Amount
Source§impl RemAssign<u64> for Amount
impl RemAssign<u64> for Amount
Source§fn rem_assign(&mut self, rhs: u64)
fn rem_assign(&mut self, rhs: u64)
%= operation. Read moreSource§impl Serialize for Amount
Available on crate feature serde only.The value is serialized as u64 msats.
impl Serialize for Amount
serde only.The value is serialized as u64 msats.
Source§impl SubAssign for Amount
Panics on overflow
impl SubAssign for Amount
Panics on overflow
Source§fn sub_assign(&mut self, rhs: Amount)
fn sub_assign(&mut self, rhs: Amount)
-= operation. Read moreSource§impl ToSql for Amount
Available on crate feature postgres-types only.Stored as i64 msats
impl ToSql for Amount
postgres-types only.Stored as i64 msats
Source§fn to_sql(
&self,
ty: &Type,
out: &mut BytesMut,
) -> Result<IsNull, Box<dyn Error + Send + Sync + 'static>>
fn to_sql( &self, ty: &Type, out: &mut BytesMut, ) -> Result<IsNull, Box<dyn Error + Send + Sync + 'static>>
self into the binary format of the specified
Postgres Type, appending it to out. Read moreSource§fn accepts(ty: &Type) -> bool
fn accepts(ty: &Type) -> bool
Type.Source§fn to_sql_checked(
&self,
ty: &Type,
out: &mut BytesMut,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn to_sql_checked( &self, ty: &Type, out: &mut BytesMut, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§fn encode_format(&self, _ty: &Type) -> Format
fn encode_format(&self, _ty: &Type) -> Format
Source§impl<'a> TryFrom<&'a str> for Amount
Accepts an unsigned integer up to 21 000 000 BTC
The amount may optionally be followed by denomination msat.
impl<'a> TryFrom<&'a str> for Amount
Accepts an unsigned integer up to 21 000 000 BTC
The amount may optionally be followed by denomination msat.
Source§impl TryFrom<Box<str>> for Amount
Available on crate feature alloc only.Accepts an unsigned integer up to 21 000 000 BTC
The amount may optionally be followed by denomination msat.
impl TryFrom<Box<str>> for Amount
alloc only.Accepts an unsigned integer up to 21 000 000 BTC
The amount may optionally be followed by denomination msat.
Source§impl TryFrom<String> for Amount
Available on crate feature alloc only.Accepts an unsigned integer up to 21 000 000 BTC
The amount may optionally be followed by denomination msat.
impl TryFrom<String> for Amount
alloc only.Accepts an unsigned integer up to 21 000 000 BTC
The amount may optionally be followed by denomination msat.
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§
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
Source§impl<T> BorrowToSql for Twhere
T: ToSql,
impl<T> BorrowToSql for Twhere
T: ToSql,
Source§fn borrow_to_sql(&self) -> &dyn ToSql
fn borrow_to_sql(&self) -> &dyn ToSql
self as a ToSql trait object.