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