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