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 /// **Call this function on startup to ensure that all assumptions about the platform are valid.**
115 /// Unfortunately we have to make assumptions about the upper bounds of the `SystemTime` type on
116 /// your platform which we can't fully verify at compile time and which isn't part of it's contract.
117 /// To our best knowledge our assumptions hold for all platforms officially supported by rust, but
118 /// since this check is fast we recommend to do it anyway.
120 /// If this function fails this is considered a bug. Please open an issue describing your
121 /// platform and stating your current system time.
124 /// If the check fails this function panics. By calling this function on startup you ensure that
125 /// this wont happen at an arbitrary later point in time.
127 pub extern "C" fn check_platform() {
128 lightning_invoice::check_platform()
132 use lightning_invoice::Invoice as nativeInvoiceImport;
133 type nativeInvoice = nativeInvoiceImport;
135 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
137 /// There are three ways to construct an `Invoice`:
138 /// 1. using `InvoiceBuilder`
139 /// 2. using `Invoice::from_signed(SignedRawInvoice)`
140 /// 3. using `str::parse::<Invoice>(&str)`
144 /// A pointer to the opaque Rust object.
146 /// Nearly everywhere, inner must be non-null, however in places where
147 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
148 pub inner: *mut nativeInvoice,
149 /// Indicates that this is the only struct which contains the same pointer.
151 /// Rust functions which take ownership of an object provided via an argument require
152 /// this to be true and invalidate the object pointed to by inner.
156 impl Drop for Invoice {
158 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
159 let _ = unsafe { Box::from_raw(self.inner) };
163 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
165 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
167 /// Used only if an object of this type is returned as a trait impl by a method
168 extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
169 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
172 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
174 pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
175 assert!(self.is_owned);
176 let ret = self.inner;
177 self.inner = std::ptr::null_mut();
181 /// Checks if two Invoices contain equal inner contents.
182 /// This ignores pointers and is_owned flags and looks at the values in fields.
183 /// Two objects with NULL inner values will be considered "equal" here.
185 pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool {
186 if a.inner == b.inner { return true; }
187 if a.inner.is_null() || b.inner.is_null() { return false; }
188 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
190 impl Clone for Invoice {
191 fn clone(&self) -> Self {
193 inner: if <*mut nativeInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
194 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
200 /// Used only if an object of this type is returned as a trait impl by a method
201 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
202 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
205 /// Creates a copy of the Invoice
206 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
210 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
211 type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
213 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
217 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
220 pub struct SignedRawInvoice {
221 /// A pointer to the opaque Rust object.
223 /// Nearly everywhere, inner must be non-null, however in places where
224 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
225 pub inner: *mut nativeSignedRawInvoice,
226 /// Indicates that this is the only struct which contains the same pointer.
228 /// Rust functions which take ownership of an object provided via an argument require
229 /// this to be true and invalidate the object pointed to by inner.
233 impl Drop for SignedRawInvoice {
235 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
236 let _ = unsafe { Box::from_raw(self.inner) };
240 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
242 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
244 /// Used only if an object of this type is returned as a trait impl by a method
245 extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
246 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
249 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
250 impl SignedRawInvoice {
251 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
252 assert!(self.is_owned);
253 let ret = self.inner;
254 self.inner = std::ptr::null_mut();
258 /// Checks if two SignedRawInvoices contain equal inner contents.
259 /// This ignores pointers and is_owned flags and looks at the values in fields.
260 /// Two objects with NULL inner values will be considered "equal" here.
262 pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice) -> bool {
263 if a.inner == b.inner { return true; }
264 if a.inner.is_null() || b.inner.is_null() { return false; }
265 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
267 impl Clone for SignedRawInvoice {
268 fn clone(&self) -> Self {
270 inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
271 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
277 /// Used only if an object of this type is returned as a trait impl by a method
278 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
279 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
282 /// Creates a copy of the SignedRawInvoice
283 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
287 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
288 type nativeRawInvoice = nativeRawInvoiceImport;
290 /// Represents an syntactically correct Invoice for a payment on the lightning network,
291 /// but without the signature information.
292 /// De- and encoding should not lead to information loss but may lead to different hashes.
294 /// For methods without docs see the corresponding methods in `Invoice`.
297 pub struct RawInvoice {
298 /// A pointer to the opaque Rust object.
300 /// Nearly everywhere, inner must be non-null, however in places where
301 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
302 pub inner: *mut nativeRawInvoice,
303 /// Indicates that this is the only struct which contains the same pointer.
305 /// Rust functions which take ownership of an object provided via an argument require
306 /// this to be true and invalidate the object pointed to by inner.
310 impl Drop for RawInvoice {
312 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
313 let _ = unsafe { Box::from_raw(self.inner) };
317 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
319 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
321 /// Used only if an object of this type is returned as a trait impl by a method
322 extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
323 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
326 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
328 pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
329 assert!(self.is_owned);
330 let ret = self.inner;
331 self.inner = std::ptr::null_mut();
337 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
338 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.data;
339 crate::lightning_invoice::RawDataPart { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
343 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
344 unsafe { &mut *this_ptr.inner }.data = *unsafe { Box::from_raw(val.take_inner()) };
346 /// Checks if two RawInvoices contain equal inner contents.
347 /// This ignores pointers and is_owned flags and looks at the values in fields.
348 /// Two objects with NULL inner values will be considered "equal" here.
350 pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool {
351 if a.inner == b.inner { return true; }
352 if a.inner.is_null() || b.inner.is_null() { return false; }
353 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
355 impl Clone for RawInvoice {
356 fn clone(&self) -> Self {
358 inner: if <*mut nativeRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
359 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
365 /// Used only if an object of this type is returned as a trait impl by a method
366 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
367 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
370 /// Creates a copy of the RawInvoice
371 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
375 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
376 type nativeRawDataPart = nativeRawDataPartImport;
378 /// Data of the `RawInvoice` that is encoded in the data part
381 pub struct RawDataPart {
382 /// A pointer to the opaque Rust object.
384 /// Nearly everywhere, inner must be non-null, however in places where
385 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
386 pub inner: *mut nativeRawDataPart,
387 /// Indicates that this is the only struct which contains the same pointer.
389 /// Rust functions which take ownership of an object provided via an argument require
390 /// this to be true and invalidate the object pointed to by inner.
394 impl Drop for RawDataPart {
396 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
397 let _ = unsafe { Box::from_raw(self.inner) };
401 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
403 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
405 /// Used only if an object of this type is returned as a trait impl by a method
406 extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
407 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
410 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
412 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
413 assert!(self.is_owned);
414 let ret = self.inner;
415 self.inner = std::ptr::null_mut();
419 /// generation time of the invoice
421 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
422 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.timestamp;
423 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
425 /// generation time of the invoice
427 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
428 unsafe { &mut *this_ptr.inner }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
430 /// Checks if two RawDataParts contain equal inner contents.
431 /// This ignores pointers and is_owned flags and looks at the values in fields.
432 /// Two objects with NULL inner values will be considered "equal" here.
434 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
435 if a.inner == b.inner { return true; }
436 if a.inner.is_null() || b.inner.is_null() { return false; }
437 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
439 impl Clone for RawDataPart {
440 fn clone(&self) -> Self {
442 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { std::ptr::null_mut() } else {
443 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
449 /// Used only if an object of this type is returned as a trait impl by a method
450 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
451 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
454 /// Creates a copy of the RawDataPart
455 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
459 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
460 type nativePositiveTimestamp = nativePositiveTimestampImport;
462 /// A timestamp that refers to a date after 1 January 1970 which means its representation as UNIX
463 /// timestamp is positive.
466 /// The UNIX timestamp representing the stored time has to be positive and small enough so that
467 /// a `EpiryTime` can be added to it without an overflow.
470 pub struct PositiveTimestamp {
471 /// A pointer to the opaque Rust object.
473 /// Nearly everywhere, inner must be non-null, however in places where
474 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
475 pub inner: *mut nativePositiveTimestamp,
476 /// Indicates that this is the only struct which contains the same pointer.
478 /// Rust functions which take ownership of an object provided via an argument require
479 /// this to be true and invalidate the object pointed to by inner.
483 impl Drop for PositiveTimestamp {
485 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
486 let _ = unsafe { Box::from_raw(self.inner) };
490 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
492 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
494 /// Used only if an object of this type is returned as a trait impl by a method
495 extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
496 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
499 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
500 impl PositiveTimestamp {
501 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
502 assert!(self.is_owned);
503 let ret = self.inner;
504 self.inner = std::ptr::null_mut();
508 /// Checks if two PositiveTimestamps contain equal inner contents.
509 /// This ignores pointers and is_owned flags and looks at the values in fields.
510 /// Two objects with NULL inner values will be considered "equal" here.
512 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
513 if a.inner == b.inner { return true; }
514 if a.inner.is_null() || b.inner.is_null() { return false; }
515 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
517 impl Clone for PositiveTimestamp {
518 fn clone(&self) -> Self {
520 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { std::ptr::null_mut() } else {
521 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
527 /// Used only if an object of this type is returned as a trait impl by a method
528 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
529 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
532 /// Creates a copy of the PositiveTimestamp
533 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
536 /// SI prefixes for the human readable part
550 use lightning_invoice::SiPrefix as nativeSiPrefix;
553 pub(crate) fn to_native(&self) -> nativeSiPrefix {
555 SiPrefix::Milli => nativeSiPrefix::Milli,
556 SiPrefix::Micro => nativeSiPrefix::Micro,
557 SiPrefix::Nano => nativeSiPrefix::Nano,
558 SiPrefix::Pico => nativeSiPrefix::Pico,
562 pub(crate) fn into_native(self) -> nativeSiPrefix {
564 SiPrefix::Milli => nativeSiPrefix::Milli,
565 SiPrefix::Micro => nativeSiPrefix::Micro,
566 SiPrefix::Nano => nativeSiPrefix::Nano,
567 SiPrefix::Pico => nativeSiPrefix::Pico,
571 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
573 nativeSiPrefix::Milli => SiPrefix::Milli,
574 nativeSiPrefix::Micro => SiPrefix::Micro,
575 nativeSiPrefix::Nano => SiPrefix::Nano,
576 nativeSiPrefix::Pico => SiPrefix::Pico,
580 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
582 nativeSiPrefix::Milli => SiPrefix::Milli,
583 nativeSiPrefix::Micro => SiPrefix::Micro,
584 nativeSiPrefix::Nano => SiPrefix::Nano,
585 nativeSiPrefix::Pico => SiPrefix::Pico,
589 /// Creates a copy of the SiPrefix
591 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
594 /// Checks if two SiPrefixs contain equal inner contents.
595 /// This ignores pointers and is_owned flags and looks at the values in fields.
597 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
598 if &a.to_native() == &b.to_native() { true } else { false }
600 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
601 /// This is effectively 10^12 * the prefix multiplier
604 pub extern "C" fn SiPrefix_multiplier(this_arg: &SiPrefix) -> u64 {
605 let mut ret = this_arg.to_native().multiplier();
609 /// Enum representing the crypto currencies (or networks) supported by this library
625 use lightning_invoice::Currency as nativeCurrency;
628 pub(crate) fn to_native(&self) -> nativeCurrency {
630 Currency::Bitcoin => nativeCurrency::Bitcoin,
631 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
632 Currency::Regtest => nativeCurrency::Regtest,
633 Currency::Simnet => nativeCurrency::Simnet,
634 Currency::Signet => nativeCurrency::Signet,
638 pub(crate) fn into_native(self) -> nativeCurrency {
640 Currency::Bitcoin => nativeCurrency::Bitcoin,
641 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
642 Currency::Regtest => nativeCurrency::Regtest,
643 Currency::Simnet => nativeCurrency::Simnet,
644 Currency::Signet => nativeCurrency::Signet,
648 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
650 nativeCurrency::Bitcoin => Currency::Bitcoin,
651 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
652 nativeCurrency::Regtest => Currency::Regtest,
653 nativeCurrency::Simnet => Currency::Simnet,
654 nativeCurrency::Signet => Currency::Signet,
658 pub(crate) fn native_into(native: nativeCurrency) -> Self {
660 nativeCurrency::Bitcoin => Currency::Bitcoin,
661 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
662 nativeCurrency::Regtest => Currency::Regtest,
663 nativeCurrency::Simnet => Currency::Simnet,
664 nativeCurrency::Signet => Currency::Signet,
668 /// Creates a copy of the Currency
670 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
673 /// Checks if two Currencys contain equal inner contents.
674 /// This ignores pointers and is_owned flags and looks at the values in fields.
676 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
677 if &a.to_native() == &b.to_native() { true } else { false }
680 use lightning_invoice::Sha256 as nativeSha256Import;
681 type nativeSha256 = nativeSha256Import;
687 /// A pointer to the opaque Rust object.
689 /// Nearly everywhere, inner must be non-null, however in places where
690 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
691 pub inner: *mut nativeSha256,
692 /// Indicates that this is the only struct which contains the same pointer.
694 /// Rust functions which take ownership of an object provided via an argument require
695 /// this to be true and invalidate the object pointed to by inner.
699 impl Drop for Sha256 {
701 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
702 let _ = unsafe { Box::from_raw(self.inner) };
706 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
708 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
710 /// Used only if an object of this type is returned as a trait impl by a method
711 extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
712 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
715 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
717 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
718 assert!(self.is_owned);
719 let ret = self.inner;
720 self.inner = std::ptr::null_mut();
724 /// Checks if two Sha256s contain equal inner contents.
725 /// This ignores pointers and is_owned flags and looks at the values in fields.
726 /// Two objects with NULL inner values will be considered "equal" here.
728 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
729 if a.inner == b.inner { return true; }
730 if a.inner.is_null() || b.inner.is_null() { return false; }
731 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
733 impl Clone for Sha256 {
734 fn clone(&self) -> Self {
736 inner: if <*mut nativeSha256>::is_null(self.inner) { std::ptr::null_mut() } else {
737 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
743 /// Used only if an object of this type is returned as a trait impl by a method
744 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
745 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
748 /// Creates a copy of the Sha256
749 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
753 use lightning_invoice::Description as nativeDescriptionImport;
754 type nativeDescription = nativeDescriptionImport;
756 /// Description string
759 /// The description can be at most 639 __bytes__ long
762 pub struct Description {
763 /// A pointer to the opaque Rust object.
765 /// Nearly everywhere, inner must be non-null, however in places where
766 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
767 pub inner: *mut nativeDescription,
768 /// Indicates that this is the only struct which contains the same pointer.
770 /// Rust functions which take ownership of an object provided via an argument require
771 /// this to be true and invalidate the object pointed to by inner.
775 impl Drop for Description {
777 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
778 let _ = unsafe { Box::from_raw(self.inner) };
782 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
784 pub extern "C" fn Description_free(this_obj: Description) { }
786 /// Used only if an object of this type is returned as a trait impl by a method
787 extern "C" fn Description_free_void(this_ptr: *mut c_void) {
788 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
791 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
793 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
794 assert!(self.is_owned);
795 let ret = self.inner;
796 self.inner = std::ptr::null_mut();
800 /// Checks if two Descriptions contain equal inner contents.
801 /// This ignores pointers and is_owned flags and looks at the values in fields.
802 /// Two objects with NULL inner values will be considered "equal" here.
804 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
805 if a.inner == b.inner { return true; }
806 if a.inner.is_null() || b.inner.is_null() { return false; }
807 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
809 impl Clone for Description {
810 fn clone(&self) -> Self {
812 inner: if <*mut nativeDescription>::is_null(self.inner) { std::ptr::null_mut() } else {
813 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
819 /// Used only if an object of this type is returned as a trait impl by a method
820 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
821 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
824 /// Creates a copy of the Description
825 pub extern "C" fn Description_clone(orig: &Description) -> Description {
829 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
830 type nativePayeePubKey = nativePayeePubKeyImport;
835 pub struct PayeePubKey {
836 /// A pointer to the opaque Rust object.
838 /// Nearly everywhere, inner must be non-null, however in places where
839 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
840 pub inner: *mut nativePayeePubKey,
841 /// Indicates that this is the only struct which contains the same pointer.
843 /// Rust functions which take ownership of an object provided via an argument require
844 /// this to be true and invalidate the object pointed to by inner.
848 impl Drop for PayeePubKey {
850 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
851 let _ = unsafe { Box::from_raw(self.inner) };
855 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
857 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
859 /// Used only if an object of this type is returned as a trait impl by a method
860 extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
861 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
864 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
866 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
867 assert!(self.is_owned);
868 let ret = self.inner;
869 self.inner = std::ptr::null_mut();
873 /// Checks if two PayeePubKeys contain equal inner contents.
874 /// This ignores pointers and is_owned flags and looks at the values in fields.
875 /// Two objects with NULL inner values will be considered "equal" here.
877 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
878 if a.inner == b.inner { return true; }
879 if a.inner.is_null() || b.inner.is_null() { return false; }
880 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
882 impl Clone for PayeePubKey {
883 fn clone(&self) -> Self {
885 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { std::ptr::null_mut() } else {
886 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
892 /// Used only if an object of this type is returned as a trait impl by a method
893 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
894 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
897 /// Creates a copy of the PayeePubKey
898 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
902 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
903 type nativeExpiryTime = nativeExpiryTimeImport;
905 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
909 /// The number of seconds this expiry time represents has to be in the range
910 /// `0...(SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME)` to avoid overflows when adding it to a
914 pub struct ExpiryTime {
915 /// A pointer to the opaque Rust object.
917 /// Nearly everywhere, inner must be non-null, however in places where
918 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
919 pub inner: *mut nativeExpiryTime,
920 /// Indicates that this is the only struct which contains the same pointer.
922 /// Rust functions which take ownership of an object provided via an argument require
923 /// this to be true and invalidate the object pointed to by inner.
927 impl Drop for ExpiryTime {
929 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
930 let _ = unsafe { Box::from_raw(self.inner) };
934 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
936 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
938 /// Used only if an object of this type is returned as a trait impl by a method
939 extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
940 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
943 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
945 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
946 assert!(self.is_owned);
947 let ret = self.inner;
948 self.inner = std::ptr::null_mut();
952 /// Checks if two ExpiryTimes contain equal inner contents.
953 /// This ignores pointers and is_owned flags and looks at the values in fields.
954 /// Two objects with NULL inner values will be considered "equal" here.
956 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
957 if a.inner == b.inner { return true; }
958 if a.inner.is_null() || b.inner.is_null() { return false; }
959 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
961 impl Clone for ExpiryTime {
962 fn clone(&self) -> Self {
964 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { std::ptr::null_mut() } else {
965 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
971 /// Used only if an object of this type is returned as a trait impl by a method
972 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
973 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
976 /// Creates a copy of the ExpiryTime
977 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
981 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
982 type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
984 /// `min_final_cltv_expiry` to use for the last HTLC in the route
987 pub struct MinFinalCltvExpiry {
988 /// A pointer to the opaque Rust object.
990 /// Nearly everywhere, inner must be non-null, however in places where
991 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
992 pub inner: *mut nativeMinFinalCltvExpiry,
993 /// Indicates that this is the only struct which contains the same pointer.
995 /// Rust functions which take ownership of an object provided via an argument require
996 /// this to be true and invalidate the object pointed to by inner.
1000 impl Drop for MinFinalCltvExpiry {
1001 fn drop(&mut self) {
1002 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
1003 let _ = unsafe { Box::from_raw(self.inner) };
1007 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1009 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1011 /// Used only if an object of this type is returned as a trait impl by a method
1012 extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1013 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1016 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1017 impl MinFinalCltvExpiry {
1018 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1019 assert!(self.is_owned);
1020 let ret = self.inner;
1021 self.inner = std::ptr::null_mut();
1025 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1026 /// This ignores pointers and is_owned flags and looks at the values in fields.
1027 /// Two objects with NULL inner values will be considered "equal" here.
1029 pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool {
1030 if a.inner == b.inner { return true; }
1031 if a.inner.is_null() || b.inner.is_null() { return false; }
1032 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1034 impl Clone for MinFinalCltvExpiry {
1035 fn clone(&self) -> Self {
1037 inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { std::ptr::null_mut() } else {
1038 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1044 /// Used only if an object of this type is returned as a trait impl by a method
1045 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1046 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1049 /// Creates a copy of the MinFinalCltvExpiry
1050 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1053 /// Fallback address in case no LN payment is possible
1059 version: crate::c_types::u5,
1060 program: crate::c_types::derived::CVec_u8Z,
1062 PubKeyHash(crate::c_types::TwentyBytes),
1063 ScriptHash(crate::c_types::TwentyBytes),
1065 use lightning_invoice::Fallback as nativeFallback;
1068 pub(crate) fn to_native(&self) -> nativeFallback {
1070 Fallback::SegWitProgram {ref version, ref program, } => {
1071 let mut version_nonref = (*version).clone();
1072 let mut program_nonref = (*program).clone();
1073 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1074 nativeFallback::SegWitProgram {
1075 version: version_nonref.into(),
1076 program: local_program_nonref,
1079 Fallback::PubKeyHash (ref a, ) => {
1080 let mut a_nonref = (*a).clone();
1081 nativeFallback::PubKeyHash (
1085 Fallback::ScriptHash (ref a, ) => {
1086 let mut a_nonref = (*a).clone();
1087 nativeFallback::ScriptHash (
1094 pub(crate) fn into_native(self) -> nativeFallback {
1096 Fallback::SegWitProgram {mut version, mut program, } => {
1097 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1098 nativeFallback::SegWitProgram {
1099 version: version.into(),
1100 program: local_program,
1103 Fallback::PubKeyHash (mut a, ) => {
1104 nativeFallback::PubKeyHash (
1108 Fallback::ScriptHash (mut a, ) => {
1109 nativeFallback::ScriptHash (
1116 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1118 nativeFallback::SegWitProgram {ref version, ref program, } => {
1119 let mut version_nonref = (*version).clone();
1120 let mut program_nonref = (*program).clone();
1121 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1122 Fallback::SegWitProgram {
1123 version: version_nonref.into(),
1124 program: local_program_nonref.into(),
1127 nativeFallback::PubKeyHash (ref a, ) => {
1128 let mut a_nonref = (*a).clone();
1129 Fallback::PubKeyHash (
1130 crate::c_types::TwentyBytes { data: a_nonref },
1133 nativeFallback::ScriptHash (ref a, ) => {
1134 let mut a_nonref = (*a).clone();
1135 Fallback::ScriptHash (
1136 crate::c_types::TwentyBytes { data: a_nonref },
1142 pub(crate) fn native_into(native: nativeFallback) -> Self {
1144 nativeFallback::SegWitProgram {mut version, mut program, } => {
1145 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1146 Fallback::SegWitProgram {
1147 version: version.into(),
1148 program: local_program.into(),
1151 nativeFallback::PubKeyHash (mut a, ) => {
1152 Fallback::PubKeyHash (
1153 crate::c_types::TwentyBytes { data: a },
1156 nativeFallback::ScriptHash (mut a, ) => {
1157 Fallback::ScriptHash (
1158 crate::c_types::TwentyBytes { data: a },
1164 /// Frees any resources used by the Fallback
1166 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1167 /// Creates a copy of the Fallback
1169 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1172 /// Checks if two Fallbacks contain equal inner contents.
1173 /// This ignores pointers and is_owned flags and looks at the values in fields.
1175 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1176 if &a.to_native() == &b.to_native() { true } else { false }
1179 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1180 type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1182 /// Recoverable signature
1185 pub struct InvoiceSignature {
1186 /// A pointer to the opaque Rust object.
1188 /// Nearly everywhere, inner must be non-null, however in places where
1189 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1190 pub inner: *mut nativeInvoiceSignature,
1191 /// Indicates that this is the only struct which contains the same pointer.
1193 /// Rust functions which take ownership of an object provided via an argument require
1194 /// this to be true and invalidate the object pointed to by inner.
1198 impl Drop for InvoiceSignature {
1199 fn drop(&mut self) {
1200 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1201 let _ = unsafe { Box::from_raw(self.inner) };
1205 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1207 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1209 /// Used only if an object of this type is returned as a trait impl by a method
1210 extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1211 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1214 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1215 impl InvoiceSignature {
1216 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1217 assert!(self.is_owned);
1218 let ret = self.inner;
1219 self.inner = std::ptr::null_mut();
1223 /// Checks if two InvoiceSignatures contain equal inner contents.
1224 /// This ignores pointers and is_owned flags and looks at the values in fields.
1225 /// Two objects with NULL inner values will be considered "equal" here.
1227 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
1228 if a.inner == b.inner { return true; }
1229 if a.inner.is_null() || b.inner.is_null() { return false; }
1230 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1232 impl Clone for InvoiceSignature {
1233 fn clone(&self) -> Self {
1235 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { std::ptr::null_mut() } else {
1236 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1242 /// Used only if an object of this type is returned as a trait impl by a method
1243 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
1244 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
1247 /// Creates a copy of the InvoiceSignature
1248 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
1252 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
1253 type nativePrivateRoute = nativePrivateRouteImport;
1255 /// Private routing information
1258 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
1262 pub struct PrivateRoute {
1263 /// A pointer to the opaque Rust object.
1265 /// Nearly everywhere, inner must be non-null, however in places where
1266 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1267 pub inner: *mut nativePrivateRoute,
1268 /// Indicates that this is the only struct which contains the same pointer.
1270 /// Rust functions which take ownership of an object provided via an argument require
1271 /// this to be true and invalidate the object pointed to by inner.
1275 impl Drop for PrivateRoute {
1276 fn drop(&mut self) {
1277 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
1278 let _ = unsafe { Box::from_raw(self.inner) };
1282 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
1284 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
1286 /// Used only if an object of this type is returned as a trait impl by a method
1287 extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
1288 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); }
1291 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1293 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
1294 assert!(self.is_owned);
1295 let ret = self.inner;
1296 self.inner = std::ptr::null_mut();
1300 /// Checks if two PrivateRoutes contain equal inner contents.
1301 /// This ignores pointers and is_owned flags and looks at the values in fields.
1302 /// Two objects with NULL inner values will be considered "equal" here.
1304 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
1305 if a.inner == b.inner { return true; }
1306 if a.inner.is_null() || b.inner.is_null() { return false; }
1307 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1309 impl Clone for PrivateRoute {
1310 fn clone(&self) -> Self {
1312 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { std::ptr::null_mut() } else {
1313 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1319 /// Used only if an object of this type is returned as a trait impl by a method
1320 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
1321 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
1324 /// Creates a copy of the PrivateRoute
1325 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
1328 /// Disassembles the `SignedRawInvoice` into its three parts:
1330 /// 2. hash of the raw invoice
1334 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
1335 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
1336 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();
1340 /// The `RawInvoice` which was signed.
1343 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
1344 let mut ret = unsafe { &*this_arg.inner }.raw_invoice();
1345 crate::lightning_invoice::RawInvoice { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1348 /// The hash of the `RawInvoice` that was signed.
1351 pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [u8; 32] {
1352 let mut ret = unsafe { &*this_arg.inner }.hash();
1356 /// InvoiceSignature for the invoice.
1359 pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
1360 let mut ret = unsafe { &*this_arg.inner }.signature();
1361 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1364 /// Recovers the public key used for signing the invoice from the recoverable signature.
1367 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
1368 let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key();
1369 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() };
1373 /// Checks if the signature is valid for the included payee public key or if none exists if it's
1374 /// valid for the recovered signature (which should always be true?).
1377 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &SignedRawInvoice) -> bool {
1378 let mut ret = unsafe { &*this_arg.inner }.check_signature();
1382 /// Calculate the hash of the encoded `RawInvoice`
1385 pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1386 let mut ret = unsafe { &*this_arg.inner }.hash();
1387 crate::c_types::ThirtyTwoBytes { data: ret }
1392 pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1393 let mut ret = unsafe { &*this_arg.inner }.payment_hash();
1394 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 };
1400 pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightning_invoice::Description {
1401 let mut ret = unsafe { &*this_arg.inner }.description();
1402 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 };
1408 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::lightning_invoice::PayeePubKey {
1409 let mut ret = unsafe { &*this_arg.inner }.payee_pub_key();
1410 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 };
1416 pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1417 let mut ret = unsafe { &*this_arg.inner }.description_hash();
1418 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 };
1424 pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightning_invoice::ExpiryTime {
1425 let mut ret = unsafe { &*this_arg.inner }.expiry_time();
1426 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 };
1432 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
1433 let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry();
1434 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 };
1440 pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1441 let mut ret = unsafe { &*this_arg.inner }.payment_secret();
1442 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1448 pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
1449 let mut ret = unsafe { &*this_arg.inner }.features();
1450 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 };
1456 pub extern "C" fn RawInvoice_private_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1457 let mut ret = unsafe { &*this_arg.inner }.private_routes();
1458 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 } }); };
1464 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z {
1465 let mut ret = unsafe { &*this_arg.inner }.amount_pico_btc();
1466 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()) } };
1472 pub extern "C" fn RawInvoice_currency(this_arg: &RawInvoice) -> crate::lightning_invoice::Currency {
1473 let mut ret = unsafe { &*this_arg.inner }.currency();
1474 crate::lightning_invoice::Currency::native_into(ret)
1477 /// Create a new `PositiveTimestamp` from a unix timestamp in the Range
1478 /// `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1479 /// `CreationError::TimestampOutOfBounds`.
1482 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1483 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
1484 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() };
1488 /// Create a new `PositiveTimestamp` from a `SystemTime` with a corresponding unix timestamp in
1489 /// the Range `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1490 /// `CreationError::TimestampOutOfBounds`.
1493 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1494 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
1495 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() };
1499 /// Returns the UNIX timestamp representing the stored time
1502 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 {
1503 let mut ret = unsafe { &*this_arg.inner }.as_unix_timestamp();
1507 /// Returns a reference to the internal `SystemTime` time representation
1510 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &PositiveTimestamp) -> u64 {
1511 let mut ret = unsafe { &*this_arg.inner }.as_time();
1512 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1515 /// Transform the `Invoice` into it's unchecked version
1518 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::lightning_invoice::SignedRawInvoice {
1519 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
1520 crate::lightning_invoice::SignedRawInvoice { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1523 /// Check that the invoice is signed correctly and that key recovery works
1526 pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
1527 let mut ret = unsafe { &*this_arg.inner }.check_signature();
1528 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() };
1532 /// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
1534 /// use lightning_invoice::*;
1536 /// let invoice = \"lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdp\\
1537 /// \tl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d7\\
1538 /// \t3gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ec\\
1539 /// \tky03ylcqca784w\";
1541 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
1543 /// assert!(Invoice::from_signed(signed).is_ok());
1547 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
1548 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
1549 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() };
1553 /// Returns the `Invoice`'s timestamp (should equal it's creation time)
1556 pub extern "C" fn Invoice_timestamp(this_arg: &Invoice) -> u64 {
1557 let mut ret = unsafe { &*this_arg.inner }.timestamp();
1558 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1561 /// Returns the hash to which we will receive the preimage on completion of the payment
1564 pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] {
1565 let mut ret = unsafe { &*this_arg.inner }.payment_hash();
1569 /// Get the payee's public key if one was included in the invoice
1572 pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1573 let mut ret = unsafe { &*this_arg.inner }.payee_pub_key();
1574 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
1578 /// Get the payment secret if one was included in the invoice
1581 pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> crate::c_types::ThirtyTwoBytes {
1582 let mut ret = unsafe { &*this_arg.inner }.payment_secret();
1583 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1587 /// Get the invoice features if they were included in the invoice
1590 pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
1591 let mut ret = unsafe { &*this_arg.inner }.features();
1592 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 };
1596 /// Recover the payee's public key (only to be used if none was included in the invoice)
1599 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1600 let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key();
1601 crate::c_types::PublicKey::from_rust(&ret)
1604 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
1607 pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 {
1608 let mut ret = unsafe { &*this_arg.inner }.expiry_time();
1612 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
1613 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
1616 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 {
1617 let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry();
1621 /// Returns a list of all routes included in the invoice
1624 pub extern "C" fn Invoice_private_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1625 let mut ret = unsafe { &*this_arg.inner }.private_routes();
1626 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 } }); };
1630 /// Returns a list of all routes included in the invoice as the underlying hints
1633 pub extern "C" fn Invoice_route_hints(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
1634 let mut ret = unsafe { &*this_arg.inner }.route_hints();
1635 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 } }); };
1639 /// Returns the currency for which the invoice was issued
1642 pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoice::Currency {
1643 let mut ret = unsafe { &*this_arg.inner }.currency();
1644 crate::lightning_invoice::Currency::native_into(ret)
1647 /// Returns the amount if specified in the invoice as pico <currency>.
1650 pub extern "C" fn Invoice_amount_pico_btc(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z {
1651 let mut ret = unsafe { &*this_arg.inner }.amount_pico_btc();
1652 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()) } };
1656 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
1657 /// returns `CreationError::DescriptionTooLong` otherwise
1659 /// Please note that single characters may use more than one byte due to UTF8 encoding.
1662 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
1663 let mut ret = lightning_invoice::Description::new(description.into_string());
1664 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() };
1668 /// Returns the underlying description `String`
1671 pub extern "C" fn Description_into_inner(mut this_arg: Description) -> crate::c_types::Str {
1672 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1676 /// Construct an `ExpiryTime` from seconds. If there exists a `PositiveTimestamp` which would
1677 /// overflow on adding the `EpiryTime` to it then this function will return a
1678 /// `CreationError::ExpiryTimeOutOfBounds`.
1681 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1682 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
1683 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() };
1687 /// Construct an `ExpiryTime` from a `Duration`. If there exists a `PositiveTimestamp` which
1688 /// would overflow on adding the `EpiryTime` to it then this function will return a
1689 /// `CreationError::ExpiryTimeOutOfBounds`.
1692 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1693 let mut ret = lightning_invoice::ExpiryTime::from_duration(std::time::Duration::from_secs(duration));
1694 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() };
1698 /// Returns the expiry time in seconds
1701 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 {
1702 let mut ret = unsafe { &*this_arg.inner }.as_seconds();
1706 /// Returns a reference to the underlying `Duration` (=expiry time)
1709 pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 {
1710 let mut ret = unsafe { &*this_arg.inner }.as_duration();
1714 /// Creates a new (partial) route from a list of hops
1717 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
1718 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
1719 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() };
1723 /// Returns the underlying list of hops
1726 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: PrivateRoute) -> crate::lightning::routing::router::RouteHint {
1727 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1728 crate::lightning::routing::router::RouteHint { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1731 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
1735 pub enum CreationError {
1736 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
1738 /// The specified route has too many hops and can't be encoded
1740 /// The unix timestamp of the supplied date is <0 or can't be represented as `SystemTime`
1741 TimestampOutOfBounds,
1742 /// The supplied expiry time could cause an overflow if added to a `PositiveTimestamp`
1743 ExpiryTimeOutOfBounds,
1745 use lightning_invoice::CreationError as nativeCreationError;
1746 impl CreationError {
1748 pub(crate) fn to_native(&self) -> nativeCreationError {
1750 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
1751 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
1752 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
1753 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
1757 pub(crate) fn into_native(self) -> nativeCreationError {
1759 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
1760 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
1761 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
1762 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
1766 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
1768 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
1769 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
1770 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
1771 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
1775 pub(crate) fn native_into(native: nativeCreationError) -> Self {
1777 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
1778 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
1779 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
1780 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
1784 /// Creates a copy of the CreationError
1786 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
1789 /// Checks if two CreationErrors contain equal inner contents.
1790 /// This ignores pointers and is_owned flags and looks at the values in fields.
1792 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
1793 if &a.to_native() == &b.to_native() { true } else { false }
1796 /// Get the string representation of a CreationError object
1797 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
1798 format!("{}", &o.to_native()).into()
1800 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
1801 /// requirements sections in BOLT #11
1805 pub enum SemanticError {
1806 /// The invoice is missing the mandatory payment hash
1808 /// The invoice has multiple payment hashes which isn't allowed
1809 MultiplePaymentHashes,
1810 /// No description or description hash are part of the invoice
1812 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
1813 MultipleDescriptions,
1814 /// The invoice contains multiple payment secrets
1815 MultiplePaymentSecrets,
1816 /// The invoice's features are invalid
1818 /// The recovery id doesn't fit the signature/pub key
1820 /// The invoice's signature is invalid
1823 use lightning_invoice::SemanticError as nativeSemanticError;
1824 impl SemanticError {
1826 pub(crate) fn to_native(&self) -> nativeSemanticError {
1828 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
1829 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
1830 SemanticError::NoDescription => nativeSemanticError::NoDescription,
1831 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
1832 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
1833 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
1834 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
1835 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
1839 pub(crate) fn into_native(self) -> nativeSemanticError {
1841 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
1842 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
1843 SemanticError::NoDescription => nativeSemanticError::NoDescription,
1844 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
1845 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
1846 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
1847 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
1848 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
1852 pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
1854 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
1855 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
1856 nativeSemanticError::NoDescription => SemanticError::NoDescription,
1857 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
1858 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
1859 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
1860 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
1861 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
1865 pub(crate) fn native_into(native: nativeSemanticError) -> Self {
1867 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
1868 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
1869 nativeSemanticError::NoDescription => SemanticError::NoDescription,
1870 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
1871 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
1872 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
1873 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
1874 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
1878 /// Creates a copy of the SemanticError
1880 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
1883 /// Checks if two SemanticErrors contain equal inner contents.
1884 /// This ignores pointers and is_owned flags and looks at the values in fields.
1886 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
1887 if &a.to_native() == &b.to_native() { true } else { false }
1890 /// Get the string representation of a SemanticError object
1891 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
1892 format!("{}", &o.to_native()).into()
1894 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
1899 pub enum SignOrCreationError {
1900 /// An error occurred during signing
1902 /// An error occurred while building the transaction
1903 CreationError(crate::lightning_invoice::CreationError),
1905 use lightning_invoice::SignOrCreationError as nativeSignOrCreationError;
1906 impl SignOrCreationError {
1908 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
1910 SignOrCreationError::SignError => {
1911 nativeSignOrCreationError::SignError (
1915 SignOrCreationError::CreationError (ref a, ) => {
1916 let mut a_nonref = (*a).clone();
1917 nativeSignOrCreationError::CreationError (
1918 a_nonref.into_native(),
1924 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
1926 SignOrCreationError::SignError => {
1927 nativeSignOrCreationError::SignError (
1931 SignOrCreationError::CreationError (mut a, ) => {
1932 nativeSignOrCreationError::CreationError (
1939 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
1941 nativeSignOrCreationError::SignError (ref a, ) => {
1942 SignOrCreationError::SignError },
1943 nativeSignOrCreationError::CreationError (ref a, ) => {
1944 let mut a_nonref = (*a).clone();
1945 SignOrCreationError::CreationError (
1946 crate::lightning_invoice::CreationError::native_into(a_nonref),
1952 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
1954 nativeSignOrCreationError::SignError (mut a, ) => {
1955 SignOrCreationError::SignError },
1956 nativeSignOrCreationError::CreationError (mut a, ) => {
1957 SignOrCreationError::CreationError (
1958 crate::lightning_invoice::CreationError::native_into(a),
1964 /// Frees any resources used by the SignOrCreationError
1966 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
1967 /// Creates a copy of the SignOrCreationError
1969 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
1972 /// Checks if two SignOrCreationErrors contain equal inner contents.
1973 /// This ignores pointers and is_owned flags and looks at the values in fields.
1975 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
1976 if &a.to_native() == &b.to_native() { true } else { false }
1979 /// Get the string representation of a SignOrCreationError object
1980 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
1981 format!("{}", &o.to_native()).into()