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
620 /// Bitcoin simnet/signet
623 use lightning_invoice::Currency as nativeCurrency;
626 pub(crate) fn to_native(&self) -> nativeCurrency {
628 Currency::Bitcoin => nativeCurrency::Bitcoin,
629 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
630 Currency::Regtest => nativeCurrency::Regtest,
631 Currency::Simnet => nativeCurrency::Simnet,
635 pub(crate) fn into_native(self) -> nativeCurrency {
637 Currency::Bitcoin => nativeCurrency::Bitcoin,
638 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
639 Currency::Regtest => nativeCurrency::Regtest,
640 Currency::Simnet => nativeCurrency::Simnet,
644 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
646 nativeCurrency::Bitcoin => Currency::Bitcoin,
647 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
648 nativeCurrency::Regtest => Currency::Regtest,
649 nativeCurrency::Simnet => Currency::Simnet,
653 pub(crate) fn native_into(native: nativeCurrency) -> Self {
655 nativeCurrency::Bitcoin => Currency::Bitcoin,
656 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
657 nativeCurrency::Regtest => Currency::Regtest,
658 nativeCurrency::Simnet => Currency::Simnet,
662 /// Creates a copy of the Currency
664 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
667 /// Checks if two Currencys contain equal inner contents.
668 /// This ignores pointers and is_owned flags and looks at the values in fields.
670 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
671 if &a.to_native() == &b.to_native() { true } else { false }
674 use lightning_invoice::Sha256 as nativeSha256Import;
675 type nativeSha256 = nativeSha256Import;
681 /// A pointer to the opaque Rust object.
683 /// Nearly everywhere, inner must be non-null, however in places where
684 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
685 pub inner: *mut nativeSha256,
686 /// Indicates that this is the only struct which contains the same pointer.
688 /// Rust functions which take ownership of an object provided via an argument require
689 /// this to be true and invalidate the object pointed to by inner.
693 impl Drop for Sha256 {
695 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
696 let _ = unsafe { Box::from_raw(self.inner) };
700 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
702 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
704 /// Used only if an object of this type is returned as a trait impl by a method
705 extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
706 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
709 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
711 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
712 assert!(self.is_owned);
713 let ret = self.inner;
714 self.inner = std::ptr::null_mut();
718 /// Checks if two Sha256s contain equal inner contents.
719 /// This ignores pointers and is_owned flags and looks at the values in fields.
720 /// Two objects with NULL inner values will be considered "equal" here.
722 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
723 if a.inner == b.inner { return true; }
724 if a.inner.is_null() || b.inner.is_null() { return false; }
725 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
727 impl Clone for Sha256 {
728 fn clone(&self) -> Self {
730 inner: if <*mut nativeSha256>::is_null(self.inner) { std::ptr::null_mut() } else {
731 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
737 /// Used only if an object of this type is returned as a trait impl by a method
738 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
739 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
742 /// Creates a copy of the Sha256
743 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
747 use lightning_invoice::Description as nativeDescriptionImport;
748 type nativeDescription = nativeDescriptionImport;
750 /// Description string
753 /// The description can be at most 639 __bytes__ long
756 pub struct Description {
757 /// A pointer to the opaque Rust object.
759 /// Nearly everywhere, inner must be non-null, however in places where
760 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
761 pub inner: *mut nativeDescription,
762 /// Indicates that this is the only struct which contains the same pointer.
764 /// Rust functions which take ownership of an object provided via an argument require
765 /// this to be true and invalidate the object pointed to by inner.
769 impl Drop for Description {
771 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
772 let _ = unsafe { Box::from_raw(self.inner) };
776 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
778 pub extern "C" fn Description_free(this_obj: Description) { }
780 /// Used only if an object of this type is returned as a trait impl by a method
781 extern "C" fn Description_free_void(this_ptr: *mut c_void) {
782 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
785 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
787 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
788 assert!(self.is_owned);
789 let ret = self.inner;
790 self.inner = std::ptr::null_mut();
794 /// Checks if two Descriptions contain equal inner contents.
795 /// This ignores pointers and is_owned flags and looks at the values in fields.
796 /// Two objects with NULL inner values will be considered "equal" here.
798 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
799 if a.inner == b.inner { return true; }
800 if a.inner.is_null() || b.inner.is_null() { return false; }
801 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
803 impl Clone for Description {
804 fn clone(&self) -> Self {
806 inner: if <*mut nativeDescription>::is_null(self.inner) { std::ptr::null_mut() } else {
807 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
813 /// Used only if an object of this type is returned as a trait impl by a method
814 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
815 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
818 /// Creates a copy of the Description
819 pub extern "C" fn Description_clone(orig: &Description) -> Description {
823 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
824 type nativePayeePubKey = nativePayeePubKeyImport;
829 pub struct PayeePubKey {
830 /// A pointer to the opaque Rust object.
832 /// Nearly everywhere, inner must be non-null, however in places where
833 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
834 pub inner: *mut nativePayeePubKey,
835 /// Indicates that this is the only struct which contains the same pointer.
837 /// Rust functions which take ownership of an object provided via an argument require
838 /// this to be true and invalidate the object pointed to by inner.
842 impl Drop for PayeePubKey {
844 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
845 let _ = unsafe { Box::from_raw(self.inner) };
849 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
851 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
853 /// Used only if an object of this type is returned as a trait impl by a method
854 extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
855 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
858 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
860 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
861 assert!(self.is_owned);
862 let ret = self.inner;
863 self.inner = std::ptr::null_mut();
867 /// Checks if two PayeePubKeys contain equal inner contents.
868 /// This ignores pointers and is_owned flags and looks at the values in fields.
869 /// Two objects with NULL inner values will be considered "equal" here.
871 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
872 if a.inner == b.inner { return true; }
873 if a.inner.is_null() || b.inner.is_null() { return false; }
874 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
876 impl Clone for PayeePubKey {
877 fn clone(&self) -> Self {
879 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { std::ptr::null_mut() } else {
880 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
886 /// Used only if an object of this type is returned as a trait impl by a method
887 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
888 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
891 /// Creates a copy of the PayeePubKey
892 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
896 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
897 type nativeExpiryTime = nativeExpiryTimeImport;
899 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
903 /// The number of seconds this expiry time represents has to be in the range
904 /// `0...(SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME)` to avoid overflows when adding it to a
908 pub struct ExpiryTime {
909 /// A pointer to the opaque Rust object.
911 /// Nearly everywhere, inner must be non-null, however in places where
912 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
913 pub inner: *mut nativeExpiryTime,
914 /// Indicates that this is the only struct which contains the same pointer.
916 /// Rust functions which take ownership of an object provided via an argument require
917 /// this to be true and invalidate the object pointed to by inner.
921 impl Drop for ExpiryTime {
923 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
924 let _ = unsafe { Box::from_raw(self.inner) };
928 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
930 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
932 /// Used only if an object of this type is returned as a trait impl by a method
933 extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
934 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
937 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
939 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
940 assert!(self.is_owned);
941 let ret = self.inner;
942 self.inner = std::ptr::null_mut();
946 /// Checks if two ExpiryTimes contain equal inner contents.
947 /// This ignores pointers and is_owned flags and looks at the values in fields.
948 /// Two objects with NULL inner values will be considered "equal" here.
950 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
951 if a.inner == b.inner { return true; }
952 if a.inner.is_null() || b.inner.is_null() { return false; }
953 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
955 impl Clone for ExpiryTime {
956 fn clone(&self) -> Self {
958 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { std::ptr::null_mut() } else {
959 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
965 /// Used only if an object of this type is returned as a trait impl by a method
966 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
967 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
970 /// Creates a copy of the ExpiryTime
971 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
975 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
976 type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
978 /// `min_final_cltv_expiry` to use for the last HTLC in the route
981 pub struct MinFinalCltvExpiry {
982 /// A pointer to the opaque Rust object.
984 /// Nearly everywhere, inner must be non-null, however in places where
985 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
986 pub inner: *mut nativeMinFinalCltvExpiry,
987 /// Indicates that this is the only struct which contains the same pointer.
989 /// Rust functions which take ownership of an object provided via an argument require
990 /// this to be true and invalidate the object pointed to by inner.
994 impl Drop for MinFinalCltvExpiry {
996 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
997 let _ = unsafe { Box::from_raw(self.inner) };
1001 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1003 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1005 /// Used only if an object of this type is returned as a trait impl by a method
1006 extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1007 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1010 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1011 impl MinFinalCltvExpiry {
1012 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1013 assert!(self.is_owned);
1014 let ret = self.inner;
1015 self.inner = std::ptr::null_mut();
1019 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1020 /// This ignores pointers and is_owned flags and looks at the values in fields.
1021 /// Two objects with NULL inner values will be considered "equal" here.
1023 pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool {
1024 if a.inner == b.inner { return true; }
1025 if a.inner.is_null() || b.inner.is_null() { return false; }
1026 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1028 impl Clone for MinFinalCltvExpiry {
1029 fn clone(&self) -> Self {
1031 inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { std::ptr::null_mut() } else {
1032 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1038 /// Used only if an object of this type is returned as a trait impl by a method
1039 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1040 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1043 /// Creates a copy of the MinFinalCltvExpiry
1044 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1047 /// Fallback address in case no LN payment is possible
1053 version: crate::c_types::u5,
1054 program: crate::c_types::derived::CVec_u8Z,
1056 PubKeyHash(crate::c_types::TwentyBytes),
1057 ScriptHash(crate::c_types::TwentyBytes),
1059 use lightning_invoice::Fallback as nativeFallback;
1062 pub(crate) fn to_native(&self) -> nativeFallback {
1064 Fallback::SegWitProgram {ref version, ref program, } => {
1065 let mut version_nonref = (*version).clone();
1066 let mut program_nonref = (*program).clone();
1067 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1068 nativeFallback::SegWitProgram {
1069 version: version_nonref.into(),
1070 program: local_program_nonref,
1073 Fallback::PubKeyHash (ref a, ) => {
1074 let mut a_nonref = (*a).clone();
1075 nativeFallback::PubKeyHash (
1079 Fallback::ScriptHash (ref a, ) => {
1080 let mut a_nonref = (*a).clone();
1081 nativeFallback::ScriptHash (
1088 pub(crate) fn into_native(self) -> nativeFallback {
1090 Fallback::SegWitProgram {mut version, mut program, } => {
1091 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1092 nativeFallback::SegWitProgram {
1093 version: version.into(),
1094 program: local_program,
1097 Fallback::PubKeyHash (mut a, ) => {
1098 nativeFallback::PubKeyHash (
1102 Fallback::ScriptHash (mut a, ) => {
1103 nativeFallback::ScriptHash (
1110 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1112 nativeFallback::SegWitProgram {ref version, ref program, } => {
1113 let mut version_nonref = (*version).clone();
1114 let mut program_nonref = (*program).clone();
1115 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1116 Fallback::SegWitProgram {
1117 version: version_nonref.into(),
1118 program: local_program_nonref.into(),
1121 nativeFallback::PubKeyHash (ref a, ) => {
1122 let mut a_nonref = (*a).clone();
1123 Fallback::PubKeyHash (
1124 crate::c_types::TwentyBytes { data: a_nonref },
1127 nativeFallback::ScriptHash (ref a, ) => {
1128 let mut a_nonref = (*a).clone();
1129 Fallback::ScriptHash (
1130 crate::c_types::TwentyBytes { data: a_nonref },
1136 pub(crate) fn native_into(native: nativeFallback) -> Self {
1138 nativeFallback::SegWitProgram {mut version, mut program, } => {
1139 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1140 Fallback::SegWitProgram {
1141 version: version.into(),
1142 program: local_program.into(),
1145 nativeFallback::PubKeyHash (mut a, ) => {
1146 Fallback::PubKeyHash (
1147 crate::c_types::TwentyBytes { data: a },
1150 nativeFallback::ScriptHash (mut a, ) => {
1151 Fallback::ScriptHash (
1152 crate::c_types::TwentyBytes { data: a },
1158 /// Frees any resources used by the Fallback
1160 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1161 /// Creates a copy of the Fallback
1163 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1166 /// Checks if two Fallbacks contain equal inner contents.
1167 /// This ignores pointers and is_owned flags and looks at the values in fields.
1169 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1170 if &a.to_native() == &b.to_native() { true } else { false }
1173 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1174 type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1176 /// Recoverable signature
1179 pub struct InvoiceSignature {
1180 /// A pointer to the opaque Rust object.
1182 /// Nearly everywhere, inner must be non-null, however in places where
1183 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1184 pub inner: *mut nativeInvoiceSignature,
1185 /// Indicates that this is the only struct which contains the same pointer.
1187 /// Rust functions which take ownership of an object provided via an argument require
1188 /// this to be true and invalidate the object pointed to by inner.
1192 impl Drop for InvoiceSignature {
1193 fn drop(&mut self) {
1194 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1195 let _ = unsafe { Box::from_raw(self.inner) };
1199 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1201 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1203 /// Used only if an object of this type is returned as a trait impl by a method
1204 extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1205 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1208 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1209 impl InvoiceSignature {
1210 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1211 assert!(self.is_owned);
1212 let ret = self.inner;
1213 self.inner = std::ptr::null_mut();
1217 /// Checks if two InvoiceSignatures contain equal inner contents.
1218 /// This ignores pointers and is_owned flags and looks at the values in fields.
1219 /// Two objects with NULL inner values will be considered "equal" here.
1221 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
1222 if a.inner == b.inner { return true; }
1223 if a.inner.is_null() || b.inner.is_null() { return false; }
1224 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1226 impl Clone for InvoiceSignature {
1227 fn clone(&self) -> Self {
1229 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { std::ptr::null_mut() } else {
1230 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1236 /// Used only if an object of this type is returned as a trait impl by a method
1237 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
1238 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
1241 /// Creates a copy of the InvoiceSignature
1242 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
1246 use lightning_invoice::RouteHint as nativeRouteHintImport;
1247 type nativeRouteHint = nativeRouteHintImport;
1249 /// Private routing information
1252 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
1256 pub struct RouteHint {
1257 /// A pointer to the opaque Rust object.
1259 /// Nearly everywhere, inner must be non-null, however in places where
1260 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1261 pub inner: *mut nativeRouteHint,
1262 /// Indicates that this is the only struct which contains the same pointer.
1264 /// Rust functions which take ownership of an object provided via an argument require
1265 /// this to be true and invalidate the object pointed to by inner.
1269 impl Drop for RouteHint {
1270 fn drop(&mut self) {
1271 if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) {
1272 let _ = unsafe { Box::from_raw(self.inner) };
1276 /// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
1278 pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
1280 /// Used only if an object of this type is returned as a trait impl by a method
1281 extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) {
1282 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHint); }
1285 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1287 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint {
1288 assert!(self.is_owned);
1289 let ret = self.inner;
1290 self.inner = std::ptr::null_mut();
1294 /// Checks if two RouteHints contain equal inner contents.
1295 /// This ignores pointers and is_owned flags and looks at the values in fields.
1296 /// Two objects with NULL inner values will be considered "equal" here.
1298 pub extern "C" fn RouteHint_eq(a: &RouteHint, b: &RouteHint) -> bool {
1299 if a.inner == b.inner { return true; }
1300 if a.inner.is_null() || b.inner.is_null() { return false; }
1301 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1303 impl Clone for RouteHint {
1304 fn clone(&self) -> Self {
1306 inner: if <*mut nativeRouteHint>::is_null(self.inner) { std::ptr::null_mut() } else {
1307 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1313 /// Used only if an object of this type is returned as a trait impl by a method
1314 pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void {
1315 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void
1318 /// Creates a copy of the RouteHint
1319 pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
1322 /// Disassembles the `SignedRawInvoice` into its three parts:
1324 /// 2. hash of the raw invoice
1328 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
1329 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
1330 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();
1334 /// The `RawInvoice` which was signed.
1337 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
1338 let mut ret = unsafe { &*this_arg.inner }.raw_invoice();
1339 crate::lightning_invoice::RawInvoice { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1342 /// The hash of the `RawInvoice` that was signed.
1345 pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [u8; 32] {
1346 let mut ret = unsafe { &*this_arg.inner }.hash();
1350 /// InvoiceSignature for the invoice.
1353 pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
1354 let mut ret = unsafe { &*this_arg.inner }.signature();
1355 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1358 /// Recovers the public key used for signing the invoice from the recoverable signature.
1361 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
1362 let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key();
1363 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() };
1367 /// Checks if the signature is valid for the included payee public key or if none exists if it's
1368 /// valid for the recovered signature (which should always be true?).
1371 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &SignedRawInvoice) -> bool {
1372 let mut ret = unsafe { &*this_arg.inner }.check_signature();
1376 /// Calculate the hash of the encoded `RawInvoice`
1379 pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1380 let mut ret = unsafe { &*this_arg.inner }.hash();
1381 crate::c_types::ThirtyTwoBytes { data: ret }
1386 pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1387 let mut ret = unsafe { &*this_arg.inner }.payment_hash();
1388 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 };
1394 pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightning_invoice::Description {
1395 let mut ret = unsafe { &*this_arg.inner }.description();
1396 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 };
1402 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::lightning_invoice::PayeePubKey {
1403 let mut ret = unsafe { &*this_arg.inner }.payee_pub_key();
1404 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 };
1410 pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1411 let mut ret = unsafe { &*this_arg.inner }.description_hash();
1412 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 };
1418 pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightning_invoice::ExpiryTime {
1419 let mut ret = unsafe { &*this_arg.inner }.expiry_time();
1420 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 };
1426 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
1427 let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry();
1428 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 };
1434 pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1435 let mut ret = unsafe { &*this_arg.inner }.payment_secret();
1436 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1442 pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
1443 let mut ret = unsafe { &*this_arg.inner }.features();
1444 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 };
1450 pub extern "C" fn RawInvoice_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_RouteHintZ {
1451 let mut ret = unsafe { &*this_arg.inner }.routes();
1452 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::RouteHint { inner: unsafe { ( (&(**item) as *const _) as *mut _) }, is_owned: false } }); };
1458 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z {
1459 let mut ret = unsafe { &*this_arg.inner }.amount_pico_btc();
1460 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()) } };
1466 pub extern "C" fn RawInvoice_currency(this_arg: &RawInvoice) -> crate::lightning_invoice::Currency {
1467 let mut ret = unsafe { &*this_arg.inner }.currency();
1468 crate::lightning_invoice::Currency::native_into(ret)
1471 /// Create a new `PositiveTimestamp` from a unix timestamp in the Range
1472 /// `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1473 /// `CreationError::TimestampOutOfBounds`.
1476 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1477 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
1478 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() };
1482 /// Create a new `PositiveTimestamp` from a `SystemTime` with a corresponding unix timestamp in
1483 /// the Range `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1484 /// `CreationError::TimestampOutOfBounds`.
1487 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1488 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
1489 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() };
1493 /// Returns the UNIX timestamp representing the stored time
1496 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 {
1497 let mut ret = unsafe { &*this_arg.inner }.as_unix_timestamp();
1501 /// Returns a reference to the internal `SystemTime` time representation
1504 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &PositiveTimestamp) -> u64 {
1505 let mut ret = unsafe { &*this_arg.inner }.as_time();
1506 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1509 /// Transform the `Invoice` into it's unchecked version
1512 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::lightning_invoice::SignedRawInvoice {
1513 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
1514 crate::lightning_invoice::SignedRawInvoice { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1517 /// Check that the invoice is signed correctly and that key recovery works
1520 pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
1521 let mut ret = unsafe { &*this_arg.inner }.check_signature();
1522 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() };
1526 /// Constructs an `Invoice` from a `SignedInvoice` by checking all its invariants.
1528 /// use lightning_invoice::*;
1530 /// let invoice = \"lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdp\\
1531 /// \tl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d7\\
1532 /// \t3gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ec\\
1533 /// \tky03ylcqca784w\";
1535 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
1537 /// assert!(Invoice::from_signed(signed).is_ok());
1541 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
1542 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
1543 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() };
1547 /// Returns the `Invoice`'s timestamp (should equal it's creation time)
1550 pub extern "C" fn Invoice_timestamp(this_arg: &Invoice) -> u64 {
1551 let mut ret = unsafe { &*this_arg.inner }.timestamp();
1552 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1555 /// Returns the hash to which we will receive the preimage on completion of the payment
1558 pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] {
1559 let mut ret = unsafe { &*this_arg.inner }.payment_hash();
1563 /// Get the payee's public key if one was included in the invoice
1566 pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1567 let mut ret = unsafe { &*this_arg.inner }.payee_pub_key();
1568 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
1572 /// Get the payment secret if one was included in the invoice
1575 pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> crate::c_types::ThirtyTwoBytes {
1576 let mut ret = unsafe { &*this_arg.inner }.payment_secret();
1577 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1581 /// Get the invoice features if they were included in the invoice
1584 pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
1585 let mut ret = unsafe { &*this_arg.inner }.features();
1586 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 };
1590 /// Recover the payee's public key (only to be used if none was included in the invoice)
1593 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1594 let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key();
1595 crate::c_types::PublicKey::from_rust(&ret)
1598 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
1601 pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 {
1602 let mut ret = unsafe { &*this_arg.inner }.expiry_time();
1606 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
1607 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
1610 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 {
1611 let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry();
1615 /// Returns a list of all routes included in the invoice
1618 pub extern "C" fn Invoice_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
1619 let mut ret = unsafe { &*this_arg.inner }.routes();
1620 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::RouteHint { inner: unsafe { ( (&(**item) as *const _) as *mut _) }, is_owned: false } }); };
1624 /// Returns the currency for which the invoice was issued
1627 pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoice::Currency {
1628 let mut ret = unsafe { &*this_arg.inner }.currency();
1629 crate::lightning_invoice::Currency::native_into(ret)
1632 /// Returns the amount if specified in the invoice as pico <currency>.
1635 pub extern "C" fn Invoice_amount_pico_btc(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z {
1636 let mut ret = unsafe { &*this_arg.inner }.amount_pico_btc();
1637 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()) } };
1641 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
1642 /// returns `CreationError::DescriptionTooLong` otherwise
1644 /// Please note that single characters may use more than one byte due to UTF8 encoding.
1647 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
1648 let mut ret = lightning_invoice::Description::new(description.into_string());
1649 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() };
1653 /// Returns the underlying description `String`
1656 pub extern "C" fn Description_into_inner(mut this_arg: Description) -> crate::c_types::Str {
1657 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1661 /// Construct an `ExpiryTime` from seconds. If there exists a `PositiveTimestamp` which would
1662 /// overflow on adding the `EpiryTime` to it then this function will return a
1663 /// `CreationError::ExpiryTimeOutOfBounds`.
1666 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1667 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
1668 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() };
1672 /// Construct an `ExpiryTime` from a `Duration`. If there exists a `PositiveTimestamp` which
1673 /// would overflow on adding the `EpiryTime` to it then this function will return a
1674 /// `CreationError::ExpiryTimeOutOfBounds`.
1677 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1678 let mut ret = lightning_invoice::ExpiryTime::from_duration(std::time::Duration::from_secs(duration));
1679 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() };
1683 /// Returns the expiry time in seconds
1686 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 {
1687 let mut ret = unsafe { &*this_arg.inner }.as_seconds();
1691 /// Returns a reference to the underlying `Duration` (=expiry time)
1694 pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 {
1695 let mut ret = unsafe { &*this_arg.inner }.as_duration();
1699 /// Create a new (partial) route from a list of hops
1702 pub extern "C" fn RouteHint_new(mut hops: crate::c_types::derived::CVec_RouteHintHopZ) -> crate::c_types::derived::CResult_RouteHintCreationErrorZ {
1703 let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1704 let mut ret = lightning_invoice::RouteHint::new(local_hops);
1705 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::RouteHint { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
1709 /// Returrn the underlying vector of hops
1712 pub extern "C" fn RouteHint_into_inner(mut this_arg: RouteHint) -> crate::c_types::derived::CVec_RouteHintHopZ {
1713 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1714 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::router::RouteHintHop { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
1718 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
1722 pub enum CreationError {
1723 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
1725 /// The specified route has too many hops and can't be encoded
1727 /// The unix timestamp of the supplied date is <0 or can't be represented as `SystemTime`
1728 TimestampOutOfBounds,
1729 /// The supplied expiry time could cause an overflow if added to a `PositiveTimestamp`
1730 ExpiryTimeOutOfBounds,
1732 use lightning_invoice::CreationError as nativeCreationError;
1733 impl CreationError {
1735 pub(crate) fn to_native(&self) -> nativeCreationError {
1737 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
1738 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
1739 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
1740 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
1744 pub(crate) fn into_native(self) -> nativeCreationError {
1746 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
1747 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
1748 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
1749 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
1753 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
1755 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
1756 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
1757 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
1758 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
1762 pub(crate) fn native_into(native: nativeCreationError) -> Self {
1764 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
1765 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
1766 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
1767 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
1771 /// Creates a copy of the CreationError
1773 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
1776 /// Checks if two CreationErrors contain equal inner contents.
1777 /// This ignores pointers and is_owned flags and looks at the values in fields.
1779 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
1780 if &a.to_native() == &b.to_native() { true } else { false }
1783 /// Get the string representation of a CreationError object
1784 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
1785 format!("{}", &o.to_native()).into()
1787 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
1788 /// requirements sections in BOLT #11
1792 pub enum SemanticError {
1793 /// The invoice is missing the mandatory payment hash
1795 /// The invoice has multiple payment hashes which isn't allowed
1796 MultiplePaymentHashes,
1797 /// No description or description hash are part of the invoice
1799 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
1800 MultipleDescriptions,
1801 /// The invoice contains multiple payment secrets
1802 MultiplePaymentSecrets,
1803 /// The invoice's features are invalid
1805 /// The recovery id doesn't fit the signature/pub key
1807 /// The invoice's signature is invalid
1810 use lightning_invoice::SemanticError as nativeSemanticError;
1811 impl SemanticError {
1813 pub(crate) fn to_native(&self) -> nativeSemanticError {
1815 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
1816 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
1817 SemanticError::NoDescription => nativeSemanticError::NoDescription,
1818 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
1819 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
1820 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
1821 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
1822 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
1826 pub(crate) fn into_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 from_native(native: &nativeSemanticError) -> Self {
1841 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
1842 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
1843 nativeSemanticError::NoDescription => SemanticError::NoDescription,
1844 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
1845 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
1846 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
1847 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
1848 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
1852 pub(crate) fn native_into(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 /// Creates a copy of the SemanticError
1867 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
1870 /// Checks if two SemanticErrors contain equal inner contents.
1871 /// This ignores pointers and is_owned flags and looks at the values in fields.
1873 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
1874 if &a.to_native() == &b.to_native() { true } else { false }
1877 /// Get the string representation of a SemanticError object
1878 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
1879 format!("{}", &o.to_native()).into()
1881 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
1886 pub enum SignOrCreationError {
1887 /// An error occurred during signing
1889 /// An error occurred while building the transaction
1890 CreationError(crate::lightning_invoice::CreationError),
1892 use lightning_invoice::SignOrCreationError as nativeSignOrCreationError;
1893 impl SignOrCreationError {
1895 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
1897 SignOrCreationError::SignError => {
1898 nativeSignOrCreationError::SignError (
1902 SignOrCreationError::CreationError (ref a, ) => {
1903 let mut a_nonref = (*a).clone();
1904 nativeSignOrCreationError::CreationError (
1905 a_nonref.into_native(),
1911 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
1913 SignOrCreationError::SignError => {
1914 nativeSignOrCreationError::SignError (
1918 SignOrCreationError::CreationError (mut a, ) => {
1919 nativeSignOrCreationError::CreationError (
1926 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
1928 nativeSignOrCreationError::SignError (ref a, ) => {
1929 SignOrCreationError::SignError },
1930 nativeSignOrCreationError::CreationError (ref a, ) => {
1931 let mut a_nonref = (*a).clone();
1932 SignOrCreationError::CreationError (
1933 crate::lightning_invoice::CreationError::native_into(a_nonref),
1939 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
1941 nativeSignOrCreationError::SignError (mut a, ) => {
1942 SignOrCreationError::SignError },
1943 nativeSignOrCreationError::CreationError (mut a, ) => {
1944 SignOrCreationError::CreationError (
1945 crate::lightning_invoice::CreationError::native_into(a),
1951 /// Frees any resources used by the SignOrCreationError
1953 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
1954 /// Creates a copy of the SignOrCreationError
1956 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
1959 /// Checks if two SignOrCreationErrors contain equal inner contents.
1960 /// This ignores pointers and is_owned flags and looks at the values in fields.
1962 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
1963 if &a.to_native() == &b.to_native() { true } else { false }
1966 /// Get the string representation of a SignOrCreationError object
1967 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
1968 format!("{}", &o.to_native()).into()