X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning_invoice%2Fmod.rs;fp=lightning-c-bindings%2Fsrc%2Flightning_invoice%2Fmod.rs;h=a12e906f4b060dc2d252e56da98b988c3a09f638;hb=5eebd45b471833805e81ad4c23ec93d7711e0a23;hp=0000000000000000000000000000000000000000;hpb=c35ef17b94a8f4e9e019a2b63e0ed22110671b9c;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning_invoice/mod.rs b/lightning-c-bindings/src/lightning_invoice/mod.rs new file mode 100644 index 0000000..a12e906 --- /dev/null +++ b/lightning-c-bindings/src/lightning_invoice/mod.rs @@ -0,0 +1,2119 @@ +// This file is Copyright its original authors, visible in version control +// history and in the source files from which this was generated. +// +// This file is licensed under the license available in the LICENSE or LICENSE.md +// file in the root of this repository or, if no such file exists, the same +// license as that which applies to the original source files from which this +// source was automatically generated. + +//! This crate provides data structures to represent +//! [lightning BOLT11](https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md) +//! invoices and functions to create, encode and decode these. If you just want to use the standard +//! en-/decoding functionality this should get you started: +//! +//! * For parsing use `str::parse::(&self)` (see the docs of `impl FromStr for Invoice`) +//! * For constructing invoices use the `InvoiceBuilder` +//! * For serializing invoices use the `Display`/`ToString` traits + +use std::str::FromStr; +use std::ffi::c_void; +use bitcoin::hashes::Hash; +use crate::c_types::*; + +pub mod constants; +mod de { + +use std::str::FromStr; +use std::ffi::c_void; +use bitcoin::hashes::Hash; +use crate::c_types::*; + +mod hrp_sm { + +use std::str::FromStr; +use std::ffi::c_void; +use bitcoin::hashes::Hash; +use crate::c_types::*; + +} +} +mod ser { + +use std::str::FromStr; +use std::ffi::c_void; +use bitcoin::hashes::Hash; +use crate::c_types::*; + +} +mod tb { + +use std::str::FromStr; +use std::ffi::c_void; +use bitcoin::hashes::Hash; +use crate::c_types::*; + +} +/// **Call this function on startup to ensure that all assumptions about the platform are valid.** +/// +/// Unfortunately we have to make assumptions about the upper bounds of the `SystemTime` type on +/// your platform which we can't fully verify at compile time and which isn't part of it's contract. +/// To our best knowledge our assumptions hold for all platforms officially supported by rust, but +/// since this check is fast we recommend to do it anyway. +/// +/// If this function fails this is considered a bug. Please open an issue describing your +/// platform and stating your current system time. +/// +/// # Panics +/// If the check fails this function panics. By calling this function on startup you ensure that +/// this wont happen at an arbitrary later point in time. +#[no_mangle] +pub extern "C" fn check_platform() { + lightning_invoice::check_platform() +} + + +use lightning_invoice::Invoice as nativeInvoiceImport; +type nativeInvoice = nativeInvoiceImport; + +/// 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(SignedRawInvoice)` +/// 3. using `str::parse::(&str)` +#[must_use] +#[repr(C)] +pub struct Invoice { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeInvoice, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for Invoice { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +/// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn Invoice_free(this_obj: Invoice) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn Invoice_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl Invoice { + pub(crate) fn take_inner(mut self) -> *mut nativeInvoice { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +impl Clone for Invoice { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeInvoice>::is_null(self.inner) { std::ptr::null_mut() } else { + Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the Invoice +pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice { + orig.clone() +} + +use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport; +type nativeSignedRawInvoice = nativeSignedRawInvoiceImport; + +/// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be +/// invalid. +/// +/// # Invariants +/// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`. +#[must_use] +#[repr(C)] +pub struct SignedRawInvoice { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeSignedRawInvoice, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for SignedRawInvoice { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +/// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl SignedRawInvoice { + pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +impl Clone for SignedRawInvoice { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else { + Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the SignedRawInvoice +pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice { + orig.clone() +} + +use lightning_invoice::RawInvoice as nativeRawInvoiceImport; +type nativeRawInvoice = nativeRawInvoiceImport; + +/// Represents an syntactically correct Invoice for a payment on the lightning network, +/// but without the signature information. +/// De- and encoding should not lead to information loss but may lead to different hashes. +/// +/// For methods without docs see the corresponding methods in `Invoice`. +#[must_use] +#[repr(C)] +pub struct RawInvoice { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeRawInvoice, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for RawInvoice { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +/// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl RawInvoice { + pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +/// data part +#[no_mangle] +pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.data; + crate::lightning_invoice::RawDataPart { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false } +} +/// data part +#[no_mangle] +pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) { + unsafe { &mut *this_ptr.inner }.data = *unsafe { Box::from_raw(val.take_inner()) }; +} +impl Clone for RawInvoice { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else { + Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the RawInvoice +pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice { + orig.clone() +} + +use lightning_invoice::RawDataPart as nativeRawDataPartImport; +type nativeRawDataPart = nativeRawDataPartImport; + +/// Data of the `RawInvoice` that is encoded in the data part +#[must_use] +#[repr(C)] +pub struct RawDataPart { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeRawDataPart, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for RawDataPart { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +/// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl RawDataPart { + pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +/// generation time of the invoice +#[no_mangle] +pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.timestamp; + crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false } +} +/// generation time of the invoice +#[no_mangle] +pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) { + unsafe { &mut *this_ptr.inner }.timestamp = *unsafe { Box::from_raw(val.take_inner()) }; +} +/// tagged fields of the payment request +#[no_mangle] +pub extern "C" fn RawDataPart_set_tagged_fields(this_ptr: &mut RawDataPart, mut val: crate::c_types::derived::CVec_RawTaggedFieldZ) { + let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); }; + unsafe { &mut *this_ptr.inner }.tagged_fields = local_val; +} +/// Constructs a new RawDataPart given each field +#[must_use] +#[no_mangle] +pub extern "C" fn RawDataPart_new(mut timestamp_arg: crate::lightning_invoice::PositiveTimestamp, mut tagged_fields_arg: crate::c_types::derived::CVec_RawTaggedFieldZ) -> RawDataPart { + let mut local_tagged_fields_arg = Vec::new(); for mut item in tagged_fields_arg.into_rust().drain(..) { local_tagged_fields_arg.push( { item.into_native() }); }; + RawDataPart { inner: Box::into_raw(Box::new(nativeRawDataPart { + timestamp: *unsafe { Box::from_raw(timestamp_arg.take_inner()) }, + tagged_fields: local_tagged_fields_arg, + })), is_owned: true } +} +impl Clone for RawDataPart { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeRawDataPart>::is_null(self.inner) { std::ptr::null_mut() } else { + Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the RawDataPart +pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart { + orig.clone() +} + +use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport; +type nativePositiveTimestamp = nativePositiveTimestampImport; + +/// A timestamp that refers to a date after 1 January 1970 which means its representation as UNIX +/// timestamp is positive. +/// +/// # Invariants +/// The UNIX timestamp representing the stored time has to be positive and small enough so that +/// a `EpiryTime` can be added to it without an overflow. +#[must_use] +#[repr(C)] +pub struct PositiveTimestamp { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativePositiveTimestamp, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for PositiveTimestamp { + fn drop(&mut self) { + if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +/// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl PositiveTimestamp { + pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +impl Clone for PositiveTimestamp { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { std::ptr::null_mut() } else { + Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the PositiveTimestamp +pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp { + orig.clone() +} +/// SI prefixes for the human readable part +#[must_use] +#[derive(Clone)] +#[repr(C)] +pub enum SiPrefix { + /// 10^-3 + Milli, + /// 10^-6 + Micro, + /// 10^-9 + Nano, + /// 10^-12 + Pico, +} +use lightning_invoice::SiPrefix as nativeSiPrefix; +impl SiPrefix { + #[allow(unused)] + pub(crate) fn to_native(&self) -> nativeSiPrefix { + match self { + SiPrefix::Milli => nativeSiPrefix::Milli, + SiPrefix::Micro => nativeSiPrefix::Micro, + SiPrefix::Nano => nativeSiPrefix::Nano, + SiPrefix::Pico => nativeSiPrefix::Pico, + } + } + #[allow(unused)] + pub(crate) fn into_native(self) -> nativeSiPrefix { + match self { + SiPrefix::Milli => nativeSiPrefix::Milli, + SiPrefix::Micro => nativeSiPrefix::Micro, + SiPrefix::Nano => nativeSiPrefix::Nano, + SiPrefix::Pico => nativeSiPrefix::Pico, + } + } + #[allow(unused)] + pub(crate) fn from_native(native: &nativeSiPrefix) -> Self { + match native { + nativeSiPrefix::Milli => SiPrefix::Milli, + nativeSiPrefix::Micro => SiPrefix::Micro, + nativeSiPrefix::Nano => SiPrefix::Nano, + nativeSiPrefix::Pico => SiPrefix::Pico, + } + } + #[allow(unused)] + pub(crate) fn native_into(native: nativeSiPrefix) -> Self { + match native { + nativeSiPrefix::Milli => SiPrefix::Milli, + nativeSiPrefix::Micro => SiPrefix::Micro, + nativeSiPrefix::Nano => SiPrefix::Nano, + nativeSiPrefix::Pico => SiPrefix::Pico, + } + } +} +/// Creates a copy of the SiPrefix +#[no_mangle] +pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix { + orig.clone() +} +/// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix. +/// This is effectively 10^12 * the prefix multiplier +#[must_use] +#[no_mangle] +pub extern "C" fn SiPrefix_multiplier(this_arg: &SiPrefix) -> u64 { + let mut ret = this_arg.to_native().multiplier(); + ret +} + +/// Enum representing the crypto currencies (or networks) supported by this library +#[must_use] +#[derive(Clone)] +#[repr(C)] +pub enum Currency { + /// Bitcoin mainnet + Bitcoin, + /// Bitcoin testnet + BitcoinTestnet, + /// Bitcoin regtest + Regtest, + /// Bitcoin simnet/signet + Simnet, +} +use lightning_invoice::Currency as nativeCurrency; +impl Currency { + #[allow(unused)] + pub(crate) fn to_native(&self) -> nativeCurrency { + match self { + Currency::Bitcoin => nativeCurrency::Bitcoin, + Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet, + Currency::Regtest => nativeCurrency::Regtest, + Currency::Simnet => nativeCurrency::Simnet, + } + } + #[allow(unused)] + pub(crate) fn into_native(self) -> nativeCurrency { + match self { + Currency::Bitcoin => nativeCurrency::Bitcoin, + Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet, + Currency::Regtest => nativeCurrency::Regtest, + Currency::Simnet => nativeCurrency::Simnet, + } + } + #[allow(unused)] + pub(crate) fn from_native(native: &nativeCurrency) -> Self { + match native { + nativeCurrency::Bitcoin => Currency::Bitcoin, + nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet, + nativeCurrency::Regtest => Currency::Regtest, + nativeCurrency::Simnet => Currency::Simnet, + } + } + #[allow(unused)] + pub(crate) fn native_into(native: nativeCurrency) -> Self { + match native { + nativeCurrency::Bitcoin => Currency::Bitcoin, + nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet, + nativeCurrency::Regtest => Currency::Regtest, + nativeCurrency::Simnet => Currency::Simnet, + } + } +} +/// Creates a copy of the Currency +#[no_mangle] +pub extern "C" fn Currency_clone(orig: &Currency) -> Currency { + orig.clone() +} +/// Tagged field which may have an unknown tag +#[must_use] +#[derive(Clone)] +#[repr(C)] +pub enum RawTaggedField { + /// Parsed tagged field with known tag + KnownSemantics(crate::lightning_invoice::TaggedField), + /// tagged field which was not parsed due to an unknown tag or undefined field semantics + UnknownSemantics(crate::c_types::derived::CVec_u5Z), +} +use lightning_invoice::RawTaggedField as nativeRawTaggedField; +impl RawTaggedField { + #[allow(unused)] + pub(crate) fn to_native(&self) -> nativeRawTaggedField { + match self { + RawTaggedField::KnownSemantics (ref a, ) => { + let mut a_nonref = (*a).clone(); + nativeRawTaggedField::KnownSemantics ( + a_nonref.into_native(), + ) + }, + RawTaggedField::UnknownSemantics (ref a, ) => { + let mut a_nonref = (*a).clone(); + let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { item.into() }); }; + nativeRawTaggedField::UnknownSemantics ( + local_a_nonref, + ) + }, + } + } + #[allow(unused)] + pub(crate) fn into_native(self) -> nativeRawTaggedField { + match self { + RawTaggedField::KnownSemantics (mut a, ) => { + nativeRawTaggedField::KnownSemantics ( + a.into_native(), + ) + }, + RawTaggedField::UnknownSemantics (mut a, ) => { + let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { item.into() }); }; + nativeRawTaggedField::UnknownSemantics ( + local_a, + ) + }, + } + } + #[allow(unused)] + pub(crate) fn from_native(native: &nativeRawTaggedField) -> Self { + match native { + nativeRawTaggedField::KnownSemantics (ref a, ) => { + let mut a_nonref = (*a).clone(); + RawTaggedField::KnownSemantics ( + crate::lightning_invoice::TaggedField::native_into(a_nonref), + ) + }, + nativeRawTaggedField::UnknownSemantics (ref a, ) => { + let mut a_nonref = (*a).clone(); + let mut local_a_nonref = Vec::new(); for mut item in a_nonref.drain(..) { local_a_nonref.push( { item.into() }); }; + RawTaggedField::UnknownSemantics ( + local_a_nonref.into(), + ) + }, + } + } + #[allow(unused)] + pub(crate) fn native_into(native: nativeRawTaggedField) -> Self { + match native { + nativeRawTaggedField::KnownSemantics (mut a, ) => { + RawTaggedField::KnownSemantics ( + crate::lightning_invoice::TaggedField::native_into(a), + ) + }, + nativeRawTaggedField::UnknownSemantics (mut a, ) => { + let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { item.into() }); }; + RawTaggedField::UnknownSemantics ( + local_a.into(), + ) + }, + } + } +} +/// Frees any resources used by the RawTaggedField +#[no_mangle] +pub extern "C" fn RawTaggedField_free(this_ptr: RawTaggedField) { } +/// Creates a copy of the RawTaggedField +#[no_mangle] +pub extern "C" fn RawTaggedField_clone(orig: &RawTaggedField) -> RawTaggedField { + orig.clone() +} +/// Tagged field with known tag +/// +/// For descriptions of the enum values please refer to the enclosed type's docs. +#[must_use] +#[derive(Clone)] +#[repr(C)] +pub enum TaggedField { + PaymentHash(crate::lightning_invoice::Sha256), + Description(crate::lightning_invoice::Description), + PayeePubKey(crate::lightning_invoice::PayeePubKey), + DescriptionHash(crate::lightning_invoice::Sha256), + ExpiryTime(crate::lightning_invoice::ExpiryTime), + MinFinalCltvExpiry(crate::lightning_invoice::MinFinalCltvExpiry), + Fallback(crate::lightning_invoice::Fallback), + Route(crate::lightning_invoice::RouteHint), + PaymentSecret(crate::lightning_invoice::PaymentSecret), + Features(crate::lightning::ln::features::InvoiceFeatures), +} +use lightning_invoice::TaggedField as nativeTaggedField; +impl TaggedField { + #[allow(unused)] + pub(crate) fn to_native(&self) -> nativeTaggedField { + match self { + TaggedField::PaymentHash (ref a, ) => { + let mut a_nonref = (*a).clone(); + nativeTaggedField::PaymentHash ( + *unsafe { Box::from_raw(a_nonref.take_inner()) }, + ) + }, + TaggedField::Description (ref a, ) => { + let mut a_nonref = (*a).clone(); + nativeTaggedField::Description ( + *unsafe { Box::from_raw(a_nonref.take_inner()) }, + ) + }, + TaggedField::PayeePubKey (ref a, ) => { + let mut a_nonref = (*a).clone(); + nativeTaggedField::PayeePubKey ( + *unsafe { Box::from_raw(a_nonref.take_inner()) }, + ) + }, + TaggedField::DescriptionHash (ref a, ) => { + let mut a_nonref = (*a).clone(); + nativeTaggedField::DescriptionHash ( + *unsafe { Box::from_raw(a_nonref.take_inner()) }, + ) + }, + TaggedField::ExpiryTime (ref a, ) => { + let mut a_nonref = (*a).clone(); + nativeTaggedField::ExpiryTime ( + *unsafe { Box::from_raw(a_nonref.take_inner()) }, + ) + }, + TaggedField::MinFinalCltvExpiry (ref a, ) => { + let mut a_nonref = (*a).clone(); + nativeTaggedField::MinFinalCltvExpiry ( + *unsafe { Box::from_raw(a_nonref.take_inner()) }, + ) + }, + TaggedField::Fallback (ref a, ) => { + let mut a_nonref = (*a).clone(); + nativeTaggedField::Fallback ( + a_nonref.into_native(), + ) + }, + TaggedField::Route (ref a, ) => { + let mut a_nonref = (*a).clone(); + nativeTaggedField::Route ( + *unsafe { Box::from_raw(a_nonref.take_inner()) }, + ) + }, + TaggedField::PaymentSecret (ref a, ) => { + let mut a_nonref = (*a).clone(); + nativeTaggedField::PaymentSecret ( + *unsafe { Box::from_raw(a_nonref.take_inner()) }, + ) + }, + TaggedField::Features (ref a, ) => { + let mut a_nonref = (*a).clone(); + nativeTaggedField::Features ( + *unsafe { Box::from_raw(a_nonref.take_inner()) }, + ) + }, + } + } + #[allow(unused)] + pub(crate) fn into_native(self) -> nativeTaggedField { + match self { + TaggedField::PaymentHash (mut a, ) => { + nativeTaggedField::PaymentHash ( + *unsafe { Box::from_raw(a.take_inner()) }, + ) + }, + TaggedField::Description (mut a, ) => { + nativeTaggedField::Description ( + *unsafe { Box::from_raw(a.take_inner()) }, + ) + }, + TaggedField::PayeePubKey (mut a, ) => { + nativeTaggedField::PayeePubKey ( + *unsafe { Box::from_raw(a.take_inner()) }, + ) + }, + TaggedField::DescriptionHash (mut a, ) => { + nativeTaggedField::DescriptionHash ( + *unsafe { Box::from_raw(a.take_inner()) }, + ) + }, + TaggedField::ExpiryTime (mut a, ) => { + nativeTaggedField::ExpiryTime ( + *unsafe { Box::from_raw(a.take_inner()) }, + ) + }, + TaggedField::MinFinalCltvExpiry (mut a, ) => { + nativeTaggedField::MinFinalCltvExpiry ( + *unsafe { Box::from_raw(a.take_inner()) }, + ) + }, + TaggedField::Fallback (mut a, ) => { + nativeTaggedField::Fallback ( + a.into_native(), + ) + }, + TaggedField::Route (mut a, ) => { + nativeTaggedField::Route ( + *unsafe { Box::from_raw(a.take_inner()) }, + ) + }, + TaggedField::PaymentSecret (mut a, ) => { + nativeTaggedField::PaymentSecret ( + *unsafe { Box::from_raw(a.take_inner()) }, + ) + }, + TaggedField::Features (mut a, ) => { + nativeTaggedField::Features ( + *unsafe { Box::from_raw(a.take_inner()) }, + ) + }, + } + } + #[allow(unused)] + pub(crate) fn from_native(native: &nativeTaggedField) -> Self { + match native { + nativeTaggedField::PaymentHash (ref a, ) => { + let mut a_nonref = (*a).clone(); + TaggedField::PaymentHash ( + crate::lightning_invoice::Sha256 { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true }, + ) + }, + nativeTaggedField::Description (ref a, ) => { + let mut a_nonref = (*a).clone(); + TaggedField::Description ( + crate::lightning_invoice::Description { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true }, + ) + }, + nativeTaggedField::PayeePubKey (ref a, ) => { + let mut a_nonref = (*a).clone(); + TaggedField::PayeePubKey ( + crate::lightning_invoice::PayeePubKey { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true }, + ) + }, + nativeTaggedField::DescriptionHash (ref a, ) => { + let mut a_nonref = (*a).clone(); + TaggedField::DescriptionHash ( + crate::lightning_invoice::Sha256 { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true }, + ) + }, + nativeTaggedField::ExpiryTime (ref a, ) => { + let mut a_nonref = (*a).clone(); + TaggedField::ExpiryTime ( + crate::lightning_invoice::ExpiryTime { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true }, + ) + }, + nativeTaggedField::MinFinalCltvExpiry (ref a, ) => { + let mut a_nonref = (*a).clone(); + TaggedField::MinFinalCltvExpiry ( + crate::lightning_invoice::MinFinalCltvExpiry { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true }, + ) + }, + nativeTaggedField::Fallback (ref a, ) => { + let mut a_nonref = (*a).clone(); + TaggedField::Fallback ( + crate::lightning_invoice::Fallback::native_into(a_nonref), + ) + }, + nativeTaggedField::Route (ref a, ) => { + let mut a_nonref = (*a).clone(); + TaggedField::Route ( + crate::lightning_invoice::RouteHint { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true }, + ) + }, + nativeTaggedField::PaymentSecret (ref a, ) => { + let mut a_nonref = (*a).clone(); + TaggedField::PaymentSecret ( + crate::lightning_invoice::PaymentSecret { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true }, + ) + }, + nativeTaggedField::Features (ref a, ) => { + let mut a_nonref = (*a).clone(); + TaggedField::Features ( + crate::lightning::ln::features::InvoiceFeatures { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true }, + ) + }, + } + } + #[allow(unused)] + pub(crate) fn native_into(native: nativeTaggedField) -> Self { + match native { + nativeTaggedField::PaymentHash (mut a, ) => { + TaggedField::PaymentHash ( + crate::lightning_invoice::Sha256 { inner: Box::into_raw(Box::new(a)), is_owned: true }, + ) + }, + nativeTaggedField::Description (mut a, ) => { + TaggedField::Description ( + crate::lightning_invoice::Description { inner: Box::into_raw(Box::new(a)), is_owned: true }, + ) + }, + nativeTaggedField::PayeePubKey (mut a, ) => { + TaggedField::PayeePubKey ( + crate::lightning_invoice::PayeePubKey { inner: Box::into_raw(Box::new(a)), is_owned: true }, + ) + }, + nativeTaggedField::DescriptionHash (mut a, ) => { + TaggedField::DescriptionHash ( + crate::lightning_invoice::Sha256 { inner: Box::into_raw(Box::new(a)), is_owned: true }, + ) + }, + nativeTaggedField::ExpiryTime (mut a, ) => { + TaggedField::ExpiryTime ( + crate::lightning_invoice::ExpiryTime { inner: Box::into_raw(Box::new(a)), is_owned: true }, + ) + }, + nativeTaggedField::MinFinalCltvExpiry (mut a, ) => { + TaggedField::MinFinalCltvExpiry ( + crate::lightning_invoice::MinFinalCltvExpiry { inner: Box::into_raw(Box::new(a)), is_owned: true }, + ) + }, + nativeTaggedField::Fallback (mut a, ) => { + TaggedField::Fallback ( + crate::lightning_invoice::Fallback::native_into(a), + ) + }, + nativeTaggedField::Route (mut a, ) => { + TaggedField::Route ( + crate::lightning_invoice::RouteHint { inner: Box::into_raw(Box::new(a)), is_owned: true }, + ) + }, + nativeTaggedField::PaymentSecret (mut a, ) => { + TaggedField::PaymentSecret ( + crate::lightning_invoice::PaymentSecret { inner: Box::into_raw(Box::new(a)), is_owned: true }, + ) + }, + nativeTaggedField::Features (mut a, ) => { + TaggedField::Features ( + crate::lightning::ln::features::InvoiceFeatures { inner: Box::into_raw(Box::new(a)), is_owned: true }, + ) + }, + } + } +} +/// Frees any resources used by the TaggedField +#[no_mangle] +pub extern "C" fn TaggedField_free(this_ptr: TaggedField) { } +/// Creates a copy of the TaggedField +#[no_mangle] +pub extern "C" fn TaggedField_clone(orig: &TaggedField) -> TaggedField { + orig.clone() +} + +use lightning_invoice::Sha256 as nativeSha256Import; +type nativeSha256 = nativeSha256Import; + +/// SHA-256 hash +#[must_use] +#[repr(C)] +pub struct Sha256 { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeSha256, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for Sha256 { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +/// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn Sha256_free(this_obj: Sha256) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn Sha256_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl Sha256 { + pub(crate) fn take_inner(mut self) -> *mut nativeSha256 { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +impl Clone for Sha256 { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeSha256>::is_null(self.inner) { std::ptr::null_mut() } else { + Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the Sha256 +pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 { + orig.clone() +} + +use lightning_invoice::Description as nativeDescriptionImport; +type nativeDescription = nativeDescriptionImport; + +/// Description string +/// +/// # Invariants +/// The description can be at most 639 __bytes__ long +#[must_use] +#[repr(C)] +pub struct Description { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeDescription, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for Description { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +/// Frees any resources used by the Description, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn Description_free(this_obj: Description) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn Description_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl Description { + pub(crate) fn take_inner(mut self) -> *mut nativeDescription { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +impl Clone for Description { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeDescription>::is_null(self.inner) { std::ptr::null_mut() } else { + Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the Description +pub extern "C" fn Description_clone(orig: &Description) -> Description { + orig.clone() +} + +use lightning_invoice::PayeePubKey as nativePayeePubKeyImport; +type nativePayeePubKey = nativePayeePubKeyImport; + +/// Payee public key +#[must_use] +#[repr(C)] +pub struct PayeePubKey { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativePayeePubKey, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for PayeePubKey { + fn drop(&mut self) { + if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +/// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl PayeePubKey { + pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +impl Clone for PayeePubKey { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativePayeePubKey>::is_null(self.inner) { std::ptr::null_mut() } else { + Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the PayeePubKey +pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey { + orig.clone() +} + +use lightning_invoice::PaymentSecret as nativePaymentSecretImport; +type nativePaymentSecret = nativePaymentSecretImport; + +/// 256-bit payment secret +#[must_use] +#[repr(C)] +pub struct PaymentSecret { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativePaymentSecret, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for PaymentSecret { + fn drop(&mut self) { + if self.is_owned && !<*mut nativePaymentSecret>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +/// Frees any resources used by the PaymentSecret, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn PaymentSecret_free(this_obj: PaymentSecret) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn PaymentSecret_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativePaymentSecret); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl PaymentSecret { + pub(crate) fn take_inner(mut self) -> *mut nativePaymentSecret { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +impl Clone for PaymentSecret { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativePaymentSecret>::is_null(self.inner) { std::ptr::null_mut() } else { + Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn PaymentSecret_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentSecret)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the PaymentSecret +pub extern "C" fn PaymentSecret_clone(orig: &PaymentSecret) -> PaymentSecret { + orig.clone() +} + +use lightning_invoice::ExpiryTime as nativeExpiryTimeImport; +type nativeExpiryTime = nativeExpiryTimeImport; + +/// Positive duration that defines when (relatively to the timestamp) in the future the invoice +/// expires +/// +/// # Invariants +/// The number of seconds this expiry time represents has to be in the range +/// `0...(SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME)` to avoid overflows when adding it to a +/// timestamp +#[must_use] +#[repr(C)] +pub struct ExpiryTime { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeExpiryTime, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for ExpiryTime { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +/// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl ExpiryTime { + pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +impl Clone for ExpiryTime { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeExpiryTime>::is_null(self.inner) { std::ptr::null_mut() } else { + Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the ExpiryTime +pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime { + orig.clone() +} + +use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport; +type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport; + +/// `min_final_cltv_expiry` to use for the last HTLC in the route +#[must_use] +#[repr(C)] +pub struct MinFinalCltvExpiry { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeMinFinalCltvExpiry, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for MinFinalCltvExpiry { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +/// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl MinFinalCltvExpiry { + pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +impl Clone for MinFinalCltvExpiry { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { std::ptr::null_mut() } else { + Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the MinFinalCltvExpiry +pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry { + orig.clone() +} +/// Fallback address in case no LN payment is possible +#[must_use] +#[derive(Clone)] +#[repr(C)] +pub enum Fallback { + SegWitProgram { + version: crate::c_types::u5, + program: crate::c_types::derived::CVec_u8Z, + }, + PubKeyHash(crate::c_types::TwentyBytes), + ScriptHash(crate::c_types::TwentyBytes), +} +use lightning_invoice::Fallback as nativeFallback; +impl Fallback { + #[allow(unused)] + pub(crate) fn to_native(&self) -> nativeFallback { + match self { + Fallback::SegWitProgram {ref version, ref program, } => { + let mut version_nonref = (*version).clone(); + let mut program_nonref = (*program).clone(); + let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); }; + nativeFallback::SegWitProgram { + version: version_nonref.into(), + program: local_program_nonref, + } + }, + Fallback::PubKeyHash (ref a, ) => { + let mut a_nonref = (*a).clone(); + nativeFallback::PubKeyHash ( + a_nonref.data, + ) + }, + Fallback::ScriptHash (ref a, ) => { + let mut a_nonref = (*a).clone(); + nativeFallback::ScriptHash ( + a_nonref.data, + ) + }, + } + } + #[allow(unused)] + pub(crate) fn into_native(self) -> nativeFallback { + match self { + Fallback::SegWitProgram {mut version, mut program, } => { + let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); }; + nativeFallback::SegWitProgram { + version: version.into(), + program: local_program, + } + }, + Fallback::PubKeyHash (mut a, ) => { + nativeFallback::PubKeyHash ( + a.data, + ) + }, + Fallback::ScriptHash (mut a, ) => { + nativeFallback::ScriptHash ( + a.data, + ) + }, + } + } + #[allow(unused)] + pub(crate) fn from_native(native: &nativeFallback) -> Self { + match native { + nativeFallback::SegWitProgram {ref version, ref program, } => { + let mut version_nonref = (*version).clone(); + let mut program_nonref = (*program).clone(); + let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); }; + Fallback::SegWitProgram { + version: version_nonref.into(), + program: local_program_nonref.into(), + } + }, + nativeFallback::PubKeyHash (ref a, ) => { + let mut a_nonref = (*a).clone(); + Fallback::PubKeyHash ( + crate::c_types::TwentyBytes { data: a_nonref }, + ) + }, + nativeFallback::ScriptHash (ref a, ) => { + let mut a_nonref = (*a).clone(); + Fallback::ScriptHash ( + crate::c_types::TwentyBytes { data: a_nonref }, + ) + }, + } + } + #[allow(unused)] + pub(crate) fn native_into(native: nativeFallback) -> Self { + match native { + nativeFallback::SegWitProgram {mut version, mut program, } => { + let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); }; + Fallback::SegWitProgram { + version: version.into(), + program: local_program.into(), + } + }, + nativeFallback::PubKeyHash (mut a, ) => { + Fallback::PubKeyHash ( + crate::c_types::TwentyBytes { data: a }, + ) + }, + nativeFallback::ScriptHash (mut a, ) => { + Fallback::ScriptHash ( + crate::c_types::TwentyBytes { data: a }, + ) + }, + } + } +} +/// Frees any resources used by the Fallback +#[no_mangle] +pub extern "C" fn Fallback_free(this_ptr: Fallback) { } +/// Creates a copy of the Fallback +#[no_mangle] +pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback { + orig.clone() +} + +use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport; +type nativeInvoiceSignature = nativeInvoiceSignatureImport; + +/// Recoverable signature +#[must_use] +#[repr(C)] +pub struct InvoiceSignature { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeInvoiceSignature, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for InvoiceSignature { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +/// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl InvoiceSignature { + pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +impl Clone for InvoiceSignature { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { std::ptr::null_mut() } else { + Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the InvoiceSignature +pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature { + orig.clone() +} + +use lightning_invoice::RouteHint as nativeRouteHintImport; +type nativeRouteHint = nativeRouteHintImport; + +/// Private routing information +/// +/// # Invariants +/// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops) +/// +#[must_use] +#[repr(C)] +pub struct RouteHint { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeRouteHint, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for RouteHint { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(self.inner) }; + } + } +} +/// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn RouteHint_free(this_obj: RouteHint) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHint); } +} +#[allow(unused)] +/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy +impl RouteHint { + pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint { + assert!(self.is_owned); + let ret = self.inner; + self.inner = std::ptr::null_mut(); + ret + } +} +impl Clone for RouteHint { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeRouteHint>::is_null(self.inner) { std::ptr::null_mut() } else { + Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the RouteHint +pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint { + orig.clone() +} +/// Disassembles the `SignedRawInvoice` into its three parts: +/// 1. raw invoice +/// 2. hash of the raw invoice +/// 3. signature +#[must_use] +#[no_mangle] +pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ { + let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts(); + let (mut orig_ret_0, mut orig_ret_1, mut orig_ret_2) = ret; let mut local_ret = (crate::lightning_invoice::RawInvoice { inner: Box::into_raw(Box::new(orig_ret_0)), is_owned: true }, crate::c_types::ThirtyTwoBytes { data: orig_ret_1 }, crate::lightning_invoice::InvoiceSignature { inner: Box::into_raw(Box::new(orig_ret_2)), is_owned: true }).into(); + local_ret +} + +/// The `RawInvoice` which was signed. +#[must_use] +#[no_mangle] +pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice { + let mut ret = unsafe { &*this_arg.inner }.raw_invoice(); + crate::lightning_invoice::RawInvoice { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } +} + +/// The hash of the `RawInvoice` that was signed. +#[must_use] +#[no_mangle] +pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [u8; 32] { + let mut ret = unsafe { &*this_arg.inner }.hash(); + ret +} + +/// InvoiceSignature for the invoice. +#[must_use] +#[no_mangle] +pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature { + let mut ret = unsafe { &*this_arg.inner }.signature(); + crate::lightning_invoice::InvoiceSignature { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false } +} + +/// Recovers the public key used for signing the invoice from the recoverable signature. +#[must_use] +#[no_mangle] +pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ { + let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key(); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PayeePubKey { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() }; + local_ret +} + +/// Checks if the signature is valid for the included payee public key or if none exists if it's +/// valid for the recovered signature (which should always be true?). +#[must_use] +#[no_mangle] +pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &SignedRawInvoice) -> bool { + let mut ret = unsafe { &*this_arg.inner }.check_signature(); + ret +} + +/// Calculate the hash of the encoded `RawInvoice` +#[must_use] +#[no_mangle] +pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes { + let mut ret = unsafe { &*this_arg.inner }.hash(); + crate::c_types::ThirtyTwoBytes { data: ret } +} + +#[must_use] +#[no_mangle] +pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 { + let mut ret = unsafe { &*this_arg.inner }.payment_hash(); + let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; + local_ret +} + +#[must_use] +#[no_mangle] +pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightning_invoice::Description { + let mut ret = unsafe { &*this_arg.inner }.description(); + let mut local_ret = crate::lightning_invoice::Description { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; + local_ret +} + +#[must_use] +#[no_mangle] +pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::lightning_invoice::PayeePubKey { + let mut ret = unsafe { &*this_arg.inner }.payee_pub_key(); + let mut local_ret = crate::lightning_invoice::PayeePubKey { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; + local_ret +} + +#[must_use] +#[no_mangle] +pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 { + let mut ret = unsafe { &*this_arg.inner }.description_hash(); + let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; + local_ret +} + +#[must_use] +#[no_mangle] +pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightning_invoice::ExpiryTime { + let mut ret = unsafe { &*this_arg.inner }.expiry_time(); + let mut local_ret = crate::lightning_invoice::ExpiryTime { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; + local_ret +} + +#[must_use] +#[no_mangle] +pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry { + let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry(); + let mut local_ret = crate::lightning_invoice::MinFinalCltvExpiry { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; + local_ret +} + +#[must_use] +#[no_mangle] +pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::lightning_invoice::PaymentSecret { + let mut ret = unsafe { &*this_arg.inner }.payment_secret(); + let mut local_ret = crate::lightning_invoice::PaymentSecret { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; + local_ret +} + +#[must_use] +#[no_mangle] +pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures { + let mut ret = unsafe { &*this_arg.inner }.features(); + let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; + local_ret +} + +#[must_use] +#[no_mangle] +pub extern "C" fn RawInvoice_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_RouteHintZ { + let mut ret = unsafe { &*this_arg.inner }.routes(); + let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::RouteHint { inner: unsafe { ( (&(**item) as *const _) as *mut _) }, is_owned: false } }); }; + local_ret.into() +} + +#[must_use] +#[no_mangle] +pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z { + let mut ret = unsafe { &*this_arg.inner }.amount_pico_btc(); + let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { { crate::c_types::derived::COption_u64Z::Some(ret.unwrap()) } }; + local_ret +} + +#[must_use] +#[no_mangle] +pub extern "C" fn RawInvoice_currency(this_arg: &RawInvoice) -> crate::lightning_invoice::Currency { + let mut ret = unsafe { &*this_arg.inner }.currency(); + crate::lightning_invoice::Currency::native_into(ret) +} + +/// Create a new `PositiveTimestamp` from a unix timestamp in the Range +/// `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a +/// `CreationError::TimestampOutOfBounds`. +#[must_use] +#[no_mangle] +pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ { + let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() }; + local_ret +} + +/// Create a new `PositiveTimestamp` from a `SystemTime` with a corresponding unix timestamp in +/// the Range `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a +/// `CreationError::TimestampOutOfBounds`. +#[must_use] +#[no_mangle] +pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ { + let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time))); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() }; + local_ret +} + +/// Returns the UNIX timestamp representing the stored time +#[must_use] +#[no_mangle] +pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 { + let mut ret = unsafe { &*this_arg.inner }.as_unix_timestamp(); + ret +} + +/// Returns a reference to the internal `SystemTime` time representation +#[must_use] +#[no_mangle] +pub extern "C" fn PositiveTimestamp_as_time(this_arg: &PositiveTimestamp) -> u64 { + let mut ret = unsafe { &*this_arg.inner }.as_time(); + ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs() +} + +/// Transform the `Invoice` into it's unchecked version +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::lightning_invoice::SignedRawInvoice { + let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw(); + crate::lightning_invoice::SignedRawInvoice { inner: Box::into_raw(Box::new(ret)), is_owned: true } +} + +/// Check that the invoice is signed correctly and that key recovery works +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ { + let mut ret = unsafe { &*this_arg.inner }.check_signature(); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::SemanticError::native_into(e) }).into() }; + local_ret +} + +/// Constructs an `Invoice` from a `SignedInvoice` by checking all its invariants. +/// ``` +/// use lightning_invoice::*; +/// +/// let invoice = \"lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdp\\ +/// \tl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d7\\ +/// \t3gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ec\\ +/// \tky03ylcqca784w\"; +/// +/// let signed = invoice.parse::().unwrap(); +/// +/// assert!(Invoice::from_signed(signed).is_ok()); +/// ``` +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ { + let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) }); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::Invoice { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::SemanticError::native_into(e) }).into() }; + local_ret +} + +/// Returns the `Invoice`'s timestamp (should equal it's creation time) +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_timestamp(this_arg: &Invoice) -> u64 { + let mut ret = unsafe { &*this_arg.inner }.timestamp(); + ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs() +} + +/// Returns the hash to which we will receive the preimage on completion of the payment +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] { + let mut ret = unsafe { &*this_arg.inner }.payment_hash(); + ret.as_inner() +} + +/// Get the payee's public key if one was included in the invoice +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey { + let mut ret = unsafe { &*this_arg.inner }.payee_pub_key(); + let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } }; + local_ret +} + +/// Get the payment secret if one was included in the invoice +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> crate::lightning_invoice::PaymentSecret { + let mut ret = unsafe { &*this_arg.inner }.payment_secret(); + let mut local_ret = crate::lightning_invoice::PaymentSecret { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; + local_ret +} + +/// Get the invoice features if they were included in the invoice +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures { + let mut ret = unsafe { &*this_arg.inner }.features(); + let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false }; + local_ret +} + +/// Recover the payee's public key (only to be used if none was included in the invoice) +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey { + let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key(); + crate::c_types::PublicKey::from_rust(&ret) +} + +/// Returns the invoice's expiry time if present +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 { + let mut ret = unsafe { &*this_arg.inner }.expiry_time(); + ret.as_secs() +} + +/// Returns the invoice's `min_cltv_expiry` time if present +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z { + let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry(); + let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { { crate::c_types::derived::COption_u64Z::Some(ret.unwrap()) } }; + local_ret +} + +/// Returns a list of all routes included in the invoice +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ { + let mut ret = unsafe { &*this_arg.inner }.routes(); + let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::RouteHint { inner: unsafe { ( (&(**item) as *const _) as *mut _) }, is_owned: false } }); }; + local_ret.into() +} + +/// Returns the currency for which the invoice was issued +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoice::Currency { + let mut ret = unsafe { &*this_arg.inner }.currency(); + crate::lightning_invoice::Currency::native_into(ret) +} + +/// Returns the amount if specified in the invoice as pico . +#[must_use] +#[no_mangle] +pub extern "C" fn Invoice_amount_pico_btc(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z { + let mut ret = unsafe { &*this_arg.inner }.amount_pico_btc(); + let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { { crate::c_types::derived::COption_u64Z::Some(ret.unwrap()) } }; + local_ret +} + +/// Numeric representation of the field's tag +#[must_use] +#[no_mangle] +pub extern "C" fn TaggedField_tag(this_arg: &TaggedField) -> crate::c_types::u5 { + let mut ret = this_arg.to_native().tag(); + ret.into() +} + +/// Creates a new `Description` if `description` is at most 1023 __bytes__ long, +/// returns `CreationError::DescriptionTooLong` otherwise +/// +/// Please note that single characters may use more than one byte due to UTF8 encoding. +#[must_use] +#[no_mangle] +pub extern "C" fn Description_new(mut description: crate::c_types::derived::CVec_u8Z) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ { + let mut ret = lightning_invoice::Description::new(String::from_utf8(description.into_rust()).unwrap()); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::Description { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() }; + local_ret +} + +/// Returns the underlying description `String` +#[must_use] +#[no_mangle] +pub extern "C" fn Description_into_inner(mut this_arg: Description) -> crate::c_types::derived::CVec_u8Z { + let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner(); + ret.into_bytes().into() +} + +/// Construct an `ExpiryTime` from seconds. If there exists a `PositiveTimestamp` which would +/// overflow on adding the `EpiryTime` to it then this function will return a +/// `CreationError::ExpiryTimeOutOfBounds`. +#[must_use] +#[no_mangle] +pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ { + let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::ExpiryTime { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() }; + local_ret +} + +/// Construct an `ExpiryTime` from a `Duration`. If there exists a `PositiveTimestamp` which +/// would overflow on adding the `EpiryTime` to it then this function will return a +/// `CreationError::ExpiryTimeOutOfBounds`. +#[must_use] +#[no_mangle] +pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ { + let mut ret = lightning_invoice::ExpiryTime::from_duration(std::time::Duration::from_secs(duration)); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::ExpiryTime { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() }; + local_ret +} + +/// Returns the expiry time in seconds +#[must_use] +#[no_mangle] +pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 { + let mut ret = unsafe { &*this_arg.inner }.as_seconds(); + ret +} + +/// Returns a reference to the underlying `Duration` (=expiry time) +#[must_use] +#[no_mangle] +pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 { + let mut ret = unsafe { &*this_arg.inner }.as_duration(); + ret.as_secs() +} + +/// Create a new (partial) route from a list of hops +#[must_use] +#[no_mangle] +pub extern "C" fn RouteHint_new(mut hops: crate::c_types::derived::CVec_RouteHintHopZ) -> crate::c_types::derived::CResult_RouteHintCreationErrorZ { + let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; + let mut ret = lightning_invoice::RouteHint::new(local_hops); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::RouteHint { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() }; + local_ret +} + +/// Returrn the underlying vector of hops +#[must_use] +#[no_mangle] +pub extern "C" fn RouteHint_into_inner(mut this_arg: RouteHint) -> crate::c_types::derived::CVec_RouteHintHopZ { + let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner(); + let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::router::RouteHintHop { inner: Box::into_raw(Box::new(item)), is_owned: true } }); }; + local_ret.into() +} + +/// Errors that may occur when constructing a new `RawInvoice` or `Invoice` +#[must_use] +#[derive(Clone)] +#[repr(C)] +pub enum CreationError { + /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new)) + DescriptionTooLong, + /// The specified route has too many hops and can't be encoded + RouteTooLong, + /// The unix timestamp of the supplied date is <0 or can't be represented as `SystemTime` + TimestampOutOfBounds, + /// The supplied expiry time could cause an overflow if added to a `PositiveTimestamp` + ExpiryTimeOutOfBounds, +} +use lightning_invoice::CreationError as nativeCreationError; +impl CreationError { + #[allow(unused)] + pub(crate) fn to_native(&self) -> nativeCreationError { + match self { + CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong, + CreationError::RouteTooLong => nativeCreationError::RouteTooLong, + CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds, + CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds, + } + } + #[allow(unused)] + pub(crate) fn into_native(self) -> nativeCreationError { + match self { + CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong, + CreationError::RouteTooLong => nativeCreationError::RouteTooLong, + CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds, + CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds, + } + } + #[allow(unused)] + pub(crate) fn from_native(native: &nativeCreationError) -> Self { + match native { + nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong, + nativeCreationError::RouteTooLong => CreationError::RouteTooLong, + nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds, + nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds, + } + } + #[allow(unused)] + pub(crate) fn native_into(native: nativeCreationError) -> Self { + match native { + nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong, + nativeCreationError::RouteTooLong => CreationError::RouteTooLong, + nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds, + nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds, + } + } +} +/// Creates a copy of the CreationError +#[no_mangle] +pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError { + orig.clone() +} +#[no_mangle] +/// Get the string representation of a CreationError object +pub extern "C" fn CreationError_to_str(o: &lightning_invoice::CreationError) -> Str { + format!("{}", o).into() +} +/// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the +/// requirements sections in BOLT #11 +#[must_use] +#[derive(Clone)] +#[repr(C)] +pub enum SemanticError { + /// The invoice is missing the mandatory payment hash + NoPaymentHash, + /// The invoice has multiple payment hashes which isn't allowed + MultiplePaymentHashes, + /// No description or description hash are part of the invoice + NoDescription, + /// The invoice contains multiple descriptions and/or description hashes which isn't allowed + MultipleDescriptions, + /// The recovery id doesn't fit the signature/pub key + InvalidRecoveryId, + /// The invoice's signature is invalid + InvalidSignature, +} +use lightning_invoice::SemanticError as nativeSemanticError; +impl SemanticError { + #[allow(unused)] + pub(crate) fn to_native(&self) -> nativeSemanticError { + match self { + SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash, + SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes, + SemanticError::NoDescription => nativeSemanticError::NoDescription, + SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions, + SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId, + SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature, + } + } + #[allow(unused)] + pub(crate) fn into_native(self) -> nativeSemanticError { + match self { + SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash, + SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes, + SemanticError::NoDescription => nativeSemanticError::NoDescription, + SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions, + SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId, + SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature, + } + } + #[allow(unused)] + pub(crate) fn from_native(native: &nativeSemanticError) -> Self { + match native { + nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash, + nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes, + nativeSemanticError::NoDescription => SemanticError::NoDescription, + nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions, + nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId, + nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature, + } + } + #[allow(unused)] + pub(crate) fn native_into(native: nativeSemanticError) -> Self { + match native { + nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash, + nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes, + nativeSemanticError::NoDescription => SemanticError::NoDescription, + nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions, + nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId, + nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature, + } + } +} +/// Creates a copy of the SemanticError +#[no_mangle] +pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError { + orig.clone() +} +#[no_mangle] +/// Get the string representation of a SemanticError object +pub extern "C" fn SemanticError_to_str(o: &lightning_invoice::SemanticError) -> Str { + format!("{}", o).into() +}