1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! This crate provides data structures to represent
10 //! [lightning BOLT11](https://github.com/lightning/bolts/blob/master/11-payment-encoding.md)
11 //! invoices and functions to create, encode and decode these. If you just want to use the standard
12 //! en-/decoding functionality this should get you started:
14 //! * For parsing use `str::parse::<Invoice>(&self)` (see the docs of `impl FromStr for Invoice`)
15 //! * For constructing invoices use the `InvoiceBuilder`
16 //! * For serializing invoices use the `Display`/`ToString` traits
18 use alloc::str::FromStr;
19 use core::ffi::c_void;
20 use core::convert::Infallible;
21 use bitcoin::hashes::Hash;
22 use crate::c_types::*;
23 #[cfg(feature="no-std")]
24 use alloc::{vec::Vec, boxed::Box};
31 use alloc::str::FromStr;
32 use core::ffi::c_void;
33 use core::convert::Infallible;
34 use bitcoin::hashes::Hash;
35 use crate::c_types::*;
36 #[cfg(feature="no-std")]
37 use alloc::{vec::Vec, boxed::Box};
42 use alloc::str::FromStr;
43 use core::ffi::c_void;
44 use core::convert::Infallible;
45 use bitcoin::hashes::Hash;
46 use crate::c_types::*;
47 #[cfg(feature="no-std")]
48 use alloc::{vec::Vec, boxed::Box};
52 use alloc::str::FromStr;
53 use core::ffi::c_void;
54 use core::convert::Infallible;
55 use bitcoin::hashes::Hash;
56 use crate::c_types::*;
57 #[cfg(feature="no-std")]
58 use alloc::{vec::Vec, boxed::Box};
62 /// Read a SiPrefix object from a string
63 pub extern "C" fn SiPrefix_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SiPrefixParseErrorZ {
64 match lightning_invoice::SiPrefix::from_str(s.into_str()) {
66 crate::c_types::CResultTempl::ok(
67 crate::lightning_invoice::SiPrefix::native_into(r)
71 crate::c_types::CResultTempl::err(
72 crate::lightning_invoice::ParseError::native_into(e)
78 /// Read a Invoice object from a string
79 pub extern "C" fn Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_InvoiceParseOrSemanticErrorZ {
80 match lightning_invoice::Invoice::from_str(s.into_str()) {
82 crate::c_types::CResultTempl::ok(
83 crate::lightning_invoice::Invoice { inner: ObjOps::heap_alloc(r), is_owned: true }
87 crate::c_types::CResultTempl::err(
88 crate::lightning_invoice::ParseOrSemanticError::native_into(e)
94 /// Read a SignedRawInvoice object from a string
95 pub extern "C" fn SignedRawInvoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SignedRawInvoiceParseErrorZ {
96 match lightning_invoice::SignedRawInvoice::from_str(s.into_str()) {
98 crate::c_types::CResultTempl::ok(
99 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(r), is_owned: true }
103 crate::c_types::CResultTempl::err(
104 crate::lightning_invoice::ParseError::native_into(e)
110 /// Get the string representation of a ParseError object
111 pub extern "C" fn ParseError_to_str(o: &crate::lightning_invoice::ParseError) -> Str {
112 alloc::format!("{}", &o.to_native()).into()
115 /// Get the string representation of a ParseOrSemanticError object
116 pub extern "C" fn ParseOrSemanticError_to_str(o: &crate::lightning_invoice::ParseOrSemanticError) -> Str {
117 alloc::format!("{}", &o.to_native()).into()
122 use alloc::str::FromStr;
123 use core::ffi::c_void;
124 use core::convert::Infallible;
125 use bitcoin::hashes::Hash;
126 use crate::c_types::*;
127 #[cfg(feature="no-std")]
128 use alloc::{vec::Vec, boxed::Box};
131 /// Get the string representation of a Invoice object
132 pub extern "C" fn Invoice_to_str(o: &crate::lightning_invoice::Invoice) -> Str {
133 alloc::format!("{}", o.get_native_ref()).into()
136 /// Get the string representation of a SignedRawInvoice object
137 pub extern "C" fn SignedRawInvoice_to_str(o: &crate::lightning_invoice::SignedRawInvoice) -> Str {
138 alloc::format!("{}", o.get_native_ref()).into()
141 /// Get the string representation of a Currency object
142 pub extern "C" fn Currency_to_str(o: &crate::lightning_invoice::Currency) -> Str {
143 alloc::format!("{}", &o.to_native()).into()
146 /// Get the string representation of a SiPrefix object
147 pub extern "C" fn SiPrefix_to_str(o: &crate::lightning_invoice::SiPrefix) -> Str {
148 alloc::format!("{}", &o.to_native()).into()
153 use alloc::str::FromStr;
154 use core::ffi::c_void;
155 use core::convert::Infallible;
156 use bitcoin::hashes::Hash;
157 use crate::c_types::*;
158 #[cfg(feature="no-std")]
159 use alloc::{vec::Vec, boxed::Box};
164 use alloc::str::FromStr;
165 use core::ffi::c_void;
166 use core::convert::Infallible;
167 use bitcoin::hashes::Hash;
168 use crate::c_types::*;
169 #[cfg(feature="no-std")]
170 use alloc::{vec::Vec, boxed::Box};
175 use alloc::str::FromStr;
176 use core::ffi::c_void;
177 use core::convert::Infallible;
178 use bitcoin::hashes::Hash;
179 use crate::c_types::*;
180 #[cfg(feature="no-std")]
181 use alloc::{vec::Vec, boxed::Box};
184 /// Errors that indicate what is wrong with the invoice. They have some granularity for debug
185 /// reasons, but should generally result in an \"invalid BOLT11 invoice\" message for the user.
189 pub enum ParseError {
191 crate::c_types::Bech32Error),
193 crate::c_types::Error),
195 crate::c_types::Secp256k1Error),
201 UnexpectedEndOfTaggedFields,
202 DescriptionDecodeError(
203 crate::c_types::Error),
205 IntegerOverflowError,
206 InvalidSegWitProgramLength,
207 InvalidPubKeyHashLength,
208 InvalidScriptHashLength,
211 crate::c_types::Str),
212 /// Not an error, but used internally to signal that a part of the invoice should be ignored
213 /// according to BOLT11
216 use lightning_invoice::ParseError as ParseErrorImport;
217 pub(crate) type nativeParseError = ParseErrorImport;
221 pub(crate) fn to_native(&self) -> nativeParseError {
223 ParseError::Bech32Error (ref a, ) => {
224 let mut a_nonref = (*a).clone();
225 nativeParseError::Bech32Error (
226 a_nonref.into_rust(),
229 ParseError::ParseAmountError (ref a, ) => {
230 let mut a_nonref = (*a).clone();
231 nativeParseError::ParseAmountError (
232 u8::from_str_radix(" a", 10).unwrap_err() /*a_nonref*/,
235 ParseError::MalformedSignature (ref a, ) => {
236 let mut a_nonref = (*a).clone();
237 nativeParseError::MalformedSignature (
238 a_nonref.into_rust(),
241 ParseError::BadPrefix => nativeParseError::BadPrefix,
242 ParseError::UnknownCurrency => nativeParseError::UnknownCurrency,
243 ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix,
244 ParseError::MalformedHRP => nativeParseError::MalformedHRP,
245 ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
246 ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
247 ParseError::DescriptionDecodeError (ref a, ) => {
248 let mut a_nonref = (*a).clone();
249 nativeParseError::DescriptionDecodeError (
250 core::str::from_utf8(&[0xff]).unwrap_err() /*a_nonref*/,
253 ParseError::PaddingError => nativeParseError::PaddingError,
254 ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError,
255 ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength,
256 ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength,
257 ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
258 ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
259 ParseError::InvalidSliceLength (ref a, ) => {
260 let mut a_nonref = (*a).clone();
261 nativeParseError::InvalidSliceLength (
262 a_nonref.into_string(),
265 ParseError::Skip => nativeParseError::Skip,
269 pub(crate) fn into_native(self) -> nativeParseError {
271 ParseError::Bech32Error (mut a, ) => {
272 nativeParseError::Bech32Error (
276 ParseError::ParseAmountError (mut a, ) => {
277 nativeParseError::ParseAmountError (
278 u8::from_str_radix(" a", 10).unwrap_err() /*a*/,
281 ParseError::MalformedSignature (mut a, ) => {
282 nativeParseError::MalformedSignature (
286 ParseError::BadPrefix => nativeParseError::BadPrefix,
287 ParseError::UnknownCurrency => nativeParseError::UnknownCurrency,
288 ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix,
289 ParseError::MalformedHRP => nativeParseError::MalformedHRP,
290 ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
291 ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
292 ParseError::DescriptionDecodeError (mut a, ) => {
293 nativeParseError::DescriptionDecodeError (
294 core::str::from_utf8(&[0xff]).unwrap_err() /*a*/,
297 ParseError::PaddingError => nativeParseError::PaddingError,
298 ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError,
299 ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength,
300 ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength,
301 ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
302 ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
303 ParseError::InvalidSliceLength (mut a, ) => {
304 nativeParseError::InvalidSliceLength (
308 ParseError::Skip => nativeParseError::Skip,
312 pub(crate) fn from_native(native: &nativeParseError) -> Self {
314 nativeParseError::Bech32Error (ref a, ) => {
315 let mut a_nonref = (*a).clone();
316 ParseError::Bech32Error (
317 crate::c_types::Bech32Error::from_rust(a_nonref),
320 nativeParseError::ParseAmountError (ref a, ) => {
321 let mut a_nonref = (*a).clone();
322 ParseError::ParseAmountError (
323 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
326 nativeParseError::MalformedSignature (ref a, ) => {
327 let mut a_nonref = (*a).clone();
328 ParseError::MalformedSignature (
329 crate::c_types::Secp256k1Error::from_rust(a_nonref),
332 nativeParseError::BadPrefix => ParseError::BadPrefix,
333 nativeParseError::UnknownCurrency => ParseError::UnknownCurrency,
334 nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix,
335 nativeParseError::MalformedHRP => ParseError::MalformedHRP,
336 nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
337 nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
338 nativeParseError::DescriptionDecodeError (ref a, ) => {
339 let mut a_nonref = (*a).clone();
340 ParseError::DescriptionDecodeError (
341 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
344 nativeParseError::PaddingError => ParseError::PaddingError,
345 nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError,
346 nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength,
347 nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength,
348 nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
349 nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
350 nativeParseError::InvalidSliceLength (ref a, ) => {
351 let mut a_nonref = (*a).clone();
352 ParseError::InvalidSliceLength (
356 nativeParseError::Skip => ParseError::Skip,
360 pub(crate) fn native_into(native: nativeParseError) -> Self {
362 nativeParseError::Bech32Error (mut a, ) => {
363 ParseError::Bech32Error (
364 crate::c_types::Bech32Error::from_rust(a),
367 nativeParseError::ParseAmountError (mut a, ) => {
368 ParseError::ParseAmountError (
369 crate::c_types::Error { _dummy: 0 } /*a*/,
372 nativeParseError::MalformedSignature (mut a, ) => {
373 ParseError::MalformedSignature (
374 crate::c_types::Secp256k1Error::from_rust(a),
377 nativeParseError::BadPrefix => ParseError::BadPrefix,
378 nativeParseError::UnknownCurrency => ParseError::UnknownCurrency,
379 nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix,
380 nativeParseError::MalformedHRP => ParseError::MalformedHRP,
381 nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
382 nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
383 nativeParseError::DescriptionDecodeError (mut a, ) => {
384 ParseError::DescriptionDecodeError (
385 crate::c_types::Error { _dummy: 0 } /*a*/,
388 nativeParseError::PaddingError => ParseError::PaddingError,
389 nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError,
390 nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength,
391 nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength,
392 nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
393 nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
394 nativeParseError::InvalidSliceLength (mut a, ) => {
395 ParseError::InvalidSliceLength (
399 nativeParseError::Skip => ParseError::Skip,
403 /// Frees any resources used by the ParseError
405 pub extern "C" fn ParseError_free(this_ptr: ParseError) { }
406 /// Creates a copy of the ParseError
408 pub extern "C" fn ParseError_clone(orig: &ParseError) -> ParseError {
412 /// Utility method to constructs a new Bech32Error-variant ParseError
413 pub extern "C" fn ParseError_bech32_error(a: crate::c_types::Bech32Error) -> ParseError {
414 ParseError::Bech32Error(a, )
417 /// Utility method to constructs a new ParseAmountError-variant ParseError
418 pub extern "C" fn ParseError_parse_amount_error(a: crate::c_types::Error) -> ParseError {
419 ParseError::ParseAmountError(a, )
422 /// Utility method to constructs a new MalformedSignature-variant ParseError
423 pub extern "C" fn ParseError_malformed_signature(a: crate::c_types::Secp256k1Error) -> ParseError {
424 ParseError::MalformedSignature(a, )
427 /// Utility method to constructs a new BadPrefix-variant ParseError
428 pub extern "C" fn ParseError_bad_prefix() -> ParseError {
429 ParseError::BadPrefix}
431 /// Utility method to constructs a new UnknownCurrency-variant ParseError
432 pub extern "C" fn ParseError_unknown_currency() -> ParseError {
433 ParseError::UnknownCurrency}
435 /// Utility method to constructs a new UnknownSiPrefix-variant ParseError
436 pub extern "C" fn ParseError_unknown_si_prefix() -> ParseError {
437 ParseError::UnknownSiPrefix}
439 /// Utility method to constructs a new MalformedHRP-variant ParseError
440 pub extern "C" fn ParseError_malformed_hrp() -> ParseError {
441 ParseError::MalformedHRP}
443 /// Utility method to constructs a new TooShortDataPart-variant ParseError
444 pub extern "C" fn ParseError_too_short_data_part() -> ParseError {
445 ParseError::TooShortDataPart}
447 /// Utility method to constructs a new UnexpectedEndOfTaggedFields-variant ParseError
448 pub extern "C" fn ParseError_unexpected_end_of_tagged_fields() -> ParseError {
449 ParseError::UnexpectedEndOfTaggedFields}
451 /// Utility method to constructs a new DescriptionDecodeError-variant ParseError
452 pub extern "C" fn ParseError_description_decode_error(a: crate::c_types::Error) -> ParseError {
453 ParseError::DescriptionDecodeError(a, )
456 /// Utility method to constructs a new PaddingError-variant ParseError
457 pub extern "C" fn ParseError_padding_error() -> ParseError {
458 ParseError::PaddingError}
460 /// Utility method to constructs a new IntegerOverflowError-variant ParseError
461 pub extern "C" fn ParseError_integer_overflow_error() -> ParseError {
462 ParseError::IntegerOverflowError}
464 /// Utility method to constructs a new InvalidSegWitProgramLength-variant ParseError
465 pub extern "C" fn ParseError_invalid_seg_wit_program_length() -> ParseError {
466 ParseError::InvalidSegWitProgramLength}
468 /// Utility method to constructs a new InvalidPubKeyHashLength-variant ParseError
469 pub extern "C" fn ParseError_invalid_pub_key_hash_length() -> ParseError {
470 ParseError::InvalidPubKeyHashLength}
472 /// Utility method to constructs a new InvalidScriptHashLength-variant ParseError
473 pub extern "C" fn ParseError_invalid_script_hash_length() -> ParseError {
474 ParseError::InvalidScriptHashLength}
476 /// Utility method to constructs a new InvalidRecoveryId-variant ParseError
477 pub extern "C" fn ParseError_invalid_recovery_id() -> ParseError {
478 ParseError::InvalidRecoveryId}
480 /// Utility method to constructs a new InvalidSliceLength-variant ParseError
481 pub extern "C" fn ParseError_invalid_slice_length(a: crate::c_types::Str) -> ParseError {
482 ParseError::InvalidSliceLength(a, )
485 /// Utility method to constructs a new Skip-variant ParseError
486 pub extern "C" fn ParseError_skip() -> ParseError {
488 /// Checks if two ParseErrors contain equal inner contents.
489 /// This ignores pointers and is_owned flags and looks at the values in fields.
491 pub extern "C" fn ParseError_eq(a: &ParseError, b: &ParseError) -> bool {
492 if &a.to_native() == &b.to_native() { true } else { false }
494 /// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
495 /// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
496 /// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
500 pub enum ParseOrSemanticError {
501 /// The invoice couldn't be decoded
503 crate::lightning_invoice::ParseError),
504 /// The invoice could be decoded but violates the BOLT11 standard
506 crate::lightning_invoice::SemanticError),
508 use lightning_invoice::ParseOrSemanticError as ParseOrSemanticErrorImport;
509 pub(crate) type nativeParseOrSemanticError = ParseOrSemanticErrorImport;
511 impl ParseOrSemanticError {
513 pub(crate) fn to_native(&self) -> nativeParseOrSemanticError {
515 ParseOrSemanticError::ParseError (ref a, ) => {
516 let mut a_nonref = (*a).clone();
517 nativeParseOrSemanticError::ParseError (
518 a_nonref.into_native(),
521 ParseOrSemanticError::SemanticError (ref a, ) => {
522 let mut a_nonref = (*a).clone();
523 nativeParseOrSemanticError::SemanticError (
524 a_nonref.into_native(),
530 pub(crate) fn into_native(self) -> nativeParseOrSemanticError {
532 ParseOrSemanticError::ParseError (mut a, ) => {
533 nativeParseOrSemanticError::ParseError (
537 ParseOrSemanticError::SemanticError (mut a, ) => {
538 nativeParseOrSemanticError::SemanticError (
545 pub(crate) fn from_native(native: &nativeParseOrSemanticError) -> Self {
547 nativeParseOrSemanticError::ParseError (ref a, ) => {
548 let mut a_nonref = (*a).clone();
549 ParseOrSemanticError::ParseError (
550 crate::lightning_invoice::ParseError::native_into(a_nonref),
553 nativeParseOrSemanticError::SemanticError (ref a, ) => {
554 let mut a_nonref = (*a).clone();
555 ParseOrSemanticError::SemanticError (
556 crate::lightning_invoice::SemanticError::native_into(a_nonref),
562 pub(crate) fn native_into(native: nativeParseOrSemanticError) -> Self {
564 nativeParseOrSemanticError::ParseError (mut a, ) => {
565 ParseOrSemanticError::ParseError (
566 crate::lightning_invoice::ParseError::native_into(a),
569 nativeParseOrSemanticError::SemanticError (mut a, ) => {
570 ParseOrSemanticError::SemanticError (
571 crate::lightning_invoice::SemanticError::native_into(a),
577 /// Frees any resources used by the ParseOrSemanticError
579 pub extern "C" fn ParseOrSemanticError_free(this_ptr: ParseOrSemanticError) { }
580 /// Creates a copy of the ParseOrSemanticError
582 pub extern "C" fn ParseOrSemanticError_clone(orig: &ParseOrSemanticError) -> ParseOrSemanticError {
586 /// Utility method to constructs a new ParseError-variant ParseOrSemanticError
587 pub extern "C" fn ParseOrSemanticError_parse_error(a: crate::lightning_invoice::ParseError) -> ParseOrSemanticError {
588 ParseOrSemanticError::ParseError(a, )
591 /// Utility method to constructs a new SemanticError-variant ParseOrSemanticError
592 pub extern "C" fn ParseOrSemanticError_semantic_error(a: crate::lightning_invoice::SemanticError) -> ParseOrSemanticError {
593 ParseOrSemanticError::SemanticError(a, )
595 /// Checks if two ParseOrSemanticErrors contain equal inner contents.
596 /// This ignores pointers and is_owned flags and looks at the values in fields.
598 pub extern "C" fn ParseOrSemanticError_eq(a: &ParseOrSemanticError, b: &ParseOrSemanticError) -> bool {
599 if &a.to_native() == &b.to_native() { true } else { false }
601 /// The maximum timestamp as [`Duration::as_secs`] since the Unix epoch allowed by [`BOLT 11`].
603 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
606 pub static MAX_TIMESTAMP: u64 = lightning_invoice::MAX_TIMESTAMP;
607 /// Default expiry time as defined by [BOLT 11].
609 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
612 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
613 /// Default minimum final CLTV expiry as defined by [BOLT 11].
615 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
616 /// provided in [`MIN_FINAL_CLTV_EXPIRY`].
618 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
619 /// [`MIN_FINAL_CLTV_EXPIRY`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY
622 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY;
624 use lightning_invoice::Invoice as nativeInvoiceImport;
625 pub(crate) type nativeInvoice = nativeInvoiceImport;
627 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
629 /// There are three ways to construct an `Invoice`:
630 /// 1. using `InvoiceBuilder`
631 /// 2. using `Invoice::from_signed(SignedRawInvoice)`
632 /// 3. using `str::parse::<Invoice>(&str)`
636 /// A pointer to the opaque Rust object.
638 /// Nearly everywhere, inner must be non-null, however in places where
639 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
640 pub inner: *mut nativeInvoice,
641 /// Indicates that this is the only struct which contains the same pointer.
643 /// Rust functions which take ownership of an object provided via an argument require
644 /// this to be true and invalidate the object pointed to by inner.
648 impl Drop for Invoice {
650 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
651 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
655 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
657 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
659 /// Used only if an object of this type is returned as a trait impl by a method
660 pub(crate) extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
661 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
665 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoice {
666 unsafe { &*ObjOps::untweak_ptr(self.inner) }
668 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoice {
669 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
671 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
672 pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
673 assert!(self.is_owned);
674 let ret = ObjOps::untweak_ptr(self.inner);
675 self.inner = core::ptr::null_mut();
679 /// Checks if two Invoices contain equal inner contents.
680 /// This ignores pointers and is_owned flags and looks at the values in fields.
681 /// Two objects with NULL inner values will be considered "equal" here.
683 pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool {
684 if a.inner == b.inner { return true; }
685 if a.inner.is_null() || b.inner.is_null() { return false; }
686 if a.get_native_ref() == b.get_native_ref() { true } else { false }
688 impl Clone for Invoice {
689 fn clone(&self) -> Self {
691 inner: if <*mut nativeInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
692 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
698 /// Used only if an object of this type is returned as a trait impl by a method
699 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
700 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
703 /// Creates a copy of the Invoice
704 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
707 /// Checks if two Invoices contain equal inner contents.
709 pub extern "C" fn Invoice_hash(o: &Invoice) -> u64 {
710 if o.inner.is_null() { return 0; }
711 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
713 let mut hasher = core::hash::SipHasher::new();
714 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
715 core::hash::Hasher::finish(&hasher)
718 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
719 pub(crate) type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
721 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
725 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
728 pub struct SignedRawInvoice {
729 /// A pointer to the opaque Rust object.
731 /// Nearly everywhere, inner must be non-null, however in places where
732 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
733 pub inner: *mut nativeSignedRawInvoice,
734 /// Indicates that this is the only struct which contains the same pointer.
736 /// Rust functions which take ownership of an object provided via an argument require
737 /// this to be true and invalidate the object pointed to by inner.
741 impl Drop for SignedRawInvoice {
743 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
744 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
748 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
750 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
752 /// Used only if an object of this type is returned as a trait impl by a method
753 pub(crate) extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
754 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
757 impl SignedRawInvoice {
758 pub(crate) fn get_native_ref(&self) -> &'static nativeSignedRawInvoice {
759 unsafe { &*ObjOps::untweak_ptr(self.inner) }
761 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSignedRawInvoice {
762 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
764 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
765 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
766 assert!(self.is_owned);
767 let ret = ObjOps::untweak_ptr(self.inner);
768 self.inner = core::ptr::null_mut();
772 /// Checks if two SignedRawInvoices contain equal inner contents.
773 /// This ignores pointers and is_owned flags and looks at the values in fields.
774 /// Two objects with NULL inner values will be considered "equal" here.
776 pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice) -> bool {
777 if a.inner == b.inner { return true; }
778 if a.inner.is_null() || b.inner.is_null() { return false; }
779 if a.get_native_ref() == b.get_native_ref() { true } else { false }
781 impl Clone for SignedRawInvoice {
782 fn clone(&self) -> Self {
784 inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
785 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
791 /// Used only if an object of this type is returned as a trait impl by a method
792 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
793 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
796 /// Creates a copy of the SignedRawInvoice
797 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
800 /// Checks if two SignedRawInvoices contain equal inner contents.
802 pub extern "C" fn SignedRawInvoice_hash(o: &SignedRawInvoice) -> u64 {
803 if o.inner.is_null() { return 0; }
804 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
806 let mut hasher = core::hash::SipHasher::new();
807 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
808 core::hash::Hasher::finish(&hasher)
811 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
812 pub(crate) type nativeRawInvoice = nativeRawInvoiceImport;
814 /// Represents an syntactically correct Invoice for a payment on the lightning network,
815 /// but without the signature information.
816 /// De- and encoding should not lead to information loss but may lead to different hashes.
818 /// For methods without docs see the corresponding methods in `Invoice`.
821 pub struct RawInvoice {
822 /// A pointer to the opaque Rust object.
824 /// Nearly everywhere, inner must be non-null, however in places where
825 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
826 pub inner: *mut nativeRawInvoice,
827 /// Indicates that this is the only struct which contains the same pointer.
829 /// Rust functions which take ownership of an object provided via an argument require
830 /// this to be true and invalidate the object pointed to by inner.
834 impl Drop for RawInvoice {
836 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
837 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
841 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
843 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
845 /// Used only if an object of this type is returned as a trait impl by a method
846 pub(crate) extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
847 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
851 pub(crate) fn get_native_ref(&self) -> &'static nativeRawInvoice {
852 unsafe { &*ObjOps::untweak_ptr(self.inner) }
854 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawInvoice {
855 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
857 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
858 pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
859 assert!(self.is_owned);
860 let ret = ObjOps::untweak_ptr(self.inner);
861 self.inner = core::ptr::null_mut();
867 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
868 let mut inner_val = &mut this_ptr.get_native_mut_ref().data;
869 crate::lightning_invoice::RawDataPart { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::RawDataPart<>) as *mut _) }, is_owned: false }
873 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
874 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.data = *unsafe { Box::from_raw(val.take_inner()) };
876 /// Checks if two RawInvoices contain equal inner contents.
877 /// This ignores pointers and is_owned flags and looks at the values in fields.
878 /// Two objects with NULL inner values will be considered "equal" here.
880 pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool {
881 if a.inner == b.inner { return true; }
882 if a.inner.is_null() || b.inner.is_null() { return false; }
883 if a.get_native_ref() == b.get_native_ref() { true } else { false }
885 impl Clone for RawInvoice {
886 fn clone(&self) -> Self {
888 inner: if <*mut nativeRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
889 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
895 /// Used only if an object of this type is returned as a trait impl by a method
896 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
897 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
900 /// Creates a copy of the RawInvoice
901 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
904 /// Checks if two RawInvoices contain equal inner contents.
906 pub extern "C" fn RawInvoice_hash(o: &RawInvoice) -> u64 {
907 if o.inner.is_null() { return 0; }
908 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
910 let mut hasher = core::hash::SipHasher::new();
911 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
912 core::hash::Hasher::finish(&hasher)
915 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
916 pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
918 /// Data of the `RawInvoice` that is encoded in the data part
921 pub struct RawDataPart {
922 /// A pointer to the opaque Rust object.
924 /// Nearly everywhere, inner must be non-null, however in places where
925 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
926 pub inner: *mut nativeRawDataPart,
927 /// Indicates that this is the only struct which contains the same pointer.
929 /// Rust functions which take ownership of an object provided via an argument require
930 /// this to be true and invalidate the object pointed to by inner.
934 impl Drop for RawDataPart {
936 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
937 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
941 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
943 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
945 /// Used only if an object of this type is returned as a trait impl by a method
946 pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
947 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
951 pub(crate) fn get_native_ref(&self) -> &'static nativeRawDataPart {
952 unsafe { &*ObjOps::untweak_ptr(self.inner) }
954 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawDataPart {
955 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
957 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
958 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
959 assert!(self.is_owned);
960 let ret = ObjOps::untweak_ptr(self.inner);
961 self.inner = core::ptr::null_mut();
965 /// generation time of the invoice
967 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
968 let mut inner_val = &mut this_ptr.get_native_mut_ref().timestamp;
969 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::PositiveTimestamp<>) as *mut _) }, is_owned: false }
971 /// generation time of the invoice
973 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
974 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
976 /// Checks if two RawDataParts contain equal inner contents.
977 /// This ignores pointers and is_owned flags and looks at the values in fields.
978 /// Two objects with NULL inner values will be considered "equal" here.
980 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
981 if a.inner == b.inner { return true; }
982 if a.inner.is_null() || b.inner.is_null() { return false; }
983 if a.get_native_ref() == b.get_native_ref() { true } else { false }
985 impl Clone for RawDataPart {
986 fn clone(&self) -> Self {
988 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { core::ptr::null_mut() } else {
989 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
995 /// Used only if an object of this type is returned as a trait impl by a method
996 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
997 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
1000 /// Creates a copy of the RawDataPart
1001 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
1004 /// Checks if two RawDataParts contain equal inner contents.
1006 pub extern "C" fn RawDataPart_hash(o: &RawDataPart) -> u64 {
1007 if o.inner.is_null() { return 0; }
1008 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1009 #[allow(deprecated)]
1010 let mut hasher = core::hash::SipHasher::new();
1011 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1012 core::hash::Hasher::finish(&hasher)
1015 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
1016 pub(crate) type nativePositiveTimestamp = nativePositiveTimestampImport;
1018 /// A timestamp that refers to a date after 1 January 1970.
1022 /// The Unix timestamp representing the stored time has to be positive and no greater than
1023 /// [`MAX_TIMESTAMP`].
1026 pub struct PositiveTimestamp {
1027 /// A pointer to the opaque Rust object.
1029 /// Nearly everywhere, inner must be non-null, however in places where
1030 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1031 pub inner: *mut nativePositiveTimestamp,
1032 /// Indicates that this is the only struct which contains the same pointer.
1034 /// Rust functions which take ownership of an object provided via an argument require
1035 /// this to be true and invalidate the object pointed to by inner.
1039 impl Drop for PositiveTimestamp {
1040 fn drop(&mut self) {
1041 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
1042 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1046 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
1048 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
1050 /// Used only if an object of this type is returned as a trait impl by a method
1051 pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
1052 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
1055 impl PositiveTimestamp {
1056 pub(crate) fn get_native_ref(&self) -> &'static nativePositiveTimestamp {
1057 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1059 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePositiveTimestamp {
1060 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1062 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1063 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
1064 assert!(self.is_owned);
1065 let ret = ObjOps::untweak_ptr(self.inner);
1066 self.inner = core::ptr::null_mut();
1070 /// Checks if two PositiveTimestamps contain equal inner contents.
1071 /// This ignores pointers and is_owned flags and looks at the values in fields.
1072 /// Two objects with NULL inner values will be considered "equal" here.
1074 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
1075 if a.inner == b.inner { return true; }
1076 if a.inner.is_null() || b.inner.is_null() { return false; }
1077 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1079 impl Clone for PositiveTimestamp {
1080 fn clone(&self) -> Self {
1082 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { core::ptr::null_mut() } else {
1083 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1089 /// Used only if an object of this type is returned as a trait impl by a method
1090 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
1091 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
1094 /// Creates a copy of the PositiveTimestamp
1095 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
1098 /// Checks if two PositiveTimestamps contain equal inner contents.
1100 pub extern "C" fn PositiveTimestamp_hash(o: &PositiveTimestamp) -> u64 {
1101 if o.inner.is_null() { return 0; }
1102 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1103 #[allow(deprecated)]
1104 let mut hasher = core::hash::SipHasher::new();
1105 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1106 core::hash::Hasher::finish(&hasher)
1108 /// SI prefixes for the human readable part
1122 use lightning_invoice::SiPrefix as SiPrefixImport;
1123 pub(crate) type nativeSiPrefix = SiPrefixImport;
1127 pub(crate) fn to_native(&self) -> nativeSiPrefix {
1129 SiPrefix::Milli => nativeSiPrefix::Milli,
1130 SiPrefix::Micro => nativeSiPrefix::Micro,
1131 SiPrefix::Nano => nativeSiPrefix::Nano,
1132 SiPrefix::Pico => nativeSiPrefix::Pico,
1136 pub(crate) fn into_native(self) -> nativeSiPrefix {
1138 SiPrefix::Milli => nativeSiPrefix::Milli,
1139 SiPrefix::Micro => nativeSiPrefix::Micro,
1140 SiPrefix::Nano => nativeSiPrefix::Nano,
1141 SiPrefix::Pico => nativeSiPrefix::Pico,
1145 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
1147 nativeSiPrefix::Milli => SiPrefix::Milli,
1148 nativeSiPrefix::Micro => SiPrefix::Micro,
1149 nativeSiPrefix::Nano => SiPrefix::Nano,
1150 nativeSiPrefix::Pico => SiPrefix::Pico,
1154 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
1156 nativeSiPrefix::Milli => SiPrefix::Milli,
1157 nativeSiPrefix::Micro => SiPrefix::Micro,
1158 nativeSiPrefix::Nano => SiPrefix::Nano,
1159 nativeSiPrefix::Pico => SiPrefix::Pico,
1163 /// Creates a copy of the SiPrefix
1165 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
1169 /// Utility method to constructs a new Milli-variant SiPrefix
1170 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
1173 /// Utility method to constructs a new Micro-variant SiPrefix
1174 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
1177 /// Utility method to constructs a new Nano-variant SiPrefix
1178 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
1181 /// Utility method to constructs a new Pico-variant SiPrefix
1182 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
1184 /// Checks if two SiPrefixs contain equal inner contents.
1185 /// This ignores pointers and is_owned flags and looks at the values in fields.
1187 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
1188 if &a.to_native() == &b.to_native() { true } else { false }
1190 /// Checks if two SiPrefixs contain equal inner contents.
1192 pub extern "C" fn SiPrefix_hash(o: &SiPrefix) -> u64 {
1193 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1194 #[allow(deprecated)]
1195 let mut hasher = core::hash::SipHasher::new();
1196 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1197 core::hash::Hasher::finish(&hasher)
1199 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
1200 /// This is effectively 10^12 * the prefix multiplier
1203 pub extern "C" fn SiPrefix_multiplier(this_arg: &crate::lightning_invoice::SiPrefix) -> u64 {
1204 let mut ret = this_arg.to_native().multiplier();
1208 /// Enum representing the crypto currencies (or networks) supported by this library
1224 use lightning_invoice::Currency as CurrencyImport;
1225 pub(crate) type nativeCurrency = CurrencyImport;
1229 pub(crate) fn to_native(&self) -> nativeCurrency {
1231 Currency::Bitcoin => nativeCurrency::Bitcoin,
1232 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1233 Currency::Regtest => nativeCurrency::Regtest,
1234 Currency::Simnet => nativeCurrency::Simnet,
1235 Currency::Signet => nativeCurrency::Signet,
1239 pub(crate) fn into_native(self) -> nativeCurrency {
1241 Currency::Bitcoin => nativeCurrency::Bitcoin,
1242 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1243 Currency::Regtest => nativeCurrency::Regtest,
1244 Currency::Simnet => nativeCurrency::Simnet,
1245 Currency::Signet => nativeCurrency::Signet,
1249 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
1251 nativeCurrency::Bitcoin => Currency::Bitcoin,
1252 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1253 nativeCurrency::Regtest => Currency::Regtest,
1254 nativeCurrency::Simnet => Currency::Simnet,
1255 nativeCurrency::Signet => Currency::Signet,
1259 pub(crate) fn native_into(native: nativeCurrency) -> Self {
1261 nativeCurrency::Bitcoin => Currency::Bitcoin,
1262 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1263 nativeCurrency::Regtest => Currency::Regtest,
1264 nativeCurrency::Simnet => Currency::Simnet,
1265 nativeCurrency::Signet => Currency::Signet,
1269 /// Creates a copy of the Currency
1271 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
1275 /// Utility method to constructs a new Bitcoin-variant Currency
1276 pub extern "C" fn Currency_bitcoin() -> Currency {
1279 /// Utility method to constructs a new BitcoinTestnet-variant Currency
1280 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
1281 Currency::BitcoinTestnet}
1283 /// Utility method to constructs a new Regtest-variant Currency
1284 pub extern "C" fn Currency_regtest() -> Currency {
1287 /// Utility method to constructs a new Simnet-variant Currency
1288 pub extern "C" fn Currency_simnet() -> Currency {
1291 /// Utility method to constructs a new Signet-variant Currency
1292 pub extern "C" fn Currency_signet() -> Currency {
1294 /// Checks if two Currencys contain equal inner contents.
1296 pub extern "C" fn Currency_hash(o: &Currency) -> u64 {
1297 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1298 #[allow(deprecated)]
1299 let mut hasher = core::hash::SipHasher::new();
1300 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1301 core::hash::Hasher::finish(&hasher)
1303 /// Checks if two Currencys contain equal inner contents.
1304 /// This ignores pointers and is_owned flags and looks at the values in fields.
1306 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
1307 if &a.to_native() == &b.to_native() { true } else { false }
1310 use lightning_invoice::Sha256 as nativeSha256Import;
1311 pub(crate) type nativeSha256 = nativeSha256Import;
1317 /// A pointer to the opaque Rust object.
1319 /// Nearly everywhere, inner must be non-null, however in places where
1320 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1321 pub inner: *mut nativeSha256,
1322 /// Indicates that this is the only struct which contains the same pointer.
1324 /// Rust functions which take ownership of an object provided via an argument require
1325 /// this to be true and invalidate the object pointed to by inner.
1329 impl Drop for Sha256 {
1330 fn drop(&mut self) {
1331 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
1332 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1336 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
1338 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
1340 /// Used only if an object of this type is returned as a trait impl by a method
1341 pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
1342 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
1346 pub(crate) fn get_native_ref(&self) -> &'static nativeSha256 {
1347 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1349 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSha256 {
1350 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1352 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1353 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
1354 assert!(self.is_owned);
1355 let ret = ObjOps::untweak_ptr(self.inner);
1356 self.inner = core::ptr::null_mut();
1360 impl Clone for Sha256 {
1361 fn clone(&self) -> Self {
1363 inner: if <*mut nativeSha256>::is_null(self.inner) { core::ptr::null_mut() } else {
1364 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1370 /// Used only if an object of this type is returned as a trait impl by a method
1371 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
1372 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
1375 /// Creates a copy of the Sha256
1376 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
1379 /// Checks if two Sha256s contain equal inner contents.
1381 pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 {
1382 if o.inner.is_null() { return 0; }
1383 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1384 #[allow(deprecated)]
1385 let mut hasher = core::hash::SipHasher::new();
1386 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1387 core::hash::Hasher::finish(&hasher)
1389 /// Checks if two Sha256s contain equal inner contents.
1390 /// This ignores pointers and is_owned flags and looks at the values in fields.
1391 /// Two objects with NULL inner values will be considered "equal" here.
1393 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
1394 if a.inner == b.inner { return true; }
1395 if a.inner.is_null() || b.inner.is_null() { return false; }
1396 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1399 use lightning_invoice::Description as nativeDescriptionImport;
1400 pub(crate) type nativeDescription = nativeDescriptionImport;
1402 /// Description string
1405 /// The description can be at most 639 __bytes__ long
1408 pub struct Description {
1409 /// A pointer to the opaque Rust object.
1411 /// Nearly everywhere, inner must be non-null, however in places where
1412 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1413 pub inner: *mut nativeDescription,
1414 /// Indicates that this is the only struct which contains the same pointer.
1416 /// Rust functions which take ownership of an object provided via an argument require
1417 /// this to be true and invalidate the object pointed to by inner.
1421 impl Drop for Description {
1422 fn drop(&mut self) {
1423 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
1424 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1428 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
1430 pub extern "C" fn Description_free(this_obj: Description) { }
1432 /// Used only if an object of this type is returned as a trait impl by a method
1433 pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) {
1434 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
1438 pub(crate) fn get_native_ref(&self) -> &'static nativeDescription {
1439 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1441 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDescription {
1442 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1444 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1445 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
1446 assert!(self.is_owned);
1447 let ret = ObjOps::untweak_ptr(self.inner);
1448 self.inner = core::ptr::null_mut();
1452 impl Clone for Description {
1453 fn clone(&self) -> Self {
1455 inner: if <*mut nativeDescription>::is_null(self.inner) { core::ptr::null_mut() } else {
1456 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1462 /// Used only if an object of this type is returned as a trait impl by a method
1463 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
1464 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
1467 /// Creates a copy of the Description
1468 pub extern "C" fn Description_clone(orig: &Description) -> Description {
1471 /// Checks if two Descriptions contain equal inner contents.
1473 pub extern "C" fn Description_hash(o: &Description) -> u64 {
1474 if o.inner.is_null() { return 0; }
1475 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1476 #[allow(deprecated)]
1477 let mut hasher = core::hash::SipHasher::new();
1478 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1479 core::hash::Hasher::finish(&hasher)
1481 /// Checks if two Descriptions contain equal inner contents.
1482 /// This ignores pointers and is_owned flags and looks at the values in fields.
1483 /// Two objects with NULL inner values will be considered "equal" here.
1485 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
1486 if a.inner == b.inner { return true; }
1487 if a.inner.is_null() || b.inner.is_null() { return false; }
1488 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1491 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
1492 pub(crate) type nativePayeePubKey = nativePayeePubKeyImport;
1494 /// Payee public key
1497 pub struct PayeePubKey {
1498 /// A pointer to the opaque Rust object.
1500 /// Nearly everywhere, inner must be non-null, however in places where
1501 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1502 pub inner: *mut nativePayeePubKey,
1503 /// Indicates that this is the only struct which contains the same pointer.
1505 /// Rust functions which take ownership of an object provided via an argument require
1506 /// this to be true and invalidate the object pointed to by inner.
1510 impl Drop for PayeePubKey {
1511 fn drop(&mut self) {
1512 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
1513 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1517 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
1519 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
1521 /// Used only if an object of this type is returned as a trait impl by a method
1522 pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
1523 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
1527 pub(crate) fn get_native_ref(&self) -> &'static nativePayeePubKey {
1528 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1530 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayeePubKey {
1531 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1533 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1534 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
1535 assert!(self.is_owned);
1536 let ret = ObjOps::untweak_ptr(self.inner);
1537 self.inner = core::ptr::null_mut();
1542 pub extern "C" fn PayeePubKey_get_a(this_ptr: &PayeePubKey) -> crate::c_types::PublicKey {
1543 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1544 crate::c_types::PublicKey::from_rust(&inner_val)
1547 pub extern "C" fn PayeePubKey_set_a(this_ptr: &mut PayeePubKey, mut val: crate::c_types::PublicKey) {
1548 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
1550 /// Constructs a new PayeePubKey given each field
1553 pub extern "C" fn PayeePubKey_new(mut a_arg: crate::c_types::PublicKey) -> PayeePubKey {
1554 PayeePubKey { inner: ObjOps::heap_alloc(lightning_invoice::PayeePubKey (
1556 )), is_owned: true }
1558 impl Clone for PayeePubKey {
1559 fn clone(&self) -> Self {
1561 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { core::ptr::null_mut() } else {
1562 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1568 /// Used only if an object of this type is returned as a trait impl by a method
1569 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
1570 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
1573 /// Creates a copy of the PayeePubKey
1574 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
1577 /// Checks if two PayeePubKeys contain equal inner contents.
1579 pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 {
1580 if o.inner.is_null() { return 0; }
1581 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1582 #[allow(deprecated)]
1583 let mut hasher = core::hash::SipHasher::new();
1584 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1585 core::hash::Hasher::finish(&hasher)
1587 /// Checks if two PayeePubKeys contain equal inner contents.
1588 /// This ignores pointers and is_owned flags and looks at the values in fields.
1589 /// Two objects with NULL inner values will be considered "equal" here.
1591 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
1592 if a.inner == b.inner { return true; }
1593 if a.inner.is_null() || b.inner.is_null() { return false; }
1594 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1597 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
1598 pub(crate) type nativeExpiryTime = nativeExpiryTimeImport;
1600 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
1604 pub struct ExpiryTime {
1605 /// A pointer to the opaque Rust object.
1607 /// Nearly everywhere, inner must be non-null, however in places where
1608 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1609 pub inner: *mut nativeExpiryTime,
1610 /// Indicates that this is the only struct which contains the same pointer.
1612 /// Rust functions which take ownership of an object provided via an argument require
1613 /// this to be true and invalidate the object pointed to by inner.
1617 impl Drop for ExpiryTime {
1618 fn drop(&mut self) {
1619 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
1620 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1624 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
1626 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
1628 /// Used only if an object of this type is returned as a trait impl by a method
1629 pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
1630 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
1634 pub(crate) fn get_native_ref(&self) -> &'static nativeExpiryTime {
1635 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1637 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpiryTime {
1638 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1640 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1641 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
1642 assert!(self.is_owned);
1643 let ret = ObjOps::untweak_ptr(self.inner);
1644 self.inner = core::ptr::null_mut();
1648 impl Clone for ExpiryTime {
1649 fn clone(&self) -> Self {
1651 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { core::ptr::null_mut() } else {
1652 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1658 /// Used only if an object of this type is returned as a trait impl by a method
1659 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1660 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1663 /// Creates a copy of the ExpiryTime
1664 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1667 /// Checks if two ExpiryTimes contain equal inner contents.
1669 pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 {
1670 if o.inner.is_null() { return 0; }
1671 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1672 #[allow(deprecated)]
1673 let mut hasher = core::hash::SipHasher::new();
1674 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1675 core::hash::Hasher::finish(&hasher)
1677 /// Checks if two ExpiryTimes contain equal inner contents.
1678 /// This ignores pointers and is_owned flags and looks at the values in fields.
1679 /// Two objects with NULL inner values will be considered "equal" here.
1681 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1682 if a.inner == b.inner { return true; }
1683 if a.inner.is_null() || b.inner.is_null() { return false; }
1684 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1687 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
1688 pub(crate) type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
1690 /// `min_final_cltv_expiry` to use for the last HTLC in the route
1693 pub struct MinFinalCltvExpiry {
1694 /// A pointer to the opaque Rust object.
1696 /// Nearly everywhere, inner must be non-null, however in places where
1697 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1698 pub inner: *mut nativeMinFinalCltvExpiry,
1699 /// Indicates that this is the only struct which contains the same pointer.
1701 /// Rust functions which take ownership of an object provided via an argument require
1702 /// this to be true and invalidate the object pointed to by inner.
1706 impl Drop for MinFinalCltvExpiry {
1707 fn drop(&mut self) {
1708 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
1709 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1713 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1715 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1717 /// Used only if an object of this type is returned as a trait impl by a method
1718 pub(crate) extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1719 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1722 impl MinFinalCltvExpiry {
1723 pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiry {
1724 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1726 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiry {
1727 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1729 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1730 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1731 assert!(self.is_owned);
1732 let ret = ObjOps::untweak_ptr(self.inner);
1733 self.inner = core::ptr::null_mut();
1738 pub extern "C" fn MinFinalCltvExpiry_get_a(this_ptr: &MinFinalCltvExpiry) -> u64 {
1739 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1743 pub extern "C" fn MinFinalCltvExpiry_set_a(this_ptr: &mut MinFinalCltvExpiry, mut val: u64) {
1744 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val;
1746 /// Constructs a new MinFinalCltvExpiry given each field
1749 pub extern "C" fn MinFinalCltvExpiry_new(mut a_arg: u64) -> MinFinalCltvExpiry {
1750 MinFinalCltvExpiry { inner: ObjOps::heap_alloc(lightning_invoice::MinFinalCltvExpiry (
1752 )), is_owned: true }
1754 impl Clone for MinFinalCltvExpiry {
1755 fn clone(&self) -> Self {
1757 inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { core::ptr::null_mut() } else {
1758 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1764 /// Used only if an object of this type is returned as a trait impl by a method
1765 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1766 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1769 /// Creates a copy of the MinFinalCltvExpiry
1770 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1773 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1775 pub extern "C" fn MinFinalCltvExpiry_hash(o: &MinFinalCltvExpiry) -> u64 {
1776 if o.inner.is_null() { return 0; }
1777 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1778 #[allow(deprecated)]
1779 let mut hasher = core::hash::SipHasher::new();
1780 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1781 core::hash::Hasher::finish(&hasher)
1783 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1784 /// This ignores pointers and is_owned flags and looks at the values in fields.
1785 /// Two objects with NULL inner values will be considered "equal" here.
1787 pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool {
1788 if a.inner == b.inner { return true; }
1789 if a.inner.is_null() || b.inner.is_null() { return false; }
1790 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1792 /// Fallback address in case no LN payment is possible
1798 version: crate::c_types::u5,
1799 program: crate::c_types::derived::CVec_u8Z,
1802 crate::c_types::TwentyBytes),
1804 crate::c_types::TwentyBytes),
1806 use lightning_invoice::Fallback as FallbackImport;
1807 pub(crate) type nativeFallback = FallbackImport;
1811 pub(crate) fn to_native(&self) -> nativeFallback {
1813 Fallback::SegWitProgram {ref version, ref program, } => {
1814 let mut version_nonref = (*version).clone();
1815 let mut program_nonref = (*program).clone();
1816 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1817 nativeFallback::SegWitProgram {
1818 version: version_nonref.into(),
1819 program: local_program_nonref,
1822 Fallback::PubKeyHash (ref a, ) => {
1823 let mut a_nonref = (*a).clone();
1824 nativeFallback::PubKeyHash (
1828 Fallback::ScriptHash (ref a, ) => {
1829 let mut a_nonref = (*a).clone();
1830 nativeFallback::ScriptHash (
1837 pub(crate) fn into_native(self) -> nativeFallback {
1839 Fallback::SegWitProgram {mut version, mut program, } => {
1840 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1841 nativeFallback::SegWitProgram {
1842 version: version.into(),
1843 program: local_program,
1846 Fallback::PubKeyHash (mut a, ) => {
1847 nativeFallback::PubKeyHash (
1851 Fallback::ScriptHash (mut a, ) => {
1852 nativeFallback::ScriptHash (
1859 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1861 nativeFallback::SegWitProgram {ref version, ref program, } => {
1862 let mut version_nonref = (*version).clone();
1863 let mut program_nonref = (*program).clone();
1864 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1865 Fallback::SegWitProgram {
1866 version: version_nonref.into(),
1867 program: local_program_nonref.into(),
1870 nativeFallback::PubKeyHash (ref a, ) => {
1871 let mut a_nonref = (*a).clone();
1872 Fallback::PubKeyHash (
1873 crate::c_types::TwentyBytes { data: a_nonref },
1876 nativeFallback::ScriptHash (ref a, ) => {
1877 let mut a_nonref = (*a).clone();
1878 Fallback::ScriptHash (
1879 crate::c_types::TwentyBytes { data: a_nonref },
1885 pub(crate) fn native_into(native: nativeFallback) -> Self {
1887 nativeFallback::SegWitProgram {mut version, mut program, } => {
1888 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1889 Fallback::SegWitProgram {
1890 version: version.into(),
1891 program: local_program.into(),
1894 nativeFallback::PubKeyHash (mut a, ) => {
1895 Fallback::PubKeyHash (
1896 crate::c_types::TwentyBytes { data: a },
1899 nativeFallback::ScriptHash (mut a, ) => {
1900 Fallback::ScriptHash (
1901 crate::c_types::TwentyBytes { data: a },
1907 /// Frees any resources used by the Fallback
1909 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1910 /// Creates a copy of the Fallback
1912 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1916 /// Utility method to constructs a new SegWitProgram-variant Fallback
1917 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::u5, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
1918 Fallback::SegWitProgram {
1924 /// Utility method to constructs a new PubKeyHash-variant Fallback
1925 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1926 Fallback::PubKeyHash(a, )
1929 /// Utility method to constructs a new ScriptHash-variant Fallback
1930 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1931 Fallback::ScriptHash(a, )
1933 /// Checks if two Fallbacks contain equal inner contents.
1935 pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 {
1936 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1937 #[allow(deprecated)]
1938 let mut hasher = core::hash::SipHasher::new();
1939 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1940 core::hash::Hasher::finish(&hasher)
1942 /// Checks if two Fallbacks contain equal inner contents.
1943 /// This ignores pointers and is_owned flags and looks at the values in fields.
1945 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1946 if &a.to_native() == &b.to_native() { true } else { false }
1949 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1950 pub(crate) type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1952 /// Recoverable signature
1955 pub struct InvoiceSignature {
1956 /// A pointer to the opaque Rust object.
1958 /// Nearly everywhere, inner must be non-null, however in places where
1959 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1960 pub inner: *mut nativeInvoiceSignature,
1961 /// Indicates that this is the only struct which contains the same pointer.
1963 /// Rust functions which take ownership of an object provided via an argument require
1964 /// this to be true and invalidate the object pointed to by inner.
1968 impl Drop for InvoiceSignature {
1969 fn drop(&mut self) {
1970 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1971 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1975 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1977 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1979 /// Used only if an object of this type is returned as a trait impl by a method
1980 pub(crate) extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1981 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1984 impl InvoiceSignature {
1985 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceSignature {
1986 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1988 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceSignature {
1989 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1991 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1992 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1993 assert!(self.is_owned);
1994 let ret = ObjOps::untweak_ptr(self.inner);
1995 self.inner = core::ptr::null_mut();
1999 impl Clone for InvoiceSignature {
2000 fn clone(&self) -> Self {
2002 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { core::ptr::null_mut() } else {
2003 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2009 /// Used only if an object of this type is returned as a trait impl by a method
2010 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
2011 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
2014 /// Creates a copy of the InvoiceSignature
2015 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
2018 /// Checks if two InvoiceSignatures contain equal inner contents.
2020 pub extern "C" fn InvoiceSignature_hash(o: &InvoiceSignature) -> u64 {
2021 if o.inner.is_null() { return 0; }
2022 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2023 #[allow(deprecated)]
2024 let mut hasher = core::hash::SipHasher::new();
2025 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2026 core::hash::Hasher::finish(&hasher)
2028 /// Checks if two InvoiceSignatures contain equal inner contents.
2029 /// This ignores pointers and is_owned flags and looks at the values in fields.
2030 /// Two objects with NULL inner values will be considered "equal" here.
2032 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
2033 if a.inner == b.inner { return true; }
2034 if a.inner.is_null() || b.inner.is_null() { return false; }
2035 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2038 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
2039 pub(crate) type nativePrivateRoute = nativePrivateRouteImport;
2041 /// Private routing information
2044 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
2048 pub struct PrivateRoute {
2049 /// A pointer to the opaque Rust object.
2051 /// Nearly everywhere, inner must be non-null, however in places where
2052 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2053 pub inner: *mut nativePrivateRoute,
2054 /// Indicates that this is the only struct which contains the same pointer.
2056 /// Rust functions which take ownership of an object provided via an argument require
2057 /// this to be true and invalidate the object pointed to by inner.
2061 impl Drop for PrivateRoute {
2062 fn drop(&mut self) {
2063 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
2064 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2068 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
2070 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
2072 /// Used only if an object of this type is returned as a trait impl by a method
2073 pub(crate) extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
2074 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); }
2078 pub(crate) fn get_native_ref(&self) -> &'static nativePrivateRoute {
2079 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2081 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateRoute {
2082 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2084 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2085 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
2086 assert!(self.is_owned);
2087 let ret = ObjOps::untweak_ptr(self.inner);
2088 self.inner = core::ptr::null_mut();
2092 impl Clone for PrivateRoute {
2093 fn clone(&self) -> Self {
2095 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
2096 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2102 /// Used only if an object of this type is returned as a trait impl by a method
2103 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
2104 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
2107 /// Creates a copy of the PrivateRoute
2108 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
2111 /// Checks if two PrivateRoutes contain equal inner contents.
2113 pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 {
2114 if o.inner.is_null() { return 0; }
2115 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2116 #[allow(deprecated)]
2117 let mut hasher = core::hash::SipHasher::new();
2118 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2119 core::hash::Hasher::finish(&hasher)
2121 /// Checks if two PrivateRoutes contain equal inner contents.
2122 /// This ignores pointers and is_owned flags and looks at the values in fields.
2123 /// Two objects with NULL inner values will be considered "equal" here.
2125 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
2126 if a.inner == b.inner { return true; }
2127 if a.inner.is_null() || b.inner.is_null() { return false; }
2128 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2130 /// Disassembles the `SignedRawInvoice` into its three parts:
2132 /// 2. hash of the raw invoice
2136 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
2137 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
2138 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();
2142 /// The `RawInvoice` which was signed.
2145 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
2146 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice();
2147 crate::lightning_invoice::RawInvoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawInvoice<>) as *mut _) }, is_owned: false }
2150 /// The hash of the `RawInvoice` that was signed.
2153 pub extern "C" fn SignedRawInvoice_signable_hash(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> *const [u8; 32] {
2154 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2158 /// InvoiceSignature for the invoice.
2161 pub extern "C" fn SignedRawInvoice_signature(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
2162 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
2163 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::InvoiceSignature<>) as *mut _) }, is_owned: false }
2166 /// Recovers the public key used for signing the invoice from the recoverable signature.
2169 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
2170 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2171 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() };
2175 /// Checks if the signature is valid for the included payee public key or if none exists if it's
2176 /// valid for the recovered signature (which should always be true?).
2179 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> bool {
2180 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2184 /// Calculate the hash of the encoded `RawInvoice` which should be signed.
2187 pub extern "C" fn RawInvoice_signable_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes {
2188 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2189 crate::c_types::ThirtyTwoBytes { data: ret }
2193 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2196 pub extern "C" fn RawInvoice_payment_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Sha256 {
2197 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2198 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 };
2203 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2206 pub extern "C" fn RawInvoice_description(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Description {
2207 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
2208 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 };
2213 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2216 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::PayeePubKey {
2217 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2218 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 };
2223 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2226 pub extern "C" fn RawInvoice_description_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Sha256 {
2227 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash();
2228 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 };
2233 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2236 pub extern "C" fn RawInvoice_expiry_time(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::ExpiryTime {
2237 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2238 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 };
2243 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2246 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
2247 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
2248 let mut local_ret = crate::lightning_invoice::MinFinalCltvExpiry { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::MinFinalCltvExpiry<>) as *mut _ }, is_owned: false };
2253 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2256 pub extern "C" fn RawInvoice_payment_secret(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes {
2257 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2258 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
2263 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2266 pub extern "C" fn RawInvoice_features(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
2267 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2268 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 };
2274 pub extern "C" fn RawInvoice_private_routes(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2275 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2276 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 } }); };
2282 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::derived::COption_u64Z {
2283 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
2284 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() }) };
2290 pub extern "C" fn RawInvoice_currency(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Currency {
2291 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2292 crate::lightning_invoice::Currency::native_into(ret)
2295 /// Creates a `PositiveTimestamp` from a Unix timestamp in the range `0..=MAX_TIMESTAMP`.
2297 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2300 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2301 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
2302 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() };
2306 /// Creates a `PositiveTimestamp` from a [`SystemTime`] with a corresponding Unix timestamp in
2307 /// the range `0..=MAX_TIMESTAMP`.
2309 /// Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
2311 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2314 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2315 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
2316 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() };
2320 /// Creates a `PositiveTimestamp` from a [`Duration`] since the Unix epoch in the range
2321 /// `0..=MAX_TIMESTAMP`.
2323 /// Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
2325 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2328 pub extern "C" fn PositiveTimestamp_from_duration_since_epoch(mut duration: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2329 let mut ret = lightning_invoice::PositiveTimestamp::from_duration_since_epoch(core::time::Duration::from_secs(duration));
2330 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() };
2334 /// Returns the Unix timestamp representing the stored time
2337 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2338 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_unix_timestamp();
2342 /// Returns the duration of the stored time since the Unix epoch
2345 pub extern "C" fn PositiveTimestamp_as_duration_since_epoch(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2346 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration_since_epoch();
2350 /// Returns the [`SystemTime`] representing the stored time
2353 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2354 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_time();
2355 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2358 /// Transform the `Invoice` into it's unchecked version
2361 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: crate::lightning_invoice::Invoice) -> crate::lightning_invoice::SignedRawInvoice {
2362 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
2363 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(ret), is_owned: true }
2366 /// Check that the invoice is signed correctly and that key recovery works
2369 pub extern "C" fn Invoice_check_signature(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
2370 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2371 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() };
2375 /// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
2377 /// use lightning_invoice::*;
2379 /// let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
2380 /// h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
2381 /// 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
2382 /// h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
2383 /// j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
2384 /// ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
2385 /// guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
2386 /// ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
2387 /// p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
2388 /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
2389 /// j5r6drg6k6zcqj0fcwg\";
2391 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
2393 /// assert!(Invoice::from_signed(signed).is_ok());
2397 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
2398 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
2399 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() };
2403 /// Returns the `Invoice`'s timestamp (should equal its creation time)
2406 pub extern "C" fn Invoice_timestamp(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2407 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timestamp();
2408 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2411 /// Returns the `Invoice`'s timestamp as a duration since the Unix epoch
2414 pub extern "C" fn Invoice_duration_since_epoch(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2415 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_since_epoch();
2419 /// Returns the hash to which we will receive the preimage on completion of the payment
2422 pub extern "C" fn Invoice_payment_hash(this_arg: &crate::lightning_invoice::Invoice) -> *const [u8; 32] {
2423 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2427 /// Get the payee's public key if one was included in the invoice
2429 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2432 pub extern "C" fn Invoice_payee_pub_key(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::PublicKey {
2433 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2434 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
2438 /// Get the payment secret if one was included in the invoice
2441 pub extern "C" fn Invoice_payment_secret(this_arg: &crate::lightning_invoice::Invoice) -> *const [u8; 32] {
2442 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2446 /// Get the invoice features if they were included in the invoice
2448 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2451 pub extern "C" fn Invoice_features(this_arg: &crate::lightning_invoice::Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
2452 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2453 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 };
2457 /// Recover the payee's public key (only to be used if none was included in the invoice)
2460 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::PublicKey {
2461 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2462 crate::c_types::PublicKey::from_rust(&ret)
2465 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
2468 pub extern "C" fn Invoice_expiry_time(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2469 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2473 /// Returns whether the invoice has expired.
2476 pub extern "C" fn Invoice_is_expired(this_arg: &crate::lightning_invoice::Invoice) -> bool {
2477 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
2481 /// Returns whether the expiry time would pass at the given point in time.
2482 /// `at_time` is the timestamp as a duration since the Unix epoch.
2485 pub extern "C" fn Invoice_would_expire(this_arg: &crate::lightning_invoice::Invoice, mut at_time: u64) -> bool {
2486 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.would_expire(core::time::Duration::from_secs(at_time));
2490 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
2491 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
2494 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2495 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
2499 /// Returns a list of all routes included in the invoice
2502 pub extern "C" fn Invoice_private_routes(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2503 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2504 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 } }); };
2508 /// Returns a list of all routes included in the invoice as the underlying hints
2511 pub extern "C" fn Invoice_route_hints(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
2512 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints();
2513 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 } }); };
2517 /// Returns the currency for which the invoice was issued
2520 pub extern "C" fn Invoice_currency(this_arg: &crate::lightning_invoice::Invoice) -> crate::lightning_invoice::Currency {
2521 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2522 crate::lightning_invoice::Currency::native_into(ret)
2525 /// Returns the amount if specified in the invoice as millisatoshis.
2528 pub extern "C" fn Invoice_amount_milli_satoshis(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::COption_u64Z {
2529 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_milli_satoshis();
2530 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() }) };
2534 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
2535 /// returns `CreationError::DescriptionTooLong` otherwise
2537 /// Please note that single characters may use more than one byte due to UTF8 encoding.
2540 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
2541 let mut ret = lightning_invoice::Description::new(description.into_string());
2542 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() };
2546 /// Returns the underlying description `String`
2549 pub extern "C" fn Description_into_inner(mut this_arg: crate::lightning_invoice::Description) -> crate::c_types::Str {
2550 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2554 /// Construct an `ExpiryTime` from seconds.
2557 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::lightning_invoice::ExpiryTime {
2558 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
2559 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2562 /// Construct an `ExpiryTime` from a `Duration`, dropping the sub-second part.
2565 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::lightning_invoice::ExpiryTime {
2566 let mut ret = lightning_invoice::ExpiryTime::from_duration(core::time::Duration::from_secs(duration));
2567 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2570 /// Returns the expiry time in seconds
2573 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2574 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_seconds();
2578 /// Returns a reference to the underlying `Duration` (=expiry time)
2581 pub extern "C" fn ExpiryTime_as_duration(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2582 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration();
2586 /// Creates a new (partial) route from a list of hops
2589 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
2590 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
2591 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() };
2595 /// Returns the underlying list of hops
2598 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: crate::lightning_invoice::PrivateRoute) -> crate::lightning::routing::router::RouteHint {
2599 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2600 crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true }
2603 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
2607 pub enum CreationError {
2608 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
2610 /// The specified route has too many hops and can't be encoded
2612 /// The Unix timestamp of the supplied date is less than zero or greater than 35-bits
2613 TimestampOutOfBounds,
2614 /// The supplied millisatoshi amount was greater than the total bitcoin supply.
2616 /// Route hints were required for this invoice and were missing. Applies to
2617 /// [phantom invoices].
2619 /// [phantom invoices]: crate::utils::create_phantom_invoice
2622 use lightning_invoice::CreationError as CreationErrorImport;
2623 pub(crate) type nativeCreationError = CreationErrorImport;
2625 impl CreationError {
2627 pub(crate) fn to_native(&self) -> nativeCreationError {
2629 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2630 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2631 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2632 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2633 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2637 pub(crate) fn into_native(self) -> nativeCreationError {
2639 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2640 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2641 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2642 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2643 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2647 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
2649 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2650 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2651 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2652 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2653 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2657 pub(crate) fn native_into(native: nativeCreationError) -> Self {
2659 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2660 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2661 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2662 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2663 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2667 /// Creates a copy of the CreationError
2669 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
2673 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
2674 pub extern "C" fn CreationError_description_too_long() -> CreationError {
2675 CreationError::DescriptionTooLong}
2677 /// Utility method to constructs a new RouteTooLong-variant CreationError
2678 pub extern "C" fn CreationError_route_too_long() -> CreationError {
2679 CreationError::RouteTooLong}
2681 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
2682 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
2683 CreationError::TimestampOutOfBounds}
2685 /// Utility method to constructs a new InvalidAmount-variant CreationError
2686 pub extern "C" fn CreationError_invalid_amount() -> CreationError {
2687 CreationError::InvalidAmount}
2689 /// Utility method to constructs a new MissingRouteHints-variant CreationError
2690 pub extern "C" fn CreationError_missing_route_hints() -> CreationError {
2691 CreationError::MissingRouteHints}
2692 /// Checks if two CreationErrors contain equal inner contents.
2693 /// This ignores pointers and is_owned flags and looks at the values in fields.
2695 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
2696 if &a.to_native() == &b.to_native() { true } else { false }
2699 /// Get the string representation of a CreationError object
2700 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
2701 alloc::format!("{}", &o.to_native()).into()
2703 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
2704 /// requirements sections in BOLT #11
2708 pub enum SemanticError {
2709 /// The invoice is missing the mandatory payment hash
2711 /// The invoice has multiple payment hashes which isn't allowed
2712 MultiplePaymentHashes,
2713 /// No description or description hash are part of the invoice
2715 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
2716 MultipleDescriptions,
2717 /// The invoice is missing the mandatory payment secret, which all modern lightning nodes
2720 /// The invoice contains multiple payment secrets
2721 MultiplePaymentSecrets,
2722 /// The invoice's features are invalid
2724 /// The recovery id doesn't fit the signature/pub key
2726 /// The invoice's signature is invalid
2728 /// The invoice's amount was not a whole number of millisatoshis
2731 use lightning_invoice::SemanticError as SemanticErrorImport;
2732 pub(crate) type nativeSemanticError = SemanticErrorImport;
2734 impl SemanticError {
2736 pub(crate) fn to_native(&self) -> nativeSemanticError {
2738 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2739 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2740 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2741 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2742 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2743 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2744 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2745 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2746 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2747 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2751 pub(crate) fn into_native(self) -> nativeSemanticError {
2753 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2754 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2755 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2756 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2757 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2758 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2759 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2760 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2761 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2762 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2766 pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
2768 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2769 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2770 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2771 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2772 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2773 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2774 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2775 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2776 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2777 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2781 pub(crate) fn native_into(native: nativeSemanticError) -> Self {
2783 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2784 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2785 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2786 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2787 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2788 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2789 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2790 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2791 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2792 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2796 /// Creates a copy of the SemanticError
2798 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
2802 /// Utility method to constructs a new NoPaymentHash-variant SemanticError
2803 pub extern "C" fn SemanticError_no_payment_hash() -> SemanticError {
2804 SemanticError::NoPaymentHash}
2806 /// Utility method to constructs a new MultiplePaymentHashes-variant SemanticError
2807 pub extern "C" fn SemanticError_multiple_payment_hashes() -> SemanticError {
2808 SemanticError::MultiplePaymentHashes}
2810 /// Utility method to constructs a new NoDescription-variant SemanticError
2811 pub extern "C" fn SemanticError_no_description() -> SemanticError {
2812 SemanticError::NoDescription}
2814 /// Utility method to constructs a new MultipleDescriptions-variant SemanticError
2815 pub extern "C" fn SemanticError_multiple_descriptions() -> SemanticError {
2816 SemanticError::MultipleDescriptions}
2818 /// Utility method to constructs a new NoPaymentSecret-variant SemanticError
2819 pub extern "C" fn SemanticError_no_payment_secret() -> SemanticError {
2820 SemanticError::NoPaymentSecret}
2822 /// Utility method to constructs a new MultiplePaymentSecrets-variant SemanticError
2823 pub extern "C" fn SemanticError_multiple_payment_secrets() -> SemanticError {
2824 SemanticError::MultiplePaymentSecrets}
2826 /// Utility method to constructs a new InvalidFeatures-variant SemanticError
2827 pub extern "C" fn SemanticError_invalid_features() -> SemanticError {
2828 SemanticError::InvalidFeatures}
2830 /// Utility method to constructs a new InvalidRecoveryId-variant SemanticError
2831 pub extern "C" fn SemanticError_invalid_recovery_id() -> SemanticError {
2832 SemanticError::InvalidRecoveryId}
2834 /// Utility method to constructs a new InvalidSignature-variant SemanticError
2835 pub extern "C" fn SemanticError_invalid_signature() -> SemanticError {
2836 SemanticError::InvalidSignature}
2838 /// Utility method to constructs a new ImpreciseAmount-variant SemanticError
2839 pub extern "C" fn SemanticError_imprecise_amount() -> SemanticError {
2840 SemanticError::ImpreciseAmount}
2841 /// Checks if two SemanticErrors contain equal inner contents.
2842 /// This ignores pointers and is_owned flags and looks at the values in fields.
2844 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
2845 if &a.to_native() == &b.to_native() { true } else { false }
2848 /// Get the string representation of a SemanticError object
2849 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
2850 alloc::format!("{}", &o.to_native()).into()
2852 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
2857 pub enum SignOrCreationError {
2858 /// An error occurred during signing
2860 /// An error occurred while building the transaction
2862 crate::lightning_invoice::CreationError),
2864 use lightning_invoice::SignOrCreationError as SignOrCreationErrorImport;
2865 pub(crate) type nativeSignOrCreationError = SignOrCreationErrorImport<>;
2867 impl SignOrCreationError {
2869 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
2871 SignOrCreationError::SignError => {
2872 nativeSignOrCreationError::SignError (
2876 SignOrCreationError::CreationError (ref a, ) => {
2877 let mut a_nonref = (*a).clone();
2878 nativeSignOrCreationError::CreationError (
2879 a_nonref.into_native(),
2885 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
2887 SignOrCreationError::SignError => {
2888 nativeSignOrCreationError::SignError (
2892 SignOrCreationError::CreationError (mut a, ) => {
2893 nativeSignOrCreationError::CreationError (
2900 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
2902 nativeSignOrCreationError::SignError (ref a, ) => {
2903 SignOrCreationError::SignError },
2904 nativeSignOrCreationError::CreationError (ref a, ) => {
2905 let mut a_nonref = (*a).clone();
2906 SignOrCreationError::CreationError (
2907 crate::lightning_invoice::CreationError::native_into(a_nonref),
2913 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
2915 nativeSignOrCreationError::SignError (mut a, ) => {
2916 SignOrCreationError::SignError },
2917 nativeSignOrCreationError::CreationError (mut a, ) => {
2918 SignOrCreationError::CreationError (
2919 crate::lightning_invoice::CreationError::native_into(a),
2925 /// Frees any resources used by the SignOrCreationError
2927 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
2928 /// Creates a copy of the SignOrCreationError
2930 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
2934 /// Utility method to constructs a new SignError-variant SignOrCreationError
2935 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
2936 SignOrCreationError::SignError
2939 /// Utility method to constructs a new CreationError-variant SignOrCreationError
2940 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
2941 SignOrCreationError::CreationError(a, )
2943 /// Checks if two SignOrCreationErrors contain equal inner contents.
2944 /// This ignores pointers and is_owned flags and looks at the values in fields.
2946 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
2947 if &a.to_native() == &b.to_native() { true } else { false }
2950 /// Get the string representation of a SignOrCreationError object
2951 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
2952 alloc::format!("{}", &o.to_native()).into()