pub struct Invoice { /* private fields */ }
Expand description

Represents a syntactically and semantically correct lightning BOLT11 invoice.

There are three ways to construct an Invoice:

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

Implementations§

source§

impl Invoice

source

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

The hash of the RawInvoice that was signed.

source

pub fn into_signed_raw(self) -> SignedRawInvoice

Transform the Invoice into it’s unchecked version

source

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

Check that the invoice is signed correctly and that key recovery works

source

pub fn from_signed( signed_invoice: SignedRawInvoice ) -> Result<Self, SemanticError>

Constructs an Invoice from a SignedRawInvoice 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::<SignedRawInvoice>().unwrap();

assert!(Invoice::from_signed(signed).is_ok());
source

pub fn timestamp(&self) -> SystemTime

Available on crate feature std only.

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

source

pub fn duration_since_epoch(&self) -> Duration

Returns the Invoice’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 Invoice.

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) -> InvoiceDescription<'_>

Return the description or a hash of it for longer ones

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

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<&InvoiceFeatures>

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

Available on crate feature std only.

Returns whether the invoice has expired.

source

pub fn duration_until_expiry(&self) -> Duration

Available on crate feature std only.

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 Clone for Invoice

source§

fn clone(&self) -> Invoice

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 Debug for Invoice

source§

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

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

impl<'de> Deserialize<'de> for Invoice

Available on crate feature serde only.
source§

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

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

impl Display for Invoice

source§

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

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

impl FromStr for Invoice

use lightning_invoice::Invoice;


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

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

type Err = ParseOrSemanticError

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

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

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

impl Hash for Invoice

source§

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

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 PartialEq<Invoice> for Invoice

source§

fn eq(&self, other: &Invoice) -> 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 Serialize for Invoice

Available on crate feature serde only.
source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Invoice

source§

impl StructuralEq for Invoice

source§

impl StructuralPartialEq for Invoice

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<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

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

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.
source§

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