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