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