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 {
610 /// Checks if two SiPrefixs contain equal inner contents.
611 /// This ignores pointers and is_owned flags and looks at the values in fields.
613 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
614 if &a.to_native() == &b.to_native() { true } else { false }
616 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
617 /// This is effectively 10^12 * the prefix multiplier
620 pub extern "C" fn SiPrefix_multiplier(this_arg: &SiPrefix) -> u64 {
621 let mut ret = this_arg.to_native().multiplier();
625 /// Enum representing the crypto currencies (or networks) supported by this library
641 use lightning_invoice::Currency as nativeCurrency;
644 pub(crate) fn to_native(&self) -> nativeCurrency {
646 Currency::Bitcoin => nativeCurrency::Bitcoin,
647 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
648 Currency::Regtest => nativeCurrency::Regtest,
649 Currency::Simnet => nativeCurrency::Simnet,
650 Currency::Signet => nativeCurrency::Signet,
654 pub(crate) fn into_native(self) -> nativeCurrency {
656 Currency::Bitcoin => nativeCurrency::Bitcoin,
657 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
658 Currency::Regtest => nativeCurrency::Regtest,
659 Currency::Simnet => nativeCurrency::Simnet,
660 Currency::Signet => nativeCurrency::Signet,
664 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
666 nativeCurrency::Bitcoin => Currency::Bitcoin,
667 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
668 nativeCurrency::Regtest => Currency::Regtest,
669 nativeCurrency::Simnet => Currency::Simnet,
670 nativeCurrency::Signet => Currency::Signet,
674 pub(crate) fn native_into(native: nativeCurrency) -> Self {
676 nativeCurrency::Bitcoin => Currency::Bitcoin,
677 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
678 nativeCurrency::Regtest => Currency::Regtest,
679 nativeCurrency::Simnet => Currency::Simnet,
680 nativeCurrency::Signet => Currency::Signet,
684 /// Creates a copy of the Currency
686 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
689 /// Checks if two Currencys contain equal inner contents.
690 /// This ignores pointers and is_owned flags and looks at the values in fields.
692 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
693 if &a.to_native() == &b.to_native() { true } else { false }
696 use lightning_invoice::Sha256 as nativeSha256Import;
697 type nativeSha256 = nativeSha256Import;
703 /// A pointer to the opaque Rust object.
705 /// Nearly everywhere, inner must be non-null, however in places where
706 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
707 pub inner: *mut nativeSha256,
708 /// Indicates that this is the only struct which contains the same pointer.
710 /// Rust functions which take ownership of an object provided via an argument require
711 /// this to be true and invalidate the object pointed to by inner.
715 impl Drop for Sha256 {
717 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
718 let _ = unsafe { Box::from_raw(self.inner) };
722 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
724 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
726 /// Used only if an object of this type is returned as a trait impl by a method
727 extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
728 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
731 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
733 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
734 assert!(self.is_owned);
735 let ret = self.inner;
736 self.inner = std::ptr::null_mut();
740 /// Checks if two Sha256s contain equal inner contents.
741 /// This ignores pointers and is_owned flags and looks at the values in fields.
742 /// Two objects with NULL inner values will be considered "equal" here.
744 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
745 if a.inner == b.inner { return true; }
746 if a.inner.is_null() || b.inner.is_null() { return false; }
747 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
749 impl Clone for Sha256 {
750 fn clone(&self) -> Self {
752 inner: if <*mut nativeSha256>::is_null(self.inner) { std::ptr::null_mut() } else {
753 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
759 /// Used only if an object of this type is returned as a trait impl by a method
760 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
761 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
764 /// Creates a copy of the Sha256
765 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
769 use lightning_invoice::Description as nativeDescriptionImport;
770 type nativeDescription = nativeDescriptionImport;
772 /// Description string
775 /// The description can be at most 639 __bytes__ long
778 pub struct Description {
779 /// A pointer to the opaque Rust object.
781 /// Nearly everywhere, inner must be non-null, however in places where
782 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
783 pub inner: *mut nativeDescription,
784 /// Indicates that this is the only struct which contains the same pointer.
786 /// Rust functions which take ownership of an object provided via an argument require
787 /// this to be true and invalidate the object pointed to by inner.
791 impl Drop for Description {
793 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
794 let _ = unsafe { Box::from_raw(self.inner) };
798 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
800 pub extern "C" fn Description_free(this_obj: Description) { }
802 /// Used only if an object of this type is returned as a trait impl by a method
803 extern "C" fn Description_free_void(this_ptr: *mut c_void) {
804 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
807 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
809 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
810 assert!(self.is_owned);
811 let ret = self.inner;
812 self.inner = std::ptr::null_mut();
816 /// Checks if two Descriptions contain equal inner contents.
817 /// This ignores pointers and is_owned flags and looks at the values in fields.
818 /// Two objects with NULL inner values will be considered "equal" here.
820 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
821 if a.inner == b.inner { return true; }
822 if a.inner.is_null() || b.inner.is_null() { return false; }
823 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
825 impl Clone for Description {
826 fn clone(&self) -> Self {
828 inner: if <*mut nativeDescription>::is_null(self.inner) { std::ptr::null_mut() } else {
829 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
835 /// Used only if an object of this type is returned as a trait impl by a method
836 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
837 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
840 /// Creates a copy of the Description
841 pub extern "C" fn Description_clone(orig: &Description) -> Description {
845 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
846 type nativePayeePubKey = nativePayeePubKeyImport;
851 pub struct PayeePubKey {
852 /// A pointer to the opaque Rust object.
854 /// Nearly everywhere, inner must be non-null, however in places where
855 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
856 pub inner: *mut nativePayeePubKey,
857 /// Indicates that this is the only struct which contains the same pointer.
859 /// Rust functions which take ownership of an object provided via an argument require
860 /// this to be true and invalidate the object pointed to by inner.
864 impl Drop for PayeePubKey {
866 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
867 let _ = unsafe { Box::from_raw(self.inner) };
871 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
873 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
875 /// Used only if an object of this type is returned as a trait impl by a method
876 extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
877 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
880 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
882 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
883 assert!(self.is_owned);
884 let ret = self.inner;
885 self.inner = std::ptr::null_mut();
889 /// Checks if two PayeePubKeys contain equal inner contents.
890 /// This ignores pointers and is_owned flags and looks at the values in fields.
891 /// Two objects with NULL inner values will be considered "equal" here.
893 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
894 if a.inner == b.inner { return true; }
895 if a.inner.is_null() || b.inner.is_null() { return false; }
896 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
898 impl Clone for PayeePubKey {
899 fn clone(&self) -> Self {
901 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { std::ptr::null_mut() } else {
902 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
908 /// Used only if an object of this type is returned as a trait impl by a method
909 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
910 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
913 /// Creates a copy of the PayeePubKey
914 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
918 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
919 type nativeExpiryTime = nativeExpiryTimeImport;
921 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
925 /// The number of seconds this expiry time represents has to be in the range
926 /// `0...(SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME)` to avoid overflows when adding it to a
930 pub struct ExpiryTime {
931 /// A pointer to the opaque Rust object.
933 /// Nearly everywhere, inner must be non-null, however in places where
934 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
935 pub inner: *mut nativeExpiryTime,
936 /// Indicates that this is the only struct which contains the same pointer.
938 /// Rust functions which take ownership of an object provided via an argument require
939 /// this to be true and invalidate the object pointed to by inner.
943 impl Drop for ExpiryTime {
945 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
946 let _ = unsafe { Box::from_raw(self.inner) };
950 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
952 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
954 /// Used only if an object of this type is returned as a trait impl by a method
955 extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
956 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
959 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
961 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
962 assert!(self.is_owned);
963 let ret = self.inner;
964 self.inner = std::ptr::null_mut();
968 /// Checks if two ExpiryTimes contain equal inner contents.
969 /// This ignores pointers and is_owned flags and looks at the values in fields.
970 /// Two objects with NULL inner values will be considered "equal" here.
972 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
973 if a.inner == b.inner { return true; }
974 if a.inner.is_null() || b.inner.is_null() { return false; }
975 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
977 impl Clone for ExpiryTime {
978 fn clone(&self) -> Self {
980 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { std::ptr::null_mut() } else {
981 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
987 /// Used only if an object of this type is returned as a trait impl by a method
988 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
989 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
992 /// Creates a copy of the ExpiryTime
993 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
997 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
998 type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
1000 /// `min_final_cltv_expiry` to use for the last HTLC in the route
1003 pub struct MinFinalCltvExpiry {
1004 /// A pointer to the opaque Rust object.
1006 /// Nearly everywhere, inner must be non-null, however in places where
1007 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1008 pub inner: *mut nativeMinFinalCltvExpiry,
1009 /// Indicates that this is the only struct which contains the same pointer.
1011 /// Rust functions which take ownership of an object provided via an argument require
1012 /// this to be true and invalidate the object pointed to by inner.
1016 impl Drop for MinFinalCltvExpiry {
1017 fn drop(&mut self) {
1018 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
1019 let _ = unsafe { Box::from_raw(self.inner) };
1023 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1025 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1027 /// Used only if an object of this type is returned as a trait impl by a method
1028 extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1029 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1032 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1033 impl MinFinalCltvExpiry {
1034 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1035 assert!(self.is_owned);
1036 let ret = self.inner;
1037 self.inner = std::ptr::null_mut();
1041 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1042 /// This ignores pointers and is_owned flags and looks at the values in fields.
1043 /// Two objects with NULL inner values will be considered "equal" here.
1045 pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool {
1046 if a.inner == b.inner { return true; }
1047 if a.inner.is_null() || b.inner.is_null() { return false; }
1048 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1050 impl Clone for MinFinalCltvExpiry {
1051 fn clone(&self) -> Self {
1053 inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { std::ptr::null_mut() } else {
1054 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1060 /// Used only if an object of this type is returned as a trait impl by a method
1061 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1062 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1065 /// Creates a copy of the MinFinalCltvExpiry
1066 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1069 /// Fallback address in case no LN payment is possible
1075 version: crate::c_types::u5,
1076 program: crate::c_types::derived::CVec_u8Z,
1078 PubKeyHash(crate::c_types::TwentyBytes),
1079 ScriptHash(crate::c_types::TwentyBytes),
1081 use lightning_invoice::Fallback as nativeFallback;
1084 pub(crate) fn to_native(&self) -> nativeFallback {
1086 Fallback::SegWitProgram {ref version, ref program, } => {
1087 let mut version_nonref = (*version).clone();
1088 let mut program_nonref = (*program).clone();
1089 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1090 nativeFallback::SegWitProgram {
1091 version: version_nonref.into(),
1092 program: local_program_nonref,
1095 Fallback::PubKeyHash (ref a, ) => {
1096 let mut a_nonref = (*a).clone();
1097 nativeFallback::PubKeyHash (
1101 Fallback::ScriptHash (ref a, ) => {
1102 let mut a_nonref = (*a).clone();
1103 nativeFallback::ScriptHash (
1110 pub(crate) fn into_native(self) -> nativeFallback {
1112 Fallback::SegWitProgram {mut version, mut program, } => {
1113 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1114 nativeFallback::SegWitProgram {
1115 version: version.into(),
1116 program: local_program,
1119 Fallback::PubKeyHash (mut a, ) => {
1120 nativeFallback::PubKeyHash (
1124 Fallback::ScriptHash (mut a, ) => {
1125 nativeFallback::ScriptHash (
1132 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1134 nativeFallback::SegWitProgram {ref version, ref program, } => {
1135 let mut version_nonref = (*version).clone();
1136 let mut program_nonref = (*program).clone();
1137 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1138 Fallback::SegWitProgram {
1139 version: version_nonref.into(),
1140 program: local_program_nonref.into(),
1143 nativeFallback::PubKeyHash (ref a, ) => {
1144 let mut a_nonref = (*a).clone();
1145 Fallback::PubKeyHash (
1146 crate::c_types::TwentyBytes { data: a_nonref },
1149 nativeFallback::ScriptHash (ref a, ) => {
1150 let mut a_nonref = (*a).clone();
1151 Fallback::ScriptHash (
1152 crate::c_types::TwentyBytes { data: a_nonref },
1158 pub(crate) fn native_into(native: nativeFallback) -> Self {
1160 nativeFallback::SegWitProgram {mut version, mut program, } => {
1161 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1162 Fallback::SegWitProgram {
1163 version: version.into(),
1164 program: local_program.into(),
1167 nativeFallback::PubKeyHash (mut a, ) => {
1168 Fallback::PubKeyHash (
1169 crate::c_types::TwentyBytes { data: a },
1172 nativeFallback::ScriptHash (mut a, ) => {
1173 Fallback::ScriptHash (
1174 crate::c_types::TwentyBytes { data: a },
1180 /// Frees any resources used by the Fallback
1182 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1183 /// Creates a copy of the Fallback
1185 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1188 /// Checks if two Fallbacks contain equal inner contents.
1189 /// This ignores pointers and is_owned flags and looks at the values in fields.
1191 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1192 if &a.to_native() == &b.to_native() { true } else { false }
1195 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1196 type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1198 /// Recoverable signature
1201 pub struct InvoiceSignature {
1202 /// A pointer to the opaque Rust object.
1204 /// Nearly everywhere, inner must be non-null, however in places where
1205 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1206 pub inner: *mut nativeInvoiceSignature,
1207 /// Indicates that this is the only struct which contains the same pointer.
1209 /// Rust functions which take ownership of an object provided via an argument require
1210 /// this to be true and invalidate the object pointed to by inner.
1214 impl Drop for InvoiceSignature {
1215 fn drop(&mut self) {
1216 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1217 let _ = unsafe { Box::from_raw(self.inner) };
1221 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1223 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1225 /// Used only if an object of this type is returned as a trait impl by a method
1226 extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1227 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1230 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1231 impl InvoiceSignature {
1232 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1233 assert!(self.is_owned);
1234 let ret = self.inner;
1235 self.inner = std::ptr::null_mut();
1239 /// Checks if two InvoiceSignatures contain equal inner contents.
1240 /// This ignores pointers and is_owned flags and looks at the values in fields.
1241 /// Two objects with NULL inner values will be considered "equal" here.
1243 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
1244 if a.inner == b.inner { return true; }
1245 if a.inner.is_null() || b.inner.is_null() { return false; }
1246 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1248 impl Clone for InvoiceSignature {
1249 fn clone(&self) -> Self {
1251 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { std::ptr::null_mut() } else {
1252 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1258 /// Used only if an object of this type is returned as a trait impl by a method
1259 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
1260 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
1263 /// Creates a copy of the InvoiceSignature
1264 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
1268 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
1269 type nativePrivateRoute = nativePrivateRouteImport;
1271 /// Private routing information
1274 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
1278 pub struct PrivateRoute {
1279 /// A pointer to the opaque Rust object.
1281 /// Nearly everywhere, inner must be non-null, however in places where
1282 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1283 pub inner: *mut nativePrivateRoute,
1284 /// Indicates that this is the only struct which contains the same pointer.
1286 /// Rust functions which take ownership of an object provided via an argument require
1287 /// this to be true and invalidate the object pointed to by inner.
1291 impl Drop for PrivateRoute {
1292 fn drop(&mut self) {
1293 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
1294 let _ = unsafe { Box::from_raw(self.inner) };
1298 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
1300 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
1302 /// Used only if an object of this type is returned as a trait impl by a method
1303 extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
1304 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); }
1307 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1309 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
1310 assert!(self.is_owned);
1311 let ret = self.inner;
1312 self.inner = std::ptr::null_mut();
1316 /// Checks if two PrivateRoutes contain equal inner contents.
1317 /// This ignores pointers and is_owned flags and looks at the values in fields.
1318 /// Two objects with NULL inner values will be considered "equal" here.
1320 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
1321 if a.inner == b.inner { return true; }
1322 if a.inner.is_null() || b.inner.is_null() { return false; }
1323 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1325 impl Clone for PrivateRoute {
1326 fn clone(&self) -> Self {
1328 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { std::ptr::null_mut() } else {
1329 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1335 /// Used only if an object of this type is returned as a trait impl by a method
1336 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
1337 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
1340 /// Creates a copy of the PrivateRoute
1341 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
1344 /// Disassembles the `SignedRawInvoice` into its three parts:
1346 /// 2. hash of the raw invoice
1350 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
1351 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
1352 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();
1356 /// The `RawInvoice` which was signed.
1359 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
1360 let mut ret = unsafe { &*this_arg.inner }.raw_invoice();
1361 crate::lightning_invoice::RawInvoice { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1364 /// The hash of the `RawInvoice` that was signed.
1367 pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [u8; 32] {
1368 let mut ret = unsafe { &*this_arg.inner }.hash();
1372 /// InvoiceSignature for the invoice.
1375 pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
1376 let mut ret = unsafe { &*this_arg.inner }.signature();
1377 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1380 /// Recovers the public key used for signing the invoice from the recoverable signature.
1383 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
1384 let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key();
1385 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() };
1389 /// Checks if the signature is valid for the included payee public key or if none exists if it's
1390 /// valid for the recovered signature (which should always be true?).
1393 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &SignedRawInvoice) -> bool {
1394 let mut ret = unsafe { &*this_arg.inner }.check_signature();
1398 /// Calculate the hash of the encoded `RawInvoice`
1401 pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1402 let mut ret = unsafe { &*this_arg.inner }.hash();
1403 crate::c_types::ThirtyTwoBytes { data: ret }
1408 pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1409 let mut ret = unsafe { &*this_arg.inner }.payment_hash();
1410 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 };
1416 pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightning_invoice::Description {
1417 let mut ret = unsafe { &*this_arg.inner }.description();
1418 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 };
1424 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::lightning_invoice::PayeePubKey {
1425 let mut ret = unsafe { &*this_arg.inner }.payee_pub_key();
1426 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 };
1432 pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1433 let mut ret = unsafe { &*this_arg.inner }.description_hash();
1434 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 };
1440 pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightning_invoice::ExpiryTime {
1441 let mut ret = unsafe { &*this_arg.inner }.expiry_time();
1442 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 };
1448 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
1449 let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry();
1450 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 };
1456 pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1457 let mut ret = unsafe { &*this_arg.inner }.payment_secret();
1458 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1464 pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
1465 let mut ret = unsafe { &*this_arg.inner }.features();
1466 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 };
1472 pub extern "C" fn RawInvoice_private_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1473 let mut ret = unsafe { &*this_arg.inner }.private_routes();
1474 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 } }); };
1480 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z {
1481 let mut ret = unsafe { &*this_arg.inner }.amount_pico_btc();
1482 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()) } };
1488 pub extern "C" fn RawInvoice_currency(this_arg: &RawInvoice) -> crate::lightning_invoice::Currency {
1489 let mut ret = unsafe { &*this_arg.inner }.currency();
1490 crate::lightning_invoice::Currency::native_into(ret)
1493 /// Create a new `PositiveTimestamp` from a unix timestamp in the Range
1494 /// `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1495 /// `CreationError::TimestampOutOfBounds`.
1498 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1499 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
1500 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() };
1504 /// Create a new `PositiveTimestamp` from a `SystemTime` with a corresponding unix timestamp in
1505 /// the Range `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1506 /// `CreationError::TimestampOutOfBounds`.
1509 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1510 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
1511 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() };
1515 /// Returns the UNIX timestamp representing the stored time
1518 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 {
1519 let mut ret = unsafe { &*this_arg.inner }.as_unix_timestamp();
1523 /// Returns a reference to the internal `SystemTime` time representation
1526 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &PositiveTimestamp) -> u64 {
1527 let mut ret = unsafe { &*this_arg.inner }.as_time();
1528 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1531 /// Transform the `Invoice` into it's unchecked version
1534 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::lightning_invoice::SignedRawInvoice {
1535 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
1536 crate::lightning_invoice::SignedRawInvoice { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1539 /// Check that the invoice is signed correctly and that key recovery works
1542 pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
1543 let mut ret = unsafe { &*this_arg.inner }.check_signature();
1544 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() };
1548 /// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
1550 /// use lightning_invoice::*;
1552 /// let invoice = \"lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdp\\
1553 /// \tl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d7\\
1554 /// \t3gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ec\\
1555 /// \tky03ylcqca784w\";
1557 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
1559 /// assert!(Invoice::from_signed(signed).is_ok());
1563 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
1564 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
1565 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() };
1569 /// Returns the `Invoice`'s timestamp (should equal it's creation time)
1572 pub extern "C" fn Invoice_timestamp(this_arg: &Invoice) -> u64 {
1573 let mut ret = unsafe { &*this_arg.inner }.timestamp();
1574 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1577 /// Returns the hash to which we will receive the preimage on completion of the payment
1580 pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] {
1581 let mut ret = unsafe { &*this_arg.inner }.payment_hash();
1585 /// Get the payee's public key if one was included in the invoice
1588 pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1589 let mut ret = unsafe { &*this_arg.inner }.payee_pub_key();
1590 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
1594 /// Get the payment secret if one was included in the invoice
1597 pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> crate::c_types::ThirtyTwoBytes {
1598 let mut ret = unsafe { &*this_arg.inner }.payment_secret();
1599 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1603 /// Get the invoice features if they were included in the invoice
1606 pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
1607 let mut ret = unsafe { &*this_arg.inner }.features();
1608 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 };
1612 /// Recover the payee's public key (only to be used if none was included in the invoice)
1615 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1616 let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key();
1617 crate::c_types::PublicKey::from_rust(&ret)
1620 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
1623 pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 {
1624 let mut ret = unsafe { &*this_arg.inner }.expiry_time();
1628 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
1629 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
1632 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 {
1633 let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry();
1637 /// Returns a list of all routes included in the invoice
1640 pub extern "C" fn Invoice_private_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1641 let mut ret = unsafe { &*this_arg.inner }.private_routes();
1642 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 } }); };
1646 /// Returns a list of all routes included in the invoice as the underlying hints
1649 pub extern "C" fn Invoice_route_hints(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
1650 let mut ret = unsafe { &*this_arg.inner }.route_hints();
1651 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 } }); };
1655 /// Returns the currency for which the invoice was issued
1658 pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoice::Currency {
1659 let mut ret = unsafe { &*this_arg.inner }.currency();
1660 crate::lightning_invoice::Currency::native_into(ret)
1663 /// Returns the amount if specified in the invoice as pico <currency>.
1666 pub extern "C" fn Invoice_amount_pico_btc(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z {
1667 let mut ret = unsafe { &*this_arg.inner }.amount_pico_btc();
1668 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()) } };
1672 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
1673 /// returns `CreationError::DescriptionTooLong` otherwise
1675 /// Please note that single characters may use more than one byte due to UTF8 encoding.
1678 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
1679 let mut ret = lightning_invoice::Description::new(description.into_string());
1680 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() };
1684 /// Returns the underlying description `String`
1687 pub extern "C" fn Description_into_inner(mut this_arg: Description) -> crate::c_types::Str {
1688 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1692 /// Construct an `ExpiryTime` from seconds. If there exists a `PositiveTimestamp` which would
1693 /// overflow on adding the `EpiryTime` to it then this function will return a
1694 /// `CreationError::ExpiryTimeOutOfBounds`.
1697 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1698 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
1699 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() };
1703 /// Construct an `ExpiryTime` from a `Duration`. If there exists a `PositiveTimestamp` which
1704 /// would overflow on adding the `EpiryTime` to it then this function will return a
1705 /// `CreationError::ExpiryTimeOutOfBounds`.
1708 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1709 let mut ret = lightning_invoice::ExpiryTime::from_duration(std::time::Duration::from_secs(duration));
1710 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() };
1714 /// Returns the expiry time in seconds
1717 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 {
1718 let mut ret = unsafe { &*this_arg.inner }.as_seconds();
1722 /// Returns a reference to the underlying `Duration` (=expiry time)
1725 pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 {
1726 let mut ret = unsafe { &*this_arg.inner }.as_duration();
1730 /// Creates a new (partial) route from a list of hops
1733 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
1734 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
1735 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() };
1739 /// Returns the underlying list of hops
1742 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: PrivateRoute) -> crate::lightning::routing::router::RouteHint {
1743 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1744 crate::lightning::routing::router::RouteHint { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1747 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
1751 pub enum CreationError {
1752 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
1754 /// The specified route has too many hops and can't be encoded
1756 /// The unix timestamp of the supplied date is <0 or can't be represented as `SystemTime`
1757 TimestampOutOfBounds,
1758 /// The supplied expiry time could cause an overflow if added to a `PositiveTimestamp`
1759 ExpiryTimeOutOfBounds,
1761 use lightning_invoice::CreationError as nativeCreationError;
1762 impl CreationError {
1764 pub(crate) fn to_native(&self) -> nativeCreationError {
1766 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
1767 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
1768 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
1769 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
1773 pub(crate) fn into_native(self) -> nativeCreationError {
1775 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
1776 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
1777 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
1778 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
1782 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
1784 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
1785 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
1786 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
1787 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
1791 pub(crate) fn native_into(native: nativeCreationError) -> Self {
1793 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
1794 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
1795 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
1796 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
1800 /// Creates a copy of the CreationError
1802 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
1805 /// Checks if two CreationErrors contain equal inner contents.
1806 /// This ignores pointers and is_owned flags and looks at the values in fields.
1808 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
1809 if &a.to_native() == &b.to_native() { true } else { false }
1812 /// Get the string representation of a CreationError object
1813 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
1814 format!("{}", &o.to_native()).into()
1816 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
1817 /// requirements sections in BOLT #11
1821 pub enum SemanticError {
1822 /// The invoice is missing the mandatory payment hash
1824 /// The invoice has multiple payment hashes which isn't allowed
1825 MultiplePaymentHashes,
1826 /// No description or description hash are part of the invoice
1828 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
1829 MultipleDescriptions,
1830 /// The invoice contains multiple payment secrets
1831 MultiplePaymentSecrets,
1832 /// The invoice's features are invalid
1834 /// The recovery id doesn't fit the signature/pub key
1836 /// The invoice's signature is invalid
1839 use lightning_invoice::SemanticError as nativeSemanticError;
1840 impl SemanticError {
1842 pub(crate) fn to_native(&self) -> nativeSemanticError {
1844 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
1845 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
1846 SemanticError::NoDescription => nativeSemanticError::NoDescription,
1847 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
1848 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
1849 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
1850 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
1851 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
1855 pub(crate) fn into_native(self) -> nativeSemanticError {
1857 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
1858 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
1859 SemanticError::NoDescription => nativeSemanticError::NoDescription,
1860 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
1861 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
1862 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
1863 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
1864 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
1868 pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
1870 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
1871 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
1872 nativeSemanticError::NoDescription => SemanticError::NoDescription,
1873 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
1874 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
1875 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
1876 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
1877 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
1881 pub(crate) fn native_into(native: nativeSemanticError) -> Self {
1883 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
1884 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
1885 nativeSemanticError::NoDescription => SemanticError::NoDescription,
1886 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
1887 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
1888 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
1889 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
1890 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
1894 /// Creates a copy of the SemanticError
1896 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
1899 /// Checks if two SemanticErrors contain equal inner contents.
1900 /// This ignores pointers and is_owned flags and looks at the values in fields.
1902 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
1903 if &a.to_native() == &b.to_native() { true } else { false }
1906 /// Get the string representation of a SemanticError object
1907 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
1908 format!("{}", &o.to_native()).into()
1910 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
1915 pub enum SignOrCreationError {
1916 /// An error occurred during signing
1918 /// An error occurred while building the transaction
1919 CreationError(crate::lightning_invoice::CreationError),
1921 use lightning_invoice::SignOrCreationError as nativeSignOrCreationError;
1922 impl SignOrCreationError {
1924 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
1926 SignOrCreationError::SignError => {
1927 nativeSignOrCreationError::SignError (
1931 SignOrCreationError::CreationError (ref a, ) => {
1932 let mut a_nonref = (*a).clone();
1933 nativeSignOrCreationError::CreationError (
1934 a_nonref.into_native(),
1940 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
1942 SignOrCreationError::SignError => {
1943 nativeSignOrCreationError::SignError (
1947 SignOrCreationError::CreationError (mut a, ) => {
1948 nativeSignOrCreationError::CreationError (
1955 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
1957 nativeSignOrCreationError::SignError (ref a, ) => {
1958 SignOrCreationError::SignError },
1959 nativeSignOrCreationError::CreationError (ref a, ) => {
1960 let mut a_nonref = (*a).clone();
1961 SignOrCreationError::CreationError (
1962 crate::lightning_invoice::CreationError::native_into(a_nonref),
1968 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
1970 nativeSignOrCreationError::SignError (mut a, ) => {
1971 SignOrCreationError::SignError },
1972 nativeSignOrCreationError::CreationError (mut a, ) => {
1973 SignOrCreationError::CreationError (
1974 crate::lightning_invoice::CreationError::native_into(a),
1980 /// Frees any resources used by the SignOrCreationError
1982 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
1983 /// Creates a copy of the SignOrCreationError
1985 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
1988 /// Checks if two SignOrCreationErrors contain equal inner contents.
1989 /// This ignores pointers and is_owned flags and looks at the values in fields.
1991 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
1992 if &a.to_native() == &b.to_native() { true } else { false }
1995 /// Get the string representation of a SignOrCreationError object
1996 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
1997 format!("{}", &o.to_native()).into()