1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
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.
9 //! This crate provides data structures to represent
10 //! [lightning BOLT11](https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md)
11 //! invoices and functions to create, encode and decode these. If you just want to use the standard
12 //! en-/decoding functionality this should get you started:
14 //! * For parsing use `str::parse::<Invoice>(&self)` (see the docs of `impl FromStr for Invoice`)
15 //! * For constructing invoices use the `InvoiceBuilder`
16 //! * For serializing invoices use the `Display`/`ToString` traits
18 use alloc::str::FromStr;
19 use core::ffi::c_void;
20 use core::convert::Infallible;
21 use bitcoin::hashes::Hash;
22 use crate::c_types::*;
23 #[cfg(feature="no-std")]
24 use alloc::{vec::Vec, boxed::Box};
31 use alloc::str::FromStr;
32 use core::ffi::c_void;
33 use core::convert::Infallible;
34 use bitcoin::hashes::Hash;
35 use crate::c_types::*;
36 #[cfg(feature="no-std")]
37 use alloc::{vec::Vec, boxed::Box};
41 use alloc::str::FromStr;
42 use core::ffi::c_void;
43 use core::convert::Infallible;
44 use bitcoin::hashes::Hash;
45 use crate::c_types::*;
46 #[cfg(feature="no-std")]
47 use alloc::{vec::Vec, boxed::Box};
51 /// Read a SiPrefix object from a string
52 pub extern "C" fn SiPrefix_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SiPrefixParseErrorZ {
53 match lightning_invoice::SiPrefix::from_str(s.into_str()) {
55 crate::c_types::CResultTempl::ok(
56 crate::lightning_invoice::SiPrefix::native_into(r)
60 crate::c_types::CResultTempl::err(
61 crate::lightning_invoice::ParseError::native_into(e)
67 /// Read a Invoice object from a string
68 pub extern "C" fn Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_InvoiceParseOrSemanticErrorZ {
69 match lightning_invoice::Invoice::from_str(s.into_str()) {
71 crate::c_types::CResultTempl::ok(
72 crate::lightning_invoice::Invoice { inner: ObjOps::heap_alloc(r), is_owned: true }
76 crate::c_types::CResultTempl::err(
77 crate::lightning_invoice::ParseOrSemanticError::native_into(e)
83 /// Read a SignedRawInvoice object from a string
84 pub extern "C" fn SignedRawInvoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SignedRawInvoiceParseErrorZ {
85 match lightning_invoice::SignedRawInvoice::from_str(s.into_str()) {
87 crate::c_types::CResultTempl::ok(
88 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(r), is_owned: true }
92 crate::c_types::CResultTempl::err(
93 crate::lightning_invoice::ParseError::native_into(e)
99 /// Get the string representation of a ParseError object
100 pub extern "C" fn ParseError_to_str(o: &crate::lightning_invoice::ParseError) -> Str {
101 alloc::format!("{}", &o.to_native()).into()
104 /// Get the string representation of a ParseOrSemanticError object
105 pub extern "C" fn ParseOrSemanticError_to_str(o: &crate::lightning_invoice::ParseOrSemanticError) -> Str {
106 alloc::format!("{}", &o.to_native()).into()
111 use alloc::str::FromStr;
112 use core::ffi::c_void;
113 use core::convert::Infallible;
114 use bitcoin::hashes::Hash;
115 use crate::c_types::*;
116 #[cfg(feature="no-std")]
117 use alloc::{vec::Vec, boxed::Box};
120 /// Get the string representation of a Invoice object
121 pub extern "C" fn Invoice_to_str(o: &crate::lightning_invoice::Invoice) -> Str {
122 alloc::format!("{}", o.get_native_ref()).into()
125 /// Get the string representation of a SignedRawInvoice object
126 pub extern "C" fn SignedRawInvoice_to_str(o: &crate::lightning_invoice::SignedRawInvoice) -> Str {
127 alloc::format!("{}", o.get_native_ref()).into()
130 /// Get the string representation of a Currency object
131 pub extern "C" fn Currency_to_str(o: &crate::lightning_invoice::Currency) -> Str {
132 alloc::format!("{}", &o.to_native()).into()
135 /// Get the string representation of a SiPrefix object
136 pub extern "C" fn SiPrefix_to_str(o: &crate::lightning_invoice::SiPrefix) -> Str {
137 alloc::format!("{}", &o.to_native()).into()
142 use alloc::str::FromStr;
143 use core::ffi::c_void;
144 use core::convert::Infallible;
145 use bitcoin::hashes::Hash;
146 use crate::c_types::*;
147 #[cfg(feature="no-std")]
148 use alloc::{vec::Vec, boxed::Box};
153 use alloc::str::FromStr;
154 use core::ffi::c_void;
155 use core::convert::Infallible;
156 use bitcoin::hashes::Hash;
157 use crate::c_types::*;
158 #[cfg(feature="no-std")]
159 use alloc::{vec::Vec, boxed::Box};
164 use alloc::str::FromStr;
165 use core::ffi::c_void;
166 use core::convert::Infallible;
167 use bitcoin::hashes::Hash;
168 use crate::c_types::*;
169 #[cfg(feature="no-std")]
170 use alloc::{vec::Vec, boxed::Box};
173 /// Errors that indicate what is wrong with the invoice. They have some granularity for debug
174 /// reasons, but should generally result in an \"invalid BOLT11 invoice\" message for the user.
178 pub enum ParseError {
179 Bech32Error(crate::c_types::Bech32Error),
180 ParseAmountError(crate::c_types::Error),
181 MalformedSignature(crate::c_types::Secp256k1Error),
187 UnexpectedEndOfTaggedFields,
188 DescriptionDecodeError(crate::c_types::Error),
190 IntegerOverflowError,
191 InvalidSegWitProgramLength,
192 InvalidPubKeyHashLength,
193 InvalidScriptHashLength,
195 InvalidSliceLength(crate::c_types::Str),
196 /// Not an error, but used internally to signal that a part of the invoice should be ignored
197 /// according to BOLT11
200 use lightning_invoice::ParseError as nativeParseError;
203 pub(crate) fn to_native(&self) -> nativeParseError {
205 ParseError::Bech32Error (ref a, ) => {
206 let mut a_nonref = (*a).clone();
207 nativeParseError::Bech32Error (
208 a_nonref.into_rust(),
211 ParseError::ParseAmountError (ref a, ) => {
212 let mut a_nonref = (*a).clone();
213 nativeParseError::ParseAmountError (
214 u8::from_str_radix(" a", 10).unwrap_err() /*a_nonref*/,
217 ParseError::MalformedSignature (ref a, ) => {
218 let mut a_nonref = (*a).clone();
219 nativeParseError::MalformedSignature (
220 a_nonref.into_rust(),
223 ParseError::BadPrefix => nativeParseError::BadPrefix,
224 ParseError::UnknownCurrency => nativeParseError::UnknownCurrency,
225 ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix,
226 ParseError::MalformedHRP => nativeParseError::MalformedHRP,
227 ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
228 ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
229 ParseError::DescriptionDecodeError (ref a, ) => {
230 let mut a_nonref = (*a).clone();
231 nativeParseError::DescriptionDecodeError (
232 core::str::from_utf8(&[0xff]).unwrap_err() /*a_nonref*/,
235 ParseError::PaddingError => nativeParseError::PaddingError,
236 ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError,
237 ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength,
238 ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength,
239 ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
240 ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
241 ParseError::InvalidSliceLength (ref a, ) => {
242 let mut a_nonref = (*a).clone();
243 nativeParseError::InvalidSliceLength (
244 a_nonref.into_string(),
247 ParseError::Skip => nativeParseError::Skip,
251 pub(crate) fn into_native(self) -> nativeParseError {
253 ParseError::Bech32Error (mut a, ) => {
254 nativeParseError::Bech32Error (
258 ParseError::ParseAmountError (mut a, ) => {
259 nativeParseError::ParseAmountError (
260 u8::from_str_radix(" a", 10).unwrap_err() /*a*/,
263 ParseError::MalformedSignature (mut a, ) => {
264 nativeParseError::MalformedSignature (
268 ParseError::BadPrefix => nativeParseError::BadPrefix,
269 ParseError::UnknownCurrency => nativeParseError::UnknownCurrency,
270 ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix,
271 ParseError::MalformedHRP => nativeParseError::MalformedHRP,
272 ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
273 ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
274 ParseError::DescriptionDecodeError (mut a, ) => {
275 nativeParseError::DescriptionDecodeError (
276 core::str::from_utf8(&[0xff]).unwrap_err() /*a*/,
279 ParseError::PaddingError => nativeParseError::PaddingError,
280 ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError,
281 ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength,
282 ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength,
283 ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
284 ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
285 ParseError::InvalidSliceLength (mut a, ) => {
286 nativeParseError::InvalidSliceLength (
290 ParseError::Skip => nativeParseError::Skip,
294 pub(crate) fn from_native(native: &nativeParseError) -> Self {
296 nativeParseError::Bech32Error (ref a, ) => {
297 let mut a_nonref = (*a).clone();
298 ParseError::Bech32Error (
299 crate::c_types::Bech32Error::from_rust(a_nonref),
302 nativeParseError::ParseAmountError (ref a, ) => {
303 let mut a_nonref = (*a).clone();
304 ParseError::ParseAmountError (
305 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
308 nativeParseError::MalformedSignature (ref a, ) => {
309 let mut a_nonref = (*a).clone();
310 ParseError::MalformedSignature (
311 crate::c_types::Secp256k1Error::from_rust(a_nonref),
314 nativeParseError::BadPrefix => ParseError::BadPrefix,
315 nativeParseError::UnknownCurrency => ParseError::UnknownCurrency,
316 nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix,
317 nativeParseError::MalformedHRP => ParseError::MalformedHRP,
318 nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
319 nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
320 nativeParseError::DescriptionDecodeError (ref a, ) => {
321 let mut a_nonref = (*a).clone();
322 ParseError::DescriptionDecodeError (
323 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
326 nativeParseError::PaddingError => ParseError::PaddingError,
327 nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError,
328 nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength,
329 nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength,
330 nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
331 nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
332 nativeParseError::InvalidSliceLength (ref a, ) => {
333 let mut a_nonref = (*a).clone();
334 ParseError::InvalidSliceLength (
338 nativeParseError::Skip => ParseError::Skip,
342 pub(crate) fn native_into(native: nativeParseError) -> Self {
344 nativeParseError::Bech32Error (mut a, ) => {
345 ParseError::Bech32Error (
346 crate::c_types::Bech32Error::from_rust(a),
349 nativeParseError::ParseAmountError (mut a, ) => {
350 ParseError::ParseAmountError (
351 crate::c_types::Error { _dummy: 0 } /*a*/,
354 nativeParseError::MalformedSignature (mut a, ) => {
355 ParseError::MalformedSignature (
356 crate::c_types::Secp256k1Error::from_rust(a),
359 nativeParseError::BadPrefix => ParseError::BadPrefix,
360 nativeParseError::UnknownCurrency => ParseError::UnknownCurrency,
361 nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix,
362 nativeParseError::MalformedHRP => ParseError::MalformedHRP,
363 nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
364 nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
365 nativeParseError::DescriptionDecodeError (mut a, ) => {
366 ParseError::DescriptionDecodeError (
367 crate::c_types::Error { _dummy: 0 } /*a*/,
370 nativeParseError::PaddingError => ParseError::PaddingError,
371 nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError,
372 nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength,
373 nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength,
374 nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
375 nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
376 nativeParseError::InvalidSliceLength (mut a, ) => {
377 ParseError::InvalidSliceLength (
381 nativeParseError::Skip => ParseError::Skip,
385 /// Frees any resources used by the ParseError
387 pub extern "C" fn ParseError_free(this_ptr: ParseError) { }
388 /// Creates a copy of the ParseError
390 pub extern "C" fn ParseError_clone(orig: &ParseError) -> ParseError {
394 /// Utility method to constructs a new Bech32Error-variant ParseError
395 pub extern "C" fn ParseError_bech32_error(a: crate::c_types::Bech32Error) -> ParseError {
396 ParseError::Bech32Error(a, )
399 /// Utility method to constructs a new ParseAmountError-variant ParseError
400 pub extern "C" fn ParseError_parse_amount_error(a: crate::c_types::Error) -> ParseError {
401 ParseError::ParseAmountError(a, )
404 /// Utility method to constructs a new MalformedSignature-variant ParseError
405 pub extern "C" fn ParseError_malformed_signature(a: crate::c_types::Secp256k1Error) -> ParseError {
406 ParseError::MalformedSignature(a, )
409 /// Utility method to constructs a new BadPrefix-variant ParseError
410 pub extern "C" fn ParseError_bad_prefix() -> ParseError {
411 ParseError::BadPrefix}
413 /// Utility method to constructs a new UnknownCurrency-variant ParseError
414 pub extern "C" fn ParseError_unknown_currency() -> ParseError {
415 ParseError::UnknownCurrency}
417 /// Utility method to constructs a new UnknownSiPrefix-variant ParseError
418 pub extern "C" fn ParseError_unknown_si_prefix() -> ParseError {
419 ParseError::UnknownSiPrefix}
421 /// Utility method to constructs a new MalformedHRP-variant ParseError
422 pub extern "C" fn ParseError_malformed_hrp() -> ParseError {
423 ParseError::MalformedHRP}
425 /// Utility method to constructs a new TooShortDataPart-variant ParseError
426 pub extern "C" fn ParseError_too_short_data_part() -> ParseError {
427 ParseError::TooShortDataPart}
429 /// Utility method to constructs a new UnexpectedEndOfTaggedFields-variant ParseError
430 pub extern "C" fn ParseError_unexpected_end_of_tagged_fields() -> ParseError {
431 ParseError::UnexpectedEndOfTaggedFields}
433 /// Utility method to constructs a new DescriptionDecodeError-variant ParseError
434 pub extern "C" fn ParseError_description_decode_error(a: crate::c_types::Error) -> ParseError {
435 ParseError::DescriptionDecodeError(a, )
438 /// Utility method to constructs a new PaddingError-variant ParseError
439 pub extern "C" fn ParseError_padding_error() -> ParseError {
440 ParseError::PaddingError}
442 /// Utility method to constructs a new IntegerOverflowError-variant ParseError
443 pub extern "C" fn ParseError_integer_overflow_error() -> ParseError {
444 ParseError::IntegerOverflowError}
446 /// Utility method to constructs a new InvalidSegWitProgramLength-variant ParseError
447 pub extern "C" fn ParseError_invalid_seg_wit_program_length() -> ParseError {
448 ParseError::InvalidSegWitProgramLength}
450 /// Utility method to constructs a new InvalidPubKeyHashLength-variant ParseError
451 pub extern "C" fn ParseError_invalid_pub_key_hash_length() -> ParseError {
452 ParseError::InvalidPubKeyHashLength}
454 /// Utility method to constructs a new InvalidScriptHashLength-variant ParseError
455 pub extern "C" fn ParseError_invalid_script_hash_length() -> ParseError {
456 ParseError::InvalidScriptHashLength}
458 /// Utility method to constructs a new InvalidRecoveryId-variant ParseError
459 pub extern "C" fn ParseError_invalid_recovery_id() -> ParseError {
460 ParseError::InvalidRecoveryId}
462 /// Utility method to constructs a new InvalidSliceLength-variant ParseError
463 pub extern "C" fn ParseError_invalid_slice_length(a: crate::c_types::Str) -> ParseError {
464 ParseError::InvalidSliceLength(a, )
467 /// Utility method to constructs a new Skip-variant ParseError
468 pub extern "C" fn ParseError_skip() -> ParseError {
470 /// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
471 /// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
472 /// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
476 pub enum ParseOrSemanticError {
477 /// The invoice couldn't be decoded
478 ParseError(crate::lightning_invoice::ParseError),
479 /// The invoice could be decoded but violates the BOLT11 standard
480 SemanticError(crate::lightning_invoice::SemanticError),
482 use lightning_invoice::ParseOrSemanticError as nativeParseOrSemanticError;
483 impl ParseOrSemanticError {
485 pub(crate) fn to_native(&self) -> nativeParseOrSemanticError {
487 ParseOrSemanticError::ParseError (ref a, ) => {
488 let mut a_nonref = (*a).clone();
489 nativeParseOrSemanticError::ParseError (
490 a_nonref.into_native(),
493 ParseOrSemanticError::SemanticError (ref a, ) => {
494 let mut a_nonref = (*a).clone();
495 nativeParseOrSemanticError::SemanticError (
496 a_nonref.into_native(),
502 pub(crate) fn into_native(self) -> nativeParseOrSemanticError {
504 ParseOrSemanticError::ParseError (mut a, ) => {
505 nativeParseOrSemanticError::ParseError (
509 ParseOrSemanticError::SemanticError (mut a, ) => {
510 nativeParseOrSemanticError::SemanticError (
517 pub(crate) fn from_native(native: &nativeParseOrSemanticError) -> Self {
519 nativeParseOrSemanticError::ParseError (ref a, ) => {
520 let mut a_nonref = (*a).clone();
521 ParseOrSemanticError::ParseError (
522 crate::lightning_invoice::ParseError::native_into(a_nonref),
525 nativeParseOrSemanticError::SemanticError (ref a, ) => {
526 let mut a_nonref = (*a).clone();
527 ParseOrSemanticError::SemanticError (
528 crate::lightning_invoice::SemanticError::native_into(a_nonref),
534 pub(crate) fn native_into(native: nativeParseOrSemanticError) -> Self {
536 nativeParseOrSemanticError::ParseError (mut a, ) => {
537 ParseOrSemanticError::ParseError (
538 crate::lightning_invoice::ParseError::native_into(a),
541 nativeParseOrSemanticError::SemanticError (mut a, ) => {
542 ParseOrSemanticError::SemanticError (
543 crate::lightning_invoice::SemanticError::native_into(a),
549 /// Frees any resources used by the ParseOrSemanticError
551 pub extern "C" fn ParseOrSemanticError_free(this_ptr: ParseOrSemanticError) { }
552 /// Creates a copy of the ParseOrSemanticError
554 pub extern "C" fn ParseOrSemanticError_clone(orig: &ParseOrSemanticError) -> ParseOrSemanticError {
558 /// Utility method to constructs a new ParseError-variant ParseOrSemanticError
559 pub extern "C" fn ParseOrSemanticError_parse_error(a: crate::lightning_invoice::ParseError) -> ParseOrSemanticError {
560 ParseOrSemanticError::ParseError(a, )
563 /// Utility method to constructs a new SemanticError-variant ParseOrSemanticError
564 pub extern "C" fn ParseOrSemanticError_semantic_error(a: crate::lightning_invoice::SemanticError) -> ParseOrSemanticError {
565 ParseOrSemanticError::SemanticError(a, )
567 /// The maximum timestamp as [`Duration::as_secs`] since the Unix epoch allowed by [`BOLT 11`].
569 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
572 pub static MAX_TIMESTAMP: u64 = lightning_invoice::MAX_TIMESTAMP;
573 /// Default expiry time as defined by [BOLT 11].
575 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
578 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
579 /// Default minimum final CLTV expiry as defined by [BOLT 11].
581 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
582 /// provided in [`MIN_FINAL_CLTV_EXPIRY`].
584 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
585 /// [`MIN_FINAL_CLTV_EXPIRY`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY
588 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY;
590 use lightning_invoice::Invoice as nativeInvoiceImport;
591 pub(crate) type nativeInvoice = nativeInvoiceImport;
593 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
595 /// There are three ways to construct an `Invoice`:
596 /// 1. using `InvoiceBuilder`
597 /// 2. using `Invoice::from_signed(SignedRawInvoice)`
598 /// 3. using `str::parse::<Invoice>(&str)`
602 /// A pointer to the opaque Rust object.
604 /// Nearly everywhere, inner must be non-null, however in places where
605 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
606 pub inner: *mut nativeInvoice,
607 /// Indicates that this is the only struct which contains the same pointer.
609 /// Rust functions which take ownership of an object provided via an argument require
610 /// this to be true and invalidate the object pointed to by inner.
614 impl Drop for Invoice {
616 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
617 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
621 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
623 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
625 /// Used only if an object of this type is returned as a trait impl by a method
626 pub(crate) extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
627 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
631 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoice {
632 unsafe { &*ObjOps::untweak_ptr(self.inner) }
634 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoice {
635 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
637 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
638 pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
639 assert!(self.is_owned);
640 let ret = ObjOps::untweak_ptr(self.inner);
641 self.inner = core::ptr::null_mut();
645 /// Checks if two Invoices contain equal inner contents.
646 /// This ignores pointers and is_owned flags and looks at the values in fields.
647 /// Two objects with NULL inner values will be considered "equal" here.
649 pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool {
650 if a.inner == b.inner { return true; }
651 if a.inner.is_null() || b.inner.is_null() { return false; }
652 if a.get_native_ref() == b.get_native_ref() { true } else { false }
654 impl Clone for Invoice {
655 fn clone(&self) -> Self {
657 inner: if <*mut nativeInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
658 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
664 /// Used only if an object of this type is returned as a trait impl by a method
665 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
666 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
669 /// Creates a copy of the Invoice
670 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
674 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
675 pub(crate) type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
677 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
681 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
684 pub struct SignedRawInvoice {
685 /// A pointer to the opaque Rust object.
687 /// Nearly everywhere, inner must be non-null, however in places where
688 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
689 pub inner: *mut nativeSignedRawInvoice,
690 /// Indicates that this is the only struct which contains the same pointer.
692 /// Rust functions which take ownership of an object provided via an argument require
693 /// this to be true and invalidate the object pointed to by inner.
697 impl Drop for SignedRawInvoice {
699 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
700 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
704 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
706 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
708 /// Used only if an object of this type is returned as a trait impl by a method
709 pub(crate) extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
710 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
713 impl SignedRawInvoice {
714 pub(crate) fn get_native_ref(&self) -> &'static nativeSignedRawInvoice {
715 unsafe { &*ObjOps::untweak_ptr(self.inner) }
717 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSignedRawInvoice {
718 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
720 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
721 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
722 assert!(self.is_owned);
723 let ret = ObjOps::untweak_ptr(self.inner);
724 self.inner = core::ptr::null_mut();
728 /// Checks if two SignedRawInvoices contain equal inner contents.
729 /// This ignores pointers and is_owned flags and looks at the values in fields.
730 /// Two objects with NULL inner values will be considered "equal" here.
732 pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice) -> bool {
733 if a.inner == b.inner { return true; }
734 if a.inner.is_null() || b.inner.is_null() { return false; }
735 if a.get_native_ref() == b.get_native_ref() { true } else { false }
737 impl Clone for SignedRawInvoice {
738 fn clone(&self) -> Self {
740 inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
741 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
747 /// Used only if an object of this type is returned as a trait impl by a method
748 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
749 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
752 /// Creates a copy of the SignedRawInvoice
753 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
757 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
758 pub(crate) type nativeRawInvoice = nativeRawInvoiceImport;
760 /// Represents an syntactically correct Invoice for a payment on the lightning network,
761 /// but without the signature information.
762 /// De- and encoding should not lead to information loss but may lead to different hashes.
764 /// For methods without docs see the corresponding methods in `Invoice`.
767 pub struct RawInvoice {
768 /// A pointer to the opaque Rust object.
770 /// Nearly everywhere, inner must be non-null, however in places where
771 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
772 pub inner: *mut nativeRawInvoice,
773 /// Indicates that this is the only struct which contains the same pointer.
775 /// Rust functions which take ownership of an object provided via an argument require
776 /// this to be true and invalidate the object pointed to by inner.
780 impl Drop for RawInvoice {
782 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
783 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
787 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
789 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
791 /// Used only if an object of this type is returned as a trait impl by a method
792 pub(crate) extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
793 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
797 pub(crate) fn get_native_ref(&self) -> &'static nativeRawInvoice {
798 unsafe { &*ObjOps::untweak_ptr(self.inner) }
800 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawInvoice {
801 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
803 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
804 pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
805 assert!(self.is_owned);
806 let ret = ObjOps::untweak_ptr(self.inner);
807 self.inner = core::ptr::null_mut();
813 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
814 let mut inner_val = &mut this_ptr.get_native_mut_ref().data;
815 crate::lightning_invoice::RawDataPart { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::RawDataPart<>) as *mut _) }, is_owned: false }
819 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
820 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.data = *unsafe { Box::from_raw(val.take_inner()) };
822 /// Checks if two RawInvoices contain equal inner contents.
823 /// This ignores pointers and is_owned flags and looks at the values in fields.
824 /// Two objects with NULL inner values will be considered "equal" here.
826 pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool {
827 if a.inner == b.inner { return true; }
828 if a.inner.is_null() || b.inner.is_null() { return false; }
829 if a.get_native_ref() == b.get_native_ref() { true } else { false }
831 impl Clone for RawInvoice {
832 fn clone(&self) -> Self {
834 inner: if <*mut nativeRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
835 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
841 /// Used only if an object of this type is returned as a trait impl by a method
842 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
843 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
846 /// Creates a copy of the RawInvoice
847 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
851 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
852 pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
854 /// Data of the `RawInvoice` that is encoded in the data part
857 pub struct RawDataPart {
858 /// A pointer to the opaque Rust object.
860 /// Nearly everywhere, inner must be non-null, however in places where
861 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
862 pub inner: *mut nativeRawDataPart,
863 /// Indicates that this is the only struct which contains the same pointer.
865 /// Rust functions which take ownership of an object provided via an argument require
866 /// this to be true and invalidate the object pointed to by inner.
870 impl Drop for RawDataPart {
872 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
873 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
877 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
879 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
881 /// Used only if an object of this type is returned as a trait impl by a method
882 pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
883 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
887 pub(crate) fn get_native_ref(&self) -> &'static nativeRawDataPart {
888 unsafe { &*ObjOps::untweak_ptr(self.inner) }
890 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawDataPart {
891 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
893 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
894 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
895 assert!(self.is_owned);
896 let ret = ObjOps::untweak_ptr(self.inner);
897 self.inner = core::ptr::null_mut();
901 /// generation time of the invoice
903 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
904 let mut inner_val = &mut this_ptr.get_native_mut_ref().timestamp;
905 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::PositiveTimestamp<>) as *mut _) }, is_owned: false }
907 /// generation time of the invoice
909 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
910 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
912 /// Checks if two RawDataParts contain equal inner contents.
913 /// This ignores pointers and is_owned flags and looks at the values in fields.
914 /// Two objects with NULL inner values will be considered "equal" here.
916 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
917 if a.inner == b.inner { return true; }
918 if a.inner.is_null() || b.inner.is_null() { return false; }
919 if a.get_native_ref() == b.get_native_ref() { true } else { false }
921 impl Clone for RawDataPart {
922 fn clone(&self) -> Self {
924 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { core::ptr::null_mut() } else {
925 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
931 /// Used only if an object of this type is returned as a trait impl by a method
932 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
933 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
936 /// Creates a copy of the RawDataPart
937 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
941 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
942 pub(crate) type nativePositiveTimestamp = nativePositiveTimestampImport;
944 /// A timestamp that refers to a date after 1 January 1970.
948 /// The Unix timestamp representing the stored time has to be positive and no greater than
949 /// [`MAX_TIMESTAMP`].
952 pub struct PositiveTimestamp {
953 /// A pointer to the opaque Rust object.
955 /// Nearly everywhere, inner must be non-null, however in places where
956 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
957 pub inner: *mut nativePositiveTimestamp,
958 /// Indicates that this is the only struct which contains the same pointer.
960 /// Rust functions which take ownership of an object provided via an argument require
961 /// this to be true and invalidate the object pointed to by inner.
965 impl Drop for PositiveTimestamp {
967 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
968 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
972 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
974 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
976 /// Used only if an object of this type is returned as a trait impl by a method
977 pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
978 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
981 impl PositiveTimestamp {
982 pub(crate) fn get_native_ref(&self) -> &'static nativePositiveTimestamp {
983 unsafe { &*ObjOps::untweak_ptr(self.inner) }
985 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePositiveTimestamp {
986 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
988 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
989 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
990 assert!(self.is_owned);
991 let ret = ObjOps::untweak_ptr(self.inner);
992 self.inner = core::ptr::null_mut();
996 /// Checks if two PositiveTimestamps contain equal inner contents.
997 /// This ignores pointers and is_owned flags and looks at the values in fields.
998 /// Two objects with NULL inner values will be considered "equal" here.
1000 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
1001 if a.inner == b.inner { return true; }
1002 if a.inner.is_null() || b.inner.is_null() { return false; }
1003 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1005 impl Clone for PositiveTimestamp {
1006 fn clone(&self) -> Self {
1008 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { core::ptr::null_mut() } else {
1009 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1015 /// Used only if an object of this type is returned as a trait impl by a method
1016 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
1017 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
1020 /// Creates a copy of the PositiveTimestamp
1021 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
1024 /// SI prefixes for the human readable part
1038 use lightning_invoice::SiPrefix as nativeSiPrefix;
1041 pub(crate) fn to_native(&self) -> nativeSiPrefix {
1043 SiPrefix::Milli => nativeSiPrefix::Milli,
1044 SiPrefix::Micro => nativeSiPrefix::Micro,
1045 SiPrefix::Nano => nativeSiPrefix::Nano,
1046 SiPrefix::Pico => nativeSiPrefix::Pico,
1050 pub(crate) fn into_native(self) -> nativeSiPrefix {
1052 SiPrefix::Milli => nativeSiPrefix::Milli,
1053 SiPrefix::Micro => nativeSiPrefix::Micro,
1054 SiPrefix::Nano => nativeSiPrefix::Nano,
1055 SiPrefix::Pico => nativeSiPrefix::Pico,
1059 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
1061 nativeSiPrefix::Milli => SiPrefix::Milli,
1062 nativeSiPrefix::Micro => SiPrefix::Micro,
1063 nativeSiPrefix::Nano => SiPrefix::Nano,
1064 nativeSiPrefix::Pico => SiPrefix::Pico,
1068 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
1070 nativeSiPrefix::Milli => SiPrefix::Milli,
1071 nativeSiPrefix::Micro => SiPrefix::Micro,
1072 nativeSiPrefix::Nano => SiPrefix::Nano,
1073 nativeSiPrefix::Pico => SiPrefix::Pico,
1077 /// Creates a copy of the SiPrefix
1079 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
1083 /// Utility method to constructs a new Milli-variant SiPrefix
1084 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
1087 /// Utility method to constructs a new Micro-variant SiPrefix
1088 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
1091 /// Utility method to constructs a new Nano-variant SiPrefix
1092 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
1095 /// Utility method to constructs a new Pico-variant SiPrefix
1096 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
1098 /// Checks if two SiPrefixs contain equal inner contents.
1099 /// This ignores pointers and is_owned flags and looks at the values in fields.
1101 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
1102 if &a.to_native() == &b.to_native() { true } else { false }
1104 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
1105 /// This is effectively 10^12 * the prefix multiplier
1108 pub extern "C" fn SiPrefix_multiplier(this_arg: &SiPrefix) -> u64 {
1109 let mut ret = this_arg.to_native().multiplier();
1113 /// Enum representing the crypto currencies (or networks) supported by this library
1129 use lightning_invoice::Currency as nativeCurrency;
1132 pub(crate) fn to_native(&self) -> nativeCurrency {
1134 Currency::Bitcoin => nativeCurrency::Bitcoin,
1135 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1136 Currency::Regtest => nativeCurrency::Regtest,
1137 Currency::Simnet => nativeCurrency::Simnet,
1138 Currency::Signet => nativeCurrency::Signet,
1142 pub(crate) fn into_native(self) -> nativeCurrency {
1144 Currency::Bitcoin => nativeCurrency::Bitcoin,
1145 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1146 Currency::Regtest => nativeCurrency::Regtest,
1147 Currency::Simnet => nativeCurrency::Simnet,
1148 Currency::Signet => nativeCurrency::Signet,
1152 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
1154 nativeCurrency::Bitcoin => Currency::Bitcoin,
1155 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1156 nativeCurrency::Regtest => Currency::Regtest,
1157 nativeCurrency::Simnet => Currency::Simnet,
1158 nativeCurrency::Signet => Currency::Signet,
1162 pub(crate) fn native_into(native: nativeCurrency) -> Self {
1164 nativeCurrency::Bitcoin => Currency::Bitcoin,
1165 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1166 nativeCurrency::Regtest => Currency::Regtest,
1167 nativeCurrency::Simnet => Currency::Simnet,
1168 nativeCurrency::Signet => Currency::Signet,
1172 /// Creates a copy of the Currency
1174 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
1178 /// Utility method to constructs a new Bitcoin-variant Currency
1179 pub extern "C" fn Currency_bitcoin() -> Currency {
1182 /// Utility method to constructs a new BitcoinTestnet-variant Currency
1183 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
1184 Currency::BitcoinTestnet}
1186 /// Utility method to constructs a new Regtest-variant Currency
1187 pub extern "C" fn Currency_regtest() -> Currency {
1190 /// Utility method to constructs a new Simnet-variant Currency
1191 pub extern "C" fn Currency_simnet() -> Currency {
1194 /// Utility method to constructs a new Signet-variant Currency
1195 pub extern "C" fn Currency_signet() -> Currency {
1197 /// Checks if two Currencys contain equal inner contents.
1199 pub extern "C" fn Currency_hash(o: &Currency) -> u64 {
1200 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1201 #[allow(deprecated)]
1202 let mut hasher = core::hash::SipHasher::new();
1203 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1204 core::hash::Hasher::finish(&hasher)
1206 /// Checks if two Currencys contain equal inner contents.
1207 /// This ignores pointers and is_owned flags and looks at the values in fields.
1209 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
1210 if &a.to_native() == &b.to_native() { true } else { false }
1213 use lightning_invoice::Sha256 as nativeSha256Import;
1214 pub(crate) type nativeSha256 = nativeSha256Import;
1220 /// A pointer to the opaque Rust object.
1222 /// Nearly everywhere, inner must be non-null, however in places where
1223 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1224 pub inner: *mut nativeSha256,
1225 /// Indicates that this is the only struct which contains the same pointer.
1227 /// Rust functions which take ownership of an object provided via an argument require
1228 /// this to be true and invalidate the object pointed to by inner.
1232 impl Drop for Sha256 {
1233 fn drop(&mut self) {
1234 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
1235 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1239 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
1241 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
1243 /// Used only if an object of this type is returned as a trait impl by a method
1244 pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
1245 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
1249 pub(crate) fn get_native_ref(&self) -> &'static nativeSha256 {
1250 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1252 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSha256 {
1253 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1255 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1256 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
1257 assert!(self.is_owned);
1258 let ret = ObjOps::untweak_ptr(self.inner);
1259 self.inner = core::ptr::null_mut();
1263 impl Clone for Sha256 {
1264 fn clone(&self) -> Self {
1266 inner: if <*mut nativeSha256>::is_null(self.inner) { core::ptr::null_mut() } else {
1267 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1273 /// Used only if an object of this type is returned as a trait impl by a method
1274 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
1275 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
1278 /// Creates a copy of the Sha256
1279 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
1282 /// Checks if two Sha256s contain equal inner contents.
1284 pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 {
1285 if o.inner.is_null() { return 0; }
1286 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1287 #[allow(deprecated)]
1288 let mut hasher = core::hash::SipHasher::new();
1289 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1290 core::hash::Hasher::finish(&hasher)
1292 /// Checks if two Sha256s contain equal inner contents.
1293 /// This ignores pointers and is_owned flags and looks at the values in fields.
1294 /// Two objects with NULL inner values will be considered "equal" here.
1296 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
1297 if a.inner == b.inner { return true; }
1298 if a.inner.is_null() || b.inner.is_null() { return false; }
1299 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1302 use lightning_invoice::Description as nativeDescriptionImport;
1303 pub(crate) type nativeDescription = nativeDescriptionImport;
1305 /// Description string
1308 /// The description can be at most 639 __bytes__ long
1311 pub struct Description {
1312 /// A pointer to the opaque Rust object.
1314 /// Nearly everywhere, inner must be non-null, however in places where
1315 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1316 pub inner: *mut nativeDescription,
1317 /// Indicates that this is the only struct which contains the same pointer.
1319 /// Rust functions which take ownership of an object provided via an argument require
1320 /// this to be true and invalidate the object pointed to by inner.
1324 impl Drop for Description {
1325 fn drop(&mut self) {
1326 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
1327 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1331 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
1333 pub extern "C" fn Description_free(this_obj: Description) { }
1335 /// Used only if an object of this type is returned as a trait impl by a method
1336 pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) {
1337 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
1341 pub(crate) fn get_native_ref(&self) -> &'static nativeDescription {
1342 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1344 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDescription {
1345 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1347 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1348 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
1349 assert!(self.is_owned);
1350 let ret = ObjOps::untweak_ptr(self.inner);
1351 self.inner = core::ptr::null_mut();
1355 impl Clone for Description {
1356 fn clone(&self) -> Self {
1358 inner: if <*mut nativeDescription>::is_null(self.inner) { core::ptr::null_mut() } else {
1359 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1365 /// Used only if an object of this type is returned as a trait impl by a method
1366 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
1367 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
1370 /// Creates a copy of the Description
1371 pub extern "C" fn Description_clone(orig: &Description) -> Description {
1374 /// Checks if two Descriptions contain equal inner contents.
1376 pub extern "C" fn Description_hash(o: &Description) -> u64 {
1377 if o.inner.is_null() { return 0; }
1378 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1379 #[allow(deprecated)]
1380 let mut hasher = core::hash::SipHasher::new();
1381 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1382 core::hash::Hasher::finish(&hasher)
1384 /// Checks if two Descriptions contain equal inner contents.
1385 /// This ignores pointers and is_owned flags and looks at the values in fields.
1386 /// Two objects with NULL inner values will be considered "equal" here.
1388 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
1389 if a.inner == b.inner { return true; }
1390 if a.inner.is_null() || b.inner.is_null() { return false; }
1391 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1394 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
1395 pub(crate) type nativePayeePubKey = nativePayeePubKeyImport;
1397 /// Payee public key
1400 pub struct PayeePubKey {
1401 /// A pointer to the opaque Rust object.
1403 /// Nearly everywhere, inner must be non-null, however in places where
1404 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1405 pub inner: *mut nativePayeePubKey,
1406 /// Indicates that this is the only struct which contains the same pointer.
1408 /// Rust functions which take ownership of an object provided via an argument require
1409 /// this to be true and invalidate the object pointed to by inner.
1413 impl Drop for PayeePubKey {
1414 fn drop(&mut self) {
1415 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
1416 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1420 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
1422 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
1424 /// Used only if an object of this type is returned as a trait impl by a method
1425 pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
1426 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
1430 pub(crate) fn get_native_ref(&self) -> &'static nativePayeePubKey {
1431 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1433 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayeePubKey {
1434 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1436 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1437 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
1438 assert!(self.is_owned);
1439 let ret = ObjOps::untweak_ptr(self.inner);
1440 self.inner = core::ptr::null_mut();
1445 pub extern "C" fn PayeePubKey_get_a(this_ptr: &PayeePubKey) -> crate::c_types::PublicKey {
1446 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1447 crate::c_types::PublicKey::from_rust(&inner_val)
1450 pub extern "C" fn PayeePubKey_set_a(this_ptr: &mut PayeePubKey, mut val: crate::c_types::PublicKey) {
1451 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
1453 /// Constructs a new PayeePubKey given each field
1456 pub extern "C" fn PayeePubKey_new(mut a_arg: crate::c_types::PublicKey) -> PayeePubKey {
1457 PayeePubKey { inner: ObjOps::heap_alloc(lightning_invoice::PayeePubKey (
1459 )), is_owned: true }
1461 impl Clone for PayeePubKey {
1462 fn clone(&self) -> Self {
1464 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { core::ptr::null_mut() } else {
1465 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1471 /// Used only if an object of this type is returned as a trait impl by a method
1472 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
1473 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
1476 /// Creates a copy of the PayeePubKey
1477 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
1480 /// Checks if two PayeePubKeys contain equal inner contents.
1482 pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 {
1483 if o.inner.is_null() { return 0; }
1484 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1485 #[allow(deprecated)]
1486 let mut hasher = core::hash::SipHasher::new();
1487 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1488 core::hash::Hasher::finish(&hasher)
1490 /// Checks if two PayeePubKeys contain equal inner contents.
1491 /// This ignores pointers and is_owned flags and looks at the values in fields.
1492 /// Two objects with NULL inner values will be considered "equal" here.
1494 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
1495 if a.inner == b.inner { return true; }
1496 if a.inner.is_null() || b.inner.is_null() { return false; }
1497 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1500 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
1501 pub(crate) type nativeExpiryTime = nativeExpiryTimeImport;
1503 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
1507 pub struct ExpiryTime {
1508 /// A pointer to the opaque Rust object.
1510 /// Nearly everywhere, inner must be non-null, however in places where
1511 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1512 pub inner: *mut nativeExpiryTime,
1513 /// Indicates that this is the only struct which contains the same pointer.
1515 /// Rust functions which take ownership of an object provided via an argument require
1516 /// this to be true and invalidate the object pointed to by inner.
1520 impl Drop for ExpiryTime {
1521 fn drop(&mut self) {
1522 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
1523 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1527 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
1529 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
1531 /// Used only if an object of this type is returned as a trait impl by a method
1532 pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
1533 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
1537 pub(crate) fn get_native_ref(&self) -> &'static nativeExpiryTime {
1538 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1540 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpiryTime {
1541 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1543 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1544 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
1545 assert!(self.is_owned);
1546 let ret = ObjOps::untweak_ptr(self.inner);
1547 self.inner = core::ptr::null_mut();
1551 impl Clone for ExpiryTime {
1552 fn clone(&self) -> Self {
1554 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { core::ptr::null_mut() } else {
1555 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1561 /// Used only if an object of this type is returned as a trait impl by a method
1562 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1563 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1566 /// Creates a copy of the ExpiryTime
1567 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1570 /// Checks if two ExpiryTimes contain equal inner contents.
1572 pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 {
1573 if o.inner.is_null() { return 0; }
1574 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1575 #[allow(deprecated)]
1576 let mut hasher = core::hash::SipHasher::new();
1577 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1578 core::hash::Hasher::finish(&hasher)
1580 /// Checks if two ExpiryTimes contain equal inner contents.
1581 /// This ignores pointers and is_owned flags and looks at the values in fields.
1582 /// Two objects with NULL inner values will be considered "equal" here.
1584 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1585 if a.inner == b.inner { return true; }
1586 if a.inner.is_null() || b.inner.is_null() { return false; }
1587 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1590 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
1591 pub(crate) type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
1593 /// `min_final_cltv_expiry` to use for the last HTLC in the route
1596 pub struct MinFinalCltvExpiry {
1597 /// A pointer to the opaque Rust object.
1599 /// Nearly everywhere, inner must be non-null, however in places where
1600 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1601 pub inner: *mut nativeMinFinalCltvExpiry,
1602 /// Indicates that this is the only struct which contains the same pointer.
1604 /// Rust functions which take ownership of an object provided via an argument require
1605 /// this to be true and invalidate the object pointed to by inner.
1609 impl Drop for MinFinalCltvExpiry {
1610 fn drop(&mut self) {
1611 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
1612 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1616 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1618 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1620 /// Used only if an object of this type is returned as a trait impl by a method
1621 pub(crate) extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1622 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1625 impl MinFinalCltvExpiry {
1626 pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiry {
1627 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1629 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiry {
1630 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1632 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1633 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1634 assert!(self.is_owned);
1635 let ret = ObjOps::untweak_ptr(self.inner);
1636 self.inner = core::ptr::null_mut();
1641 pub extern "C" fn MinFinalCltvExpiry_get_a(this_ptr: &MinFinalCltvExpiry) -> u64 {
1642 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1646 pub extern "C" fn MinFinalCltvExpiry_set_a(this_ptr: &mut MinFinalCltvExpiry, mut val: u64) {
1647 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val;
1649 /// Constructs a new MinFinalCltvExpiry given each field
1652 pub extern "C" fn MinFinalCltvExpiry_new(mut a_arg: u64) -> MinFinalCltvExpiry {
1653 MinFinalCltvExpiry { inner: ObjOps::heap_alloc(lightning_invoice::MinFinalCltvExpiry (
1655 )), is_owned: true }
1657 impl Clone for MinFinalCltvExpiry {
1658 fn clone(&self) -> Self {
1660 inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { core::ptr::null_mut() } else {
1661 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1667 /// Used only if an object of this type is returned as a trait impl by a method
1668 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1669 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1672 /// Creates a copy of the MinFinalCltvExpiry
1673 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1676 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1678 pub extern "C" fn MinFinalCltvExpiry_hash(o: &MinFinalCltvExpiry) -> u64 {
1679 if o.inner.is_null() { return 0; }
1680 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1681 #[allow(deprecated)]
1682 let mut hasher = core::hash::SipHasher::new();
1683 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1684 core::hash::Hasher::finish(&hasher)
1686 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1687 /// This ignores pointers and is_owned flags and looks at the values in fields.
1688 /// Two objects with NULL inner values will be considered "equal" here.
1690 pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool {
1691 if a.inner == b.inner { return true; }
1692 if a.inner.is_null() || b.inner.is_null() { return false; }
1693 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1695 /// Fallback address in case no LN payment is possible
1701 version: crate::c_types::u5,
1702 program: crate::c_types::derived::CVec_u8Z,
1704 PubKeyHash(crate::c_types::TwentyBytes),
1705 ScriptHash(crate::c_types::TwentyBytes),
1707 use lightning_invoice::Fallback as nativeFallback;
1710 pub(crate) fn to_native(&self) -> nativeFallback {
1712 Fallback::SegWitProgram {ref version, ref program, } => {
1713 let mut version_nonref = (*version).clone();
1714 let mut program_nonref = (*program).clone();
1715 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1716 nativeFallback::SegWitProgram {
1717 version: version_nonref.into(),
1718 program: local_program_nonref,
1721 Fallback::PubKeyHash (ref a, ) => {
1722 let mut a_nonref = (*a).clone();
1723 nativeFallback::PubKeyHash (
1727 Fallback::ScriptHash (ref a, ) => {
1728 let mut a_nonref = (*a).clone();
1729 nativeFallback::ScriptHash (
1736 pub(crate) fn into_native(self) -> nativeFallback {
1738 Fallback::SegWitProgram {mut version, mut program, } => {
1739 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1740 nativeFallback::SegWitProgram {
1741 version: version.into(),
1742 program: local_program,
1745 Fallback::PubKeyHash (mut a, ) => {
1746 nativeFallback::PubKeyHash (
1750 Fallback::ScriptHash (mut a, ) => {
1751 nativeFallback::ScriptHash (
1758 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1760 nativeFallback::SegWitProgram {ref version, ref program, } => {
1761 let mut version_nonref = (*version).clone();
1762 let mut program_nonref = (*program).clone();
1763 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1764 Fallback::SegWitProgram {
1765 version: version_nonref.into(),
1766 program: local_program_nonref.into(),
1769 nativeFallback::PubKeyHash (ref a, ) => {
1770 let mut a_nonref = (*a).clone();
1771 Fallback::PubKeyHash (
1772 crate::c_types::TwentyBytes { data: a_nonref },
1775 nativeFallback::ScriptHash (ref a, ) => {
1776 let mut a_nonref = (*a).clone();
1777 Fallback::ScriptHash (
1778 crate::c_types::TwentyBytes { data: a_nonref },
1784 pub(crate) fn native_into(native: nativeFallback) -> Self {
1786 nativeFallback::SegWitProgram {mut version, mut program, } => {
1787 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1788 Fallback::SegWitProgram {
1789 version: version.into(),
1790 program: local_program.into(),
1793 nativeFallback::PubKeyHash (mut a, ) => {
1794 Fallback::PubKeyHash (
1795 crate::c_types::TwentyBytes { data: a },
1798 nativeFallback::ScriptHash (mut a, ) => {
1799 Fallback::ScriptHash (
1800 crate::c_types::TwentyBytes { data: a },
1806 /// Frees any resources used by the Fallback
1808 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1809 /// Creates a copy of the Fallback
1811 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1815 /// Utility method to constructs a new SegWitProgram-variant Fallback
1816 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::u5, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
1817 Fallback::SegWitProgram {
1823 /// Utility method to constructs a new PubKeyHash-variant Fallback
1824 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1825 Fallback::PubKeyHash(a, )
1828 /// Utility method to constructs a new ScriptHash-variant Fallback
1829 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1830 Fallback::ScriptHash(a, )
1832 /// Checks if two Fallbacks contain equal inner contents.
1834 pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 {
1835 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1836 #[allow(deprecated)]
1837 let mut hasher = core::hash::SipHasher::new();
1838 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1839 core::hash::Hasher::finish(&hasher)
1841 /// Checks if two Fallbacks contain equal inner contents.
1842 /// This ignores pointers and is_owned flags and looks at the values in fields.
1844 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1845 if &a.to_native() == &b.to_native() { true } else { false }
1848 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1849 pub(crate) type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1851 /// Recoverable signature
1854 pub struct InvoiceSignature {
1855 /// A pointer to the opaque Rust object.
1857 /// Nearly everywhere, inner must be non-null, however in places where
1858 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1859 pub inner: *mut nativeInvoiceSignature,
1860 /// Indicates that this is the only struct which contains the same pointer.
1862 /// Rust functions which take ownership of an object provided via an argument require
1863 /// this to be true and invalidate the object pointed to by inner.
1867 impl Drop for InvoiceSignature {
1868 fn drop(&mut self) {
1869 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1870 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1874 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1876 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1878 /// Used only if an object of this type is returned as a trait impl by a method
1879 pub(crate) extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1880 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1883 impl InvoiceSignature {
1884 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceSignature {
1885 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1887 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceSignature {
1888 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1890 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1891 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1892 assert!(self.is_owned);
1893 let ret = ObjOps::untweak_ptr(self.inner);
1894 self.inner = core::ptr::null_mut();
1898 impl Clone for InvoiceSignature {
1899 fn clone(&self) -> Self {
1901 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { core::ptr::null_mut() } else {
1902 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1908 /// Used only if an object of this type is returned as a trait impl by a method
1909 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
1910 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
1913 /// Creates a copy of the InvoiceSignature
1914 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
1917 /// Checks if two InvoiceSignatures contain equal inner contents.
1918 /// This ignores pointers and is_owned flags and looks at the values in fields.
1919 /// Two objects with NULL inner values will be considered "equal" here.
1921 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
1922 if a.inner == b.inner { return true; }
1923 if a.inner.is_null() || b.inner.is_null() { return false; }
1924 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1927 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
1928 pub(crate) type nativePrivateRoute = nativePrivateRouteImport;
1930 /// Private routing information
1933 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
1937 pub struct PrivateRoute {
1938 /// A pointer to the opaque Rust object.
1940 /// Nearly everywhere, inner must be non-null, however in places where
1941 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1942 pub inner: *mut nativePrivateRoute,
1943 /// Indicates that this is the only struct which contains the same pointer.
1945 /// Rust functions which take ownership of an object provided via an argument require
1946 /// this to be true and invalidate the object pointed to by inner.
1950 impl Drop for PrivateRoute {
1951 fn drop(&mut self) {
1952 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
1953 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1957 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
1959 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
1961 /// Used only if an object of this type is returned as a trait impl by a method
1962 pub(crate) extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
1963 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); }
1967 pub(crate) fn get_native_ref(&self) -> &'static nativePrivateRoute {
1968 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1970 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateRoute {
1971 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1973 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1974 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
1975 assert!(self.is_owned);
1976 let ret = ObjOps::untweak_ptr(self.inner);
1977 self.inner = core::ptr::null_mut();
1981 impl Clone for PrivateRoute {
1982 fn clone(&self) -> Self {
1984 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
1985 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1991 /// Used only if an object of this type is returned as a trait impl by a method
1992 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
1993 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
1996 /// Creates a copy of the PrivateRoute
1997 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
2000 /// Checks if two PrivateRoutes contain equal inner contents.
2002 pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 {
2003 if o.inner.is_null() { return 0; }
2004 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2005 #[allow(deprecated)]
2006 let mut hasher = core::hash::SipHasher::new();
2007 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2008 core::hash::Hasher::finish(&hasher)
2010 /// Checks if two PrivateRoutes contain equal inner contents.
2011 /// This ignores pointers and is_owned flags and looks at the values in fields.
2012 /// Two objects with NULL inner values will be considered "equal" here.
2014 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
2015 if a.inner == b.inner { return true; }
2016 if a.inner.is_null() || b.inner.is_null() { return false; }
2017 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2019 /// Disassembles the `SignedRawInvoice` into its three parts:
2021 /// 2. hash of the raw invoice
2025 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
2026 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
2027 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();
2031 /// The `RawInvoice` which was signed.
2034 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
2035 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice();
2036 crate::lightning_invoice::RawInvoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawInvoice<>) as *mut _) }, is_owned: false }
2039 /// The hash of the `RawInvoice` that was signed.
2042 pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [u8; 32] {
2043 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
2047 /// InvoiceSignature for the invoice.
2050 pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
2051 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
2052 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::InvoiceSignature<>) as *mut _) }, is_owned: false }
2055 /// Recovers the public key used for signing the invoice from the recoverable signature.
2058 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
2059 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2060 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() };
2064 /// Checks if the signature is valid for the included payee public key or if none exists if it's
2065 /// valid for the recovered signature (which should always be true?).
2068 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &SignedRawInvoice) -> bool {
2069 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2073 /// Calculate the hash of the encoded `RawInvoice`
2076 pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
2077 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
2078 crate::c_types::ThirtyTwoBytes { data: ret }
2082 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2085 pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
2086 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2087 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 };
2092 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2095 pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightning_invoice::Description {
2096 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
2097 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 };
2102 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2105 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::lightning_invoice::PayeePubKey {
2106 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2107 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 };
2112 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2115 pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
2116 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash();
2117 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 };
2122 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2125 pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightning_invoice::ExpiryTime {
2126 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2127 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 };
2132 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2135 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
2136 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
2137 let mut local_ret = crate::lightning_invoice::MinFinalCltvExpiry { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::MinFinalCltvExpiry<>) as *mut _ }, is_owned: false };
2142 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2145 pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
2146 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2147 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
2152 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2155 pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
2156 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2157 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 };
2163 pub extern "C" fn RawInvoice_private_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2164 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2165 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 } }); };
2171 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z {
2172 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
2173 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() }) };
2179 pub extern "C" fn RawInvoice_currency(this_arg: &RawInvoice) -> crate::lightning_invoice::Currency {
2180 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2181 crate::lightning_invoice::Currency::native_into(ret)
2184 /// Creates a `PositiveTimestamp` from a Unix timestamp in the range `0..=MAX_TIMESTAMP`.
2186 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2189 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2190 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
2191 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() };
2195 /// Creates a `PositiveTimestamp` from a [`SystemTime`] with a corresponding Unix timestamp in
2196 /// the range `0..=MAX_TIMESTAMP`.
2198 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2201 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2202 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
2203 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() };
2207 /// Creates a `PositiveTimestamp` from a [`Duration`] since the Unix epoch in the range
2208 /// `0..=MAX_TIMESTAMP`.
2210 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2213 pub extern "C" fn PositiveTimestamp_from_duration_since_epoch(mut duration: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2214 let mut ret = lightning_invoice::PositiveTimestamp::from_duration_since_epoch(core::time::Duration::from_secs(duration));
2215 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() };
2219 /// Returns the Unix timestamp representing the stored time
2222 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 {
2223 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_unix_timestamp();
2227 /// Returns the duration of the stored time since the Unix epoch
2230 pub extern "C" fn PositiveTimestamp_as_duration_since_epoch(this_arg: &PositiveTimestamp) -> u64 {
2231 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration_since_epoch();
2235 /// Returns the [`SystemTime`] representing the stored time
2238 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &PositiveTimestamp) -> u64 {
2239 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_time();
2240 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2243 /// Transform the `Invoice` into it's unchecked version
2246 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::lightning_invoice::SignedRawInvoice {
2247 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
2248 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(ret), is_owned: true }
2251 /// Check that the invoice is signed correctly and that key recovery works
2254 pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
2255 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2256 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() };
2260 /// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
2262 /// use lightning_invoice::*;
2264 /// let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
2265 /// h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
2266 /// 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
2267 /// h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
2268 /// j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
2269 /// ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
2270 /// guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
2271 /// ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
2272 /// p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
2273 /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
2274 /// j5r6drg6k6zcqj0fcwg\";
2276 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
2278 /// assert!(Invoice::from_signed(signed).is_ok());
2282 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
2283 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
2284 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() };
2288 /// Returns the `Invoice`'s timestamp (should equal its creation time)
2291 pub extern "C" fn Invoice_timestamp(this_arg: &Invoice) -> u64 {
2292 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timestamp();
2293 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2296 /// Returns the `Invoice`'s timestamp as a duration since the Unix epoch
2299 pub extern "C" fn Invoice_duration_since_epoch(this_arg: &Invoice) -> u64 {
2300 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_since_epoch();
2304 /// Returns the hash to which we will receive the preimage on completion of the payment
2307 pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] {
2308 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2312 /// Get the payee's public key if one was included in the invoice
2314 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2317 pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
2318 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2319 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
2323 /// Get the payment secret if one was included in the invoice
2326 pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> *const [u8; 32] {
2327 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2331 /// Get the invoice features if they were included in the invoice
2333 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2336 pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
2337 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2338 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 };
2342 /// Recover the payee's public key (only to be used if none was included in the invoice)
2345 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
2346 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2347 crate::c_types::PublicKey::from_rust(&ret)
2350 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
2353 pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 {
2354 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2358 /// Returns whether the invoice has expired.
2361 pub extern "C" fn Invoice_is_expired(this_arg: &Invoice) -> bool {
2362 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
2366 /// Returns whether the expiry time would pass at the given point in time.
2367 /// `at_time` is the timestamp as a duration since the Unix epoch.
2370 pub extern "C" fn Invoice_would_expire(this_arg: &Invoice, mut at_time: u64) -> bool {
2371 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.would_expire(core::time::Duration::from_secs(at_time));
2375 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
2376 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
2379 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 {
2380 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
2384 /// Returns a list of all routes included in the invoice
2387 pub extern "C" fn Invoice_private_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2388 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2389 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 } }); };
2393 /// Returns a list of all routes included in the invoice as the underlying hints
2396 pub extern "C" fn Invoice_route_hints(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
2397 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints();
2398 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 } }); };
2402 /// Returns the currency for which the invoice was issued
2405 pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoice::Currency {
2406 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2407 crate::lightning_invoice::Currency::native_into(ret)
2410 /// Returns the amount if specified in the invoice as millisatoshis.
2413 pub extern "C" fn Invoice_amount_milli_satoshis(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z {
2414 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_milli_satoshis();
2415 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() }) };
2419 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
2420 /// returns `CreationError::DescriptionTooLong` otherwise
2422 /// Please note that single characters may use more than one byte due to UTF8 encoding.
2425 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
2426 let mut ret = lightning_invoice::Description::new(description.into_string());
2427 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() };
2431 /// Returns the underlying description `String`
2434 pub extern "C" fn Description_into_inner(mut this_arg: Description) -> crate::c_types::Str {
2435 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2439 /// Construct an `ExpiryTime` from seconds.
2442 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::lightning_invoice::ExpiryTime {
2443 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
2444 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2447 /// Construct an `ExpiryTime` from a `Duration`.
2450 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::lightning_invoice::ExpiryTime {
2451 let mut ret = lightning_invoice::ExpiryTime::from_duration(core::time::Duration::from_secs(duration));
2452 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2455 /// Returns the expiry time in seconds
2458 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 {
2459 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_seconds();
2463 /// Returns a reference to the underlying `Duration` (=expiry time)
2466 pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 {
2467 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration();
2471 /// Creates a new (partial) route from a list of hops
2474 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
2475 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
2476 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() };
2480 /// Returns the underlying list of hops
2483 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: PrivateRoute) -> crate::lightning::routing::router::RouteHint {
2484 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2485 crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true }
2488 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
2492 pub enum CreationError {
2493 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
2495 /// The specified route has too many hops and can't be encoded
2497 /// The Unix timestamp of the supplied date is less than zero or greater than 35-bits
2498 TimestampOutOfBounds,
2499 /// The supplied millisatoshi amount was greater than the total bitcoin supply.
2501 /// Route hints were required for this invoice and were missing. Applies to
2502 /// [phantom invoices].
2504 /// [phantom invoices]: crate::utils::create_phantom_invoice
2507 use lightning_invoice::CreationError as nativeCreationError;
2508 impl CreationError {
2510 pub(crate) fn to_native(&self) -> nativeCreationError {
2512 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2513 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2514 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2515 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2516 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2520 pub(crate) fn into_native(self) -> nativeCreationError {
2522 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2523 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2524 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2525 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2526 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2530 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
2532 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2533 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2534 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2535 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2536 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2540 pub(crate) fn native_into(native: nativeCreationError) -> Self {
2542 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2543 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2544 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2545 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2546 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2550 /// Creates a copy of the CreationError
2552 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
2556 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
2557 pub extern "C" fn CreationError_description_too_long() -> CreationError {
2558 CreationError::DescriptionTooLong}
2560 /// Utility method to constructs a new RouteTooLong-variant CreationError
2561 pub extern "C" fn CreationError_route_too_long() -> CreationError {
2562 CreationError::RouteTooLong}
2564 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
2565 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
2566 CreationError::TimestampOutOfBounds}
2568 /// Utility method to constructs a new InvalidAmount-variant CreationError
2569 pub extern "C" fn CreationError_invalid_amount() -> CreationError {
2570 CreationError::InvalidAmount}
2572 /// Utility method to constructs a new MissingRouteHints-variant CreationError
2573 pub extern "C" fn CreationError_missing_route_hints() -> CreationError {
2574 CreationError::MissingRouteHints}
2575 /// Checks if two CreationErrors contain equal inner contents.
2576 /// This ignores pointers and is_owned flags and looks at the values in fields.
2578 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
2579 if &a.to_native() == &b.to_native() { true } else { false }
2582 /// Get the string representation of a CreationError object
2583 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
2584 alloc::format!("{}", &o.to_native()).into()
2586 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
2587 /// requirements sections in BOLT #11
2591 pub enum SemanticError {
2592 /// The invoice is missing the mandatory payment hash
2594 /// The invoice has multiple payment hashes which isn't allowed
2595 MultiplePaymentHashes,
2596 /// No description or description hash are part of the invoice
2598 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
2599 MultipleDescriptions,
2600 /// The invoice is missing the mandatory payment secret, which all modern lightning nodes
2603 /// The invoice contains multiple payment secrets
2604 MultiplePaymentSecrets,
2605 /// The invoice's features are invalid
2607 /// The recovery id doesn't fit the signature/pub key
2609 /// The invoice's signature is invalid
2611 /// The invoice's amount was not a whole number of millisatoshis
2614 use lightning_invoice::SemanticError as nativeSemanticError;
2615 impl SemanticError {
2617 pub(crate) fn to_native(&self) -> nativeSemanticError {
2619 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2620 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2621 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2622 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2623 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2624 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2625 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2626 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2627 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2628 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2632 pub(crate) fn into_native(self) -> nativeSemanticError {
2634 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2635 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2636 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2637 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2638 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2639 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2640 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2641 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2642 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2643 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2647 pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
2649 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2650 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2651 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2652 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2653 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2654 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2655 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2656 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2657 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2658 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2662 pub(crate) fn native_into(native: nativeSemanticError) -> Self {
2664 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2665 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2666 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2667 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2668 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2669 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2670 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2671 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2672 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2673 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2677 /// Creates a copy of the SemanticError
2679 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
2683 /// Utility method to constructs a new NoPaymentHash-variant SemanticError
2684 pub extern "C" fn SemanticError_no_payment_hash() -> SemanticError {
2685 SemanticError::NoPaymentHash}
2687 /// Utility method to constructs a new MultiplePaymentHashes-variant SemanticError
2688 pub extern "C" fn SemanticError_multiple_payment_hashes() -> SemanticError {
2689 SemanticError::MultiplePaymentHashes}
2691 /// Utility method to constructs a new NoDescription-variant SemanticError
2692 pub extern "C" fn SemanticError_no_description() -> SemanticError {
2693 SemanticError::NoDescription}
2695 /// Utility method to constructs a new MultipleDescriptions-variant SemanticError
2696 pub extern "C" fn SemanticError_multiple_descriptions() -> SemanticError {
2697 SemanticError::MultipleDescriptions}
2699 /// Utility method to constructs a new NoPaymentSecret-variant SemanticError
2700 pub extern "C" fn SemanticError_no_payment_secret() -> SemanticError {
2701 SemanticError::NoPaymentSecret}
2703 /// Utility method to constructs a new MultiplePaymentSecrets-variant SemanticError
2704 pub extern "C" fn SemanticError_multiple_payment_secrets() -> SemanticError {
2705 SemanticError::MultiplePaymentSecrets}
2707 /// Utility method to constructs a new InvalidFeatures-variant SemanticError
2708 pub extern "C" fn SemanticError_invalid_features() -> SemanticError {
2709 SemanticError::InvalidFeatures}
2711 /// Utility method to constructs a new InvalidRecoveryId-variant SemanticError
2712 pub extern "C" fn SemanticError_invalid_recovery_id() -> SemanticError {
2713 SemanticError::InvalidRecoveryId}
2715 /// Utility method to constructs a new InvalidSignature-variant SemanticError
2716 pub extern "C" fn SemanticError_invalid_signature() -> SemanticError {
2717 SemanticError::InvalidSignature}
2719 /// Utility method to constructs a new ImpreciseAmount-variant SemanticError
2720 pub extern "C" fn SemanticError_imprecise_amount() -> SemanticError {
2721 SemanticError::ImpreciseAmount}
2722 /// Checks if two SemanticErrors contain equal inner contents.
2723 /// This ignores pointers and is_owned flags and looks at the values in fields.
2725 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
2726 if &a.to_native() == &b.to_native() { true } else { false }
2729 /// Get the string representation of a SemanticError object
2730 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
2731 alloc::format!("{}", &o.to_native()).into()
2733 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
2738 pub enum SignOrCreationError {
2739 /// An error occurred during signing
2741 /// An error occurred while building the transaction
2742 CreationError(crate::lightning_invoice::CreationError),
2744 use lightning_invoice::SignOrCreationError as nativeSignOrCreationError;
2745 impl SignOrCreationError {
2747 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
2749 SignOrCreationError::SignError => {
2750 nativeSignOrCreationError::SignError (
2754 SignOrCreationError::CreationError (ref a, ) => {
2755 let mut a_nonref = (*a).clone();
2756 nativeSignOrCreationError::CreationError (
2757 a_nonref.into_native(),
2763 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
2765 SignOrCreationError::SignError => {
2766 nativeSignOrCreationError::SignError (
2770 SignOrCreationError::CreationError (mut a, ) => {
2771 nativeSignOrCreationError::CreationError (
2778 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
2780 nativeSignOrCreationError::SignError (ref a, ) => {
2781 SignOrCreationError::SignError },
2782 nativeSignOrCreationError::CreationError (ref a, ) => {
2783 let mut a_nonref = (*a).clone();
2784 SignOrCreationError::CreationError (
2785 crate::lightning_invoice::CreationError::native_into(a_nonref),
2791 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
2793 nativeSignOrCreationError::SignError (mut a, ) => {
2794 SignOrCreationError::SignError },
2795 nativeSignOrCreationError::CreationError (mut a, ) => {
2796 SignOrCreationError::CreationError (
2797 crate::lightning_invoice::CreationError::native_into(a),
2803 /// Frees any resources used by the SignOrCreationError
2805 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
2806 /// Creates a copy of the SignOrCreationError
2808 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
2812 /// Utility method to constructs a new SignError-variant SignOrCreationError
2813 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
2814 SignOrCreationError::SignError
2817 /// Utility method to constructs a new CreationError-variant SignOrCreationError
2818 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
2819 SignOrCreationError::CreationError(a, )
2821 /// Checks if two SignOrCreationErrors contain equal inner contents.
2822 /// This ignores pointers and is_owned flags and looks at the values in fields.
2824 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
2825 if &a.to_native() == &b.to_native() { true } else { false }
2828 /// Get the string representation of a SignOrCreationError object
2829 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
2830 alloc::format!("{}", &o.to_native()).into()