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