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/lightning/bolts/blob/master/11-payment-encoding.md)
11 //! invoices and functions to create, encode and decode these. If you just want to use the standard
12 //! en-/decoding functionality this should get you started:
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};
42 use alloc::str::FromStr;
43 use core::ffi::c_void;
44 use core::convert::Infallible;
45 use bitcoin::hashes::Hash;
46 use crate::c_types::*;
47 #[cfg(feature="no-std")]
48 use alloc::{vec::Vec, boxed::Box};
52 use alloc::str::FromStr;
53 use core::ffi::c_void;
54 use core::convert::Infallible;
55 use bitcoin::hashes::Hash;
56 use crate::c_types::*;
57 #[cfg(feature="no-std")]
58 use alloc::{vec::Vec, boxed::Box};
62 /// Read a SiPrefix object from a string
63 pub extern "C" fn SiPrefix_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SiPrefixParseErrorZ {
64 match lightning_invoice::SiPrefix::from_str(s.into_str()) {
66 crate::c_types::CResultTempl::ok(
67 crate::lightning_invoice::SiPrefix::native_into(r)
71 crate::c_types::CResultTempl::err(
72 crate::lightning_invoice::ParseError::native_into(e)
78 /// Read a Invoice object from a string
79 pub extern "C" fn Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_InvoiceParseOrSemanticErrorZ {
80 match lightning_invoice::Invoice::from_str(s.into_str()) {
82 crate::c_types::CResultTempl::ok(
83 crate::lightning_invoice::Invoice { inner: ObjOps::heap_alloc(r), is_owned: true }
87 crate::c_types::CResultTempl::err(
88 crate::lightning_invoice::ParseOrSemanticError::native_into(e)
94 /// Read a SignedRawInvoice object from a string
95 pub extern "C" fn SignedRawInvoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SignedRawInvoiceParseErrorZ {
96 match lightning_invoice::SignedRawInvoice::from_str(s.into_str()) {
98 crate::c_types::CResultTempl::ok(
99 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(r), is_owned: true }
103 crate::c_types::CResultTempl::err(
104 crate::lightning_invoice::ParseError::native_into(e)
110 /// Get the string representation of a ParseError object
111 pub extern "C" fn ParseError_to_str(o: &crate::lightning_invoice::ParseError) -> Str {
112 alloc::format!("{}", &o.to_native()).into()
115 /// Get the string representation of a ParseOrSemanticError object
116 pub extern "C" fn ParseOrSemanticError_to_str(o: &crate::lightning_invoice::ParseOrSemanticError) -> Str {
117 alloc::format!("{}", &o.to_native()).into()
122 use alloc::str::FromStr;
123 use core::ffi::c_void;
124 use core::convert::Infallible;
125 use bitcoin::hashes::Hash;
126 use crate::c_types::*;
127 #[cfg(feature="no-std")]
128 use alloc::{vec::Vec, boxed::Box};
131 /// Get the string representation of a Invoice object
132 pub extern "C" fn Invoice_to_str(o: &crate::lightning_invoice::Invoice) -> Str {
133 alloc::format!("{}", o.get_native_ref()).into()
136 /// Get the string representation of a SignedRawInvoice object
137 pub extern "C" fn SignedRawInvoice_to_str(o: &crate::lightning_invoice::SignedRawInvoice) -> Str {
138 alloc::format!("{}", o.get_native_ref()).into()
141 /// Get the string representation of a Currency object
142 pub extern "C" fn Currency_to_str(o: &crate::lightning_invoice::Currency) -> Str {
143 alloc::format!("{}", &o.to_native()).into()
146 /// Get the string representation of a SiPrefix object
147 pub extern "C" fn SiPrefix_to_str(o: &crate::lightning_invoice::SiPrefix) -> Str {
148 alloc::format!("{}", &o.to_native()).into()
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};
175 use alloc::str::FromStr;
176 use core::ffi::c_void;
177 use core::convert::Infallible;
178 use bitcoin::hashes::Hash;
179 use crate::c_types::*;
180 #[cfg(feature="no-std")]
181 use alloc::{vec::Vec, boxed::Box};
184 /// Errors that indicate what is wrong with the invoice. They have some granularity for debug
185 /// reasons, but should generally result in an \"invalid BOLT11 invoice\" message for the user.
189 pub enum ParseError {
191 crate::c_types::Bech32Error),
193 crate::c_types::Error),
195 crate::c_types::Secp256k1Error),
201 UnexpectedEndOfTaggedFields,
202 DescriptionDecodeError(
203 crate::c_types::Error),
205 IntegerOverflowError,
206 InvalidSegWitProgramLength,
207 InvalidPubKeyHashLength,
208 InvalidScriptHashLength,
211 crate::c_types::Str),
212 /// Not an error, but used internally to signal that a part of the invoice should be ignored
213 /// according to BOLT11
216 use lightning_invoice::ParseError as ParseErrorImport;
217 pub(crate) type nativeParseError = ParseErrorImport;
221 pub(crate) fn to_native(&self) -> nativeParseError {
223 ParseError::Bech32Error (ref a, ) => {
224 let mut a_nonref = (*a).clone();
225 nativeParseError::Bech32Error (
226 a_nonref.into_rust(),
229 ParseError::ParseAmountError (ref a, ) => {
230 let mut a_nonref = (*a).clone();
231 nativeParseError::ParseAmountError (
232 u8::from_str_radix(" a", 10).unwrap_err() /*a_nonref*/,
235 ParseError::MalformedSignature (ref a, ) => {
236 let mut a_nonref = (*a).clone();
237 nativeParseError::MalformedSignature (
238 a_nonref.into_rust(),
241 ParseError::BadPrefix => nativeParseError::BadPrefix,
242 ParseError::UnknownCurrency => nativeParseError::UnknownCurrency,
243 ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix,
244 ParseError::MalformedHRP => nativeParseError::MalformedHRP,
245 ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
246 ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
247 ParseError::DescriptionDecodeError (ref a, ) => {
248 let mut a_nonref = (*a).clone();
249 nativeParseError::DescriptionDecodeError (
250 core::str::from_utf8(&[0xff]).unwrap_err() /*a_nonref*/,
253 ParseError::PaddingError => nativeParseError::PaddingError,
254 ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError,
255 ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength,
256 ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength,
257 ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
258 ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
259 ParseError::InvalidSliceLength (ref a, ) => {
260 let mut a_nonref = (*a).clone();
261 nativeParseError::InvalidSliceLength (
262 a_nonref.into_string(),
265 ParseError::Skip => nativeParseError::Skip,
269 pub(crate) fn into_native(self) -> nativeParseError {
271 ParseError::Bech32Error (mut a, ) => {
272 nativeParseError::Bech32Error (
276 ParseError::ParseAmountError (mut a, ) => {
277 nativeParseError::ParseAmountError (
278 u8::from_str_radix(" a", 10).unwrap_err() /*a*/,
281 ParseError::MalformedSignature (mut a, ) => {
282 nativeParseError::MalformedSignature (
286 ParseError::BadPrefix => nativeParseError::BadPrefix,
287 ParseError::UnknownCurrency => nativeParseError::UnknownCurrency,
288 ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix,
289 ParseError::MalformedHRP => nativeParseError::MalformedHRP,
290 ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
291 ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
292 ParseError::DescriptionDecodeError (mut a, ) => {
293 nativeParseError::DescriptionDecodeError (
294 core::str::from_utf8(&[0xff]).unwrap_err() /*a*/,
297 ParseError::PaddingError => nativeParseError::PaddingError,
298 ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError,
299 ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength,
300 ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength,
301 ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
302 ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
303 ParseError::InvalidSliceLength (mut a, ) => {
304 nativeParseError::InvalidSliceLength (
308 ParseError::Skip => nativeParseError::Skip,
312 pub(crate) fn from_native(native: &nativeParseError) -> Self {
314 nativeParseError::Bech32Error (ref a, ) => {
315 let mut a_nonref = (*a).clone();
316 ParseError::Bech32Error (
317 crate::c_types::Bech32Error::from_rust(a_nonref),
320 nativeParseError::ParseAmountError (ref a, ) => {
321 let mut a_nonref = (*a).clone();
322 ParseError::ParseAmountError (
323 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
326 nativeParseError::MalformedSignature (ref a, ) => {
327 let mut a_nonref = (*a).clone();
328 ParseError::MalformedSignature (
329 crate::c_types::Secp256k1Error::from_rust(a_nonref),
332 nativeParseError::BadPrefix => ParseError::BadPrefix,
333 nativeParseError::UnknownCurrency => ParseError::UnknownCurrency,
334 nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix,
335 nativeParseError::MalformedHRP => ParseError::MalformedHRP,
336 nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
337 nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
338 nativeParseError::DescriptionDecodeError (ref a, ) => {
339 let mut a_nonref = (*a).clone();
340 ParseError::DescriptionDecodeError (
341 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
344 nativeParseError::PaddingError => ParseError::PaddingError,
345 nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError,
346 nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength,
347 nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength,
348 nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
349 nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
350 nativeParseError::InvalidSliceLength (ref a, ) => {
351 let mut a_nonref = (*a).clone();
352 ParseError::InvalidSliceLength (
356 nativeParseError::Skip => ParseError::Skip,
360 pub(crate) fn native_into(native: nativeParseError) -> Self {
362 nativeParseError::Bech32Error (mut a, ) => {
363 ParseError::Bech32Error (
364 crate::c_types::Bech32Error::from_rust(a),
367 nativeParseError::ParseAmountError (mut a, ) => {
368 ParseError::ParseAmountError (
369 crate::c_types::Error { _dummy: 0 } /*a*/,
372 nativeParseError::MalformedSignature (mut a, ) => {
373 ParseError::MalformedSignature (
374 crate::c_types::Secp256k1Error::from_rust(a),
377 nativeParseError::BadPrefix => ParseError::BadPrefix,
378 nativeParseError::UnknownCurrency => ParseError::UnknownCurrency,
379 nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix,
380 nativeParseError::MalformedHRP => ParseError::MalformedHRP,
381 nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
382 nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
383 nativeParseError::DescriptionDecodeError (mut a, ) => {
384 ParseError::DescriptionDecodeError (
385 crate::c_types::Error { _dummy: 0 } /*a*/,
388 nativeParseError::PaddingError => ParseError::PaddingError,
389 nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError,
390 nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength,
391 nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength,
392 nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
393 nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
394 nativeParseError::InvalidSliceLength (mut a, ) => {
395 ParseError::InvalidSliceLength (
399 nativeParseError::Skip => ParseError::Skip,
403 /// Frees any resources used by the ParseError
405 pub extern "C" fn ParseError_free(this_ptr: ParseError) { }
406 /// Creates a copy of the ParseError
408 pub extern "C" fn ParseError_clone(orig: &ParseError) -> ParseError {
412 /// Utility method to constructs a new Bech32Error-variant ParseError
413 pub extern "C" fn ParseError_bech32_error(a: crate::c_types::Bech32Error) -> ParseError {
414 ParseError::Bech32Error(a, )
417 /// Utility method to constructs a new ParseAmountError-variant ParseError
418 pub extern "C" fn ParseError_parse_amount_error(a: crate::c_types::Error) -> ParseError {
419 ParseError::ParseAmountError(a, )
422 /// Utility method to constructs a new MalformedSignature-variant ParseError
423 pub extern "C" fn ParseError_malformed_signature(a: crate::c_types::Secp256k1Error) -> ParseError {
424 ParseError::MalformedSignature(a, )
427 /// Utility method to constructs a new BadPrefix-variant ParseError
428 pub extern "C" fn ParseError_bad_prefix() -> ParseError {
429 ParseError::BadPrefix}
431 /// Utility method to constructs a new UnknownCurrency-variant ParseError
432 pub extern "C" fn ParseError_unknown_currency() -> ParseError {
433 ParseError::UnknownCurrency}
435 /// Utility method to constructs a new UnknownSiPrefix-variant ParseError
436 pub extern "C" fn ParseError_unknown_si_prefix() -> ParseError {
437 ParseError::UnknownSiPrefix}
439 /// Utility method to constructs a new MalformedHRP-variant ParseError
440 pub extern "C" fn ParseError_malformed_hrp() -> ParseError {
441 ParseError::MalformedHRP}
443 /// Utility method to constructs a new TooShortDataPart-variant ParseError
444 pub extern "C" fn ParseError_too_short_data_part() -> ParseError {
445 ParseError::TooShortDataPart}
447 /// Utility method to constructs a new UnexpectedEndOfTaggedFields-variant ParseError
448 pub extern "C" fn ParseError_unexpected_end_of_tagged_fields() -> ParseError {
449 ParseError::UnexpectedEndOfTaggedFields}
451 /// Utility method to constructs a new DescriptionDecodeError-variant ParseError
452 pub extern "C" fn ParseError_description_decode_error(a: crate::c_types::Error) -> ParseError {
453 ParseError::DescriptionDecodeError(a, )
456 /// Utility method to constructs a new PaddingError-variant ParseError
457 pub extern "C" fn ParseError_padding_error() -> ParseError {
458 ParseError::PaddingError}
460 /// Utility method to constructs a new IntegerOverflowError-variant ParseError
461 pub extern "C" fn ParseError_integer_overflow_error() -> ParseError {
462 ParseError::IntegerOverflowError}
464 /// Utility method to constructs a new InvalidSegWitProgramLength-variant ParseError
465 pub extern "C" fn ParseError_invalid_seg_wit_program_length() -> ParseError {
466 ParseError::InvalidSegWitProgramLength}
468 /// Utility method to constructs a new InvalidPubKeyHashLength-variant ParseError
469 pub extern "C" fn ParseError_invalid_pub_key_hash_length() -> ParseError {
470 ParseError::InvalidPubKeyHashLength}
472 /// Utility method to constructs a new InvalidScriptHashLength-variant ParseError
473 pub extern "C" fn ParseError_invalid_script_hash_length() -> ParseError {
474 ParseError::InvalidScriptHashLength}
476 /// Utility method to constructs a new InvalidRecoveryId-variant ParseError
477 pub extern "C" fn ParseError_invalid_recovery_id() -> ParseError {
478 ParseError::InvalidRecoveryId}
480 /// Utility method to constructs a new InvalidSliceLength-variant ParseError
481 pub extern "C" fn ParseError_invalid_slice_length(a: crate::c_types::Str) -> ParseError {
482 ParseError::InvalidSliceLength(a, )
485 /// Utility method to constructs a new Skip-variant ParseError
486 pub extern "C" fn ParseError_skip() -> ParseError {
488 /// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
489 /// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
490 /// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
494 pub enum ParseOrSemanticError {
495 /// The invoice couldn't be decoded
497 crate::lightning_invoice::ParseError),
498 /// The invoice could be decoded but violates the BOLT11 standard
500 crate::lightning_invoice::SemanticError),
502 use lightning_invoice::ParseOrSemanticError as ParseOrSemanticErrorImport;
503 pub(crate) type nativeParseOrSemanticError = ParseOrSemanticErrorImport;
505 impl ParseOrSemanticError {
507 pub(crate) fn to_native(&self) -> nativeParseOrSemanticError {
509 ParseOrSemanticError::ParseError (ref a, ) => {
510 let mut a_nonref = (*a).clone();
511 nativeParseOrSemanticError::ParseError (
512 a_nonref.into_native(),
515 ParseOrSemanticError::SemanticError (ref a, ) => {
516 let mut a_nonref = (*a).clone();
517 nativeParseOrSemanticError::SemanticError (
518 a_nonref.into_native(),
524 pub(crate) fn into_native(self) -> nativeParseOrSemanticError {
526 ParseOrSemanticError::ParseError (mut a, ) => {
527 nativeParseOrSemanticError::ParseError (
531 ParseOrSemanticError::SemanticError (mut a, ) => {
532 nativeParseOrSemanticError::SemanticError (
539 pub(crate) fn from_native(native: &nativeParseOrSemanticError) -> Self {
541 nativeParseOrSemanticError::ParseError (ref a, ) => {
542 let mut a_nonref = (*a).clone();
543 ParseOrSemanticError::ParseError (
544 crate::lightning_invoice::ParseError::native_into(a_nonref),
547 nativeParseOrSemanticError::SemanticError (ref a, ) => {
548 let mut a_nonref = (*a).clone();
549 ParseOrSemanticError::SemanticError (
550 crate::lightning_invoice::SemanticError::native_into(a_nonref),
556 pub(crate) fn native_into(native: nativeParseOrSemanticError) -> Self {
558 nativeParseOrSemanticError::ParseError (mut a, ) => {
559 ParseOrSemanticError::ParseError (
560 crate::lightning_invoice::ParseError::native_into(a),
563 nativeParseOrSemanticError::SemanticError (mut a, ) => {
564 ParseOrSemanticError::SemanticError (
565 crate::lightning_invoice::SemanticError::native_into(a),
571 /// Frees any resources used by the ParseOrSemanticError
573 pub extern "C" fn ParseOrSemanticError_free(this_ptr: ParseOrSemanticError) { }
574 /// Creates a copy of the ParseOrSemanticError
576 pub extern "C" fn ParseOrSemanticError_clone(orig: &ParseOrSemanticError) -> ParseOrSemanticError {
580 /// Utility method to constructs a new ParseError-variant ParseOrSemanticError
581 pub extern "C" fn ParseOrSemanticError_parse_error(a: crate::lightning_invoice::ParseError) -> ParseOrSemanticError {
582 ParseOrSemanticError::ParseError(a, )
585 /// Utility method to constructs a new SemanticError-variant ParseOrSemanticError
586 pub extern "C" fn ParseOrSemanticError_semantic_error(a: crate::lightning_invoice::SemanticError) -> ParseOrSemanticError {
587 ParseOrSemanticError::SemanticError(a, )
589 /// The maximum timestamp as [`Duration::as_secs`] since the Unix epoch allowed by [`BOLT 11`].
591 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
594 pub static MAX_TIMESTAMP: u64 = lightning_invoice::MAX_TIMESTAMP;
595 /// Default expiry time as defined by [BOLT 11].
597 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
600 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
601 /// Default minimum final CLTV expiry as defined by [BOLT 11].
603 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
604 /// provided in [`MIN_FINAL_CLTV_EXPIRY`].
606 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
607 /// [`MIN_FINAL_CLTV_EXPIRY`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY
610 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY;
612 use lightning_invoice::Invoice as nativeInvoiceImport;
613 pub(crate) type nativeInvoice = nativeInvoiceImport;
615 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
617 /// There are three ways to construct an `Invoice`:
618 /// 1. using `InvoiceBuilder`
619 /// 2. using `Invoice::from_signed(SignedRawInvoice)`
620 /// 3. using `str::parse::<Invoice>(&str)`
624 /// A pointer to the opaque Rust object.
626 /// Nearly everywhere, inner must be non-null, however in places where
627 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
628 pub inner: *mut nativeInvoice,
629 /// Indicates that this is the only struct which contains the same pointer.
631 /// Rust functions which take ownership of an object provided via an argument require
632 /// this to be true and invalidate the object pointed to by inner.
636 impl Drop for Invoice {
638 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
639 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
643 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
645 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
647 /// Used only if an object of this type is returned as a trait impl by a method
648 pub(crate) extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
649 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
653 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoice {
654 unsafe { &*ObjOps::untweak_ptr(self.inner) }
656 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoice {
657 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
659 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
660 pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
661 assert!(self.is_owned);
662 let ret = ObjOps::untweak_ptr(self.inner);
663 self.inner = core::ptr::null_mut();
667 /// Checks if two Invoices contain equal inner contents.
668 /// This ignores pointers and is_owned flags and looks at the values in fields.
669 /// Two objects with NULL inner values will be considered "equal" here.
671 pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool {
672 if a.inner == b.inner { return true; }
673 if a.inner.is_null() || b.inner.is_null() { return false; }
674 if a.get_native_ref() == b.get_native_ref() { true } else { false }
676 impl Clone for Invoice {
677 fn clone(&self) -> Self {
679 inner: if <*mut nativeInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
680 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
686 /// Used only if an object of this type is returned as a trait impl by a method
687 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
688 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
691 /// Creates a copy of the Invoice
692 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
696 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
697 pub(crate) type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
699 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
703 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
706 pub struct SignedRawInvoice {
707 /// A pointer to the opaque Rust object.
709 /// Nearly everywhere, inner must be non-null, however in places where
710 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
711 pub inner: *mut nativeSignedRawInvoice,
712 /// Indicates that this is the only struct which contains the same pointer.
714 /// Rust functions which take ownership of an object provided via an argument require
715 /// this to be true and invalidate the object pointed to by inner.
719 impl Drop for SignedRawInvoice {
721 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
722 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
726 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
728 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
730 /// Used only if an object of this type is returned as a trait impl by a method
731 pub(crate) extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
732 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
735 impl SignedRawInvoice {
736 pub(crate) fn get_native_ref(&self) -> &'static nativeSignedRawInvoice {
737 unsafe { &*ObjOps::untweak_ptr(self.inner) }
739 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSignedRawInvoice {
740 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
742 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
743 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
744 assert!(self.is_owned);
745 let ret = ObjOps::untweak_ptr(self.inner);
746 self.inner = core::ptr::null_mut();
750 /// Checks if two SignedRawInvoices contain equal inner contents.
751 /// This ignores pointers and is_owned flags and looks at the values in fields.
752 /// Two objects with NULL inner values will be considered "equal" here.
754 pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice) -> bool {
755 if a.inner == b.inner { return true; }
756 if a.inner.is_null() || b.inner.is_null() { return false; }
757 if a.get_native_ref() == b.get_native_ref() { true } else { false }
759 impl Clone for SignedRawInvoice {
760 fn clone(&self) -> Self {
762 inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
763 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
769 /// Used only if an object of this type is returned as a trait impl by a method
770 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
771 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
774 /// Creates a copy of the SignedRawInvoice
775 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
779 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
780 pub(crate) type nativeRawInvoice = nativeRawInvoiceImport;
782 /// Represents an syntactically correct Invoice for a payment on the lightning network,
783 /// but without the signature information.
784 /// De- and encoding should not lead to information loss but may lead to different hashes.
786 /// For methods without docs see the corresponding methods in `Invoice`.
789 pub struct RawInvoice {
790 /// A pointer to the opaque Rust object.
792 /// Nearly everywhere, inner must be non-null, however in places where
793 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
794 pub inner: *mut nativeRawInvoice,
795 /// Indicates that this is the only struct which contains the same pointer.
797 /// Rust functions which take ownership of an object provided via an argument require
798 /// this to be true and invalidate the object pointed to by inner.
802 impl Drop for RawInvoice {
804 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
805 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
809 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
811 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
813 /// Used only if an object of this type is returned as a trait impl by a method
814 pub(crate) extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
815 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
819 pub(crate) fn get_native_ref(&self) -> &'static nativeRawInvoice {
820 unsafe { &*ObjOps::untweak_ptr(self.inner) }
822 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawInvoice {
823 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
825 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
826 pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
827 assert!(self.is_owned);
828 let ret = ObjOps::untweak_ptr(self.inner);
829 self.inner = core::ptr::null_mut();
835 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
836 let mut inner_val = &mut this_ptr.get_native_mut_ref().data;
837 crate::lightning_invoice::RawDataPart { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::RawDataPart<>) as *mut _) }, is_owned: false }
841 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
842 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.data = *unsafe { Box::from_raw(val.take_inner()) };
844 /// Checks if two RawInvoices contain equal inner contents.
845 /// This ignores pointers and is_owned flags and looks at the values in fields.
846 /// Two objects with NULL inner values will be considered "equal" here.
848 pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool {
849 if a.inner == b.inner { return true; }
850 if a.inner.is_null() || b.inner.is_null() { return false; }
851 if a.get_native_ref() == b.get_native_ref() { true } else { false }
853 impl Clone for RawInvoice {
854 fn clone(&self) -> Self {
856 inner: if <*mut nativeRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
857 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
863 /// Used only if an object of this type is returned as a trait impl by a method
864 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
865 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
868 /// Creates a copy of the RawInvoice
869 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
873 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
874 pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
876 /// Data of the `RawInvoice` that is encoded in the data part
879 pub struct RawDataPart {
880 /// A pointer to the opaque Rust object.
882 /// Nearly everywhere, inner must be non-null, however in places where
883 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
884 pub inner: *mut nativeRawDataPart,
885 /// Indicates that this is the only struct which contains the same pointer.
887 /// Rust functions which take ownership of an object provided via an argument require
888 /// this to be true and invalidate the object pointed to by inner.
892 impl Drop for RawDataPart {
894 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
895 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
899 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
901 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
903 /// Used only if an object of this type is returned as a trait impl by a method
904 pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
905 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
909 pub(crate) fn get_native_ref(&self) -> &'static nativeRawDataPart {
910 unsafe { &*ObjOps::untweak_ptr(self.inner) }
912 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawDataPart {
913 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
915 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
916 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
917 assert!(self.is_owned);
918 let ret = ObjOps::untweak_ptr(self.inner);
919 self.inner = core::ptr::null_mut();
923 /// generation time of the invoice
925 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
926 let mut inner_val = &mut this_ptr.get_native_mut_ref().timestamp;
927 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::PositiveTimestamp<>) as *mut _) }, is_owned: false }
929 /// generation time of the invoice
931 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
932 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
934 /// Checks if two RawDataParts contain equal inner contents.
935 /// This ignores pointers and is_owned flags and looks at the values in fields.
936 /// Two objects with NULL inner values will be considered "equal" here.
938 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
939 if a.inner == b.inner { return true; }
940 if a.inner.is_null() || b.inner.is_null() { return false; }
941 if a.get_native_ref() == b.get_native_ref() { true } else { false }
943 impl Clone for RawDataPart {
944 fn clone(&self) -> Self {
946 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { core::ptr::null_mut() } else {
947 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
953 /// Used only if an object of this type is returned as a trait impl by a method
954 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
955 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
958 /// Creates a copy of the RawDataPart
959 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
963 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
964 pub(crate) type nativePositiveTimestamp = nativePositiveTimestampImport;
966 /// A timestamp that refers to a date after 1 January 1970.
970 /// The Unix timestamp representing the stored time has to be positive and no greater than
971 /// [`MAX_TIMESTAMP`].
974 pub struct PositiveTimestamp {
975 /// A pointer to the opaque Rust object.
977 /// Nearly everywhere, inner must be non-null, however in places where
978 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
979 pub inner: *mut nativePositiveTimestamp,
980 /// Indicates that this is the only struct which contains the same pointer.
982 /// Rust functions which take ownership of an object provided via an argument require
983 /// this to be true and invalidate the object pointed to by inner.
987 impl Drop for PositiveTimestamp {
989 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
990 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
994 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
996 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
998 /// Used only if an object of this type is returned as a trait impl by a method
999 pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
1000 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
1003 impl PositiveTimestamp {
1004 pub(crate) fn get_native_ref(&self) -> &'static nativePositiveTimestamp {
1005 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1007 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePositiveTimestamp {
1008 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1010 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1011 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
1012 assert!(self.is_owned);
1013 let ret = ObjOps::untweak_ptr(self.inner);
1014 self.inner = core::ptr::null_mut();
1018 /// Checks if two PositiveTimestamps contain equal inner contents.
1019 /// This ignores pointers and is_owned flags and looks at the values in fields.
1020 /// Two objects with NULL inner values will be considered "equal" here.
1022 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
1023 if a.inner == b.inner { return true; }
1024 if a.inner.is_null() || b.inner.is_null() { return false; }
1025 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1027 impl Clone for PositiveTimestamp {
1028 fn clone(&self) -> Self {
1030 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { core::ptr::null_mut() } else {
1031 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1037 /// Used only if an object of this type is returned as a trait impl by a method
1038 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
1039 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
1042 /// Creates a copy of the PositiveTimestamp
1043 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
1046 /// SI prefixes for the human readable part
1060 use lightning_invoice::SiPrefix as SiPrefixImport;
1061 pub(crate) type nativeSiPrefix = SiPrefixImport;
1065 pub(crate) fn to_native(&self) -> nativeSiPrefix {
1067 SiPrefix::Milli => nativeSiPrefix::Milli,
1068 SiPrefix::Micro => nativeSiPrefix::Micro,
1069 SiPrefix::Nano => nativeSiPrefix::Nano,
1070 SiPrefix::Pico => nativeSiPrefix::Pico,
1074 pub(crate) fn into_native(self) -> nativeSiPrefix {
1076 SiPrefix::Milli => nativeSiPrefix::Milli,
1077 SiPrefix::Micro => nativeSiPrefix::Micro,
1078 SiPrefix::Nano => nativeSiPrefix::Nano,
1079 SiPrefix::Pico => nativeSiPrefix::Pico,
1083 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
1085 nativeSiPrefix::Milli => SiPrefix::Milli,
1086 nativeSiPrefix::Micro => SiPrefix::Micro,
1087 nativeSiPrefix::Nano => SiPrefix::Nano,
1088 nativeSiPrefix::Pico => SiPrefix::Pico,
1092 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
1094 nativeSiPrefix::Milli => SiPrefix::Milli,
1095 nativeSiPrefix::Micro => SiPrefix::Micro,
1096 nativeSiPrefix::Nano => SiPrefix::Nano,
1097 nativeSiPrefix::Pico => SiPrefix::Pico,
1101 /// Creates a copy of the SiPrefix
1103 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
1107 /// Utility method to constructs a new Milli-variant SiPrefix
1108 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
1111 /// Utility method to constructs a new Micro-variant SiPrefix
1112 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
1115 /// Utility method to constructs a new Nano-variant SiPrefix
1116 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
1119 /// Utility method to constructs a new Pico-variant SiPrefix
1120 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
1122 /// Checks if two SiPrefixs contain equal inner contents.
1123 /// This ignores pointers and is_owned flags and looks at the values in fields.
1125 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
1126 if &a.to_native() == &b.to_native() { true } else { false }
1128 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
1129 /// This is effectively 10^12 * the prefix multiplier
1132 pub extern "C" fn SiPrefix_multiplier(this_arg: &crate::lightning_invoice::SiPrefix) -> u64 {
1133 let mut ret = this_arg.to_native().multiplier();
1137 /// Enum representing the crypto currencies (or networks) supported by this library
1153 use lightning_invoice::Currency as CurrencyImport;
1154 pub(crate) type nativeCurrency = CurrencyImport;
1158 pub(crate) fn to_native(&self) -> nativeCurrency {
1160 Currency::Bitcoin => nativeCurrency::Bitcoin,
1161 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1162 Currency::Regtest => nativeCurrency::Regtest,
1163 Currency::Simnet => nativeCurrency::Simnet,
1164 Currency::Signet => nativeCurrency::Signet,
1168 pub(crate) fn into_native(self) -> nativeCurrency {
1170 Currency::Bitcoin => nativeCurrency::Bitcoin,
1171 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1172 Currency::Regtest => nativeCurrency::Regtest,
1173 Currency::Simnet => nativeCurrency::Simnet,
1174 Currency::Signet => nativeCurrency::Signet,
1178 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
1180 nativeCurrency::Bitcoin => Currency::Bitcoin,
1181 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1182 nativeCurrency::Regtest => Currency::Regtest,
1183 nativeCurrency::Simnet => Currency::Simnet,
1184 nativeCurrency::Signet => Currency::Signet,
1188 pub(crate) fn native_into(native: nativeCurrency) -> Self {
1190 nativeCurrency::Bitcoin => Currency::Bitcoin,
1191 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1192 nativeCurrency::Regtest => Currency::Regtest,
1193 nativeCurrency::Simnet => Currency::Simnet,
1194 nativeCurrency::Signet => Currency::Signet,
1198 /// Creates a copy of the Currency
1200 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
1204 /// Utility method to constructs a new Bitcoin-variant Currency
1205 pub extern "C" fn Currency_bitcoin() -> Currency {
1208 /// Utility method to constructs a new BitcoinTestnet-variant Currency
1209 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
1210 Currency::BitcoinTestnet}
1212 /// Utility method to constructs a new Regtest-variant Currency
1213 pub extern "C" fn Currency_regtest() -> Currency {
1216 /// Utility method to constructs a new Simnet-variant Currency
1217 pub extern "C" fn Currency_simnet() -> Currency {
1220 /// Utility method to constructs a new Signet-variant Currency
1221 pub extern "C" fn Currency_signet() -> Currency {
1223 /// Checks if two Currencys contain equal inner contents.
1225 pub extern "C" fn Currency_hash(o: &Currency) -> u64 {
1226 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1227 #[allow(deprecated)]
1228 let mut hasher = core::hash::SipHasher::new();
1229 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1230 core::hash::Hasher::finish(&hasher)
1232 /// Checks if two Currencys contain equal inner contents.
1233 /// This ignores pointers and is_owned flags and looks at the values in fields.
1235 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
1236 if &a.to_native() == &b.to_native() { true } else { false }
1239 use lightning_invoice::Sha256 as nativeSha256Import;
1240 pub(crate) type nativeSha256 = nativeSha256Import;
1246 /// A pointer to the opaque Rust object.
1248 /// Nearly everywhere, inner must be non-null, however in places where
1249 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1250 pub inner: *mut nativeSha256,
1251 /// Indicates that this is the only struct which contains the same pointer.
1253 /// Rust functions which take ownership of an object provided via an argument require
1254 /// this to be true and invalidate the object pointed to by inner.
1258 impl Drop for Sha256 {
1259 fn drop(&mut self) {
1260 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
1261 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1265 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
1267 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
1269 /// Used only if an object of this type is returned as a trait impl by a method
1270 pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
1271 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
1275 pub(crate) fn get_native_ref(&self) -> &'static nativeSha256 {
1276 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1278 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSha256 {
1279 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1281 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1282 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
1283 assert!(self.is_owned);
1284 let ret = ObjOps::untweak_ptr(self.inner);
1285 self.inner = core::ptr::null_mut();
1289 impl Clone for Sha256 {
1290 fn clone(&self) -> Self {
1292 inner: if <*mut nativeSha256>::is_null(self.inner) { core::ptr::null_mut() } else {
1293 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1299 /// Used only if an object of this type is returned as a trait impl by a method
1300 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
1301 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
1304 /// Creates a copy of the Sha256
1305 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
1308 /// Checks if two Sha256s contain equal inner contents.
1310 pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 {
1311 if o.inner.is_null() { return 0; }
1312 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1313 #[allow(deprecated)]
1314 let mut hasher = core::hash::SipHasher::new();
1315 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1316 core::hash::Hasher::finish(&hasher)
1318 /// Checks if two Sha256s contain equal inner contents.
1319 /// This ignores pointers and is_owned flags and looks at the values in fields.
1320 /// Two objects with NULL inner values will be considered "equal" here.
1322 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
1323 if a.inner == b.inner { return true; }
1324 if a.inner.is_null() || b.inner.is_null() { return false; }
1325 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1328 use lightning_invoice::Description as nativeDescriptionImport;
1329 pub(crate) type nativeDescription = nativeDescriptionImport;
1331 /// Description string
1334 /// The description can be at most 639 __bytes__ long
1337 pub struct Description {
1338 /// A pointer to the opaque Rust object.
1340 /// Nearly everywhere, inner must be non-null, however in places where
1341 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1342 pub inner: *mut nativeDescription,
1343 /// Indicates that this is the only struct which contains the same pointer.
1345 /// Rust functions which take ownership of an object provided via an argument require
1346 /// this to be true and invalidate the object pointed to by inner.
1350 impl Drop for Description {
1351 fn drop(&mut self) {
1352 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
1353 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1357 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
1359 pub extern "C" fn Description_free(this_obj: Description) { }
1361 /// Used only if an object of this type is returned as a trait impl by a method
1362 pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) {
1363 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
1367 pub(crate) fn get_native_ref(&self) -> &'static nativeDescription {
1368 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1370 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDescription {
1371 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1373 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1374 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
1375 assert!(self.is_owned);
1376 let ret = ObjOps::untweak_ptr(self.inner);
1377 self.inner = core::ptr::null_mut();
1381 impl Clone for Description {
1382 fn clone(&self) -> Self {
1384 inner: if <*mut nativeDescription>::is_null(self.inner) { core::ptr::null_mut() } else {
1385 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1391 /// Used only if an object of this type is returned as a trait impl by a method
1392 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
1393 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
1396 /// Creates a copy of the Description
1397 pub extern "C" fn Description_clone(orig: &Description) -> Description {
1400 /// Checks if two Descriptions contain equal inner contents.
1402 pub extern "C" fn Description_hash(o: &Description) -> u64 {
1403 if o.inner.is_null() { return 0; }
1404 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1405 #[allow(deprecated)]
1406 let mut hasher = core::hash::SipHasher::new();
1407 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1408 core::hash::Hasher::finish(&hasher)
1410 /// Checks if two Descriptions contain equal inner contents.
1411 /// This ignores pointers and is_owned flags and looks at the values in fields.
1412 /// Two objects with NULL inner values will be considered "equal" here.
1414 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
1415 if a.inner == b.inner { return true; }
1416 if a.inner.is_null() || b.inner.is_null() { return false; }
1417 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1420 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
1421 pub(crate) type nativePayeePubKey = nativePayeePubKeyImport;
1423 /// Payee public key
1426 pub struct PayeePubKey {
1427 /// A pointer to the opaque Rust object.
1429 /// Nearly everywhere, inner must be non-null, however in places where
1430 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1431 pub inner: *mut nativePayeePubKey,
1432 /// Indicates that this is the only struct which contains the same pointer.
1434 /// Rust functions which take ownership of an object provided via an argument require
1435 /// this to be true and invalidate the object pointed to by inner.
1439 impl Drop for PayeePubKey {
1440 fn drop(&mut self) {
1441 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
1442 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1446 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
1448 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
1450 /// Used only if an object of this type is returned as a trait impl by a method
1451 pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
1452 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
1456 pub(crate) fn get_native_ref(&self) -> &'static nativePayeePubKey {
1457 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1459 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayeePubKey {
1460 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1462 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1463 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
1464 assert!(self.is_owned);
1465 let ret = ObjOps::untweak_ptr(self.inner);
1466 self.inner = core::ptr::null_mut();
1471 pub extern "C" fn PayeePubKey_get_a(this_ptr: &PayeePubKey) -> crate::c_types::PublicKey {
1472 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1473 crate::c_types::PublicKey::from_rust(&inner_val)
1476 pub extern "C" fn PayeePubKey_set_a(this_ptr: &mut PayeePubKey, mut val: crate::c_types::PublicKey) {
1477 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
1479 /// Constructs a new PayeePubKey given each field
1482 pub extern "C" fn PayeePubKey_new(mut a_arg: crate::c_types::PublicKey) -> PayeePubKey {
1483 PayeePubKey { inner: ObjOps::heap_alloc(lightning_invoice::PayeePubKey (
1485 )), is_owned: true }
1487 impl Clone for PayeePubKey {
1488 fn clone(&self) -> Self {
1490 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { core::ptr::null_mut() } else {
1491 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1497 /// Used only if an object of this type is returned as a trait impl by a method
1498 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
1499 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
1502 /// Creates a copy of the PayeePubKey
1503 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
1506 /// Checks if two PayeePubKeys contain equal inner contents.
1508 pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 {
1509 if o.inner.is_null() { return 0; }
1510 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1511 #[allow(deprecated)]
1512 let mut hasher = core::hash::SipHasher::new();
1513 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1514 core::hash::Hasher::finish(&hasher)
1516 /// Checks if two PayeePubKeys contain equal inner contents.
1517 /// This ignores pointers and is_owned flags and looks at the values in fields.
1518 /// Two objects with NULL inner values will be considered "equal" here.
1520 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
1521 if a.inner == b.inner { return true; }
1522 if a.inner.is_null() || b.inner.is_null() { return false; }
1523 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1526 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
1527 pub(crate) type nativeExpiryTime = nativeExpiryTimeImport;
1529 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
1533 pub struct ExpiryTime {
1534 /// A pointer to the opaque Rust object.
1536 /// Nearly everywhere, inner must be non-null, however in places where
1537 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1538 pub inner: *mut nativeExpiryTime,
1539 /// Indicates that this is the only struct which contains the same pointer.
1541 /// Rust functions which take ownership of an object provided via an argument require
1542 /// this to be true and invalidate the object pointed to by inner.
1546 impl Drop for ExpiryTime {
1547 fn drop(&mut self) {
1548 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
1549 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1553 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
1555 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
1557 /// Used only if an object of this type is returned as a trait impl by a method
1558 pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
1559 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
1563 pub(crate) fn get_native_ref(&self) -> &'static nativeExpiryTime {
1564 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1566 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpiryTime {
1567 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1569 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1570 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
1571 assert!(self.is_owned);
1572 let ret = ObjOps::untweak_ptr(self.inner);
1573 self.inner = core::ptr::null_mut();
1577 impl Clone for ExpiryTime {
1578 fn clone(&self) -> Self {
1580 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { core::ptr::null_mut() } else {
1581 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1587 /// Used only if an object of this type is returned as a trait impl by a method
1588 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1589 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1592 /// Creates a copy of the ExpiryTime
1593 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1596 /// Checks if two ExpiryTimes contain equal inner contents.
1598 pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 {
1599 if o.inner.is_null() { return 0; }
1600 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1601 #[allow(deprecated)]
1602 let mut hasher = core::hash::SipHasher::new();
1603 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1604 core::hash::Hasher::finish(&hasher)
1606 /// Checks if two ExpiryTimes contain equal inner contents.
1607 /// This ignores pointers and is_owned flags and looks at the values in fields.
1608 /// Two objects with NULL inner values will be considered "equal" here.
1610 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1611 if a.inner == b.inner { return true; }
1612 if a.inner.is_null() || b.inner.is_null() { return false; }
1613 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1616 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
1617 pub(crate) type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
1619 /// `min_final_cltv_expiry` to use for the last HTLC in the route
1622 pub struct MinFinalCltvExpiry {
1623 /// A pointer to the opaque Rust object.
1625 /// Nearly everywhere, inner must be non-null, however in places where
1626 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1627 pub inner: *mut nativeMinFinalCltvExpiry,
1628 /// Indicates that this is the only struct which contains the same pointer.
1630 /// Rust functions which take ownership of an object provided via an argument require
1631 /// this to be true and invalidate the object pointed to by inner.
1635 impl Drop for MinFinalCltvExpiry {
1636 fn drop(&mut self) {
1637 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
1638 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1642 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1644 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1646 /// Used only if an object of this type is returned as a trait impl by a method
1647 pub(crate) extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1648 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1651 impl MinFinalCltvExpiry {
1652 pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiry {
1653 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1655 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiry {
1656 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1658 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1659 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1660 assert!(self.is_owned);
1661 let ret = ObjOps::untweak_ptr(self.inner);
1662 self.inner = core::ptr::null_mut();
1667 pub extern "C" fn MinFinalCltvExpiry_get_a(this_ptr: &MinFinalCltvExpiry) -> u64 {
1668 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1672 pub extern "C" fn MinFinalCltvExpiry_set_a(this_ptr: &mut MinFinalCltvExpiry, mut val: u64) {
1673 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val;
1675 /// Constructs a new MinFinalCltvExpiry given each field
1678 pub extern "C" fn MinFinalCltvExpiry_new(mut a_arg: u64) -> MinFinalCltvExpiry {
1679 MinFinalCltvExpiry { inner: ObjOps::heap_alloc(lightning_invoice::MinFinalCltvExpiry (
1681 )), is_owned: true }
1683 impl Clone for MinFinalCltvExpiry {
1684 fn clone(&self) -> Self {
1686 inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { core::ptr::null_mut() } else {
1687 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1693 /// Used only if an object of this type is returned as a trait impl by a method
1694 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1695 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1698 /// Creates a copy of the MinFinalCltvExpiry
1699 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1702 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1704 pub extern "C" fn MinFinalCltvExpiry_hash(o: &MinFinalCltvExpiry) -> u64 {
1705 if o.inner.is_null() { return 0; }
1706 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1707 #[allow(deprecated)]
1708 let mut hasher = core::hash::SipHasher::new();
1709 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1710 core::hash::Hasher::finish(&hasher)
1712 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1713 /// This ignores pointers and is_owned flags and looks at the values in fields.
1714 /// Two objects with NULL inner values will be considered "equal" here.
1716 pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool {
1717 if a.inner == b.inner { return true; }
1718 if a.inner.is_null() || b.inner.is_null() { return false; }
1719 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1721 /// Fallback address in case no LN payment is possible
1727 version: crate::c_types::u5,
1728 program: crate::c_types::derived::CVec_u8Z,
1731 crate::c_types::TwentyBytes),
1733 crate::c_types::TwentyBytes),
1735 use lightning_invoice::Fallback as FallbackImport;
1736 pub(crate) type nativeFallback = FallbackImport;
1740 pub(crate) fn to_native(&self) -> nativeFallback {
1742 Fallback::SegWitProgram {ref version, ref program, } => {
1743 let mut version_nonref = (*version).clone();
1744 let mut program_nonref = (*program).clone();
1745 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1746 nativeFallback::SegWitProgram {
1747 version: version_nonref.into(),
1748 program: local_program_nonref,
1751 Fallback::PubKeyHash (ref a, ) => {
1752 let mut a_nonref = (*a).clone();
1753 nativeFallback::PubKeyHash (
1757 Fallback::ScriptHash (ref a, ) => {
1758 let mut a_nonref = (*a).clone();
1759 nativeFallback::ScriptHash (
1766 pub(crate) fn into_native(self) -> nativeFallback {
1768 Fallback::SegWitProgram {mut version, mut program, } => {
1769 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1770 nativeFallback::SegWitProgram {
1771 version: version.into(),
1772 program: local_program,
1775 Fallback::PubKeyHash (mut a, ) => {
1776 nativeFallback::PubKeyHash (
1780 Fallback::ScriptHash (mut a, ) => {
1781 nativeFallback::ScriptHash (
1788 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1790 nativeFallback::SegWitProgram {ref version, ref program, } => {
1791 let mut version_nonref = (*version).clone();
1792 let mut program_nonref = (*program).clone();
1793 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1794 Fallback::SegWitProgram {
1795 version: version_nonref.into(),
1796 program: local_program_nonref.into(),
1799 nativeFallback::PubKeyHash (ref a, ) => {
1800 let mut a_nonref = (*a).clone();
1801 Fallback::PubKeyHash (
1802 crate::c_types::TwentyBytes { data: a_nonref },
1805 nativeFallback::ScriptHash (ref a, ) => {
1806 let mut a_nonref = (*a).clone();
1807 Fallback::ScriptHash (
1808 crate::c_types::TwentyBytes { data: a_nonref },
1814 pub(crate) fn native_into(native: nativeFallback) -> Self {
1816 nativeFallback::SegWitProgram {mut version, mut program, } => {
1817 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1818 Fallback::SegWitProgram {
1819 version: version.into(),
1820 program: local_program.into(),
1823 nativeFallback::PubKeyHash (mut a, ) => {
1824 Fallback::PubKeyHash (
1825 crate::c_types::TwentyBytes { data: a },
1828 nativeFallback::ScriptHash (mut a, ) => {
1829 Fallback::ScriptHash (
1830 crate::c_types::TwentyBytes { data: a },
1836 /// Frees any resources used by the Fallback
1838 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1839 /// Creates a copy of the Fallback
1841 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1845 /// Utility method to constructs a new SegWitProgram-variant Fallback
1846 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::u5, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
1847 Fallback::SegWitProgram {
1853 /// Utility method to constructs a new PubKeyHash-variant Fallback
1854 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1855 Fallback::PubKeyHash(a, )
1858 /// Utility method to constructs a new ScriptHash-variant Fallback
1859 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1860 Fallback::ScriptHash(a, )
1862 /// Checks if two Fallbacks contain equal inner contents.
1864 pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 {
1865 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1866 #[allow(deprecated)]
1867 let mut hasher = core::hash::SipHasher::new();
1868 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1869 core::hash::Hasher::finish(&hasher)
1871 /// Checks if two Fallbacks contain equal inner contents.
1872 /// This ignores pointers and is_owned flags and looks at the values in fields.
1874 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1875 if &a.to_native() == &b.to_native() { true } else { false }
1878 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1879 pub(crate) type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1881 /// Recoverable signature
1884 pub struct InvoiceSignature {
1885 /// A pointer to the opaque Rust object.
1887 /// Nearly everywhere, inner must be non-null, however in places where
1888 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1889 pub inner: *mut nativeInvoiceSignature,
1890 /// Indicates that this is the only struct which contains the same pointer.
1892 /// Rust functions which take ownership of an object provided via an argument require
1893 /// this to be true and invalidate the object pointed to by inner.
1897 impl Drop for InvoiceSignature {
1898 fn drop(&mut self) {
1899 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1900 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1904 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1906 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
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_free_void(this_ptr: *mut c_void) {
1910 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1913 impl InvoiceSignature {
1914 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceSignature {
1915 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1917 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceSignature {
1918 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1920 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1921 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1922 assert!(self.is_owned);
1923 let ret = ObjOps::untweak_ptr(self.inner);
1924 self.inner = core::ptr::null_mut();
1928 impl Clone for InvoiceSignature {
1929 fn clone(&self) -> Self {
1931 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { core::ptr::null_mut() } else {
1932 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1938 /// Used only if an object of this type is returned as a trait impl by a method
1939 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
1940 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
1943 /// Creates a copy of the InvoiceSignature
1944 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
1947 /// Checks if two InvoiceSignatures contain equal inner contents.
1948 /// This ignores pointers and is_owned flags and looks at the values in fields.
1949 /// Two objects with NULL inner values will be considered "equal" here.
1951 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
1952 if a.inner == b.inner { return true; }
1953 if a.inner.is_null() || b.inner.is_null() { return false; }
1954 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1957 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
1958 pub(crate) type nativePrivateRoute = nativePrivateRouteImport;
1960 /// Private routing information
1963 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
1967 pub struct PrivateRoute {
1968 /// A pointer to the opaque Rust object.
1970 /// Nearly everywhere, inner must be non-null, however in places where
1971 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1972 pub inner: *mut nativePrivateRoute,
1973 /// Indicates that this is the only struct which contains the same pointer.
1975 /// Rust functions which take ownership of an object provided via an argument require
1976 /// this to be true and invalidate the object pointed to by inner.
1980 impl Drop for PrivateRoute {
1981 fn drop(&mut self) {
1982 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
1983 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1987 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
1989 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
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_free_void(this_ptr: *mut c_void) {
1993 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); }
1997 pub(crate) fn get_native_ref(&self) -> &'static nativePrivateRoute {
1998 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2000 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateRoute {
2001 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2003 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2004 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
2005 assert!(self.is_owned);
2006 let ret = ObjOps::untweak_ptr(self.inner);
2007 self.inner = core::ptr::null_mut();
2011 impl Clone for PrivateRoute {
2012 fn clone(&self) -> Self {
2014 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
2015 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2021 /// Used only if an object of this type is returned as a trait impl by a method
2022 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
2023 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
2026 /// Creates a copy of the PrivateRoute
2027 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
2030 /// Checks if two PrivateRoutes contain equal inner contents.
2032 pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 {
2033 if o.inner.is_null() { return 0; }
2034 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2035 #[allow(deprecated)]
2036 let mut hasher = core::hash::SipHasher::new();
2037 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2038 core::hash::Hasher::finish(&hasher)
2040 /// Checks if two PrivateRoutes contain equal inner contents.
2041 /// This ignores pointers and is_owned flags and looks at the values in fields.
2042 /// Two objects with NULL inner values will be considered "equal" here.
2044 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
2045 if a.inner == b.inner { return true; }
2046 if a.inner.is_null() || b.inner.is_null() { return false; }
2047 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2049 /// Disassembles the `SignedRawInvoice` into its three parts:
2051 /// 2. hash of the raw invoice
2055 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
2056 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
2057 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();
2061 /// The `RawInvoice` which was signed.
2064 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
2065 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice();
2066 crate::lightning_invoice::RawInvoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawInvoice<>) as *mut _) }, is_owned: false }
2069 /// The hash of the `RawInvoice` that was signed.
2072 pub extern "C" fn SignedRawInvoice_hash(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> *const [u8; 32] {
2073 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
2077 /// InvoiceSignature for the invoice.
2080 pub extern "C" fn SignedRawInvoice_signature(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
2081 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
2082 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::InvoiceSignature<>) as *mut _) }, is_owned: false }
2085 /// Recovers the public key used for signing the invoice from the recoverable signature.
2088 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
2089 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2090 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() };
2094 /// Checks if the signature is valid for the included payee public key or if none exists if it's
2095 /// valid for the recovered signature (which should always be true?).
2098 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> bool {
2099 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2103 /// Calculate the hash of the encoded `RawInvoice`
2106 pub extern "C" fn RawInvoice_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes {
2107 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
2108 crate::c_types::ThirtyTwoBytes { data: ret }
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_payment_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Sha256 {
2116 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_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_description(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Description {
2126 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
2127 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 };
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_payee_pub_key(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::PayeePubKey {
2136 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2137 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 };
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_description_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Sha256 {
2146 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash();
2147 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 };
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_expiry_time(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::ExpiryTime {
2156 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2157 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 };
2162 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2165 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
2166 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
2167 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 };
2172 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2175 pub extern "C" fn RawInvoice_payment_secret(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes {
2176 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2177 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
2182 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2185 pub extern "C" fn RawInvoice_features(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
2186 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2187 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 };
2193 pub extern "C" fn RawInvoice_private_routes(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2194 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2195 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 } }); };
2201 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::derived::COption_u64Z {
2202 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
2203 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() }) };
2209 pub extern "C" fn RawInvoice_currency(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Currency {
2210 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2211 crate::lightning_invoice::Currency::native_into(ret)
2214 /// Creates a `PositiveTimestamp` from a Unix timestamp in the range `0..=MAX_TIMESTAMP`.
2216 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2219 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2220 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
2221 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() };
2225 /// Creates a `PositiveTimestamp` from a [`SystemTime`] with a corresponding Unix timestamp in
2226 /// the range `0..=MAX_TIMESTAMP`.
2228 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2231 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2232 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
2233 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() };
2237 /// Creates a `PositiveTimestamp` from a [`Duration`] since the Unix epoch in the range
2238 /// `0..=MAX_TIMESTAMP`.
2240 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2243 pub extern "C" fn PositiveTimestamp_from_duration_since_epoch(mut duration: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2244 let mut ret = lightning_invoice::PositiveTimestamp::from_duration_since_epoch(core::time::Duration::from_secs(duration));
2245 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() };
2249 /// Returns the Unix timestamp representing the stored time
2252 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2253 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_unix_timestamp();
2257 /// Returns the duration of the stored time since the Unix epoch
2260 pub extern "C" fn PositiveTimestamp_as_duration_since_epoch(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2261 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration_since_epoch();
2265 /// Returns the [`SystemTime`] representing the stored time
2268 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2269 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_time();
2270 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2273 /// Transform the `Invoice` into it's unchecked version
2276 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: crate::lightning_invoice::Invoice) -> crate::lightning_invoice::SignedRawInvoice {
2277 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
2278 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(ret), is_owned: true }
2281 /// Check that the invoice is signed correctly and that key recovery works
2284 pub extern "C" fn Invoice_check_signature(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
2285 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2286 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() };
2290 /// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
2292 /// use lightning_invoice::*;
2294 /// let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
2295 /// h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
2296 /// 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
2297 /// h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
2298 /// j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
2299 /// ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
2300 /// guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
2301 /// ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
2302 /// p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
2303 /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
2304 /// j5r6drg6k6zcqj0fcwg\";
2306 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
2308 /// assert!(Invoice::from_signed(signed).is_ok());
2312 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
2313 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
2314 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() };
2318 /// Returns the `Invoice`'s timestamp (should equal its creation time)
2321 pub extern "C" fn Invoice_timestamp(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2322 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timestamp();
2323 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2326 /// Returns the `Invoice`'s timestamp as a duration since the Unix epoch
2329 pub extern "C" fn Invoice_duration_since_epoch(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2330 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_since_epoch();
2334 /// Returns the hash to which we will receive the preimage on completion of the payment
2337 pub extern "C" fn Invoice_payment_hash(this_arg: &crate::lightning_invoice::Invoice) -> *const [u8; 32] {
2338 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2342 /// Get the payee's public key if one was included in the invoice
2344 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2347 pub extern "C" fn Invoice_payee_pub_key(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::PublicKey {
2348 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2349 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
2353 /// Get the payment secret if one was included in the invoice
2356 pub extern "C" fn Invoice_payment_secret(this_arg: &crate::lightning_invoice::Invoice) -> *const [u8; 32] {
2357 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2361 /// Get the invoice features if they were included in the invoice
2363 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2366 pub extern "C" fn Invoice_features(this_arg: &crate::lightning_invoice::Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
2367 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2368 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 };
2372 /// Recover the payee's public key (only to be used if none was included in the invoice)
2375 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::PublicKey {
2376 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2377 crate::c_types::PublicKey::from_rust(&ret)
2380 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
2383 pub extern "C" fn Invoice_expiry_time(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2384 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2388 /// Returns whether the invoice has expired.
2391 pub extern "C" fn Invoice_is_expired(this_arg: &crate::lightning_invoice::Invoice) -> bool {
2392 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
2396 /// Returns whether the expiry time would pass at the given point in time.
2397 /// `at_time` is the timestamp as a duration since the Unix epoch.
2400 pub extern "C" fn Invoice_would_expire(this_arg: &crate::lightning_invoice::Invoice, mut at_time: u64) -> bool {
2401 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.would_expire(core::time::Duration::from_secs(at_time));
2405 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
2406 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
2409 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2410 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
2414 /// Returns a list of all routes included in the invoice
2417 pub extern "C" fn Invoice_private_routes(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2418 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2419 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 } }); };
2423 /// Returns a list of all routes included in the invoice as the underlying hints
2426 pub extern "C" fn Invoice_route_hints(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
2427 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints();
2428 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 } }); };
2432 /// Returns the currency for which the invoice was issued
2435 pub extern "C" fn Invoice_currency(this_arg: &crate::lightning_invoice::Invoice) -> crate::lightning_invoice::Currency {
2436 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2437 crate::lightning_invoice::Currency::native_into(ret)
2440 /// Returns the amount if specified in the invoice as millisatoshis.
2443 pub extern "C" fn Invoice_amount_milli_satoshis(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::COption_u64Z {
2444 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_milli_satoshis();
2445 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() }) };
2449 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
2450 /// returns `CreationError::DescriptionTooLong` otherwise
2452 /// Please note that single characters may use more than one byte due to UTF8 encoding.
2455 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
2456 let mut ret = lightning_invoice::Description::new(description.into_string());
2457 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() };
2461 /// Returns the underlying description `String`
2464 pub extern "C" fn Description_into_inner(mut this_arg: crate::lightning_invoice::Description) -> crate::c_types::Str {
2465 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2469 /// Construct an `ExpiryTime` from seconds.
2472 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::lightning_invoice::ExpiryTime {
2473 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
2474 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2477 /// Construct an `ExpiryTime` from a `Duration`.
2480 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::lightning_invoice::ExpiryTime {
2481 let mut ret = lightning_invoice::ExpiryTime::from_duration(core::time::Duration::from_secs(duration));
2482 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2485 /// Returns the expiry time in seconds
2488 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2489 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_seconds();
2493 /// Returns a reference to the underlying `Duration` (=expiry time)
2496 pub extern "C" fn ExpiryTime_as_duration(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2497 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration();
2501 /// Creates a new (partial) route from a list of hops
2504 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
2505 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
2506 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() };
2510 /// Returns the underlying list of hops
2513 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: crate::lightning_invoice::PrivateRoute) -> crate::lightning::routing::router::RouteHint {
2514 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2515 crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true }
2518 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
2522 pub enum CreationError {
2523 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
2525 /// The specified route has too many hops and can't be encoded
2527 /// The Unix timestamp of the supplied date is less than zero or greater than 35-bits
2528 TimestampOutOfBounds,
2529 /// The supplied millisatoshi amount was greater than the total bitcoin supply.
2531 /// Route hints were required for this invoice and were missing. Applies to
2532 /// [phantom invoices].
2534 /// [phantom invoices]: crate::utils::create_phantom_invoice
2537 use lightning_invoice::CreationError as CreationErrorImport;
2538 pub(crate) type nativeCreationError = CreationErrorImport;
2540 impl CreationError {
2542 pub(crate) fn to_native(&self) -> nativeCreationError {
2544 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2545 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2546 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2547 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2548 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2552 pub(crate) fn into_native(self) -> nativeCreationError {
2554 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2555 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2556 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2557 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2558 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2562 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
2564 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2565 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2566 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2567 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2568 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2572 pub(crate) fn native_into(native: nativeCreationError) -> Self {
2574 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2575 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2576 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2577 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2578 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2582 /// Creates a copy of the CreationError
2584 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
2588 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
2589 pub extern "C" fn CreationError_description_too_long() -> CreationError {
2590 CreationError::DescriptionTooLong}
2592 /// Utility method to constructs a new RouteTooLong-variant CreationError
2593 pub extern "C" fn CreationError_route_too_long() -> CreationError {
2594 CreationError::RouteTooLong}
2596 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
2597 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
2598 CreationError::TimestampOutOfBounds}
2600 /// Utility method to constructs a new InvalidAmount-variant CreationError
2601 pub extern "C" fn CreationError_invalid_amount() -> CreationError {
2602 CreationError::InvalidAmount}
2604 /// Utility method to constructs a new MissingRouteHints-variant CreationError
2605 pub extern "C" fn CreationError_missing_route_hints() -> CreationError {
2606 CreationError::MissingRouteHints}
2607 /// Checks if two CreationErrors contain equal inner contents.
2608 /// This ignores pointers and is_owned flags and looks at the values in fields.
2610 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
2611 if &a.to_native() == &b.to_native() { true } else { false }
2614 /// Get the string representation of a CreationError object
2615 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
2616 alloc::format!("{}", &o.to_native()).into()
2618 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
2619 /// requirements sections in BOLT #11
2623 pub enum SemanticError {
2624 /// The invoice is missing the mandatory payment hash
2626 /// The invoice has multiple payment hashes which isn't allowed
2627 MultiplePaymentHashes,
2628 /// No description or description hash are part of the invoice
2630 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
2631 MultipleDescriptions,
2632 /// The invoice is missing the mandatory payment secret, which all modern lightning nodes
2635 /// The invoice contains multiple payment secrets
2636 MultiplePaymentSecrets,
2637 /// The invoice's features are invalid
2639 /// The recovery id doesn't fit the signature/pub key
2641 /// The invoice's signature is invalid
2643 /// The invoice's amount was not a whole number of millisatoshis
2646 use lightning_invoice::SemanticError as SemanticErrorImport;
2647 pub(crate) type nativeSemanticError = SemanticErrorImport;
2649 impl SemanticError {
2651 pub(crate) fn to_native(&self) -> nativeSemanticError {
2653 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2654 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2655 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2656 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2657 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2658 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2659 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2660 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2661 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2662 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2666 pub(crate) fn into_native(self) -> nativeSemanticError {
2668 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2669 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2670 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2671 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2672 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2673 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2674 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2675 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2676 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2677 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2681 pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
2683 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2684 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2685 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2686 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2687 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2688 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2689 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2690 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2691 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2692 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2696 pub(crate) fn native_into(native: nativeSemanticError) -> Self {
2698 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2699 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2700 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2701 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2702 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2703 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2704 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2705 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2706 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2707 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2711 /// Creates a copy of the SemanticError
2713 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
2717 /// Utility method to constructs a new NoPaymentHash-variant SemanticError
2718 pub extern "C" fn SemanticError_no_payment_hash() -> SemanticError {
2719 SemanticError::NoPaymentHash}
2721 /// Utility method to constructs a new MultiplePaymentHashes-variant SemanticError
2722 pub extern "C" fn SemanticError_multiple_payment_hashes() -> SemanticError {
2723 SemanticError::MultiplePaymentHashes}
2725 /// Utility method to constructs a new NoDescription-variant SemanticError
2726 pub extern "C" fn SemanticError_no_description() -> SemanticError {
2727 SemanticError::NoDescription}
2729 /// Utility method to constructs a new MultipleDescriptions-variant SemanticError
2730 pub extern "C" fn SemanticError_multiple_descriptions() -> SemanticError {
2731 SemanticError::MultipleDescriptions}
2733 /// Utility method to constructs a new NoPaymentSecret-variant SemanticError
2734 pub extern "C" fn SemanticError_no_payment_secret() -> SemanticError {
2735 SemanticError::NoPaymentSecret}
2737 /// Utility method to constructs a new MultiplePaymentSecrets-variant SemanticError
2738 pub extern "C" fn SemanticError_multiple_payment_secrets() -> SemanticError {
2739 SemanticError::MultiplePaymentSecrets}
2741 /// Utility method to constructs a new InvalidFeatures-variant SemanticError
2742 pub extern "C" fn SemanticError_invalid_features() -> SemanticError {
2743 SemanticError::InvalidFeatures}
2745 /// Utility method to constructs a new InvalidRecoveryId-variant SemanticError
2746 pub extern "C" fn SemanticError_invalid_recovery_id() -> SemanticError {
2747 SemanticError::InvalidRecoveryId}
2749 /// Utility method to constructs a new InvalidSignature-variant SemanticError
2750 pub extern "C" fn SemanticError_invalid_signature() -> SemanticError {
2751 SemanticError::InvalidSignature}
2753 /// Utility method to constructs a new ImpreciseAmount-variant SemanticError
2754 pub extern "C" fn SemanticError_imprecise_amount() -> SemanticError {
2755 SemanticError::ImpreciseAmount}
2756 /// Checks if two SemanticErrors contain equal inner contents.
2757 /// This ignores pointers and is_owned flags and looks at the values in fields.
2759 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
2760 if &a.to_native() == &b.to_native() { true } else { false }
2763 /// Get the string representation of a SemanticError object
2764 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
2765 alloc::format!("{}", &o.to_native()).into()
2767 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
2772 pub enum SignOrCreationError {
2773 /// An error occurred during signing
2775 /// An error occurred while building the transaction
2777 crate::lightning_invoice::CreationError),
2779 use lightning_invoice::SignOrCreationError as SignOrCreationErrorImport;
2780 pub(crate) type nativeSignOrCreationError = SignOrCreationErrorImport<>;
2782 impl SignOrCreationError {
2784 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
2786 SignOrCreationError::SignError => {
2787 nativeSignOrCreationError::SignError (
2791 SignOrCreationError::CreationError (ref a, ) => {
2792 let mut a_nonref = (*a).clone();
2793 nativeSignOrCreationError::CreationError (
2794 a_nonref.into_native(),
2800 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
2802 SignOrCreationError::SignError => {
2803 nativeSignOrCreationError::SignError (
2807 SignOrCreationError::CreationError (mut a, ) => {
2808 nativeSignOrCreationError::CreationError (
2815 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
2817 nativeSignOrCreationError::SignError (ref a, ) => {
2818 SignOrCreationError::SignError },
2819 nativeSignOrCreationError::CreationError (ref a, ) => {
2820 let mut a_nonref = (*a).clone();
2821 SignOrCreationError::CreationError (
2822 crate::lightning_invoice::CreationError::native_into(a_nonref),
2828 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
2830 nativeSignOrCreationError::SignError (mut a, ) => {
2831 SignOrCreationError::SignError },
2832 nativeSignOrCreationError::CreationError (mut a, ) => {
2833 SignOrCreationError::CreationError (
2834 crate::lightning_invoice::CreationError::native_into(a),
2840 /// Frees any resources used by the SignOrCreationError
2842 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
2843 /// Creates a copy of the SignOrCreationError
2845 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
2849 /// Utility method to constructs a new SignError-variant SignOrCreationError
2850 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
2851 SignOrCreationError::SignError
2854 /// Utility method to constructs a new CreationError-variant SignOrCreationError
2855 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
2856 SignOrCreationError::CreationError(a, )
2858 /// Checks if two SignOrCreationErrors contain equal inner contents.
2859 /// This ignores pointers and is_owned flags and looks at the values in fields.
2861 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
2862 if &a.to_native() == &b.to_native() { true } else { false }
2865 /// Get the string representation of a SignOrCreationError object
2866 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
2867 alloc::format!("{}", &o.to_native()).into()