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 [`Invoice::from_str`])
15 //! * For constructing invoices use the [`InvoiceBuilder`]
16 //! * For serializing invoices use the [`Display`]/[`ToString`] traits
18 //! [`Invoice::from_str`]: crate::Invoice#impl-FromStr
20 use alloc::str::FromStr;
21 use core::ffi::c_void;
22 use core::convert::Infallible;
23 use bitcoin::hashes::Hash;
24 use crate::c_types::*;
25 #[cfg(feature="no-std")]
26 use alloc::{vec::Vec, boxed::Box};
33 use alloc::str::FromStr;
34 use core::ffi::c_void;
35 use core::convert::Infallible;
36 use bitcoin::hashes::Hash;
37 use crate::c_types::*;
38 #[cfg(feature="no-std")]
39 use alloc::{vec::Vec, boxed::Box};
44 use alloc::str::FromStr;
45 use core::ffi::c_void;
46 use core::convert::Infallible;
47 use bitcoin::hashes::Hash;
48 use crate::c_types::*;
49 #[cfg(feature="no-std")]
50 use alloc::{vec::Vec, boxed::Box};
54 use alloc::str::FromStr;
55 use core::ffi::c_void;
56 use core::convert::Infallible;
57 use bitcoin::hashes::Hash;
58 use crate::c_types::*;
59 #[cfg(feature="no-std")]
60 use alloc::{vec::Vec, boxed::Box};
64 /// Read a SiPrefix object from a string
65 pub extern "C" fn SiPrefix_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SiPrefixParseErrorZ {
66 match lightning_invoice::SiPrefix::from_str(s.into_str()) {
68 crate::c_types::CResultTempl::ok(
69 crate::lightning_invoice::SiPrefix::native_into(r)
73 crate::c_types::CResultTempl::err(
74 crate::lightning_invoice::ParseError::native_into(e)
80 /// Read a Invoice object from a string
81 pub extern "C" fn Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_InvoiceParseOrSemanticErrorZ {
82 match lightning_invoice::Invoice::from_str(s.into_str()) {
84 crate::c_types::CResultTempl::ok(
85 crate::lightning_invoice::Invoice { inner: ObjOps::heap_alloc(r), is_owned: true }
89 crate::c_types::CResultTempl::err(
90 crate::lightning_invoice::ParseOrSemanticError::native_into(e)
96 /// Read a SignedRawInvoice object from a string
97 pub extern "C" fn SignedRawInvoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SignedRawInvoiceParseErrorZ {
98 match lightning_invoice::SignedRawInvoice::from_str(s.into_str()) {
100 crate::c_types::CResultTempl::ok(
101 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(r), is_owned: true }
105 crate::c_types::CResultTempl::err(
106 crate::lightning_invoice::ParseError::native_into(e)
112 /// Get the string representation of a ParseError object
113 pub extern "C" fn ParseError_to_str(o: &crate::lightning_invoice::ParseError) -> Str {
114 alloc::format!("{}", &o.to_native()).into()
117 /// Get the string representation of a ParseOrSemanticError object
118 pub extern "C" fn ParseOrSemanticError_to_str(o: &crate::lightning_invoice::ParseOrSemanticError) -> Str {
119 alloc::format!("{}", &o.to_native()).into()
124 use alloc::str::FromStr;
125 use core::ffi::c_void;
126 use core::convert::Infallible;
127 use bitcoin::hashes::Hash;
128 use crate::c_types::*;
129 #[cfg(feature="no-std")]
130 use alloc::{vec::Vec, boxed::Box};
133 /// Get the string representation of a Invoice object
134 pub extern "C" fn Invoice_to_str(o: &crate::lightning_invoice::Invoice) -> Str {
135 alloc::format!("{}", o.get_native_ref()).into()
138 /// Get the string representation of a SignedRawInvoice object
139 pub extern "C" fn SignedRawInvoice_to_str(o: &crate::lightning_invoice::SignedRawInvoice) -> Str {
140 alloc::format!("{}", o.get_native_ref()).into()
143 /// Get the string representation of a Currency object
144 pub extern "C" fn Currency_to_str(o: &crate::lightning_invoice::Currency) -> Str {
145 alloc::format!("{}", &o.to_native()).into()
148 /// Get the string representation of a SiPrefix object
149 pub extern "C" fn SiPrefix_to_str(o: &crate::lightning_invoice::SiPrefix) -> Str {
150 alloc::format!("{}", &o.to_native()).into()
155 use alloc::str::FromStr;
156 use core::ffi::c_void;
157 use core::convert::Infallible;
158 use bitcoin::hashes::Hash;
159 use crate::c_types::*;
160 #[cfg(feature="no-std")]
161 use alloc::{vec::Vec, boxed::Box};
166 use alloc::str::FromStr;
167 use core::ffi::c_void;
168 use core::convert::Infallible;
169 use bitcoin::hashes::Hash;
170 use crate::c_types::*;
171 #[cfg(feature="no-std")]
172 use alloc::{vec::Vec, boxed::Box};
177 use alloc::str::FromStr;
178 use core::ffi::c_void;
179 use core::convert::Infallible;
180 use bitcoin::hashes::Hash;
181 use crate::c_types::*;
182 #[cfg(feature="no-std")]
183 use alloc::{vec::Vec, boxed::Box};
186 /// Errors that indicate what is wrong with the invoice. They have some granularity for debug
187 /// reasons, but should generally result in an \"invalid BOLT11 invoice\" message for the user.
191 pub enum ParseError {
193 crate::c_types::Bech32Error),
195 crate::c_types::Error),
197 crate::c_types::Secp256k1Error),
203 UnexpectedEndOfTaggedFields,
204 DescriptionDecodeError(
205 crate::c_types::Error),
207 IntegerOverflowError,
208 InvalidSegWitProgramLength,
209 InvalidPubKeyHashLength,
210 InvalidScriptHashLength,
213 crate::c_types::Str),
214 /// Not an error, but used internally to signal that a part of the invoice should be ignored
215 /// according to BOLT11
218 use lightning_invoice::ParseError as ParseErrorImport;
219 pub(crate) type nativeParseError = ParseErrorImport;
223 pub(crate) fn to_native(&self) -> nativeParseError {
225 ParseError::Bech32Error (ref a, ) => {
226 let mut a_nonref = Clone::clone(a);
227 nativeParseError::Bech32Error (
228 a_nonref.into_rust(),
231 ParseError::ParseAmountError (ref a, ) => {
232 let mut a_nonref = Clone::clone(a);
233 nativeParseError::ParseAmountError (
234 u8::from_str_radix(" a", 10).unwrap_err() /*a_nonref*/,
237 ParseError::MalformedSignature (ref a, ) => {
238 let mut a_nonref = Clone::clone(a);
239 nativeParseError::MalformedSignature (
240 a_nonref.into_rust(),
243 ParseError::BadPrefix => nativeParseError::BadPrefix,
244 ParseError::UnknownCurrency => nativeParseError::UnknownCurrency,
245 ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix,
246 ParseError::MalformedHRP => nativeParseError::MalformedHRP,
247 ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
248 ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
249 ParseError::DescriptionDecodeError (ref a, ) => {
250 let mut a_nonref = Clone::clone(a);
251 nativeParseError::DescriptionDecodeError (
252 core::str::from_utf8(&[0xff]).unwrap_err() /*a_nonref*/,
255 ParseError::PaddingError => nativeParseError::PaddingError,
256 ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError,
257 ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength,
258 ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength,
259 ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
260 ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
261 ParseError::InvalidSliceLength (ref a, ) => {
262 let mut a_nonref = Clone::clone(a);
263 nativeParseError::InvalidSliceLength (
264 a_nonref.into_string(),
267 ParseError::Skip => nativeParseError::Skip,
271 pub(crate) fn into_native(self) -> nativeParseError {
273 ParseError::Bech32Error (mut a, ) => {
274 nativeParseError::Bech32Error (
278 ParseError::ParseAmountError (mut a, ) => {
279 nativeParseError::ParseAmountError (
280 u8::from_str_radix(" a", 10).unwrap_err() /*a*/,
283 ParseError::MalformedSignature (mut a, ) => {
284 nativeParseError::MalformedSignature (
288 ParseError::BadPrefix => nativeParseError::BadPrefix,
289 ParseError::UnknownCurrency => nativeParseError::UnknownCurrency,
290 ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix,
291 ParseError::MalformedHRP => nativeParseError::MalformedHRP,
292 ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
293 ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
294 ParseError::DescriptionDecodeError (mut a, ) => {
295 nativeParseError::DescriptionDecodeError (
296 core::str::from_utf8(&[0xff]).unwrap_err() /*a*/,
299 ParseError::PaddingError => nativeParseError::PaddingError,
300 ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError,
301 ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength,
302 ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength,
303 ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
304 ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
305 ParseError::InvalidSliceLength (mut a, ) => {
306 nativeParseError::InvalidSliceLength (
310 ParseError::Skip => nativeParseError::Skip,
314 pub(crate) fn from_native(native: &nativeParseError) -> Self {
316 nativeParseError::Bech32Error (ref a, ) => {
317 let mut a_nonref = Clone::clone(a);
318 ParseError::Bech32Error (
319 crate::c_types::Bech32Error::from_rust(a_nonref),
322 nativeParseError::ParseAmountError (ref a, ) => {
323 let mut a_nonref = Clone::clone(a);
324 ParseError::ParseAmountError (
325 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
328 nativeParseError::MalformedSignature (ref a, ) => {
329 let mut a_nonref = Clone::clone(a);
330 ParseError::MalformedSignature (
331 crate::c_types::Secp256k1Error::from_rust(a_nonref),
334 nativeParseError::BadPrefix => ParseError::BadPrefix,
335 nativeParseError::UnknownCurrency => ParseError::UnknownCurrency,
336 nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix,
337 nativeParseError::MalformedHRP => ParseError::MalformedHRP,
338 nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
339 nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
340 nativeParseError::DescriptionDecodeError (ref a, ) => {
341 let mut a_nonref = Clone::clone(a);
342 ParseError::DescriptionDecodeError (
343 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
346 nativeParseError::PaddingError => ParseError::PaddingError,
347 nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError,
348 nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength,
349 nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength,
350 nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
351 nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
352 nativeParseError::InvalidSliceLength (ref a, ) => {
353 let mut a_nonref = Clone::clone(a);
354 ParseError::InvalidSliceLength (
358 nativeParseError::Skip => ParseError::Skip,
362 pub(crate) fn native_into(native: nativeParseError) -> Self {
364 nativeParseError::Bech32Error (mut a, ) => {
365 ParseError::Bech32Error (
366 crate::c_types::Bech32Error::from_rust(a),
369 nativeParseError::ParseAmountError (mut a, ) => {
370 ParseError::ParseAmountError (
371 crate::c_types::Error { _dummy: 0 } /*a*/,
374 nativeParseError::MalformedSignature (mut a, ) => {
375 ParseError::MalformedSignature (
376 crate::c_types::Secp256k1Error::from_rust(a),
379 nativeParseError::BadPrefix => ParseError::BadPrefix,
380 nativeParseError::UnknownCurrency => ParseError::UnknownCurrency,
381 nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix,
382 nativeParseError::MalformedHRP => ParseError::MalformedHRP,
383 nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
384 nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
385 nativeParseError::DescriptionDecodeError (mut a, ) => {
386 ParseError::DescriptionDecodeError (
387 crate::c_types::Error { _dummy: 0 } /*a*/,
390 nativeParseError::PaddingError => ParseError::PaddingError,
391 nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError,
392 nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength,
393 nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength,
394 nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
395 nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
396 nativeParseError::InvalidSliceLength (mut a, ) => {
397 ParseError::InvalidSliceLength (
401 nativeParseError::Skip => ParseError::Skip,
405 /// Frees any resources used by the ParseError
407 pub extern "C" fn ParseError_free(this_ptr: ParseError) { }
408 /// Creates a copy of the ParseError
410 pub extern "C" fn ParseError_clone(orig: &ParseError) -> ParseError {
414 /// Utility method to constructs a new Bech32Error-variant ParseError
415 pub extern "C" fn ParseError_bech32_error(a: crate::c_types::Bech32Error) -> ParseError {
416 ParseError::Bech32Error(a, )
419 /// Utility method to constructs a new ParseAmountError-variant ParseError
420 pub extern "C" fn ParseError_parse_amount_error(a: crate::c_types::Error) -> ParseError {
421 ParseError::ParseAmountError(a, )
424 /// Utility method to constructs a new MalformedSignature-variant ParseError
425 pub extern "C" fn ParseError_malformed_signature(a: crate::c_types::Secp256k1Error) -> ParseError {
426 ParseError::MalformedSignature(a, )
429 /// Utility method to constructs a new BadPrefix-variant ParseError
430 pub extern "C" fn ParseError_bad_prefix() -> ParseError {
431 ParseError::BadPrefix}
433 /// Utility method to constructs a new UnknownCurrency-variant ParseError
434 pub extern "C" fn ParseError_unknown_currency() -> ParseError {
435 ParseError::UnknownCurrency}
437 /// Utility method to constructs a new UnknownSiPrefix-variant ParseError
438 pub extern "C" fn ParseError_unknown_si_prefix() -> ParseError {
439 ParseError::UnknownSiPrefix}
441 /// Utility method to constructs a new MalformedHRP-variant ParseError
442 pub extern "C" fn ParseError_malformed_hrp() -> ParseError {
443 ParseError::MalformedHRP}
445 /// Utility method to constructs a new TooShortDataPart-variant ParseError
446 pub extern "C" fn ParseError_too_short_data_part() -> ParseError {
447 ParseError::TooShortDataPart}
449 /// Utility method to constructs a new UnexpectedEndOfTaggedFields-variant ParseError
450 pub extern "C" fn ParseError_unexpected_end_of_tagged_fields() -> ParseError {
451 ParseError::UnexpectedEndOfTaggedFields}
453 /// Utility method to constructs a new DescriptionDecodeError-variant ParseError
454 pub extern "C" fn ParseError_description_decode_error(a: crate::c_types::Error) -> ParseError {
455 ParseError::DescriptionDecodeError(a, )
458 /// Utility method to constructs a new PaddingError-variant ParseError
459 pub extern "C" fn ParseError_padding_error() -> ParseError {
460 ParseError::PaddingError}
462 /// Utility method to constructs a new IntegerOverflowError-variant ParseError
463 pub extern "C" fn ParseError_integer_overflow_error() -> ParseError {
464 ParseError::IntegerOverflowError}
466 /// Utility method to constructs a new InvalidSegWitProgramLength-variant ParseError
467 pub extern "C" fn ParseError_invalid_seg_wit_program_length() -> ParseError {
468 ParseError::InvalidSegWitProgramLength}
470 /// Utility method to constructs a new InvalidPubKeyHashLength-variant ParseError
471 pub extern "C" fn ParseError_invalid_pub_key_hash_length() -> ParseError {
472 ParseError::InvalidPubKeyHashLength}
474 /// Utility method to constructs a new InvalidScriptHashLength-variant ParseError
475 pub extern "C" fn ParseError_invalid_script_hash_length() -> ParseError {
476 ParseError::InvalidScriptHashLength}
478 /// Utility method to constructs a new InvalidRecoveryId-variant ParseError
479 pub extern "C" fn ParseError_invalid_recovery_id() -> ParseError {
480 ParseError::InvalidRecoveryId}
482 /// Utility method to constructs a new InvalidSliceLength-variant ParseError
483 pub extern "C" fn ParseError_invalid_slice_length(a: crate::c_types::Str) -> ParseError {
484 ParseError::InvalidSliceLength(a, )
487 /// Utility method to constructs a new Skip-variant ParseError
488 pub extern "C" fn ParseError_skip() -> ParseError {
490 /// Checks if two ParseErrors contain equal inner contents.
491 /// This ignores pointers and is_owned flags and looks at the values in fields.
493 pub extern "C" fn ParseError_eq(a: &ParseError, b: &ParseError) -> bool {
494 if &a.to_native() == &b.to_native() { true } else { false }
496 /// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
497 /// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
498 /// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
502 pub enum ParseOrSemanticError {
503 /// The invoice couldn't be decoded
505 crate::lightning_invoice::ParseError),
506 /// The invoice could be decoded but violates the BOLT11 standard
508 crate::lightning_invoice::SemanticError),
510 use lightning_invoice::ParseOrSemanticError as ParseOrSemanticErrorImport;
511 pub(crate) type nativeParseOrSemanticError = ParseOrSemanticErrorImport;
513 impl ParseOrSemanticError {
515 pub(crate) fn to_native(&self) -> nativeParseOrSemanticError {
517 ParseOrSemanticError::ParseError (ref a, ) => {
518 let mut a_nonref = Clone::clone(a);
519 nativeParseOrSemanticError::ParseError (
520 a_nonref.into_native(),
523 ParseOrSemanticError::SemanticError (ref a, ) => {
524 let mut a_nonref = Clone::clone(a);
525 nativeParseOrSemanticError::SemanticError (
526 a_nonref.into_native(),
532 pub(crate) fn into_native(self) -> nativeParseOrSemanticError {
534 ParseOrSemanticError::ParseError (mut a, ) => {
535 nativeParseOrSemanticError::ParseError (
539 ParseOrSemanticError::SemanticError (mut a, ) => {
540 nativeParseOrSemanticError::SemanticError (
547 pub(crate) fn from_native(native: &nativeParseOrSemanticError) -> Self {
549 nativeParseOrSemanticError::ParseError (ref a, ) => {
550 let mut a_nonref = Clone::clone(a);
551 ParseOrSemanticError::ParseError (
552 crate::lightning_invoice::ParseError::native_into(a_nonref),
555 nativeParseOrSemanticError::SemanticError (ref a, ) => {
556 let mut a_nonref = Clone::clone(a);
557 ParseOrSemanticError::SemanticError (
558 crate::lightning_invoice::SemanticError::native_into(a_nonref),
564 pub(crate) fn native_into(native: nativeParseOrSemanticError) -> Self {
566 nativeParseOrSemanticError::ParseError (mut a, ) => {
567 ParseOrSemanticError::ParseError (
568 crate::lightning_invoice::ParseError::native_into(a),
571 nativeParseOrSemanticError::SemanticError (mut a, ) => {
572 ParseOrSemanticError::SemanticError (
573 crate::lightning_invoice::SemanticError::native_into(a),
579 /// Frees any resources used by the ParseOrSemanticError
581 pub extern "C" fn ParseOrSemanticError_free(this_ptr: ParseOrSemanticError) { }
582 /// Creates a copy of the ParseOrSemanticError
584 pub extern "C" fn ParseOrSemanticError_clone(orig: &ParseOrSemanticError) -> ParseOrSemanticError {
588 /// Utility method to constructs a new ParseError-variant ParseOrSemanticError
589 pub extern "C" fn ParseOrSemanticError_parse_error(a: crate::lightning_invoice::ParseError) -> ParseOrSemanticError {
590 ParseOrSemanticError::ParseError(a, )
593 /// Utility method to constructs a new SemanticError-variant ParseOrSemanticError
594 pub extern "C" fn ParseOrSemanticError_semantic_error(a: crate::lightning_invoice::SemanticError) -> ParseOrSemanticError {
595 ParseOrSemanticError::SemanticError(a, )
597 /// Checks if two ParseOrSemanticErrors contain equal inner contents.
598 /// This ignores pointers and is_owned flags and looks at the values in fields.
600 pub extern "C" fn ParseOrSemanticError_eq(a: &ParseOrSemanticError, b: &ParseOrSemanticError) -> bool {
601 if &a.to_native() == &b.to_native() { true } else { false }
603 /// The maximum timestamp as [`Duration::as_secs`] since the Unix epoch allowed by [`BOLT 11`].
605 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
608 pub static MAX_TIMESTAMP: u64 = lightning_invoice::MAX_TIMESTAMP;
609 /// Default expiry time as defined by [BOLT 11].
611 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
614 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
615 /// Default minimum final CLTV expiry as defined by [BOLT 11].
617 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
618 /// provided in [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
620 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
621 /// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
624 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA;
626 use lightning_invoice::Invoice as nativeInvoiceImport;
627 pub(crate) type nativeInvoice = nativeInvoiceImport;
629 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
631 /// There are three ways to construct an `Invoice`:
632 /// 1. using [`InvoiceBuilder`]
633 /// 2. using [`Invoice::from_signed`]
634 /// 3. using `str::parse::<Invoice>(&str)` (see [`Invoice::from_str`])
636 /// [`Invoice::from_str`]: crate::Invoice#impl-FromStr
640 /// A pointer to the opaque Rust object.
642 /// Nearly everywhere, inner must be non-null, however in places where
643 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
644 pub inner: *mut nativeInvoice,
645 /// Indicates that this is the only struct which contains the same pointer.
647 /// Rust functions which take ownership of an object provided via an argument require
648 /// this to be true and invalidate the object pointed to by inner.
652 impl Drop for Invoice {
654 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
655 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
659 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
661 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
663 /// Used only if an object of this type is returned as a trait impl by a method
664 pub(crate) extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
665 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInvoice) };
669 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoice {
670 unsafe { &*ObjOps::untweak_ptr(self.inner) }
672 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoice {
673 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
675 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
676 pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
677 assert!(self.is_owned);
678 let ret = ObjOps::untweak_ptr(self.inner);
679 self.inner = core::ptr::null_mut();
683 /// Checks if two Invoices contain equal inner contents.
684 /// This ignores pointers and is_owned flags and looks at the values in fields.
685 /// Two objects with NULL inner values will be considered "equal" here.
687 pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool {
688 if a.inner == b.inner { return true; }
689 if a.inner.is_null() || b.inner.is_null() { return false; }
690 if a.get_native_ref() == b.get_native_ref() { true } else { false }
692 impl Clone for Invoice {
693 fn clone(&self) -> Self {
695 inner: if <*mut nativeInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
696 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
702 /// Used only if an object of this type is returned as a trait impl by a method
703 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
704 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
707 /// Creates a copy of the Invoice
708 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
711 /// Generates a non-cryptographic 64-bit hash of the Invoice.
713 pub extern "C" fn Invoice_hash(o: &Invoice) -> u64 {
714 if o.inner.is_null() { return 0; }
715 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
717 let mut hasher = core::hash::SipHasher::new();
718 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
719 core::hash::Hasher::finish(&hasher)
722 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
723 pub(crate) type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
725 /// Represents a signed [`RawInvoice`] with cached hash. The signature is not checked and may be
729 /// The hash has to be either from the deserialized invoice or from the serialized [`RawInvoice`].
732 pub struct SignedRawInvoice {
733 /// A pointer to the opaque Rust object.
735 /// Nearly everywhere, inner must be non-null, however in places where
736 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
737 pub inner: *mut nativeSignedRawInvoice,
738 /// Indicates that this is the only struct which contains the same pointer.
740 /// Rust functions which take ownership of an object provided via an argument require
741 /// this to be true and invalidate the object pointed to by inner.
745 impl Drop for SignedRawInvoice {
747 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
748 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
752 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
754 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
756 /// Used only if an object of this type is returned as a trait impl by a method
757 pub(crate) extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
758 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSignedRawInvoice) };
761 impl SignedRawInvoice {
762 pub(crate) fn get_native_ref(&self) -> &'static nativeSignedRawInvoice {
763 unsafe { &*ObjOps::untweak_ptr(self.inner) }
765 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSignedRawInvoice {
766 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
768 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
769 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
770 assert!(self.is_owned);
771 let ret = ObjOps::untweak_ptr(self.inner);
772 self.inner = core::ptr::null_mut();
776 /// Checks if two SignedRawInvoices contain equal inner contents.
777 /// This ignores pointers and is_owned flags and looks at the values in fields.
778 /// Two objects with NULL inner values will be considered "equal" here.
780 pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice) -> bool {
781 if a.inner == b.inner { return true; }
782 if a.inner.is_null() || b.inner.is_null() { return false; }
783 if a.get_native_ref() == b.get_native_ref() { true } else { false }
785 impl Clone for SignedRawInvoice {
786 fn clone(&self) -> Self {
788 inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
789 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
795 /// Used only if an object of this type is returned as a trait impl by a method
796 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
797 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
800 /// Creates a copy of the SignedRawInvoice
801 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
804 /// Generates a non-cryptographic 64-bit hash of the SignedRawInvoice.
806 pub extern "C" fn SignedRawInvoice_hash(o: &SignedRawInvoice) -> u64 {
807 if o.inner.is_null() { return 0; }
808 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
810 let mut hasher = core::hash::SipHasher::new();
811 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
812 core::hash::Hasher::finish(&hasher)
815 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
816 pub(crate) type nativeRawInvoice = nativeRawInvoiceImport;
818 /// Represents an syntactically correct [`Invoice`] for a payment on the lightning network,
819 /// but without the signature information.
820 /// Decoding and encoding should not lead to information loss but may lead to different hashes.
822 /// For methods without docs see the corresponding methods in [`Invoice`].
825 pub struct RawInvoice {
826 /// A pointer to the opaque Rust object.
828 /// Nearly everywhere, inner must be non-null, however in places where
829 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
830 pub inner: *mut nativeRawInvoice,
831 /// Indicates that this is the only struct which contains the same pointer.
833 /// Rust functions which take ownership of an object provided via an argument require
834 /// this to be true and invalidate the object pointed to by inner.
838 impl Drop for RawInvoice {
840 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
841 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
845 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
847 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
849 /// Used only if an object of this type is returned as a trait impl by a method
850 pub(crate) extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
851 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRawInvoice) };
855 pub(crate) fn get_native_ref(&self) -> &'static nativeRawInvoice {
856 unsafe { &*ObjOps::untweak_ptr(self.inner) }
858 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawInvoice {
859 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
861 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
862 pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
863 assert!(self.is_owned);
864 let ret = ObjOps::untweak_ptr(self.inner);
865 self.inner = core::ptr::null_mut();
871 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
872 let mut inner_val = &mut this_ptr.get_native_mut_ref().data;
873 crate::lightning_invoice::RawDataPart { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::RawDataPart<>) as *mut _) }, is_owned: false }
877 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
878 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.data = *unsafe { Box::from_raw(val.take_inner()) };
880 /// Checks if two RawInvoices contain equal inner contents.
881 /// This ignores pointers and is_owned flags and looks at the values in fields.
882 /// Two objects with NULL inner values will be considered "equal" here.
884 pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool {
885 if a.inner == b.inner { return true; }
886 if a.inner.is_null() || b.inner.is_null() { return false; }
887 if a.get_native_ref() == b.get_native_ref() { true } else { false }
889 impl Clone for RawInvoice {
890 fn clone(&self) -> Self {
892 inner: if <*mut nativeRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
893 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
899 /// Used only if an object of this type is returned as a trait impl by a method
900 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
901 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
904 /// Creates a copy of the RawInvoice
905 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
908 /// Generates a non-cryptographic 64-bit hash of the RawInvoice.
910 pub extern "C" fn RawInvoice_hash(o: &RawInvoice) -> u64 {
911 if o.inner.is_null() { return 0; }
912 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
914 let mut hasher = core::hash::SipHasher::new();
915 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
916 core::hash::Hasher::finish(&hasher)
919 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
920 pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
922 /// Data of the [`RawInvoice`] that is encoded in the data part
925 pub struct RawDataPart {
926 /// A pointer to the opaque Rust object.
928 /// Nearly everywhere, inner must be non-null, however in places where
929 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
930 pub inner: *mut nativeRawDataPart,
931 /// Indicates that this is the only struct which contains the same pointer.
933 /// Rust functions which take ownership of an object provided via an argument require
934 /// this to be true and invalidate the object pointed to by inner.
938 impl Drop for RawDataPart {
940 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
941 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
945 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
947 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
949 /// Used only if an object of this type is returned as a trait impl by a method
950 pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
951 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRawDataPart) };
955 pub(crate) fn get_native_ref(&self) -> &'static nativeRawDataPart {
956 unsafe { &*ObjOps::untweak_ptr(self.inner) }
958 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawDataPart {
959 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
961 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
962 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
963 assert!(self.is_owned);
964 let ret = ObjOps::untweak_ptr(self.inner);
965 self.inner = core::ptr::null_mut();
969 /// generation time of the invoice
971 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
972 let mut inner_val = &mut this_ptr.get_native_mut_ref().timestamp;
973 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::PositiveTimestamp<>) as *mut _) }, is_owned: false }
975 /// generation time of the invoice
977 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
978 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
980 /// Checks if two RawDataParts contain equal inner contents.
981 /// This ignores pointers and is_owned flags and looks at the values in fields.
982 /// Two objects with NULL inner values will be considered "equal" here.
984 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
985 if a.inner == b.inner { return true; }
986 if a.inner.is_null() || b.inner.is_null() { return false; }
987 if a.get_native_ref() == b.get_native_ref() { true } else { false }
989 impl Clone for RawDataPart {
990 fn clone(&self) -> Self {
992 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { core::ptr::null_mut() } else {
993 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
999 /// Used only if an object of this type is returned as a trait impl by a method
1000 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
1001 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
1004 /// Creates a copy of the RawDataPart
1005 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
1008 /// Generates a non-cryptographic 64-bit hash of the RawDataPart.
1010 pub extern "C" fn RawDataPart_hash(o: &RawDataPart) -> u64 {
1011 if o.inner.is_null() { return 0; }
1012 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1013 #[allow(deprecated)]
1014 let mut hasher = core::hash::SipHasher::new();
1015 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1016 core::hash::Hasher::finish(&hasher)
1019 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
1020 pub(crate) type nativePositiveTimestamp = nativePositiveTimestampImport;
1022 /// A timestamp that refers to a date after 1 January 1970.
1026 /// The Unix timestamp representing the stored time has to be positive and no greater than
1027 /// [`MAX_TIMESTAMP`].
1030 pub struct PositiveTimestamp {
1031 /// A pointer to the opaque Rust object.
1033 /// Nearly everywhere, inner must be non-null, however in places where
1034 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1035 pub inner: *mut nativePositiveTimestamp,
1036 /// Indicates that this is the only struct which contains the same pointer.
1038 /// Rust functions which take ownership of an object provided via an argument require
1039 /// this to be true and invalidate the object pointed to by inner.
1043 impl Drop for PositiveTimestamp {
1044 fn drop(&mut self) {
1045 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
1046 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1050 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
1052 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
1054 /// Used only if an object of this type is returned as a trait impl by a method
1055 pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
1056 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePositiveTimestamp) };
1059 impl PositiveTimestamp {
1060 pub(crate) fn get_native_ref(&self) -> &'static nativePositiveTimestamp {
1061 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1063 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePositiveTimestamp {
1064 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1066 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1067 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
1068 assert!(self.is_owned);
1069 let ret = ObjOps::untweak_ptr(self.inner);
1070 self.inner = core::ptr::null_mut();
1074 /// Checks if two PositiveTimestamps contain equal inner contents.
1075 /// This ignores pointers and is_owned flags and looks at the values in fields.
1076 /// Two objects with NULL inner values will be considered "equal" here.
1078 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
1079 if a.inner == b.inner { return true; }
1080 if a.inner.is_null() || b.inner.is_null() { return false; }
1081 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1083 impl Clone for PositiveTimestamp {
1084 fn clone(&self) -> Self {
1086 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { core::ptr::null_mut() } else {
1087 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1093 /// Used only if an object of this type is returned as a trait impl by a method
1094 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
1095 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
1098 /// Creates a copy of the PositiveTimestamp
1099 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
1102 /// Generates a non-cryptographic 64-bit hash of the PositiveTimestamp.
1104 pub extern "C" fn PositiveTimestamp_hash(o: &PositiveTimestamp) -> u64 {
1105 if o.inner.is_null() { return 0; }
1106 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1107 #[allow(deprecated)]
1108 let mut hasher = core::hash::SipHasher::new();
1109 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1110 core::hash::Hasher::finish(&hasher)
1112 /// SI prefixes for the human readable part
1126 use lightning_invoice::SiPrefix as SiPrefixImport;
1127 pub(crate) type nativeSiPrefix = SiPrefixImport;
1131 pub(crate) fn to_native(&self) -> nativeSiPrefix {
1133 SiPrefix::Milli => nativeSiPrefix::Milli,
1134 SiPrefix::Micro => nativeSiPrefix::Micro,
1135 SiPrefix::Nano => nativeSiPrefix::Nano,
1136 SiPrefix::Pico => nativeSiPrefix::Pico,
1140 pub(crate) fn into_native(self) -> nativeSiPrefix {
1142 SiPrefix::Milli => nativeSiPrefix::Milli,
1143 SiPrefix::Micro => nativeSiPrefix::Micro,
1144 SiPrefix::Nano => nativeSiPrefix::Nano,
1145 SiPrefix::Pico => nativeSiPrefix::Pico,
1149 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
1151 nativeSiPrefix::Milli => SiPrefix::Milli,
1152 nativeSiPrefix::Micro => SiPrefix::Micro,
1153 nativeSiPrefix::Nano => SiPrefix::Nano,
1154 nativeSiPrefix::Pico => SiPrefix::Pico,
1158 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
1160 nativeSiPrefix::Milli => SiPrefix::Milli,
1161 nativeSiPrefix::Micro => SiPrefix::Micro,
1162 nativeSiPrefix::Nano => SiPrefix::Nano,
1163 nativeSiPrefix::Pico => SiPrefix::Pico,
1167 /// Creates a copy of the SiPrefix
1169 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
1173 /// Utility method to constructs a new Milli-variant SiPrefix
1174 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
1177 /// Utility method to constructs a new Micro-variant SiPrefix
1178 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
1181 /// Utility method to constructs a new Nano-variant SiPrefix
1182 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
1185 /// Utility method to constructs a new Pico-variant SiPrefix
1186 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
1188 /// Checks if two SiPrefixs contain equal inner contents.
1189 /// This ignores pointers and is_owned flags and looks at the values in fields.
1191 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
1192 if &a.to_native() == &b.to_native() { true } else { false }
1194 /// Generates a non-cryptographic 64-bit hash of the SiPrefix.
1196 pub extern "C" fn SiPrefix_hash(o: &SiPrefix) -> u64 {
1197 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1198 #[allow(deprecated)]
1199 let mut hasher = core::hash::SipHasher::new();
1200 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1201 core::hash::Hasher::finish(&hasher)
1203 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
1204 /// This is effectively 10^12 * the prefix multiplier
1207 pub extern "C" fn SiPrefix_multiplier(this_arg: &crate::lightning_invoice::SiPrefix) -> u64 {
1208 let mut ret = this_arg.to_native().multiplier();
1212 /// Enum representing the crypto currencies (or networks) supported by this library
1228 use lightning_invoice::Currency as CurrencyImport;
1229 pub(crate) type nativeCurrency = CurrencyImport;
1233 pub(crate) fn to_native(&self) -> nativeCurrency {
1235 Currency::Bitcoin => nativeCurrency::Bitcoin,
1236 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1237 Currency::Regtest => nativeCurrency::Regtest,
1238 Currency::Simnet => nativeCurrency::Simnet,
1239 Currency::Signet => nativeCurrency::Signet,
1243 pub(crate) fn into_native(self) -> nativeCurrency {
1245 Currency::Bitcoin => nativeCurrency::Bitcoin,
1246 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1247 Currency::Regtest => nativeCurrency::Regtest,
1248 Currency::Simnet => nativeCurrency::Simnet,
1249 Currency::Signet => nativeCurrency::Signet,
1253 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
1255 nativeCurrency::Bitcoin => Currency::Bitcoin,
1256 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1257 nativeCurrency::Regtest => Currency::Regtest,
1258 nativeCurrency::Simnet => Currency::Simnet,
1259 nativeCurrency::Signet => Currency::Signet,
1263 pub(crate) fn native_into(native: nativeCurrency) -> Self {
1265 nativeCurrency::Bitcoin => Currency::Bitcoin,
1266 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1267 nativeCurrency::Regtest => Currency::Regtest,
1268 nativeCurrency::Simnet => Currency::Simnet,
1269 nativeCurrency::Signet => Currency::Signet,
1273 /// Creates a copy of the Currency
1275 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
1279 /// Utility method to constructs a new Bitcoin-variant Currency
1280 pub extern "C" fn Currency_bitcoin() -> Currency {
1283 /// Utility method to constructs a new BitcoinTestnet-variant Currency
1284 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
1285 Currency::BitcoinTestnet}
1287 /// Utility method to constructs a new Regtest-variant Currency
1288 pub extern "C" fn Currency_regtest() -> Currency {
1291 /// Utility method to constructs a new Simnet-variant Currency
1292 pub extern "C" fn Currency_simnet() -> Currency {
1295 /// Utility method to constructs a new Signet-variant Currency
1296 pub extern "C" fn Currency_signet() -> Currency {
1298 /// Generates a non-cryptographic 64-bit hash of the Currency.
1300 pub extern "C" fn Currency_hash(o: &Currency) -> u64 {
1301 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1302 #[allow(deprecated)]
1303 let mut hasher = core::hash::SipHasher::new();
1304 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1305 core::hash::Hasher::finish(&hasher)
1307 /// Checks if two Currencys contain equal inner contents.
1308 /// This ignores pointers and is_owned flags and looks at the values in fields.
1310 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
1311 if &a.to_native() == &b.to_native() { true } else { false }
1314 use lightning_invoice::Sha256 as nativeSha256Import;
1315 pub(crate) type nativeSha256 = nativeSha256Import;
1321 /// A pointer to the opaque Rust object.
1323 /// Nearly everywhere, inner must be non-null, however in places where
1324 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1325 pub inner: *mut nativeSha256,
1326 /// Indicates that this is the only struct which contains the same pointer.
1328 /// Rust functions which take ownership of an object provided via an argument require
1329 /// this to be true and invalidate the object pointed to by inner.
1333 impl Drop for Sha256 {
1334 fn drop(&mut self) {
1335 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
1336 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1340 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
1342 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
1344 /// Used only if an object of this type is returned as a trait impl by a method
1345 pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
1346 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSha256) };
1350 pub(crate) fn get_native_ref(&self) -> &'static nativeSha256 {
1351 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1353 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSha256 {
1354 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1356 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1357 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
1358 assert!(self.is_owned);
1359 let ret = ObjOps::untweak_ptr(self.inner);
1360 self.inner = core::ptr::null_mut();
1364 impl Clone for Sha256 {
1365 fn clone(&self) -> Self {
1367 inner: if <*mut nativeSha256>::is_null(self.inner) { core::ptr::null_mut() } else {
1368 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1374 /// Used only if an object of this type is returned as a trait impl by a method
1375 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
1376 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
1379 /// Creates a copy of the Sha256
1380 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
1383 /// Generates a non-cryptographic 64-bit hash of the Sha256.
1385 pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 {
1386 if o.inner.is_null() { return 0; }
1387 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1388 #[allow(deprecated)]
1389 let mut hasher = core::hash::SipHasher::new();
1390 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1391 core::hash::Hasher::finish(&hasher)
1393 /// Checks if two Sha256s contain equal inner contents.
1394 /// This ignores pointers and is_owned flags and looks at the values in fields.
1395 /// Two objects with NULL inner values will be considered "equal" here.
1397 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
1398 if a.inner == b.inner { return true; }
1399 if a.inner.is_null() || b.inner.is_null() { return false; }
1400 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1402 /// Constructs a new [`Sha256`] from the given bytes, which are assumed to be the output of a
1403 /// single sha256 hash.
1406 pub extern "C" fn Sha256_from_bytes(bytes: *const [u8; 32]) -> crate::lightning_invoice::Sha256 {
1407 let mut ret = lightning_invoice::Sha256::from_bytes(unsafe { &*bytes});
1408 crate::lightning_invoice::Sha256 { inner: ObjOps::heap_alloc(ret), is_owned: true }
1412 use lightning_invoice::Description as nativeDescriptionImport;
1413 pub(crate) type nativeDescription = nativeDescriptionImport;
1415 /// Description string
1418 /// The description can be at most 639 __bytes__ long
1421 pub struct Description {
1422 /// A pointer to the opaque Rust object.
1424 /// Nearly everywhere, inner must be non-null, however in places where
1425 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1426 pub inner: *mut nativeDescription,
1427 /// Indicates that this is the only struct which contains the same pointer.
1429 /// Rust functions which take ownership of an object provided via an argument require
1430 /// this to be true and invalidate the object pointed to by inner.
1434 impl Drop for Description {
1435 fn drop(&mut self) {
1436 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
1437 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1441 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
1443 pub extern "C" fn Description_free(this_obj: Description) { }
1445 /// Used only if an object of this type is returned as a trait impl by a method
1446 pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) {
1447 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDescription) };
1451 pub(crate) fn get_native_ref(&self) -> &'static nativeDescription {
1452 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1454 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDescription {
1455 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1457 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1458 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
1459 assert!(self.is_owned);
1460 let ret = ObjOps::untweak_ptr(self.inner);
1461 self.inner = core::ptr::null_mut();
1465 impl Clone for Description {
1466 fn clone(&self) -> Self {
1468 inner: if <*mut nativeDescription>::is_null(self.inner) { core::ptr::null_mut() } else {
1469 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1475 /// Used only if an object of this type is returned as a trait impl by a method
1476 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
1477 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
1480 /// Creates a copy of the Description
1481 pub extern "C" fn Description_clone(orig: &Description) -> Description {
1484 /// Generates a non-cryptographic 64-bit hash of the Description.
1486 pub extern "C" fn Description_hash(o: &Description) -> u64 {
1487 if o.inner.is_null() { return 0; }
1488 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1489 #[allow(deprecated)]
1490 let mut hasher = core::hash::SipHasher::new();
1491 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1492 core::hash::Hasher::finish(&hasher)
1494 /// Checks if two Descriptions contain equal inner contents.
1495 /// This ignores pointers and is_owned flags and looks at the values in fields.
1496 /// Two objects with NULL inner values will be considered "equal" here.
1498 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
1499 if a.inner == b.inner { return true; }
1500 if a.inner.is_null() || b.inner.is_null() { return false; }
1501 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1504 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
1505 pub(crate) type nativePayeePubKey = nativePayeePubKeyImport;
1507 /// Payee public key
1510 pub struct PayeePubKey {
1511 /// A pointer to the opaque Rust object.
1513 /// Nearly everywhere, inner must be non-null, however in places where
1514 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1515 pub inner: *mut nativePayeePubKey,
1516 /// Indicates that this is the only struct which contains the same pointer.
1518 /// Rust functions which take ownership of an object provided via an argument require
1519 /// this to be true and invalidate the object pointed to by inner.
1523 impl Drop for PayeePubKey {
1524 fn drop(&mut self) {
1525 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
1526 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1530 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
1532 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
1534 /// Used only if an object of this type is returned as a trait impl by a method
1535 pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
1536 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePayeePubKey) };
1540 pub(crate) fn get_native_ref(&self) -> &'static nativePayeePubKey {
1541 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1543 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayeePubKey {
1544 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1546 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1547 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
1548 assert!(self.is_owned);
1549 let ret = ObjOps::untweak_ptr(self.inner);
1550 self.inner = core::ptr::null_mut();
1555 pub extern "C" fn PayeePubKey_get_a(this_ptr: &PayeePubKey) -> crate::c_types::PublicKey {
1556 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1557 crate::c_types::PublicKey::from_rust(&inner_val)
1560 pub extern "C" fn PayeePubKey_set_a(this_ptr: &mut PayeePubKey, mut val: crate::c_types::PublicKey) {
1561 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
1563 /// Constructs a new PayeePubKey given each field
1566 pub extern "C" fn PayeePubKey_new(mut a_arg: crate::c_types::PublicKey) -> PayeePubKey {
1567 PayeePubKey { inner: ObjOps::heap_alloc(lightning_invoice::PayeePubKey (
1569 )), is_owned: true }
1571 impl Clone for PayeePubKey {
1572 fn clone(&self) -> Self {
1574 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { core::ptr::null_mut() } else {
1575 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1581 /// Used only if an object of this type is returned as a trait impl by a method
1582 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
1583 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
1586 /// Creates a copy of the PayeePubKey
1587 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
1590 /// Generates a non-cryptographic 64-bit hash of the PayeePubKey.
1592 pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 {
1593 if o.inner.is_null() { return 0; }
1594 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1595 #[allow(deprecated)]
1596 let mut hasher = core::hash::SipHasher::new();
1597 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1598 core::hash::Hasher::finish(&hasher)
1600 /// Checks if two PayeePubKeys contain equal inner contents.
1601 /// This ignores pointers and is_owned flags and looks at the values in fields.
1602 /// Two objects with NULL inner values will be considered "equal" here.
1604 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
1605 if a.inner == b.inner { return true; }
1606 if a.inner.is_null() || b.inner.is_null() { return false; }
1607 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1610 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
1611 pub(crate) type nativeExpiryTime = nativeExpiryTimeImport;
1613 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
1617 pub struct ExpiryTime {
1618 /// A pointer to the opaque Rust object.
1620 /// Nearly everywhere, inner must be non-null, however in places where
1621 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1622 pub inner: *mut nativeExpiryTime,
1623 /// Indicates that this is the only struct which contains the same pointer.
1625 /// Rust functions which take ownership of an object provided via an argument require
1626 /// this to be true and invalidate the object pointed to by inner.
1630 impl Drop for ExpiryTime {
1631 fn drop(&mut self) {
1632 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
1633 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1637 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
1639 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
1641 /// Used only if an object of this type is returned as a trait impl by a method
1642 pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
1643 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeExpiryTime) };
1647 pub(crate) fn get_native_ref(&self) -> &'static nativeExpiryTime {
1648 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1650 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpiryTime {
1651 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1653 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1654 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
1655 assert!(self.is_owned);
1656 let ret = ObjOps::untweak_ptr(self.inner);
1657 self.inner = core::ptr::null_mut();
1661 impl Clone for ExpiryTime {
1662 fn clone(&self) -> Self {
1664 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { core::ptr::null_mut() } else {
1665 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1671 /// Used only if an object of this type is returned as a trait impl by a method
1672 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1673 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1676 /// Creates a copy of the ExpiryTime
1677 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1680 /// Generates a non-cryptographic 64-bit hash of the ExpiryTime.
1682 pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 {
1683 if o.inner.is_null() { return 0; }
1684 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1685 #[allow(deprecated)]
1686 let mut hasher = core::hash::SipHasher::new();
1687 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1688 core::hash::Hasher::finish(&hasher)
1690 /// Checks if two ExpiryTimes contain equal inner contents.
1691 /// This ignores pointers and is_owned flags and looks at the values in fields.
1692 /// Two objects with NULL inner values will be considered "equal" here.
1694 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1695 if a.inner == b.inner { return true; }
1696 if a.inner.is_null() || b.inner.is_null() { return false; }
1697 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1700 use lightning_invoice::MinFinalCltvExpiryDelta as nativeMinFinalCltvExpiryDeltaImport;
1701 pub(crate) type nativeMinFinalCltvExpiryDelta = nativeMinFinalCltvExpiryDeltaImport;
1703 /// `min_final_cltv_expiry_delta` to use for the last HTLC in the route
1706 pub struct MinFinalCltvExpiryDelta {
1707 /// A pointer to the opaque Rust object.
1709 /// Nearly everywhere, inner must be non-null, however in places where
1710 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1711 pub inner: *mut nativeMinFinalCltvExpiryDelta,
1712 /// Indicates that this is the only struct which contains the same pointer.
1714 /// Rust functions which take ownership of an object provided via an argument require
1715 /// this to be true and invalidate the object pointed to by inner.
1719 impl Drop for MinFinalCltvExpiryDelta {
1720 fn drop(&mut self) {
1721 if self.is_owned && !<*mut nativeMinFinalCltvExpiryDelta>::is_null(self.inner) {
1722 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1726 /// Frees any resources used by the MinFinalCltvExpiryDelta, if is_owned is set and inner is non-NULL.
1728 pub extern "C" fn MinFinalCltvExpiryDelta_free(this_obj: MinFinalCltvExpiryDelta) { }
1730 /// Used only if an object of this type is returned as a trait impl by a method
1731 pub(crate) extern "C" fn MinFinalCltvExpiryDelta_free_void(this_ptr: *mut c_void) {
1732 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiryDelta) };
1735 impl MinFinalCltvExpiryDelta {
1736 pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiryDelta {
1737 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1739 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiryDelta {
1740 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1742 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1743 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiryDelta {
1744 assert!(self.is_owned);
1745 let ret = ObjOps::untweak_ptr(self.inner);
1746 self.inner = core::ptr::null_mut();
1751 pub extern "C" fn MinFinalCltvExpiryDelta_get_a(this_ptr: &MinFinalCltvExpiryDelta) -> u64 {
1752 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1756 pub extern "C" fn MinFinalCltvExpiryDelta_set_a(this_ptr: &mut MinFinalCltvExpiryDelta, mut val: u64) {
1757 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val;
1759 /// Constructs a new MinFinalCltvExpiryDelta given each field
1762 pub extern "C" fn MinFinalCltvExpiryDelta_new(mut a_arg: u64) -> MinFinalCltvExpiryDelta {
1763 MinFinalCltvExpiryDelta { inner: ObjOps::heap_alloc(lightning_invoice::MinFinalCltvExpiryDelta (
1765 )), is_owned: true }
1767 impl Clone for MinFinalCltvExpiryDelta {
1768 fn clone(&self) -> Self {
1770 inner: if <*mut nativeMinFinalCltvExpiryDelta>::is_null(self.inner) { core::ptr::null_mut() } else {
1771 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1777 /// Used only if an object of this type is returned as a trait impl by a method
1778 pub(crate) extern "C" fn MinFinalCltvExpiryDelta_clone_void(this_ptr: *const c_void) -> *mut c_void {
1779 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiryDelta)).clone() })) as *mut c_void
1782 /// Creates a copy of the MinFinalCltvExpiryDelta
1783 pub extern "C" fn MinFinalCltvExpiryDelta_clone(orig: &MinFinalCltvExpiryDelta) -> MinFinalCltvExpiryDelta {
1786 /// Generates a non-cryptographic 64-bit hash of the MinFinalCltvExpiryDelta.
1788 pub extern "C" fn MinFinalCltvExpiryDelta_hash(o: &MinFinalCltvExpiryDelta) -> u64 {
1789 if o.inner.is_null() { return 0; }
1790 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1791 #[allow(deprecated)]
1792 let mut hasher = core::hash::SipHasher::new();
1793 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1794 core::hash::Hasher::finish(&hasher)
1796 /// Checks if two MinFinalCltvExpiryDeltas contain equal inner contents.
1797 /// This ignores pointers and is_owned flags and looks at the values in fields.
1798 /// Two objects with NULL inner values will be considered "equal" here.
1800 pub extern "C" fn MinFinalCltvExpiryDelta_eq(a: &MinFinalCltvExpiryDelta, b: &MinFinalCltvExpiryDelta) -> bool {
1801 if a.inner == b.inner { return true; }
1802 if a.inner.is_null() || b.inner.is_null() { return false; }
1803 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1805 /// Fallback address in case no LN payment is possible
1811 version: crate::c_types::WitnessVersion,
1812 program: crate::c_types::derived::CVec_u8Z,
1815 crate::c_types::TwentyBytes),
1817 crate::c_types::TwentyBytes),
1819 use lightning_invoice::Fallback as FallbackImport;
1820 pub(crate) type nativeFallback = FallbackImport;
1824 pub(crate) fn to_native(&self) -> nativeFallback {
1826 Fallback::SegWitProgram {ref version, ref program, } => {
1827 let mut version_nonref = Clone::clone(version);
1828 let mut program_nonref = Clone::clone(program);
1829 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1830 nativeFallback::SegWitProgram {
1831 version: version_nonref.into(),
1832 program: local_program_nonref,
1835 Fallback::PubKeyHash (ref a, ) => {
1836 let mut a_nonref = Clone::clone(a);
1837 nativeFallback::PubKeyHash (
1838 bitcoin::hash_types::PubkeyHash::from_hash(bitcoin::hashes::Hash::from_inner(a_nonref.data)),
1841 Fallback::ScriptHash (ref a, ) => {
1842 let mut a_nonref = Clone::clone(a);
1843 nativeFallback::ScriptHash (
1844 bitcoin::hash_types::ScriptHash::from_hash(bitcoin::hashes::Hash::from_inner(a_nonref.data)),
1850 pub(crate) fn into_native(self) -> nativeFallback {
1852 Fallback::SegWitProgram {mut version, mut program, } => {
1853 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1854 nativeFallback::SegWitProgram {
1855 version: version.into(),
1856 program: local_program,
1859 Fallback::PubKeyHash (mut a, ) => {
1860 nativeFallback::PubKeyHash (
1861 bitcoin::hash_types::PubkeyHash::from_hash(bitcoin::hashes::Hash::from_inner(a.data)),
1864 Fallback::ScriptHash (mut a, ) => {
1865 nativeFallback::ScriptHash (
1866 bitcoin::hash_types::ScriptHash::from_hash(bitcoin::hashes::Hash::from_inner(a.data)),
1872 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1874 nativeFallback::SegWitProgram {ref version, ref program, } => {
1875 let mut version_nonref = Clone::clone(version);
1876 let mut program_nonref = Clone::clone(program);
1877 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1878 Fallback::SegWitProgram {
1879 version: version_nonref.into(),
1880 program: local_program_nonref.into(),
1883 nativeFallback::PubKeyHash (ref a, ) => {
1884 let mut a_nonref = Clone::clone(a);
1885 Fallback::PubKeyHash (
1886 crate::c_types::TwentyBytes { data: a_nonref.as_hash().into_inner() },
1889 nativeFallback::ScriptHash (ref a, ) => {
1890 let mut a_nonref = Clone::clone(a);
1891 Fallback::ScriptHash (
1892 crate::c_types::TwentyBytes { data: a_nonref.as_hash().into_inner() },
1898 pub(crate) fn native_into(native: nativeFallback) -> Self {
1900 nativeFallback::SegWitProgram {mut version, mut program, } => {
1901 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1902 Fallback::SegWitProgram {
1903 version: version.into(),
1904 program: local_program.into(),
1907 nativeFallback::PubKeyHash (mut a, ) => {
1908 Fallback::PubKeyHash (
1909 crate::c_types::TwentyBytes { data: a.as_hash().into_inner() },
1912 nativeFallback::ScriptHash (mut a, ) => {
1913 Fallback::ScriptHash (
1914 crate::c_types::TwentyBytes { data: a.as_hash().into_inner() },
1920 /// Frees any resources used by the Fallback
1922 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1923 /// Creates a copy of the Fallback
1925 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1929 /// Utility method to constructs a new SegWitProgram-variant Fallback
1930 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::WitnessVersion, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
1931 Fallback::SegWitProgram {
1937 /// Utility method to constructs a new PubKeyHash-variant Fallback
1938 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1939 Fallback::PubKeyHash(a, )
1942 /// Utility method to constructs a new ScriptHash-variant Fallback
1943 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1944 Fallback::ScriptHash(a, )
1946 /// Generates a non-cryptographic 64-bit hash of the Fallback.
1948 pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 {
1949 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1950 #[allow(deprecated)]
1951 let mut hasher = core::hash::SipHasher::new();
1952 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1953 core::hash::Hasher::finish(&hasher)
1955 /// Checks if two Fallbacks contain equal inner contents.
1956 /// This ignores pointers and is_owned flags and looks at the values in fields.
1958 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1959 if &a.to_native() == &b.to_native() { true } else { false }
1962 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1963 pub(crate) type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1965 /// Recoverable signature
1968 pub struct InvoiceSignature {
1969 /// A pointer to the opaque Rust object.
1971 /// Nearly everywhere, inner must be non-null, however in places where
1972 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1973 pub inner: *mut nativeInvoiceSignature,
1974 /// Indicates that this is the only struct which contains the same pointer.
1976 /// Rust functions which take ownership of an object provided via an argument require
1977 /// this to be true and invalidate the object pointed to by inner.
1981 impl Drop for InvoiceSignature {
1982 fn drop(&mut self) {
1983 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1984 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1988 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1990 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1992 /// Used only if an object of this type is returned as a trait impl by a method
1993 pub(crate) extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1994 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInvoiceSignature) };
1997 impl InvoiceSignature {
1998 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceSignature {
1999 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2001 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceSignature {
2002 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2004 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2005 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
2006 assert!(self.is_owned);
2007 let ret = ObjOps::untweak_ptr(self.inner);
2008 self.inner = core::ptr::null_mut();
2012 impl Clone for InvoiceSignature {
2013 fn clone(&self) -> Self {
2015 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { core::ptr::null_mut() } else {
2016 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2022 /// Used only if an object of this type is returned as a trait impl by a method
2023 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
2024 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
2027 /// Creates a copy of the InvoiceSignature
2028 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
2031 /// Generates a non-cryptographic 64-bit hash of the InvoiceSignature.
2033 pub extern "C" fn InvoiceSignature_hash(o: &InvoiceSignature) -> u64 {
2034 if o.inner.is_null() { return 0; }
2035 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2036 #[allow(deprecated)]
2037 let mut hasher = core::hash::SipHasher::new();
2038 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2039 core::hash::Hasher::finish(&hasher)
2041 /// Checks if two InvoiceSignatures contain equal inner contents.
2042 /// This ignores pointers and is_owned flags and looks at the values in fields.
2043 /// Two objects with NULL inner values will be considered "equal" here.
2045 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
2046 if a.inner == b.inner { return true; }
2047 if a.inner.is_null() || b.inner.is_null() { return false; }
2048 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2051 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
2052 pub(crate) type nativePrivateRoute = nativePrivateRouteImport;
2054 /// Private routing information
2057 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
2061 pub struct PrivateRoute {
2062 /// A pointer to the opaque Rust object.
2064 /// Nearly everywhere, inner must be non-null, however in places where
2065 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2066 pub inner: *mut nativePrivateRoute,
2067 /// Indicates that this is the only struct which contains the same pointer.
2069 /// Rust functions which take ownership of an object provided via an argument require
2070 /// this to be true and invalidate the object pointed to by inner.
2074 impl Drop for PrivateRoute {
2075 fn drop(&mut self) {
2076 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
2077 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2081 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
2083 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
2085 /// Used only if an object of this type is returned as a trait impl by a method
2086 pub(crate) extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
2087 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePrivateRoute) };
2091 pub(crate) fn get_native_ref(&self) -> &'static nativePrivateRoute {
2092 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2094 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateRoute {
2095 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2097 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2098 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
2099 assert!(self.is_owned);
2100 let ret = ObjOps::untweak_ptr(self.inner);
2101 self.inner = core::ptr::null_mut();
2105 impl Clone for PrivateRoute {
2106 fn clone(&self) -> Self {
2108 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
2109 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2115 /// Used only if an object of this type is returned as a trait impl by a method
2116 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
2117 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
2120 /// Creates a copy of the PrivateRoute
2121 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
2124 /// Generates a non-cryptographic 64-bit hash of the PrivateRoute.
2126 pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 {
2127 if o.inner.is_null() { return 0; }
2128 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2129 #[allow(deprecated)]
2130 let mut hasher = core::hash::SipHasher::new();
2131 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2132 core::hash::Hasher::finish(&hasher)
2134 /// Checks if two PrivateRoutes contain equal inner contents.
2135 /// This ignores pointers and is_owned flags and looks at the values in fields.
2136 /// Two objects with NULL inner values will be considered "equal" here.
2138 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
2139 if a.inner == b.inner { return true; }
2140 if a.inner.is_null() || b.inner.is_null() { return false; }
2141 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2143 /// Disassembles the `SignedRawInvoice` into its three parts:
2145 /// 2. hash of the raw invoice
2149 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
2150 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
2151 let (mut orig_ret_0, mut orig_ret_1, mut orig_ret_2) = ret; let mut local_ret = (crate::lightning_invoice::RawInvoice { inner: ObjOps::heap_alloc(orig_ret_0), is_owned: true }, crate::c_types::ThirtyTwoBytes { data: orig_ret_1 }, crate::lightning_invoice::InvoiceSignature { inner: ObjOps::heap_alloc(orig_ret_2), is_owned: true }).into();
2155 /// The [`RawInvoice`] which was signed.
2158 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
2159 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice();
2160 crate::lightning_invoice::RawInvoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawInvoice<>) as *mut _) }, is_owned: false }
2163 /// The hash of the [`RawInvoice`] that was signed.
2166 pub extern "C" fn SignedRawInvoice_signable_hash(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> *const [u8; 32] {
2167 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2171 /// Signature for the invoice.
2174 pub extern "C" fn SignedRawInvoice_signature(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
2175 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
2176 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::InvoiceSignature<>) as *mut _) }, is_owned: false }
2179 /// Recovers the public key used for signing the invoice from the recoverable signature.
2182 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
2183 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2184 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PayeePubKey { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
2188 /// Checks if the signature is valid for the included payee public key or if none exists if it's
2189 /// valid for the recovered signature (which should always be true?).
2192 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> bool {
2193 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2197 /// Calculate the hash of the encoded `RawInvoice` which should be signed.
2200 pub extern "C" fn RawInvoice_signable_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes {
2201 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2202 crate::c_types::ThirtyTwoBytes { data: ret }
2206 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2209 pub extern "C" fn RawInvoice_payment_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Sha256 {
2210 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2211 let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Sha256<>) as *mut _ }, is_owned: false };
2216 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2219 pub extern "C" fn RawInvoice_description(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Description {
2220 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
2221 let mut local_ret = crate::lightning_invoice::Description { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Description<>) as *mut _ }, is_owned: false };
2226 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2229 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::PayeePubKey {
2230 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2231 let mut local_ret = crate::lightning_invoice::PayeePubKey { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::PayeePubKey<>) as *mut _ }, is_owned: false };
2236 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2239 pub extern "C" fn RawInvoice_description_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Sha256 {
2240 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash();
2241 let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Sha256<>) as *mut _ }, is_owned: false };
2246 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2249 pub extern "C" fn RawInvoice_expiry_time(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::ExpiryTime {
2250 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2251 let mut local_ret = crate::lightning_invoice::ExpiryTime { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::ExpiryTime<>) as *mut _ }, is_owned: false };
2256 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2259 pub extern "C" fn RawInvoice_min_final_cltv_expiry_delta(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiryDelta {
2260 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry_delta();
2261 let mut local_ret = crate::lightning_invoice::MinFinalCltvExpiryDelta { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::MinFinalCltvExpiryDelta<>) as *mut _ }, is_owned: false };
2266 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2269 pub extern "C" fn RawInvoice_payment_secret(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes {
2270 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2271 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
2277 pub extern "C" fn RawInvoice_payment_metadata(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
2278 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_metadata();
2279 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { let mut local_ret_0 = Vec::new(); for mut item in (*ret.as_ref().unwrap()).clone().drain(..) { local_ret_0.push( { item }); }; local_ret_0.into() }) };
2284 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2287 pub extern "C" fn RawInvoice_features(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
2288 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2289 let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::InvoiceFeatures<>) as *mut _ }, is_owned: false };
2295 pub extern "C" fn RawInvoice_private_routes(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2296 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2297 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning_invoice::PrivateRoute<>) as *mut _) }, is_owned: false } }); };
2303 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::derived::COption_u64Z {
2304 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
2305 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap() }) };
2311 pub extern "C" fn RawInvoice_currency(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Currency {
2312 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2313 crate::lightning_invoice::Currency::native_into(ret)
2316 /// Creates a `PositiveTimestamp` from a Unix timestamp in the range `0..=MAX_TIMESTAMP`.
2318 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2321 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2322 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
2323 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
2327 /// Creates a `PositiveTimestamp` from a [`SystemTime`] with a corresponding Unix timestamp in
2328 /// the range `0..=MAX_TIMESTAMP`.
2330 /// Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
2332 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2335 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2336 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
2337 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
2341 /// Creates a `PositiveTimestamp` from a [`Duration`] since the Unix epoch in the range
2342 /// `0..=MAX_TIMESTAMP`.
2344 /// Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
2346 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2349 pub extern "C" fn PositiveTimestamp_from_duration_since_epoch(mut duration: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2350 let mut ret = lightning_invoice::PositiveTimestamp::from_duration_since_epoch(core::time::Duration::from_secs(duration));
2351 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
2355 /// Returns the Unix timestamp representing the stored time
2358 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2359 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_unix_timestamp();
2363 /// Returns the duration of the stored time since the Unix epoch
2366 pub extern "C" fn PositiveTimestamp_as_duration_since_epoch(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2367 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration_since_epoch();
2371 /// Returns the [`SystemTime`] representing the stored time
2374 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2375 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_time();
2376 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2379 /// The hash of the [`RawInvoice`] that was signed.
2382 pub extern "C" fn Invoice_signable_hash(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::ThirtyTwoBytes {
2383 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2384 crate::c_types::ThirtyTwoBytes { data: ret }
2387 /// Transform the `Invoice` into it's unchecked version
2390 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: crate::lightning_invoice::Invoice) -> crate::lightning_invoice::SignedRawInvoice {
2391 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
2392 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(ret), is_owned: true }
2395 /// Check that the invoice is signed correctly and that key recovery works
2398 pub extern "C" fn Invoice_check_signature(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
2399 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2400 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::SemanticError::native_into(e) }).into() };
2404 /// Constructs an `Invoice` from a [`SignedRawInvoice`] by checking all its invariants.
2406 /// use lightning_invoice::*;
2408 /// let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
2409 /// h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
2410 /// 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
2411 /// h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
2412 /// j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
2413 /// ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
2414 /// guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
2415 /// ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
2416 /// p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
2417 /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
2418 /// j5r6drg6k6zcqj0fcwg\";
2420 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
2422 /// assert!(Invoice::from_signed(signed).is_ok());
2426 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
2427 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
2428 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::Invoice { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::SemanticError::native_into(e) }).into() };
2432 /// Returns the `Invoice`'s timestamp (should equal its creation time)
2435 pub extern "C" fn Invoice_timestamp(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2436 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timestamp();
2437 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2440 /// Returns the `Invoice`'s timestamp as a duration since the Unix epoch
2443 pub extern "C" fn Invoice_duration_since_epoch(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2444 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_since_epoch();
2448 /// Returns the hash to which we will receive the preimage on completion of the payment
2451 pub extern "C" fn Invoice_payment_hash(this_arg: &crate::lightning_invoice::Invoice) -> *const [u8; 32] {
2452 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2456 /// Get the payee's public key if one was included in the invoice
2458 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2461 pub extern "C" fn Invoice_payee_pub_key(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::PublicKey {
2462 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2463 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
2467 /// Get the payment secret if one was included in the invoice
2470 pub extern "C" fn Invoice_payment_secret(this_arg: &crate::lightning_invoice::Invoice) -> *const [u8; 32] {
2471 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2475 /// Get the payment metadata blob if one was included in the invoice
2478 pub extern "C" fn Invoice_payment_metadata(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
2479 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_metadata();
2480 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { let mut local_ret_0 = Vec::new(); for mut item in (*ret.as_ref().unwrap()).clone().drain(..) { local_ret_0.push( { item }); }; local_ret_0.into() }) };
2484 /// Get the invoice features if they were included in the invoice
2486 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2489 pub extern "C" fn Invoice_features(this_arg: &crate::lightning_invoice::Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
2490 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2491 let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::InvoiceFeatures<>) as *mut _ }, is_owned: false };
2495 /// Recover the payee's public key (only to be used if none was included in the invoice)
2498 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::PublicKey {
2499 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2500 crate::c_types::PublicKey::from_rust(&ret)
2503 /// Returns the Duration since the Unix epoch at which the invoice expires.
2504 /// Returning None if overflow occurred.
2507 pub extern "C" fn Invoice_expires_at(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::COption_DurationZ {
2508 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expires_at();
2509 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_DurationZ::None } else { crate::c_types::derived::COption_DurationZ::Some( { ret.unwrap().as_secs() }) };
2513 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
2516 pub extern "C" fn Invoice_expiry_time(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2517 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2521 /// Returns whether the invoice has expired.
2524 pub extern "C" fn Invoice_is_expired(this_arg: &crate::lightning_invoice::Invoice) -> bool {
2525 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
2529 /// Returns the Duration remaining until the invoice expires.
2532 pub extern "C" fn Invoice_duration_until_expiry(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2533 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_until_expiry();
2537 /// Returns the Duration remaining until the invoice expires given the current time.
2538 /// `time` is the timestamp as a duration since the Unix epoch.
2541 pub extern "C" fn Invoice_expiration_remaining_from_epoch(this_arg: &crate::lightning_invoice::Invoice, mut time: u64) -> u64 {
2542 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiration_remaining_from_epoch(core::time::Duration::from_secs(time));
2546 /// Returns whether the expiry time would pass at the given point in time.
2547 /// `at_time` is the timestamp as a duration since the Unix epoch.
2550 pub extern "C" fn Invoice_would_expire(this_arg: &crate::lightning_invoice::Invoice, mut at_time: u64) -> bool {
2551 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.would_expire(core::time::Duration::from_secs(at_time));
2555 /// Returns the invoice's `min_final_cltv_expiry_delta` time, if present, otherwise
2556 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA`].
2559 pub extern "C" fn Invoice_min_final_cltv_expiry_delta(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2560 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry_delta();
2564 /// Returns a list of all fallback addresses as [`Address`]es
2567 pub extern "C" fn Invoice_fallback_addresses(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CVec_AddressZ {
2568 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fallback_addresses();
2569 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { alloc::string::ToString::to_string(&item).into() }); };
2573 /// Returns a list of all routes included in the invoice
2576 pub extern "C" fn Invoice_private_routes(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2577 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2578 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning_invoice::PrivateRoute<>) as *mut _) }, is_owned: false } }); };
2582 /// Returns a list of all routes included in the invoice as the underlying hints
2585 pub extern "C" fn Invoice_route_hints(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
2586 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints();
2587 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
2591 /// Returns the currency for which the invoice was issued
2594 pub extern "C" fn Invoice_currency(this_arg: &crate::lightning_invoice::Invoice) -> crate::lightning_invoice::Currency {
2595 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2596 crate::lightning_invoice::Currency::native_into(ret)
2599 /// Returns the amount if specified in the invoice as millisatoshis.
2602 pub extern "C" fn Invoice_amount_milli_satoshis(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::COption_u64Z {
2603 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_milli_satoshis();
2604 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap() }) };
2608 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
2609 /// returns [`CreationError::DescriptionTooLong`] otherwise
2611 /// Please note that single characters may use more than one byte due to UTF8 encoding.
2614 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
2615 let mut ret = lightning_invoice::Description::new(description.into_string());
2616 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::Description { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
2620 /// Returns the underlying description [`String`]
2623 pub extern "C" fn Description_into_inner(mut this_arg: crate::lightning_invoice::Description) -> crate::c_types::Str {
2624 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2628 /// Construct an `ExpiryTime` from seconds.
2631 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::lightning_invoice::ExpiryTime {
2632 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
2633 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2636 /// Construct an `ExpiryTime` from a [`Duration`], dropping the sub-second part.
2639 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::lightning_invoice::ExpiryTime {
2640 let mut ret = lightning_invoice::ExpiryTime::from_duration(core::time::Duration::from_secs(duration));
2641 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2644 /// Returns the expiry time in seconds
2647 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2648 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_seconds();
2652 /// Returns a reference to the underlying [`Duration`] (=expiry time)
2655 pub extern "C" fn ExpiryTime_as_duration(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2656 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration();
2660 /// Creates a new (partial) route from a list of hops
2663 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
2664 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
2665 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PrivateRoute { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
2669 /// Returns the underlying list of hops
2672 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: crate::lightning_invoice::PrivateRoute) -> crate::lightning::routing::router::RouteHint {
2673 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2674 crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true }
2677 /// Errors that may occur when constructing a new [`RawInvoice`] or [`Invoice`]
2681 pub enum CreationError {
2682 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new`])
2684 /// The specified route has too many hops and can't be encoded
2686 /// The Unix timestamp of the supplied date is less than zero or greater than 35-bits
2687 TimestampOutOfBounds,
2688 /// The supplied millisatoshi amount was greater than the total bitcoin supply.
2690 /// Route hints were required for this invoice and were missing. Applies to
2691 /// [phantom invoices].
2693 /// [phantom invoices]: crate::utils::create_phantom_invoice
2695 /// The provided `min_final_cltv_expiry_delta` was less than [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
2697 /// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
2698 MinFinalCltvExpiryDeltaTooShort,
2700 use lightning_invoice::CreationError as CreationErrorImport;
2701 pub(crate) type nativeCreationError = CreationErrorImport;
2703 impl CreationError {
2705 pub(crate) fn to_native(&self) -> nativeCreationError {
2707 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2708 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2709 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2710 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2711 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2712 CreationError::MinFinalCltvExpiryDeltaTooShort => nativeCreationError::MinFinalCltvExpiryDeltaTooShort,
2716 pub(crate) fn into_native(self) -> nativeCreationError {
2718 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2719 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2720 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2721 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2722 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2723 CreationError::MinFinalCltvExpiryDeltaTooShort => nativeCreationError::MinFinalCltvExpiryDeltaTooShort,
2727 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
2729 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2730 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2731 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2732 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2733 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2734 nativeCreationError::MinFinalCltvExpiryDeltaTooShort => CreationError::MinFinalCltvExpiryDeltaTooShort,
2738 pub(crate) fn native_into(native: nativeCreationError) -> Self {
2740 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2741 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2742 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2743 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2744 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2745 nativeCreationError::MinFinalCltvExpiryDeltaTooShort => CreationError::MinFinalCltvExpiryDeltaTooShort,
2749 /// Creates a copy of the CreationError
2751 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
2755 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
2756 pub extern "C" fn CreationError_description_too_long() -> CreationError {
2757 CreationError::DescriptionTooLong}
2759 /// Utility method to constructs a new RouteTooLong-variant CreationError
2760 pub extern "C" fn CreationError_route_too_long() -> CreationError {
2761 CreationError::RouteTooLong}
2763 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
2764 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
2765 CreationError::TimestampOutOfBounds}
2767 /// Utility method to constructs a new InvalidAmount-variant CreationError
2768 pub extern "C" fn CreationError_invalid_amount() -> CreationError {
2769 CreationError::InvalidAmount}
2771 /// Utility method to constructs a new MissingRouteHints-variant CreationError
2772 pub extern "C" fn CreationError_missing_route_hints() -> CreationError {
2773 CreationError::MissingRouteHints}
2775 /// Utility method to constructs a new MinFinalCltvExpiryDeltaTooShort-variant CreationError
2776 pub extern "C" fn CreationError_min_final_cltv_expiry_delta_too_short() -> CreationError {
2777 CreationError::MinFinalCltvExpiryDeltaTooShort}
2778 /// Checks if two CreationErrors contain equal inner contents.
2779 /// This ignores pointers and is_owned flags and looks at the values in fields.
2781 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
2782 if &a.to_native() == &b.to_native() { true } else { false }
2785 /// Get the string representation of a CreationError object
2786 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
2787 alloc::format!("{}", &o.to_native()).into()
2789 /// Errors that may occur when converting a [`RawInvoice`] to an [`Invoice`]. They relate to the
2790 /// requirements sections in BOLT #11
2794 pub enum SemanticError {
2795 /// The invoice is missing the mandatory payment hash
2797 /// The invoice has multiple payment hashes which isn't allowed
2798 MultiplePaymentHashes,
2799 /// No description or description hash are part of the invoice
2801 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
2802 MultipleDescriptions,
2803 /// The invoice is missing the mandatory payment secret, which all modern lightning nodes
2806 /// The invoice contains multiple payment secrets
2807 MultiplePaymentSecrets,
2808 /// The invoice's features are invalid
2810 /// The recovery id doesn't fit the signature/pub key
2812 /// The invoice's signature is invalid
2814 /// The invoice's amount was not a whole number of millisatoshis
2817 use lightning_invoice::SemanticError as SemanticErrorImport;
2818 pub(crate) type nativeSemanticError = SemanticErrorImport;
2820 impl SemanticError {
2822 pub(crate) fn to_native(&self) -> nativeSemanticError {
2824 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2825 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2826 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2827 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2828 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2829 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2830 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2831 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2832 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2833 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2837 pub(crate) fn into_native(self) -> nativeSemanticError {
2839 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2840 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2841 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2842 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2843 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2844 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2845 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2846 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2847 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2848 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2852 pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
2854 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2855 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2856 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2857 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2858 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2859 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2860 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2861 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2862 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2863 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2867 pub(crate) fn native_into(native: nativeSemanticError) -> Self {
2869 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2870 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2871 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2872 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2873 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2874 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2875 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2876 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2877 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2878 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2882 /// Creates a copy of the SemanticError
2884 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
2888 /// Utility method to constructs a new NoPaymentHash-variant SemanticError
2889 pub extern "C" fn SemanticError_no_payment_hash() -> SemanticError {
2890 SemanticError::NoPaymentHash}
2892 /// Utility method to constructs a new MultiplePaymentHashes-variant SemanticError
2893 pub extern "C" fn SemanticError_multiple_payment_hashes() -> SemanticError {
2894 SemanticError::MultiplePaymentHashes}
2896 /// Utility method to constructs a new NoDescription-variant SemanticError
2897 pub extern "C" fn SemanticError_no_description() -> SemanticError {
2898 SemanticError::NoDescription}
2900 /// Utility method to constructs a new MultipleDescriptions-variant SemanticError
2901 pub extern "C" fn SemanticError_multiple_descriptions() -> SemanticError {
2902 SemanticError::MultipleDescriptions}
2904 /// Utility method to constructs a new NoPaymentSecret-variant SemanticError
2905 pub extern "C" fn SemanticError_no_payment_secret() -> SemanticError {
2906 SemanticError::NoPaymentSecret}
2908 /// Utility method to constructs a new MultiplePaymentSecrets-variant SemanticError
2909 pub extern "C" fn SemanticError_multiple_payment_secrets() -> SemanticError {
2910 SemanticError::MultiplePaymentSecrets}
2912 /// Utility method to constructs a new InvalidFeatures-variant SemanticError
2913 pub extern "C" fn SemanticError_invalid_features() -> SemanticError {
2914 SemanticError::InvalidFeatures}
2916 /// Utility method to constructs a new InvalidRecoveryId-variant SemanticError
2917 pub extern "C" fn SemanticError_invalid_recovery_id() -> SemanticError {
2918 SemanticError::InvalidRecoveryId}
2920 /// Utility method to constructs a new InvalidSignature-variant SemanticError
2921 pub extern "C" fn SemanticError_invalid_signature() -> SemanticError {
2922 SemanticError::InvalidSignature}
2924 /// Utility method to constructs a new ImpreciseAmount-variant SemanticError
2925 pub extern "C" fn SemanticError_imprecise_amount() -> SemanticError {
2926 SemanticError::ImpreciseAmount}
2927 /// Checks if two SemanticErrors contain equal inner contents.
2928 /// This ignores pointers and is_owned flags and looks at the values in fields.
2930 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
2931 if &a.to_native() == &b.to_native() { true } else { false }
2934 /// Get the string representation of a SemanticError object
2935 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
2936 alloc::format!("{}", &o.to_native()).into()
2938 /// When signing using a fallible method either an user-supplied `SignError` or a [`CreationError`]
2943 pub enum SignOrCreationError {
2944 /// An error occurred during signing
2946 /// An error occurred while building the transaction
2948 crate::lightning_invoice::CreationError),
2950 use lightning_invoice::SignOrCreationError as SignOrCreationErrorImport;
2951 pub(crate) type nativeSignOrCreationError = SignOrCreationErrorImport<>;
2953 impl SignOrCreationError {
2955 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
2957 SignOrCreationError::SignError => {
2958 nativeSignOrCreationError::SignError (
2962 SignOrCreationError::CreationError (ref a, ) => {
2963 let mut a_nonref = Clone::clone(a);
2964 nativeSignOrCreationError::CreationError (
2965 a_nonref.into_native(),
2971 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
2973 SignOrCreationError::SignError => {
2974 nativeSignOrCreationError::SignError (
2978 SignOrCreationError::CreationError (mut a, ) => {
2979 nativeSignOrCreationError::CreationError (
2986 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
2988 nativeSignOrCreationError::SignError (ref a, ) => {
2989 SignOrCreationError::SignError },
2990 nativeSignOrCreationError::CreationError (ref a, ) => {
2991 let mut a_nonref = Clone::clone(a);
2992 SignOrCreationError::CreationError (
2993 crate::lightning_invoice::CreationError::native_into(a_nonref),
2999 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
3001 nativeSignOrCreationError::SignError (mut a, ) => {
3002 SignOrCreationError::SignError },
3003 nativeSignOrCreationError::CreationError (mut a, ) => {
3004 SignOrCreationError::CreationError (
3005 crate::lightning_invoice::CreationError::native_into(a),
3011 /// Frees any resources used by the SignOrCreationError
3013 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
3014 /// Creates a copy of the SignOrCreationError
3016 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
3020 /// Utility method to constructs a new SignError-variant SignOrCreationError
3021 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
3022 SignOrCreationError::SignError
3025 /// Utility method to constructs a new CreationError-variant SignOrCreationError
3026 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
3027 SignOrCreationError::CreationError(a, )
3029 /// Checks if two SignOrCreationErrors contain equal inner contents.
3030 /// This ignores pointers and is_owned flags and looks at the values in fields.
3032 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
3033 if &a.to_native() == &b.to_native() { true } else { false }
3036 /// Get the string representation of a SignOrCreationError object
3037 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
3038 alloc::format!("{}", &o.to_native()).into()