1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! This crate provides data structures to represent
10 //! [lightning BOLT11](https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md)
11 //! invoices and functions to create, encode and decode these. If you just want to use the standard
12 //! en-/decoding functionality this should get you started:
14 //! * For parsing use `str::parse::<Invoice>(&self)` (see the docs of `impl FromStr for Invoice`)
15 //! * For constructing invoices use the `InvoiceBuilder`
16 //! * For serializing invoices use the `Display`/`ToString` traits
18 use std::str::FromStr;
20 use bitcoin::hashes::Hash;
21 use crate::c_types::*;
27 use std::str::FromStr;
29 use bitcoin::hashes::Hash;
30 use crate::c_types::*;
34 use std::str::FromStr;
36 use bitcoin::hashes::Hash;
37 use crate::c_types::*;
41 /// Read a SiPrefix object from a string
42 pub extern "C" fn SiPrefix_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SiPrefixNoneZ {
43 match lightning_invoice::SiPrefix::from_str(s.into_str()) {
45 crate::c_types::CResultTempl::ok(
46 crate::lightning_invoice::SiPrefix::native_into(r)
49 Err(e) => crate::c_types::CResultTempl::err(()),
53 /// Read a Invoice object from a string
54 pub extern "C" fn Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_InvoiceNoneZ {
55 match lightning_invoice::Invoice::from_str(s.into_str()) {
57 crate::c_types::CResultTempl::ok(
58 crate::lightning_invoice::Invoice { inner: Box::into_raw(Box::new(r)), is_owned: true }
61 Err(e) => crate::c_types::CResultTempl::err(()),
65 /// Read a SignedRawInvoice object from a string
66 pub extern "C" fn SignedRawInvoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SignedRawInvoiceNoneZ {
67 match lightning_invoice::SignedRawInvoice::from_str(s.into_str()) {
69 crate::c_types::CResultTempl::ok(
70 crate::lightning_invoice::SignedRawInvoice { inner: Box::into_raw(Box::new(r)), is_owned: true }
73 Err(e) => crate::c_types::CResultTempl::err(()),
79 use std::str::FromStr;
81 use bitcoin::hashes::Hash;
82 use crate::c_types::*;
85 /// Get the string representation of a Invoice object
86 pub extern "C" fn Invoice_to_str(o: &crate::lightning_invoice::Invoice) -> Str {
87 format!("{}", unsafe { &*o.inner }).into()
90 /// Get the string representation of a SignedRawInvoice object
91 pub extern "C" fn SignedRawInvoice_to_str(o: &crate::lightning_invoice::SignedRawInvoice) -> Str {
92 format!("{}", unsafe { &*o.inner }).into()
95 /// Get the string representation of a Currency object
96 pub extern "C" fn Currency_to_str(o: &crate::lightning_invoice::Currency) -> Str {
97 format!("{}", &o.to_native()).into()
100 /// Get the string representation of a SiPrefix object
101 pub extern "C" fn SiPrefix_to_str(o: &crate::lightning_invoice::SiPrefix) -> Str {
102 format!("{}", &o.to_native()).into()
107 use std::str::FromStr;
108 use std::ffi::c_void;
109 use bitcoin::hashes::Hash;
110 use crate::c_types::*;
113 /// Default expiry time as defined by [BOLT 11].
115 /// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md
118 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
119 /// Default minimum final CLTV expiry as defined by [BOLT 11].
121 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
122 /// provided in [`MIN_FINAL_CLTV_EXPIRY`].
124 /// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md
125 /// [`MIN_FINAL_CLTV_EXPIRY`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY
128 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY;
129 /// **Call this function on startup to ensure that all assumptions about the platform are valid.**
131 /// Unfortunately we have to make assumptions about the upper bounds of the `SystemTime` type on
132 /// your platform which we can't fully verify at compile time and which isn't part of it's contract.
133 /// To our best knowledge our assumptions hold for all platforms officially supported by rust, but
134 /// since this check is fast we recommend to do it anyway.
136 /// If this function fails this is considered a bug. Please open an issue describing your
137 /// platform and stating your current system time.
140 /// If the check fails this function panics. By calling this function on startup you ensure that
141 /// this wont happen at an arbitrary later point in time.
143 pub extern "C" fn check_platform() {
144 lightning_invoice::check_platform()
148 use lightning_invoice::Invoice as nativeInvoiceImport;
149 type nativeInvoice = nativeInvoiceImport;
151 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
153 /// There are three ways to construct an `Invoice`:
154 /// 1. using `InvoiceBuilder`
155 /// 2. using `Invoice::from_signed(SignedRawInvoice)`
156 /// 3. using `str::parse::<Invoice>(&str)`
160 /// A pointer to the opaque Rust object.
162 /// Nearly everywhere, inner must be non-null, however in places where
163 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
164 pub inner: *mut nativeInvoice,
165 /// Indicates that this is the only struct which contains the same pointer.
167 /// Rust functions which take ownership of an object provided via an argument require
168 /// this to be true and invalidate the object pointed to by inner.
172 impl Drop for Invoice {
174 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
175 let _ = unsafe { Box::from_raw(self.inner) };
179 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
181 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
183 /// Used only if an object of this type is returned as a trait impl by a method
184 extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
185 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
188 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
190 pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
191 assert!(self.is_owned);
192 let ret = self.inner;
193 self.inner = std::ptr::null_mut();
197 /// Checks if two Invoices contain equal inner contents.
198 /// This ignores pointers and is_owned flags and looks at the values in fields.
199 /// Two objects with NULL inner values will be considered "equal" here.
201 pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool {
202 if a.inner == b.inner { return true; }
203 if a.inner.is_null() || b.inner.is_null() { return false; }
204 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
206 impl Clone for Invoice {
207 fn clone(&self) -> Self {
209 inner: if <*mut nativeInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
210 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
216 /// Used only if an object of this type is returned as a trait impl by a method
217 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
218 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
221 /// Creates a copy of the Invoice
222 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
226 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
227 type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
229 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
233 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
236 pub struct SignedRawInvoice {
237 /// A pointer to the opaque Rust object.
239 /// Nearly everywhere, inner must be non-null, however in places where
240 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
241 pub inner: *mut nativeSignedRawInvoice,
242 /// Indicates that this is the only struct which contains the same pointer.
244 /// Rust functions which take ownership of an object provided via an argument require
245 /// this to be true and invalidate the object pointed to by inner.
249 impl Drop for SignedRawInvoice {
251 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
252 let _ = unsafe { Box::from_raw(self.inner) };
256 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
258 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
260 /// Used only if an object of this type is returned as a trait impl by a method
261 extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
262 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
265 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
266 impl SignedRawInvoice {
267 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
268 assert!(self.is_owned);
269 let ret = self.inner;
270 self.inner = std::ptr::null_mut();
274 /// Checks if two SignedRawInvoices contain equal inner contents.
275 /// This ignores pointers and is_owned flags and looks at the values in fields.
276 /// Two objects with NULL inner values will be considered "equal" here.
278 pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice) -> bool {
279 if a.inner == b.inner { return true; }
280 if a.inner.is_null() || b.inner.is_null() { return false; }
281 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
283 impl Clone for SignedRawInvoice {
284 fn clone(&self) -> Self {
286 inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
287 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
293 /// Used only if an object of this type is returned as a trait impl by a method
294 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
295 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
298 /// Creates a copy of the SignedRawInvoice
299 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
303 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
304 type nativeRawInvoice = nativeRawInvoiceImport;
306 /// Represents an syntactically correct Invoice for a payment on the lightning network,
307 /// but without the signature information.
308 /// De- and encoding should not lead to information loss but may lead to different hashes.
310 /// For methods without docs see the corresponding methods in `Invoice`.
313 pub struct RawInvoice {
314 /// A pointer to the opaque Rust object.
316 /// Nearly everywhere, inner must be non-null, however in places where
317 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
318 pub inner: *mut nativeRawInvoice,
319 /// Indicates that this is the only struct which contains the same pointer.
321 /// Rust functions which take ownership of an object provided via an argument require
322 /// this to be true and invalidate the object pointed to by inner.
326 impl Drop for RawInvoice {
328 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
329 let _ = unsafe { Box::from_raw(self.inner) };
333 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
335 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
337 /// Used only if an object of this type is returned as a trait impl by a method
338 extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
339 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
342 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
344 pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
345 assert!(self.is_owned);
346 let ret = self.inner;
347 self.inner = std::ptr::null_mut();
353 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
354 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.data;
355 crate::lightning_invoice::RawDataPart { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
359 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
360 unsafe { &mut *this_ptr.inner }.data = *unsafe { Box::from_raw(val.take_inner()) };
362 /// Checks if two RawInvoices contain equal inner contents.
363 /// This ignores pointers and is_owned flags and looks at the values in fields.
364 /// Two objects with NULL inner values will be considered "equal" here.
366 pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool {
367 if a.inner == b.inner { return true; }
368 if a.inner.is_null() || b.inner.is_null() { return false; }
369 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
371 impl Clone for RawInvoice {
372 fn clone(&self) -> Self {
374 inner: if <*mut nativeRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
375 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
381 /// Used only if an object of this type is returned as a trait impl by a method
382 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
383 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
386 /// Creates a copy of the RawInvoice
387 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
391 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
392 type nativeRawDataPart = nativeRawDataPartImport;
394 /// Data of the `RawInvoice` that is encoded in the data part
397 pub struct RawDataPart {
398 /// A pointer to the opaque Rust object.
400 /// Nearly everywhere, inner must be non-null, however in places where
401 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
402 pub inner: *mut nativeRawDataPart,
403 /// Indicates that this is the only struct which contains the same pointer.
405 /// Rust functions which take ownership of an object provided via an argument require
406 /// this to be true and invalidate the object pointed to by inner.
410 impl Drop for RawDataPart {
412 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
413 let _ = unsafe { Box::from_raw(self.inner) };
417 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
419 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
421 /// Used only if an object of this type is returned as a trait impl by a method
422 extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
423 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
426 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
428 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
429 assert!(self.is_owned);
430 let ret = self.inner;
431 self.inner = std::ptr::null_mut();
435 /// generation time of the invoice
437 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
438 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.timestamp;
439 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
441 /// generation time of the invoice
443 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
444 unsafe { &mut *this_ptr.inner }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
446 /// Checks if two RawDataParts contain equal inner contents.
447 /// This ignores pointers and is_owned flags and looks at the values in fields.
448 /// Two objects with NULL inner values will be considered "equal" here.
450 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
451 if a.inner == b.inner { return true; }
452 if a.inner.is_null() || b.inner.is_null() { return false; }
453 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
455 impl Clone for RawDataPart {
456 fn clone(&self) -> Self {
458 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { std::ptr::null_mut() } else {
459 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
465 /// Used only if an object of this type is returned as a trait impl by a method
466 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
467 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
470 /// Creates a copy of the RawDataPart
471 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
475 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
476 type nativePositiveTimestamp = nativePositiveTimestampImport;
478 /// A timestamp that refers to a date after 1 January 1970 which means its representation as UNIX
479 /// timestamp is positive.
482 /// The UNIX timestamp representing the stored time has to be positive and small enough so that
483 /// a `EpiryTime` can be added to it without an overflow.
486 pub struct PositiveTimestamp {
487 /// A pointer to the opaque Rust object.
489 /// Nearly everywhere, inner must be non-null, however in places where
490 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
491 pub inner: *mut nativePositiveTimestamp,
492 /// Indicates that this is the only struct which contains the same pointer.
494 /// Rust functions which take ownership of an object provided via an argument require
495 /// this to be true and invalidate the object pointed to by inner.
499 impl Drop for PositiveTimestamp {
501 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
502 let _ = unsafe { Box::from_raw(self.inner) };
506 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
508 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
510 /// Used only if an object of this type is returned as a trait impl by a method
511 extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
512 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
515 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
516 impl PositiveTimestamp {
517 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
518 assert!(self.is_owned);
519 let ret = self.inner;
520 self.inner = std::ptr::null_mut();
524 /// Checks if two PositiveTimestamps contain equal inner contents.
525 /// This ignores pointers and is_owned flags and looks at the values in fields.
526 /// Two objects with NULL inner values will be considered "equal" here.
528 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
529 if a.inner == b.inner { return true; }
530 if a.inner.is_null() || b.inner.is_null() { return false; }
531 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
533 impl Clone for PositiveTimestamp {
534 fn clone(&self) -> Self {
536 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { std::ptr::null_mut() } else {
537 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
543 /// Used only if an object of this type is returned as a trait impl by a method
544 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
545 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
548 /// Creates a copy of the PositiveTimestamp
549 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
552 /// SI prefixes for the human readable part
566 use lightning_invoice::SiPrefix as nativeSiPrefix;
569 pub(crate) fn to_native(&self) -> nativeSiPrefix {
571 SiPrefix::Milli => nativeSiPrefix::Milli,
572 SiPrefix::Micro => nativeSiPrefix::Micro,
573 SiPrefix::Nano => nativeSiPrefix::Nano,
574 SiPrefix::Pico => nativeSiPrefix::Pico,
578 pub(crate) fn into_native(self) -> nativeSiPrefix {
580 SiPrefix::Milli => nativeSiPrefix::Milli,
581 SiPrefix::Micro => nativeSiPrefix::Micro,
582 SiPrefix::Nano => nativeSiPrefix::Nano,
583 SiPrefix::Pico => nativeSiPrefix::Pico,
587 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
589 nativeSiPrefix::Milli => SiPrefix::Milli,
590 nativeSiPrefix::Micro => SiPrefix::Micro,
591 nativeSiPrefix::Nano => SiPrefix::Nano,
592 nativeSiPrefix::Pico => SiPrefix::Pico,
596 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
598 nativeSiPrefix::Milli => SiPrefix::Milli,
599 nativeSiPrefix::Micro => SiPrefix::Micro,
600 nativeSiPrefix::Nano => SiPrefix::Nano,
601 nativeSiPrefix::Pico => SiPrefix::Pico,
605 /// Creates a copy of the SiPrefix
607 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
611 /// Utility method to constructs a new Milli-variant SiPrefix
612 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
615 /// Utility method to constructs a new Micro-variant SiPrefix
616 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
619 /// Utility method to constructs a new Nano-variant SiPrefix
620 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
623 /// Utility method to constructs a new Pico-variant SiPrefix
624 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
626 /// Checks if two SiPrefixs contain equal inner contents.
627 /// This ignores pointers and is_owned flags and looks at the values in fields.
629 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
630 if &a.to_native() == &b.to_native() { true } else { false }
632 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
633 /// This is effectively 10^12 * the prefix multiplier
636 pub extern "C" fn SiPrefix_multiplier(this_arg: &SiPrefix) -> u64 {
637 let mut ret = this_arg.to_native().multiplier();
641 /// Enum representing the crypto currencies (or networks) supported by this library
657 use lightning_invoice::Currency as nativeCurrency;
660 pub(crate) fn to_native(&self) -> nativeCurrency {
662 Currency::Bitcoin => nativeCurrency::Bitcoin,
663 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
664 Currency::Regtest => nativeCurrency::Regtest,
665 Currency::Simnet => nativeCurrency::Simnet,
666 Currency::Signet => nativeCurrency::Signet,
670 pub(crate) fn into_native(self) -> nativeCurrency {
672 Currency::Bitcoin => nativeCurrency::Bitcoin,
673 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
674 Currency::Regtest => nativeCurrency::Regtest,
675 Currency::Simnet => nativeCurrency::Simnet,
676 Currency::Signet => nativeCurrency::Signet,
680 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
682 nativeCurrency::Bitcoin => Currency::Bitcoin,
683 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
684 nativeCurrency::Regtest => Currency::Regtest,
685 nativeCurrency::Simnet => Currency::Simnet,
686 nativeCurrency::Signet => Currency::Signet,
690 pub(crate) fn native_into(native: nativeCurrency) -> Self {
692 nativeCurrency::Bitcoin => Currency::Bitcoin,
693 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
694 nativeCurrency::Regtest => Currency::Regtest,
695 nativeCurrency::Simnet => Currency::Simnet,
696 nativeCurrency::Signet => Currency::Signet,
700 /// Creates a copy of the Currency
702 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
706 /// Utility method to constructs a new Bitcoin-variant Currency
707 pub extern "C" fn Currency_bitcoin() -> Currency {
710 /// Utility method to constructs a new BitcoinTestnet-variant Currency
711 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
712 Currency::BitcoinTestnet}
714 /// Utility method to constructs a new Regtest-variant Currency
715 pub extern "C" fn Currency_regtest() -> Currency {
718 /// Utility method to constructs a new Simnet-variant Currency
719 pub extern "C" fn Currency_simnet() -> Currency {
722 /// Utility method to constructs a new Signet-variant Currency
723 pub extern "C" fn Currency_signet() -> Currency {
725 /// Checks if two Currencys contain equal inner contents.
726 /// This ignores pointers and is_owned flags and looks at the values in fields.
728 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
729 if &a.to_native() == &b.to_native() { true } else { false }
732 use lightning_invoice::Sha256 as nativeSha256Import;
733 type nativeSha256 = nativeSha256Import;
739 /// A pointer to the opaque Rust object.
741 /// Nearly everywhere, inner must be non-null, however in places where
742 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
743 pub inner: *mut nativeSha256,
744 /// Indicates that this is the only struct which contains the same pointer.
746 /// Rust functions which take ownership of an object provided via an argument require
747 /// this to be true and invalidate the object pointed to by inner.
751 impl Drop for Sha256 {
753 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
754 let _ = unsafe { Box::from_raw(self.inner) };
758 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
760 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
762 /// Used only if an object of this type is returned as a trait impl by a method
763 extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
764 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
767 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
769 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
770 assert!(self.is_owned);
771 let ret = self.inner;
772 self.inner = std::ptr::null_mut();
776 /// Checks if two Sha256s contain equal inner contents.
777 /// This ignores pointers and is_owned flags and looks at the values in fields.
778 /// Two objects with NULL inner values will be considered "equal" here.
780 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
781 if a.inner == b.inner { return true; }
782 if a.inner.is_null() || b.inner.is_null() { return false; }
783 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
785 impl Clone for Sha256 {
786 fn clone(&self) -> Self {
788 inner: if <*mut nativeSha256>::is_null(self.inner) { std::ptr::null_mut() } else {
789 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
795 /// Used only if an object of this type is returned as a trait impl by a method
796 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
797 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
800 /// Creates a copy of the Sha256
801 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
805 use lightning_invoice::Description as nativeDescriptionImport;
806 type nativeDescription = nativeDescriptionImport;
808 /// Description string
811 /// The description can be at most 639 __bytes__ long
814 pub struct Description {
815 /// A pointer to the opaque Rust object.
817 /// Nearly everywhere, inner must be non-null, however in places where
818 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
819 pub inner: *mut nativeDescription,
820 /// Indicates that this is the only struct which contains the same pointer.
822 /// Rust functions which take ownership of an object provided via an argument require
823 /// this to be true and invalidate the object pointed to by inner.
827 impl Drop for Description {
829 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
830 let _ = unsafe { Box::from_raw(self.inner) };
834 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
836 pub extern "C" fn Description_free(this_obj: Description) { }
838 /// Used only if an object of this type is returned as a trait impl by a method
839 extern "C" fn Description_free_void(this_ptr: *mut c_void) {
840 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
843 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
845 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
846 assert!(self.is_owned);
847 let ret = self.inner;
848 self.inner = std::ptr::null_mut();
852 /// Checks if two Descriptions contain equal inner contents.
853 /// This ignores pointers and is_owned flags and looks at the values in fields.
854 /// Two objects with NULL inner values will be considered "equal" here.
856 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
857 if a.inner == b.inner { return true; }
858 if a.inner.is_null() || b.inner.is_null() { return false; }
859 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
861 impl Clone for Description {
862 fn clone(&self) -> Self {
864 inner: if <*mut nativeDescription>::is_null(self.inner) { std::ptr::null_mut() } else {
865 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
871 /// Used only if an object of this type is returned as a trait impl by a method
872 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
873 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
876 /// Creates a copy of the Description
877 pub extern "C" fn Description_clone(orig: &Description) -> Description {
881 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
882 type nativePayeePubKey = nativePayeePubKeyImport;
887 pub struct PayeePubKey {
888 /// A pointer to the opaque Rust object.
890 /// Nearly everywhere, inner must be non-null, however in places where
891 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
892 pub inner: *mut nativePayeePubKey,
893 /// Indicates that this is the only struct which contains the same pointer.
895 /// Rust functions which take ownership of an object provided via an argument require
896 /// this to be true and invalidate the object pointed to by inner.
900 impl Drop for PayeePubKey {
902 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
903 let _ = unsafe { Box::from_raw(self.inner) };
907 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
909 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
911 /// Used only if an object of this type is returned as a trait impl by a method
912 extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
913 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
916 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
918 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
919 assert!(self.is_owned);
920 let ret = self.inner;
921 self.inner = std::ptr::null_mut();
925 /// Checks if two PayeePubKeys contain equal inner contents.
926 /// This ignores pointers and is_owned flags and looks at the values in fields.
927 /// Two objects with NULL inner values will be considered "equal" here.
929 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
930 if a.inner == b.inner { return true; }
931 if a.inner.is_null() || b.inner.is_null() { return false; }
932 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
934 impl Clone for PayeePubKey {
935 fn clone(&self) -> Self {
937 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { std::ptr::null_mut() } else {
938 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
944 /// Used only if an object of this type is returned as a trait impl by a method
945 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
946 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
949 /// Creates a copy of the PayeePubKey
950 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
954 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
955 type nativeExpiryTime = nativeExpiryTimeImport;
957 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
961 /// The number of seconds this expiry time represents has to be in the range
962 /// `0...(SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME)` to avoid overflows when adding it to a
966 pub struct ExpiryTime {
967 /// A pointer to the opaque Rust object.
969 /// Nearly everywhere, inner must be non-null, however in places where
970 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
971 pub inner: *mut nativeExpiryTime,
972 /// Indicates that this is the only struct which contains the same pointer.
974 /// Rust functions which take ownership of an object provided via an argument require
975 /// this to be true and invalidate the object pointed to by inner.
979 impl Drop for ExpiryTime {
981 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
982 let _ = unsafe { Box::from_raw(self.inner) };
986 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
988 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
990 /// Used only if an object of this type is returned as a trait impl by a method
991 extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
992 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
995 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
997 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
998 assert!(self.is_owned);
999 let ret = self.inner;
1000 self.inner = std::ptr::null_mut();
1004 /// Checks if two ExpiryTimes contain equal inner contents.
1005 /// This ignores pointers and is_owned flags and looks at the values in fields.
1006 /// Two objects with NULL inner values will be considered "equal" here.
1008 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1009 if a.inner == b.inner { return true; }
1010 if a.inner.is_null() || b.inner.is_null() { return false; }
1011 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1013 impl Clone for ExpiryTime {
1014 fn clone(&self) -> Self {
1016 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { std::ptr::null_mut() } else {
1017 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1023 /// Used only if an object of this type is returned as a trait impl by a method
1024 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1025 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1028 /// Creates a copy of the ExpiryTime
1029 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1033 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
1034 type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
1036 /// `min_final_cltv_expiry` to use for the last HTLC in the route
1039 pub struct MinFinalCltvExpiry {
1040 /// A pointer to the opaque Rust object.
1042 /// Nearly everywhere, inner must be non-null, however in places where
1043 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1044 pub inner: *mut nativeMinFinalCltvExpiry,
1045 /// Indicates that this is the only struct which contains the same pointer.
1047 /// Rust functions which take ownership of an object provided via an argument require
1048 /// this to be true and invalidate the object pointed to by inner.
1052 impl Drop for MinFinalCltvExpiry {
1053 fn drop(&mut self) {
1054 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
1055 let _ = unsafe { Box::from_raw(self.inner) };
1059 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1061 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1063 /// Used only if an object of this type is returned as a trait impl by a method
1064 extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1065 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1068 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1069 impl MinFinalCltvExpiry {
1070 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1071 assert!(self.is_owned);
1072 let ret = self.inner;
1073 self.inner = std::ptr::null_mut();
1077 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1078 /// This ignores pointers and is_owned flags and looks at the values in fields.
1079 /// Two objects with NULL inner values will be considered "equal" here.
1081 pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool {
1082 if a.inner == b.inner { return true; }
1083 if a.inner.is_null() || b.inner.is_null() { return false; }
1084 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1086 impl Clone for MinFinalCltvExpiry {
1087 fn clone(&self) -> Self {
1089 inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { std::ptr::null_mut() } else {
1090 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1096 /// Used only if an object of this type is returned as a trait impl by a method
1097 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1098 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1101 /// Creates a copy of the MinFinalCltvExpiry
1102 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1105 /// Fallback address in case no LN payment is possible
1111 version: crate::c_types::u5,
1112 program: crate::c_types::derived::CVec_u8Z,
1114 PubKeyHash(crate::c_types::TwentyBytes),
1115 ScriptHash(crate::c_types::TwentyBytes),
1117 use lightning_invoice::Fallback as nativeFallback;
1120 pub(crate) fn to_native(&self) -> nativeFallback {
1122 Fallback::SegWitProgram {ref version, ref program, } => {
1123 let mut version_nonref = (*version).clone();
1124 let mut program_nonref = (*program).clone();
1125 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1126 nativeFallback::SegWitProgram {
1127 version: version_nonref.into(),
1128 program: local_program_nonref,
1131 Fallback::PubKeyHash (ref a, ) => {
1132 let mut a_nonref = (*a).clone();
1133 nativeFallback::PubKeyHash (
1137 Fallback::ScriptHash (ref a, ) => {
1138 let mut a_nonref = (*a).clone();
1139 nativeFallback::ScriptHash (
1146 pub(crate) fn into_native(self) -> nativeFallback {
1148 Fallback::SegWitProgram {mut version, mut program, } => {
1149 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1150 nativeFallback::SegWitProgram {
1151 version: version.into(),
1152 program: local_program,
1155 Fallback::PubKeyHash (mut a, ) => {
1156 nativeFallback::PubKeyHash (
1160 Fallback::ScriptHash (mut a, ) => {
1161 nativeFallback::ScriptHash (
1168 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1170 nativeFallback::SegWitProgram {ref version, ref program, } => {
1171 let mut version_nonref = (*version).clone();
1172 let mut program_nonref = (*program).clone();
1173 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1174 Fallback::SegWitProgram {
1175 version: version_nonref.into(),
1176 program: local_program_nonref.into(),
1179 nativeFallback::PubKeyHash (ref a, ) => {
1180 let mut a_nonref = (*a).clone();
1181 Fallback::PubKeyHash (
1182 crate::c_types::TwentyBytes { data: a_nonref },
1185 nativeFallback::ScriptHash (ref a, ) => {
1186 let mut a_nonref = (*a).clone();
1187 Fallback::ScriptHash (
1188 crate::c_types::TwentyBytes { data: a_nonref },
1194 pub(crate) fn native_into(native: nativeFallback) -> Self {
1196 nativeFallback::SegWitProgram {mut version, mut program, } => {
1197 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1198 Fallback::SegWitProgram {
1199 version: version.into(),
1200 program: local_program.into(),
1203 nativeFallback::PubKeyHash (mut a, ) => {
1204 Fallback::PubKeyHash (
1205 crate::c_types::TwentyBytes { data: a },
1208 nativeFallback::ScriptHash (mut a, ) => {
1209 Fallback::ScriptHash (
1210 crate::c_types::TwentyBytes { data: a },
1216 /// Frees any resources used by the Fallback
1218 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1219 /// Creates a copy of the Fallback
1221 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1225 /// Utility method to constructs a new SegWitProgram-variant Fallback
1226 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::u5, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
1227 Fallback::SegWitProgram {
1233 /// Utility method to constructs a new PubKeyHash-variant Fallback
1234 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1235 Fallback::PubKeyHash(a, )
1238 /// Utility method to constructs a new ScriptHash-variant Fallback
1239 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1240 Fallback::ScriptHash(a, )
1242 /// Checks if two Fallbacks contain equal inner contents.
1243 /// This ignores pointers and is_owned flags and looks at the values in fields.
1245 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1246 if &a.to_native() == &b.to_native() { true } else { false }
1249 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1250 type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1252 /// Recoverable signature
1255 pub struct InvoiceSignature {
1256 /// A pointer to the opaque Rust object.
1258 /// Nearly everywhere, inner must be non-null, however in places where
1259 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1260 pub inner: *mut nativeInvoiceSignature,
1261 /// Indicates that this is the only struct which contains the same pointer.
1263 /// Rust functions which take ownership of an object provided via an argument require
1264 /// this to be true and invalidate the object pointed to by inner.
1268 impl Drop for InvoiceSignature {
1269 fn drop(&mut self) {
1270 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1271 let _ = unsafe { Box::from_raw(self.inner) };
1275 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1277 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1279 /// Used only if an object of this type is returned as a trait impl by a method
1280 extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1281 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1284 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1285 impl InvoiceSignature {
1286 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1287 assert!(self.is_owned);
1288 let ret = self.inner;
1289 self.inner = std::ptr::null_mut();
1293 /// Checks if two InvoiceSignatures contain equal inner contents.
1294 /// This ignores pointers and is_owned flags and looks at the values in fields.
1295 /// Two objects with NULL inner values will be considered "equal" here.
1297 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
1298 if a.inner == b.inner { return true; }
1299 if a.inner.is_null() || b.inner.is_null() { return false; }
1300 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1302 impl Clone for InvoiceSignature {
1303 fn clone(&self) -> Self {
1305 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { std::ptr::null_mut() } else {
1306 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1312 /// Used only if an object of this type is returned as a trait impl by a method
1313 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
1314 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
1317 /// Creates a copy of the InvoiceSignature
1318 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
1322 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
1323 type nativePrivateRoute = nativePrivateRouteImport;
1325 /// Private routing information
1328 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
1332 pub struct PrivateRoute {
1333 /// A pointer to the opaque Rust object.
1335 /// Nearly everywhere, inner must be non-null, however in places where
1336 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1337 pub inner: *mut nativePrivateRoute,
1338 /// Indicates that this is the only struct which contains the same pointer.
1340 /// Rust functions which take ownership of an object provided via an argument require
1341 /// this to be true and invalidate the object pointed to by inner.
1345 impl Drop for PrivateRoute {
1346 fn drop(&mut self) {
1347 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
1348 let _ = unsafe { Box::from_raw(self.inner) };
1352 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
1354 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
1356 /// Used only if an object of this type is returned as a trait impl by a method
1357 extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
1358 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); }
1361 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1363 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
1364 assert!(self.is_owned);
1365 let ret = self.inner;
1366 self.inner = std::ptr::null_mut();
1370 /// Checks if two PrivateRoutes contain equal inner contents.
1371 /// This ignores pointers and is_owned flags and looks at the values in fields.
1372 /// Two objects with NULL inner values will be considered "equal" here.
1374 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
1375 if a.inner == b.inner { return true; }
1376 if a.inner.is_null() || b.inner.is_null() { return false; }
1377 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1379 impl Clone for PrivateRoute {
1380 fn clone(&self) -> Self {
1382 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { std::ptr::null_mut() } else {
1383 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1389 /// Used only if an object of this type is returned as a trait impl by a method
1390 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
1391 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
1394 /// Creates a copy of the PrivateRoute
1395 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
1398 /// Disassembles the `SignedRawInvoice` into its three parts:
1400 /// 2. hash of the raw invoice
1404 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
1405 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
1406 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();
1410 /// The `RawInvoice` which was signed.
1413 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
1414 let mut ret = unsafe { &*this_arg.inner }.raw_invoice();
1415 crate::lightning_invoice::RawInvoice { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1418 /// The hash of the `RawInvoice` that was signed.
1421 pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [u8; 32] {
1422 let mut ret = unsafe { &*this_arg.inner }.hash();
1426 /// InvoiceSignature for the invoice.
1429 pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
1430 let mut ret = unsafe { &*this_arg.inner }.signature();
1431 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1434 /// Recovers the public key used for signing the invoice from the recoverable signature.
1437 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
1438 let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key();
1439 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() };
1443 /// Checks if the signature is valid for the included payee public key or if none exists if it's
1444 /// valid for the recovered signature (which should always be true?).
1447 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &SignedRawInvoice) -> bool {
1448 let mut ret = unsafe { &*this_arg.inner }.check_signature();
1452 /// Calculate the hash of the encoded `RawInvoice`
1455 pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1456 let mut ret = unsafe { &*this_arg.inner }.hash();
1457 crate::c_types::ThirtyTwoBytes { data: ret }
1461 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1464 pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1465 let mut ret = unsafe { &*this_arg.inner }.payment_hash();
1466 let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1471 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1474 pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightning_invoice::Description {
1475 let mut ret = unsafe { &*this_arg.inner }.description();
1476 let mut local_ret = crate::lightning_invoice::Description { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1481 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1484 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::lightning_invoice::PayeePubKey {
1485 let mut ret = unsafe { &*this_arg.inner }.payee_pub_key();
1486 let mut local_ret = crate::lightning_invoice::PayeePubKey { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1491 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1494 pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1495 let mut ret = unsafe { &*this_arg.inner }.description_hash();
1496 let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1501 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1504 pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightning_invoice::ExpiryTime {
1505 let mut ret = unsafe { &*this_arg.inner }.expiry_time();
1506 let mut local_ret = crate::lightning_invoice::ExpiryTime { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1511 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1514 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
1515 let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry();
1516 let mut local_ret = crate::lightning_invoice::MinFinalCltvExpiry { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1521 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1524 pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1525 let mut ret = unsafe { &*this_arg.inner }.payment_secret();
1526 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1531 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1534 pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
1535 let mut ret = unsafe { &*this_arg.inner }.features();
1536 let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1542 pub extern "C" fn RawInvoice_private_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1543 let mut ret = unsafe { &*this_arg.inner }.private_routes();
1544 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ( (&(*item) as *const _) as *mut _) }, is_owned: false } }); };
1550 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z {
1551 let mut ret = unsafe { &*this_arg.inner }.amount_pico_btc();
1552 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()) } };
1558 pub extern "C" fn RawInvoice_currency(this_arg: &RawInvoice) -> crate::lightning_invoice::Currency {
1559 let mut ret = unsafe { &*this_arg.inner }.currency();
1560 crate::lightning_invoice::Currency::native_into(ret)
1563 /// Create a new `PositiveTimestamp` from a unix timestamp in the Range
1564 /// `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1565 /// `CreationError::TimestampOutOfBounds`.
1568 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1569 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
1570 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() };
1574 /// Create a new `PositiveTimestamp` from a `SystemTime` with a corresponding unix timestamp in
1575 /// the Range `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1576 /// `CreationError::TimestampOutOfBounds`.
1579 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1580 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
1581 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() };
1585 /// Returns the UNIX timestamp representing the stored time
1588 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 {
1589 let mut ret = unsafe { &*this_arg.inner }.as_unix_timestamp();
1593 /// Returns a reference to the internal `SystemTime` time representation
1596 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &PositiveTimestamp) -> u64 {
1597 let mut ret = unsafe { &*this_arg.inner }.as_time();
1598 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1601 /// Transform the `Invoice` into it's unchecked version
1604 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::lightning_invoice::SignedRawInvoice {
1605 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
1606 crate::lightning_invoice::SignedRawInvoice { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1609 /// Check that the invoice is signed correctly and that key recovery works
1612 pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
1613 let mut ret = unsafe { &*this_arg.inner }.check_signature();
1614 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::SemanticError::native_into(e) }).into() };
1618 /// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
1620 /// use lightning_invoice::*;
1622 /// let invoice = \"lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdp\\
1623 /// \tl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d7\\
1624 /// \t3gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ec\\
1625 /// \tky03ylcqca784w\";
1627 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
1629 /// assert!(Invoice::from_signed(signed).is_ok());
1633 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
1634 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
1635 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() };
1639 /// Returns the `Invoice`'s timestamp (should equal it's creation time)
1642 pub extern "C" fn Invoice_timestamp(this_arg: &Invoice) -> u64 {
1643 let mut ret = unsafe { &*this_arg.inner }.timestamp();
1644 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1647 /// Returns the hash to which we will receive the preimage on completion of the payment
1650 pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] {
1651 let mut ret = unsafe { &*this_arg.inner }.payment_hash();
1655 /// Get the payee's public key if one was included in the invoice
1657 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1660 pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1661 let mut ret = unsafe { &*this_arg.inner }.payee_pub_key();
1662 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
1666 /// Get the payment secret if one was included in the invoice
1668 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1671 pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> crate::c_types::ThirtyTwoBytes {
1672 let mut ret = unsafe { &*this_arg.inner }.payment_secret();
1673 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1677 /// Get the invoice features if they were included in the invoice
1679 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1682 pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
1683 let mut ret = unsafe { &*this_arg.inner }.features();
1684 let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1688 /// Recover the payee's public key (only to be used if none was included in the invoice)
1691 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1692 let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key();
1693 crate::c_types::PublicKey::from_rust(&ret)
1696 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
1699 pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 {
1700 let mut ret = unsafe { &*this_arg.inner }.expiry_time();
1704 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
1705 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
1708 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 {
1709 let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry();
1713 /// Returns a list of all routes included in the invoice
1716 pub extern "C" fn Invoice_private_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1717 let mut ret = unsafe { &*this_arg.inner }.private_routes();
1718 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ( (&(*item) as *const _) as *mut _) }, is_owned: false } }); };
1722 /// Returns a list of all routes included in the invoice as the underlying hints
1725 pub extern "C" fn Invoice_route_hints(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
1726 let mut ret = unsafe { &*this_arg.inner }.route_hints();
1727 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::router::RouteHint { inner: unsafe { ( (&(*item) as *const _) as *mut _) }, is_owned: false } }); };
1731 /// Returns the currency for which the invoice was issued
1734 pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoice::Currency {
1735 let mut ret = unsafe { &*this_arg.inner }.currency();
1736 crate::lightning_invoice::Currency::native_into(ret)
1739 /// Returns the amount if specified in the invoice as pico <currency>.
1742 pub extern "C" fn Invoice_amount_pico_btc(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z {
1743 let mut ret = unsafe { &*this_arg.inner }.amount_pico_btc();
1744 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()) } };
1748 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
1749 /// returns `CreationError::DescriptionTooLong` otherwise
1751 /// Please note that single characters may use more than one byte due to UTF8 encoding.
1754 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
1755 let mut ret = lightning_invoice::Description::new(description.into_string());
1756 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() };
1760 /// Returns the underlying description `String`
1763 pub extern "C" fn Description_into_inner(mut this_arg: Description) -> crate::c_types::Str {
1764 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1768 /// Construct an `ExpiryTime` from seconds. If there exists a `PositiveTimestamp` which would
1769 /// overflow on adding the `EpiryTime` to it then this function will return a
1770 /// `CreationError::ExpiryTimeOutOfBounds`.
1773 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1774 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
1775 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() };
1779 /// Construct an `ExpiryTime` from a `Duration`. If there exists a `PositiveTimestamp` which
1780 /// would overflow on adding the `EpiryTime` to it then this function will return a
1781 /// `CreationError::ExpiryTimeOutOfBounds`.
1784 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1785 let mut ret = lightning_invoice::ExpiryTime::from_duration(std::time::Duration::from_secs(duration));
1786 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() };
1790 /// Returns the expiry time in seconds
1793 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 {
1794 let mut ret = unsafe { &*this_arg.inner }.as_seconds();
1798 /// Returns a reference to the underlying `Duration` (=expiry time)
1801 pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 {
1802 let mut ret = unsafe { &*this_arg.inner }.as_duration();
1806 /// Creates a new (partial) route from a list of hops
1809 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
1810 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
1811 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PrivateRoute { 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() };
1815 /// Returns the underlying list of hops
1818 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: PrivateRoute) -> crate::lightning::routing::router::RouteHint {
1819 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1820 crate::lightning::routing::router::RouteHint { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1823 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
1827 pub enum CreationError {
1828 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
1830 /// The specified route has too many hops and can't be encoded
1832 /// The unix timestamp of the supplied date is <0 or can't be represented as `SystemTime`
1833 TimestampOutOfBounds,
1834 /// The supplied expiry time could cause an overflow if added to a `PositiveTimestamp`
1835 ExpiryTimeOutOfBounds,
1837 use lightning_invoice::CreationError as nativeCreationError;
1838 impl CreationError {
1840 pub(crate) fn to_native(&self) -> nativeCreationError {
1842 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
1843 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
1844 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
1845 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
1849 pub(crate) fn into_native(self) -> nativeCreationError {
1851 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
1852 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
1853 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
1854 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
1858 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
1860 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
1861 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
1862 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
1863 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
1867 pub(crate) fn native_into(native: nativeCreationError) -> Self {
1869 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
1870 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
1871 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
1872 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
1876 /// Creates a copy of the CreationError
1878 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
1882 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
1883 pub extern "C" fn CreationError_description_too_long() -> CreationError {
1884 CreationError::DescriptionTooLong}
1886 /// Utility method to constructs a new RouteTooLong-variant CreationError
1887 pub extern "C" fn CreationError_route_too_long() -> CreationError {
1888 CreationError::RouteTooLong}
1890 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
1891 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
1892 CreationError::TimestampOutOfBounds}
1894 /// Utility method to constructs a new ExpiryTimeOutOfBounds-variant CreationError
1895 pub extern "C" fn CreationError_expiry_time_out_of_bounds() -> CreationError {
1896 CreationError::ExpiryTimeOutOfBounds}
1897 /// Checks if two CreationErrors contain equal inner contents.
1898 /// This ignores pointers and is_owned flags and looks at the values in fields.
1900 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
1901 if &a.to_native() == &b.to_native() { true } else { false }
1904 /// Get the string representation of a CreationError object
1905 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
1906 format!("{}", &o.to_native()).into()
1908 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
1909 /// requirements sections in BOLT #11
1913 pub enum SemanticError {
1914 /// The invoice is missing the mandatory payment hash
1916 /// The invoice has multiple payment hashes which isn't allowed
1917 MultiplePaymentHashes,
1918 /// No description or description hash are part of the invoice
1920 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
1921 MultipleDescriptions,
1922 /// The invoice contains multiple payment secrets
1923 MultiplePaymentSecrets,
1924 /// The invoice's features are invalid
1926 /// The recovery id doesn't fit the signature/pub key
1928 /// The invoice's signature is invalid
1931 use lightning_invoice::SemanticError as nativeSemanticError;
1932 impl SemanticError {
1934 pub(crate) fn to_native(&self) -> nativeSemanticError {
1936 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
1937 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
1938 SemanticError::NoDescription => nativeSemanticError::NoDescription,
1939 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
1940 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
1941 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
1942 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
1943 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
1947 pub(crate) fn into_native(self) -> nativeSemanticError {
1949 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
1950 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
1951 SemanticError::NoDescription => nativeSemanticError::NoDescription,
1952 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
1953 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
1954 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
1955 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
1956 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
1960 pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
1962 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
1963 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
1964 nativeSemanticError::NoDescription => SemanticError::NoDescription,
1965 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
1966 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
1967 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
1968 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
1969 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
1973 pub(crate) fn native_into(native: nativeSemanticError) -> Self {
1975 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
1976 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
1977 nativeSemanticError::NoDescription => SemanticError::NoDescription,
1978 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
1979 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
1980 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
1981 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
1982 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
1986 /// Creates a copy of the SemanticError
1988 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
1992 /// Utility method to constructs a new NoPaymentHash-variant SemanticError
1993 pub extern "C" fn SemanticError_no_payment_hash() -> SemanticError {
1994 SemanticError::NoPaymentHash}
1996 /// Utility method to constructs a new MultiplePaymentHashes-variant SemanticError
1997 pub extern "C" fn SemanticError_multiple_payment_hashes() -> SemanticError {
1998 SemanticError::MultiplePaymentHashes}
2000 /// Utility method to constructs a new NoDescription-variant SemanticError
2001 pub extern "C" fn SemanticError_no_description() -> SemanticError {
2002 SemanticError::NoDescription}
2004 /// Utility method to constructs a new MultipleDescriptions-variant SemanticError
2005 pub extern "C" fn SemanticError_multiple_descriptions() -> SemanticError {
2006 SemanticError::MultipleDescriptions}
2008 /// Utility method to constructs a new MultiplePaymentSecrets-variant SemanticError
2009 pub extern "C" fn SemanticError_multiple_payment_secrets() -> SemanticError {
2010 SemanticError::MultiplePaymentSecrets}
2012 /// Utility method to constructs a new InvalidFeatures-variant SemanticError
2013 pub extern "C" fn SemanticError_invalid_features() -> SemanticError {
2014 SemanticError::InvalidFeatures}
2016 /// Utility method to constructs a new InvalidRecoveryId-variant SemanticError
2017 pub extern "C" fn SemanticError_invalid_recovery_id() -> SemanticError {
2018 SemanticError::InvalidRecoveryId}
2020 /// Utility method to constructs a new InvalidSignature-variant SemanticError
2021 pub extern "C" fn SemanticError_invalid_signature() -> SemanticError {
2022 SemanticError::InvalidSignature}
2023 /// Checks if two SemanticErrors contain equal inner contents.
2024 /// This ignores pointers and is_owned flags and looks at the values in fields.
2026 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
2027 if &a.to_native() == &b.to_native() { true } else { false }
2030 /// Get the string representation of a SemanticError object
2031 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
2032 format!("{}", &o.to_native()).into()
2034 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
2039 pub enum SignOrCreationError {
2040 /// An error occurred during signing
2042 /// An error occurred while building the transaction
2043 CreationError(crate::lightning_invoice::CreationError),
2045 use lightning_invoice::SignOrCreationError as nativeSignOrCreationError;
2046 impl SignOrCreationError {
2048 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
2050 SignOrCreationError::SignError => {
2051 nativeSignOrCreationError::SignError (
2055 SignOrCreationError::CreationError (ref a, ) => {
2056 let mut a_nonref = (*a).clone();
2057 nativeSignOrCreationError::CreationError (
2058 a_nonref.into_native(),
2064 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
2066 SignOrCreationError::SignError => {
2067 nativeSignOrCreationError::SignError (
2071 SignOrCreationError::CreationError (mut a, ) => {
2072 nativeSignOrCreationError::CreationError (
2079 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
2081 nativeSignOrCreationError::SignError (ref a, ) => {
2082 SignOrCreationError::SignError },
2083 nativeSignOrCreationError::CreationError (ref a, ) => {
2084 let mut a_nonref = (*a).clone();
2085 SignOrCreationError::CreationError (
2086 crate::lightning_invoice::CreationError::native_into(a_nonref),
2092 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
2094 nativeSignOrCreationError::SignError (mut a, ) => {
2095 SignOrCreationError::SignError },
2096 nativeSignOrCreationError::CreationError (mut a, ) => {
2097 SignOrCreationError::CreationError (
2098 crate::lightning_invoice::CreationError::native_into(a),
2104 /// Frees any resources used by the SignOrCreationError
2106 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
2107 /// Creates a copy of the SignOrCreationError
2109 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
2113 /// Utility method to constructs a new SignError-variant SignOrCreationError
2114 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
2115 SignOrCreationError::SignError
2118 /// Utility method to constructs a new CreationError-variant SignOrCreationError
2119 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
2120 SignOrCreationError::CreationError(a, )
2122 /// Checks if two SignOrCreationErrors contain equal inner contents.
2123 /// This ignores pointers and is_owned flags and looks at the values in fields.
2125 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
2126 if &a.to_native() == &b.to_native() { true } else { false }
2129 /// Get the string representation of a SignOrCreationError object
2130 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
2131 format!("{}", &o.to_native()).into()