1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! This crate provides data structures to represent
10 //! [lightning BOLT11](https://github.com/lightning/bolts/blob/master/11-payment-encoding.md)
11 //! invoices and functions to create, encode and decode these. If you just want to use the standard
12 //! en-/decoding functionality this should get you started:
14 //! * For parsing use `str::parse::<Invoice>(&self)` (see the docs of `impl FromStr for Invoice`)
15 //! * For constructing invoices use the `InvoiceBuilder`
16 //! * For serializing invoices use the `Display`/`ToString` traits
18 use alloc::str::FromStr;
19 use core::ffi::c_void;
20 use core::convert::Infallible;
21 use bitcoin::hashes::Hash;
22 use crate::c_types::*;
23 #[cfg(feature="no-std")]
24 use alloc::{vec::Vec, boxed::Box};
31 use alloc::str::FromStr;
32 use core::ffi::c_void;
33 use core::convert::Infallible;
34 use bitcoin::hashes::Hash;
35 use crate::c_types::*;
36 #[cfg(feature="no-std")]
37 use alloc::{vec::Vec, boxed::Box};
42 use alloc::str::FromStr;
43 use core::ffi::c_void;
44 use core::convert::Infallible;
45 use bitcoin::hashes::Hash;
46 use crate::c_types::*;
47 #[cfg(feature="no-std")]
48 use alloc::{vec::Vec, boxed::Box};
52 use alloc::str::FromStr;
53 use core::ffi::c_void;
54 use core::convert::Infallible;
55 use bitcoin::hashes::Hash;
56 use crate::c_types::*;
57 #[cfg(feature="no-std")]
58 use alloc::{vec::Vec, boxed::Box};
62 /// Read a SiPrefix object from a string
63 pub extern "C" fn SiPrefix_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SiPrefixParseErrorZ {
64 match lightning_invoice::SiPrefix::from_str(s.into_str()) {
66 crate::c_types::CResultTempl::ok(
67 crate::lightning_invoice::SiPrefix::native_into(r)
71 crate::c_types::CResultTempl::err(
72 crate::lightning_invoice::ParseError::native_into(e)
78 /// Read a Invoice object from a string
79 pub extern "C" fn Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_InvoiceParseOrSemanticErrorZ {
80 match lightning_invoice::Invoice::from_str(s.into_str()) {
82 crate::c_types::CResultTempl::ok(
83 crate::lightning_invoice::Invoice { inner: ObjOps::heap_alloc(r), is_owned: true }
87 crate::c_types::CResultTempl::err(
88 crate::lightning_invoice::ParseOrSemanticError::native_into(e)
94 /// Read a SignedRawInvoice object from a string
95 pub extern "C" fn SignedRawInvoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SignedRawInvoiceParseErrorZ {
96 match lightning_invoice::SignedRawInvoice::from_str(s.into_str()) {
98 crate::c_types::CResultTempl::ok(
99 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(r), is_owned: true }
103 crate::c_types::CResultTempl::err(
104 crate::lightning_invoice::ParseError::native_into(e)
110 /// Get the string representation of a ParseError object
111 pub extern "C" fn ParseError_to_str(o: &crate::lightning_invoice::ParseError) -> Str {
112 alloc::format!("{}", &o.to_native()).into()
115 /// Get the string representation of a ParseOrSemanticError object
116 pub extern "C" fn ParseOrSemanticError_to_str(o: &crate::lightning_invoice::ParseOrSemanticError) -> Str {
117 alloc::format!("{}", &o.to_native()).into()
122 use alloc::str::FromStr;
123 use core::ffi::c_void;
124 use core::convert::Infallible;
125 use bitcoin::hashes::Hash;
126 use crate::c_types::*;
127 #[cfg(feature="no-std")]
128 use alloc::{vec::Vec, boxed::Box};
131 /// Get the string representation of a Invoice object
132 pub extern "C" fn Invoice_to_str(o: &crate::lightning_invoice::Invoice) -> Str {
133 alloc::format!("{}", o.get_native_ref()).into()
136 /// Get the string representation of a SignedRawInvoice object
137 pub extern "C" fn SignedRawInvoice_to_str(o: &crate::lightning_invoice::SignedRawInvoice) -> Str {
138 alloc::format!("{}", o.get_native_ref()).into()
141 /// Get the string representation of a Currency object
142 pub extern "C" fn Currency_to_str(o: &crate::lightning_invoice::Currency) -> Str {
143 alloc::format!("{}", &o.to_native()).into()
146 /// Get the string representation of a SiPrefix object
147 pub extern "C" fn SiPrefix_to_str(o: &crate::lightning_invoice::SiPrefix) -> Str {
148 alloc::format!("{}", &o.to_native()).into()
153 use alloc::str::FromStr;
154 use core::ffi::c_void;
155 use core::convert::Infallible;
156 use bitcoin::hashes::Hash;
157 use crate::c_types::*;
158 #[cfg(feature="no-std")]
159 use alloc::{vec::Vec, boxed::Box};
164 use alloc::str::FromStr;
165 use core::ffi::c_void;
166 use core::convert::Infallible;
167 use bitcoin::hashes::Hash;
168 use crate::c_types::*;
169 #[cfg(feature="no-std")]
170 use alloc::{vec::Vec, boxed::Box};
175 use alloc::str::FromStr;
176 use core::ffi::c_void;
177 use core::convert::Infallible;
178 use bitcoin::hashes::Hash;
179 use crate::c_types::*;
180 #[cfg(feature="no-std")]
181 use alloc::{vec::Vec, boxed::Box};
184 /// Errors that indicate what is wrong with the invoice. They have some granularity for debug
185 /// reasons, but should generally result in an \"invalid BOLT11 invoice\" message for the user.
189 pub enum ParseError {
191 crate::c_types::Bech32Error),
193 crate::c_types::Error),
195 crate::c_types::Secp256k1Error),
201 UnexpectedEndOfTaggedFields,
202 DescriptionDecodeError(
203 crate::c_types::Error),
205 IntegerOverflowError,
206 InvalidSegWitProgramLength,
207 InvalidPubKeyHashLength,
208 InvalidScriptHashLength,
211 crate::c_types::Str),
212 /// Not an error, but used internally to signal that a part of the invoice should be ignored
213 /// according to BOLT11
216 use lightning_invoice::ParseError as ParseErrorImport;
217 pub(crate) type nativeParseError = ParseErrorImport;
221 pub(crate) fn to_native(&self) -> nativeParseError {
223 ParseError::Bech32Error (ref a, ) => {
224 let mut a_nonref = (*a).clone();
225 nativeParseError::Bech32Error (
226 a_nonref.into_rust(),
229 ParseError::ParseAmountError (ref a, ) => {
230 let mut a_nonref = (*a).clone();
231 nativeParseError::ParseAmountError (
232 u8::from_str_radix(" a", 10).unwrap_err() /*a_nonref*/,
235 ParseError::MalformedSignature (ref a, ) => {
236 let mut a_nonref = (*a).clone();
237 nativeParseError::MalformedSignature (
238 a_nonref.into_rust(),
241 ParseError::BadPrefix => nativeParseError::BadPrefix,
242 ParseError::UnknownCurrency => nativeParseError::UnknownCurrency,
243 ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix,
244 ParseError::MalformedHRP => nativeParseError::MalformedHRP,
245 ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
246 ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
247 ParseError::DescriptionDecodeError (ref a, ) => {
248 let mut a_nonref = (*a).clone();
249 nativeParseError::DescriptionDecodeError (
250 core::str::from_utf8(&[0xff]).unwrap_err() /*a_nonref*/,
253 ParseError::PaddingError => nativeParseError::PaddingError,
254 ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError,
255 ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength,
256 ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength,
257 ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
258 ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
259 ParseError::InvalidSliceLength (ref a, ) => {
260 let mut a_nonref = (*a).clone();
261 nativeParseError::InvalidSliceLength (
262 a_nonref.into_string(),
265 ParseError::Skip => nativeParseError::Skip,
269 pub(crate) fn into_native(self) -> nativeParseError {
271 ParseError::Bech32Error (mut a, ) => {
272 nativeParseError::Bech32Error (
276 ParseError::ParseAmountError (mut a, ) => {
277 nativeParseError::ParseAmountError (
278 u8::from_str_radix(" a", 10).unwrap_err() /*a*/,
281 ParseError::MalformedSignature (mut a, ) => {
282 nativeParseError::MalformedSignature (
286 ParseError::BadPrefix => nativeParseError::BadPrefix,
287 ParseError::UnknownCurrency => nativeParseError::UnknownCurrency,
288 ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix,
289 ParseError::MalformedHRP => nativeParseError::MalformedHRP,
290 ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
291 ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
292 ParseError::DescriptionDecodeError (mut a, ) => {
293 nativeParseError::DescriptionDecodeError (
294 core::str::from_utf8(&[0xff]).unwrap_err() /*a*/,
297 ParseError::PaddingError => nativeParseError::PaddingError,
298 ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError,
299 ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength,
300 ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength,
301 ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
302 ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
303 ParseError::InvalidSliceLength (mut a, ) => {
304 nativeParseError::InvalidSliceLength (
308 ParseError::Skip => nativeParseError::Skip,
312 pub(crate) fn from_native(native: &nativeParseError) -> Self {
314 nativeParseError::Bech32Error (ref a, ) => {
315 let mut a_nonref = (*a).clone();
316 ParseError::Bech32Error (
317 crate::c_types::Bech32Error::from_rust(a_nonref),
320 nativeParseError::ParseAmountError (ref a, ) => {
321 let mut a_nonref = (*a).clone();
322 ParseError::ParseAmountError (
323 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
326 nativeParseError::MalformedSignature (ref a, ) => {
327 let mut a_nonref = (*a).clone();
328 ParseError::MalformedSignature (
329 crate::c_types::Secp256k1Error::from_rust(a_nonref),
332 nativeParseError::BadPrefix => ParseError::BadPrefix,
333 nativeParseError::UnknownCurrency => ParseError::UnknownCurrency,
334 nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix,
335 nativeParseError::MalformedHRP => ParseError::MalformedHRP,
336 nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
337 nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
338 nativeParseError::DescriptionDecodeError (ref a, ) => {
339 let mut a_nonref = (*a).clone();
340 ParseError::DescriptionDecodeError (
341 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
344 nativeParseError::PaddingError => ParseError::PaddingError,
345 nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError,
346 nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength,
347 nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength,
348 nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
349 nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
350 nativeParseError::InvalidSliceLength (ref a, ) => {
351 let mut a_nonref = (*a).clone();
352 ParseError::InvalidSliceLength (
356 nativeParseError::Skip => ParseError::Skip,
360 pub(crate) fn native_into(native: nativeParseError) -> Self {
362 nativeParseError::Bech32Error (mut a, ) => {
363 ParseError::Bech32Error (
364 crate::c_types::Bech32Error::from_rust(a),
367 nativeParseError::ParseAmountError (mut a, ) => {
368 ParseError::ParseAmountError (
369 crate::c_types::Error { _dummy: 0 } /*a*/,
372 nativeParseError::MalformedSignature (mut a, ) => {
373 ParseError::MalformedSignature (
374 crate::c_types::Secp256k1Error::from_rust(a),
377 nativeParseError::BadPrefix => ParseError::BadPrefix,
378 nativeParseError::UnknownCurrency => ParseError::UnknownCurrency,
379 nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix,
380 nativeParseError::MalformedHRP => ParseError::MalformedHRP,
381 nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
382 nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
383 nativeParseError::DescriptionDecodeError (mut a, ) => {
384 ParseError::DescriptionDecodeError (
385 crate::c_types::Error { _dummy: 0 } /*a*/,
388 nativeParseError::PaddingError => ParseError::PaddingError,
389 nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError,
390 nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength,
391 nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength,
392 nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
393 nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
394 nativeParseError::InvalidSliceLength (mut a, ) => {
395 ParseError::InvalidSliceLength (
399 nativeParseError::Skip => ParseError::Skip,
403 /// Frees any resources used by the ParseError
405 pub extern "C" fn ParseError_free(this_ptr: ParseError) { }
406 /// Creates a copy of the ParseError
408 pub extern "C" fn ParseError_clone(orig: &ParseError) -> ParseError {
412 /// Utility method to constructs a new Bech32Error-variant ParseError
413 pub extern "C" fn ParseError_bech32_error(a: crate::c_types::Bech32Error) -> ParseError {
414 ParseError::Bech32Error(a, )
417 /// Utility method to constructs a new ParseAmountError-variant ParseError
418 pub extern "C" fn ParseError_parse_amount_error(a: crate::c_types::Error) -> ParseError {
419 ParseError::ParseAmountError(a, )
422 /// Utility method to constructs a new MalformedSignature-variant ParseError
423 pub extern "C" fn ParseError_malformed_signature(a: crate::c_types::Secp256k1Error) -> ParseError {
424 ParseError::MalformedSignature(a, )
427 /// Utility method to constructs a new BadPrefix-variant ParseError
428 pub extern "C" fn ParseError_bad_prefix() -> ParseError {
429 ParseError::BadPrefix}
431 /// Utility method to constructs a new UnknownCurrency-variant ParseError
432 pub extern "C" fn ParseError_unknown_currency() -> ParseError {
433 ParseError::UnknownCurrency}
435 /// Utility method to constructs a new UnknownSiPrefix-variant ParseError
436 pub extern "C" fn ParseError_unknown_si_prefix() -> ParseError {
437 ParseError::UnknownSiPrefix}
439 /// Utility method to constructs a new MalformedHRP-variant ParseError
440 pub extern "C" fn ParseError_malformed_hrp() -> ParseError {
441 ParseError::MalformedHRP}
443 /// Utility method to constructs a new TooShortDataPart-variant ParseError
444 pub extern "C" fn ParseError_too_short_data_part() -> ParseError {
445 ParseError::TooShortDataPart}
447 /// Utility method to constructs a new UnexpectedEndOfTaggedFields-variant ParseError
448 pub extern "C" fn ParseError_unexpected_end_of_tagged_fields() -> ParseError {
449 ParseError::UnexpectedEndOfTaggedFields}
451 /// Utility method to constructs a new DescriptionDecodeError-variant ParseError
452 pub extern "C" fn ParseError_description_decode_error(a: crate::c_types::Error) -> ParseError {
453 ParseError::DescriptionDecodeError(a, )
456 /// Utility method to constructs a new PaddingError-variant ParseError
457 pub extern "C" fn ParseError_padding_error() -> ParseError {
458 ParseError::PaddingError}
460 /// Utility method to constructs a new IntegerOverflowError-variant ParseError
461 pub extern "C" fn ParseError_integer_overflow_error() -> ParseError {
462 ParseError::IntegerOverflowError}
464 /// Utility method to constructs a new InvalidSegWitProgramLength-variant ParseError
465 pub extern "C" fn ParseError_invalid_seg_wit_program_length() -> ParseError {
466 ParseError::InvalidSegWitProgramLength}
468 /// Utility method to constructs a new InvalidPubKeyHashLength-variant ParseError
469 pub extern "C" fn ParseError_invalid_pub_key_hash_length() -> ParseError {
470 ParseError::InvalidPubKeyHashLength}
472 /// Utility method to constructs a new InvalidScriptHashLength-variant ParseError
473 pub extern "C" fn ParseError_invalid_script_hash_length() -> ParseError {
474 ParseError::InvalidScriptHashLength}
476 /// Utility method to constructs a new InvalidRecoveryId-variant ParseError
477 pub extern "C" fn ParseError_invalid_recovery_id() -> ParseError {
478 ParseError::InvalidRecoveryId}
480 /// Utility method to constructs a new InvalidSliceLength-variant ParseError
481 pub extern "C" fn ParseError_invalid_slice_length(a: crate::c_types::Str) -> ParseError {
482 ParseError::InvalidSliceLength(a, )
485 /// Utility method to constructs a new Skip-variant ParseError
486 pub extern "C" fn ParseError_skip() -> ParseError {
488 /// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
489 /// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
490 /// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
494 pub enum ParseOrSemanticError {
495 /// The invoice couldn't be decoded
497 crate::lightning_invoice::ParseError),
498 /// The invoice could be decoded but violates the BOLT11 standard
500 crate::lightning_invoice::SemanticError),
502 use lightning_invoice::ParseOrSemanticError as ParseOrSemanticErrorImport;
503 pub(crate) type nativeParseOrSemanticError = ParseOrSemanticErrorImport;
505 impl ParseOrSemanticError {
507 pub(crate) fn to_native(&self) -> nativeParseOrSemanticError {
509 ParseOrSemanticError::ParseError (ref a, ) => {
510 let mut a_nonref = (*a).clone();
511 nativeParseOrSemanticError::ParseError (
512 a_nonref.into_native(),
515 ParseOrSemanticError::SemanticError (ref a, ) => {
516 let mut a_nonref = (*a).clone();
517 nativeParseOrSemanticError::SemanticError (
518 a_nonref.into_native(),
524 pub(crate) fn into_native(self) -> nativeParseOrSemanticError {
526 ParseOrSemanticError::ParseError (mut a, ) => {
527 nativeParseOrSemanticError::ParseError (
531 ParseOrSemanticError::SemanticError (mut a, ) => {
532 nativeParseOrSemanticError::SemanticError (
539 pub(crate) fn from_native(native: &nativeParseOrSemanticError) -> Self {
541 nativeParseOrSemanticError::ParseError (ref a, ) => {
542 let mut a_nonref = (*a).clone();
543 ParseOrSemanticError::ParseError (
544 crate::lightning_invoice::ParseError::native_into(a_nonref),
547 nativeParseOrSemanticError::SemanticError (ref a, ) => {
548 let mut a_nonref = (*a).clone();
549 ParseOrSemanticError::SemanticError (
550 crate::lightning_invoice::SemanticError::native_into(a_nonref),
556 pub(crate) fn native_into(native: nativeParseOrSemanticError) -> Self {
558 nativeParseOrSemanticError::ParseError (mut a, ) => {
559 ParseOrSemanticError::ParseError (
560 crate::lightning_invoice::ParseError::native_into(a),
563 nativeParseOrSemanticError::SemanticError (mut a, ) => {
564 ParseOrSemanticError::SemanticError (
565 crate::lightning_invoice::SemanticError::native_into(a),
571 /// Frees any resources used by the ParseOrSemanticError
573 pub extern "C" fn ParseOrSemanticError_free(this_ptr: ParseOrSemanticError) { }
574 /// Creates a copy of the ParseOrSemanticError
576 pub extern "C" fn ParseOrSemanticError_clone(orig: &ParseOrSemanticError) -> ParseOrSemanticError {
580 /// Utility method to constructs a new ParseError-variant ParseOrSemanticError
581 pub extern "C" fn ParseOrSemanticError_parse_error(a: crate::lightning_invoice::ParseError) -> ParseOrSemanticError {
582 ParseOrSemanticError::ParseError(a, )
585 /// Utility method to constructs a new SemanticError-variant ParseOrSemanticError
586 pub extern "C" fn ParseOrSemanticError_semantic_error(a: crate::lightning_invoice::SemanticError) -> ParseOrSemanticError {
587 ParseOrSemanticError::SemanticError(a, )
589 /// The maximum timestamp as [`Duration::as_secs`] since the Unix epoch allowed by [`BOLT 11`].
591 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
594 pub static MAX_TIMESTAMP: u64 = lightning_invoice::MAX_TIMESTAMP;
595 /// Default expiry time as defined by [BOLT 11].
597 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
600 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
601 /// Default minimum final CLTV expiry as defined by [BOLT 11].
603 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
604 /// provided in [`MIN_FINAL_CLTV_EXPIRY`].
606 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
607 /// [`MIN_FINAL_CLTV_EXPIRY`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY
610 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY;
612 use lightning_invoice::Invoice as nativeInvoiceImport;
613 pub(crate) type nativeInvoice = nativeInvoiceImport;
615 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
617 /// There are three ways to construct an `Invoice`:
618 /// 1. using `InvoiceBuilder`
619 /// 2. using `Invoice::from_signed(SignedRawInvoice)`
620 /// 3. using `str::parse::<Invoice>(&str)`
624 /// A pointer to the opaque Rust object.
626 /// Nearly everywhere, inner must be non-null, however in places where
627 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
628 pub inner: *mut nativeInvoice,
629 /// Indicates that this is the only struct which contains the same pointer.
631 /// Rust functions which take ownership of an object provided via an argument require
632 /// this to be true and invalidate the object pointed to by inner.
636 impl Drop for Invoice {
638 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
639 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
643 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
645 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
647 /// Used only if an object of this type is returned as a trait impl by a method
648 pub(crate) extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
649 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
653 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoice {
654 unsafe { &*ObjOps::untweak_ptr(self.inner) }
656 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoice {
657 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
659 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
660 pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
661 assert!(self.is_owned);
662 let ret = ObjOps::untweak_ptr(self.inner);
663 self.inner = core::ptr::null_mut();
667 /// Checks if two Invoices contain equal inner contents.
668 /// This ignores pointers and is_owned flags and looks at the values in fields.
669 /// Two objects with NULL inner values will be considered "equal" here.
671 pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool {
672 if a.inner == b.inner { return true; }
673 if a.inner.is_null() || b.inner.is_null() { return false; }
674 if a.get_native_ref() == b.get_native_ref() { true } else { false }
676 impl Clone for Invoice {
677 fn clone(&self) -> Self {
679 inner: if <*mut nativeInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
680 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
686 /// Used only if an object of this type is returned as a trait impl by a method
687 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
688 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
691 /// Creates a copy of the Invoice
692 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
695 /// Checks if two Invoices contain equal inner contents.
697 pub extern "C" fn Invoice_hash(o: &Invoice) -> u64 {
698 if o.inner.is_null() { return 0; }
699 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
701 let mut hasher = core::hash::SipHasher::new();
702 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
703 core::hash::Hasher::finish(&hasher)
706 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
707 pub(crate) type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
709 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
713 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
716 pub struct SignedRawInvoice {
717 /// A pointer to the opaque Rust object.
719 /// Nearly everywhere, inner must be non-null, however in places where
720 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
721 pub inner: *mut nativeSignedRawInvoice,
722 /// Indicates that this is the only struct which contains the same pointer.
724 /// Rust functions which take ownership of an object provided via an argument require
725 /// this to be true and invalidate the object pointed to by inner.
729 impl Drop for SignedRawInvoice {
731 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
732 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
736 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
738 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
740 /// Used only if an object of this type is returned as a trait impl by a method
741 pub(crate) extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
742 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
745 impl SignedRawInvoice {
746 pub(crate) fn get_native_ref(&self) -> &'static nativeSignedRawInvoice {
747 unsafe { &*ObjOps::untweak_ptr(self.inner) }
749 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSignedRawInvoice {
750 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
752 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
753 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
754 assert!(self.is_owned);
755 let ret = ObjOps::untweak_ptr(self.inner);
756 self.inner = core::ptr::null_mut();
760 /// Checks if two SignedRawInvoices contain equal inner contents.
761 /// This ignores pointers and is_owned flags and looks at the values in fields.
762 /// Two objects with NULL inner values will be considered "equal" here.
764 pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice) -> bool {
765 if a.inner == b.inner { return true; }
766 if a.inner.is_null() || b.inner.is_null() { return false; }
767 if a.get_native_ref() == b.get_native_ref() { true } else { false }
769 impl Clone for SignedRawInvoice {
770 fn clone(&self) -> Self {
772 inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
773 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
779 /// Used only if an object of this type is returned as a trait impl by a method
780 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
781 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
784 /// Creates a copy of the SignedRawInvoice
785 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
788 /// Checks if two SignedRawInvoices contain equal inner contents.
790 pub extern "C" fn SignedRawInvoice_hash(o: &SignedRawInvoice) -> u64 {
791 if o.inner.is_null() { return 0; }
792 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
794 let mut hasher = core::hash::SipHasher::new();
795 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
796 core::hash::Hasher::finish(&hasher)
799 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
800 pub(crate) type nativeRawInvoice = nativeRawInvoiceImport;
802 /// Represents an syntactically correct Invoice for a payment on the lightning network,
803 /// but without the signature information.
804 /// De- and encoding should not lead to information loss but may lead to different hashes.
806 /// For methods without docs see the corresponding methods in `Invoice`.
809 pub struct RawInvoice {
810 /// A pointer to the opaque Rust object.
812 /// Nearly everywhere, inner must be non-null, however in places where
813 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
814 pub inner: *mut nativeRawInvoice,
815 /// Indicates that this is the only struct which contains the same pointer.
817 /// Rust functions which take ownership of an object provided via an argument require
818 /// this to be true and invalidate the object pointed to by inner.
822 impl Drop for RawInvoice {
824 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
825 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
829 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
831 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
833 /// Used only if an object of this type is returned as a trait impl by a method
834 pub(crate) extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
835 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
839 pub(crate) fn get_native_ref(&self) -> &'static nativeRawInvoice {
840 unsafe { &*ObjOps::untweak_ptr(self.inner) }
842 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawInvoice {
843 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
845 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
846 pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
847 assert!(self.is_owned);
848 let ret = ObjOps::untweak_ptr(self.inner);
849 self.inner = core::ptr::null_mut();
855 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
856 let mut inner_val = &mut this_ptr.get_native_mut_ref().data;
857 crate::lightning_invoice::RawDataPart { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::RawDataPart<>) as *mut _) }, is_owned: false }
861 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
862 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.data = *unsafe { Box::from_raw(val.take_inner()) };
864 /// Checks if two RawInvoices contain equal inner contents.
865 /// This ignores pointers and is_owned flags and looks at the values in fields.
866 /// Two objects with NULL inner values will be considered "equal" here.
868 pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool {
869 if a.inner == b.inner { return true; }
870 if a.inner.is_null() || b.inner.is_null() { return false; }
871 if a.get_native_ref() == b.get_native_ref() { true } else { false }
873 impl Clone for RawInvoice {
874 fn clone(&self) -> Self {
876 inner: if <*mut nativeRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
877 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
883 /// Used only if an object of this type is returned as a trait impl by a method
884 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
885 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
888 /// Creates a copy of the RawInvoice
889 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
892 /// Checks if two RawInvoices contain equal inner contents.
894 pub extern "C" fn RawInvoice_hash(o: &RawInvoice) -> u64 {
895 if o.inner.is_null() { return 0; }
896 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
898 let mut hasher = core::hash::SipHasher::new();
899 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
900 core::hash::Hasher::finish(&hasher)
903 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
904 pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
906 /// Data of the `RawInvoice` that is encoded in the data part
909 pub struct RawDataPart {
910 /// A pointer to the opaque Rust object.
912 /// Nearly everywhere, inner must be non-null, however in places where
913 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
914 pub inner: *mut nativeRawDataPart,
915 /// Indicates that this is the only struct which contains the same pointer.
917 /// Rust functions which take ownership of an object provided via an argument require
918 /// this to be true and invalidate the object pointed to by inner.
922 impl Drop for RawDataPart {
924 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
925 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
929 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
931 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
933 /// Used only if an object of this type is returned as a trait impl by a method
934 pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
935 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
939 pub(crate) fn get_native_ref(&self) -> &'static nativeRawDataPart {
940 unsafe { &*ObjOps::untweak_ptr(self.inner) }
942 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawDataPart {
943 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
945 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
946 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
947 assert!(self.is_owned);
948 let ret = ObjOps::untweak_ptr(self.inner);
949 self.inner = core::ptr::null_mut();
953 /// generation time of the invoice
955 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
956 let mut inner_val = &mut this_ptr.get_native_mut_ref().timestamp;
957 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::PositiveTimestamp<>) as *mut _) }, is_owned: false }
959 /// generation time of the invoice
961 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
962 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
964 /// Checks if two RawDataParts contain equal inner contents.
965 /// This ignores pointers and is_owned flags and looks at the values in fields.
966 /// Two objects with NULL inner values will be considered "equal" here.
968 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
969 if a.inner == b.inner { return true; }
970 if a.inner.is_null() || b.inner.is_null() { return false; }
971 if a.get_native_ref() == b.get_native_ref() { true } else { false }
973 impl Clone for RawDataPart {
974 fn clone(&self) -> Self {
976 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { core::ptr::null_mut() } else {
977 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
983 /// Used only if an object of this type is returned as a trait impl by a method
984 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
985 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
988 /// Creates a copy of the RawDataPart
989 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
992 /// Checks if two RawDataParts contain equal inner contents.
994 pub extern "C" fn RawDataPart_hash(o: &RawDataPart) -> u64 {
995 if o.inner.is_null() { return 0; }
996 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
998 let mut hasher = core::hash::SipHasher::new();
999 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1000 core::hash::Hasher::finish(&hasher)
1003 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
1004 pub(crate) type nativePositiveTimestamp = nativePositiveTimestampImport;
1006 /// A timestamp that refers to a date after 1 January 1970.
1010 /// The Unix timestamp representing the stored time has to be positive and no greater than
1011 /// [`MAX_TIMESTAMP`].
1014 pub struct PositiveTimestamp {
1015 /// A pointer to the opaque Rust object.
1017 /// Nearly everywhere, inner must be non-null, however in places where
1018 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1019 pub inner: *mut nativePositiveTimestamp,
1020 /// Indicates that this is the only struct which contains the same pointer.
1022 /// Rust functions which take ownership of an object provided via an argument require
1023 /// this to be true and invalidate the object pointed to by inner.
1027 impl Drop for PositiveTimestamp {
1028 fn drop(&mut self) {
1029 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
1030 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1034 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
1036 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
1038 /// Used only if an object of this type is returned as a trait impl by a method
1039 pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
1040 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
1043 impl PositiveTimestamp {
1044 pub(crate) fn get_native_ref(&self) -> &'static nativePositiveTimestamp {
1045 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1047 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePositiveTimestamp {
1048 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1050 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1051 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
1052 assert!(self.is_owned);
1053 let ret = ObjOps::untweak_ptr(self.inner);
1054 self.inner = core::ptr::null_mut();
1058 /// Checks if two PositiveTimestamps contain equal inner contents.
1059 /// This ignores pointers and is_owned flags and looks at the values in fields.
1060 /// Two objects with NULL inner values will be considered "equal" here.
1062 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
1063 if a.inner == b.inner { return true; }
1064 if a.inner.is_null() || b.inner.is_null() { return false; }
1065 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1067 impl Clone for PositiveTimestamp {
1068 fn clone(&self) -> Self {
1070 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { core::ptr::null_mut() } else {
1071 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1077 /// Used only if an object of this type is returned as a trait impl by a method
1078 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
1079 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
1082 /// Creates a copy of the PositiveTimestamp
1083 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
1086 /// Checks if two PositiveTimestamps contain equal inner contents.
1088 pub extern "C" fn PositiveTimestamp_hash(o: &PositiveTimestamp) -> u64 {
1089 if o.inner.is_null() { return 0; }
1090 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1091 #[allow(deprecated)]
1092 let mut hasher = core::hash::SipHasher::new();
1093 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1094 core::hash::Hasher::finish(&hasher)
1096 /// SI prefixes for the human readable part
1110 use lightning_invoice::SiPrefix as SiPrefixImport;
1111 pub(crate) type nativeSiPrefix = SiPrefixImport;
1115 pub(crate) fn to_native(&self) -> nativeSiPrefix {
1117 SiPrefix::Milli => nativeSiPrefix::Milli,
1118 SiPrefix::Micro => nativeSiPrefix::Micro,
1119 SiPrefix::Nano => nativeSiPrefix::Nano,
1120 SiPrefix::Pico => nativeSiPrefix::Pico,
1124 pub(crate) fn into_native(self) -> nativeSiPrefix {
1126 SiPrefix::Milli => nativeSiPrefix::Milli,
1127 SiPrefix::Micro => nativeSiPrefix::Micro,
1128 SiPrefix::Nano => nativeSiPrefix::Nano,
1129 SiPrefix::Pico => nativeSiPrefix::Pico,
1133 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
1135 nativeSiPrefix::Milli => SiPrefix::Milli,
1136 nativeSiPrefix::Micro => SiPrefix::Micro,
1137 nativeSiPrefix::Nano => SiPrefix::Nano,
1138 nativeSiPrefix::Pico => SiPrefix::Pico,
1142 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
1144 nativeSiPrefix::Milli => SiPrefix::Milli,
1145 nativeSiPrefix::Micro => SiPrefix::Micro,
1146 nativeSiPrefix::Nano => SiPrefix::Nano,
1147 nativeSiPrefix::Pico => SiPrefix::Pico,
1151 /// Creates a copy of the SiPrefix
1153 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
1157 /// Utility method to constructs a new Milli-variant SiPrefix
1158 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
1161 /// Utility method to constructs a new Micro-variant SiPrefix
1162 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
1165 /// Utility method to constructs a new Nano-variant SiPrefix
1166 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
1169 /// Utility method to constructs a new Pico-variant SiPrefix
1170 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
1172 /// Checks if two SiPrefixs contain equal inner contents.
1173 /// This ignores pointers and is_owned flags and looks at the values in fields.
1175 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
1176 if &a.to_native() == &b.to_native() { true } else { false }
1178 /// Checks if two SiPrefixs contain equal inner contents.
1180 pub extern "C" fn SiPrefix_hash(o: &SiPrefix) -> u64 {
1181 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1182 #[allow(deprecated)]
1183 let mut hasher = core::hash::SipHasher::new();
1184 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1185 core::hash::Hasher::finish(&hasher)
1187 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
1188 /// This is effectively 10^12 * the prefix multiplier
1191 pub extern "C" fn SiPrefix_multiplier(this_arg: &crate::lightning_invoice::SiPrefix) -> u64 {
1192 let mut ret = this_arg.to_native().multiplier();
1196 /// Enum representing the crypto currencies (or networks) supported by this library
1212 use lightning_invoice::Currency as CurrencyImport;
1213 pub(crate) type nativeCurrency = CurrencyImport;
1217 pub(crate) fn to_native(&self) -> nativeCurrency {
1219 Currency::Bitcoin => nativeCurrency::Bitcoin,
1220 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1221 Currency::Regtest => nativeCurrency::Regtest,
1222 Currency::Simnet => nativeCurrency::Simnet,
1223 Currency::Signet => nativeCurrency::Signet,
1227 pub(crate) fn into_native(self) -> nativeCurrency {
1229 Currency::Bitcoin => nativeCurrency::Bitcoin,
1230 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1231 Currency::Regtest => nativeCurrency::Regtest,
1232 Currency::Simnet => nativeCurrency::Simnet,
1233 Currency::Signet => nativeCurrency::Signet,
1237 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
1239 nativeCurrency::Bitcoin => Currency::Bitcoin,
1240 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1241 nativeCurrency::Regtest => Currency::Regtest,
1242 nativeCurrency::Simnet => Currency::Simnet,
1243 nativeCurrency::Signet => Currency::Signet,
1247 pub(crate) fn native_into(native: nativeCurrency) -> Self {
1249 nativeCurrency::Bitcoin => Currency::Bitcoin,
1250 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1251 nativeCurrency::Regtest => Currency::Regtest,
1252 nativeCurrency::Simnet => Currency::Simnet,
1253 nativeCurrency::Signet => Currency::Signet,
1257 /// Creates a copy of the Currency
1259 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
1263 /// Utility method to constructs a new Bitcoin-variant Currency
1264 pub extern "C" fn Currency_bitcoin() -> Currency {
1267 /// Utility method to constructs a new BitcoinTestnet-variant Currency
1268 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
1269 Currency::BitcoinTestnet}
1271 /// Utility method to constructs a new Regtest-variant Currency
1272 pub extern "C" fn Currency_regtest() -> Currency {
1275 /// Utility method to constructs a new Simnet-variant Currency
1276 pub extern "C" fn Currency_simnet() -> Currency {
1279 /// Utility method to constructs a new Signet-variant Currency
1280 pub extern "C" fn Currency_signet() -> Currency {
1282 /// Checks if two Currencys contain equal inner contents.
1284 pub extern "C" fn Currency_hash(o: &Currency) -> u64 {
1285 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1286 #[allow(deprecated)]
1287 let mut hasher = core::hash::SipHasher::new();
1288 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1289 core::hash::Hasher::finish(&hasher)
1291 /// Checks if two Currencys contain equal inner contents.
1292 /// This ignores pointers and is_owned flags and looks at the values in fields.
1294 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
1295 if &a.to_native() == &b.to_native() { true } else { false }
1298 use lightning_invoice::Sha256 as nativeSha256Import;
1299 pub(crate) type nativeSha256 = nativeSha256Import;
1305 /// A pointer to the opaque Rust object.
1307 /// Nearly everywhere, inner must be non-null, however in places where
1308 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1309 pub inner: *mut nativeSha256,
1310 /// Indicates that this is the only struct which contains the same pointer.
1312 /// Rust functions which take ownership of an object provided via an argument require
1313 /// this to be true and invalidate the object pointed to by inner.
1317 impl Drop for Sha256 {
1318 fn drop(&mut self) {
1319 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
1320 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1324 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
1326 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
1328 /// Used only if an object of this type is returned as a trait impl by a method
1329 pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
1330 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
1334 pub(crate) fn get_native_ref(&self) -> &'static nativeSha256 {
1335 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1337 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSha256 {
1338 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1340 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1341 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
1342 assert!(self.is_owned);
1343 let ret = ObjOps::untweak_ptr(self.inner);
1344 self.inner = core::ptr::null_mut();
1348 impl Clone for Sha256 {
1349 fn clone(&self) -> Self {
1351 inner: if <*mut nativeSha256>::is_null(self.inner) { core::ptr::null_mut() } else {
1352 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1358 /// Used only if an object of this type is returned as a trait impl by a method
1359 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
1360 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
1363 /// Creates a copy of the Sha256
1364 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
1367 /// Checks if two Sha256s contain equal inner contents.
1369 pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 {
1370 if o.inner.is_null() { return 0; }
1371 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1372 #[allow(deprecated)]
1373 let mut hasher = core::hash::SipHasher::new();
1374 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1375 core::hash::Hasher::finish(&hasher)
1377 /// Checks if two Sha256s contain equal inner contents.
1378 /// This ignores pointers and is_owned flags and looks at the values in fields.
1379 /// Two objects with NULL inner values will be considered "equal" here.
1381 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
1382 if a.inner == b.inner { return true; }
1383 if a.inner.is_null() || b.inner.is_null() { return false; }
1384 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1387 use lightning_invoice::Description as nativeDescriptionImport;
1388 pub(crate) type nativeDescription = nativeDescriptionImport;
1390 /// Description string
1393 /// The description can be at most 639 __bytes__ long
1396 pub struct Description {
1397 /// A pointer to the opaque Rust object.
1399 /// Nearly everywhere, inner must be non-null, however in places where
1400 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1401 pub inner: *mut nativeDescription,
1402 /// Indicates that this is the only struct which contains the same pointer.
1404 /// Rust functions which take ownership of an object provided via an argument require
1405 /// this to be true and invalidate the object pointed to by inner.
1409 impl Drop for Description {
1410 fn drop(&mut self) {
1411 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
1412 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1416 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
1418 pub extern "C" fn Description_free(this_obj: Description) { }
1420 /// Used only if an object of this type is returned as a trait impl by a method
1421 pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) {
1422 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
1426 pub(crate) fn get_native_ref(&self) -> &'static nativeDescription {
1427 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1429 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDescription {
1430 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1432 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1433 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
1434 assert!(self.is_owned);
1435 let ret = ObjOps::untweak_ptr(self.inner);
1436 self.inner = core::ptr::null_mut();
1440 impl Clone for Description {
1441 fn clone(&self) -> Self {
1443 inner: if <*mut nativeDescription>::is_null(self.inner) { core::ptr::null_mut() } else {
1444 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1450 /// Used only if an object of this type is returned as a trait impl by a method
1451 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
1452 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
1455 /// Creates a copy of the Description
1456 pub extern "C" fn Description_clone(orig: &Description) -> Description {
1459 /// Checks if two Descriptions contain equal inner contents.
1461 pub extern "C" fn Description_hash(o: &Description) -> u64 {
1462 if o.inner.is_null() { return 0; }
1463 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1464 #[allow(deprecated)]
1465 let mut hasher = core::hash::SipHasher::new();
1466 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1467 core::hash::Hasher::finish(&hasher)
1469 /// Checks if two Descriptions contain equal inner contents.
1470 /// This ignores pointers and is_owned flags and looks at the values in fields.
1471 /// Two objects with NULL inner values will be considered "equal" here.
1473 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
1474 if a.inner == b.inner { return true; }
1475 if a.inner.is_null() || b.inner.is_null() { return false; }
1476 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1479 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
1480 pub(crate) type nativePayeePubKey = nativePayeePubKeyImport;
1482 /// Payee public key
1485 pub struct PayeePubKey {
1486 /// A pointer to the opaque Rust object.
1488 /// Nearly everywhere, inner must be non-null, however in places where
1489 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1490 pub inner: *mut nativePayeePubKey,
1491 /// Indicates that this is the only struct which contains the same pointer.
1493 /// Rust functions which take ownership of an object provided via an argument require
1494 /// this to be true and invalidate the object pointed to by inner.
1498 impl Drop for PayeePubKey {
1499 fn drop(&mut self) {
1500 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
1501 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1505 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
1507 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
1509 /// Used only if an object of this type is returned as a trait impl by a method
1510 pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
1511 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
1515 pub(crate) fn get_native_ref(&self) -> &'static nativePayeePubKey {
1516 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1518 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayeePubKey {
1519 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1521 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1522 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
1523 assert!(self.is_owned);
1524 let ret = ObjOps::untweak_ptr(self.inner);
1525 self.inner = core::ptr::null_mut();
1530 pub extern "C" fn PayeePubKey_get_a(this_ptr: &PayeePubKey) -> crate::c_types::PublicKey {
1531 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1532 crate::c_types::PublicKey::from_rust(&inner_val)
1535 pub extern "C" fn PayeePubKey_set_a(this_ptr: &mut PayeePubKey, mut val: crate::c_types::PublicKey) {
1536 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
1538 /// Constructs a new PayeePubKey given each field
1541 pub extern "C" fn PayeePubKey_new(mut a_arg: crate::c_types::PublicKey) -> PayeePubKey {
1542 PayeePubKey { inner: ObjOps::heap_alloc(lightning_invoice::PayeePubKey (
1544 )), is_owned: true }
1546 impl Clone for PayeePubKey {
1547 fn clone(&self) -> Self {
1549 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { core::ptr::null_mut() } else {
1550 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1556 /// Used only if an object of this type is returned as a trait impl by a method
1557 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
1558 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
1561 /// Creates a copy of the PayeePubKey
1562 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
1565 /// Checks if two PayeePubKeys contain equal inner contents.
1567 pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 {
1568 if o.inner.is_null() { return 0; }
1569 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1570 #[allow(deprecated)]
1571 let mut hasher = core::hash::SipHasher::new();
1572 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1573 core::hash::Hasher::finish(&hasher)
1575 /// Checks if two PayeePubKeys contain equal inner contents.
1576 /// This ignores pointers and is_owned flags and looks at the values in fields.
1577 /// Two objects with NULL inner values will be considered "equal" here.
1579 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
1580 if a.inner == b.inner { return true; }
1581 if a.inner.is_null() || b.inner.is_null() { return false; }
1582 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1585 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
1586 pub(crate) type nativeExpiryTime = nativeExpiryTimeImport;
1588 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
1592 pub struct ExpiryTime {
1593 /// A pointer to the opaque Rust object.
1595 /// Nearly everywhere, inner must be non-null, however in places where
1596 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1597 pub inner: *mut nativeExpiryTime,
1598 /// Indicates that this is the only struct which contains the same pointer.
1600 /// Rust functions which take ownership of an object provided via an argument require
1601 /// this to be true and invalidate the object pointed to by inner.
1605 impl Drop for ExpiryTime {
1606 fn drop(&mut self) {
1607 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
1608 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1612 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
1614 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
1616 /// Used only if an object of this type is returned as a trait impl by a method
1617 pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
1618 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
1622 pub(crate) fn get_native_ref(&self) -> &'static nativeExpiryTime {
1623 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1625 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpiryTime {
1626 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1628 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1629 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
1630 assert!(self.is_owned);
1631 let ret = ObjOps::untweak_ptr(self.inner);
1632 self.inner = core::ptr::null_mut();
1636 impl Clone for ExpiryTime {
1637 fn clone(&self) -> Self {
1639 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { core::ptr::null_mut() } else {
1640 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1646 /// Used only if an object of this type is returned as a trait impl by a method
1647 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1648 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1651 /// Creates a copy of the ExpiryTime
1652 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1655 /// Checks if two ExpiryTimes contain equal inner contents.
1657 pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 {
1658 if o.inner.is_null() { return 0; }
1659 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1660 #[allow(deprecated)]
1661 let mut hasher = core::hash::SipHasher::new();
1662 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1663 core::hash::Hasher::finish(&hasher)
1665 /// Checks if two ExpiryTimes contain equal inner contents.
1666 /// This ignores pointers and is_owned flags and looks at the values in fields.
1667 /// Two objects with NULL inner values will be considered "equal" here.
1669 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1670 if a.inner == b.inner { return true; }
1671 if a.inner.is_null() || b.inner.is_null() { return false; }
1672 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1675 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
1676 pub(crate) type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
1678 /// `min_final_cltv_expiry` to use for the last HTLC in the route
1681 pub struct MinFinalCltvExpiry {
1682 /// A pointer to the opaque Rust object.
1684 /// Nearly everywhere, inner must be non-null, however in places where
1685 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1686 pub inner: *mut nativeMinFinalCltvExpiry,
1687 /// Indicates that this is the only struct which contains the same pointer.
1689 /// Rust functions which take ownership of an object provided via an argument require
1690 /// this to be true and invalidate the object pointed to by inner.
1694 impl Drop for MinFinalCltvExpiry {
1695 fn drop(&mut self) {
1696 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
1697 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1701 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1703 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1705 /// Used only if an object of this type is returned as a trait impl by a method
1706 pub(crate) extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1707 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1710 impl MinFinalCltvExpiry {
1711 pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiry {
1712 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1714 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiry {
1715 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1717 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1718 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1719 assert!(self.is_owned);
1720 let ret = ObjOps::untweak_ptr(self.inner);
1721 self.inner = core::ptr::null_mut();
1726 pub extern "C" fn MinFinalCltvExpiry_get_a(this_ptr: &MinFinalCltvExpiry) -> u64 {
1727 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1731 pub extern "C" fn MinFinalCltvExpiry_set_a(this_ptr: &mut MinFinalCltvExpiry, mut val: u64) {
1732 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val;
1734 /// Constructs a new MinFinalCltvExpiry given each field
1737 pub extern "C" fn MinFinalCltvExpiry_new(mut a_arg: u64) -> MinFinalCltvExpiry {
1738 MinFinalCltvExpiry { inner: ObjOps::heap_alloc(lightning_invoice::MinFinalCltvExpiry (
1740 )), is_owned: true }
1742 impl Clone for MinFinalCltvExpiry {
1743 fn clone(&self) -> Self {
1745 inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { core::ptr::null_mut() } else {
1746 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1752 /// Used only if an object of this type is returned as a trait impl by a method
1753 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1754 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1757 /// Creates a copy of the MinFinalCltvExpiry
1758 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1761 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1763 pub extern "C" fn MinFinalCltvExpiry_hash(o: &MinFinalCltvExpiry) -> u64 {
1764 if o.inner.is_null() { return 0; }
1765 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1766 #[allow(deprecated)]
1767 let mut hasher = core::hash::SipHasher::new();
1768 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1769 core::hash::Hasher::finish(&hasher)
1771 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1772 /// This ignores pointers and is_owned flags and looks at the values in fields.
1773 /// Two objects with NULL inner values will be considered "equal" here.
1775 pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool {
1776 if a.inner == b.inner { return true; }
1777 if a.inner.is_null() || b.inner.is_null() { return false; }
1778 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1780 /// Fallback address in case no LN payment is possible
1786 version: crate::c_types::u5,
1787 program: crate::c_types::derived::CVec_u8Z,
1790 crate::c_types::TwentyBytes),
1792 crate::c_types::TwentyBytes),
1794 use lightning_invoice::Fallback as FallbackImport;
1795 pub(crate) type nativeFallback = FallbackImport;
1799 pub(crate) fn to_native(&self) -> nativeFallback {
1801 Fallback::SegWitProgram {ref version, ref program, } => {
1802 let mut version_nonref = (*version).clone();
1803 let mut program_nonref = (*program).clone();
1804 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1805 nativeFallback::SegWitProgram {
1806 version: version_nonref.into(),
1807 program: local_program_nonref,
1810 Fallback::PubKeyHash (ref a, ) => {
1811 let mut a_nonref = (*a).clone();
1812 nativeFallback::PubKeyHash (
1816 Fallback::ScriptHash (ref a, ) => {
1817 let mut a_nonref = (*a).clone();
1818 nativeFallback::ScriptHash (
1825 pub(crate) fn into_native(self) -> nativeFallback {
1827 Fallback::SegWitProgram {mut version, mut program, } => {
1828 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1829 nativeFallback::SegWitProgram {
1830 version: version.into(),
1831 program: local_program,
1834 Fallback::PubKeyHash (mut a, ) => {
1835 nativeFallback::PubKeyHash (
1839 Fallback::ScriptHash (mut a, ) => {
1840 nativeFallback::ScriptHash (
1847 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1849 nativeFallback::SegWitProgram {ref version, ref program, } => {
1850 let mut version_nonref = (*version).clone();
1851 let mut program_nonref = (*program).clone();
1852 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1853 Fallback::SegWitProgram {
1854 version: version_nonref.into(),
1855 program: local_program_nonref.into(),
1858 nativeFallback::PubKeyHash (ref a, ) => {
1859 let mut a_nonref = (*a).clone();
1860 Fallback::PubKeyHash (
1861 crate::c_types::TwentyBytes { data: a_nonref },
1864 nativeFallback::ScriptHash (ref a, ) => {
1865 let mut a_nonref = (*a).clone();
1866 Fallback::ScriptHash (
1867 crate::c_types::TwentyBytes { data: a_nonref },
1873 pub(crate) fn native_into(native: nativeFallback) -> Self {
1875 nativeFallback::SegWitProgram {mut version, mut program, } => {
1876 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1877 Fallback::SegWitProgram {
1878 version: version.into(),
1879 program: local_program.into(),
1882 nativeFallback::PubKeyHash (mut a, ) => {
1883 Fallback::PubKeyHash (
1884 crate::c_types::TwentyBytes { data: a },
1887 nativeFallback::ScriptHash (mut a, ) => {
1888 Fallback::ScriptHash (
1889 crate::c_types::TwentyBytes { data: a },
1895 /// Frees any resources used by the Fallback
1897 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1898 /// Creates a copy of the Fallback
1900 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1904 /// Utility method to constructs a new SegWitProgram-variant Fallback
1905 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::u5, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
1906 Fallback::SegWitProgram {
1912 /// Utility method to constructs a new PubKeyHash-variant Fallback
1913 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1914 Fallback::PubKeyHash(a, )
1917 /// Utility method to constructs a new ScriptHash-variant Fallback
1918 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1919 Fallback::ScriptHash(a, )
1921 /// Checks if two Fallbacks contain equal inner contents.
1923 pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 {
1924 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1925 #[allow(deprecated)]
1926 let mut hasher = core::hash::SipHasher::new();
1927 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1928 core::hash::Hasher::finish(&hasher)
1930 /// Checks if two Fallbacks contain equal inner contents.
1931 /// This ignores pointers and is_owned flags and looks at the values in fields.
1933 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1934 if &a.to_native() == &b.to_native() { true } else { false }
1937 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1938 pub(crate) type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1940 /// Recoverable signature
1943 pub struct InvoiceSignature {
1944 /// A pointer to the opaque Rust object.
1946 /// Nearly everywhere, inner must be non-null, however in places where
1947 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1948 pub inner: *mut nativeInvoiceSignature,
1949 /// Indicates that this is the only struct which contains the same pointer.
1951 /// Rust functions which take ownership of an object provided via an argument require
1952 /// this to be true and invalidate the object pointed to by inner.
1956 impl Drop for InvoiceSignature {
1957 fn drop(&mut self) {
1958 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1959 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1963 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1965 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1967 /// Used only if an object of this type is returned as a trait impl by a method
1968 pub(crate) extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1969 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1972 impl InvoiceSignature {
1973 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceSignature {
1974 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1976 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceSignature {
1977 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1979 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1980 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1981 assert!(self.is_owned);
1982 let ret = ObjOps::untweak_ptr(self.inner);
1983 self.inner = core::ptr::null_mut();
1987 impl Clone for InvoiceSignature {
1988 fn clone(&self) -> Self {
1990 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { core::ptr::null_mut() } else {
1991 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1997 /// Used only if an object of this type is returned as a trait impl by a method
1998 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
1999 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
2002 /// Creates a copy of the InvoiceSignature
2003 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
2006 /// Checks if two InvoiceSignatures contain equal inner contents.
2008 pub extern "C" fn InvoiceSignature_hash(o: &InvoiceSignature) -> u64 {
2009 if o.inner.is_null() { return 0; }
2010 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2011 #[allow(deprecated)]
2012 let mut hasher = core::hash::SipHasher::new();
2013 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2014 core::hash::Hasher::finish(&hasher)
2016 /// Checks if two InvoiceSignatures contain equal inner contents.
2017 /// This ignores pointers and is_owned flags and looks at the values in fields.
2018 /// Two objects with NULL inner values will be considered "equal" here.
2020 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
2021 if a.inner == b.inner { return true; }
2022 if a.inner.is_null() || b.inner.is_null() { return false; }
2023 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2026 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
2027 pub(crate) type nativePrivateRoute = nativePrivateRouteImport;
2029 /// Private routing information
2032 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
2036 pub struct PrivateRoute {
2037 /// A pointer to the opaque Rust object.
2039 /// Nearly everywhere, inner must be non-null, however in places where
2040 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2041 pub inner: *mut nativePrivateRoute,
2042 /// Indicates that this is the only struct which contains the same pointer.
2044 /// Rust functions which take ownership of an object provided via an argument require
2045 /// this to be true and invalidate the object pointed to by inner.
2049 impl Drop for PrivateRoute {
2050 fn drop(&mut self) {
2051 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
2052 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2056 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
2058 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
2060 /// Used only if an object of this type is returned as a trait impl by a method
2061 pub(crate) extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
2062 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); }
2066 pub(crate) fn get_native_ref(&self) -> &'static nativePrivateRoute {
2067 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2069 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateRoute {
2070 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2072 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2073 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
2074 assert!(self.is_owned);
2075 let ret = ObjOps::untweak_ptr(self.inner);
2076 self.inner = core::ptr::null_mut();
2080 impl Clone for PrivateRoute {
2081 fn clone(&self) -> Self {
2083 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
2084 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2090 /// Used only if an object of this type is returned as a trait impl by a method
2091 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
2092 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
2095 /// Creates a copy of the PrivateRoute
2096 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
2099 /// Checks if two PrivateRoutes contain equal inner contents.
2101 pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 {
2102 if o.inner.is_null() { return 0; }
2103 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2104 #[allow(deprecated)]
2105 let mut hasher = core::hash::SipHasher::new();
2106 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2107 core::hash::Hasher::finish(&hasher)
2109 /// Checks if two PrivateRoutes contain equal inner contents.
2110 /// This ignores pointers and is_owned flags and looks at the values in fields.
2111 /// Two objects with NULL inner values will be considered "equal" here.
2113 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
2114 if a.inner == b.inner { return true; }
2115 if a.inner.is_null() || b.inner.is_null() { return false; }
2116 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2118 /// Disassembles the `SignedRawInvoice` into its three parts:
2120 /// 2. hash of the raw invoice
2124 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
2125 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
2126 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();
2130 /// The `RawInvoice` which was signed.
2133 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
2134 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice();
2135 crate::lightning_invoice::RawInvoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawInvoice<>) as *mut _) }, is_owned: false }
2138 /// The hash of the `RawInvoice` that was signed.
2141 pub extern "C" fn SignedRawInvoice_signable_hash(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> *const [u8; 32] {
2142 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2146 /// InvoiceSignature for the invoice.
2149 pub extern "C" fn SignedRawInvoice_signature(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
2150 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
2151 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::InvoiceSignature<>) as *mut _) }, is_owned: false }
2154 /// Recovers the public key used for signing the invoice from the recoverable signature.
2157 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
2158 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2159 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() };
2163 /// Checks if the signature is valid for the included payee public key or if none exists if it's
2164 /// valid for the recovered signature (which should always be true?).
2167 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &crate::lightning_invoice::SignedRawInvoice) -> bool {
2168 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2172 /// Calculate the hash of the encoded `RawInvoice` which should be signed.
2175 pub extern "C" fn RawInvoice_signable_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes {
2176 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2177 crate::c_types::ThirtyTwoBytes { data: ret }
2181 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2184 pub extern "C" fn RawInvoice_payment_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Sha256 {
2185 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2186 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 };
2191 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2194 pub extern "C" fn RawInvoice_description(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Description {
2195 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
2196 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 };
2201 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2204 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::PayeePubKey {
2205 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2206 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 };
2211 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2214 pub extern "C" fn RawInvoice_description_hash(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Sha256 {
2215 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash();
2216 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 };
2221 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2224 pub extern "C" fn RawInvoice_expiry_time(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::ExpiryTime {
2225 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2226 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 };
2231 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2234 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
2235 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
2236 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 };
2241 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2244 pub extern "C" fn RawInvoice_payment_secret(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::ThirtyTwoBytes {
2245 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2246 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
2251 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2254 pub extern "C" fn RawInvoice_features(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
2255 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2256 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 };
2262 pub extern "C" fn RawInvoice_private_routes(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2263 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2264 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 } }); };
2270 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::c_types::derived::COption_u64Z {
2271 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
2272 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() }) };
2278 pub extern "C" fn RawInvoice_currency(this_arg: &crate::lightning_invoice::RawInvoice) -> crate::lightning_invoice::Currency {
2279 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2280 crate::lightning_invoice::Currency::native_into(ret)
2283 /// Creates a `PositiveTimestamp` from a Unix timestamp in the range `0..=MAX_TIMESTAMP`.
2285 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2288 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2289 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
2290 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() };
2294 /// Creates a `PositiveTimestamp` from a [`SystemTime`] with a corresponding Unix timestamp in
2295 /// the range `0..=MAX_TIMESTAMP`.
2297 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2300 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2301 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
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 [`Duration`] since the Unix epoch in the range
2307 /// `0..=MAX_TIMESTAMP`.
2309 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2312 pub extern "C" fn PositiveTimestamp_from_duration_since_epoch(mut duration: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2313 let mut ret = lightning_invoice::PositiveTimestamp::from_duration_since_epoch(core::time::Duration::from_secs(duration));
2314 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() };
2318 /// Returns the Unix timestamp representing the stored time
2321 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2322 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_unix_timestamp();
2326 /// Returns the duration of the stored time since the Unix epoch
2329 pub extern "C" fn PositiveTimestamp_as_duration_since_epoch(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2330 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration_since_epoch();
2334 /// Returns the [`SystemTime`] representing the stored time
2337 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2338 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_time();
2339 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2342 /// Transform the `Invoice` into it's unchecked version
2345 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: crate::lightning_invoice::Invoice) -> crate::lightning_invoice::SignedRawInvoice {
2346 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
2347 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(ret), is_owned: true }
2350 /// Check that the invoice is signed correctly and that key recovery works
2353 pub extern "C" fn Invoice_check_signature(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
2354 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2355 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() };
2359 /// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
2361 /// use lightning_invoice::*;
2363 /// let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
2364 /// h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
2365 /// 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
2366 /// h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
2367 /// j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
2368 /// ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
2369 /// guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
2370 /// ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
2371 /// p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
2372 /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
2373 /// j5r6drg6k6zcqj0fcwg\";
2375 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
2377 /// assert!(Invoice::from_signed(signed).is_ok());
2381 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
2382 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
2383 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() };
2387 /// Returns the `Invoice`'s timestamp (should equal its creation time)
2390 pub extern "C" fn Invoice_timestamp(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2391 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timestamp();
2392 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2395 /// Returns the `Invoice`'s timestamp as a duration since the Unix epoch
2398 pub extern "C" fn Invoice_duration_since_epoch(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2399 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_since_epoch();
2403 /// Returns the hash to which we will receive the preimage on completion of the payment
2406 pub extern "C" fn Invoice_payment_hash(this_arg: &crate::lightning_invoice::Invoice) -> *const [u8; 32] {
2407 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2411 /// Get the payee's public key if one was included in the invoice
2413 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2416 pub extern "C" fn Invoice_payee_pub_key(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::PublicKey {
2417 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2418 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
2422 /// Get the payment secret if one was included in the invoice
2425 pub extern "C" fn Invoice_payment_secret(this_arg: &crate::lightning_invoice::Invoice) -> *const [u8; 32] {
2426 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2430 /// Get the invoice features if they were included in the invoice
2432 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2435 pub extern "C" fn Invoice_features(this_arg: &crate::lightning_invoice::Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
2436 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2437 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 };
2441 /// Recover the payee's public key (only to be used if none was included in the invoice)
2444 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::PublicKey {
2445 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2446 crate::c_types::PublicKey::from_rust(&ret)
2449 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
2452 pub extern "C" fn Invoice_expiry_time(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2453 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2457 /// Returns whether the invoice has expired.
2460 pub extern "C" fn Invoice_is_expired(this_arg: &crate::lightning_invoice::Invoice) -> bool {
2461 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
2465 /// Returns whether the expiry time would pass at the given point in time.
2466 /// `at_time` is the timestamp as a duration since the Unix epoch.
2469 pub extern "C" fn Invoice_would_expire(this_arg: &crate::lightning_invoice::Invoice, mut at_time: u64) -> bool {
2470 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.would_expire(core::time::Duration::from_secs(at_time));
2474 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
2475 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
2478 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &crate::lightning_invoice::Invoice) -> u64 {
2479 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
2483 /// Returns a list of all routes included in the invoice
2486 pub extern "C" fn Invoice_private_routes(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2487 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2488 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 } }); };
2492 /// Returns a list of all routes included in the invoice as the underlying hints
2495 pub extern "C" fn Invoice_route_hints(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
2496 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints();
2497 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 } }); };
2501 /// Returns the currency for which the invoice was issued
2504 pub extern "C" fn Invoice_currency(this_arg: &crate::lightning_invoice::Invoice) -> crate::lightning_invoice::Currency {
2505 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2506 crate::lightning_invoice::Currency::native_into(ret)
2509 /// Returns the amount if specified in the invoice as millisatoshis.
2512 pub extern "C" fn Invoice_amount_milli_satoshis(this_arg: &crate::lightning_invoice::Invoice) -> crate::c_types::derived::COption_u64Z {
2513 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_milli_satoshis();
2514 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() }) };
2518 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
2519 /// returns `CreationError::DescriptionTooLong` otherwise
2521 /// Please note that single characters may use more than one byte due to UTF8 encoding.
2524 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
2525 let mut ret = lightning_invoice::Description::new(description.into_string());
2526 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() };
2530 /// Returns the underlying description `String`
2533 pub extern "C" fn Description_into_inner(mut this_arg: crate::lightning_invoice::Description) -> crate::c_types::Str {
2534 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2538 /// Construct an `ExpiryTime` from seconds.
2541 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::lightning_invoice::ExpiryTime {
2542 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
2543 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2546 /// Construct an `ExpiryTime` from a `Duration`.
2549 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::lightning_invoice::ExpiryTime {
2550 let mut ret = lightning_invoice::ExpiryTime::from_duration(core::time::Duration::from_secs(duration));
2551 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2554 /// Returns the expiry time in seconds
2557 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2558 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_seconds();
2562 /// Returns a reference to the underlying `Duration` (=expiry time)
2565 pub extern "C" fn ExpiryTime_as_duration(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2566 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration();
2570 /// Creates a new (partial) route from a list of hops
2573 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
2574 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
2575 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() };
2579 /// Returns the underlying list of hops
2582 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: crate::lightning_invoice::PrivateRoute) -> crate::lightning::routing::router::RouteHint {
2583 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2584 crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true }
2587 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
2591 pub enum CreationError {
2592 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
2594 /// The specified route has too many hops and can't be encoded
2596 /// The Unix timestamp of the supplied date is less than zero or greater than 35-bits
2597 TimestampOutOfBounds,
2598 /// The supplied millisatoshi amount was greater than the total bitcoin supply.
2600 /// Route hints were required for this invoice and were missing. Applies to
2601 /// [phantom invoices].
2603 /// [phantom invoices]: crate::utils::create_phantom_invoice
2606 use lightning_invoice::CreationError as CreationErrorImport;
2607 pub(crate) type nativeCreationError = CreationErrorImport;
2609 impl CreationError {
2611 pub(crate) fn to_native(&self) -> nativeCreationError {
2613 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2614 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2615 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2616 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2617 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2621 pub(crate) fn into_native(self) -> nativeCreationError {
2623 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2624 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2625 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2626 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2627 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2631 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
2633 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2634 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2635 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2636 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2637 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2641 pub(crate) fn native_into(native: nativeCreationError) -> Self {
2643 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2644 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2645 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2646 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2647 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2651 /// Creates a copy of the CreationError
2653 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
2657 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
2658 pub extern "C" fn CreationError_description_too_long() -> CreationError {
2659 CreationError::DescriptionTooLong}
2661 /// Utility method to constructs a new RouteTooLong-variant CreationError
2662 pub extern "C" fn CreationError_route_too_long() -> CreationError {
2663 CreationError::RouteTooLong}
2665 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
2666 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
2667 CreationError::TimestampOutOfBounds}
2669 /// Utility method to constructs a new InvalidAmount-variant CreationError
2670 pub extern "C" fn CreationError_invalid_amount() -> CreationError {
2671 CreationError::InvalidAmount}
2673 /// Utility method to constructs a new MissingRouteHints-variant CreationError
2674 pub extern "C" fn CreationError_missing_route_hints() -> CreationError {
2675 CreationError::MissingRouteHints}
2676 /// Checks if two CreationErrors contain equal inner contents.
2677 /// This ignores pointers and is_owned flags and looks at the values in fields.
2679 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
2680 if &a.to_native() == &b.to_native() { true } else { false }
2683 /// Get the string representation of a CreationError object
2684 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
2685 alloc::format!("{}", &o.to_native()).into()
2687 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
2688 /// requirements sections in BOLT #11
2692 pub enum SemanticError {
2693 /// The invoice is missing the mandatory payment hash
2695 /// The invoice has multiple payment hashes which isn't allowed
2696 MultiplePaymentHashes,
2697 /// No description or description hash are part of the invoice
2699 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
2700 MultipleDescriptions,
2701 /// The invoice is missing the mandatory payment secret, which all modern lightning nodes
2704 /// The invoice contains multiple payment secrets
2705 MultiplePaymentSecrets,
2706 /// The invoice's features are invalid
2708 /// The recovery id doesn't fit the signature/pub key
2710 /// The invoice's signature is invalid
2712 /// The invoice's amount was not a whole number of millisatoshis
2715 use lightning_invoice::SemanticError as SemanticErrorImport;
2716 pub(crate) type nativeSemanticError = SemanticErrorImport;
2718 impl SemanticError {
2720 pub(crate) fn to_native(&self) -> nativeSemanticError {
2722 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2723 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2724 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2725 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2726 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2727 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2728 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2729 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2730 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2731 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2735 pub(crate) fn into_native(self) -> nativeSemanticError {
2737 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2738 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2739 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2740 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2741 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2742 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2743 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2744 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2745 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2746 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2750 pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
2752 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2753 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2754 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2755 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2756 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2757 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2758 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2759 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2760 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2761 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2765 pub(crate) fn native_into(native: nativeSemanticError) -> Self {
2767 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2768 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2769 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2770 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2771 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2772 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2773 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2774 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2775 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2776 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2780 /// Creates a copy of the SemanticError
2782 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
2786 /// Utility method to constructs a new NoPaymentHash-variant SemanticError
2787 pub extern "C" fn SemanticError_no_payment_hash() -> SemanticError {
2788 SemanticError::NoPaymentHash}
2790 /// Utility method to constructs a new MultiplePaymentHashes-variant SemanticError
2791 pub extern "C" fn SemanticError_multiple_payment_hashes() -> SemanticError {
2792 SemanticError::MultiplePaymentHashes}
2794 /// Utility method to constructs a new NoDescription-variant SemanticError
2795 pub extern "C" fn SemanticError_no_description() -> SemanticError {
2796 SemanticError::NoDescription}
2798 /// Utility method to constructs a new MultipleDescriptions-variant SemanticError
2799 pub extern "C" fn SemanticError_multiple_descriptions() -> SemanticError {
2800 SemanticError::MultipleDescriptions}
2802 /// Utility method to constructs a new NoPaymentSecret-variant SemanticError
2803 pub extern "C" fn SemanticError_no_payment_secret() -> SemanticError {
2804 SemanticError::NoPaymentSecret}
2806 /// Utility method to constructs a new MultiplePaymentSecrets-variant SemanticError
2807 pub extern "C" fn SemanticError_multiple_payment_secrets() -> SemanticError {
2808 SemanticError::MultiplePaymentSecrets}
2810 /// Utility method to constructs a new InvalidFeatures-variant SemanticError
2811 pub extern "C" fn SemanticError_invalid_features() -> SemanticError {
2812 SemanticError::InvalidFeatures}
2814 /// Utility method to constructs a new InvalidRecoveryId-variant SemanticError
2815 pub extern "C" fn SemanticError_invalid_recovery_id() -> SemanticError {
2816 SemanticError::InvalidRecoveryId}
2818 /// Utility method to constructs a new InvalidSignature-variant SemanticError
2819 pub extern "C" fn SemanticError_invalid_signature() -> SemanticError {
2820 SemanticError::InvalidSignature}
2822 /// Utility method to constructs a new ImpreciseAmount-variant SemanticError
2823 pub extern "C" fn SemanticError_imprecise_amount() -> SemanticError {
2824 SemanticError::ImpreciseAmount}
2825 /// Checks if two SemanticErrors contain equal inner contents.
2826 /// This ignores pointers and is_owned flags and looks at the values in fields.
2828 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
2829 if &a.to_native() == &b.to_native() { true } else { false }
2832 /// Get the string representation of a SemanticError object
2833 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
2834 alloc::format!("{}", &o.to_native()).into()
2836 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
2841 pub enum SignOrCreationError {
2842 /// An error occurred during signing
2844 /// An error occurred while building the transaction
2846 crate::lightning_invoice::CreationError),
2848 use lightning_invoice::SignOrCreationError as SignOrCreationErrorImport;
2849 pub(crate) type nativeSignOrCreationError = SignOrCreationErrorImport<>;
2851 impl SignOrCreationError {
2853 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
2855 SignOrCreationError::SignError => {
2856 nativeSignOrCreationError::SignError (
2860 SignOrCreationError::CreationError (ref a, ) => {
2861 let mut a_nonref = (*a).clone();
2862 nativeSignOrCreationError::CreationError (
2863 a_nonref.into_native(),
2869 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
2871 SignOrCreationError::SignError => {
2872 nativeSignOrCreationError::SignError (
2876 SignOrCreationError::CreationError (mut a, ) => {
2877 nativeSignOrCreationError::CreationError (
2884 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
2886 nativeSignOrCreationError::SignError (ref a, ) => {
2887 SignOrCreationError::SignError },
2888 nativeSignOrCreationError::CreationError (ref a, ) => {
2889 let mut a_nonref = (*a).clone();
2890 SignOrCreationError::CreationError (
2891 crate::lightning_invoice::CreationError::native_into(a_nonref),
2897 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
2899 nativeSignOrCreationError::SignError (mut a, ) => {
2900 SignOrCreationError::SignError },
2901 nativeSignOrCreationError::CreationError (mut a, ) => {
2902 SignOrCreationError::CreationError (
2903 crate::lightning_invoice::CreationError::native_into(a),
2909 /// Frees any resources used by the SignOrCreationError
2911 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
2912 /// Creates a copy of the SignOrCreationError
2914 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
2918 /// Utility method to constructs a new SignError-variant SignOrCreationError
2919 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
2920 SignOrCreationError::SignError
2923 /// Utility method to constructs a new CreationError-variant SignOrCreationError
2924 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
2925 SignOrCreationError::CreationError(a, )
2927 /// Checks if two SignOrCreationErrors contain equal inner contents.
2928 /// This ignores pointers and is_owned flags and looks at the values in fields.
2930 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
2931 if &a.to_native() == &b.to_native() { true } else { false }
2934 /// Get the string representation of a SignOrCreationError object
2935 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
2936 alloc::format!("{}", &o.to_native()).into()