Struct Bolt11Invoice

Source
pub struct Bolt11Invoice { /* private fields */ }
Expand description

Represents a syntactically and semantically correct lightning BOLT11 invoice.

There are three ways to construct a Bolt11Invoice:

  1. using InvoiceBuilder
  2. using Bolt11Invoice::from_signed
  3. using str::parse::<Bolt11Invoice>(&str) (see Bolt11Invoice::from_str)

Implementations§

Source§

impl Bolt11Invoice

Source

pub fn signable_hash(&self) -> [u8; 32]

The hash of the RawBolt11Invoice that was signed.

Source

pub fn into_signed_raw(self) -> SignedRawBolt11Invoice

Transform the Bolt11Invoice into its unchecked version.

Source

pub fn check_signature(&self) -> Result<(), Bolt11SemanticError>

Check that the invoice is signed correctly

Source

pub fn from_signed( signed_invoice: SignedRawBolt11Invoice, ) -> Result<Bolt11Invoice, Bolt11SemanticError>

Constructs a Bolt11Invoice from a SignedRawBolt11Invoice by checking all its invariants.

use lightning_invoice::*;

let invoice = "lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\
h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\
5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\
h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\
j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\
ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\
guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\
ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\
p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\
8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\
j5r6drg6k6zcqj0fcwg";

let signed = invoice.parse::<SignedRawBolt11Invoice>().unwrap();

assert!(Bolt11Invoice::from_signed(signed).is_ok());
Source

pub fn timestamp(&self) -> SystemTime

Returns the Bolt11Invoice’s timestamp (should equal its creation time)

Source

pub fn duration_since_epoch(&self) -> Duration

Returns the Bolt11Invoice’s timestamp as a duration since the Unix epoch

Source

pub fn tagged_fields( &self, ) -> FilterMap<Iter<'_, RawTaggedField>, fn(&RawTaggedField) -> Option<&TaggedField>>

Returns an iterator over all tagged fields of this Bolt11Invoice.

This is not exported to bindings users as there is not yet a manual mapping for a FilterMap

Source

pub fn payment_hash(&self) -> &Hash

Returns the hash to which we will receive the preimage on completion of the payment

Source

pub fn description(&self) -> Bolt11InvoiceDescriptionRef<'_>

Return the description or a hash of it for longer ones

This is not exported to bindings users because we don’t yet export Bolt11InvoiceDescription

Source

pub fn payee_pub_key(&self) -> Option<&PublicKey>

Get the payee’s public key if one was included in the invoice

Source

pub fn payment_secret(&self) -> &PaymentSecret

Get the payment secret if one was included in the invoice

Source

pub fn payment_metadata(&self) -> Option<&Vec<u8>>

Get the payment metadata blob if one was included in the invoice

Source

pub fn features(&self) -> Option<&Features<Bolt11InvoiceContext>>

Get the invoice features if they were included in the invoice

Source

pub fn recover_payee_pub_key(&self) -> PublicKey

Recover the payee’s public key (only to be used if none was included in the invoice)

Source

pub fn get_payee_pub_key(&self) -> PublicKey

Recover the payee’s public key if one was included in the invoice, otherwise return the recovered public key from the signature

Source

pub fn expires_at(&self) -> Option<Duration>

Returns the Duration since the Unix epoch at which the invoice expires. Returning None if overflow occurred.

Source

pub fn expiry_time(&self) -> Duration

Returns the invoice’s expiry time, if present, otherwise DEFAULT_EXPIRY_TIME.

Source

pub fn is_expired(&self) -> bool

Returns whether the invoice has expired.

Source

pub fn duration_until_expiry(&self) -> Duration

Returns the Duration remaining until the invoice expires.

Source

pub fn expiration_remaining_from_epoch(&self, time: Duration) -> Duration

Returns the Duration remaining until the invoice expires given the current time. time is the timestamp as a duration since the Unix epoch.

Source

pub fn would_expire(&self, at_time: Duration) -> bool

Returns whether the expiry time would pass at the given point in time. at_time is the timestamp as a duration since the Unix epoch.

Source

pub fn min_final_cltv_expiry_delta(&self) -> u64

Returns the invoice’s min_final_cltv_expiry_delta time, if present, otherwise DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA.

Source

pub fn fallbacks(&self) -> Vec<&Fallback>

Returns a list of all fallback addresses

This is not exported to bindings users as we don’t support Vec<&NonOpaqueType>

Source

pub fn fallback_addresses(&self) -> Vec<Address>

Returns a list of all fallback addresses as Addresses

Source

pub fn private_routes(&self) -> Vec<&PrivateRoute>

Returns a list of all routes included in the invoice

Source

pub fn route_hints(&self) -> Vec<RouteHint>

Returns a list of all routes included in the invoice as the underlying hints

Source

pub fn currency(&self) -> Currency

Returns the currency for which the invoice was issued

Source

pub fn network(&self) -> Network

Returns the network for which the invoice was issued

This is not exported to bindings users, see Self::currency instead.

Source

pub fn amount_milli_satoshis(&self) -> Option<u64>

Returns the amount if specified in the invoice as millisatoshis.

Trait Implementations§

Source§

impl Bolt11InvoiceExt for Bolt11Invoice

Source§

fn get_final_amount( &self, user_amount: Option<Amount>, ) -> Result<Amount, CheckAmountError>

Get the amount to be paid. It checks both user and invoice equality if both are provided, else it tries to return one of them, or returns an error if neither are provided.
Source§

impl Clone for Bolt11Invoice

Source§

fn clone(&self) -> Bolt11Invoice

Returns a duplicate 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 Debug for Bolt11Invoice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Bolt11Invoice

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Bolt11Invoice, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Bolt11Invoice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a Bolt11Invoice> for PaymentHash

Source§

fn from(i: &'a Bolt11Invoice) -> Self

Converts to this type from the input type.
Source§

impl From<Bolt11Invoice> for Invoice

Source§

fn from(invoice: Bolt11Invoice) -> Self

Converts to this type from the input type.
Source§

impl From<Bolt11Invoice> for PaymentHash

Source§

fn from(i: Bolt11Invoice) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Bolt11Invoice

use lightning_invoice::Bolt11Invoice;


let invoice = "lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\
h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\
5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\
h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\
j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\
ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\
guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\
ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\
p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\
8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\
j5r6drg6k6zcqj0fcwg";

assert!(invoice.parse::<Bolt11Invoice>().is_ok());
Source§

type Err = ParseOrSemanticError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Bolt11Invoice, <Bolt11Invoice as FromStr>::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Bolt11Invoice

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Bolt11Invoice

Source§

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

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

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

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

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

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

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

impl PartialEq for Bolt11Invoice

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Bolt11Invoice

Source§

fn partial_cmp(&self, other: &Bolt11Invoice) -> 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Bolt11Invoice

Source§

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
Source§

impl Eq for Bolt11Invoice

Source§

impl StructuralPartialEq for Bolt11Invoice

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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

Checks if this value is equivalent to the given key. Read more
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 T
where 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.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

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

Source§

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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,