Update auto-generated bindings
[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/lightning/bolts/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 alloc::str::FromStr;
19 use core::ffi::c_void;
20 use core::convert::Infallible;
21 use bitcoin::hashes::Hash;
22 use crate::c_types::*;
23 #[cfg(feature="no-std")]
24 use alloc::{vec::Vec, boxed::Box};
25
26 pub mod payment;
27 pub mod utils;
28 pub mod constants;
29 mod time_utils {
30
31 use alloc::str::FromStr;
32 use core::ffi::c_void;
33 use core::convert::Infallible;
34 use bitcoin::hashes::Hash;
35 use crate::c_types::*;
36 #[cfg(feature="no-std")]
37 use alloc::{vec::Vec, boxed::Box};
38
39 }
40 mod de {
41
42 use alloc::str::FromStr;
43 use core::ffi::c_void;
44 use core::convert::Infallible;
45 use bitcoin::hashes::Hash;
46 use crate::c_types::*;
47 #[cfg(feature="no-std")]
48 use alloc::{vec::Vec, boxed::Box};
49
50 mod hrp_sm {
51
52 use alloc::str::FromStr;
53 use core::ffi::c_void;
54 use core::convert::Infallible;
55 use bitcoin::hashes::Hash;
56 use crate::c_types::*;
57 #[cfg(feature="no-std")]
58 use alloc::{vec::Vec, boxed::Box};
59
60 }
61 #[no_mangle]
62 /// Read a SiPrefix object from a string
63 pub extern "C" fn SiPrefix_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SiPrefixParseErrorZ {
64         match lightning_invoice::SiPrefix::from_str(s.into_str()) {
65                 Ok(r) => {
66                         crate::c_types::CResultTempl::ok(
67                                 crate::lightning_invoice::SiPrefix::native_into(r)
68                         )
69                 },
70                 Err(e) => {
71                         crate::c_types::CResultTempl::err(
72                                 crate::lightning_invoice::ParseError::native_into(e)
73                         )
74                 },
75         }.into()
76 }
77 #[no_mangle]
78 /// Read a Invoice object from a string
79 pub extern "C" fn Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_InvoiceParseOrSemanticErrorZ {
80         match lightning_invoice::Invoice::from_str(s.into_str()) {
81                 Ok(r) => {
82                         crate::c_types::CResultTempl::ok(
83                                 crate::lightning_invoice::Invoice { inner: ObjOps::heap_alloc(r), is_owned: true }
84                         )
85                 },
86                 Err(e) => {
87                         crate::c_types::CResultTempl::err(
88                                 crate::lightning_invoice::ParseOrSemanticError::native_into(e)
89                         )
90                 },
91         }.into()
92 }
93 #[no_mangle]
94 /// Read a SignedRawInvoice object from a string
95 pub extern "C" fn SignedRawInvoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SignedRawInvoiceParseErrorZ {
96         match lightning_invoice::SignedRawInvoice::from_str(s.into_str()) {
97                 Ok(r) => {
98                         crate::c_types::CResultTempl::ok(
99                                 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(r), is_owned: true }
100                         )
101                 },
102                 Err(e) => {
103                         crate::c_types::CResultTempl::err(
104                                 crate::lightning_invoice::ParseError::native_into(e)
105                         )
106                 },
107         }.into()
108 }
109 #[no_mangle]
110 /// Get the string representation of a ParseError object
111 pub extern "C" fn ParseError_to_str(o: &crate::lightning_invoice::ParseError) -> Str {
112         alloc::format!("{}", &o.to_native()).into()
113 }
114 #[no_mangle]
115 /// Get the string representation of a ParseOrSemanticError object
116 pub extern "C" fn ParseOrSemanticError_to_str(o: &crate::lightning_invoice::ParseOrSemanticError) -> Str {
117         alloc::format!("{}", &o.to_native()).into()
118 }
119 }
120 mod ser {
121
122 use alloc::str::FromStr;
123 use core::ffi::c_void;
124 use core::convert::Infallible;
125 use bitcoin::hashes::Hash;
126 use crate::c_types::*;
127 #[cfg(feature="no-std")]
128 use alloc::{vec::Vec, boxed::Box};
129
130 #[no_mangle]
131 /// Get the string representation of a Invoice object
132 pub extern "C" fn Invoice_to_str(o: &crate::lightning_invoice::Invoice) -> Str {
133         alloc::format!("{}", o.get_native_ref()).into()
134 }
135 #[no_mangle]
136 /// Get the string representation of a SignedRawInvoice object
137 pub extern "C" fn SignedRawInvoice_to_str(o: &crate::lightning_invoice::SignedRawInvoice) -> Str {
138         alloc::format!("{}", o.get_native_ref()).into()
139 }
140 #[no_mangle]
141 /// Get the string representation of a Currency object
142 pub extern "C" fn Currency_to_str(o: &crate::lightning_invoice::Currency) -> Str {
143         alloc::format!("{}", &o.to_native()).into()
144 }
145 #[no_mangle]
146 /// Get the string representation of a SiPrefix object
147 pub extern "C" fn SiPrefix_to_str(o: &crate::lightning_invoice::SiPrefix) -> Str {
148         alloc::format!("{}", &o.to_native()).into()
149 }
150 }
151 mod tb {
152
153 use alloc::str::FromStr;
154 use core::ffi::c_void;
155 use core::convert::Infallible;
156 use bitcoin::hashes::Hash;
157 use crate::c_types::*;
158 #[cfg(feature="no-std")]
159 use alloc::{vec::Vec, boxed::Box};
160
161 }
162 mod prelude {
163
164 use alloc::str::FromStr;
165 use core::ffi::c_void;
166 use core::convert::Infallible;
167 use bitcoin::hashes::Hash;
168 use crate::c_types::*;
169 #[cfg(feature="no-std")]
170 use alloc::{vec::Vec, boxed::Box};
171
172 }
173 mod sync {
174
175 use alloc::str::FromStr;
176 use core::ffi::c_void;
177 use core::convert::Infallible;
178 use bitcoin::hashes::Hash;
179 use crate::c_types::*;
180 #[cfg(feature="no-std")]
181 use alloc::{vec::Vec, boxed::Box};
182
183 }
184 /// Errors that indicate what is wrong with the invoice. They have some granularity for debug
185 /// reasons, but should generally result in an \"invalid BOLT11 invoice\" message for the user.
186 #[derive(Clone)]
187 #[must_use]
188 #[repr(C)]
189 pub enum ParseError {
190         Bech32Error(
191                 crate::c_types::Bech32Error),
192         ParseAmountError(
193                 crate::c_types::Error),
194         MalformedSignature(
195                 crate::c_types::Secp256k1Error),
196         BadPrefix,
197         UnknownCurrency,
198         UnknownSiPrefix,
199         MalformedHRP,
200         TooShortDataPart,
201         UnexpectedEndOfTaggedFields,
202         DescriptionDecodeError(
203                 crate::c_types::Error),
204         PaddingError,
205         IntegerOverflowError,
206         InvalidSegWitProgramLength,
207         InvalidPubKeyHashLength,
208         InvalidScriptHashLength,
209         InvalidRecoveryId,
210         InvalidSliceLength(
211                 crate::c_types::Str),
212         /// Not an error, but used internally to signal that a part of the invoice should be ignored
213         /// according to BOLT11
214         Skip,
215 }
216 use lightning_invoice::ParseError as ParseErrorImport;
217 pub(crate) type nativeParseError = ParseErrorImport;
218
219 impl ParseError {
220         #[allow(unused)]
221         pub(crate) fn to_native(&self) -> nativeParseError {
222                 match self {
223                         ParseError::Bech32Error (ref a, ) => {
224                                 let mut a_nonref = (*a).clone();
225                                 nativeParseError::Bech32Error (
226                                         a_nonref.into_rust(),
227                                 )
228                         },
229                         ParseError::ParseAmountError (ref a, ) => {
230                                 let mut a_nonref = (*a).clone();
231                                 nativeParseError::ParseAmountError (
232                                         u8::from_str_radix(" a", 10).unwrap_err() /*a_nonref*/,
233                                 )
234                         },
235                         ParseError::MalformedSignature (ref a, ) => {
236                                 let mut a_nonref = (*a).clone();
237                                 nativeParseError::MalformedSignature (
238                                         a_nonref.into_rust(),
239                                 )
240                         },
241                         ParseError::BadPrefix => nativeParseError::BadPrefix,
242                         ParseError::UnknownCurrency => nativeParseError::UnknownCurrency,
243                         ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix,
244                         ParseError::MalformedHRP => nativeParseError::MalformedHRP,
245                         ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
246                         ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
247                         ParseError::DescriptionDecodeError (ref a, ) => {
248                                 let mut a_nonref = (*a).clone();
249                                 nativeParseError::DescriptionDecodeError (
250                                         core::str::from_utf8(&[0xff]).unwrap_err() /*a_nonref*/,
251                                 )
252                         },
253                         ParseError::PaddingError => nativeParseError::PaddingError,
254                         ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError,
255                         ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength,
256                         ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength,
257                         ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
258                         ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
259                         ParseError::InvalidSliceLength (ref a, ) => {
260                                 let mut a_nonref = (*a).clone();
261                                 nativeParseError::InvalidSliceLength (
262                                         a_nonref.into_string(),
263                                 )
264                         },
265                         ParseError::Skip => nativeParseError::Skip,
266                 }
267         }
268         #[allow(unused)]
269         pub(crate) fn into_native(self) -> nativeParseError {
270                 match self {
271                         ParseError::Bech32Error (mut a, ) => {
272                                 nativeParseError::Bech32Error (
273                                         a.into_rust(),
274                                 )
275                         },
276                         ParseError::ParseAmountError (mut a, ) => {
277                                 nativeParseError::ParseAmountError (
278                                         u8::from_str_radix(" a", 10).unwrap_err() /*a*/,
279                                 )
280                         },
281                         ParseError::MalformedSignature (mut a, ) => {
282                                 nativeParseError::MalformedSignature (
283                                         a.into_rust(),
284                                 )
285                         },
286                         ParseError::BadPrefix => nativeParseError::BadPrefix,
287                         ParseError::UnknownCurrency => nativeParseError::UnknownCurrency,
288                         ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix,
289                         ParseError::MalformedHRP => nativeParseError::MalformedHRP,
290                         ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
291                         ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
292                         ParseError::DescriptionDecodeError (mut a, ) => {
293                                 nativeParseError::DescriptionDecodeError (
294                                         core::str::from_utf8(&[0xff]).unwrap_err() /*a*/,
295                                 )
296                         },
297                         ParseError::PaddingError => nativeParseError::PaddingError,
298                         ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError,
299                         ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength,
300                         ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength,
301                         ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
302                         ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
303                         ParseError::InvalidSliceLength (mut a, ) => {
304                                 nativeParseError::InvalidSliceLength (
305                                         a.into_string(),
306                                 )
307                         },
308                         ParseError::Skip => nativeParseError::Skip,
309                 }
310         }
311         #[allow(unused)]
312         pub(crate) fn from_native(native: &nativeParseError) -> Self {
313                 match native {
314                         nativeParseError::Bech32Error (ref a, ) => {
315                                 let mut a_nonref = (*a).clone();
316                                 ParseError::Bech32Error (
317                                         crate::c_types::Bech32Error::from_rust(a_nonref),
318                                 )
319                         },
320                         nativeParseError::ParseAmountError (ref a, ) => {
321                                 let mut a_nonref = (*a).clone();
322                                 ParseError::ParseAmountError (
323                                         crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
324                                 )
325                         },
326                         nativeParseError::MalformedSignature (ref a, ) => {
327                                 let mut a_nonref = (*a).clone();
328                                 ParseError::MalformedSignature (
329                                         crate::c_types::Secp256k1Error::from_rust(a_nonref),
330                                 )
331                         },
332                         nativeParseError::BadPrefix => ParseError::BadPrefix,
333                         nativeParseError::UnknownCurrency => ParseError::UnknownCurrency,
334                         nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix,
335                         nativeParseError::MalformedHRP => ParseError::MalformedHRP,
336                         nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
337                         nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
338                         nativeParseError::DescriptionDecodeError (ref a, ) => {
339                                 let mut a_nonref = (*a).clone();
340                                 ParseError::DescriptionDecodeError (
341                                         crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
342                                 )
343                         },
344                         nativeParseError::PaddingError => ParseError::PaddingError,
345                         nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError,
346                         nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength,
347                         nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength,
348                         nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
349                         nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
350                         nativeParseError::InvalidSliceLength (ref a, ) => {
351                                 let mut a_nonref = (*a).clone();
352                                 ParseError::InvalidSliceLength (
353                                         a_nonref.into(),
354                                 )
355                         },
356                         nativeParseError::Skip => ParseError::Skip,
357                 }
358         }
359         #[allow(unused)]
360         pub(crate) fn native_into(native: nativeParseError) -> Self {
361                 match native {
362                         nativeParseError::Bech32Error (mut a, ) => {
363                                 ParseError::Bech32Error (
364                                         crate::c_types::Bech32Error::from_rust(a),
365                                 )
366                         },
367                         nativeParseError::ParseAmountError (mut a, ) => {
368                                 ParseError::ParseAmountError (
369                                         crate::c_types::Error { _dummy: 0 } /*a*/,
370                                 )
371                         },
372                         nativeParseError::MalformedSignature (mut a, ) => {
373                                 ParseError::MalformedSignature (
374                                         crate::c_types::Secp256k1Error::from_rust(a),
375                                 )
376                         },
377                         nativeParseError::BadPrefix => ParseError::BadPrefix,
378                         nativeParseError::UnknownCurrency => ParseError::UnknownCurrency,
379                         nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix,
380                         nativeParseError::MalformedHRP => ParseError::MalformedHRP,
381                         nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
382                         nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
383                         nativeParseError::DescriptionDecodeError (mut a, ) => {
384                                 ParseError::DescriptionDecodeError (
385                                         crate::c_types::Error { _dummy: 0 } /*a*/,
386                                 )
387                         },
388                         nativeParseError::PaddingError => ParseError::PaddingError,
389                         nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError,
390                         nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength,
391                         nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength,
392                         nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
393                         nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
394                         nativeParseError::InvalidSliceLength (mut a, ) => {
395                                 ParseError::InvalidSliceLength (
396                                         a.into(),
397                                 )
398                         },
399                         nativeParseError::Skip => ParseError::Skip,
400                 }
401         }
402 }
403 /// Frees any resources used by the ParseError
404 #[no_mangle]
405 pub extern "C" fn ParseError_free(this_ptr: ParseError) { }
406 /// Creates a copy of the ParseError
407 #[no_mangle]
408 pub extern "C" fn ParseError_clone(orig: &ParseError) -> ParseError {
409         orig.clone()
410 }
411 #[no_mangle]
412 /// Utility method to constructs a new Bech32Error-variant ParseError
413 pub extern "C" fn ParseError_bech32_error(a: crate::c_types::Bech32Error) -> ParseError {
414         ParseError::Bech32Error(a, )
415 }
416 #[no_mangle]
417 /// Utility method to constructs a new ParseAmountError-variant ParseError
418 pub extern "C" fn ParseError_parse_amount_error(a: crate::c_types::Error) -> ParseError {
419         ParseError::ParseAmountError(a, )
420 }
421 #[no_mangle]
422 /// Utility method to constructs a new MalformedSignature-variant ParseError
423 pub extern "C" fn ParseError_malformed_signature(a: crate::c_types::Secp256k1Error) -> ParseError {
424         ParseError::MalformedSignature(a, )
425 }
426 #[no_mangle]
427 /// Utility method to constructs a new BadPrefix-variant ParseError
428 pub extern "C" fn ParseError_bad_prefix() -> ParseError {
429         ParseError::BadPrefix}
430 #[no_mangle]
431 /// Utility method to constructs a new UnknownCurrency-variant ParseError
432 pub extern "C" fn ParseError_unknown_currency() -> ParseError {
433         ParseError::UnknownCurrency}
434 #[no_mangle]
435 /// Utility method to constructs a new UnknownSiPrefix-variant ParseError
436 pub extern "C" fn ParseError_unknown_si_prefix() -> ParseError {
437         ParseError::UnknownSiPrefix}
438 #[no_mangle]
439 /// Utility method to constructs a new MalformedHRP-variant ParseError
440 pub extern "C" fn ParseError_malformed_hrp() -> ParseError {
441         ParseError::MalformedHRP}
442 #[no_mangle]
443 /// Utility method to constructs a new TooShortDataPart-variant ParseError
444 pub extern "C" fn ParseError_too_short_data_part() -> ParseError {
445         ParseError::TooShortDataPart}
446 #[no_mangle]
447 /// Utility method to constructs a new UnexpectedEndOfTaggedFields-variant ParseError
448 pub extern "C" fn ParseError_unexpected_end_of_tagged_fields() -> ParseError {
449         ParseError::UnexpectedEndOfTaggedFields}
450 #[no_mangle]
451 /// Utility method to constructs a new DescriptionDecodeError-variant ParseError
452 pub extern "C" fn ParseError_description_decode_error(a: crate::c_types::Error) -> ParseError {
453         ParseError::DescriptionDecodeError(a, )
454 }
455 #[no_mangle]
456 /// Utility method to constructs a new PaddingError-variant ParseError
457 pub extern "C" fn ParseError_padding_error() -> ParseError {
458         ParseError::PaddingError}
459 #[no_mangle]
460 /// Utility method to constructs a new IntegerOverflowError-variant ParseError
461 pub extern "C" fn ParseError_integer_overflow_error() -> ParseError {
462         ParseError::IntegerOverflowError}
463 #[no_mangle]
464 /// Utility method to constructs a new InvalidSegWitProgramLength-variant ParseError
465 pub extern "C" fn ParseError_invalid_seg_wit_program_length() -> ParseError {
466         ParseError::InvalidSegWitProgramLength}
467 #[no_mangle]
468 /// Utility method to constructs a new InvalidPubKeyHashLength-variant ParseError
469 pub extern "C" fn ParseError_invalid_pub_key_hash_length() -> ParseError {
470         ParseError::InvalidPubKeyHashLength}
471 #[no_mangle]
472 /// Utility method to constructs a new InvalidScriptHashLength-variant ParseError
473 pub extern "C" fn ParseError_invalid_script_hash_length() -> ParseError {
474         ParseError::InvalidScriptHashLength}
475 #[no_mangle]
476 /// Utility method to constructs a new InvalidRecoveryId-variant ParseError
477 pub extern "C" fn ParseError_invalid_recovery_id() -> ParseError {
478         ParseError::InvalidRecoveryId}
479 #[no_mangle]
480 /// Utility method to constructs a new InvalidSliceLength-variant ParseError
481 pub extern "C" fn ParseError_invalid_slice_length(a: crate::c_types::Str) -> ParseError {
482         ParseError::InvalidSliceLength(a, )
483 }
484 #[no_mangle]
485 /// Utility method to constructs a new Skip-variant ParseError
486 pub extern "C" fn ParseError_skip() -> ParseError {
487         ParseError::Skip}
488 /// Checks if two ParseErrors contain equal inner contents.
489 /// This ignores pointers and is_owned flags and looks at the values in fields.
490 #[no_mangle]
491 pub extern "C" fn ParseError_eq(a: &ParseError, b: &ParseError) -> bool {
492         if &a.to_native() == &b.to_native() { true } else { false }
493 }
494 /// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
495 /// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
496 /// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
497 #[derive(Clone)]
498 #[must_use]
499 #[repr(C)]
500 pub enum ParseOrSemanticError {
501         /// The invoice couldn't be decoded
502         ParseError(
503                 crate::lightning_invoice::ParseError),
504         /// The invoice could be decoded but violates the BOLT11 standard
505         SemanticError(
506                 crate::lightning_invoice::SemanticError),
507 }
508 use lightning_invoice::ParseOrSemanticError as ParseOrSemanticErrorImport;
509 pub(crate) type nativeParseOrSemanticError = ParseOrSemanticErrorImport;
510
511 impl ParseOrSemanticError {
512         #[allow(unused)]
513         pub(crate) fn to_native(&self) -> nativeParseOrSemanticError {
514                 match self {
515                         ParseOrSemanticError::ParseError (ref a, ) => {
516                                 let mut a_nonref = (*a).clone();
517                                 nativeParseOrSemanticError::ParseError (
518                                         a_nonref.into_native(),
519                                 )
520                         },
521                         ParseOrSemanticError::SemanticError (ref a, ) => {
522                                 let mut a_nonref = (*a).clone();
523                                 nativeParseOrSemanticError::SemanticError (
524                                         a_nonref.into_native(),
525                                 )
526                         },
527                 }
528         }
529         #[allow(unused)]
530         pub(crate) fn into_native(self) -> nativeParseOrSemanticError {
531                 match self {
532                         ParseOrSemanticError::ParseError (mut a, ) => {
533                                 nativeParseOrSemanticError::ParseError (
534                                         a.into_native(),
535                                 )
536                         },
537                         ParseOrSemanticError::SemanticError (mut a, ) => {
538                                 nativeParseOrSemanticError::SemanticError (
539                                         a.into_native(),
540                                 )
541                         },
542                 }
543         }
544         #[allow(unused)]
545         pub(crate) fn from_native(native: &nativeParseOrSemanticError) -> Self {
546                 match native {
547                         nativeParseOrSemanticError::ParseError (ref a, ) => {
548                                 let mut a_nonref = (*a).clone();
549                                 ParseOrSemanticError::ParseError (
550                                         crate::lightning_invoice::ParseError::native_into(a_nonref),
551                                 )
552                         },
553                         nativeParseOrSemanticError::SemanticError (ref a, ) => {
554                                 let mut a_nonref = (*a).clone();
555                                 ParseOrSemanticError::SemanticError (
556                                         crate::lightning_invoice::SemanticError::native_into(a_nonref),
557                                 )
558                         },
559                 }
560         }
561         #[allow(unused)]
562         pub(crate) fn native_into(native: nativeParseOrSemanticError) -> Self {
563                 match native {
564                         nativeParseOrSemanticError::ParseError (mut a, ) => {
565                                 ParseOrSemanticError::ParseError (
566                                         crate::lightning_invoice::ParseError::native_into(a),
567                                 )
568                         },
569                         nativeParseOrSemanticError::SemanticError (mut a, ) => {
570                                 ParseOrSemanticError::SemanticError (
571                                         crate::lightning_invoice::SemanticError::native_into(a),
572                                 )
573                         },
574                 }
575         }
576 }
577 /// Frees any resources used by the ParseOrSemanticError
578 #[no_mangle]
579 pub extern "C" fn ParseOrSemanticError_free(this_ptr: ParseOrSemanticError) { }
580 /// Creates a copy of the ParseOrSemanticError
581 #[no_mangle]
582 pub extern "C" fn ParseOrSemanticError_clone(orig: &ParseOrSemanticError) -> ParseOrSemanticError {
583         orig.clone()
584 }
585 #[no_mangle]
586 /// Utility method to constructs a new ParseError-variant ParseOrSemanticError
587 pub extern "C" fn ParseOrSemanticError_parse_error(a: crate::lightning_invoice::ParseError) -> ParseOrSemanticError {
588         ParseOrSemanticError::ParseError(a, )
589 }
590 #[no_mangle]
591 /// Utility method to constructs a new SemanticError-variant ParseOrSemanticError
592 pub extern "C" fn ParseOrSemanticError_semantic_error(a: crate::lightning_invoice::SemanticError) -> ParseOrSemanticError {
593         ParseOrSemanticError::SemanticError(a, )
594 }
595 /// Checks if two ParseOrSemanticErrors contain equal inner contents.
596 /// This ignores pointers and is_owned flags and looks at the values in fields.
597 #[no_mangle]
598 pub extern "C" fn ParseOrSemanticError_eq(a: &ParseOrSemanticError, b: &ParseOrSemanticError) -> bool {
599         if &a.to_native() == &b.to_native() { true } else { false }
600 }
601 /// The maximum timestamp as [`Duration::as_secs`] since the Unix epoch allowed by [`BOLT 11`].
602 ///
603 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
604
605 #[no_mangle]
606 pub static MAX_TIMESTAMP: u64 = lightning_invoice::MAX_TIMESTAMP;
607 /// Default expiry time as defined by [BOLT 11].
608 ///
609 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
610
611 #[no_mangle]
612 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
613 /// Default minimum final CLTV expiry as defined by [BOLT 11].
614 ///
615 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
616 /// provided in [`MIN_FINAL_CLTV_EXPIRY`].
617 ///
618 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
619 /// [`MIN_FINAL_CLTV_EXPIRY`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY
620
621 #[no_mangle]
622 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY;
623
624 use lightning_invoice::Invoice as nativeInvoiceImport;
625 pub(crate) type nativeInvoice = nativeInvoiceImport;
626
627 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
628 ///
629 /// There are three ways to construct an `Invoice`:
630 ///  1. using `InvoiceBuilder`
631 ///  2. using `Invoice::from_signed(SignedRawInvoice)`
632 ///  3. using `str::parse::<Invoice>(&str)`
633 #[must_use]
634 #[repr(C)]
635 pub struct Invoice {
636         /// A pointer to the opaque Rust object.
637
638         /// Nearly everywhere, inner must be non-null, however in places where
639         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
640         pub inner: *mut nativeInvoice,
641         /// Indicates that this is the only struct which contains the same pointer.
642
643         /// Rust functions which take ownership of an object provided via an argument require
644         /// this to be true and invalidate the object pointed to by inner.
645         pub is_owned: bool,
646 }
647
648 impl Drop for Invoice {
649         fn drop(&mut self) {
650                 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
651                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
652                 }
653         }
654 }
655 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
656 #[no_mangle]
657 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
658 #[allow(unused)]
659 /// Used only if an object of this type is returned as a trait impl by a method
660 pub(crate) extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
661         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
662 }
663 #[allow(unused)]
664 impl Invoice {
665         pub(crate) fn get_native_ref(&self) -> &'static nativeInvoice {
666                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
667         }
668         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoice {
669                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
670         }
671         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
672         pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
673                 assert!(self.is_owned);
674                 let ret = ObjOps::untweak_ptr(self.inner);
675                 self.inner = core::ptr::null_mut();
676                 ret
677         }
678 }
679 /// Checks if two Invoices contain equal inner contents.
680 /// This ignores pointers and is_owned flags and looks at the values in fields.
681 /// Two objects with NULL inner values will be considered "equal" here.
682 #[no_mangle]
683 pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool {
684         if a.inner == b.inner { return true; }
685         if a.inner.is_null() || b.inner.is_null() { return false; }
686         if a.get_native_ref() == b.get_native_ref() { true } else { false }
687 }
688 impl Clone for Invoice {
689         fn clone(&self) -> Self {
690                 Self {
691                         inner: if <*mut nativeInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
692                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
693                         is_owned: true,
694                 }
695         }
696 }
697 #[allow(unused)]
698 /// Used only if an object of this type is returned as a trait impl by a method
699 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
700         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
701 }
702 #[no_mangle]
703 /// Creates a copy of the Invoice
704 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
705         orig.clone()
706 }
707 /// Checks if two Invoices contain equal inner contents.
708 #[no_mangle]
709 pub extern "C" fn Invoice_hash(o: &Invoice) -> u64 {
710         if o.inner.is_null() { return 0; }
711         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
712         #[allow(deprecated)]
713         let mut hasher = core::hash::SipHasher::new();
714         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
715         core::hash::Hasher::finish(&hasher)
716 }
717
718 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
719 pub(crate) type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
720
721 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
722 /// invalid.
723 ///
724 /// # Invariants
725 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
726 #[must_use]
727 #[repr(C)]
728 pub struct SignedRawInvoice {
729         /// A pointer to the opaque Rust object.
730
731         /// Nearly everywhere, inner must be non-null, however in places where
732         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
733         pub inner: *mut nativeSignedRawInvoice,
734         /// Indicates that this is the only struct which contains the same pointer.
735
736         /// Rust functions which take ownership of an object provided via an argument require
737         /// this to be true and invalidate the object pointed to by inner.
738         pub is_owned: bool,
739 }
740
741 impl Drop for SignedRawInvoice {
742         fn drop(&mut self) {
743                 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
744                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
745                 }
746         }
747 }
748 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
749 #[no_mangle]
750 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
751 #[allow(unused)]
752 /// Used only if an object of this type is returned as a trait impl by a method
753 pub(crate) extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
754         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
755 }
756 #[allow(unused)]
757 impl SignedRawInvoice {
758         pub(crate) fn get_native_ref(&self) -> &'static nativeSignedRawInvoice {
759                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
760         }
761         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSignedRawInvoice {
762                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
763         }
764         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
765         pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
766                 assert!(self.is_owned);
767                 let ret = ObjOps::untweak_ptr(self.inner);
768                 self.inner = core::ptr::null_mut();
769                 ret
770         }
771 }
772 /// Checks if two SignedRawInvoices contain equal inner contents.
773 /// This ignores pointers and is_owned flags and looks at the values in fields.
774 /// Two objects with NULL inner values will be considered "equal" here.
775 #[no_mangle]
776 pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice) -> bool {
777         if a.inner == b.inner { return true; }
778         if a.inner.is_null() || b.inner.is_null() { return false; }
779         if a.get_native_ref() == b.get_native_ref() { true } else { false }
780 }
781 impl Clone for SignedRawInvoice {
782         fn clone(&self) -> Self {
783                 Self {
784                         inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
785                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
786                         is_owned: true,
787                 }
788         }
789 }
790 #[allow(unused)]
791 /// Used only if an object of this type is returned as a trait impl by a method
792 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
793         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
794 }
795 #[no_mangle]
796 /// Creates a copy of the SignedRawInvoice
797 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
798         orig.clone()
799 }
800 /// Checks if two SignedRawInvoices contain equal inner contents.
801 #[no_mangle]
802 pub extern "C" fn SignedRawInvoice_hash(o: &SignedRawInvoice) -> u64 {
803         if o.inner.is_null() { return 0; }
804         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
805         #[allow(deprecated)]
806         let mut hasher = core::hash::SipHasher::new();
807         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
808         core::hash::Hasher::finish(&hasher)
809 }
810
811 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
812 pub(crate) type nativeRawInvoice = nativeRawInvoiceImport;
813
814 /// Represents an syntactically correct Invoice for a payment on the lightning network,
815 /// but without the signature information.
816 /// De- and encoding should not lead to information loss but may lead to different hashes.
817 ///
818 /// For methods without docs see the corresponding methods in `Invoice`.
819 #[must_use]
820 #[repr(C)]
821 pub struct RawInvoice {
822         /// A pointer to the opaque Rust object.
823
824         /// Nearly everywhere, inner must be non-null, however in places where
825         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
826         pub inner: *mut nativeRawInvoice,
827         /// Indicates that this is the only struct which contains the same pointer.
828
829         /// Rust functions which take ownership of an object provided via an argument require
830         /// this to be true and invalidate the object pointed to by inner.
831         pub is_owned: bool,
832 }
833
834 impl Drop for RawInvoice {
835         fn drop(&mut self) {
836                 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
837                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
838                 }
839         }
840 }
841 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
842 #[no_mangle]
843 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
844 #[allow(unused)]
845 /// Used only if an object of this type is returned as a trait impl by a method
846 pub(crate) extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
847         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
848 }
849 #[allow(unused)]
850 impl RawInvoice {
851         pub(crate) fn get_native_ref(&self) -> &'static nativeRawInvoice {
852                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
853         }
854         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawInvoice {
855                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
856         }
857         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
858         pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
859                 assert!(self.is_owned);
860                 let ret = ObjOps::untweak_ptr(self.inner);
861                 self.inner = core::ptr::null_mut();
862                 ret
863         }
864 }
865 /// data part
866 #[no_mangle]
867 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
868         let mut inner_val = &mut this_ptr.get_native_mut_ref().data;
869         crate::lightning_invoice::RawDataPart { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::RawDataPart<>) as *mut _) }, is_owned: false }
870 }
871 /// data part
872 #[no_mangle]
873 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
874         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.data = *unsafe { Box::from_raw(val.take_inner()) };
875 }
876 /// Checks if two RawInvoices contain equal inner contents.
877 /// This ignores pointers and is_owned flags and looks at the values in fields.
878 /// Two objects with NULL inner values will be considered "equal" here.
879 #[no_mangle]
880 pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool {
881         if a.inner == b.inner { return true; }
882         if a.inner.is_null() || b.inner.is_null() { return false; }
883         if a.get_native_ref() == b.get_native_ref() { true } else { false }
884 }
885 impl Clone for RawInvoice {
886         fn clone(&self) -> Self {
887                 Self {
888                         inner: if <*mut nativeRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
889                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
890                         is_owned: true,
891                 }
892         }
893 }
894 #[allow(unused)]
895 /// Used only if an object of this type is returned as a trait impl by a method
896 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
897         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
898 }
899 #[no_mangle]
900 /// Creates a copy of the RawInvoice
901 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
902         orig.clone()
903 }
904 /// Checks if two RawInvoices contain equal inner contents.
905 #[no_mangle]
906 pub extern "C" fn RawInvoice_hash(o: &RawInvoice) -> u64 {
907         if o.inner.is_null() { return 0; }
908         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
909         #[allow(deprecated)]
910         let mut hasher = core::hash::SipHasher::new();
911         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
912         core::hash::Hasher::finish(&hasher)
913 }
914
915 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
916 pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
917
918 /// Data of the `RawInvoice` that is encoded in the data part
919 #[must_use]
920 #[repr(C)]
921 pub struct RawDataPart {
922         /// A pointer to the opaque Rust object.
923
924         /// Nearly everywhere, inner must be non-null, however in places where
925         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
926         pub inner: *mut nativeRawDataPart,
927         /// Indicates that this is the only struct which contains the same pointer.
928
929         /// Rust functions which take ownership of an object provided via an argument require
930         /// this to be true and invalidate the object pointed to by inner.
931         pub is_owned: bool,
932 }
933
934 impl Drop for RawDataPart {
935         fn drop(&mut self) {
936                 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
937                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
938                 }
939         }
940 }
941 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
942 #[no_mangle]
943 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
944 #[allow(unused)]
945 /// Used only if an object of this type is returned as a trait impl by a method
946 pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
947         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
948 }
949 #[allow(unused)]
950 impl RawDataPart {
951         pub(crate) fn get_native_ref(&self) -> &'static nativeRawDataPart {
952                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
953         }
954         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawDataPart {
955                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
956         }
957         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
958         pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
959                 assert!(self.is_owned);
960                 let ret = ObjOps::untweak_ptr(self.inner);
961                 self.inner = core::ptr::null_mut();
962                 ret
963         }
964 }
965 /// generation time of the invoice
966 #[no_mangle]
967 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
968         let mut inner_val = &mut this_ptr.get_native_mut_ref().timestamp;
969         crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::PositiveTimestamp<>) as *mut _) }, is_owned: false }
970 }
971 /// generation time of the invoice
972 #[no_mangle]
973 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
974         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
975 }
976 /// Checks if two RawDataParts contain equal inner contents.
977 /// This ignores pointers and is_owned flags and looks at the values in fields.
978 /// Two objects with NULL inner values will be considered "equal" here.
979 #[no_mangle]
980 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
981         if a.inner == b.inner { return true; }
982         if a.inner.is_null() || b.inner.is_null() { return false; }
983         if a.get_native_ref() == b.get_native_ref() { true } else { false }
984 }
985 impl Clone for RawDataPart {
986         fn clone(&self) -> Self {
987                 Self {
988                         inner: if <*mut nativeRawDataPart>::is_null(self.inner) { core::ptr::null_mut() } else {
989                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
990                         is_owned: true,
991                 }
992         }
993 }
994 #[allow(unused)]
995 /// Used only if an object of this type is returned as a trait impl by a method
996 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
997         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
998 }
999 #[no_mangle]
1000 /// Creates a copy of the RawDataPart
1001 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
1002         orig.clone()
1003 }
1004 /// Checks if two RawDataParts contain equal inner contents.
1005 #[no_mangle]
1006 pub extern "C" fn RawDataPart_hash(o: &RawDataPart) -> u64 {
1007         if o.inner.is_null() { return 0; }
1008         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1009         #[allow(deprecated)]
1010         let mut hasher = core::hash::SipHasher::new();
1011         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1012         core::hash::Hasher::finish(&hasher)
1013 }
1014
1015 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
1016 pub(crate) type nativePositiveTimestamp = nativePositiveTimestampImport;
1017
1018 /// A timestamp that refers to a date after 1 January 1970.
1019 ///
1020 /// # Invariants
1021 ///
1022 /// The Unix timestamp representing the stored time has to be positive and no greater than
1023 /// [`MAX_TIMESTAMP`].
1024 #[must_use]
1025 #[repr(C)]
1026 pub struct PositiveTimestamp {
1027         /// A pointer to the opaque Rust object.
1028
1029         /// Nearly everywhere, inner must be non-null, however in places where
1030         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1031         pub inner: *mut nativePositiveTimestamp,
1032         /// Indicates that this is the only struct which contains the same pointer.
1033
1034         /// Rust functions which take ownership of an object provided via an argument require
1035         /// this to be true and invalidate the object pointed to by inner.
1036         pub is_owned: bool,
1037 }
1038
1039 impl Drop for PositiveTimestamp {
1040         fn drop(&mut self) {
1041                 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
1042                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1043                 }
1044         }
1045 }
1046 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
1047 #[no_mangle]
1048 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
1049 #[allow(unused)]
1050 /// Used only if an object of this type is returned as a trait impl by a method
1051 pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
1052         unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
1053 }
1054 #[allow(unused)]
1055 impl PositiveTimestamp {
1056         pub(crate) fn get_native_ref(&self) -> &'static nativePositiveTimestamp {
1057                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1058         }
1059         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePositiveTimestamp {
1060                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1061         }
1062         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1063         pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
1064                 assert!(self.is_owned);
1065                 let ret = ObjOps::untweak_ptr(self.inner);
1066                 self.inner = core::ptr::null_mut();
1067                 ret
1068         }
1069 }
1070 /// Checks if two PositiveTimestamps contain equal inner contents.
1071 /// This ignores pointers and is_owned flags and looks at the values in fields.
1072 /// Two objects with NULL inner values will be considered "equal" here.
1073 #[no_mangle]
1074 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
1075         if a.inner == b.inner { return true; }
1076         if a.inner.is_null() || b.inner.is_null() { return false; }
1077         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1078 }
1079 impl Clone for PositiveTimestamp {
1080         fn clone(&self) -> Self {
1081                 Self {
1082                         inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { core::ptr::null_mut() } else {
1083                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1084                         is_owned: true,
1085                 }
1086         }
1087 }
1088 #[allow(unused)]
1089 /// Used only if an object of this type is returned as a trait impl by a method
1090 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
1091         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
1092 }
1093 #[no_mangle]
1094 /// Creates a copy of the PositiveTimestamp
1095 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
1096         orig.clone()
1097 }
1098 /// Checks if two PositiveTimestamps contain equal inner contents.
1099 #[no_mangle]
1100 pub extern "C" fn PositiveTimestamp_hash(o: &PositiveTimestamp) -> u64 {
1101         if o.inner.is_null() { return 0; }
1102         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1103         #[allow(deprecated)]
1104         let mut hasher = core::hash::SipHasher::new();
1105         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1106         core::hash::Hasher::finish(&hasher)
1107 }
1108 /// SI prefixes for the human readable part
1109 #[derive(Clone)]
1110 #[must_use]
1111 #[repr(C)]
1112 pub enum SiPrefix {
1113         /// 10^-3
1114         Milli,
1115         /// 10^-6
1116         Micro,
1117         /// 10^-9
1118         Nano,
1119         /// 10^-12
1120         Pico,
1121 }
1122 use lightning_invoice::SiPrefix as SiPrefixImport;
1123 pub(crate) type nativeSiPrefix = SiPrefixImport;
1124
1125 impl SiPrefix {
1126         #[allow(unused)]
1127         pub(crate) fn to_native(&self) -> nativeSiPrefix {
1128                 match self {
1129                         SiPrefix::Milli => nativeSiPrefix::Milli,
1130                         SiPrefix::Micro => nativeSiPrefix::Micro,
1131                         SiPrefix::Nano => nativeSiPrefix::Nano,
1132                         SiPrefix::Pico => nativeSiPrefix::Pico,
1133                 }
1134         }
1135         #[allow(unused)]
1136         pub(crate) fn into_native(self) -> nativeSiPrefix {
1137                 match self {
1138                         SiPrefix::Milli => nativeSiPrefix::Milli,
1139                         SiPrefix::Micro => nativeSiPrefix::Micro,
1140                         SiPrefix::Nano => nativeSiPrefix::Nano,
1141                         SiPrefix::Pico => nativeSiPrefix::Pico,
1142                 }
1143         }
1144         #[allow(unused)]
1145         pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
1146                 match native {
1147                         nativeSiPrefix::Milli => SiPrefix::Milli,
1148                         nativeSiPrefix::Micro => SiPrefix::Micro,
1149                         nativeSiPrefix::Nano => SiPrefix::Nano,
1150                         nativeSiPrefix::Pico => SiPrefix::Pico,
1151                 }
1152         }
1153         #[allow(unused)]
1154         pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
1155                 match native {
1156                         nativeSiPrefix::Milli => SiPrefix::Milli,
1157                         nativeSiPrefix::Micro => SiPrefix::Micro,
1158                         nativeSiPrefix::Nano => SiPrefix::Nano,
1159                         nativeSiPrefix::Pico => SiPrefix::Pico,
1160                 }
1161         }
1162 }
1163 /// Creates a copy of the SiPrefix
1164 #[no_mangle]
1165 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
1166         orig.clone()
1167 }
1168 #[no_mangle]
1169 /// Utility method to constructs a new Milli-variant SiPrefix
1170 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
1171         SiPrefix::Milli}
1172 #[no_mangle]
1173 /// Utility method to constructs a new Micro-variant SiPrefix
1174 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
1175         SiPrefix::Micro}
1176 #[no_mangle]
1177 /// Utility method to constructs a new Nano-variant SiPrefix
1178 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
1179         SiPrefix::Nano}
1180 #[no_mangle]
1181 /// Utility method to constructs a new Pico-variant SiPrefix
1182 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
1183         SiPrefix::Pico}
1184 /// Checks if two SiPrefixs contain equal inner contents.
1185 /// This ignores pointers and is_owned flags and looks at the values in fields.
1186 #[no_mangle]
1187 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
1188         if &a.to_native() == &b.to_native() { true } else { false }
1189 }
1190 /// Checks if two SiPrefixs contain equal inner contents.
1191 #[no_mangle]
1192 pub extern "C" fn SiPrefix_hash(o: &SiPrefix) -> u64 {
1193         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1194         #[allow(deprecated)]
1195         let mut hasher = core::hash::SipHasher::new();
1196         core::hash::Hash::hash(&o.to_native(), &mut hasher);
1197         core::hash::Hasher::finish(&hasher)
1198 }
1199 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
1200 /// This is effectively 10^12 * the prefix multiplier
1201 #[must_use]
1202 #[no_mangle]
1203 pub extern "C" fn SiPrefix_multiplier(this_arg: &crate::lightning_invoice::SiPrefix) -> u64 {
1204         let mut ret = this_arg.to_native().multiplier();
1205         ret
1206 }
1207
1208 /// Enum representing the crypto currencies (or networks) supported by this library
1209 #[derive(Clone)]
1210 #[must_use]
1211 #[repr(C)]
1212 pub enum Currency {
1213         /// Bitcoin mainnet
1214         Bitcoin,
1215         /// Bitcoin testnet
1216         BitcoinTestnet,
1217         /// Bitcoin regtest
1218         Regtest,
1219         /// Bitcoin simnet
1220         Simnet,
1221         /// Bitcoin signet
1222         Signet,
1223 }
1224 use lightning_invoice::Currency as CurrencyImport;
1225 pub(crate) type nativeCurrency = CurrencyImport;
1226
1227 impl Currency {
1228         #[allow(unused)]
1229         pub(crate) fn to_native(&self) -> nativeCurrency {
1230                 match self {
1231                         Currency::Bitcoin => nativeCurrency::Bitcoin,
1232                         Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1233                         Currency::Regtest => nativeCurrency::Regtest,
1234                         Currency::Simnet => nativeCurrency::Simnet,
1235                         Currency::Signet => nativeCurrency::Signet,
1236                 }
1237         }
1238         #[allow(unused)]
1239         pub(crate) fn into_native(self) -> nativeCurrency {
1240                 match self {
1241                         Currency::Bitcoin => nativeCurrency::Bitcoin,
1242                         Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1243                         Currency::Regtest => nativeCurrency::Regtest,
1244                         Currency::Simnet => nativeCurrency::Simnet,
1245                         Currency::Signet => nativeCurrency::Signet,
1246                 }
1247         }
1248         #[allow(unused)]
1249         pub(crate) fn from_native(native: &nativeCurrency) -> Self {
1250                 match native {
1251                         nativeCurrency::Bitcoin => Currency::Bitcoin,
1252                         nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1253                         nativeCurrency::Regtest => Currency::Regtest,
1254                         nativeCurrency::Simnet => Currency::Simnet,
1255                         nativeCurrency::Signet => Currency::Signet,
1256                 }
1257         }
1258         #[allow(unused)]
1259         pub(crate) fn native_into(native: nativeCurrency) -> Self {
1260                 match native {
1261                         nativeCurrency::Bitcoin => Currency::Bitcoin,
1262                         nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1263                         nativeCurrency::Regtest => Currency::Regtest,
1264                         nativeCurrency::Simnet => Currency::Simnet,
1265                         nativeCurrency::Signet => Currency::Signet,
1266                 }
1267         }
1268 }
1269 /// Creates a copy of the Currency
1270 #[no_mangle]
1271 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
1272         orig.clone()
1273 }
1274 #[no_mangle]
1275 /// Utility method to constructs a new Bitcoin-variant Currency
1276 pub extern "C" fn Currency_bitcoin() -> Currency {
1277         Currency::Bitcoin}
1278 #[no_mangle]
1279 /// Utility method to constructs a new BitcoinTestnet-variant Currency
1280 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
1281         Currency::BitcoinTestnet}
1282 #[no_mangle]
1283 /// Utility method to constructs a new Regtest-variant Currency
1284 pub extern "C" fn Currency_regtest() -> Currency {
1285         Currency::Regtest}
1286 #[no_mangle]
1287 /// Utility method to constructs a new Simnet-variant Currency
1288 pub extern "C" fn Currency_simnet() -> Currency {
1289         Currency::Simnet}
1290 #[no_mangle]
1291 /// Utility method to constructs a new Signet-variant Currency
1292 pub extern "C" fn Currency_signet() -> Currency {
1293         Currency::Signet}
1294 /// Checks if two Currencys contain equal inner contents.
1295 #[no_mangle]
1296 pub extern "C" fn Currency_hash(o: &Currency) -> u64 {
1297         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1298         #[allow(deprecated)]
1299         let mut hasher = core::hash::SipHasher::new();
1300         core::hash::Hash::hash(&o.to_native(), &mut hasher);
1301         core::hash::Hasher::finish(&hasher)
1302 }
1303 /// Checks if two Currencys contain equal inner contents.
1304 /// This ignores pointers and is_owned flags and looks at the values in fields.
1305 #[no_mangle]
1306 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
1307         if &a.to_native() == &b.to_native() { true } else { false }
1308 }
1309
1310 use lightning_invoice::Sha256 as nativeSha256Import;
1311 pub(crate) type nativeSha256 = nativeSha256Import;
1312
1313 /// SHA-256 hash
1314 #[must_use]
1315 #[repr(C)]
1316 pub struct Sha256 {
1317         /// A pointer to the opaque Rust object.
1318
1319         /// Nearly everywhere, inner must be non-null, however in places where
1320         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1321         pub inner: *mut nativeSha256,
1322         /// Indicates that this is the only struct which contains the same pointer.
1323
1324         /// Rust functions which take ownership of an object provided via an argument require
1325         /// this to be true and invalidate the object pointed to by inner.
1326         pub is_owned: bool,
1327 }
1328
1329 impl Drop for Sha256 {
1330         fn drop(&mut self) {
1331                 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
1332                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1333                 }
1334         }
1335 }
1336 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
1337 #[no_mangle]
1338 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
1339 #[allow(unused)]
1340 /// Used only if an object of this type is returned as a trait impl by a method
1341 pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
1342         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
1343 }
1344 #[allow(unused)]
1345 impl Sha256 {
1346         pub(crate) fn get_native_ref(&self) -> &'static nativeSha256 {
1347                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1348         }
1349         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSha256 {
1350                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1351         }
1352         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1353         pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
1354                 assert!(self.is_owned);
1355                 let ret = ObjOps::untweak_ptr(self.inner);
1356                 self.inner = core::ptr::null_mut();
1357                 ret
1358         }
1359 }
1360 impl Clone for Sha256 {
1361         fn clone(&self) -> Self {
1362                 Self {
1363                         inner: if <*mut nativeSha256>::is_null(self.inner) { core::ptr::null_mut() } else {
1364                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1365                         is_owned: true,
1366                 }
1367         }
1368 }
1369 #[allow(unused)]
1370 /// Used only if an object of this type is returned as a trait impl by a method
1371 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
1372         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
1373 }
1374 #[no_mangle]
1375 /// Creates a copy of the Sha256
1376 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
1377         orig.clone()
1378 }
1379 /// Checks if two Sha256s contain equal inner contents.
1380 #[no_mangle]
1381 pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 {
1382         if o.inner.is_null() { return 0; }
1383         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1384         #[allow(deprecated)]
1385         let mut hasher = core::hash::SipHasher::new();
1386         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1387         core::hash::Hasher::finish(&hasher)
1388 }
1389 /// Checks if two Sha256s contain equal inner contents.
1390 /// This ignores pointers and is_owned flags and looks at the values in fields.
1391 /// Two objects with NULL inner values will be considered "equal" here.
1392 #[no_mangle]
1393 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
1394         if a.inner == b.inner { return true; }
1395         if a.inner.is_null() || b.inner.is_null() { return false; }
1396         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1397 }
1398
1399 use lightning_invoice::Description as nativeDescriptionImport;
1400 pub(crate) type nativeDescription = nativeDescriptionImport;
1401
1402 /// Description string
1403 ///
1404 /// # Invariants
1405 /// The description can be at most 639 __bytes__ long
1406 #[must_use]
1407 #[repr(C)]
1408 pub struct Description {
1409         /// A pointer to the opaque Rust object.
1410
1411         /// Nearly everywhere, inner must be non-null, however in places where
1412         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1413         pub inner: *mut nativeDescription,
1414         /// Indicates that this is the only struct which contains the same pointer.
1415
1416         /// Rust functions which take ownership of an object provided via an argument require
1417         /// this to be true and invalidate the object pointed to by inner.
1418         pub is_owned: bool,
1419 }
1420
1421 impl Drop for Description {
1422         fn drop(&mut self) {
1423                 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
1424                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1425                 }
1426         }
1427 }
1428 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
1429 #[no_mangle]
1430 pub extern "C" fn Description_free(this_obj: Description) { }
1431 #[allow(unused)]
1432 /// Used only if an object of this type is returned as a trait impl by a method
1433 pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) {
1434         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
1435 }
1436 #[allow(unused)]
1437 impl Description {
1438         pub(crate) fn get_native_ref(&self) -> &'static nativeDescription {
1439                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1440         }
1441         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDescription {
1442                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1443         }
1444         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1445         pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
1446                 assert!(self.is_owned);
1447                 let ret = ObjOps::untweak_ptr(self.inner);
1448                 self.inner = core::ptr::null_mut();
1449                 ret
1450         }
1451 }
1452 impl Clone for Description {
1453         fn clone(&self) -> Self {
1454                 Self {
1455                         inner: if <*mut nativeDescription>::is_null(self.inner) { core::ptr::null_mut() } else {
1456                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1457                         is_owned: true,
1458                 }
1459         }
1460 }
1461 #[allow(unused)]
1462 /// Used only if an object of this type is returned as a trait impl by a method
1463 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
1464         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
1465 }
1466 #[no_mangle]
1467 /// Creates a copy of the Description
1468 pub extern "C" fn Description_clone(orig: &Description) -> Description {
1469         orig.clone()
1470 }
1471 /// Checks if two Descriptions contain equal inner contents.
1472 #[no_mangle]
1473 pub extern "C" fn Description_hash(o: &Description) -> u64 {
1474         if o.inner.is_null() { return 0; }
1475         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1476         #[allow(deprecated)]
1477         let mut hasher = core::hash::SipHasher::new();
1478         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1479         core::hash::Hasher::finish(&hasher)
1480 }
1481 /// Checks if two Descriptions contain equal inner contents.
1482 /// This ignores pointers and is_owned flags and looks at the values in fields.
1483 /// Two objects with NULL inner values will be considered "equal" here.
1484 #[no_mangle]
1485 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
1486         if a.inner == b.inner { return true; }
1487         if a.inner.is_null() || b.inner.is_null() { return false; }
1488         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1489 }
1490
1491 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
1492 pub(crate) type nativePayeePubKey = nativePayeePubKeyImport;
1493
1494 /// Payee public key
1495 #[must_use]
1496 #[repr(C)]
1497 pub struct PayeePubKey {
1498         /// A pointer to the opaque Rust object.
1499
1500         /// Nearly everywhere, inner must be non-null, however in places where
1501         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1502         pub inner: *mut nativePayeePubKey,
1503         /// Indicates that this is the only struct which contains the same pointer.
1504
1505         /// Rust functions which take ownership of an object provided via an argument require
1506         /// this to be true and invalidate the object pointed to by inner.
1507         pub is_owned: bool,
1508 }
1509
1510 impl Drop for PayeePubKey {
1511         fn drop(&mut self) {
1512                 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
1513                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1514                 }
1515         }
1516 }
1517 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
1518 #[no_mangle]
1519 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
1520 #[allow(unused)]
1521 /// Used only if an object of this type is returned as a trait impl by a method
1522 pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
1523         unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
1524 }
1525 #[allow(unused)]
1526 impl PayeePubKey {
1527         pub(crate) fn get_native_ref(&self) -> &'static nativePayeePubKey {
1528                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1529         }
1530         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayeePubKey {
1531                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1532         }
1533         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1534         pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
1535                 assert!(self.is_owned);
1536                 let ret = ObjOps::untweak_ptr(self.inner);
1537                 self.inner = core::ptr::null_mut();
1538                 ret
1539         }
1540 }
1541 #[no_mangle]
1542 pub extern "C" fn PayeePubKey_get_a(this_ptr: &PayeePubKey) -> crate::c_types::PublicKey {
1543         let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1544         crate::c_types::PublicKey::from_rust(&inner_val)
1545 }
1546 #[no_mangle]
1547 pub extern "C" fn PayeePubKey_set_a(this_ptr: &mut PayeePubKey, mut val: crate::c_types::PublicKey) {
1548         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
1549 }
1550 /// Constructs a new PayeePubKey given each field
1551 #[must_use]
1552 #[no_mangle]
1553 pub extern "C" fn PayeePubKey_new(mut a_arg: crate::c_types::PublicKey) -> PayeePubKey {
1554         PayeePubKey { inner: ObjOps::heap_alloc(lightning_invoice::PayeePubKey (
1555                 a_arg.into_rust(),
1556         )), is_owned: true }
1557 }
1558 impl Clone for PayeePubKey {
1559         fn clone(&self) -> Self {
1560                 Self {
1561                         inner: if <*mut nativePayeePubKey>::is_null(self.inner) { core::ptr::null_mut() } else {
1562                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(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 PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
1570         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
1571 }
1572 #[no_mangle]
1573 /// Creates a copy of the PayeePubKey
1574 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
1575         orig.clone()
1576 }
1577 /// Checks if two PayeePubKeys contain equal inner contents.
1578 #[no_mangle]
1579 pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 {
1580         if o.inner.is_null() { return 0; }
1581         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1582         #[allow(deprecated)]
1583         let mut hasher = core::hash::SipHasher::new();
1584         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1585         core::hash::Hasher::finish(&hasher)
1586 }
1587 /// Checks if two PayeePubKeys contain equal inner contents.
1588 /// This ignores pointers and is_owned flags and looks at the values in fields.
1589 /// Two objects with NULL inner values will be considered "equal" here.
1590 #[no_mangle]
1591 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
1592         if a.inner == b.inner { return true; }
1593         if a.inner.is_null() || b.inner.is_null() { return false; }
1594         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1595 }
1596
1597 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
1598 pub(crate) type nativeExpiryTime = nativeExpiryTimeImport;
1599
1600 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
1601 /// expires
1602 #[must_use]
1603 #[repr(C)]
1604 pub struct ExpiryTime {
1605         /// A pointer to the opaque Rust object.
1606
1607         /// Nearly everywhere, inner must be non-null, however in places where
1608         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1609         pub inner: *mut nativeExpiryTime,
1610         /// Indicates that this is the only struct which contains the same pointer.
1611
1612         /// Rust functions which take ownership of an object provided via an argument require
1613         /// this to be true and invalidate the object pointed to by inner.
1614         pub is_owned: bool,
1615 }
1616
1617 impl Drop for ExpiryTime {
1618         fn drop(&mut self) {
1619                 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
1620                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1621                 }
1622         }
1623 }
1624 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
1625 #[no_mangle]
1626 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
1627 #[allow(unused)]
1628 /// Used only if an object of this type is returned as a trait impl by a method
1629 pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
1630         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
1631 }
1632 #[allow(unused)]
1633 impl ExpiryTime {
1634         pub(crate) fn get_native_ref(&self) -> &'static nativeExpiryTime {
1635                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1636         }
1637         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpiryTime {
1638                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1639         }
1640         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1641         pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
1642                 assert!(self.is_owned);
1643                 let ret = ObjOps::untweak_ptr(self.inner);
1644                 self.inner = core::ptr::null_mut();
1645                 ret
1646         }
1647 }
1648 impl Clone for ExpiryTime {
1649         fn clone(&self) -> Self {
1650                 Self {
1651                         inner: if <*mut nativeExpiryTime>::is_null(self.inner) { core::ptr::null_mut() } else {
1652                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1653                         is_owned: true,
1654                 }
1655         }
1656 }
1657 #[allow(unused)]
1658 /// Used only if an object of this type is returned as a trait impl by a method
1659 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1660         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1661 }
1662 #[no_mangle]
1663 /// Creates a copy of the ExpiryTime
1664 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1665         orig.clone()
1666 }
1667 /// Checks if two ExpiryTimes contain equal inner contents.
1668 #[no_mangle]
1669 pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 {
1670         if o.inner.is_null() { return 0; }
1671         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1672         #[allow(deprecated)]
1673         let mut hasher = core::hash::SipHasher::new();
1674         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1675         core::hash::Hasher::finish(&hasher)
1676 }
1677 /// Checks if two ExpiryTimes contain equal inner contents.
1678 /// This ignores pointers and is_owned flags and looks at the values in fields.
1679 /// Two objects with NULL inner values will be considered "equal" here.
1680 #[no_mangle]
1681 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1682         if a.inner == b.inner { return true; }
1683         if a.inner.is_null() || b.inner.is_null() { return false; }
1684         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1685 }
1686
1687 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
1688 pub(crate) type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
1689
1690 /// `min_final_cltv_expiry` to use for the last HTLC in the route
1691 #[must_use]
1692 #[repr(C)]
1693 pub struct MinFinalCltvExpiry {
1694         /// A pointer to the opaque Rust object.
1695
1696         /// Nearly everywhere, inner must be non-null, however in places where
1697         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1698         pub inner: *mut nativeMinFinalCltvExpiry,
1699         /// Indicates that this is the only struct which contains the same pointer.
1700
1701         /// Rust functions which take ownership of an object provided via an argument require
1702         /// this to be true and invalidate the object pointed to by inner.
1703         pub is_owned: bool,
1704 }
1705
1706 impl Drop for MinFinalCltvExpiry {
1707         fn drop(&mut self) {
1708                 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
1709                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1710                 }
1711         }
1712 }
1713 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1714 #[no_mangle]
1715 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1716 #[allow(unused)]
1717 /// Used only if an object of this type is returned as a trait impl by a method
1718 pub(crate) extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1719         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1720 }
1721 #[allow(unused)]
1722 impl MinFinalCltvExpiry {
1723         pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiry {
1724                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1725         }
1726         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiry {
1727                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1728         }
1729         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1730         pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1731                 assert!(self.is_owned);
1732                 let ret = ObjOps::untweak_ptr(self.inner);
1733                 self.inner = core::ptr::null_mut();
1734                 ret
1735         }
1736 }
1737 #[no_mangle]
1738 pub extern "C" fn MinFinalCltvExpiry_get_a(this_ptr: &MinFinalCltvExpiry) -> u64 {
1739         let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1740         *inner_val
1741 }
1742 #[no_mangle]
1743 pub extern "C" fn MinFinalCltvExpiry_set_a(this_ptr: &mut MinFinalCltvExpiry, mut val: u64) {
1744         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val;
1745 }
1746 /// Constructs a new MinFinalCltvExpiry given each field
1747 #[must_use]
1748 #[no_mangle]
1749 pub extern "C" fn MinFinalCltvExpiry_new(mut a_arg: u64) -> MinFinalCltvExpiry {
1750         MinFinalCltvExpiry { inner: ObjOps::heap_alloc(lightning_invoice::MinFinalCltvExpiry (
1751                 a_arg,
1752         )), is_owned: true }
1753 }
1754 impl Clone for MinFinalCltvExpiry {
1755         fn clone(&self) -> Self {
1756                 Self {
1757                         inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { core::ptr::null_mut() } else {
1758                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1759                         is_owned: true,
1760                 }
1761         }
1762 }
1763 #[allow(unused)]
1764 /// Used only if an object of this type is returned as a trait impl by a method
1765 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1766         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1767 }
1768 #[no_mangle]
1769 /// Creates a copy of the MinFinalCltvExpiry
1770 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1771         orig.clone()
1772 }
1773 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1774 #[no_mangle]
1775 pub extern "C" fn MinFinalCltvExpiry_hash(o: &MinFinalCltvExpiry) -> u64 {
1776         if o.inner.is_null() { return 0; }
1777         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1778         #[allow(deprecated)]
1779         let mut hasher = core::hash::SipHasher::new();
1780         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1781         core::hash::Hasher::finish(&hasher)
1782 }
1783 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1784 /// This ignores pointers and is_owned flags and looks at the values in fields.
1785 /// Two objects with NULL inner values will be considered "equal" here.
1786 #[no_mangle]
1787 pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool {
1788         if a.inner == b.inner { return true; }
1789         if a.inner.is_null() || b.inner.is_null() { return false; }
1790         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1791 }
1792 /// Fallback address in case no LN payment is possible
1793 #[derive(Clone)]
1794 #[must_use]
1795 #[repr(C)]
1796 pub enum Fallback {
1797         SegWitProgram {
1798                 version: crate::c_types::u5,
1799                 program: crate::c_types::derived::CVec_u8Z,
1800         },
1801         PubKeyHash(
1802                 crate::c_types::TwentyBytes),
1803         ScriptHash(
1804                 crate::c_types::TwentyBytes),
1805 }
1806 use lightning_invoice::Fallback as FallbackImport;
1807 pub(crate) type nativeFallback = FallbackImport;
1808
1809 impl Fallback {
1810         #[allow(unused)]
1811         pub(crate) fn to_native(&self) -> nativeFallback {
1812                 match self {
1813                         Fallback::SegWitProgram {ref version, ref program, } => {
1814                                 let mut version_nonref = (*version).clone();
1815                                 let mut program_nonref = (*program).clone();
1816                                 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1817                                 nativeFallback::SegWitProgram {
1818                                         version: version_nonref.into(),
1819                                         program: local_program_nonref,
1820                                 }
1821                         },
1822                         Fallback::PubKeyHash (ref a, ) => {
1823                                 let mut a_nonref = (*a).clone();
1824                                 nativeFallback::PubKeyHash (
1825                                         a_nonref.data,
1826                                 )
1827                         },
1828                         Fallback::ScriptHash (ref a, ) => {
1829                                 let mut a_nonref = (*a).clone();
1830                                 nativeFallback::ScriptHash (
1831                                         a_nonref.data,
1832                                 )
1833                         },
1834                 }
1835         }
1836         #[allow(unused)]
1837         pub(crate) fn into_native(self) -> nativeFallback {
1838                 match self {
1839                         Fallback::SegWitProgram {mut version, mut program, } => {
1840                                 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1841                                 nativeFallback::SegWitProgram {
1842                                         version: version.into(),
1843                                         program: local_program,
1844                                 }
1845                         },
1846                         Fallback::PubKeyHash (mut a, ) => {
1847                                 nativeFallback::PubKeyHash (
1848                                         a.data,
1849                                 )
1850                         },
1851                         Fallback::ScriptHash (mut a, ) => {
1852                                 nativeFallback::ScriptHash (
1853                                         a.data,
1854                                 )
1855                         },
1856                 }
1857         }
1858         #[allow(unused)]
1859         pub(crate) fn from_native(native: &nativeFallback) -> Self {
1860                 match native {
1861                         nativeFallback::SegWitProgram {ref version, ref program, } => {
1862                                 let mut version_nonref = (*version).clone();
1863                                 let mut program_nonref = (*program).clone();
1864                                 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1865                                 Fallback::SegWitProgram {
1866                                         version: version_nonref.into(),
1867                                         program: local_program_nonref.into(),
1868                                 }
1869                         },
1870                         nativeFallback::PubKeyHash (ref a, ) => {
1871                                 let mut a_nonref = (*a).clone();
1872                                 Fallback::PubKeyHash (
1873                                         crate::c_types::TwentyBytes { data: a_nonref },
1874                                 )
1875                         },
1876                         nativeFallback::ScriptHash (ref a, ) => {
1877                                 let mut a_nonref = (*a).clone();
1878                                 Fallback::ScriptHash (
1879                                         crate::c_types::TwentyBytes { data: a_nonref },
1880                                 )
1881                         },
1882                 }
1883         }
1884         #[allow(unused)]
1885         pub(crate) fn native_into(native: nativeFallback) -> Self {
1886                 match native {
1887                         nativeFallback::SegWitProgram {mut version, mut program, } => {
1888                                 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1889                                 Fallback::SegWitProgram {
1890                                         version: version.into(),
1891                                         program: local_program.into(),
1892                                 }
1893                         },
1894                         nativeFallback::PubKeyHash (mut a, ) => {
1895                                 Fallback::PubKeyHash (
1896                                         crate::c_types::TwentyBytes { data: a },
1897                                 )
1898                         },
1899                         nativeFallback::ScriptHash (mut a, ) => {
1900                                 Fallback::ScriptHash (
1901                                         crate::c_types::TwentyBytes { data: a },
1902                                 )
1903                         },
1904                 }
1905         }
1906 }
1907 /// Frees any resources used by the Fallback
1908 #[no_mangle]
1909 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1910 /// Creates a copy of the Fallback
1911 #[no_mangle]
1912 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1913         orig.clone()
1914 }
1915 #[no_mangle]
1916 /// Utility method to constructs a new SegWitProgram-variant Fallback
1917 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::u5, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
1918         Fallback::SegWitProgram {
1919                 version,
1920                 program,
1921         }
1922 }
1923 #[no_mangle]
1924 /// Utility method to constructs a new PubKeyHash-variant Fallback
1925 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1926         Fallback::PubKeyHash(a, )
1927 }
1928 #[no_mangle]
1929 /// Utility method to constructs a new ScriptHash-variant Fallback
1930 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1931         Fallback::ScriptHash(a, )
1932 }
1933 /// Checks if two Fallbacks contain equal inner contents.
1934 #[no_mangle]
1935 pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 {
1936         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1937         #[allow(deprecated)]
1938         let mut hasher = core::hash::SipHasher::new();
1939         core::hash::Hash::hash(&o.to_native(), &mut hasher);
1940         core::hash::Hasher::finish(&hasher)
1941 }
1942 /// Checks if two Fallbacks contain equal inner contents.
1943 /// This ignores pointers and is_owned flags and looks at the values in fields.
1944 #[no_mangle]
1945 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1946         if &a.to_native() == &b.to_native() { true } else { false }
1947 }
1948
1949 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1950 pub(crate) type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1951
1952 /// Recoverable signature
1953 #[must_use]
1954 #[repr(C)]
1955 pub struct InvoiceSignature {
1956         /// A pointer to the opaque Rust object.
1957
1958         /// Nearly everywhere, inner must be non-null, however in places where
1959         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1960         pub inner: *mut nativeInvoiceSignature,
1961         /// Indicates that this is the only struct which contains the same pointer.
1962
1963         /// Rust functions which take ownership of an object provided via an argument require
1964         /// this to be true and invalidate the object pointed to by inner.
1965         pub is_owned: bool,
1966 }
1967
1968 impl Drop for InvoiceSignature {
1969         fn drop(&mut self) {
1970                 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1971                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1972                 }
1973         }
1974 }
1975 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1976 #[no_mangle]
1977 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1978 #[allow(unused)]
1979 /// Used only if an object of this type is returned as a trait impl by a method
1980 pub(crate) extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1981         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1982 }
1983 #[allow(unused)]
1984 impl InvoiceSignature {
1985         pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceSignature {
1986                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1987         }
1988         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceSignature {
1989                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1990         }
1991         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1992         pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1993                 assert!(self.is_owned);
1994                 let ret = ObjOps::untweak_ptr(self.inner);
1995                 self.inner = core::ptr::null_mut();
1996                 ret
1997         }
1998 }
1999 impl Clone for InvoiceSignature {
2000         fn clone(&self) -> Self {
2001                 Self {
2002                         inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { core::ptr::null_mut() } else {
2003                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2004                         is_owned: true,
2005                 }
2006         }
2007 }
2008 #[allow(unused)]
2009 /// Used only if an object of this type is returned as a trait impl by a method
2010 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
2011         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
2012 }
2013 #[no_mangle]
2014 /// Creates a copy of the InvoiceSignature
2015 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
2016         orig.clone()
2017 }
2018 /// Checks if two InvoiceSignatures contain equal inner contents.
2019 #[no_mangle]
2020 pub extern "C" fn InvoiceSignature_hash(o: &InvoiceSignature) -> u64 {
2021         if o.inner.is_null() { return 0; }
2022         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2023         #[allow(deprecated)]
2024         let mut hasher = core::hash::SipHasher::new();
2025         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2026         core::hash::Hasher::finish(&hasher)
2027 }
2028 /// Checks if two InvoiceSignatures contain equal inner contents.
2029 /// This ignores pointers and is_owned flags and looks at the values in fields.
2030 /// Two objects with NULL inner values will be considered "equal" here.
2031 #[no_mangle]
2032 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
2033         if a.inner == b.inner { return true; }
2034         if a.inner.is_null() || b.inner.is_null() { return false; }
2035         if a.get_native_ref() == b.get_native_ref() { true } else { false }
2036 }
2037
2038 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
2039 pub(crate) type nativePrivateRoute = nativePrivateRouteImport;
2040
2041 /// Private routing information
2042 ///
2043 /// # Invariants
2044 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
2045 ///
2046 #[must_use]
2047 #[repr(C)]
2048 pub struct PrivateRoute {
2049         /// A pointer to the opaque Rust object.
2050
2051         /// Nearly everywhere, inner must be non-null, however in places where
2052         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2053         pub inner: *mut nativePrivateRoute,
2054         /// Indicates that this is the only struct which contains the same pointer.
2055
2056         /// Rust functions which take ownership of an object provided via an argument require
2057         /// this to be true and invalidate the object pointed to by inner.
2058         pub is_owned: bool,
2059 }
2060
2061 impl Drop for PrivateRoute {
2062         fn drop(&mut self) {
2063                 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
2064                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2065                 }
2066         }
2067 }
2068 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
2069 #[no_mangle]
2070 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
2071 #[allow(unused)]
2072 /// Used only if an object of this type is returned as a trait impl by a method
2073 pub(crate) extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
2074         unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); }
2075 }
2076 #[allow(unused)]
2077 impl PrivateRoute {
2078         pub(crate) fn get_native_ref(&self) -> &'static nativePrivateRoute {
2079                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2080         }
2081         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateRoute {
2082                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2083         }
2084         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2085         pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
2086                 assert!(self.is_owned);
2087                 let ret = ObjOps::untweak_ptr(self.inner);
2088                 self.inner = core::ptr::null_mut();
2089                 ret
2090         }
2091 }
2092 impl Clone for PrivateRoute {
2093         fn clone(&self) -> Self {
2094                 Self {
2095                         inner: if <*mut nativePrivateRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
2096                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2097                         is_owned: true,
2098                 }
2099         }
2100 }
2101 #[allow(unused)]
2102 /// Used only if an object of this type is returned as a trait impl by a method
2103 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
2104         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
2105 }
2106 #[no_mangle]
2107 /// Creates a copy of the PrivateRoute
2108 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
2109         orig.clone()
2110 }
2111 /// Checks if two PrivateRoutes contain equal inner contents.
2112 #[no_mangle]
2113 pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 {
2114         if o.inner.is_null() { return 0; }
2115         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2116         #[allow(deprecated)]
2117         let mut hasher = core::hash::SipHasher::new();
2118         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2119         core::hash::Hasher::finish(&hasher)
2120 }
2121 /// Checks if two PrivateRoutes contain equal inner contents.
2122 /// This ignores pointers and is_owned flags and looks at the values in fields.
2123 /// Two objects with NULL inner values will be considered "equal" here.
2124 #[no_mangle]
2125 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
2126         if a.inner == b.inner { return true; }
2127         if a.inner.is_null() || b.inner.is_null() { return false; }
2128         if a.get_native_ref() == b.get_native_ref() { true } else { false }
2129 }
2130 /// Disassembles the `SignedRawInvoice` into its three parts:
2131 ///  1. raw invoice
2132 ///  2. hash of the raw invoice
2133 ///  3. signature
2134 #[must_use]
2135 #[no_mangle]
2136 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
2137         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
2138         let (mut orig_ret_0, mut orig_ret_1, mut orig_ret_2) = ret; let mut local_ret = (crate::lightning_invoice::RawInvoice { inner: ObjOps::heap_alloc(orig_ret_0), is_owned: true }, crate::c_types::ThirtyTwoBytes { data: orig_ret_1 }, crate::lightning_invoice::InvoiceSignature { inner: ObjOps::heap_alloc(orig_ret_2), is_owned: true }).into();
2139         local_ret
2140 }
2141
2142 /// The `RawInvoice` which was signed.
2143 #[must_use]
2144 #[no_mangle]
2145 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
2146         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice();
2147         crate::lightning_invoice::RawInvoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawInvoice<>) as *mut _) }, is_owned: false }
2148 }
2149
2150 /// The hash of the `RawInvoice` that was signed.
2151 #[must_use]
2152 #[no_mangle]
2153 pub extern "C" fn SignedRawInvoice_signable_hash(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> *const [u8; 32] {
2154         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2155         ret
2156 }
2157
2158 /// InvoiceSignature for the invoice.
2159 #[must_use]
2160 #[no_mangle]
2161 pub extern "C" fn SignedRawInvoice_signature(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
2162         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
2163         crate::lightning_invoice::InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::InvoiceSignature<>) as *mut _) }, is_owned: false }
2164 }
2165
2166 /// Recovers the public key used for signing the invoice from the recoverable signature.
2167 #[must_use]
2168 #[no_mangle]
2169 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
2170         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2171         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PayeePubKey { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
2172         local_ret
2173 }
2174
2175 /// Checks if the signature is valid for the included payee public key or if none exists if it's
2176 /// valid for the recovered signature (which should always be true?).
2177 #[must_use]
2178 #[no_mangle]
2179 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> bool {
2180         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2181         ret
2182 }
2183
2184 /// Calculate the hash of the encoded `RawInvoice` which should be signed.
2185 #[must_use]
2186 #[no_mangle]
2187 pub extern "C" fn RawInvoice_signable_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes {
2188         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2189         crate::c_types::ThirtyTwoBytes { data: ret }
2190 }
2191
2192 ///
2193 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2194 #[must_use]
2195 #[no_mangle]
2196 pub extern "C" fn RawInvoice_payment_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Sha256 {
2197         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2198         let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Sha256<>) as *mut _ }, is_owned: false };
2199         local_ret
2200 }
2201
2202 ///
2203 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2204 #[must_use]
2205 #[no_mangle]
2206 pub extern "C" fn RawInvoice_description(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Description {
2207         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
2208         let mut local_ret = crate::lightning_invoice::Description { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Description<>) as *mut _ }, is_owned: false };
2209         local_ret
2210 }
2211
2212 ///
2213 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2214 #[must_use]
2215 #[no_mangle]
2216 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::PayeePubKey {
2217         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2218         let mut local_ret = crate::lightning_invoice::PayeePubKey { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::PayeePubKey<>) as *mut _ }, is_owned: false };
2219         local_ret
2220 }
2221
2222 ///
2223 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2224 #[must_use]
2225 #[no_mangle]
2226 pub extern "C" fn RawInvoice_description_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Sha256 {
2227         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash();
2228         let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Sha256<>) as *mut _ }, is_owned: false };
2229         local_ret
2230 }
2231
2232 ///
2233 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2234 #[must_use]
2235 #[no_mangle]
2236 pub extern "C" fn RawInvoice_expiry_time(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::ExpiryTime {
2237         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2238         let mut local_ret = crate::lightning_invoice::ExpiryTime { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::ExpiryTime<>) as *mut _ }, is_owned: false };
2239         local_ret
2240 }
2241
2242 ///
2243 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2244 #[must_use]
2245 #[no_mangle]
2246 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
2247         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
2248         let mut local_ret = crate::lightning_invoice::MinFinalCltvExpiry { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::MinFinalCltvExpiry<>) as *mut _ }, is_owned: false };
2249         local_ret
2250 }
2251
2252 ///
2253 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2254 #[must_use]
2255 #[no_mangle]
2256 pub extern "C" fn RawInvoice_payment_secret(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes {
2257         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2258         let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else {  { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
2259         local_ret
2260 }
2261
2262 ///
2263 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2264 #[must_use]
2265 #[no_mangle]
2266 pub extern "C" fn RawInvoice_features(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
2267         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2268         let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::InvoiceFeatures<>) as *mut _ }, is_owned: false };
2269         local_ret
2270 }
2271
2272 #[must_use]
2273 #[no_mangle]
2274 pub extern "C" fn RawInvoice_private_routes(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2275         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2276         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning_invoice::PrivateRoute<>) as *mut _) }, is_owned: false } }); };
2277         local_ret.into()
2278 }
2279
2280 #[must_use]
2281 #[no_mangle]
2282 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::derived::COption_u64Z {
2283         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
2284         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() }) };
2285         local_ret
2286 }
2287
2288 #[must_use]
2289 #[no_mangle]
2290 pub extern "C" fn RawInvoice_currency(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Currency {
2291         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2292         crate::lightning_invoice::Currency::native_into(ret)
2293 }
2294
2295 /// Creates a `PositiveTimestamp` from a Unix timestamp in the range `0..=MAX_TIMESTAMP`.
2296 ///
2297 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2298 #[must_use]
2299 #[no_mangle]
2300 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2301         let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
2302         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
2303         local_ret
2304 }
2305
2306 /// Creates a `PositiveTimestamp` from a [`SystemTime`] with a corresponding Unix timestamp in
2307 /// the range `0..=MAX_TIMESTAMP`.
2308 ///
2309 /// Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
2310 ///
2311 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2312 #[must_use]
2313 #[no_mangle]
2314 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2315         let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
2316         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
2317         local_ret
2318 }
2319
2320 /// Creates a `PositiveTimestamp` from a [`Duration`] since the Unix epoch in the range
2321 /// `0..=MAX_TIMESTAMP`.
2322 ///
2323 /// Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
2324 ///
2325 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2326 #[must_use]
2327 #[no_mangle]
2328 pub extern "C" fn PositiveTimestamp_from_duration_since_epoch(mut duration: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2329         let mut ret = lightning_invoice::PositiveTimestamp::from_duration_since_epoch(core::time::Duration::from_secs(duration));
2330         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
2331         local_ret
2332 }
2333
2334 /// Returns the Unix timestamp representing the stored time
2335 #[must_use]
2336 #[no_mangle]
2337 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2338         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_unix_timestamp();
2339         ret
2340 }
2341
2342 /// Returns the duration of the stored time since the Unix epoch
2343 #[must_use]
2344 #[no_mangle]
2345 pub extern "C" fn PositiveTimestamp_as_duration_since_epoch(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2346         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration_since_epoch();
2347         ret.as_secs()
2348 }
2349
2350 /// Returns the [`SystemTime`] representing the stored time
2351 #[must_use]
2352 #[no_mangle]
2353 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2354         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_time();
2355         ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2356 }
2357
2358 /// Transform the `Invoice` into it's unchecked version
2359 #[must_use]
2360 #[no_mangle]
2361 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: crate::lightning_invoice::Invoice) -> crate::lightning_invoice::SignedRawInvoice {
2362         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
2363         crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(ret), is_owned: true }
2364 }
2365
2366 /// Check that the invoice is signed correctly and that key recovery works
2367 #[must_use]
2368 #[no_mangle]
2369 pub extern "C" fn Invoice_check_signature(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
2370         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2371         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::SemanticError::native_into(e) }).into() };
2372         local_ret
2373 }
2374
2375 /// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
2376 /// ```
2377 /// use lightning_invoice::*;
2378 ///
2379 /// let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
2380 /// h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
2381 /// 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
2382 /// h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
2383 /// j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
2384 /// ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
2385 /// guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
2386 /// ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
2387 /// p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
2388 /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
2389 /// j5r6drg6k6zcqj0fcwg\";
2390 ///
2391 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
2392 ///
2393 /// assert!(Invoice::from_signed(signed).is_ok());
2394 /// ```
2395 #[must_use]
2396 #[no_mangle]
2397 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
2398         let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
2399         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::Invoice { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::SemanticError::native_into(e) }).into() };
2400         local_ret
2401 }
2402
2403 /// Returns the `Invoice`'s timestamp (should equal its creation time)
2404 #[must_use]
2405 #[no_mangle]
2406 pub extern "C" fn Invoice_timestamp(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2407         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timestamp();
2408         ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2409 }
2410
2411 /// Returns the `Invoice`'s timestamp as a duration since the Unix epoch
2412 #[must_use]
2413 #[no_mangle]
2414 pub extern "C" fn Invoice_duration_since_epoch(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2415         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_since_epoch();
2416         ret.as_secs()
2417 }
2418
2419 /// Returns the hash to which we will receive the preimage on completion of the payment
2420 #[must_use]
2421 #[no_mangle]
2422 pub extern "C" fn Invoice_payment_hash(this_arg: &crate::lightning_invoice::Invoice) -> *const [u8; 32] {
2423         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2424         ret.as_inner()
2425 }
2426
2427 /// Get the payee's public key if one was included in the invoice
2428 ///
2429 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2430 #[must_use]
2431 #[no_mangle]
2432 pub extern "C" fn Invoice_payee_pub_key(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::PublicKey {
2433         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2434         let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else {  { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
2435         local_ret
2436 }
2437
2438 /// Get the payment secret if one was included in the invoice
2439 #[must_use]
2440 #[no_mangle]
2441 pub extern "C" fn Invoice_payment_secret(this_arg: &crate::lightning_invoice::Invoice) -> *const [u8; 32] {
2442         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2443         &ret.0
2444 }
2445
2446 /// Get the invoice features if they were included in the invoice
2447 ///
2448 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2449 #[must_use]
2450 #[no_mangle]
2451 pub extern "C" fn Invoice_features(this_arg: &crate::lightning_invoice::Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
2452         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2453         let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::InvoiceFeatures<>) as *mut _ }, is_owned: false };
2454         local_ret
2455 }
2456
2457 /// Recover the payee's public key (only to be used if none was included in the invoice)
2458 #[must_use]
2459 #[no_mangle]
2460 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::PublicKey {
2461         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2462         crate::c_types::PublicKey::from_rust(&ret)
2463 }
2464
2465 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
2466 #[must_use]
2467 #[no_mangle]
2468 pub extern "C" fn Invoice_expiry_time(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2469         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2470         ret.as_secs()
2471 }
2472
2473 /// Returns whether the invoice has expired.
2474 #[must_use]
2475 #[no_mangle]
2476 pub extern "C" fn Invoice_is_expired(this_arg: &crate::lightning_invoice::Invoice) -> bool {
2477         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
2478         ret
2479 }
2480
2481 /// Returns whether the expiry time would pass at the given point in time.
2482 /// `at_time` is the timestamp as a duration since the Unix epoch.
2483 #[must_use]
2484 #[no_mangle]
2485 pub extern "C" fn Invoice_would_expire(this_arg: &crate::lightning_invoice::Invoice, mut at_time: u64) -> bool {
2486         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.would_expire(core::time::Duration::from_secs(at_time));
2487         ret
2488 }
2489
2490 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
2491 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
2492 #[must_use]
2493 #[no_mangle]
2494 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2495         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
2496         ret
2497 }
2498
2499 /// Returns a list of all routes included in the invoice
2500 #[must_use]
2501 #[no_mangle]
2502 pub extern "C" fn Invoice_private_routes(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2503         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2504         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning_invoice::PrivateRoute<>) as *mut _) }, is_owned: false } }); };
2505         local_ret.into()
2506 }
2507
2508 /// Returns a list of all routes included in the invoice as the underlying hints
2509 #[must_use]
2510 #[no_mangle]
2511 pub extern "C" fn Invoice_route_hints(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
2512         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints();
2513         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
2514         local_ret.into()
2515 }
2516
2517 /// Returns the currency for which the invoice was issued
2518 #[must_use]
2519 #[no_mangle]
2520 pub extern "C" fn Invoice_currency(this_arg: &crate::lightning_invoice::Invoice) -> crate::lightning_invoice::Currency {
2521         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2522         crate::lightning_invoice::Currency::native_into(ret)
2523 }
2524
2525 /// Returns the amount if specified in the invoice as millisatoshis.
2526 #[must_use]
2527 #[no_mangle]
2528 pub extern "C" fn Invoice_amount_milli_satoshis(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::COption_u64Z {
2529         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_milli_satoshis();
2530         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() }) };
2531         local_ret
2532 }
2533
2534 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
2535 /// returns `CreationError::DescriptionTooLong` otherwise
2536 ///
2537 /// Please note that single characters may use more than one byte due to UTF8 encoding.
2538 #[must_use]
2539 #[no_mangle]
2540 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
2541         let mut ret = lightning_invoice::Description::new(description.into_string());
2542         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::Description { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
2543         local_ret
2544 }
2545
2546 /// Returns the underlying description `String`
2547 #[must_use]
2548 #[no_mangle]
2549 pub extern "C" fn Description_into_inner(mut this_arg: crate::lightning_invoice::Description) -> crate::c_types::Str {
2550         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2551         ret.into()
2552 }
2553
2554 /// Construct an `ExpiryTime` from seconds.
2555 #[must_use]
2556 #[no_mangle]
2557 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::lightning_invoice::ExpiryTime {
2558         let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
2559         crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2560 }
2561
2562 /// Construct an `ExpiryTime` from a `Duration`, dropping the sub-second part.
2563 #[must_use]
2564 #[no_mangle]
2565 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::lightning_invoice::ExpiryTime {
2566         let mut ret = lightning_invoice::ExpiryTime::from_duration(core::time::Duration::from_secs(duration));
2567         crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2568 }
2569
2570 /// Returns the expiry time in seconds
2571 #[must_use]
2572 #[no_mangle]
2573 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2574         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_seconds();
2575         ret
2576 }
2577
2578 /// Returns a reference to the underlying `Duration` (=expiry time)
2579 #[must_use]
2580 #[no_mangle]
2581 pub extern "C" fn ExpiryTime_as_duration(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2582         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration();
2583         ret.as_secs()
2584 }
2585
2586 /// Creates a new (partial) route from a list of hops
2587 #[must_use]
2588 #[no_mangle]
2589 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
2590         let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
2591         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PrivateRoute { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
2592         local_ret
2593 }
2594
2595 /// Returns the underlying list of hops
2596 #[must_use]
2597 #[no_mangle]
2598 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: crate::lightning_invoice::PrivateRoute) -> crate::lightning::routing::router::RouteHint {
2599         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2600         crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true }
2601 }
2602
2603 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
2604 #[derive(Clone)]
2605 #[must_use]
2606 #[repr(C)]
2607 pub enum CreationError {
2608         /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
2609         DescriptionTooLong,
2610         /// The specified route has too many hops and can't be encoded
2611         RouteTooLong,
2612         /// The Unix timestamp of the supplied date is less than zero or greater than 35-bits
2613         TimestampOutOfBounds,
2614         /// The supplied millisatoshi amount was greater than the total bitcoin supply.
2615         InvalidAmount,
2616         /// Route hints were required for this invoice and were missing. Applies to
2617         /// [phantom invoices].
2618         ///
2619         /// [phantom invoices]: crate::utils::create_phantom_invoice
2620         MissingRouteHints,
2621 }
2622 use lightning_invoice::CreationError as CreationErrorImport;
2623 pub(crate) type nativeCreationError = CreationErrorImport;
2624
2625 impl CreationError {
2626         #[allow(unused)]
2627         pub(crate) fn to_native(&self) -> nativeCreationError {
2628                 match self {
2629                         CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2630                         CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2631                         CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2632                         CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2633                         CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2634                 }
2635         }
2636         #[allow(unused)]
2637         pub(crate) fn into_native(self) -> nativeCreationError {
2638                 match self {
2639                         CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2640                         CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2641                         CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2642                         CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2643                         CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2644                 }
2645         }
2646         #[allow(unused)]
2647         pub(crate) fn from_native(native: &nativeCreationError) -> Self {
2648                 match native {
2649                         nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2650                         nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2651                         nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2652                         nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2653                         nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2654                 }
2655         }
2656         #[allow(unused)]
2657         pub(crate) fn native_into(native: nativeCreationError) -> Self {
2658                 match native {
2659                         nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2660                         nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2661                         nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2662                         nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2663                         nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2664                 }
2665         }
2666 }
2667 /// Creates a copy of the CreationError
2668 #[no_mangle]
2669 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
2670         orig.clone()
2671 }
2672 #[no_mangle]
2673 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
2674 pub extern "C" fn CreationError_description_too_long() -> CreationError {
2675         CreationError::DescriptionTooLong}
2676 #[no_mangle]
2677 /// Utility method to constructs a new RouteTooLong-variant CreationError
2678 pub extern "C" fn CreationError_route_too_long() -> CreationError {
2679         CreationError::RouteTooLong}
2680 #[no_mangle]
2681 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
2682 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
2683         CreationError::TimestampOutOfBounds}
2684 #[no_mangle]
2685 /// Utility method to constructs a new InvalidAmount-variant CreationError
2686 pub extern "C" fn CreationError_invalid_amount() -> CreationError {
2687         CreationError::InvalidAmount}
2688 #[no_mangle]
2689 /// Utility method to constructs a new MissingRouteHints-variant CreationError
2690 pub extern "C" fn CreationError_missing_route_hints() -> CreationError {
2691         CreationError::MissingRouteHints}
2692 /// Checks if two CreationErrors contain equal inner contents.
2693 /// This ignores pointers and is_owned flags and looks at the values in fields.
2694 #[no_mangle]
2695 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
2696         if &a.to_native() == &b.to_native() { true } else { false }
2697 }
2698 #[no_mangle]
2699 /// Get the string representation of a CreationError object
2700 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
2701         alloc::format!("{}", &o.to_native()).into()
2702 }
2703 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
2704 /// requirements sections in BOLT #11
2705 #[derive(Clone)]
2706 #[must_use]
2707 #[repr(C)]
2708 pub enum SemanticError {
2709         /// The invoice is missing the mandatory payment hash
2710         NoPaymentHash,
2711         /// The invoice has multiple payment hashes which isn't allowed
2712         MultiplePaymentHashes,
2713         /// No description or description hash are part of the invoice
2714         NoDescription,
2715         /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
2716         MultipleDescriptions,
2717         /// The invoice is missing the mandatory payment secret, which all modern lightning nodes
2718         /// should provide.
2719         NoPaymentSecret,
2720         /// The invoice contains multiple payment secrets
2721         MultiplePaymentSecrets,
2722         /// The invoice's features are invalid
2723         InvalidFeatures,
2724         /// The recovery id doesn't fit the signature/pub key
2725         InvalidRecoveryId,
2726         /// The invoice's signature is invalid
2727         InvalidSignature,
2728         /// The invoice's amount was not a whole number of millisatoshis
2729         ImpreciseAmount,
2730 }
2731 use lightning_invoice::SemanticError as SemanticErrorImport;
2732 pub(crate) type nativeSemanticError = SemanticErrorImport;
2733
2734 impl SemanticError {
2735         #[allow(unused)]
2736         pub(crate) fn to_native(&self) -> nativeSemanticError {
2737                 match self {
2738                         SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2739                         SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2740                         SemanticError::NoDescription => nativeSemanticError::NoDescription,
2741                         SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2742                         SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2743                         SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2744                         SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2745                         SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2746                         SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2747                         SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2748                 }
2749         }
2750         #[allow(unused)]
2751         pub(crate) fn into_native(self) -> nativeSemanticError {
2752                 match self {
2753                         SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2754                         SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2755                         SemanticError::NoDescription => nativeSemanticError::NoDescription,
2756                         SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2757                         SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2758                         SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2759                         SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2760                         SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2761                         SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2762                         SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2763                 }
2764         }
2765         #[allow(unused)]
2766         pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
2767                 match native {
2768                         nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2769                         nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2770                         nativeSemanticError::NoDescription => SemanticError::NoDescription,
2771                         nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2772                         nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2773                         nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2774                         nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2775                         nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2776                         nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2777                         nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2778                 }
2779         }
2780         #[allow(unused)]
2781         pub(crate) fn native_into(native: nativeSemanticError) -> Self {
2782                 match native {
2783                         nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2784                         nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2785                         nativeSemanticError::NoDescription => SemanticError::NoDescription,
2786                         nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2787                         nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2788                         nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2789                         nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2790                         nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2791                         nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2792                         nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2793                 }
2794         }
2795 }
2796 /// Creates a copy of the SemanticError
2797 #[no_mangle]
2798 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
2799         orig.clone()
2800 }
2801 #[no_mangle]
2802 /// Utility method to constructs a new NoPaymentHash-variant SemanticError
2803 pub extern "C" fn SemanticError_no_payment_hash() -> SemanticError {
2804         SemanticError::NoPaymentHash}
2805 #[no_mangle]
2806 /// Utility method to constructs a new MultiplePaymentHashes-variant SemanticError
2807 pub extern "C" fn SemanticError_multiple_payment_hashes() -> SemanticError {
2808         SemanticError::MultiplePaymentHashes}
2809 #[no_mangle]
2810 /// Utility method to constructs a new NoDescription-variant SemanticError
2811 pub extern "C" fn SemanticError_no_description() -> SemanticError {
2812         SemanticError::NoDescription}
2813 #[no_mangle]
2814 /// Utility method to constructs a new MultipleDescriptions-variant SemanticError
2815 pub extern "C" fn SemanticError_multiple_descriptions() -> SemanticError {
2816         SemanticError::MultipleDescriptions}
2817 #[no_mangle]
2818 /// Utility method to constructs a new NoPaymentSecret-variant SemanticError
2819 pub extern "C" fn SemanticError_no_payment_secret() -> SemanticError {
2820         SemanticError::NoPaymentSecret}
2821 #[no_mangle]
2822 /// Utility method to constructs a new MultiplePaymentSecrets-variant SemanticError
2823 pub extern "C" fn SemanticError_multiple_payment_secrets() -> SemanticError {
2824         SemanticError::MultiplePaymentSecrets}
2825 #[no_mangle]
2826 /// Utility method to constructs a new InvalidFeatures-variant SemanticError
2827 pub extern "C" fn SemanticError_invalid_features() -> SemanticError {
2828         SemanticError::InvalidFeatures}
2829 #[no_mangle]
2830 /// Utility method to constructs a new InvalidRecoveryId-variant SemanticError
2831 pub extern "C" fn SemanticError_invalid_recovery_id() -> SemanticError {
2832         SemanticError::InvalidRecoveryId}
2833 #[no_mangle]
2834 /// Utility method to constructs a new InvalidSignature-variant SemanticError
2835 pub extern "C" fn SemanticError_invalid_signature() -> SemanticError {
2836         SemanticError::InvalidSignature}
2837 #[no_mangle]
2838 /// Utility method to constructs a new ImpreciseAmount-variant SemanticError
2839 pub extern "C" fn SemanticError_imprecise_amount() -> SemanticError {
2840         SemanticError::ImpreciseAmount}
2841 /// Checks if two SemanticErrors contain equal inner contents.
2842 /// This ignores pointers and is_owned flags and looks at the values in fields.
2843 #[no_mangle]
2844 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
2845         if &a.to_native() == &b.to_native() { true } else { false }
2846 }
2847 #[no_mangle]
2848 /// Get the string representation of a SemanticError object
2849 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
2850         alloc::format!("{}", &o.to_native()).into()
2851 }
2852 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
2853 /// may occur.
2854 #[derive(Clone)]
2855 #[must_use]
2856 #[repr(C)]
2857 pub enum SignOrCreationError {
2858         /// An error occurred during signing
2859         SignError,
2860         /// An error occurred while building the transaction
2861         CreationError(
2862                 crate::lightning_invoice::CreationError),
2863 }
2864 use lightning_invoice::SignOrCreationError as SignOrCreationErrorImport;
2865 pub(crate) type nativeSignOrCreationError = SignOrCreationErrorImport<>;
2866
2867 impl SignOrCreationError {
2868         #[allow(unused)]
2869         pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
2870                 match self {
2871                         SignOrCreationError::SignError => {
2872                                 nativeSignOrCreationError::SignError (
2873                                         () /*a_nonref*/,
2874                                 )
2875                         },
2876                         SignOrCreationError::CreationError (ref a, ) => {
2877                                 let mut a_nonref = (*a).clone();
2878                                 nativeSignOrCreationError::CreationError (
2879                                         a_nonref.into_native(),
2880                                 )
2881                         },
2882                 }
2883         }
2884         #[allow(unused)]
2885         pub(crate) fn into_native(self) -> nativeSignOrCreationError {
2886                 match self {
2887                         SignOrCreationError::SignError => {
2888                                 nativeSignOrCreationError::SignError (
2889                                         () /*a*/,
2890                                 )
2891                         },
2892                         SignOrCreationError::CreationError (mut a, ) => {
2893                                 nativeSignOrCreationError::CreationError (
2894                                         a.into_native(),
2895                                 )
2896                         },
2897                 }
2898         }
2899         #[allow(unused)]
2900         pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
2901                 match native {
2902                         nativeSignOrCreationError::SignError (ref a, ) => {
2903                                 SignOrCreationError::SignError                  },
2904                         nativeSignOrCreationError::CreationError (ref a, ) => {
2905                                 let mut a_nonref = (*a).clone();
2906                                 SignOrCreationError::CreationError (
2907                                         crate::lightning_invoice::CreationError::native_into(a_nonref),
2908                                 )
2909                         },
2910                 }
2911         }
2912         #[allow(unused)]
2913         pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
2914                 match native {
2915                         nativeSignOrCreationError::SignError (mut a, ) => {
2916                                 SignOrCreationError::SignError                  },
2917                         nativeSignOrCreationError::CreationError (mut a, ) => {
2918                                 SignOrCreationError::CreationError (
2919                                         crate::lightning_invoice::CreationError::native_into(a),
2920                                 )
2921                         },
2922                 }
2923         }
2924 }
2925 /// Frees any resources used by the SignOrCreationError
2926 #[no_mangle]
2927 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
2928 /// Creates a copy of the SignOrCreationError
2929 #[no_mangle]
2930 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
2931         orig.clone()
2932 }
2933 #[no_mangle]
2934 /// Utility method to constructs a new SignError-variant SignOrCreationError
2935 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
2936         SignOrCreationError::SignError
2937 }
2938 #[no_mangle]
2939 /// Utility method to constructs a new CreationError-variant SignOrCreationError
2940 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
2941         SignOrCreationError::CreationError(a, )
2942 }
2943 /// Checks if two SignOrCreationErrors contain equal inner contents.
2944 /// This ignores pointers and is_owned flags and looks at the values in fields.
2945 #[no_mangle]
2946 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
2947         if &a.to_native() == &b.to_native() { true } else { false }
2948 }
2949 #[no_mangle]
2950 /// Get the string representation of a SignOrCreationError object
2951 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
2952         alloc::format!("{}", &o.to_native()).into()
2953 }