Merge pull request #38 from TheBlueMatt/main
[ldk-c-bindings] / lightning-c-bindings / src / lightning_invoice / mod.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
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.
8
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:
13 //!
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
17
18 use std::str::FromStr;
19 use std::ffi::c_void;
20 use bitcoin::hashes::Hash;
21 use crate::c_types::*;
22
23 pub mod utils;
24 pub mod constants;
25 mod de {
26
27 use std::str::FromStr;
28 use std::ffi::c_void;
29 use bitcoin::hashes::Hash;
30 use crate::c_types::*;
31
32 mod hrp_sm {
33
34 use std::str::FromStr;
35 use std::ffi::c_void;
36 use bitcoin::hashes::Hash;
37 use crate::c_types::*;
38
39 }
40 #[no_mangle]
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()) {
44                 Ok(r) => {
45                         crate::c_types::CResultTempl::ok(
46                                 crate::lightning_invoice::SiPrefix::native_into(r)
47                         )
48                 },
49                 Err(e) => crate::c_types::CResultTempl::err(()),
50         }.into()
51 }
52 #[no_mangle]
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()) {
56                 Ok(r) => {
57                         crate::c_types::CResultTempl::ok(
58                                 crate::lightning_invoice::Invoice { inner: Box::into_raw(Box::new(r)), is_owned: true }
59                         )
60                 },
61                 Err(e) => crate::c_types::CResultTempl::err(()),
62         }.into()
63 }
64 #[no_mangle]
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()) {
68                 Ok(r) => {
69                         crate::c_types::CResultTempl::ok(
70                                 crate::lightning_invoice::SignedRawInvoice { inner: Box::into_raw(Box::new(r)), is_owned: true }
71                         )
72                 },
73                 Err(e) => crate::c_types::CResultTempl::err(()),
74         }.into()
75 }
76 }
77 mod ser {
78
79 use std::str::FromStr;
80 use std::ffi::c_void;
81 use bitcoin::hashes::Hash;
82 use crate::c_types::*;
83
84 #[no_mangle]
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()
88 }
89 #[no_mangle]
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()
93 }
94 #[no_mangle]
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()
98 }
99 #[no_mangle]
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()
103 }
104 }
105 mod tb {
106
107 use std::str::FromStr;
108 use std::ffi::c_void;
109 use bitcoin::hashes::Hash;
110 use crate::c_types::*;
111
112 }
113 /// Default expiry time as defined by [BOLT 11].
114 ///
115 /// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md
116
117 #[no_mangle]
118 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
119 /// Default minimum final CLTV expiry as defined by [BOLT 11].
120 ///
121 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
122 /// provided in [`MIN_FINAL_CLTV_EXPIRY`].
123 ///
124 /// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md
125 /// [`MIN_FINAL_CLTV_EXPIRY`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY
126
127 #[no_mangle]
128 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY;
129 /// **Call this function on startup to ensure that all assumptions about the platform are valid.**
130 ///
131 /// Unfortunately we have to make assumptions about the upper bounds of the `SystemTime` type on
132 /// your platform which we can't fully verify at compile time and which isn't part of it's contract.
133 /// To our best knowledge our assumptions hold for all platforms officially supported by rust, but
134 /// since this check is fast we recommend to do it anyway.
135 ///
136 /// If this function fails this is considered a bug. Please open an issue describing your
137 /// platform and stating your current system time.
138 ///
139 /// # Panics
140 /// If the check fails this function panics. By calling this function on startup you ensure that
141 /// this wont happen at an arbitrary later point in time.
142 #[no_mangle]
143 pub extern "C" fn check_platform() {
144         lightning_invoice::check_platform()
145 }
146
147
148 use lightning_invoice::Invoice as nativeInvoiceImport;
149 type nativeInvoice = nativeInvoiceImport;
150
151 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
152 ///
153 /// There are three ways to construct an `Invoice`:
154 ///  1. using `InvoiceBuilder`
155 ///  2. using `Invoice::from_signed(SignedRawInvoice)`
156 ///  3. using `str::parse::<Invoice>(&str)`
157 #[must_use]
158 #[repr(C)]
159 pub struct Invoice {
160         /// A pointer to the opaque Rust object.
161
162         /// Nearly everywhere, inner must be non-null, however in places where
163         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
164         pub inner: *mut nativeInvoice,
165         /// Indicates that this is the only struct which contains the same pointer.
166
167         /// Rust functions which take ownership of an object provided via an argument require
168         /// this to be true and invalidate the object pointed to by inner.
169         pub is_owned: bool,
170 }
171
172 impl Drop for Invoice {
173         fn drop(&mut self) {
174                 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
175                         let _ = unsafe { Box::from_raw(self.inner) };
176                 }
177         }
178 }
179 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
180 #[no_mangle]
181 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
182 #[allow(unused)]
183 /// Used only if an object of this type is returned as a trait impl by a method
184 extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
185         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
186 }
187 #[allow(unused)]
188 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
189 impl Invoice {
190         pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
191                 assert!(self.is_owned);
192                 let ret = self.inner;
193                 self.inner = std::ptr::null_mut();
194                 ret
195         }
196 }
197 /// Checks if two Invoices contain equal inner contents.
198 /// This ignores pointers and is_owned flags and looks at the values in fields.
199 /// Two objects with NULL inner values will be considered "equal" here.
200 #[no_mangle]
201 pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool {
202         if a.inner == b.inner { return true; }
203         if a.inner.is_null() || b.inner.is_null() { return false; }
204         if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
205 }
206 impl Clone for Invoice {
207         fn clone(&self) -> Self {
208                 Self {
209                         inner: if <*mut nativeInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
210                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
211                         is_owned: true,
212                 }
213         }
214 }
215 #[allow(unused)]
216 /// Used only if an object of this type is returned as a trait impl by a method
217 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
218         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
219 }
220 #[no_mangle]
221 /// Creates a copy of the Invoice
222 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
223         orig.clone()
224 }
225
226 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
227 type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
228
229 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
230 /// invalid.
231 ///
232 /// # Invariants
233 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
234 #[must_use]
235 #[repr(C)]
236 pub struct SignedRawInvoice {
237         /// A pointer to the opaque Rust object.
238
239         /// Nearly everywhere, inner must be non-null, however in places where
240         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
241         pub inner: *mut nativeSignedRawInvoice,
242         /// Indicates that this is the only struct which contains the same pointer.
243
244         /// Rust functions which take ownership of an object provided via an argument require
245         /// this to be true and invalidate the object pointed to by inner.
246         pub is_owned: bool,
247 }
248
249 impl Drop for SignedRawInvoice {
250         fn drop(&mut self) {
251                 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
252                         let _ = unsafe { Box::from_raw(self.inner) };
253                 }
254         }
255 }
256 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
257 #[no_mangle]
258 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
259 #[allow(unused)]
260 /// Used only if an object of this type is returned as a trait impl by a method
261 extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
262         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
263 }
264 #[allow(unused)]
265 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
266 impl SignedRawInvoice {
267         pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
268                 assert!(self.is_owned);
269                 let ret = self.inner;
270                 self.inner = std::ptr::null_mut();
271                 ret
272         }
273 }
274 /// Checks if two SignedRawInvoices contain equal inner contents.
275 /// This ignores pointers and is_owned flags and looks at the values in fields.
276 /// Two objects with NULL inner values will be considered "equal" here.
277 #[no_mangle]
278 pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice) -> bool {
279         if a.inner == b.inner { return true; }
280         if a.inner.is_null() || b.inner.is_null() { return false; }
281         if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
282 }
283 impl Clone for SignedRawInvoice {
284         fn clone(&self) -> Self {
285                 Self {
286                         inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
287                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
288                         is_owned: true,
289                 }
290         }
291 }
292 #[allow(unused)]
293 /// Used only if an object of this type is returned as a trait impl by a method
294 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
295         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
296 }
297 #[no_mangle]
298 /// Creates a copy of the SignedRawInvoice
299 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
300         orig.clone()
301 }
302
303 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
304 type nativeRawInvoice = nativeRawInvoiceImport;
305
306 /// Represents an syntactically correct Invoice for a payment on the lightning network,
307 /// but without the signature information.
308 /// De- and encoding should not lead to information loss but may lead to different hashes.
309 ///
310 /// For methods without docs see the corresponding methods in `Invoice`.
311 #[must_use]
312 #[repr(C)]
313 pub struct RawInvoice {
314         /// A pointer to the opaque Rust object.
315
316         /// Nearly everywhere, inner must be non-null, however in places where
317         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
318         pub inner: *mut nativeRawInvoice,
319         /// Indicates that this is the only struct which contains the same pointer.
320
321         /// Rust functions which take ownership of an object provided via an argument require
322         /// this to be true and invalidate the object pointed to by inner.
323         pub is_owned: bool,
324 }
325
326 impl Drop for RawInvoice {
327         fn drop(&mut self) {
328                 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
329                         let _ = unsafe { Box::from_raw(self.inner) };
330                 }
331         }
332 }
333 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
334 #[no_mangle]
335 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
336 #[allow(unused)]
337 /// Used only if an object of this type is returned as a trait impl by a method
338 extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
339         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
340 }
341 #[allow(unused)]
342 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
343 impl RawInvoice {
344         pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
345                 assert!(self.is_owned);
346                 let ret = self.inner;
347                 self.inner = std::ptr::null_mut();
348                 ret
349         }
350 }
351 /// data part
352 #[no_mangle]
353 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
354         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.data;
355         crate::lightning_invoice::RawDataPart { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
356 }
357 /// data part
358 #[no_mangle]
359 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
360         unsafe { &mut *this_ptr.inner }.data = *unsafe { Box::from_raw(val.take_inner()) };
361 }
362 /// Checks if two RawInvoices contain equal inner contents.
363 /// This ignores pointers and is_owned flags and looks at the values in fields.
364 /// Two objects with NULL inner values will be considered "equal" here.
365 #[no_mangle]
366 pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool {
367         if a.inner == b.inner { return true; }
368         if a.inner.is_null() || b.inner.is_null() { return false; }
369         if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
370 }
371 impl Clone for RawInvoice {
372         fn clone(&self) -> Self {
373                 Self {
374                         inner: if <*mut nativeRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
375                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
376                         is_owned: true,
377                 }
378         }
379 }
380 #[allow(unused)]
381 /// Used only if an object of this type is returned as a trait impl by a method
382 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
383         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
384 }
385 #[no_mangle]
386 /// Creates a copy of the RawInvoice
387 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
388         orig.clone()
389 }
390
391 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
392 type nativeRawDataPart = nativeRawDataPartImport;
393
394 /// Data of the `RawInvoice` that is encoded in the data part
395 #[must_use]
396 #[repr(C)]
397 pub struct RawDataPart {
398         /// A pointer to the opaque Rust object.
399
400         /// Nearly everywhere, inner must be non-null, however in places where
401         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
402         pub inner: *mut nativeRawDataPart,
403         /// Indicates that this is the only struct which contains the same pointer.
404
405         /// Rust functions which take ownership of an object provided via an argument require
406         /// this to be true and invalidate the object pointed to by inner.
407         pub is_owned: bool,
408 }
409
410 impl Drop for RawDataPart {
411         fn drop(&mut self) {
412                 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
413                         let _ = unsafe { Box::from_raw(self.inner) };
414                 }
415         }
416 }
417 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
418 #[no_mangle]
419 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
420 #[allow(unused)]
421 /// Used only if an object of this type is returned as a trait impl by a method
422 extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
423         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
424 }
425 #[allow(unused)]
426 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
427 impl RawDataPart {
428         pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
429                 assert!(self.is_owned);
430                 let ret = self.inner;
431                 self.inner = std::ptr::null_mut();
432                 ret
433         }
434 }
435 /// generation time of the invoice
436 #[no_mangle]
437 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
438         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.timestamp;
439         crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
440 }
441 /// generation time of the invoice
442 #[no_mangle]
443 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
444         unsafe { &mut *this_ptr.inner }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
445 }
446 /// Checks if two RawDataParts contain equal inner contents.
447 /// This ignores pointers and is_owned flags and looks at the values in fields.
448 /// Two objects with NULL inner values will be considered "equal" here.
449 #[no_mangle]
450 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
451         if a.inner == b.inner { return true; }
452         if a.inner.is_null() || b.inner.is_null() { return false; }
453         if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
454 }
455 impl Clone for RawDataPart {
456         fn clone(&self) -> Self {
457                 Self {
458                         inner: if <*mut nativeRawDataPart>::is_null(self.inner) { std::ptr::null_mut() } else {
459                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
460                         is_owned: true,
461                 }
462         }
463 }
464 #[allow(unused)]
465 /// Used only if an object of this type is returned as a trait impl by a method
466 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
467         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
468 }
469 #[no_mangle]
470 /// Creates a copy of the RawDataPart
471 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
472         orig.clone()
473 }
474
475 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
476 type nativePositiveTimestamp = nativePositiveTimestampImport;
477
478 /// A timestamp that refers to a date after 1 January 1970 which means its representation as UNIX
479 /// timestamp is positive.
480 ///
481 /// # Invariants
482 /// The UNIX timestamp representing the stored time has to be positive and small enough so that
483 /// a `EpiryTime` can be added to it without an overflow.
484 #[must_use]
485 #[repr(C)]
486 pub struct PositiveTimestamp {
487         /// A pointer to the opaque Rust object.
488
489         /// Nearly everywhere, inner must be non-null, however in places where
490         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
491         pub inner: *mut nativePositiveTimestamp,
492         /// Indicates that this is the only struct which contains the same pointer.
493
494         /// Rust functions which take ownership of an object provided via an argument require
495         /// this to be true and invalidate the object pointed to by inner.
496         pub is_owned: bool,
497 }
498
499 impl Drop for PositiveTimestamp {
500         fn drop(&mut self) {
501                 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
502                         let _ = unsafe { Box::from_raw(self.inner) };
503                 }
504         }
505 }
506 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
507 #[no_mangle]
508 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
509 #[allow(unused)]
510 /// Used only if an object of this type is returned as a trait impl by a method
511 extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
512         unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
513 }
514 #[allow(unused)]
515 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
516 impl PositiveTimestamp {
517         pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
518                 assert!(self.is_owned);
519                 let ret = self.inner;
520                 self.inner = std::ptr::null_mut();
521                 ret
522         }
523 }
524 /// Checks if two PositiveTimestamps contain equal inner contents.
525 /// This ignores pointers and is_owned flags and looks at the values in fields.
526 /// Two objects with NULL inner values will be considered "equal" here.
527 #[no_mangle]
528 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
529         if a.inner == b.inner { return true; }
530         if a.inner.is_null() || b.inner.is_null() { return false; }
531         if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
532 }
533 impl Clone for PositiveTimestamp {
534         fn clone(&self) -> Self {
535                 Self {
536                         inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { std::ptr::null_mut() } else {
537                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
538                         is_owned: true,
539                 }
540         }
541 }
542 #[allow(unused)]
543 /// Used only if an object of this type is returned as a trait impl by a method
544 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
545         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
546 }
547 #[no_mangle]
548 /// Creates a copy of the PositiveTimestamp
549 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
550         orig.clone()
551 }
552 /// SI prefixes for the human readable part
553 #[must_use]
554 #[derive(Clone)]
555 #[repr(C)]
556 pub enum SiPrefix {
557         /// 10^-3
558         Milli,
559         /// 10^-6
560         Micro,
561         /// 10^-9
562         Nano,
563         /// 10^-12
564         Pico,
565 }
566 use lightning_invoice::SiPrefix as nativeSiPrefix;
567 impl SiPrefix {
568         #[allow(unused)]
569         pub(crate) fn to_native(&self) -> nativeSiPrefix {
570                 match self {
571                         SiPrefix::Milli => nativeSiPrefix::Milli,
572                         SiPrefix::Micro => nativeSiPrefix::Micro,
573                         SiPrefix::Nano => nativeSiPrefix::Nano,
574                         SiPrefix::Pico => nativeSiPrefix::Pico,
575                 }
576         }
577         #[allow(unused)]
578         pub(crate) fn into_native(self) -> nativeSiPrefix {
579                 match self {
580                         SiPrefix::Milli => nativeSiPrefix::Milli,
581                         SiPrefix::Micro => nativeSiPrefix::Micro,
582                         SiPrefix::Nano => nativeSiPrefix::Nano,
583                         SiPrefix::Pico => nativeSiPrefix::Pico,
584                 }
585         }
586         #[allow(unused)]
587         pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
588                 match native {
589                         nativeSiPrefix::Milli => SiPrefix::Milli,
590                         nativeSiPrefix::Micro => SiPrefix::Micro,
591                         nativeSiPrefix::Nano => SiPrefix::Nano,
592                         nativeSiPrefix::Pico => SiPrefix::Pico,
593                 }
594         }
595         #[allow(unused)]
596         pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
597                 match native {
598                         nativeSiPrefix::Milli => SiPrefix::Milli,
599                         nativeSiPrefix::Micro => SiPrefix::Micro,
600                         nativeSiPrefix::Nano => SiPrefix::Nano,
601                         nativeSiPrefix::Pico => SiPrefix::Pico,
602                 }
603         }
604 }
605 /// Creates a copy of the SiPrefix
606 #[no_mangle]
607 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
608         orig.clone()
609 }
610 #[no_mangle]
611 /// Utility method to constructs a new Milli-variant SiPrefix
612 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
613         SiPrefix::Milli}
614 #[no_mangle]
615 /// Utility method to constructs a new Micro-variant SiPrefix
616 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
617         SiPrefix::Micro}
618 #[no_mangle]
619 /// Utility method to constructs a new Nano-variant SiPrefix
620 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
621         SiPrefix::Nano}
622 #[no_mangle]
623 /// Utility method to constructs a new Pico-variant SiPrefix
624 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
625         SiPrefix::Pico}
626 /// Checks if two SiPrefixs contain equal inner contents.
627 /// This ignores pointers and is_owned flags and looks at the values in fields.
628 #[no_mangle]
629 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
630         if &a.to_native() == &b.to_native() { true } else { false }
631 }
632 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
633 /// This is effectively 10^12 * the prefix multiplier
634 #[must_use]
635 #[no_mangle]
636 pub extern "C" fn SiPrefix_multiplier(this_arg: &SiPrefix) -> u64 {
637         let mut ret = this_arg.to_native().multiplier();
638         ret
639 }
640
641 /// Enum representing the crypto currencies (or networks) supported by this library
642 #[must_use]
643 #[derive(Clone)]
644 #[repr(C)]
645 pub enum Currency {
646         /// Bitcoin mainnet
647         Bitcoin,
648         /// Bitcoin testnet
649         BitcoinTestnet,
650         /// Bitcoin regtest
651         Regtest,
652         /// Bitcoin simnet
653         Simnet,
654         /// Bitcoin signet
655         Signet,
656 }
657 use lightning_invoice::Currency as nativeCurrency;
658 impl Currency {
659         #[allow(unused)]
660         pub(crate) fn to_native(&self) -> nativeCurrency {
661                 match self {
662                         Currency::Bitcoin => nativeCurrency::Bitcoin,
663                         Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
664                         Currency::Regtest => nativeCurrency::Regtest,
665                         Currency::Simnet => nativeCurrency::Simnet,
666                         Currency::Signet => nativeCurrency::Signet,
667                 }
668         }
669         #[allow(unused)]
670         pub(crate) fn into_native(self) -> nativeCurrency {
671                 match self {
672                         Currency::Bitcoin => nativeCurrency::Bitcoin,
673                         Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
674                         Currency::Regtest => nativeCurrency::Regtest,
675                         Currency::Simnet => nativeCurrency::Simnet,
676                         Currency::Signet => nativeCurrency::Signet,
677                 }
678         }
679         #[allow(unused)]
680         pub(crate) fn from_native(native: &nativeCurrency) -> Self {
681                 match native {
682                         nativeCurrency::Bitcoin => Currency::Bitcoin,
683                         nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
684                         nativeCurrency::Regtest => Currency::Regtest,
685                         nativeCurrency::Simnet => Currency::Simnet,
686                         nativeCurrency::Signet => Currency::Signet,
687                 }
688         }
689         #[allow(unused)]
690         pub(crate) fn native_into(native: nativeCurrency) -> Self {
691                 match native {
692                         nativeCurrency::Bitcoin => Currency::Bitcoin,
693                         nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
694                         nativeCurrency::Regtest => Currency::Regtest,
695                         nativeCurrency::Simnet => Currency::Simnet,
696                         nativeCurrency::Signet => Currency::Signet,
697                 }
698         }
699 }
700 /// Creates a copy of the Currency
701 #[no_mangle]
702 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
703         orig.clone()
704 }
705 #[no_mangle]
706 /// Utility method to constructs a new Bitcoin-variant Currency
707 pub extern "C" fn Currency_bitcoin() -> Currency {
708         Currency::Bitcoin}
709 #[no_mangle]
710 /// Utility method to constructs a new BitcoinTestnet-variant Currency
711 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
712         Currency::BitcoinTestnet}
713 #[no_mangle]
714 /// Utility method to constructs a new Regtest-variant Currency
715 pub extern "C" fn Currency_regtest() -> Currency {
716         Currency::Regtest}
717 #[no_mangle]
718 /// Utility method to constructs a new Simnet-variant Currency
719 pub extern "C" fn Currency_simnet() -> Currency {
720         Currency::Simnet}
721 #[no_mangle]
722 /// Utility method to constructs a new Signet-variant Currency
723 pub extern "C" fn Currency_signet() -> Currency {
724         Currency::Signet}
725 /// Checks if two Currencys contain equal inner contents.
726 /// This ignores pointers and is_owned flags and looks at the values in fields.
727 #[no_mangle]
728 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
729         if &a.to_native() == &b.to_native() { true } else { false }
730 }
731
732 use lightning_invoice::Sha256 as nativeSha256Import;
733 type nativeSha256 = nativeSha256Import;
734
735 /// SHA-256 hash
736 #[must_use]
737 #[repr(C)]
738 pub struct Sha256 {
739         /// A pointer to the opaque Rust object.
740
741         /// Nearly everywhere, inner must be non-null, however in places where
742         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
743         pub inner: *mut nativeSha256,
744         /// Indicates that this is the only struct which contains the same pointer.
745
746         /// Rust functions which take ownership of an object provided via an argument require
747         /// this to be true and invalidate the object pointed to by inner.
748         pub is_owned: bool,
749 }
750
751 impl Drop for Sha256 {
752         fn drop(&mut self) {
753                 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
754                         let _ = unsafe { Box::from_raw(self.inner) };
755                 }
756         }
757 }
758 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
759 #[no_mangle]
760 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
761 #[allow(unused)]
762 /// Used only if an object of this type is returned as a trait impl by a method
763 extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
764         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
765 }
766 #[allow(unused)]
767 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
768 impl Sha256 {
769         pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
770                 assert!(self.is_owned);
771                 let ret = self.inner;
772                 self.inner = std::ptr::null_mut();
773                 ret
774         }
775 }
776 /// Checks if two Sha256s contain equal inner contents.
777 /// This ignores pointers and is_owned flags and looks at the values in fields.
778 /// Two objects with NULL inner values will be considered "equal" here.
779 #[no_mangle]
780 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
781         if a.inner == b.inner { return true; }
782         if a.inner.is_null() || b.inner.is_null() { return false; }
783         if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
784 }
785 impl Clone for Sha256 {
786         fn clone(&self) -> Self {
787                 Self {
788                         inner: if <*mut nativeSha256>::is_null(self.inner) { std::ptr::null_mut() } else {
789                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
790                         is_owned: true,
791                 }
792         }
793 }
794 #[allow(unused)]
795 /// Used only if an object of this type is returned as a trait impl by a method
796 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
797         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
798 }
799 #[no_mangle]
800 /// Creates a copy of the Sha256
801 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
802         orig.clone()
803 }
804
805 use lightning_invoice::Description as nativeDescriptionImport;
806 type nativeDescription = nativeDescriptionImport;
807
808 /// Description string
809 ///
810 /// # Invariants
811 /// The description can be at most 639 __bytes__ long
812 #[must_use]
813 #[repr(C)]
814 pub struct Description {
815         /// A pointer to the opaque Rust object.
816
817         /// Nearly everywhere, inner must be non-null, however in places where
818         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
819         pub inner: *mut nativeDescription,
820         /// Indicates that this is the only struct which contains the same pointer.
821
822         /// Rust functions which take ownership of an object provided via an argument require
823         /// this to be true and invalidate the object pointed to by inner.
824         pub is_owned: bool,
825 }
826
827 impl Drop for Description {
828         fn drop(&mut self) {
829                 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
830                         let _ = unsafe { Box::from_raw(self.inner) };
831                 }
832         }
833 }
834 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
835 #[no_mangle]
836 pub extern "C" fn Description_free(this_obj: Description) { }
837 #[allow(unused)]
838 /// Used only if an object of this type is returned as a trait impl by a method
839 extern "C" fn Description_free_void(this_ptr: *mut c_void) {
840         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
841 }
842 #[allow(unused)]
843 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
844 impl Description {
845         pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
846                 assert!(self.is_owned);
847                 let ret = self.inner;
848                 self.inner = std::ptr::null_mut();
849                 ret
850         }
851 }
852 /// Checks if two Descriptions contain equal inner contents.
853 /// This ignores pointers and is_owned flags and looks at the values in fields.
854 /// Two objects with NULL inner values will be considered "equal" here.
855 #[no_mangle]
856 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
857         if a.inner == b.inner { return true; }
858         if a.inner.is_null() || b.inner.is_null() { return false; }
859         if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
860 }
861 impl Clone for Description {
862         fn clone(&self) -> Self {
863                 Self {
864                         inner: if <*mut nativeDescription>::is_null(self.inner) { std::ptr::null_mut() } else {
865                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
866                         is_owned: true,
867                 }
868         }
869 }
870 #[allow(unused)]
871 /// Used only if an object of this type is returned as a trait impl by a method
872 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
873         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
874 }
875 #[no_mangle]
876 /// Creates a copy of the Description
877 pub extern "C" fn Description_clone(orig: &Description) -> Description {
878         orig.clone()
879 }
880
881 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
882 type nativePayeePubKey = nativePayeePubKeyImport;
883
884 /// Payee public key
885 #[must_use]
886 #[repr(C)]
887 pub struct PayeePubKey {
888         /// A pointer to the opaque Rust object.
889
890         /// Nearly everywhere, inner must be non-null, however in places where
891         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
892         pub inner: *mut nativePayeePubKey,
893         /// Indicates that this is the only struct which contains the same pointer.
894
895         /// Rust functions which take ownership of an object provided via an argument require
896         /// this to be true and invalidate the object pointed to by inner.
897         pub is_owned: bool,
898 }
899
900 impl Drop for PayeePubKey {
901         fn drop(&mut self) {
902                 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
903                         let _ = unsafe { Box::from_raw(self.inner) };
904                 }
905         }
906 }
907 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
908 #[no_mangle]
909 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
910 #[allow(unused)]
911 /// Used only if an object of this type is returned as a trait impl by a method
912 extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
913         unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
914 }
915 #[allow(unused)]
916 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
917 impl PayeePubKey {
918         pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
919                 assert!(self.is_owned);
920                 let ret = self.inner;
921                 self.inner = std::ptr::null_mut();
922                 ret
923         }
924 }
925 /// Checks if two PayeePubKeys contain equal inner contents.
926 /// This ignores pointers and is_owned flags and looks at the values in fields.
927 /// Two objects with NULL inner values will be considered "equal" here.
928 #[no_mangle]
929 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
930         if a.inner == b.inner { return true; }
931         if a.inner.is_null() || b.inner.is_null() { return false; }
932         if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
933 }
934 impl Clone for PayeePubKey {
935         fn clone(&self) -> Self {
936                 Self {
937                         inner: if <*mut nativePayeePubKey>::is_null(self.inner) { std::ptr::null_mut() } else {
938                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
939                         is_owned: true,
940                 }
941         }
942 }
943 #[allow(unused)]
944 /// Used only if an object of this type is returned as a trait impl by a method
945 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
946         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
947 }
948 #[no_mangle]
949 /// Creates a copy of the PayeePubKey
950 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
951         orig.clone()
952 }
953
954 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
955 type nativeExpiryTime = nativeExpiryTimeImport;
956
957 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
958 /// expires
959 ///
960 /// # Invariants
961 /// The number of seconds this expiry time represents has to be in the range
962 /// `0...(SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME)` to avoid overflows when adding it to a
963 /// timestamp
964 #[must_use]
965 #[repr(C)]
966 pub struct ExpiryTime {
967         /// A pointer to the opaque Rust object.
968
969         /// Nearly everywhere, inner must be non-null, however in places where
970         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
971         pub inner: *mut nativeExpiryTime,
972         /// Indicates that this is the only struct which contains the same pointer.
973
974         /// Rust functions which take ownership of an object provided via an argument require
975         /// this to be true and invalidate the object pointed to by inner.
976         pub is_owned: bool,
977 }
978
979 impl Drop for ExpiryTime {
980         fn drop(&mut self) {
981                 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
982                         let _ = unsafe { Box::from_raw(self.inner) };
983                 }
984         }
985 }
986 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
987 #[no_mangle]
988 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
989 #[allow(unused)]
990 /// Used only if an object of this type is returned as a trait impl by a method
991 extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
992         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
993 }
994 #[allow(unused)]
995 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
996 impl ExpiryTime {
997         pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
998                 assert!(self.is_owned);
999                 let ret = self.inner;
1000                 self.inner = std::ptr::null_mut();
1001                 ret
1002         }
1003 }
1004 /// Checks if two ExpiryTimes contain equal inner contents.
1005 /// This ignores pointers and is_owned flags and looks at the values in fields.
1006 /// Two objects with NULL inner values will be considered "equal" here.
1007 #[no_mangle]
1008 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1009         if a.inner == b.inner { return true; }
1010         if a.inner.is_null() || b.inner.is_null() { return false; }
1011         if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1012 }
1013 impl Clone for ExpiryTime {
1014         fn clone(&self) -> Self {
1015                 Self {
1016                         inner: if <*mut nativeExpiryTime>::is_null(self.inner) { std::ptr::null_mut() } else {
1017                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1018                         is_owned: true,
1019                 }
1020         }
1021 }
1022 #[allow(unused)]
1023 /// Used only if an object of this type is returned as a trait impl by a method
1024 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1025         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1026 }
1027 #[no_mangle]
1028 /// Creates a copy of the ExpiryTime
1029 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1030         orig.clone()
1031 }
1032
1033 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
1034 type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
1035
1036 /// `min_final_cltv_expiry` to use for the last HTLC in the route
1037 #[must_use]
1038 #[repr(C)]
1039 pub struct MinFinalCltvExpiry {
1040         /// A pointer to the opaque Rust object.
1041
1042         /// Nearly everywhere, inner must be non-null, however in places where
1043         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1044         pub inner: *mut nativeMinFinalCltvExpiry,
1045         /// Indicates that this is the only struct which contains the same pointer.
1046
1047         /// Rust functions which take ownership of an object provided via an argument require
1048         /// this to be true and invalidate the object pointed to by inner.
1049         pub is_owned: bool,
1050 }
1051
1052 impl Drop for MinFinalCltvExpiry {
1053         fn drop(&mut self) {
1054                 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
1055                         let _ = unsafe { Box::from_raw(self.inner) };
1056                 }
1057         }
1058 }
1059 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1060 #[no_mangle]
1061 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1062 #[allow(unused)]
1063 /// Used only if an object of this type is returned as a trait impl by a method
1064 extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1065         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1066 }
1067 #[allow(unused)]
1068 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1069 impl MinFinalCltvExpiry {
1070         pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1071                 assert!(self.is_owned);
1072                 let ret = self.inner;
1073                 self.inner = std::ptr::null_mut();
1074                 ret
1075         }
1076 }
1077 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1078 /// This ignores pointers and is_owned flags and looks at the values in fields.
1079 /// Two objects with NULL inner values will be considered "equal" here.
1080 #[no_mangle]
1081 pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool {
1082         if a.inner == b.inner { return true; }
1083         if a.inner.is_null() || b.inner.is_null() { return false; }
1084         if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1085 }
1086 impl Clone for MinFinalCltvExpiry {
1087         fn clone(&self) -> Self {
1088                 Self {
1089                         inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { std::ptr::null_mut() } else {
1090                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1091                         is_owned: true,
1092                 }
1093         }
1094 }
1095 #[allow(unused)]
1096 /// Used only if an object of this type is returned as a trait impl by a method
1097 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1098         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1099 }
1100 #[no_mangle]
1101 /// Creates a copy of the MinFinalCltvExpiry
1102 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1103         orig.clone()
1104 }
1105 /// Fallback address in case no LN payment is possible
1106 #[must_use]
1107 #[derive(Clone)]
1108 #[repr(C)]
1109 pub enum Fallback {
1110         SegWitProgram {
1111                 version: crate::c_types::u5,
1112                 program: crate::c_types::derived::CVec_u8Z,
1113         },
1114         PubKeyHash(crate::c_types::TwentyBytes),
1115         ScriptHash(crate::c_types::TwentyBytes),
1116 }
1117 use lightning_invoice::Fallback as nativeFallback;
1118 impl Fallback {
1119         #[allow(unused)]
1120         pub(crate) fn to_native(&self) -> nativeFallback {
1121                 match self {
1122                         Fallback::SegWitProgram {ref version, ref program, } => {
1123                                 let mut version_nonref = (*version).clone();
1124                                 let mut program_nonref = (*program).clone();
1125                                 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1126                                 nativeFallback::SegWitProgram {
1127                                         version: version_nonref.into(),
1128                                         program: local_program_nonref,
1129                                 }
1130                         },
1131                         Fallback::PubKeyHash (ref a, ) => {
1132                                 let mut a_nonref = (*a).clone();
1133                                 nativeFallback::PubKeyHash (
1134                                         a_nonref.data,
1135                                 )
1136                         },
1137                         Fallback::ScriptHash (ref a, ) => {
1138                                 let mut a_nonref = (*a).clone();
1139                                 nativeFallback::ScriptHash (
1140                                         a_nonref.data,
1141                                 )
1142                         },
1143                 }
1144         }
1145         #[allow(unused)]
1146         pub(crate) fn into_native(self) -> nativeFallback {
1147                 match self {
1148                         Fallback::SegWitProgram {mut version, mut program, } => {
1149                                 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1150                                 nativeFallback::SegWitProgram {
1151                                         version: version.into(),
1152                                         program: local_program,
1153                                 }
1154                         },
1155                         Fallback::PubKeyHash (mut a, ) => {
1156                                 nativeFallback::PubKeyHash (
1157                                         a.data,
1158                                 )
1159                         },
1160                         Fallback::ScriptHash (mut a, ) => {
1161                                 nativeFallback::ScriptHash (
1162                                         a.data,
1163                                 )
1164                         },
1165                 }
1166         }
1167         #[allow(unused)]
1168         pub(crate) fn from_native(native: &nativeFallback) -> Self {
1169                 match native {
1170                         nativeFallback::SegWitProgram {ref version, ref program, } => {
1171                                 let mut version_nonref = (*version).clone();
1172                                 let mut program_nonref = (*program).clone();
1173                                 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1174                                 Fallback::SegWitProgram {
1175                                         version: version_nonref.into(),
1176                                         program: local_program_nonref.into(),
1177                                 }
1178                         },
1179                         nativeFallback::PubKeyHash (ref a, ) => {
1180                                 let mut a_nonref = (*a).clone();
1181                                 Fallback::PubKeyHash (
1182                                         crate::c_types::TwentyBytes { data: a_nonref },
1183                                 )
1184                         },
1185                         nativeFallback::ScriptHash (ref a, ) => {
1186                                 let mut a_nonref = (*a).clone();
1187                                 Fallback::ScriptHash (
1188                                         crate::c_types::TwentyBytes { data: a_nonref },
1189                                 )
1190                         },
1191                 }
1192         }
1193         #[allow(unused)]
1194         pub(crate) fn native_into(native: nativeFallback) -> Self {
1195                 match native {
1196                         nativeFallback::SegWitProgram {mut version, mut program, } => {
1197                                 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1198                                 Fallback::SegWitProgram {
1199                                         version: version.into(),
1200                                         program: local_program.into(),
1201                                 }
1202                         },
1203                         nativeFallback::PubKeyHash (mut a, ) => {
1204                                 Fallback::PubKeyHash (
1205                                         crate::c_types::TwentyBytes { data: a },
1206                                 )
1207                         },
1208                         nativeFallback::ScriptHash (mut a, ) => {
1209                                 Fallback::ScriptHash (
1210                                         crate::c_types::TwentyBytes { data: a },
1211                                 )
1212                         },
1213                 }
1214         }
1215 }
1216 /// Frees any resources used by the Fallback
1217 #[no_mangle]
1218 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1219 /// Creates a copy of the Fallback
1220 #[no_mangle]
1221 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1222         orig.clone()
1223 }
1224 #[no_mangle]
1225 /// Utility method to constructs a new SegWitProgram-variant Fallback
1226 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::u5, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
1227         Fallback::SegWitProgram {
1228                 version,
1229                 program,
1230         }
1231 }
1232 #[no_mangle]
1233 /// Utility method to constructs a new PubKeyHash-variant Fallback
1234 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1235         Fallback::PubKeyHash(a, )
1236 }
1237 #[no_mangle]
1238 /// Utility method to constructs a new ScriptHash-variant Fallback
1239 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1240         Fallback::ScriptHash(a, )
1241 }
1242 /// Checks if two Fallbacks contain equal inner contents.
1243 /// This ignores pointers and is_owned flags and looks at the values in fields.
1244 #[no_mangle]
1245 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1246         if &a.to_native() == &b.to_native() { true } else { false }
1247 }
1248
1249 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1250 type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1251
1252 /// Recoverable signature
1253 #[must_use]
1254 #[repr(C)]
1255 pub struct InvoiceSignature {
1256         /// A pointer to the opaque Rust object.
1257
1258         /// Nearly everywhere, inner must be non-null, however in places where
1259         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1260         pub inner: *mut nativeInvoiceSignature,
1261         /// Indicates that this is the only struct which contains the same pointer.
1262
1263         /// Rust functions which take ownership of an object provided via an argument require
1264         /// this to be true and invalidate the object pointed to by inner.
1265         pub is_owned: bool,
1266 }
1267
1268 impl Drop for InvoiceSignature {
1269         fn drop(&mut self) {
1270                 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1271                         let _ = unsafe { Box::from_raw(self.inner) };
1272                 }
1273         }
1274 }
1275 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1276 #[no_mangle]
1277 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1278 #[allow(unused)]
1279 /// Used only if an object of this type is returned as a trait impl by a method
1280 extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1281         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1282 }
1283 #[allow(unused)]
1284 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1285 impl InvoiceSignature {
1286         pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1287                 assert!(self.is_owned);
1288                 let ret = self.inner;
1289                 self.inner = std::ptr::null_mut();
1290                 ret
1291         }
1292 }
1293 /// Checks if two InvoiceSignatures contain equal inner contents.
1294 /// This ignores pointers and is_owned flags and looks at the values in fields.
1295 /// Two objects with NULL inner values will be considered "equal" here.
1296 #[no_mangle]
1297 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
1298         if a.inner == b.inner { return true; }
1299         if a.inner.is_null() || b.inner.is_null() { return false; }
1300         if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1301 }
1302 impl Clone for InvoiceSignature {
1303         fn clone(&self) -> Self {
1304                 Self {
1305                         inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { std::ptr::null_mut() } else {
1306                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1307                         is_owned: true,
1308                 }
1309         }
1310 }
1311 #[allow(unused)]
1312 /// Used only if an object of this type is returned as a trait impl by a method
1313 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
1314         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
1315 }
1316 #[no_mangle]
1317 /// Creates a copy of the InvoiceSignature
1318 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
1319         orig.clone()
1320 }
1321
1322 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
1323 type nativePrivateRoute = nativePrivateRouteImport;
1324
1325 /// Private routing information
1326 ///
1327 /// # Invariants
1328 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
1329 ///
1330 #[must_use]
1331 #[repr(C)]
1332 pub struct PrivateRoute {
1333         /// A pointer to the opaque Rust object.
1334
1335         /// Nearly everywhere, inner must be non-null, however in places where
1336         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1337         pub inner: *mut nativePrivateRoute,
1338         /// Indicates that this is the only struct which contains the same pointer.
1339
1340         /// Rust functions which take ownership of an object provided via an argument require
1341         /// this to be true and invalidate the object pointed to by inner.
1342         pub is_owned: bool,
1343 }
1344
1345 impl Drop for PrivateRoute {
1346         fn drop(&mut self) {
1347                 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
1348                         let _ = unsafe { Box::from_raw(self.inner) };
1349                 }
1350         }
1351 }
1352 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
1353 #[no_mangle]
1354 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
1355 #[allow(unused)]
1356 /// Used only if an object of this type is returned as a trait impl by a method
1357 extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
1358         unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); }
1359 }
1360 #[allow(unused)]
1361 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1362 impl PrivateRoute {
1363         pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
1364                 assert!(self.is_owned);
1365                 let ret = self.inner;
1366                 self.inner = std::ptr::null_mut();
1367                 ret
1368         }
1369 }
1370 /// Checks if two PrivateRoutes contain equal inner contents.
1371 /// This ignores pointers and is_owned flags and looks at the values in fields.
1372 /// Two objects with NULL inner values will be considered "equal" here.
1373 #[no_mangle]
1374 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
1375         if a.inner == b.inner { return true; }
1376         if a.inner.is_null() || b.inner.is_null() { return false; }
1377         if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
1378 }
1379 impl Clone for PrivateRoute {
1380         fn clone(&self) -> Self {
1381                 Self {
1382                         inner: if <*mut nativePrivateRoute>::is_null(self.inner) { std::ptr::null_mut() } else {
1383                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1384                         is_owned: true,
1385                 }
1386         }
1387 }
1388 #[allow(unused)]
1389 /// Used only if an object of this type is returned as a trait impl by a method
1390 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
1391         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
1392 }
1393 #[no_mangle]
1394 /// Creates a copy of the PrivateRoute
1395 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
1396         orig.clone()
1397 }
1398 /// Disassembles the `SignedRawInvoice` into its three parts:
1399 ///  1. raw invoice
1400 ///  2. hash of the raw invoice
1401 ///  3. signature
1402 #[must_use]
1403 #[no_mangle]
1404 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
1405         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
1406         let (mut orig_ret_0, mut orig_ret_1, mut orig_ret_2) = ret; let mut local_ret = (crate::lightning_invoice::RawInvoice { inner: Box::into_raw(Box::new(orig_ret_0)), is_owned: true }, crate::c_types::ThirtyTwoBytes { data: orig_ret_1 }, crate::lightning_invoice::InvoiceSignature { inner: Box::into_raw(Box::new(orig_ret_2)), is_owned: true }).into();
1407         local_ret
1408 }
1409
1410 /// The `RawInvoice` which was signed.
1411 #[must_use]
1412 #[no_mangle]
1413 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
1414         let mut ret = unsafe { &*this_arg.inner }.raw_invoice();
1415         crate::lightning_invoice::RawInvoice { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1416 }
1417
1418 /// The hash of the `RawInvoice` that was signed.
1419 #[must_use]
1420 #[no_mangle]
1421 pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [u8; 32] {
1422         let mut ret = unsafe { &*this_arg.inner }.hash();
1423         ret
1424 }
1425
1426 /// InvoiceSignature for the invoice.
1427 #[must_use]
1428 #[no_mangle]
1429 pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
1430         let mut ret = unsafe { &*this_arg.inner }.signature();
1431         crate::lightning_invoice::InvoiceSignature { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1432 }
1433
1434 /// Recovers the public key used for signing the invoice from the recoverable signature.
1435 #[must_use]
1436 #[no_mangle]
1437 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
1438         let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key();
1439         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PayeePubKey { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
1440         local_ret
1441 }
1442
1443 /// Checks if the signature is valid for the included payee public key or if none exists if it's
1444 /// valid for the recovered signature (which should always be true?).
1445 #[must_use]
1446 #[no_mangle]
1447 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &SignedRawInvoice) -> bool {
1448         let mut ret = unsafe { &*this_arg.inner }.check_signature();
1449         ret
1450 }
1451
1452 /// Calculate the hash of the encoded `RawInvoice`
1453 #[must_use]
1454 #[no_mangle]
1455 pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1456         let mut ret = unsafe { &*this_arg.inner }.hash();
1457         crate::c_types::ThirtyTwoBytes { data: ret }
1458 }
1459
1460 ///
1461 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1462 #[must_use]
1463 #[no_mangle]
1464 pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1465         let mut ret = unsafe { &*this_arg.inner }.payment_hash();
1466         let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else {  { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1467         local_ret
1468 }
1469
1470 ///
1471 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1472 #[must_use]
1473 #[no_mangle]
1474 pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightning_invoice::Description {
1475         let mut ret = unsafe { &*this_arg.inner }.description();
1476         let mut local_ret = crate::lightning_invoice::Description { inner: unsafe { (if ret.is_none() { std::ptr::null() } else {  { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1477         local_ret
1478 }
1479
1480 ///
1481 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1482 #[must_use]
1483 #[no_mangle]
1484 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::lightning_invoice::PayeePubKey {
1485         let mut ret = unsafe { &*this_arg.inner }.payee_pub_key();
1486         let mut local_ret = crate::lightning_invoice::PayeePubKey { inner: unsafe { (if ret.is_none() { std::ptr::null() } else {  { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1487         local_ret
1488 }
1489
1490 ///
1491 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1492 #[must_use]
1493 #[no_mangle]
1494 pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1495         let mut ret = unsafe { &*this_arg.inner }.description_hash();
1496         let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else {  { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1497         local_ret
1498 }
1499
1500 ///
1501 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1502 #[must_use]
1503 #[no_mangle]
1504 pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightning_invoice::ExpiryTime {
1505         let mut ret = unsafe { &*this_arg.inner }.expiry_time();
1506         let mut local_ret = crate::lightning_invoice::ExpiryTime { inner: unsafe { (if ret.is_none() { std::ptr::null() } else {  { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1507         local_ret
1508 }
1509
1510 ///
1511 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1512 #[must_use]
1513 #[no_mangle]
1514 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
1515         let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry();
1516         let mut local_ret = crate::lightning_invoice::MinFinalCltvExpiry { inner: unsafe { (if ret.is_none() { std::ptr::null() } else {  { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1517         local_ret
1518 }
1519
1520 ///
1521 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1522 #[must_use]
1523 #[no_mangle]
1524 pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1525         let mut ret = unsafe { &*this_arg.inner }.payment_secret();
1526         let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else {  { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1527         local_ret
1528 }
1529
1530 ///
1531 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1532 #[must_use]
1533 #[no_mangle]
1534 pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
1535         let mut ret = unsafe { &*this_arg.inner }.features();
1536         let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else {  { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1537         local_ret
1538 }
1539
1540 #[must_use]
1541 #[no_mangle]
1542 pub extern "C" fn RawInvoice_private_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1543         let mut ret = unsafe { &*this_arg.inner }.private_routes();
1544         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ( (&(*item) as *const _) as *mut _) }, is_owned: false } }); };
1545         local_ret.into()
1546 }
1547
1548 #[must_use]
1549 #[no_mangle]
1550 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z {
1551         let mut ret = unsafe { &*this_arg.inner }.amount_pico_btc();
1552         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else {  { crate::c_types::derived::COption_u64Z::Some(ret.unwrap()) } };
1553         local_ret
1554 }
1555
1556 #[must_use]
1557 #[no_mangle]
1558 pub extern "C" fn RawInvoice_currency(this_arg: &RawInvoice) -> crate::lightning_invoice::Currency {
1559         let mut ret = unsafe { &*this_arg.inner }.currency();
1560         crate::lightning_invoice::Currency::native_into(ret)
1561 }
1562
1563 /// Create a new `PositiveTimestamp` from a unix timestamp in the Range
1564 /// `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1565 /// `CreationError::TimestampOutOfBounds`.
1566 #[must_use]
1567 #[no_mangle]
1568 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1569         let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
1570         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
1571         local_ret
1572 }
1573
1574 /// Create a new `PositiveTimestamp` from a `SystemTime` with a corresponding unix timestamp in
1575 /// the Range `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1576 /// `CreationError::TimestampOutOfBounds`.
1577 #[must_use]
1578 #[no_mangle]
1579 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1580         let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
1581         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
1582         local_ret
1583 }
1584
1585 /// Returns the UNIX timestamp representing the stored time
1586 #[must_use]
1587 #[no_mangle]
1588 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 {
1589         let mut ret = unsafe { &*this_arg.inner }.as_unix_timestamp();
1590         ret
1591 }
1592
1593 /// Returns a reference to the internal `SystemTime` time representation
1594 #[must_use]
1595 #[no_mangle]
1596 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &PositiveTimestamp) -> u64 {
1597         let mut ret = unsafe { &*this_arg.inner }.as_time();
1598         ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1599 }
1600
1601 /// Transform the `Invoice` into it's unchecked version
1602 #[must_use]
1603 #[no_mangle]
1604 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::lightning_invoice::SignedRawInvoice {
1605         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
1606         crate::lightning_invoice::SignedRawInvoice { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1607 }
1608
1609 /// Check that the invoice is signed correctly and that key recovery works
1610 #[must_use]
1611 #[no_mangle]
1612 pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
1613         let mut ret = unsafe { &*this_arg.inner }.check_signature();
1614         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::SemanticError::native_into(e) }).into() };
1615         local_ret
1616 }
1617
1618 /// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
1619 /// ```
1620 /// use lightning_invoice::*;
1621 ///
1622 /// let invoice = \"lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdp\\
1623 /// \tl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d7\\
1624 /// \t3gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ec\\
1625 /// \tky03ylcqca784w\";
1626 ///
1627 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
1628 ///
1629 /// assert!(Invoice::from_signed(signed).is_ok());
1630 /// ```
1631 #[must_use]
1632 #[no_mangle]
1633 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
1634         let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
1635         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::Invoice { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::SemanticError::native_into(e) }).into() };
1636         local_ret
1637 }
1638
1639 /// Returns the `Invoice`'s timestamp (should equal it's creation time)
1640 #[must_use]
1641 #[no_mangle]
1642 pub extern "C" fn Invoice_timestamp(this_arg: &Invoice) -> u64 {
1643         let mut ret = unsafe { &*this_arg.inner }.timestamp();
1644         ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1645 }
1646
1647 /// Returns the hash to which we will receive the preimage on completion of the payment
1648 #[must_use]
1649 #[no_mangle]
1650 pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] {
1651         let mut ret = unsafe { &*this_arg.inner }.payment_hash();
1652         ret.as_inner()
1653 }
1654
1655 /// Get the payee's public key if one was included in the invoice
1656 ///
1657 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1658 #[must_use]
1659 #[no_mangle]
1660 pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1661         let mut ret = unsafe { &*this_arg.inner }.payee_pub_key();
1662         let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else {  { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
1663         local_ret
1664 }
1665
1666 /// Get the payment secret if one was included in the invoice
1667 ///
1668 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1669 #[must_use]
1670 #[no_mangle]
1671 pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> crate::c_types::ThirtyTwoBytes {
1672         let mut ret = unsafe { &*this_arg.inner }.payment_secret();
1673         let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else {  { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1674         local_ret
1675 }
1676
1677 /// Get the invoice features if they were included in the invoice
1678 ///
1679 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1680 #[must_use]
1681 #[no_mangle]
1682 pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
1683         let mut ret = unsafe { &*this_arg.inner }.features();
1684         let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else {  { (ret.unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1685         local_ret
1686 }
1687
1688 /// Recover the payee's public key (only to be used if none was included in the invoice)
1689 #[must_use]
1690 #[no_mangle]
1691 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1692         let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key();
1693         crate::c_types::PublicKey::from_rust(&ret)
1694 }
1695
1696 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
1697 #[must_use]
1698 #[no_mangle]
1699 pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 {
1700         let mut ret = unsafe { &*this_arg.inner }.expiry_time();
1701         ret.as_secs()
1702 }
1703
1704 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
1705 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
1706 #[must_use]
1707 #[no_mangle]
1708 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 {
1709         let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry();
1710         ret
1711 }
1712
1713 /// Returns a list of all routes included in the invoice
1714 #[must_use]
1715 #[no_mangle]
1716 pub extern "C" fn Invoice_private_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1717         let mut ret = unsafe { &*this_arg.inner }.private_routes();
1718         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ( (&(*item) as *const _) as *mut _) }, is_owned: false } }); };
1719         local_ret.into()
1720 }
1721
1722 /// Returns a list of all routes included in the invoice as the underlying hints
1723 #[must_use]
1724 #[no_mangle]
1725 pub extern "C" fn Invoice_route_hints(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
1726         let mut ret = unsafe { &*this_arg.inner }.route_hints();
1727         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::router::RouteHint { inner: unsafe { ( (&(*item) as *const _) as *mut _) }, is_owned: false } }); };
1728         local_ret.into()
1729 }
1730
1731 /// Returns the currency for which the invoice was issued
1732 #[must_use]
1733 #[no_mangle]
1734 pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoice::Currency {
1735         let mut ret = unsafe { &*this_arg.inner }.currency();
1736         crate::lightning_invoice::Currency::native_into(ret)
1737 }
1738
1739 /// Returns the amount if specified in the invoice as pico <currency>.
1740 #[must_use]
1741 #[no_mangle]
1742 pub extern "C" fn Invoice_amount_pico_btc(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z {
1743         let mut ret = unsafe { &*this_arg.inner }.amount_pico_btc();
1744         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else {  { crate::c_types::derived::COption_u64Z::Some(ret.unwrap()) } };
1745         local_ret
1746 }
1747
1748 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
1749 /// returns `CreationError::DescriptionTooLong` otherwise
1750 ///
1751 /// Please note that single characters may use more than one byte due to UTF8 encoding.
1752 #[must_use]
1753 #[no_mangle]
1754 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
1755         let mut ret = lightning_invoice::Description::new(description.into_string());
1756         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::Description { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
1757         local_ret
1758 }
1759
1760 /// Returns the underlying description `String`
1761 #[must_use]
1762 #[no_mangle]
1763 pub extern "C" fn Description_into_inner(mut this_arg: Description) -> crate::c_types::Str {
1764         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1765         ret.into()
1766 }
1767
1768 /// Construct an `ExpiryTime` from seconds. If there exists a `PositiveTimestamp` which would
1769 /// overflow on adding the `EpiryTime` to it then this function will return a
1770 /// `CreationError::ExpiryTimeOutOfBounds`.
1771 #[must_use]
1772 #[no_mangle]
1773 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1774         let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
1775         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::ExpiryTime { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
1776         local_ret
1777 }
1778
1779 /// Construct an `ExpiryTime` from a `Duration`. If there exists a `PositiveTimestamp` which
1780 /// would overflow on adding the `EpiryTime` to it then this function will return a
1781 /// `CreationError::ExpiryTimeOutOfBounds`.
1782 #[must_use]
1783 #[no_mangle]
1784 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1785         let mut ret = lightning_invoice::ExpiryTime::from_duration(std::time::Duration::from_secs(duration));
1786         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::ExpiryTime { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
1787         local_ret
1788 }
1789
1790 /// Returns the expiry time in seconds
1791 #[must_use]
1792 #[no_mangle]
1793 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 {
1794         let mut ret = unsafe { &*this_arg.inner }.as_seconds();
1795         ret
1796 }
1797
1798 /// Returns a reference to the underlying `Duration` (=expiry time)
1799 #[must_use]
1800 #[no_mangle]
1801 pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 {
1802         let mut ret = unsafe { &*this_arg.inner }.as_duration();
1803         ret.as_secs()
1804 }
1805
1806 /// Creates a new (partial) route from a list of hops
1807 #[must_use]
1808 #[no_mangle]
1809 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
1810         let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
1811         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PrivateRoute { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
1812         local_ret
1813 }
1814
1815 /// Returns the underlying list of hops
1816 #[must_use]
1817 #[no_mangle]
1818 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: PrivateRoute) -> crate::lightning::routing::router::RouteHint {
1819         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1820         crate::lightning::routing::router::RouteHint { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1821 }
1822
1823 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
1824 #[must_use]
1825 #[derive(Clone)]
1826 #[repr(C)]
1827 pub enum CreationError {
1828         /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
1829         DescriptionTooLong,
1830         /// The specified route has too many hops and can't be encoded
1831         RouteTooLong,
1832         /// The unix timestamp of the supplied date is <0 or can't be represented as `SystemTime`
1833         TimestampOutOfBounds,
1834         /// The supplied expiry time could cause an overflow if added to a `PositiveTimestamp`
1835         ExpiryTimeOutOfBounds,
1836 }
1837 use lightning_invoice::CreationError as nativeCreationError;
1838 impl CreationError {
1839         #[allow(unused)]
1840         pub(crate) fn to_native(&self) -> nativeCreationError {
1841                 match self {
1842                         CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
1843                         CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
1844                         CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
1845                         CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
1846                 }
1847         }
1848         #[allow(unused)]
1849         pub(crate) fn into_native(self) -> nativeCreationError {
1850                 match self {
1851                         CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
1852                         CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
1853                         CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
1854                         CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
1855                 }
1856         }
1857         #[allow(unused)]
1858         pub(crate) fn from_native(native: &nativeCreationError) -> Self {
1859                 match native {
1860                         nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
1861                         nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
1862                         nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
1863                         nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
1864                 }
1865         }
1866         #[allow(unused)]
1867         pub(crate) fn native_into(native: nativeCreationError) -> Self {
1868                 match native {
1869                         nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
1870                         nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
1871                         nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
1872                         nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
1873                 }
1874         }
1875 }
1876 /// Creates a copy of the CreationError
1877 #[no_mangle]
1878 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
1879         orig.clone()
1880 }
1881 #[no_mangle]
1882 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
1883 pub extern "C" fn CreationError_description_too_long() -> CreationError {
1884         CreationError::DescriptionTooLong}
1885 #[no_mangle]
1886 /// Utility method to constructs a new RouteTooLong-variant CreationError
1887 pub extern "C" fn CreationError_route_too_long() -> CreationError {
1888         CreationError::RouteTooLong}
1889 #[no_mangle]
1890 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
1891 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
1892         CreationError::TimestampOutOfBounds}
1893 #[no_mangle]
1894 /// Utility method to constructs a new ExpiryTimeOutOfBounds-variant CreationError
1895 pub extern "C" fn CreationError_expiry_time_out_of_bounds() -> CreationError {
1896         CreationError::ExpiryTimeOutOfBounds}
1897 /// Checks if two CreationErrors contain equal inner contents.
1898 /// This ignores pointers and is_owned flags and looks at the values in fields.
1899 #[no_mangle]
1900 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
1901         if &a.to_native() == &b.to_native() { true } else { false }
1902 }
1903 #[no_mangle]
1904 /// Get the string representation of a CreationError object
1905 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
1906         format!("{}", &o.to_native()).into()
1907 }
1908 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
1909 /// requirements sections in BOLT #11
1910 #[must_use]
1911 #[derive(Clone)]
1912 #[repr(C)]
1913 pub enum SemanticError {
1914         /// The invoice is missing the mandatory payment hash
1915         NoPaymentHash,
1916         /// The invoice has multiple payment hashes which isn't allowed
1917         MultiplePaymentHashes,
1918         /// No description or description hash are part of the invoice
1919         NoDescription,
1920         /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
1921         MultipleDescriptions,
1922         /// The invoice contains multiple payment secrets
1923         MultiplePaymentSecrets,
1924         /// The invoice's features are invalid
1925         InvalidFeatures,
1926         /// The recovery id doesn't fit the signature/pub key
1927         InvalidRecoveryId,
1928         /// The invoice's signature is invalid
1929         InvalidSignature,
1930 }
1931 use lightning_invoice::SemanticError as nativeSemanticError;
1932 impl SemanticError {
1933         #[allow(unused)]
1934         pub(crate) fn to_native(&self) -> nativeSemanticError {
1935                 match self {
1936                         SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
1937                         SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
1938                         SemanticError::NoDescription => nativeSemanticError::NoDescription,
1939                         SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
1940                         SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
1941                         SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
1942                         SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
1943                         SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
1944                 }
1945         }
1946         #[allow(unused)]
1947         pub(crate) fn into_native(self) -> nativeSemanticError {
1948                 match self {
1949                         SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
1950                         SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
1951                         SemanticError::NoDescription => nativeSemanticError::NoDescription,
1952                         SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
1953                         SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
1954                         SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
1955                         SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
1956                         SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
1957                 }
1958         }
1959         #[allow(unused)]
1960         pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
1961                 match native {
1962                         nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
1963                         nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
1964                         nativeSemanticError::NoDescription => SemanticError::NoDescription,
1965                         nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
1966                         nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
1967                         nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
1968                         nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
1969                         nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
1970                 }
1971         }
1972         #[allow(unused)]
1973         pub(crate) fn native_into(native: nativeSemanticError) -> Self {
1974                 match native {
1975                         nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
1976                         nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
1977                         nativeSemanticError::NoDescription => SemanticError::NoDescription,
1978                         nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
1979                         nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
1980                         nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
1981                         nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
1982                         nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
1983                 }
1984         }
1985 }
1986 /// Creates a copy of the SemanticError
1987 #[no_mangle]
1988 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
1989         orig.clone()
1990 }
1991 #[no_mangle]
1992 /// Utility method to constructs a new NoPaymentHash-variant SemanticError
1993 pub extern "C" fn SemanticError_no_payment_hash() -> SemanticError {
1994         SemanticError::NoPaymentHash}
1995 #[no_mangle]
1996 /// Utility method to constructs a new MultiplePaymentHashes-variant SemanticError
1997 pub extern "C" fn SemanticError_multiple_payment_hashes() -> SemanticError {
1998         SemanticError::MultiplePaymentHashes}
1999 #[no_mangle]
2000 /// Utility method to constructs a new NoDescription-variant SemanticError
2001 pub extern "C" fn SemanticError_no_description() -> SemanticError {
2002         SemanticError::NoDescription}
2003 #[no_mangle]
2004 /// Utility method to constructs a new MultipleDescriptions-variant SemanticError
2005 pub extern "C" fn SemanticError_multiple_descriptions() -> SemanticError {
2006         SemanticError::MultipleDescriptions}
2007 #[no_mangle]
2008 /// Utility method to constructs a new MultiplePaymentSecrets-variant SemanticError
2009 pub extern "C" fn SemanticError_multiple_payment_secrets() -> SemanticError {
2010         SemanticError::MultiplePaymentSecrets}
2011 #[no_mangle]
2012 /// Utility method to constructs a new InvalidFeatures-variant SemanticError
2013 pub extern "C" fn SemanticError_invalid_features() -> SemanticError {
2014         SemanticError::InvalidFeatures}
2015 #[no_mangle]
2016 /// Utility method to constructs a new InvalidRecoveryId-variant SemanticError
2017 pub extern "C" fn SemanticError_invalid_recovery_id() -> SemanticError {
2018         SemanticError::InvalidRecoveryId}
2019 #[no_mangle]
2020 /// Utility method to constructs a new InvalidSignature-variant SemanticError
2021 pub extern "C" fn SemanticError_invalid_signature() -> SemanticError {
2022         SemanticError::InvalidSignature}
2023 /// Checks if two SemanticErrors contain equal inner contents.
2024 /// This ignores pointers and is_owned flags and looks at the values in fields.
2025 #[no_mangle]
2026 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
2027         if &a.to_native() == &b.to_native() { true } else { false }
2028 }
2029 #[no_mangle]
2030 /// Get the string representation of a SemanticError object
2031 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
2032         format!("{}", &o.to_native()).into()
2033 }
2034 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
2035 /// may occur.
2036 #[must_use]
2037 #[derive(Clone)]
2038 #[repr(C)]
2039 pub enum SignOrCreationError {
2040         /// An error occurred during signing
2041         SignError,
2042         /// An error occurred while building the transaction
2043         CreationError(crate::lightning_invoice::CreationError),
2044 }
2045 use lightning_invoice::SignOrCreationError as nativeSignOrCreationError;
2046 impl SignOrCreationError {
2047         #[allow(unused)]
2048         pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
2049                 match self {
2050                         SignOrCreationError::SignError => {
2051                                 nativeSignOrCreationError::SignError (
2052                                         () /*a_nonref*/,
2053                                 )
2054                         },
2055                         SignOrCreationError::CreationError (ref a, ) => {
2056                                 let mut a_nonref = (*a).clone();
2057                                 nativeSignOrCreationError::CreationError (
2058                                         a_nonref.into_native(),
2059                                 )
2060                         },
2061                 }
2062         }
2063         #[allow(unused)]
2064         pub(crate) fn into_native(self) -> nativeSignOrCreationError {
2065                 match self {
2066                         SignOrCreationError::SignError => {
2067                                 nativeSignOrCreationError::SignError (
2068                                         () /*a*/,
2069                                 )
2070                         },
2071                         SignOrCreationError::CreationError (mut a, ) => {
2072                                 nativeSignOrCreationError::CreationError (
2073                                         a.into_native(),
2074                                 )
2075                         },
2076                 }
2077         }
2078         #[allow(unused)]
2079         pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
2080                 match native {
2081                         nativeSignOrCreationError::SignError (ref a, ) => {
2082                                 SignOrCreationError::SignError                  },
2083                         nativeSignOrCreationError::CreationError (ref a, ) => {
2084                                 let mut a_nonref = (*a).clone();
2085                                 SignOrCreationError::CreationError (
2086                                         crate::lightning_invoice::CreationError::native_into(a_nonref),
2087                                 )
2088                         },
2089                 }
2090         }
2091         #[allow(unused)]
2092         pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
2093                 match native {
2094                         nativeSignOrCreationError::SignError (mut a, ) => {
2095                                 SignOrCreationError::SignError                  },
2096                         nativeSignOrCreationError::CreationError (mut a, ) => {
2097                                 SignOrCreationError::CreationError (
2098                                         crate::lightning_invoice::CreationError::native_into(a),
2099                                 )
2100                         },
2101                 }
2102         }
2103 }
2104 /// Frees any resources used by the SignOrCreationError
2105 #[no_mangle]
2106 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
2107 /// Creates a copy of the SignOrCreationError
2108 #[no_mangle]
2109 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
2110         orig.clone()
2111 }
2112 #[no_mangle]
2113 /// Utility method to constructs a new SignError-variant SignOrCreationError
2114 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
2115         SignOrCreationError::SignError
2116 }
2117 #[no_mangle]
2118 /// Utility method to constructs a new CreationError-variant SignOrCreationError
2119 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
2120         SignOrCreationError::CreationError(a, )
2121 }
2122 /// Checks if two SignOrCreationErrors contain equal inner contents.
2123 /// This ignores pointers and is_owned flags and looks at the values in fields.
2124 #[no_mangle]
2125 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
2126         if &a.to_native() == &b.to_native() { true } else { false }
2127 }
2128 #[no_mangle]
2129 /// Get the string representation of a SignOrCreationError object
2130 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
2131         format!("{}", &o.to_native()).into()
2132 }