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 {
190 Bech32Error(crate::c_types::Bech32Error),
191 ParseAmountError(crate::c_types::Error),
192 MalformedSignature(crate::c_types::Secp256k1Error),
198 UnexpectedEndOfTaggedFields,
199 DescriptionDecodeError(crate::c_types::Error),
201 IntegerOverflowError,
202 InvalidSegWitProgramLength,
203 InvalidPubKeyHashLength,
204 InvalidScriptHashLength,
206 InvalidSliceLength(crate::c_types::Str),
207 /// Not an error, but used internally to signal that a part of the invoice should be ignored
208 /// according to BOLT11
211 use lightning_invoice::ParseError as ParseErrorImport;
212 pub(crate) type nativeParseError = ParseErrorImport;
216 pub(crate) fn to_native(&self) -> nativeParseError {
218 ParseError::Bech32Error (ref a, ) => {
219 let mut a_nonref = (*a).clone();
220 nativeParseError::Bech32Error (
221 a_nonref.into_rust(),
224 ParseError::ParseAmountError (ref a, ) => {
225 let mut a_nonref = (*a).clone();
226 nativeParseError::ParseAmountError (
227 u8::from_str_radix(" a", 10).unwrap_err() /*a_nonref*/,
230 ParseError::MalformedSignature (ref a, ) => {
231 let mut a_nonref = (*a).clone();
232 nativeParseError::MalformedSignature (
233 a_nonref.into_rust(),
236 ParseError::BadPrefix => nativeParseError::BadPrefix,
237 ParseError::UnknownCurrency => nativeParseError::UnknownCurrency,
238 ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix,
239 ParseError::MalformedHRP => nativeParseError::MalformedHRP,
240 ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
241 ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
242 ParseError::DescriptionDecodeError (ref a, ) => {
243 let mut a_nonref = (*a).clone();
244 nativeParseError::DescriptionDecodeError (
245 core::str::from_utf8(&[0xff]).unwrap_err() /*a_nonref*/,
248 ParseError::PaddingError => nativeParseError::PaddingError,
249 ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError,
250 ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength,
251 ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength,
252 ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
253 ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
254 ParseError::InvalidSliceLength (ref a, ) => {
255 let mut a_nonref = (*a).clone();
256 nativeParseError::InvalidSliceLength (
257 a_nonref.into_string(),
260 ParseError::Skip => nativeParseError::Skip,
264 pub(crate) fn into_native(self) -> nativeParseError {
266 ParseError::Bech32Error (mut a, ) => {
267 nativeParseError::Bech32Error (
271 ParseError::ParseAmountError (mut a, ) => {
272 nativeParseError::ParseAmountError (
273 u8::from_str_radix(" a", 10).unwrap_err() /*a*/,
276 ParseError::MalformedSignature (mut a, ) => {
277 nativeParseError::MalformedSignature (
281 ParseError::BadPrefix => nativeParseError::BadPrefix,
282 ParseError::UnknownCurrency => nativeParseError::UnknownCurrency,
283 ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix,
284 ParseError::MalformedHRP => nativeParseError::MalformedHRP,
285 ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
286 ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
287 ParseError::DescriptionDecodeError (mut a, ) => {
288 nativeParseError::DescriptionDecodeError (
289 core::str::from_utf8(&[0xff]).unwrap_err() /*a*/,
292 ParseError::PaddingError => nativeParseError::PaddingError,
293 ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError,
294 ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength,
295 ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength,
296 ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
297 ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
298 ParseError::InvalidSliceLength (mut a, ) => {
299 nativeParseError::InvalidSliceLength (
303 ParseError::Skip => nativeParseError::Skip,
307 pub(crate) fn from_native(native: &nativeParseError) -> Self {
309 nativeParseError::Bech32Error (ref a, ) => {
310 let mut a_nonref = (*a).clone();
311 ParseError::Bech32Error (
312 crate::c_types::Bech32Error::from_rust(a_nonref),
315 nativeParseError::ParseAmountError (ref a, ) => {
316 let mut a_nonref = (*a).clone();
317 ParseError::ParseAmountError (
318 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
321 nativeParseError::MalformedSignature (ref a, ) => {
322 let mut a_nonref = (*a).clone();
323 ParseError::MalformedSignature (
324 crate::c_types::Secp256k1Error::from_rust(a_nonref),
327 nativeParseError::BadPrefix => ParseError::BadPrefix,
328 nativeParseError::UnknownCurrency => ParseError::UnknownCurrency,
329 nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix,
330 nativeParseError::MalformedHRP => ParseError::MalformedHRP,
331 nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
332 nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
333 nativeParseError::DescriptionDecodeError (ref a, ) => {
334 let mut a_nonref = (*a).clone();
335 ParseError::DescriptionDecodeError (
336 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
339 nativeParseError::PaddingError => ParseError::PaddingError,
340 nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError,
341 nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength,
342 nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength,
343 nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
344 nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
345 nativeParseError::InvalidSliceLength (ref a, ) => {
346 let mut a_nonref = (*a).clone();
347 ParseError::InvalidSliceLength (
351 nativeParseError::Skip => ParseError::Skip,
355 pub(crate) fn native_into(native: nativeParseError) -> Self {
357 nativeParseError::Bech32Error (mut a, ) => {
358 ParseError::Bech32Error (
359 crate::c_types::Bech32Error::from_rust(a),
362 nativeParseError::ParseAmountError (mut a, ) => {
363 ParseError::ParseAmountError (
364 crate::c_types::Error { _dummy: 0 } /*a*/,
367 nativeParseError::MalformedSignature (mut a, ) => {
368 ParseError::MalformedSignature (
369 crate::c_types::Secp256k1Error::from_rust(a),
372 nativeParseError::BadPrefix => ParseError::BadPrefix,
373 nativeParseError::UnknownCurrency => ParseError::UnknownCurrency,
374 nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix,
375 nativeParseError::MalformedHRP => ParseError::MalformedHRP,
376 nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
377 nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
378 nativeParseError::DescriptionDecodeError (mut a, ) => {
379 ParseError::DescriptionDecodeError (
380 crate::c_types::Error { _dummy: 0 } /*a*/,
383 nativeParseError::PaddingError => ParseError::PaddingError,
384 nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError,
385 nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength,
386 nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength,
387 nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
388 nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
389 nativeParseError::InvalidSliceLength (mut a, ) => {
390 ParseError::InvalidSliceLength (
394 nativeParseError::Skip => ParseError::Skip,
398 /// Frees any resources used by the ParseError
400 pub extern "C" fn ParseError_free(this_ptr: ParseError) { }
401 /// Creates a copy of the ParseError
403 pub extern "C" fn ParseError_clone(orig: &ParseError) -> ParseError {
407 /// Utility method to constructs a new Bech32Error-variant ParseError
408 pub extern "C" fn ParseError_bech32_error(a: crate::c_types::Bech32Error) -> ParseError {
409 ParseError::Bech32Error(a, )
412 /// Utility method to constructs a new ParseAmountError-variant ParseError
413 pub extern "C" fn ParseError_parse_amount_error(a: crate::c_types::Error) -> ParseError {
414 ParseError::ParseAmountError(a, )
417 /// Utility method to constructs a new MalformedSignature-variant ParseError
418 pub extern "C" fn ParseError_malformed_signature(a: crate::c_types::Secp256k1Error) -> ParseError {
419 ParseError::MalformedSignature(a, )
422 /// Utility method to constructs a new BadPrefix-variant ParseError
423 pub extern "C" fn ParseError_bad_prefix() -> ParseError {
424 ParseError::BadPrefix}
426 /// Utility method to constructs a new UnknownCurrency-variant ParseError
427 pub extern "C" fn ParseError_unknown_currency() -> ParseError {
428 ParseError::UnknownCurrency}
430 /// Utility method to constructs a new UnknownSiPrefix-variant ParseError
431 pub extern "C" fn ParseError_unknown_si_prefix() -> ParseError {
432 ParseError::UnknownSiPrefix}
434 /// Utility method to constructs a new MalformedHRP-variant ParseError
435 pub extern "C" fn ParseError_malformed_hrp() -> ParseError {
436 ParseError::MalformedHRP}
438 /// Utility method to constructs a new TooShortDataPart-variant ParseError
439 pub extern "C" fn ParseError_too_short_data_part() -> ParseError {
440 ParseError::TooShortDataPart}
442 /// Utility method to constructs a new UnexpectedEndOfTaggedFields-variant ParseError
443 pub extern "C" fn ParseError_unexpected_end_of_tagged_fields() -> ParseError {
444 ParseError::UnexpectedEndOfTaggedFields}
446 /// Utility method to constructs a new DescriptionDecodeError-variant ParseError
447 pub extern "C" fn ParseError_description_decode_error(a: crate::c_types::Error) -> ParseError {
448 ParseError::DescriptionDecodeError(a, )
451 /// Utility method to constructs a new PaddingError-variant ParseError
452 pub extern "C" fn ParseError_padding_error() -> ParseError {
453 ParseError::PaddingError}
455 /// Utility method to constructs a new IntegerOverflowError-variant ParseError
456 pub extern "C" fn ParseError_integer_overflow_error() -> ParseError {
457 ParseError::IntegerOverflowError}
459 /// Utility method to constructs a new InvalidSegWitProgramLength-variant ParseError
460 pub extern "C" fn ParseError_invalid_seg_wit_program_length() -> ParseError {
461 ParseError::InvalidSegWitProgramLength}
463 /// Utility method to constructs a new InvalidPubKeyHashLength-variant ParseError
464 pub extern "C" fn ParseError_invalid_pub_key_hash_length() -> ParseError {
465 ParseError::InvalidPubKeyHashLength}
467 /// Utility method to constructs a new InvalidScriptHashLength-variant ParseError
468 pub extern "C" fn ParseError_invalid_script_hash_length() -> ParseError {
469 ParseError::InvalidScriptHashLength}
471 /// Utility method to constructs a new InvalidRecoveryId-variant ParseError
472 pub extern "C" fn ParseError_invalid_recovery_id() -> ParseError {
473 ParseError::InvalidRecoveryId}
475 /// Utility method to constructs a new InvalidSliceLength-variant ParseError
476 pub extern "C" fn ParseError_invalid_slice_length(a: crate::c_types::Str) -> ParseError {
477 ParseError::InvalidSliceLength(a, )
480 /// Utility method to constructs a new Skip-variant ParseError
481 pub extern "C" fn ParseError_skip() -> ParseError {
483 /// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
484 /// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
485 /// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
489 pub enum ParseOrSemanticError {
490 /// The invoice couldn't be decoded
491 ParseError(crate::lightning_invoice::ParseError),
492 /// The invoice could be decoded but violates the BOLT11 standard
493 SemanticError(crate::lightning_invoice::SemanticError),
495 use lightning_invoice::ParseOrSemanticError as ParseOrSemanticErrorImport;
496 pub(crate) type nativeParseOrSemanticError = ParseOrSemanticErrorImport;
498 impl ParseOrSemanticError {
500 pub(crate) fn to_native(&self) -> nativeParseOrSemanticError {
502 ParseOrSemanticError::ParseError (ref a, ) => {
503 let mut a_nonref = (*a).clone();
504 nativeParseOrSemanticError::ParseError (
505 a_nonref.into_native(),
508 ParseOrSemanticError::SemanticError (ref a, ) => {
509 let mut a_nonref = (*a).clone();
510 nativeParseOrSemanticError::SemanticError (
511 a_nonref.into_native(),
517 pub(crate) fn into_native(self) -> nativeParseOrSemanticError {
519 ParseOrSemanticError::ParseError (mut a, ) => {
520 nativeParseOrSemanticError::ParseError (
524 ParseOrSemanticError::SemanticError (mut a, ) => {
525 nativeParseOrSemanticError::SemanticError (
532 pub(crate) fn from_native(native: &nativeParseOrSemanticError) -> Self {
534 nativeParseOrSemanticError::ParseError (ref a, ) => {
535 let mut a_nonref = (*a).clone();
536 ParseOrSemanticError::ParseError (
537 crate::lightning_invoice::ParseError::native_into(a_nonref),
540 nativeParseOrSemanticError::SemanticError (ref a, ) => {
541 let mut a_nonref = (*a).clone();
542 ParseOrSemanticError::SemanticError (
543 crate::lightning_invoice::SemanticError::native_into(a_nonref),
549 pub(crate) fn native_into(native: nativeParseOrSemanticError) -> Self {
551 nativeParseOrSemanticError::ParseError (mut a, ) => {
552 ParseOrSemanticError::ParseError (
553 crate::lightning_invoice::ParseError::native_into(a),
556 nativeParseOrSemanticError::SemanticError (mut a, ) => {
557 ParseOrSemanticError::SemanticError (
558 crate::lightning_invoice::SemanticError::native_into(a),
564 /// Frees any resources used by the ParseOrSemanticError
566 pub extern "C" fn ParseOrSemanticError_free(this_ptr: ParseOrSemanticError) { }
567 /// Creates a copy of the ParseOrSemanticError
569 pub extern "C" fn ParseOrSemanticError_clone(orig: &ParseOrSemanticError) -> ParseOrSemanticError {
573 /// Utility method to constructs a new ParseError-variant ParseOrSemanticError
574 pub extern "C" fn ParseOrSemanticError_parse_error(a: crate::lightning_invoice::ParseError) -> ParseOrSemanticError {
575 ParseOrSemanticError::ParseError(a, )
578 /// Utility method to constructs a new SemanticError-variant ParseOrSemanticError
579 pub extern "C" fn ParseOrSemanticError_semantic_error(a: crate::lightning_invoice::SemanticError) -> ParseOrSemanticError {
580 ParseOrSemanticError::SemanticError(a, )
582 /// The maximum timestamp as [`Duration::as_secs`] since the Unix epoch allowed by [`BOLT 11`].
584 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
587 pub static MAX_TIMESTAMP: u64 = lightning_invoice::MAX_TIMESTAMP;
588 /// Default expiry time as defined by [BOLT 11].
590 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
593 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
594 /// Default minimum final CLTV expiry as defined by [BOLT 11].
596 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
597 /// provided in [`MIN_FINAL_CLTV_EXPIRY`].
599 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
600 /// [`MIN_FINAL_CLTV_EXPIRY`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY
603 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY;
605 use lightning_invoice::Invoice as nativeInvoiceImport;
606 pub(crate) type nativeInvoice = nativeInvoiceImport;
608 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
610 /// There are three ways to construct an `Invoice`:
611 /// 1. using `InvoiceBuilder`
612 /// 2. using `Invoice::from_signed(SignedRawInvoice)`
613 /// 3. using `str::parse::<Invoice>(&str)`
617 /// A pointer to the opaque Rust object.
619 /// Nearly everywhere, inner must be non-null, however in places where
620 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
621 pub inner: *mut nativeInvoice,
622 /// Indicates that this is the only struct which contains the same pointer.
624 /// Rust functions which take ownership of an object provided via an argument require
625 /// this to be true and invalidate the object pointed to by inner.
629 impl Drop for Invoice {
631 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
632 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
636 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
638 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
640 /// Used only if an object of this type is returned as a trait impl by a method
641 pub(crate) extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
642 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
646 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoice {
647 unsafe { &*ObjOps::untweak_ptr(self.inner) }
649 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoice {
650 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
652 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
653 pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
654 assert!(self.is_owned);
655 let ret = ObjOps::untweak_ptr(self.inner);
656 self.inner = core::ptr::null_mut();
660 /// Checks if two Invoices contain equal inner contents.
661 /// This ignores pointers and is_owned flags and looks at the values in fields.
662 /// Two objects with NULL inner values will be considered "equal" here.
664 pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool {
665 if a.inner == b.inner { return true; }
666 if a.inner.is_null() || b.inner.is_null() { return false; }
667 if a.get_native_ref() == b.get_native_ref() { true } else { false }
669 impl Clone for Invoice {
670 fn clone(&self) -> Self {
672 inner: if <*mut nativeInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
673 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
679 /// Used only if an object of this type is returned as a trait impl by a method
680 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
681 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
684 /// Creates a copy of the Invoice
685 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
689 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
690 pub(crate) type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
692 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
696 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
699 pub struct SignedRawInvoice {
700 /// A pointer to the opaque Rust object.
702 /// Nearly everywhere, inner must be non-null, however in places where
703 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
704 pub inner: *mut nativeSignedRawInvoice,
705 /// Indicates that this is the only struct which contains the same pointer.
707 /// Rust functions which take ownership of an object provided via an argument require
708 /// this to be true and invalidate the object pointed to by inner.
712 impl Drop for SignedRawInvoice {
714 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
715 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
719 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
721 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
723 /// Used only if an object of this type is returned as a trait impl by a method
724 pub(crate) extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
725 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
728 impl SignedRawInvoice {
729 pub(crate) fn get_native_ref(&self) -> &'static nativeSignedRawInvoice {
730 unsafe { &*ObjOps::untweak_ptr(self.inner) }
732 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSignedRawInvoice {
733 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
735 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
736 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
737 assert!(self.is_owned);
738 let ret = ObjOps::untweak_ptr(self.inner);
739 self.inner = core::ptr::null_mut();
743 /// Checks if two SignedRawInvoices contain equal inner contents.
744 /// This ignores pointers and is_owned flags and looks at the values in fields.
745 /// Two objects with NULL inner values will be considered "equal" here.
747 pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice) -> bool {
748 if a.inner == b.inner { return true; }
749 if a.inner.is_null() || b.inner.is_null() { return false; }
750 if a.get_native_ref() == b.get_native_ref() { true } else { false }
752 impl Clone for SignedRawInvoice {
753 fn clone(&self) -> Self {
755 inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
756 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
762 /// Used only if an object of this type is returned as a trait impl by a method
763 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
764 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
767 /// Creates a copy of the SignedRawInvoice
768 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
772 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
773 pub(crate) type nativeRawInvoice = nativeRawInvoiceImport;
775 /// Represents an syntactically correct Invoice for a payment on the lightning network,
776 /// but without the signature information.
777 /// De- and encoding should not lead to information loss but may lead to different hashes.
779 /// For methods without docs see the corresponding methods in `Invoice`.
782 pub struct RawInvoice {
783 /// A pointer to the opaque Rust object.
785 /// Nearly everywhere, inner must be non-null, however in places where
786 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
787 pub inner: *mut nativeRawInvoice,
788 /// Indicates that this is the only struct which contains the same pointer.
790 /// Rust functions which take ownership of an object provided via an argument require
791 /// this to be true and invalidate the object pointed to by inner.
795 impl Drop for RawInvoice {
797 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
798 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
802 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
804 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
806 /// Used only if an object of this type is returned as a trait impl by a method
807 pub(crate) extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
808 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
812 pub(crate) fn get_native_ref(&self) -> &'static nativeRawInvoice {
813 unsafe { &*ObjOps::untweak_ptr(self.inner) }
815 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawInvoice {
816 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
818 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
819 pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
820 assert!(self.is_owned);
821 let ret = ObjOps::untweak_ptr(self.inner);
822 self.inner = core::ptr::null_mut();
828 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
829 let mut inner_val = &mut this_ptr.get_native_mut_ref().data;
830 crate::lightning_invoice::RawDataPart { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::RawDataPart<>) as *mut _) }, is_owned: false }
834 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
835 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.data = *unsafe { Box::from_raw(val.take_inner()) };
837 /// Checks if two RawInvoices contain equal inner contents.
838 /// This ignores pointers and is_owned flags and looks at the values in fields.
839 /// Two objects with NULL inner values will be considered "equal" here.
841 pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool {
842 if a.inner == b.inner { return true; }
843 if a.inner.is_null() || b.inner.is_null() { return false; }
844 if a.get_native_ref() == b.get_native_ref() { true } else { false }
846 impl Clone for RawInvoice {
847 fn clone(&self) -> Self {
849 inner: if <*mut nativeRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
850 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
856 /// Used only if an object of this type is returned as a trait impl by a method
857 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
858 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
861 /// Creates a copy of the RawInvoice
862 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
866 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
867 pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
869 /// Data of the `RawInvoice` that is encoded in the data part
872 pub struct RawDataPart {
873 /// A pointer to the opaque Rust object.
875 /// Nearly everywhere, inner must be non-null, however in places where
876 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
877 pub inner: *mut nativeRawDataPart,
878 /// Indicates that this is the only struct which contains the same pointer.
880 /// Rust functions which take ownership of an object provided via an argument require
881 /// this to be true and invalidate the object pointed to by inner.
885 impl Drop for RawDataPart {
887 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
888 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
892 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
894 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
896 /// Used only if an object of this type is returned as a trait impl by a method
897 pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
898 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
902 pub(crate) fn get_native_ref(&self) -> &'static nativeRawDataPart {
903 unsafe { &*ObjOps::untweak_ptr(self.inner) }
905 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawDataPart {
906 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
908 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
909 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
910 assert!(self.is_owned);
911 let ret = ObjOps::untweak_ptr(self.inner);
912 self.inner = core::ptr::null_mut();
916 /// generation time of the invoice
918 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
919 let mut inner_val = &mut this_ptr.get_native_mut_ref().timestamp;
920 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::PositiveTimestamp<>) as *mut _) }, is_owned: false }
922 /// generation time of the invoice
924 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
925 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
927 /// Checks if two RawDataParts contain equal inner contents.
928 /// This ignores pointers and is_owned flags and looks at the values in fields.
929 /// Two objects with NULL inner values will be considered "equal" here.
931 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
932 if a.inner == b.inner { return true; }
933 if a.inner.is_null() || b.inner.is_null() { return false; }
934 if a.get_native_ref() == b.get_native_ref() { true } else { false }
936 impl Clone for RawDataPart {
937 fn clone(&self) -> Self {
939 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { core::ptr::null_mut() } else {
940 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
946 /// Used only if an object of this type is returned as a trait impl by a method
947 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
948 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
951 /// Creates a copy of the RawDataPart
952 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
956 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
957 pub(crate) type nativePositiveTimestamp = nativePositiveTimestampImport;
959 /// A timestamp that refers to a date after 1 January 1970.
963 /// The Unix timestamp representing the stored time has to be positive and no greater than
964 /// [`MAX_TIMESTAMP`].
967 pub struct PositiveTimestamp {
968 /// A pointer to the opaque Rust object.
970 /// Nearly everywhere, inner must be non-null, however in places where
971 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
972 pub inner: *mut nativePositiveTimestamp,
973 /// Indicates that this is the only struct which contains the same pointer.
975 /// Rust functions which take ownership of an object provided via an argument require
976 /// this to be true and invalidate the object pointed to by inner.
980 impl Drop for PositiveTimestamp {
982 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
983 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
987 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
989 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
991 /// Used only if an object of this type is returned as a trait impl by a method
992 pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
993 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
996 impl PositiveTimestamp {
997 pub(crate) fn get_native_ref(&self) -> &'static nativePositiveTimestamp {
998 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1000 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePositiveTimestamp {
1001 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1003 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1004 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
1005 assert!(self.is_owned);
1006 let ret = ObjOps::untweak_ptr(self.inner);
1007 self.inner = core::ptr::null_mut();
1011 /// Checks if two PositiveTimestamps contain equal inner contents.
1012 /// This ignores pointers and is_owned flags and looks at the values in fields.
1013 /// Two objects with NULL inner values will be considered "equal" here.
1015 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
1016 if a.inner == b.inner { return true; }
1017 if a.inner.is_null() || b.inner.is_null() { return false; }
1018 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1020 impl Clone for PositiveTimestamp {
1021 fn clone(&self) -> Self {
1023 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { core::ptr::null_mut() } else {
1024 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1030 /// Used only if an object of this type is returned as a trait impl by a method
1031 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
1032 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
1035 /// Creates a copy of the PositiveTimestamp
1036 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
1039 /// SI prefixes for the human readable part
1053 use lightning_invoice::SiPrefix as SiPrefixImport;
1054 pub(crate) type nativeSiPrefix = SiPrefixImport;
1058 pub(crate) fn to_native(&self) -> nativeSiPrefix {
1060 SiPrefix::Milli => nativeSiPrefix::Milli,
1061 SiPrefix::Micro => nativeSiPrefix::Micro,
1062 SiPrefix::Nano => nativeSiPrefix::Nano,
1063 SiPrefix::Pico => nativeSiPrefix::Pico,
1067 pub(crate) fn into_native(self) -> nativeSiPrefix {
1069 SiPrefix::Milli => nativeSiPrefix::Milli,
1070 SiPrefix::Micro => nativeSiPrefix::Micro,
1071 SiPrefix::Nano => nativeSiPrefix::Nano,
1072 SiPrefix::Pico => nativeSiPrefix::Pico,
1076 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
1078 nativeSiPrefix::Milli => SiPrefix::Milli,
1079 nativeSiPrefix::Micro => SiPrefix::Micro,
1080 nativeSiPrefix::Nano => SiPrefix::Nano,
1081 nativeSiPrefix::Pico => SiPrefix::Pico,
1085 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
1087 nativeSiPrefix::Milli => SiPrefix::Milli,
1088 nativeSiPrefix::Micro => SiPrefix::Micro,
1089 nativeSiPrefix::Nano => SiPrefix::Nano,
1090 nativeSiPrefix::Pico => SiPrefix::Pico,
1094 /// Creates a copy of the SiPrefix
1096 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
1100 /// Utility method to constructs a new Milli-variant SiPrefix
1101 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
1104 /// Utility method to constructs a new Micro-variant SiPrefix
1105 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
1108 /// Utility method to constructs a new Nano-variant SiPrefix
1109 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
1112 /// Utility method to constructs a new Pico-variant SiPrefix
1113 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
1115 /// Checks if two SiPrefixs contain equal inner contents.
1116 /// This ignores pointers and is_owned flags and looks at the values in fields.
1118 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
1119 if &a.to_native() == &b.to_native() { true } else { false }
1121 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
1122 /// This is effectively 10^12 * the prefix multiplier
1125 pub extern "C" fn SiPrefix_multiplier(this_arg: &crate::lightning_invoice::SiPrefix) -> u64 {
1126 let mut ret = this_arg.to_native().multiplier();
1130 /// Enum representing the crypto currencies (or networks) supported by this library
1146 use lightning_invoice::Currency as CurrencyImport;
1147 pub(crate) type nativeCurrency = CurrencyImport;
1151 pub(crate) fn to_native(&self) -> nativeCurrency {
1153 Currency::Bitcoin => nativeCurrency::Bitcoin,
1154 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1155 Currency::Regtest => nativeCurrency::Regtest,
1156 Currency::Simnet => nativeCurrency::Simnet,
1157 Currency::Signet => nativeCurrency::Signet,
1161 pub(crate) fn into_native(self) -> nativeCurrency {
1163 Currency::Bitcoin => nativeCurrency::Bitcoin,
1164 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1165 Currency::Regtest => nativeCurrency::Regtest,
1166 Currency::Simnet => nativeCurrency::Simnet,
1167 Currency::Signet => nativeCurrency::Signet,
1171 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
1173 nativeCurrency::Bitcoin => Currency::Bitcoin,
1174 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1175 nativeCurrency::Regtest => Currency::Regtest,
1176 nativeCurrency::Simnet => Currency::Simnet,
1177 nativeCurrency::Signet => Currency::Signet,
1181 pub(crate) fn native_into(native: nativeCurrency) -> Self {
1183 nativeCurrency::Bitcoin => Currency::Bitcoin,
1184 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1185 nativeCurrency::Regtest => Currency::Regtest,
1186 nativeCurrency::Simnet => Currency::Simnet,
1187 nativeCurrency::Signet => Currency::Signet,
1191 /// Creates a copy of the Currency
1193 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
1197 /// Utility method to constructs a new Bitcoin-variant Currency
1198 pub extern "C" fn Currency_bitcoin() -> Currency {
1201 /// Utility method to constructs a new BitcoinTestnet-variant Currency
1202 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
1203 Currency::BitcoinTestnet}
1205 /// Utility method to constructs a new Regtest-variant Currency
1206 pub extern "C" fn Currency_regtest() -> Currency {
1209 /// Utility method to constructs a new Simnet-variant Currency
1210 pub extern "C" fn Currency_simnet() -> Currency {
1213 /// Utility method to constructs a new Signet-variant Currency
1214 pub extern "C" fn Currency_signet() -> Currency {
1216 /// Checks if two Currencys contain equal inner contents.
1218 pub extern "C" fn Currency_hash(o: &Currency) -> u64 {
1219 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1220 #[allow(deprecated)]
1221 let mut hasher = core::hash::SipHasher::new();
1222 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1223 core::hash::Hasher::finish(&hasher)
1225 /// Checks if two Currencys contain equal inner contents.
1226 /// This ignores pointers and is_owned flags and looks at the values in fields.
1228 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
1229 if &a.to_native() == &b.to_native() { true } else { false }
1232 use lightning_invoice::Sha256 as nativeSha256Import;
1233 pub(crate) type nativeSha256 = nativeSha256Import;
1239 /// A pointer to the opaque Rust object.
1241 /// Nearly everywhere, inner must be non-null, however in places where
1242 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1243 pub inner: *mut nativeSha256,
1244 /// Indicates that this is the only struct which contains the same pointer.
1246 /// Rust functions which take ownership of an object provided via an argument require
1247 /// this to be true and invalidate the object pointed to by inner.
1251 impl Drop for Sha256 {
1252 fn drop(&mut self) {
1253 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
1254 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1258 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
1260 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
1262 /// Used only if an object of this type is returned as a trait impl by a method
1263 pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
1264 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
1268 pub(crate) fn get_native_ref(&self) -> &'static nativeSha256 {
1269 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1271 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSha256 {
1272 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1274 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1275 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
1276 assert!(self.is_owned);
1277 let ret = ObjOps::untweak_ptr(self.inner);
1278 self.inner = core::ptr::null_mut();
1282 impl Clone for Sha256 {
1283 fn clone(&self) -> Self {
1285 inner: if <*mut nativeSha256>::is_null(self.inner) { core::ptr::null_mut() } else {
1286 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1292 /// Used only if an object of this type is returned as a trait impl by a method
1293 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
1294 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
1297 /// Creates a copy of the Sha256
1298 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
1301 /// Checks if two Sha256s contain equal inner contents.
1303 pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 {
1304 if o.inner.is_null() { return 0; }
1305 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1306 #[allow(deprecated)]
1307 let mut hasher = core::hash::SipHasher::new();
1308 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1309 core::hash::Hasher::finish(&hasher)
1311 /// Checks if two Sha256s contain equal inner contents.
1312 /// This ignores pointers and is_owned flags and looks at the values in fields.
1313 /// Two objects with NULL inner values will be considered "equal" here.
1315 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
1316 if a.inner == b.inner { return true; }
1317 if a.inner.is_null() || b.inner.is_null() { return false; }
1318 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1321 use lightning_invoice::Description as nativeDescriptionImport;
1322 pub(crate) type nativeDescription = nativeDescriptionImport;
1324 /// Description string
1327 /// The description can be at most 639 __bytes__ long
1330 pub struct Description {
1331 /// A pointer to the opaque Rust object.
1333 /// Nearly everywhere, inner must be non-null, however in places where
1334 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1335 pub inner: *mut nativeDescription,
1336 /// Indicates that this is the only struct which contains the same pointer.
1338 /// Rust functions which take ownership of an object provided via an argument require
1339 /// this to be true and invalidate the object pointed to by inner.
1343 impl Drop for Description {
1344 fn drop(&mut self) {
1345 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
1346 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1350 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
1352 pub extern "C" fn Description_free(this_obj: Description) { }
1354 /// Used only if an object of this type is returned as a trait impl by a method
1355 pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) {
1356 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
1360 pub(crate) fn get_native_ref(&self) -> &'static nativeDescription {
1361 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1363 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDescription {
1364 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1366 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1367 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
1368 assert!(self.is_owned);
1369 let ret = ObjOps::untweak_ptr(self.inner);
1370 self.inner = core::ptr::null_mut();
1374 impl Clone for Description {
1375 fn clone(&self) -> Self {
1377 inner: if <*mut nativeDescription>::is_null(self.inner) { core::ptr::null_mut() } else {
1378 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1384 /// Used only if an object of this type is returned as a trait impl by a method
1385 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
1386 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
1389 /// Creates a copy of the Description
1390 pub extern "C" fn Description_clone(orig: &Description) -> Description {
1393 /// Checks if two Descriptions contain equal inner contents.
1395 pub extern "C" fn Description_hash(o: &Description) -> u64 {
1396 if o.inner.is_null() { return 0; }
1397 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1398 #[allow(deprecated)]
1399 let mut hasher = core::hash::SipHasher::new();
1400 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1401 core::hash::Hasher::finish(&hasher)
1403 /// Checks if two Descriptions contain equal inner contents.
1404 /// This ignores pointers and is_owned flags and looks at the values in fields.
1405 /// Two objects with NULL inner values will be considered "equal" here.
1407 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
1408 if a.inner == b.inner { return true; }
1409 if a.inner.is_null() || b.inner.is_null() { return false; }
1410 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1413 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
1414 pub(crate) type nativePayeePubKey = nativePayeePubKeyImport;
1416 /// Payee public key
1419 pub struct PayeePubKey {
1420 /// A pointer to the opaque Rust object.
1422 /// Nearly everywhere, inner must be non-null, however in places where
1423 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1424 pub inner: *mut nativePayeePubKey,
1425 /// Indicates that this is the only struct which contains the same pointer.
1427 /// Rust functions which take ownership of an object provided via an argument require
1428 /// this to be true and invalidate the object pointed to by inner.
1432 impl Drop for PayeePubKey {
1433 fn drop(&mut self) {
1434 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
1435 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1439 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
1441 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
1443 /// Used only if an object of this type is returned as a trait impl by a method
1444 pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
1445 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
1449 pub(crate) fn get_native_ref(&self) -> &'static nativePayeePubKey {
1450 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1452 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayeePubKey {
1453 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1455 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1456 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
1457 assert!(self.is_owned);
1458 let ret = ObjOps::untweak_ptr(self.inner);
1459 self.inner = core::ptr::null_mut();
1464 pub extern "C" fn PayeePubKey_get_a(this_ptr: &PayeePubKey) -> crate::c_types::PublicKey {
1465 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1466 crate::c_types::PublicKey::from_rust(&inner_val)
1469 pub extern "C" fn PayeePubKey_set_a(this_ptr: &mut PayeePubKey, mut val: crate::c_types::PublicKey) {
1470 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
1472 /// Constructs a new PayeePubKey given each field
1475 pub extern "C" fn PayeePubKey_new(mut a_arg: crate::c_types::PublicKey) -> PayeePubKey {
1476 PayeePubKey { inner: ObjOps::heap_alloc(lightning_invoice::PayeePubKey (
1478 )), is_owned: true }
1480 impl Clone for PayeePubKey {
1481 fn clone(&self) -> Self {
1483 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { core::ptr::null_mut() } else {
1484 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1490 /// Used only if an object of this type is returned as a trait impl by a method
1491 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
1492 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
1495 /// Creates a copy of the PayeePubKey
1496 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
1499 /// Checks if two PayeePubKeys contain equal inner contents.
1501 pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 {
1502 if o.inner.is_null() { return 0; }
1503 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1504 #[allow(deprecated)]
1505 let mut hasher = core::hash::SipHasher::new();
1506 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1507 core::hash::Hasher::finish(&hasher)
1509 /// Checks if two PayeePubKeys contain equal inner contents.
1510 /// This ignores pointers and is_owned flags and looks at the values in fields.
1511 /// Two objects with NULL inner values will be considered "equal" here.
1513 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
1514 if a.inner == b.inner { return true; }
1515 if a.inner.is_null() || b.inner.is_null() { return false; }
1516 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1519 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
1520 pub(crate) type nativeExpiryTime = nativeExpiryTimeImport;
1522 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
1526 pub struct ExpiryTime {
1527 /// A pointer to the opaque Rust object.
1529 /// Nearly everywhere, inner must be non-null, however in places where
1530 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1531 pub inner: *mut nativeExpiryTime,
1532 /// Indicates that this is the only struct which contains the same pointer.
1534 /// Rust functions which take ownership of an object provided via an argument require
1535 /// this to be true and invalidate the object pointed to by inner.
1539 impl Drop for ExpiryTime {
1540 fn drop(&mut self) {
1541 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
1542 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1546 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
1548 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
1550 /// Used only if an object of this type is returned as a trait impl by a method
1551 pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
1552 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
1556 pub(crate) fn get_native_ref(&self) -> &'static nativeExpiryTime {
1557 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1559 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpiryTime {
1560 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1562 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1563 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
1564 assert!(self.is_owned);
1565 let ret = ObjOps::untweak_ptr(self.inner);
1566 self.inner = core::ptr::null_mut();
1570 impl Clone for ExpiryTime {
1571 fn clone(&self) -> Self {
1573 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { core::ptr::null_mut() } else {
1574 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1580 /// Used only if an object of this type is returned as a trait impl by a method
1581 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1582 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1585 /// Creates a copy of the ExpiryTime
1586 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1589 /// Checks if two ExpiryTimes contain equal inner contents.
1591 pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 {
1592 if o.inner.is_null() { return 0; }
1593 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1594 #[allow(deprecated)]
1595 let mut hasher = core::hash::SipHasher::new();
1596 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1597 core::hash::Hasher::finish(&hasher)
1599 /// Checks if two ExpiryTimes contain equal inner contents.
1600 /// This ignores pointers and is_owned flags and looks at the values in fields.
1601 /// Two objects with NULL inner values will be considered "equal" here.
1603 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1604 if a.inner == b.inner { return true; }
1605 if a.inner.is_null() || b.inner.is_null() { return false; }
1606 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1609 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
1610 pub(crate) type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
1612 /// `min_final_cltv_expiry` to use for the last HTLC in the route
1615 pub struct MinFinalCltvExpiry {
1616 /// A pointer to the opaque Rust object.
1618 /// Nearly everywhere, inner must be non-null, however in places where
1619 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1620 pub inner: *mut nativeMinFinalCltvExpiry,
1621 /// Indicates that this is the only struct which contains the same pointer.
1623 /// Rust functions which take ownership of an object provided via an argument require
1624 /// this to be true and invalidate the object pointed to by inner.
1628 impl Drop for MinFinalCltvExpiry {
1629 fn drop(&mut self) {
1630 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
1631 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1635 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1637 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1639 /// Used only if an object of this type is returned as a trait impl by a method
1640 pub(crate) extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1641 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1644 impl MinFinalCltvExpiry {
1645 pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiry {
1646 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1648 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiry {
1649 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1651 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1652 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1653 assert!(self.is_owned);
1654 let ret = ObjOps::untweak_ptr(self.inner);
1655 self.inner = core::ptr::null_mut();
1660 pub extern "C" fn MinFinalCltvExpiry_get_a(this_ptr: &MinFinalCltvExpiry) -> u64 {
1661 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1665 pub extern "C" fn MinFinalCltvExpiry_set_a(this_ptr: &mut MinFinalCltvExpiry, mut val: u64) {
1666 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val;
1668 /// Constructs a new MinFinalCltvExpiry given each field
1671 pub extern "C" fn MinFinalCltvExpiry_new(mut a_arg: u64) -> MinFinalCltvExpiry {
1672 MinFinalCltvExpiry { inner: ObjOps::heap_alloc(lightning_invoice::MinFinalCltvExpiry (
1674 )), is_owned: true }
1676 impl Clone for MinFinalCltvExpiry {
1677 fn clone(&self) -> Self {
1679 inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { core::ptr::null_mut() } else {
1680 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1686 /// Used only if an object of this type is returned as a trait impl by a method
1687 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1688 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1691 /// Creates a copy of the MinFinalCltvExpiry
1692 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1695 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1697 pub extern "C" fn MinFinalCltvExpiry_hash(o: &MinFinalCltvExpiry) -> u64 {
1698 if o.inner.is_null() { return 0; }
1699 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1700 #[allow(deprecated)]
1701 let mut hasher = core::hash::SipHasher::new();
1702 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1703 core::hash::Hasher::finish(&hasher)
1705 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1706 /// This ignores pointers and is_owned flags and looks at the values in fields.
1707 /// Two objects with NULL inner values will be considered "equal" here.
1709 pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool {
1710 if a.inner == b.inner { return true; }
1711 if a.inner.is_null() || b.inner.is_null() { return false; }
1712 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1714 /// Fallback address in case no LN payment is possible
1720 version: crate::c_types::u5,
1721 program: crate::c_types::derived::CVec_u8Z,
1723 PubKeyHash(crate::c_types::TwentyBytes),
1724 ScriptHash(crate::c_types::TwentyBytes),
1726 use lightning_invoice::Fallback as FallbackImport;
1727 pub(crate) type nativeFallback = FallbackImport;
1731 pub(crate) fn to_native(&self) -> nativeFallback {
1733 Fallback::SegWitProgram {ref version, ref program, } => {
1734 let mut version_nonref = (*version).clone();
1735 let mut program_nonref = (*program).clone();
1736 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1737 nativeFallback::SegWitProgram {
1738 version: version_nonref.into(),
1739 program: local_program_nonref,
1742 Fallback::PubKeyHash (ref a, ) => {
1743 let mut a_nonref = (*a).clone();
1744 nativeFallback::PubKeyHash (
1748 Fallback::ScriptHash (ref a, ) => {
1749 let mut a_nonref = (*a).clone();
1750 nativeFallback::ScriptHash (
1757 pub(crate) fn into_native(self) -> nativeFallback {
1759 Fallback::SegWitProgram {mut version, mut program, } => {
1760 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1761 nativeFallback::SegWitProgram {
1762 version: version.into(),
1763 program: local_program,
1766 Fallback::PubKeyHash (mut a, ) => {
1767 nativeFallback::PubKeyHash (
1771 Fallback::ScriptHash (mut a, ) => {
1772 nativeFallback::ScriptHash (
1779 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1781 nativeFallback::SegWitProgram {ref version, ref program, } => {
1782 let mut version_nonref = (*version).clone();
1783 let mut program_nonref = (*program).clone();
1784 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1785 Fallback::SegWitProgram {
1786 version: version_nonref.into(),
1787 program: local_program_nonref.into(),
1790 nativeFallback::PubKeyHash (ref a, ) => {
1791 let mut a_nonref = (*a).clone();
1792 Fallback::PubKeyHash (
1793 crate::c_types::TwentyBytes { data: a_nonref },
1796 nativeFallback::ScriptHash (ref a, ) => {
1797 let mut a_nonref = (*a).clone();
1798 Fallback::ScriptHash (
1799 crate::c_types::TwentyBytes { data: a_nonref },
1805 pub(crate) fn native_into(native: nativeFallback) -> Self {
1807 nativeFallback::SegWitProgram {mut version, mut program, } => {
1808 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1809 Fallback::SegWitProgram {
1810 version: version.into(),
1811 program: local_program.into(),
1814 nativeFallback::PubKeyHash (mut a, ) => {
1815 Fallback::PubKeyHash (
1816 crate::c_types::TwentyBytes { data: a },
1819 nativeFallback::ScriptHash (mut a, ) => {
1820 Fallback::ScriptHash (
1821 crate::c_types::TwentyBytes { data: a },
1827 /// Frees any resources used by the Fallback
1829 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1830 /// Creates a copy of the Fallback
1832 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1836 /// Utility method to constructs a new SegWitProgram-variant Fallback
1837 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::u5, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
1838 Fallback::SegWitProgram {
1844 /// Utility method to constructs a new PubKeyHash-variant Fallback
1845 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1846 Fallback::PubKeyHash(a, )
1849 /// Utility method to constructs a new ScriptHash-variant Fallback
1850 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1851 Fallback::ScriptHash(a, )
1853 /// Checks if two Fallbacks contain equal inner contents.
1855 pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 {
1856 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1857 #[allow(deprecated)]
1858 let mut hasher = core::hash::SipHasher::new();
1859 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1860 core::hash::Hasher::finish(&hasher)
1862 /// Checks if two Fallbacks contain equal inner contents.
1863 /// This ignores pointers and is_owned flags and looks at the values in fields.
1865 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1866 if &a.to_native() == &b.to_native() { true } else { false }
1869 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1870 pub(crate) type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1872 /// Recoverable signature
1875 pub struct InvoiceSignature {
1876 /// A pointer to the opaque Rust object.
1878 /// Nearly everywhere, inner must be non-null, however in places where
1879 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1880 pub inner: *mut nativeInvoiceSignature,
1881 /// Indicates that this is the only struct which contains the same pointer.
1883 /// Rust functions which take ownership of an object provided via an argument require
1884 /// this to be true and invalidate the object pointed to by inner.
1888 impl Drop for InvoiceSignature {
1889 fn drop(&mut self) {
1890 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1891 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1895 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1897 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1899 /// Used only if an object of this type is returned as a trait impl by a method
1900 pub(crate) extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1901 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1904 impl InvoiceSignature {
1905 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceSignature {
1906 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1908 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceSignature {
1909 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1911 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1912 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1913 assert!(self.is_owned);
1914 let ret = ObjOps::untweak_ptr(self.inner);
1915 self.inner = core::ptr::null_mut();
1919 impl Clone for InvoiceSignature {
1920 fn clone(&self) -> Self {
1922 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { core::ptr::null_mut() } else {
1923 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1929 /// Used only if an object of this type is returned as a trait impl by a method
1930 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
1931 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
1934 /// Creates a copy of the InvoiceSignature
1935 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
1938 /// Checks if two InvoiceSignatures contain equal inner contents.
1939 /// This ignores pointers and is_owned flags and looks at the values in fields.
1940 /// Two objects with NULL inner values will be considered "equal" here.
1942 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
1943 if a.inner == b.inner { return true; }
1944 if a.inner.is_null() || b.inner.is_null() { return false; }
1945 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1948 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
1949 pub(crate) type nativePrivateRoute = nativePrivateRouteImport;
1951 /// Private routing information
1954 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
1958 pub struct PrivateRoute {
1959 /// A pointer to the opaque Rust object.
1961 /// Nearly everywhere, inner must be non-null, however in places where
1962 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1963 pub inner: *mut nativePrivateRoute,
1964 /// Indicates that this is the only struct which contains the same pointer.
1966 /// Rust functions which take ownership of an object provided via an argument require
1967 /// this to be true and invalidate the object pointed to by inner.
1971 impl Drop for PrivateRoute {
1972 fn drop(&mut self) {
1973 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
1974 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1978 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
1980 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
1982 /// Used only if an object of this type is returned as a trait impl by a method
1983 pub(crate) extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
1984 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); }
1988 pub(crate) fn get_native_ref(&self) -> &'static nativePrivateRoute {
1989 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1991 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateRoute {
1992 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1994 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1995 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
1996 assert!(self.is_owned);
1997 let ret = ObjOps::untweak_ptr(self.inner);
1998 self.inner = core::ptr::null_mut();
2002 impl Clone for PrivateRoute {
2003 fn clone(&self) -> Self {
2005 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
2006 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2012 /// Used only if an object of this type is returned as a trait impl by a method
2013 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
2014 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
2017 /// Creates a copy of the PrivateRoute
2018 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
2021 /// Checks if two PrivateRoutes contain equal inner contents.
2023 pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 {
2024 if o.inner.is_null() { return 0; }
2025 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2026 #[allow(deprecated)]
2027 let mut hasher = core::hash::SipHasher::new();
2028 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2029 core::hash::Hasher::finish(&hasher)
2031 /// Checks if two PrivateRoutes contain equal inner contents.
2032 /// This ignores pointers and is_owned flags and looks at the values in fields.
2033 /// Two objects with NULL inner values will be considered "equal" here.
2035 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
2036 if a.inner == b.inner { return true; }
2037 if a.inner.is_null() || b.inner.is_null() { return false; }
2038 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2040 /// Disassembles the `SignedRawInvoice` into its three parts:
2042 /// 2. hash of the raw invoice
2046 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
2047 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
2048 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();
2052 /// The `RawInvoice` which was signed.
2055 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
2056 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice();
2057 crate::lightning_invoice::RawInvoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawInvoice<>) as *mut _) }, is_owned: false }
2060 /// The hash of the `RawInvoice` that was signed.
2063 pub extern "C" fn SignedRawInvoice_hash(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> *const [u8; 32] {
2064 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
2068 /// InvoiceSignature for the invoice.
2071 pub extern "C" fn SignedRawInvoice_signature(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
2072 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
2073 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::InvoiceSignature<>) as *mut _) }, is_owned: false }
2076 /// Recovers the public key used for signing the invoice from the recoverable signature.
2079 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
2080 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2081 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() };
2085 /// Checks if the signature is valid for the included payee public key or if none exists if it's
2086 /// valid for the recovered signature (which should always be true?).
2089 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> bool {
2090 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2094 /// Calculate the hash of the encoded `RawInvoice`
2097 pub extern "C" fn RawInvoice_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes {
2098 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
2099 crate::c_types::ThirtyTwoBytes { data: ret }
2103 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2106 pub extern "C" fn RawInvoice_payment_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Sha256 {
2107 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2108 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 };
2113 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2116 pub extern "C" fn RawInvoice_description(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Description {
2117 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
2118 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 };
2123 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2126 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::PayeePubKey {
2127 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2128 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 };
2133 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2136 pub extern "C" fn RawInvoice_description_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Sha256 {
2137 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash();
2138 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 };
2143 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2146 pub extern "C" fn RawInvoice_expiry_time(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::ExpiryTime {
2147 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2148 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 };
2153 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2156 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
2157 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
2158 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 };
2163 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2166 pub extern "C" fn RawInvoice_payment_secret(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes {
2167 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2168 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
2173 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2176 pub extern "C" fn RawInvoice_features(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
2177 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2178 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 };
2184 pub extern "C" fn RawInvoice_private_routes(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2185 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2186 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 } }); };
2192 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::derived::COption_u64Z {
2193 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
2194 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() }) };
2200 pub extern "C" fn RawInvoice_currency(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Currency {
2201 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2202 crate::lightning_invoice::Currency::native_into(ret)
2205 /// Creates a `PositiveTimestamp` from a Unix timestamp in the range `0..=MAX_TIMESTAMP`.
2207 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2210 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2211 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
2212 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() };
2216 /// Creates a `PositiveTimestamp` from a [`SystemTime`] with a corresponding Unix timestamp in
2217 /// the range `0..=MAX_TIMESTAMP`.
2219 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2222 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2223 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
2224 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() };
2228 /// Creates a `PositiveTimestamp` from a [`Duration`] since the Unix epoch in the range
2229 /// `0..=MAX_TIMESTAMP`.
2231 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2234 pub extern "C" fn PositiveTimestamp_from_duration_since_epoch(mut duration: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2235 let mut ret = lightning_invoice::PositiveTimestamp::from_duration_since_epoch(core::time::Duration::from_secs(duration));
2236 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() };
2240 /// Returns the Unix timestamp representing the stored time
2243 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2244 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_unix_timestamp();
2248 /// Returns the duration of the stored time since the Unix epoch
2251 pub extern "C" fn PositiveTimestamp_as_duration_since_epoch(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2252 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration_since_epoch();
2256 /// Returns the [`SystemTime`] representing the stored time
2259 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2260 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_time();
2261 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2264 /// Transform the `Invoice` into it's unchecked version
2267 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: crate::lightning_invoice::Invoice) -> crate::lightning_invoice::SignedRawInvoice {
2268 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
2269 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(ret), is_owned: true }
2272 /// Check that the invoice is signed correctly and that key recovery works
2275 pub extern "C" fn Invoice_check_signature(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
2276 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2277 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() };
2281 /// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
2283 /// use lightning_invoice::*;
2285 /// let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
2286 /// h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
2287 /// 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
2288 /// h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
2289 /// j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
2290 /// ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
2291 /// guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
2292 /// ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
2293 /// p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
2294 /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
2295 /// j5r6drg6k6zcqj0fcwg\";
2297 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
2299 /// assert!(Invoice::from_signed(signed).is_ok());
2303 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
2304 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
2305 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() };
2309 /// Returns the `Invoice`'s timestamp (should equal its creation time)
2312 pub extern "C" fn Invoice_timestamp(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2313 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timestamp();
2314 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2317 /// Returns the `Invoice`'s timestamp as a duration since the Unix epoch
2320 pub extern "C" fn Invoice_duration_since_epoch(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2321 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_since_epoch();
2325 /// Returns the hash to which we will receive the preimage on completion of the payment
2328 pub extern "C" fn Invoice_payment_hash(this_arg: &crate::lightning_invoice::Invoice) -> *const [u8; 32] {
2329 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2333 /// Get the payee's public key if one was included in the invoice
2335 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2338 pub extern "C" fn Invoice_payee_pub_key(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::PublicKey {
2339 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2340 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
2344 /// Get the payment secret if one was included in the invoice
2347 pub extern "C" fn Invoice_payment_secret(this_arg: &crate::lightning_invoice::Invoice) -> *const [u8; 32] {
2348 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2352 /// Get the invoice features if they were included in the invoice
2354 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2357 pub extern "C" fn Invoice_features(this_arg: &crate::lightning_invoice::Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
2358 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2359 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 };
2363 /// Recover the payee's public key (only to be used if none was included in the invoice)
2366 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::PublicKey {
2367 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2368 crate::c_types::PublicKey::from_rust(&ret)
2371 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
2374 pub extern "C" fn Invoice_expiry_time(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2375 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2379 /// Returns whether the invoice has expired.
2382 pub extern "C" fn Invoice_is_expired(this_arg: &crate::lightning_invoice::Invoice) -> bool {
2383 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
2387 /// Returns whether the expiry time would pass at the given point in time.
2388 /// `at_time` is the timestamp as a duration since the Unix epoch.
2391 pub extern "C" fn Invoice_would_expire(this_arg: &crate::lightning_invoice::Invoice, mut at_time: u64) -> bool {
2392 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.would_expire(core::time::Duration::from_secs(at_time));
2396 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
2397 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
2400 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2401 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
2405 /// Returns a list of all routes included in the invoice
2408 pub extern "C" fn Invoice_private_routes(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2409 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2410 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 } }); };
2414 /// Returns a list of all routes included in the invoice as the underlying hints
2417 pub extern "C" fn Invoice_route_hints(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
2418 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints();
2419 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 } }); };
2423 /// Returns the currency for which the invoice was issued
2426 pub extern "C" fn Invoice_currency(this_arg: &crate::lightning_invoice::Invoice) -> crate::lightning_invoice::Currency {
2427 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2428 crate::lightning_invoice::Currency::native_into(ret)
2431 /// Returns the amount if specified in the invoice as millisatoshis.
2434 pub extern "C" fn Invoice_amount_milli_satoshis(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::COption_u64Z {
2435 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_milli_satoshis();
2436 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() }) };
2440 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
2441 /// returns `CreationError::DescriptionTooLong` otherwise
2443 /// Please note that single characters may use more than one byte due to UTF8 encoding.
2446 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
2447 let mut ret = lightning_invoice::Description::new(description.into_string());
2448 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() };
2452 /// Returns the underlying description `String`
2455 pub extern "C" fn Description_into_inner(mut this_arg: crate::lightning_invoice::Description) -> crate::c_types::Str {
2456 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2460 /// Construct an `ExpiryTime` from seconds.
2463 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::lightning_invoice::ExpiryTime {
2464 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
2465 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2468 /// Construct an `ExpiryTime` from a `Duration`.
2471 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::lightning_invoice::ExpiryTime {
2472 let mut ret = lightning_invoice::ExpiryTime::from_duration(core::time::Duration::from_secs(duration));
2473 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2476 /// Returns the expiry time in seconds
2479 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2480 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_seconds();
2484 /// Returns a reference to the underlying `Duration` (=expiry time)
2487 pub extern "C" fn ExpiryTime_as_duration(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2488 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration();
2492 /// Creates a new (partial) route from a list of hops
2495 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
2496 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
2497 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() };
2501 /// Returns the underlying list of hops
2504 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: crate::lightning_invoice::PrivateRoute) -> crate::lightning::routing::router::RouteHint {
2505 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2506 crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true }
2509 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
2513 pub enum CreationError {
2514 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
2516 /// The specified route has too many hops and can't be encoded
2518 /// The Unix timestamp of the supplied date is less than zero or greater than 35-bits
2519 TimestampOutOfBounds,
2520 /// The supplied millisatoshi amount was greater than the total bitcoin supply.
2522 /// Route hints were required for this invoice and were missing. Applies to
2523 /// [phantom invoices].
2525 /// [phantom invoices]: crate::utils::create_phantom_invoice
2528 use lightning_invoice::CreationError as CreationErrorImport;
2529 pub(crate) type nativeCreationError = CreationErrorImport;
2531 impl CreationError {
2533 pub(crate) fn to_native(&self) -> nativeCreationError {
2535 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2536 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2537 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2538 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2539 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2543 pub(crate) fn into_native(self) -> nativeCreationError {
2545 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2546 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2547 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2548 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2549 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2553 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
2555 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2556 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2557 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2558 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2559 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2563 pub(crate) fn native_into(native: nativeCreationError) -> Self {
2565 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2566 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2567 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2568 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2569 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2573 /// Creates a copy of the CreationError
2575 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
2579 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
2580 pub extern "C" fn CreationError_description_too_long() -> CreationError {
2581 CreationError::DescriptionTooLong}
2583 /// Utility method to constructs a new RouteTooLong-variant CreationError
2584 pub extern "C" fn CreationError_route_too_long() -> CreationError {
2585 CreationError::RouteTooLong}
2587 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
2588 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
2589 CreationError::TimestampOutOfBounds}
2591 /// Utility method to constructs a new InvalidAmount-variant CreationError
2592 pub extern "C" fn CreationError_invalid_amount() -> CreationError {
2593 CreationError::InvalidAmount}
2595 /// Utility method to constructs a new MissingRouteHints-variant CreationError
2596 pub extern "C" fn CreationError_missing_route_hints() -> CreationError {
2597 CreationError::MissingRouteHints}
2598 /// Checks if two CreationErrors contain equal inner contents.
2599 /// This ignores pointers and is_owned flags and looks at the values in fields.
2601 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
2602 if &a.to_native() == &b.to_native() { true } else { false }
2605 /// Get the string representation of a CreationError object
2606 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
2607 alloc::format!("{}", &o.to_native()).into()
2609 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
2610 /// requirements sections in BOLT #11
2614 pub enum SemanticError {
2615 /// The invoice is missing the mandatory payment hash
2617 /// The invoice has multiple payment hashes which isn't allowed
2618 MultiplePaymentHashes,
2619 /// No description or description hash are part of the invoice
2621 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
2622 MultipleDescriptions,
2623 /// The invoice is missing the mandatory payment secret, which all modern lightning nodes
2626 /// The invoice contains multiple payment secrets
2627 MultiplePaymentSecrets,
2628 /// The invoice's features are invalid
2630 /// The recovery id doesn't fit the signature/pub key
2632 /// The invoice's signature is invalid
2634 /// The invoice's amount was not a whole number of millisatoshis
2637 use lightning_invoice::SemanticError as SemanticErrorImport;
2638 pub(crate) type nativeSemanticError = SemanticErrorImport;
2640 impl SemanticError {
2642 pub(crate) fn to_native(&self) -> nativeSemanticError {
2644 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2645 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2646 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2647 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2648 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2649 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2650 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2651 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2652 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2653 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2657 pub(crate) fn into_native(self) -> nativeSemanticError {
2659 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2660 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2661 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2662 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2663 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2664 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2665 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2666 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2667 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2668 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2672 pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
2674 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2675 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2676 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2677 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2678 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2679 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2680 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2681 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2682 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2683 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2687 pub(crate) fn native_into(native: nativeSemanticError) -> Self {
2689 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2690 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2691 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2692 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2693 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2694 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2695 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2696 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2697 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2698 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2702 /// Creates a copy of the SemanticError
2704 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
2708 /// Utility method to constructs a new NoPaymentHash-variant SemanticError
2709 pub extern "C" fn SemanticError_no_payment_hash() -> SemanticError {
2710 SemanticError::NoPaymentHash}
2712 /// Utility method to constructs a new MultiplePaymentHashes-variant SemanticError
2713 pub extern "C" fn SemanticError_multiple_payment_hashes() -> SemanticError {
2714 SemanticError::MultiplePaymentHashes}
2716 /// Utility method to constructs a new NoDescription-variant SemanticError
2717 pub extern "C" fn SemanticError_no_description() -> SemanticError {
2718 SemanticError::NoDescription}
2720 /// Utility method to constructs a new MultipleDescriptions-variant SemanticError
2721 pub extern "C" fn SemanticError_multiple_descriptions() -> SemanticError {
2722 SemanticError::MultipleDescriptions}
2724 /// Utility method to constructs a new NoPaymentSecret-variant SemanticError
2725 pub extern "C" fn SemanticError_no_payment_secret() -> SemanticError {
2726 SemanticError::NoPaymentSecret}
2728 /// Utility method to constructs a new MultiplePaymentSecrets-variant SemanticError
2729 pub extern "C" fn SemanticError_multiple_payment_secrets() -> SemanticError {
2730 SemanticError::MultiplePaymentSecrets}
2732 /// Utility method to constructs a new InvalidFeatures-variant SemanticError
2733 pub extern "C" fn SemanticError_invalid_features() -> SemanticError {
2734 SemanticError::InvalidFeatures}
2736 /// Utility method to constructs a new InvalidRecoveryId-variant SemanticError
2737 pub extern "C" fn SemanticError_invalid_recovery_id() -> SemanticError {
2738 SemanticError::InvalidRecoveryId}
2740 /// Utility method to constructs a new InvalidSignature-variant SemanticError
2741 pub extern "C" fn SemanticError_invalid_signature() -> SemanticError {
2742 SemanticError::InvalidSignature}
2744 /// Utility method to constructs a new ImpreciseAmount-variant SemanticError
2745 pub extern "C" fn SemanticError_imprecise_amount() -> SemanticError {
2746 SemanticError::ImpreciseAmount}
2747 /// Checks if two SemanticErrors contain equal inner contents.
2748 /// This ignores pointers and is_owned flags and looks at the values in fields.
2750 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
2751 if &a.to_native() == &b.to_native() { true } else { false }
2754 /// Get the string representation of a SemanticError object
2755 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
2756 alloc::format!("{}", &o.to_native()).into()
2758 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
2763 pub enum SignOrCreationError {
2764 /// An error occurred during signing
2766 /// An error occurred while building the transaction
2767 CreationError(crate::lightning_invoice::CreationError),
2769 use lightning_invoice::SignOrCreationError as SignOrCreationErrorImport;
2770 pub(crate) type nativeSignOrCreationError = SignOrCreationErrorImport<>;
2772 impl SignOrCreationError {
2774 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
2776 SignOrCreationError::SignError => {
2777 nativeSignOrCreationError::SignError (
2781 SignOrCreationError::CreationError (ref a, ) => {
2782 let mut a_nonref = (*a).clone();
2783 nativeSignOrCreationError::CreationError (
2784 a_nonref.into_native(),
2790 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
2792 SignOrCreationError::SignError => {
2793 nativeSignOrCreationError::SignError (
2797 SignOrCreationError::CreationError (mut a, ) => {
2798 nativeSignOrCreationError::CreationError (
2805 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
2807 nativeSignOrCreationError::SignError (ref a, ) => {
2808 SignOrCreationError::SignError },
2809 nativeSignOrCreationError::CreationError (ref a, ) => {
2810 let mut a_nonref = (*a).clone();
2811 SignOrCreationError::CreationError (
2812 crate::lightning_invoice::CreationError::native_into(a_nonref),
2818 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
2820 nativeSignOrCreationError::SignError (mut a, ) => {
2821 SignOrCreationError::SignError },
2822 nativeSignOrCreationError::CreationError (mut a, ) => {
2823 SignOrCreationError::CreationError (
2824 crate::lightning_invoice::CreationError::native_into(a),
2830 /// Frees any resources used by the SignOrCreationError
2832 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
2833 /// Creates a copy of the SignOrCreationError
2835 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
2839 /// Utility method to constructs a new SignError-variant SignOrCreationError
2840 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
2841 SignOrCreationError::SignError
2844 /// Utility method to constructs a new CreationError-variant SignOrCreationError
2845 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
2846 SignOrCreationError::CreationError(a, )
2848 /// Checks if two SignOrCreationErrors contain equal inner contents.
2849 /// This ignores pointers and is_owned flags and looks at the values in fields.
2851 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
2852 if &a.to_native() == &b.to_native() { true } else { false }
2855 /// Get the string representation of a SignOrCreationError object
2856 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
2857 alloc::format!("{}", &o.to_native()).into()