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/lightningnetwork/lightning-rfc/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};
41 use alloc::str::FromStr;
42 use core::ffi::c_void;
43 use core::convert::Infallible;
44 use bitcoin::hashes::Hash;
45 use crate::c_types::*;
46 #[cfg(feature="no-std")]
47 use alloc::{vec::Vec, boxed::Box};
51 /// Read a SiPrefix object from a string
52 pub extern "C" fn SiPrefix_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SiPrefixNoneZ {
53 match lightning_invoice::SiPrefix::from_str(s.into_str()) {
55 crate::c_types::CResultTempl::ok(
56 crate::lightning_invoice::SiPrefix::native_into(r)
59 Err(e) => crate::c_types::CResultTempl::err(()),
63 /// Read a Invoice object from a string
64 pub extern "C" fn Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_InvoiceNoneZ {
65 match lightning_invoice::Invoice::from_str(s.into_str()) {
67 crate::c_types::CResultTempl::ok(
68 crate::lightning_invoice::Invoice { inner: ObjOps::heap_alloc(r), is_owned: true }
71 Err(e) => crate::c_types::CResultTempl::err(()),
75 /// Read a SignedRawInvoice object from a string
76 pub extern "C" fn SignedRawInvoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SignedRawInvoiceNoneZ {
77 match lightning_invoice::SignedRawInvoice::from_str(s.into_str()) {
79 crate::c_types::CResultTempl::ok(
80 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(r), is_owned: true }
83 Err(e) => crate::c_types::CResultTempl::err(()),
89 use alloc::str::FromStr;
90 use core::ffi::c_void;
91 use core::convert::Infallible;
92 use bitcoin::hashes::Hash;
93 use crate::c_types::*;
94 #[cfg(feature="no-std")]
95 use alloc::{vec::Vec, boxed::Box};
98 /// Get the string representation of a Invoice object
99 pub extern "C" fn Invoice_to_str(o: &crate::lightning_invoice::Invoice) -> Str {
100 format!("{}", o.get_native_ref()).into()
103 /// Get the string representation of a SignedRawInvoice object
104 pub extern "C" fn SignedRawInvoice_to_str(o: &crate::lightning_invoice::SignedRawInvoice) -> Str {
105 format!("{}", o.get_native_ref()).into()
108 /// Get the string representation of a Currency object
109 pub extern "C" fn Currency_to_str(o: &crate::lightning_invoice::Currency) -> Str {
110 format!("{}", &o.to_native()).into()
113 /// Get the string representation of a SiPrefix object
114 pub extern "C" fn SiPrefix_to_str(o: &crate::lightning_invoice::SiPrefix) -> Str {
115 format!("{}", &o.to_native()).into()
120 use alloc::str::FromStr;
121 use core::ffi::c_void;
122 use core::convert::Infallible;
123 use bitcoin::hashes::Hash;
124 use crate::c_types::*;
125 #[cfg(feature="no-std")]
126 use alloc::{vec::Vec, boxed::Box};
129 /// Default expiry time as defined by [BOLT 11].
131 /// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md
134 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
135 /// Default minimum final CLTV expiry as defined by [BOLT 11].
137 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
138 /// provided in [`MIN_FINAL_CLTV_EXPIRY`].
140 /// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md
141 /// [`MIN_FINAL_CLTV_EXPIRY`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY
144 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY;
145 /// **Call this function on startup to ensure that all assumptions about the platform are valid.**
147 /// Unfortunately we have to make assumptions about the upper bounds of the `SystemTime` type on
148 /// your platform which we can't fully verify at compile time and which isn't part of it's contract.
149 /// To our best knowledge our assumptions hold for all platforms officially supported by rust, but
150 /// since this check is fast we recommend to do it anyway.
152 /// If this function fails this is considered a bug. Please open an issue describing your
153 /// platform and stating your current system time.
156 /// If the check fails this function panics. By calling this function on startup you ensure that
157 /// this wont happen at an arbitrary later point in time.
159 pub extern "C" fn check_platform() {
160 lightning_invoice::check_platform()
164 use lightning_invoice::Invoice as nativeInvoiceImport;
165 pub(crate) type nativeInvoice = nativeInvoiceImport;
167 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
169 /// There are three ways to construct an `Invoice`:
170 /// 1. using `InvoiceBuilder`
171 /// 2. using `Invoice::from_signed(SignedRawInvoice)`
172 /// 3. using `str::parse::<Invoice>(&str)`
176 /// A pointer to the opaque Rust object.
178 /// Nearly everywhere, inner must be non-null, however in places where
179 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
180 pub inner: *mut nativeInvoice,
181 /// Indicates that this is the only struct which contains the same pointer.
183 /// Rust functions which take ownership of an object provided via an argument require
184 /// this to be true and invalidate the object pointed to by inner.
188 impl Drop for Invoice {
190 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
191 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
195 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
197 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
199 /// Used only if an object of this type is returned as a trait impl by a method
200 pub(crate) extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
201 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
205 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoice {
206 unsafe { &*ObjOps::untweak_ptr(self.inner) }
208 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoice {
209 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
211 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
212 pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
213 assert!(self.is_owned);
214 let ret = ObjOps::untweak_ptr(self.inner);
215 self.inner = core::ptr::null_mut();
219 /// Checks if two Invoices contain equal inner contents.
220 /// This ignores pointers and is_owned flags and looks at the values in fields.
221 /// Two objects with NULL inner values will be considered "equal" here.
223 pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool {
224 if a.inner == b.inner { return true; }
225 if a.inner.is_null() || b.inner.is_null() { return false; }
226 if a.get_native_ref() == b.get_native_ref() { true } else { false }
228 impl Clone for Invoice {
229 fn clone(&self) -> Self {
231 inner: if <*mut nativeInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
232 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
238 /// Used only if an object of this type is returned as a trait impl by a method
239 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
240 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
243 /// Creates a copy of the Invoice
244 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
248 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
249 pub(crate) type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
251 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
255 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
258 pub struct SignedRawInvoice {
259 /// A pointer to the opaque Rust object.
261 /// Nearly everywhere, inner must be non-null, however in places where
262 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
263 pub inner: *mut nativeSignedRawInvoice,
264 /// Indicates that this is the only struct which contains the same pointer.
266 /// Rust functions which take ownership of an object provided via an argument require
267 /// this to be true and invalidate the object pointed to by inner.
271 impl Drop for SignedRawInvoice {
273 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
274 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
278 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
280 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
282 /// Used only if an object of this type is returned as a trait impl by a method
283 pub(crate) extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
284 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
287 impl SignedRawInvoice {
288 pub(crate) fn get_native_ref(&self) -> &'static nativeSignedRawInvoice {
289 unsafe { &*ObjOps::untweak_ptr(self.inner) }
291 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSignedRawInvoice {
292 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
294 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
295 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
296 assert!(self.is_owned);
297 let ret = ObjOps::untweak_ptr(self.inner);
298 self.inner = core::ptr::null_mut();
302 /// Checks if two SignedRawInvoices contain equal inner contents.
303 /// This ignores pointers and is_owned flags and looks at the values in fields.
304 /// Two objects with NULL inner values will be considered "equal" here.
306 pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice) -> bool {
307 if a.inner == b.inner { return true; }
308 if a.inner.is_null() || b.inner.is_null() { return false; }
309 if a.get_native_ref() == b.get_native_ref() { true } else { false }
311 impl Clone for SignedRawInvoice {
312 fn clone(&self) -> Self {
314 inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
315 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
321 /// Used only if an object of this type is returned as a trait impl by a method
322 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
323 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
326 /// Creates a copy of the SignedRawInvoice
327 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
331 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
332 pub(crate) type nativeRawInvoice = nativeRawInvoiceImport;
334 /// Represents an syntactically correct Invoice for a payment on the lightning network,
335 /// but without the signature information.
336 /// De- and encoding should not lead to information loss but may lead to different hashes.
338 /// For methods without docs see the corresponding methods in `Invoice`.
341 pub struct RawInvoice {
342 /// A pointer to the opaque Rust object.
344 /// Nearly everywhere, inner must be non-null, however in places where
345 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
346 pub inner: *mut nativeRawInvoice,
347 /// Indicates that this is the only struct which contains the same pointer.
349 /// Rust functions which take ownership of an object provided via an argument require
350 /// this to be true and invalidate the object pointed to by inner.
354 impl Drop for RawInvoice {
356 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
357 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
361 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
363 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
365 /// Used only if an object of this type is returned as a trait impl by a method
366 pub(crate) extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
367 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
371 pub(crate) fn get_native_ref(&self) -> &'static nativeRawInvoice {
372 unsafe { &*ObjOps::untweak_ptr(self.inner) }
374 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawInvoice {
375 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
377 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
378 pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
379 assert!(self.is_owned);
380 let ret = ObjOps::untweak_ptr(self.inner);
381 self.inner = core::ptr::null_mut();
387 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
388 let mut inner_val = &mut this_ptr.get_native_mut_ref().data;
389 crate::lightning_invoice::RawDataPart { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::RawDataPart<>) as *mut _) }, is_owned: false }
393 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
394 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.data = *unsafe { Box::from_raw(val.take_inner()) };
396 /// Checks if two RawInvoices contain equal inner contents.
397 /// This ignores pointers and is_owned flags and looks at the values in fields.
398 /// Two objects with NULL inner values will be considered "equal" here.
400 pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool {
401 if a.inner == b.inner { return true; }
402 if a.inner.is_null() || b.inner.is_null() { return false; }
403 if a.get_native_ref() == b.get_native_ref() { true } else { false }
405 impl Clone for RawInvoice {
406 fn clone(&self) -> Self {
408 inner: if <*mut nativeRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
409 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
415 /// Used only if an object of this type is returned as a trait impl by a method
416 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
417 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
420 /// Creates a copy of the RawInvoice
421 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
425 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
426 pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
428 /// Data of the `RawInvoice` that is encoded in the data part
431 pub struct RawDataPart {
432 /// A pointer to the opaque Rust object.
434 /// Nearly everywhere, inner must be non-null, however in places where
435 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
436 pub inner: *mut nativeRawDataPart,
437 /// Indicates that this is the only struct which contains the same pointer.
439 /// Rust functions which take ownership of an object provided via an argument require
440 /// this to be true and invalidate the object pointed to by inner.
444 impl Drop for RawDataPart {
446 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
447 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
451 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
453 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
455 /// Used only if an object of this type is returned as a trait impl by a method
456 pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
457 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
461 pub(crate) fn get_native_ref(&self) -> &'static nativeRawDataPart {
462 unsafe { &*ObjOps::untweak_ptr(self.inner) }
464 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawDataPart {
465 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
467 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
468 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
469 assert!(self.is_owned);
470 let ret = ObjOps::untweak_ptr(self.inner);
471 self.inner = core::ptr::null_mut();
475 /// generation time of the invoice
477 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
478 let mut inner_val = &mut this_ptr.get_native_mut_ref().timestamp;
479 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::PositiveTimestamp<>) as *mut _) }, is_owned: false }
481 /// generation time of the invoice
483 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
484 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
486 /// Checks if two RawDataParts contain equal inner contents.
487 /// This ignores pointers and is_owned flags and looks at the values in fields.
488 /// Two objects with NULL inner values will be considered "equal" here.
490 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
491 if a.inner == b.inner { return true; }
492 if a.inner.is_null() || b.inner.is_null() { return false; }
493 if a.get_native_ref() == b.get_native_ref() { true } else { false }
495 impl Clone for RawDataPart {
496 fn clone(&self) -> Self {
498 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { core::ptr::null_mut() } else {
499 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
505 /// Used only if an object of this type is returned as a trait impl by a method
506 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
507 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
510 /// Creates a copy of the RawDataPart
511 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
515 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
516 pub(crate) type nativePositiveTimestamp = nativePositiveTimestampImport;
518 /// A timestamp that refers to a date after 1 January 1970 which means its representation as UNIX
519 /// timestamp is positive.
522 /// The UNIX timestamp representing the stored time has to be positive and small enough so that
523 /// a `EpiryTime` can be added to it without an overflow.
526 pub struct PositiveTimestamp {
527 /// A pointer to the opaque Rust object.
529 /// Nearly everywhere, inner must be non-null, however in places where
530 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
531 pub inner: *mut nativePositiveTimestamp,
532 /// Indicates that this is the only struct which contains the same pointer.
534 /// Rust functions which take ownership of an object provided via an argument require
535 /// this to be true and invalidate the object pointed to by inner.
539 impl Drop for PositiveTimestamp {
541 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
542 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
546 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
548 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
550 /// Used only if an object of this type is returned as a trait impl by a method
551 pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
552 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
555 impl PositiveTimestamp {
556 pub(crate) fn get_native_ref(&self) -> &'static nativePositiveTimestamp {
557 unsafe { &*ObjOps::untweak_ptr(self.inner) }
559 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePositiveTimestamp {
560 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
562 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
563 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
564 assert!(self.is_owned);
565 let ret = ObjOps::untweak_ptr(self.inner);
566 self.inner = core::ptr::null_mut();
570 /// Checks if two PositiveTimestamps contain equal inner contents.
571 /// This ignores pointers and is_owned flags and looks at the values in fields.
572 /// Two objects with NULL inner values will be considered "equal" here.
574 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
575 if a.inner == b.inner { return true; }
576 if a.inner.is_null() || b.inner.is_null() { return false; }
577 if a.get_native_ref() == b.get_native_ref() { true } else { false }
579 impl Clone for PositiveTimestamp {
580 fn clone(&self) -> Self {
582 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { core::ptr::null_mut() } else {
583 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
589 /// Used only if an object of this type is returned as a trait impl by a method
590 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
591 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
594 /// Creates a copy of the PositiveTimestamp
595 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
598 /// SI prefixes for the human readable part
612 use lightning_invoice::SiPrefix as nativeSiPrefix;
615 pub(crate) fn to_native(&self) -> nativeSiPrefix {
617 SiPrefix::Milli => nativeSiPrefix::Milli,
618 SiPrefix::Micro => nativeSiPrefix::Micro,
619 SiPrefix::Nano => nativeSiPrefix::Nano,
620 SiPrefix::Pico => nativeSiPrefix::Pico,
624 pub(crate) fn into_native(self) -> nativeSiPrefix {
626 SiPrefix::Milli => nativeSiPrefix::Milli,
627 SiPrefix::Micro => nativeSiPrefix::Micro,
628 SiPrefix::Nano => nativeSiPrefix::Nano,
629 SiPrefix::Pico => nativeSiPrefix::Pico,
633 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
635 nativeSiPrefix::Milli => SiPrefix::Milli,
636 nativeSiPrefix::Micro => SiPrefix::Micro,
637 nativeSiPrefix::Nano => SiPrefix::Nano,
638 nativeSiPrefix::Pico => SiPrefix::Pico,
642 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
644 nativeSiPrefix::Milli => SiPrefix::Milli,
645 nativeSiPrefix::Micro => SiPrefix::Micro,
646 nativeSiPrefix::Nano => SiPrefix::Nano,
647 nativeSiPrefix::Pico => SiPrefix::Pico,
651 /// Creates a copy of the SiPrefix
653 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
657 /// Utility method to constructs a new Milli-variant SiPrefix
658 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
661 /// Utility method to constructs a new Micro-variant SiPrefix
662 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
665 /// Utility method to constructs a new Nano-variant SiPrefix
666 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
669 /// Utility method to constructs a new Pico-variant SiPrefix
670 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
672 /// Checks if two SiPrefixs contain equal inner contents.
673 /// This ignores pointers and is_owned flags and looks at the values in fields.
675 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
676 if &a.to_native() == &b.to_native() { true } else { false }
678 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
679 /// This is effectively 10^12 * the prefix multiplier
682 pub extern "C" fn SiPrefix_multiplier(this_arg: &SiPrefix) -> u64 {
683 let mut ret = this_arg.to_native().multiplier();
687 /// Enum representing the crypto currencies (or networks) supported by this library
703 use lightning_invoice::Currency as nativeCurrency;
706 pub(crate) fn to_native(&self) -> nativeCurrency {
708 Currency::Bitcoin => nativeCurrency::Bitcoin,
709 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
710 Currency::Regtest => nativeCurrency::Regtest,
711 Currency::Simnet => nativeCurrency::Simnet,
712 Currency::Signet => nativeCurrency::Signet,
716 pub(crate) fn into_native(self) -> nativeCurrency {
718 Currency::Bitcoin => nativeCurrency::Bitcoin,
719 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
720 Currency::Regtest => nativeCurrency::Regtest,
721 Currency::Simnet => nativeCurrency::Simnet,
722 Currency::Signet => nativeCurrency::Signet,
726 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
728 nativeCurrency::Bitcoin => Currency::Bitcoin,
729 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
730 nativeCurrency::Regtest => Currency::Regtest,
731 nativeCurrency::Simnet => Currency::Simnet,
732 nativeCurrency::Signet => Currency::Signet,
736 pub(crate) fn native_into(native: nativeCurrency) -> Self {
738 nativeCurrency::Bitcoin => Currency::Bitcoin,
739 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
740 nativeCurrency::Regtest => Currency::Regtest,
741 nativeCurrency::Simnet => Currency::Simnet,
742 nativeCurrency::Signet => Currency::Signet,
746 /// Creates a copy of the Currency
748 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
752 /// Utility method to constructs a new Bitcoin-variant Currency
753 pub extern "C" fn Currency_bitcoin() -> Currency {
756 /// Utility method to constructs a new BitcoinTestnet-variant Currency
757 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
758 Currency::BitcoinTestnet}
760 /// Utility method to constructs a new Regtest-variant Currency
761 pub extern "C" fn Currency_regtest() -> Currency {
764 /// Utility method to constructs a new Simnet-variant Currency
765 pub extern "C" fn Currency_simnet() -> Currency {
768 /// Utility method to constructs a new Signet-variant Currency
769 pub extern "C" fn Currency_signet() -> Currency {
771 /// Checks if two Currencys contain equal inner contents.
773 pub extern "C" fn Currency_hash(o: &Currency) -> u64 {
774 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
776 let mut hasher = core::hash::SipHasher::new();
777 core::hash::Hash::hash(&o.to_native(), &mut hasher);
778 core::hash::Hasher::finish(&hasher)
780 /// Checks if two Currencys contain equal inner contents.
781 /// This ignores pointers and is_owned flags and looks at the values in fields.
783 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
784 if &a.to_native() == &b.to_native() { true } else { false }
787 use lightning_invoice::Sha256 as nativeSha256Import;
788 pub(crate) type nativeSha256 = nativeSha256Import;
794 /// A pointer to the opaque Rust object.
796 /// Nearly everywhere, inner must be non-null, however in places where
797 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
798 pub inner: *mut nativeSha256,
799 /// Indicates that this is the only struct which contains the same pointer.
801 /// Rust functions which take ownership of an object provided via an argument require
802 /// this to be true and invalidate the object pointed to by inner.
806 impl Drop for Sha256 {
808 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
809 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
813 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
815 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
817 /// Used only if an object of this type is returned as a trait impl by a method
818 pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
819 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
823 pub(crate) fn get_native_ref(&self) -> &'static nativeSha256 {
824 unsafe { &*ObjOps::untweak_ptr(self.inner) }
826 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSha256 {
827 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
829 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
830 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
831 assert!(self.is_owned);
832 let ret = ObjOps::untweak_ptr(self.inner);
833 self.inner = core::ptr::null_mut();
837 impl Clone for Sha256 {
838 fn clone(&self) -> Self {
840 inner: if <*mut nativeSha256>::is_null(self.inner) { core::ptr::null_mut() } else {
841 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
847 /// Used only if an object of this type is returned as a trait impl by a method
848 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
849 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
852 /// Creates a copy of the Sha256
853 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
856 /// Checks if two Sha256s contain equal inner contents.
858 pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 {
859 if o.inner.is_null() { return 0; }
860 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
862 let mut hasher = core::hash::SipHasher::new();
863 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
864 core::hash::Hasher::finish(&hasher)
866 /// Checks if two Sha256s contain equal inner contents.
867 /// This ignores pointers and is_owned flags and looks at the values in fields.
868 /// Two objects with NULL inner values will be considered "equal" here.
870 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
871 if a.inner == b.inner { return true; }
872 if a.inner.is_null() || b.inner.is_null() { return false; }
873 if a.get_native_ref() == b.get_native_ref() { true } else { false }
876 use lightning_invoice::Description as nativeDescriptionImport;
877 pub(crate) type nativeDescription = nativeDescriptionImport;
879 /// Description string
882 /// The description can be at most 639 __bytes__ long
885 pub struct Description {
886 /// A pointer to the opaque Rust object.
888 /// Nearly everywhere, inner must be non-null, however in places where
889 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
890 pub inner: *mut nativeDescription,
891 /// Indicates that this is the only struct which contains the same pointer.
893 /// Rust functions which take ownership of an object provided via an argument require
894 /// this to be true and invalidate the object pointed to by inner.
898 impl Drop for Description {
900 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
901 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
905 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
907 pub extern "C" fn Description_free(this_obj: Description) { }
909 /// Used only if an object of this type is returned as a trait impl by a method
910 pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) {
911 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
915 pub(crate) fn get_native_ref(&self) -> &'static nativeDescription {
916 unsafe { &*ObjOps::untweak_ptr(self.inner) }
918 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDescription {
919 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
921 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
922 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
923 assert!(self.is_owned);
924 let ret = ObjOps::untweak_ptr(self.inner);
925 self.inner = core::ptr::null_mut();
929 impl Clone for Description {
930 fn clone(&self) -> Self {
932 inner: if <*mut nativeDescription>::is_null(self.inner) { core::ptr::null_mut() } else {
933 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
939 /// Used only if an object of this type is returned as a trait impl by a method
940 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
941 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
944 /// Creates a copy of the Description
945 pub extern "C" fn Description_clone(orig: &Description) -> Description {
948 /// Checks if two Descriptions contain equal inner contents.
950 pub extern "C" fn Description_hash(o: &Description) -> u64 {
951 if o.inner.is_null() { return 0; }
952 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
954 let mut hasher = core::hash::SipHasher::new();
955 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
956 core::hash::Hasher::finish(&hasher)
958 /// Checks if two Descriptions contain equal inner contents.
959 /// This ignores pointers and is_owned flags and looks at the values in fields.
960 /// Two objects with NULL inner values will be considered "equal" here.
962 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
963 if a.inner == b.inner { return true; }
964 if a.inner.is_null() || b.inner.is_null() { return false; }
965 if a.get_native_ref() == b.get_native_ref() { true } else { false }
968 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
969 pub(crate) type nativePayeePubKey = nativePayeePubKeyImport;
974 pub struct PayeePubKey {
975 /// A pointer to the opaque Rust object.
977 /// Nearly everywhere, inner must be non-null, however in places where
978 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
979 pub inner: *mut nativePayeePubKey,
980 /// Indicates that this is the only struct which contains the same pointer.
982 /// Rust functions which take ownership of an object provided via an argument require
983 /// this to be true and invalidate the object pointed to by inner.
987 impl Drop for PayeePubKey {
989 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
990 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
994 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
996 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
998 /// Used only if an object of this type is returned as a trait impl by a method
999 pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
1000 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
1004 pub(crate) fn get_native_ref(&self) -> &'static nativePayeePubKey {
1005 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1007 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayeePubKey {
1008 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1010 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1011 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
1012 assert!(self.is_owned);
1013 let ret = ObjOps::untweak_ptr(self.inner);
1014 self.inner = core::ptr::null_mut();
1019 pub extern "C" fn PayeePubKey_get_a(this_ptr: &PayeePubKey) -> crate::c_types::PublicKey {
1020 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1021 crate::c_types::PublicKey::from_rust(&inner_val)
1024 pub extern "C" fn PayeePubKey_set_a(this_ptr: &mut PayeePubKey, mut val: crate::c_types::PublicKey) {
1025 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
1027 /// Constructs a new PayeePubKey given each field
1030 pub extern "C" fn PayeePubKey_new(mut a_arg: crate::c_types::PublicKey) -> PayeePubKey {
1031 PayeePubKey { inner: ObjOps::heap_alloc(lightning_invoice::PayeePubKey (
1033 )), is_owned: true }
1035 impl Clone for PayeePubKey {
1036 fn clone(&self) -> Self {
1038 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { core::ptr::null_mut() } else {
1039 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1045 /// Used only if an object of this type is returned as a trait impl by a method
1046 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
1047 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
1050 /// Creates a copy of the PayeePubKey
1051 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
1054 /// Checks if two PayeePubKeys contain equal inner contents.
1056 pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 {
1057 if o.inner.is_null() { return 0; }
1058 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1059 #[allow(deprecated)]
1060 let mut hasher = core::hash::SipHasher::new();
1061 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1062 core::hash::Hasher::finish(&hasher)
1064 /// Checks if two PayeePubKeys contain equal inner contents.
1065 /// This ignores pointers and is_owned flags and looks at the values in fields.
1066 /// Two objects with NULL inner values will be considered "equal" here.
1068 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
1069 if a.inner == b.inner { return true; }
1070 if a.inner.is_null() || b.inner.is_null() { return false; }
1071 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1074 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
1075 pub(crate) type nativeExpiryTime = nativeExpiryTimeImport;
1077 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
1081 /// The number of seconds this expiry time represents has to be in the range
1082 /// `0...(SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME)` to avoid overflows when adding it to a
1086 pub struct ExpiryTime {
1087 /// A pointer to the opaque Rust object.
1089 /// Nearly everywhere, inner must be non-null, however in places where
1090 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1091 pub inner: *mut nativeExpiryTime,
1092 /// Indicates that this is the only struct which contains the same pointer.
1094 /// Rust functions which take ownership of an object provided via an argument require
1095 /// this to be true and invalidate the object pointed to by inner.
1099 impl Drop for ExpiryTime {
1100 fn drop(&mut self) {
1101 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
1102 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1106 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
1108 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
1110 /// Used only if an object of this type is returned as a trait impl by a method
1111 pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
1112 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
1116 pub(crate) fn get_native_ref(&self) -> &'static nativeExpiryTime {
1117 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1119 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpiryTime {
1120 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1122 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1123 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
1124 assert!(self.is_owned);
1125 let ret = ObjOps::untweak_ptr(self.inner);
1126 self.inner = core::ptr::null_mut();
1130 impl Clone for ExpiryTime {
1131 fn clone(&self) -> Self {
1133 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { core::ptr::null_mut() } else {
1134 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1140 /// Used only if an object of this type is returned as a trait impl by a method
1141 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1142 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1145 /// Creates a copy of the ExpiryTime
1146 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1149 /// Checks if two ExpiryTimes contain equal inner contents.
1151 pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 {
1152 if o.inner.is_null() { return 0; }
1153 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1154 #[allow(deprecated)]
1155 let mut hasher = core::hash::SipHasher::new();
1156 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1157 core::hash::Hasher::finish(&hasher)
1159 /// Checks if two ExpiryTimes contain equal inner contents.
1160 /// This ignores pointers and is_owned flags and looks at the values in fields.
1161 /// Two objects with NULL inner values will be considered "equal" here.
1163 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1164 if a.inner == b.inner { return true; }
1165 if a.inner.is_null() || b.inner.is_null() { return false; }
1166 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1169 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
1170 pub(crate) type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
1172 /// `min_final_cltv_expiry` to use for the last HTLC in the route
1175 pub struct MinFinalCltvExpiry {
1176 /// A pointer to the opaque Rust object.
1178 /// Nearly everywhere, inner must be non-null, however in places where
1179 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1180 pub inner: *mut nativeMinFinalCltvExpiry,
1181 /// Indicates that this is the only struct which contains the same pointer.
1183 /// Rust functions which take ownership of an object provided via an argument require
1184 /// this to be true and invalidate the object pointed to by inner.
1188 impl Drop for MinFinalCltvExpiry {
1189 fn drop(&mut self) {
1190 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
1191 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1195 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1197 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1199 /// Used only if an object of this type is returned as a trait impl by a method
1200 pub(crate) extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1201 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1204 impl MinFinalCltvExpiry {
1205 pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiry {
1206 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1208 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiry {
1209 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1211 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1212 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1213 assert!(self.is_owned);
1214 let ret = ObjOps::untweak_ptr(self.inner);
1215 self.inner = core::ptr::null_mut();
1220 pub extern "C" fn MinFinalCltvExpiry_get_a(this_ptr: &MinFinalCltvExpiry) -> u64 {
1221 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1225 pub extern "C" fn MinFinalCltvExpiry_set_a(this_ptr: &mut MinFinalCltvExpiry, mut val: u64) {
1226 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val;
1228 /// Constructs a new MinFinalCltvExpiry given each field
1231 pub extern "C" fn MinFinalCltvExpiry_new(mut a_arg: u64) -> MinFinalCltvExpiry {
1232 MinFinalCltvExpiry { inner: ObjOps::heap_alloc(lightning_invoice::MinFinalCltvExpiry (
1234 )), is_owned: true }
1236 impl Clone for MinFinalCltvExpiry {
1237 fn clone(&self) -> Self {
1239 inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { core::ptr::null_mut() } else {
1240 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1246 /// Used only if an object of this type is returned as a trait impl by a method
1247 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1248 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1251 /// Creates a copy of the MinFinalCltvExpiry
1252 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1255 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1257 pub extern "C" fn MinFinalCltvExpiry_hash(o: &MinFinalCltvExpiry) -> u64 {
1258 if o.inner.is_null() { return 0; }
1259 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1260 #[allow(deprecated)]
1261 let mut hasher = core::hash::SipHasher::new();
1262 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1263 core::hash::Hasher::finish(&hasher)
1265 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1266 /// This ignores pointers and is_owned flags and looks at the values in fields.
1267 /// Two objects with NULL inner values will be considered "equal" here.
1269 pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool {
1270 if a.inner == b.inner { return true; }
1271 if a.inner.is_null() || b.inner.is_null() { return false; }
1272 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1274 /// Fallback address in case no LN payment is possible
1280 version: crate::c_types::u5,
1281 program: crate::c_types::derived::CVec_u8Z,
1283 PubKeyHash(crate::c_types::TwentyBytes),
1284 ScriptHash(crate::c_types::TwentyBytes),
1286 use lightning_invoice::Fallback as nativeFallback;
1289 pub(crate) fn to_native(&self) -> nativeFallback {
1291 Fallback::SegWitProgram {ref version, ref program, } => {
1292 let mut version_nonref = (*version).clone();
1293 let mut program_nonref = (*program).clone();
1294 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1295 nativeFallback::SegWitProgram {
1296 version: version_nonref.into(),
1297 program: local_program_nonref,
1300 Fallback::PubKeyHash (ref a, ) => {
1301 let mut a_nonref = (*a).clone();
1302 nativeFallback::PubKeyHash (
1306 Fallback::ScriptHash (ref a, ) => {
1307 let mut a_nonref = (*a).clone();
1308 nativeFallback::ScriptHash (
1315 pub(crate) fn into_native(self) -> nativeFallback {
1317 Fallback::SegWitProgram {mut version, mut program, } => {
1318 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1319 nativeFallback::SegWitProgram {
1320 version: version.into(),
1321 program: local_program,
1324 Fallback::PubKeyHash (mut a, ) => {
1325 nativeFallback::PubKeyHash (
1329 Fallback::ScriptHash (mut a, ) => {
1330 nativeFallback::ScriptHash (
1337 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1339 nativeFallback::SegWitProgram {ref version, ref program, } => {
1340 let mut version_nonref = (*version).clone();
1341 let mut program_nonref = (*program).clone();
1342 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1343 Fallback::SegWitProgram {
1344 version: version_nonref.into(),
1345 program: local_program_nonref.into(),
1348 nativeFallback::PubKeyHash (ref a, ) => {
1349 let mut a_nonref = (*a).clone();
1350 Fallback::PubKeyHash (
1351 crate::c_types::TwentyBytes { data: a_nonref },
1354 nativeFallback::ScriptHash (ref a, ) => {
1355 let mut a_nonref = (*a).clone();
1356 Fallback::ScriptHash (
1357 crate::c_types::TwentyBytes { data: a_nonref },
1363 pub(crate) fn native_into(native: nativeFallback) -> Self {
1365 nativeFallback::SegWitProgram {mut version, mut program, } => {
1366 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1367 Fallback::SegWitProgram {
1368 version: version.into(),
1369 program: local_program.into(),
1372 nativeFallback::PubKeyHash (mut a, ) => {
1373 Fallback::PubKeyHash (
1374 crate::c_types::TwentyBytes { data: a },
1377 nativeFallback::ScriptHash (mut a, ) => {
1378 Fallback::ScriptHash (
1379 crate::c_types::TwentyBytes { data: a },
1385 /// Frees any resources used by the Fallback
1387 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1388 /// Creates a copy of the Fallback
1390 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1394 /// Utility method to constructs a new SegWitProgram-variant Fallback
1395 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::u5, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
1396 Fallback::SegWitProgram {
1402 /// Utility method to constructs a new PubKeyHash-variant Fallback
1403 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1404 Fallback::PubKeyHash(a, )
1407 /// Utility method to constructs a new ScriptHash-variant Fallback
1408 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1409 Fallback::ScriptHash(a, )
1411 /// Checks if two Fallbacks contain equal inner contents.
1413 pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 {
1414 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1415 #[allow(deprecated)]
1416 let mut hasher = core::hash::SipHasher::new();
1417 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1418 core::hash::Hasher::finish(&hasher)
1420 /// Checks if two Fallbacks contain equal inner contents.
1421 /// This ignores pointers and is_owned flags and looks at the values in fields.
1423 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1424 if &a.to_native() == &b.to_native() { true } else { false }
1427 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1428 pub(crate) type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1430 /// Recoverable signature
1433 pub struct InvoiceSignature {
1434 /// A pointer to the opaque Rust object.
1436 /// Nearly everywhere, inner must be non-null, however in places where
1437 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1438 pub inner: *mut nativeInvoiceSignature,
1439 /// Indicates that this is the only struct which contains the same pointer.
1441 /// Rust functions which take ownership of an object provided via an argument require
1442 /// this to be true and invalidate the object pointed to by inner.
1446 impl Drop for InvoiceSignature {
1447 fn drop(&mut self) {
1448 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1449 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1453 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1455 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1457 /// Used only if an object of this type is returned as a trait impl by a method
1458 pub(crate) extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1459 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1462 impl InvoiceSignature {
1463 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceSignature {
1464 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1466 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceSignature {
1467 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1469 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1470 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1471 assert!(self.is_owned);
1472 let ret = ObjOps::untweak_ptr(self.inner);
1473 self.inner = core::ptr::null_mut();
1477 impl Clone for InvoiceSignature {
1478 fn clone(&self) -> Self {
1480 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { core::ptr::null_mut() } else {
1481 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1487 /// Used only if an object of this type is returned as a trait impl by a method
1488 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
1489 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
1492 /// Creates a copy of the InvoiceSignature
1493 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
1496 /// Checks if two InvoiceSignatures contain equal inner contents.
1497 /// This ignores pointers and is_owned flags and looks at the values in fields.
1498 /// Two objects with NULL inner values will be considered "equal" here.
1500 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
1501 if a.inner == b.inner { return true; }
1502 if a.inner.is_null() || b.inner.is_null() { return false; }
1503 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1506 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
1507 pub(crate) type nativePrivateRoute = nativePrivateRouteImport;
1509 /// Private routing information
1512 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
1516 pub struct PrivateRoute {
1517 /// A pointer to the opaque Rust object.
1519 /// Nearly everywhere, inner must be non-null, however in places where
1520 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1521 pub inner: *mut nativePrivateRoute,
1522 /// Indicates that this is the only struct which contains the same pointer.
1524 /// Rust functions which take ownership of an object provided via an argument require
1525 /// this to be true and invalidate the object pointed to by inner.
1529 impl Drop for PrivateRoute {
1530 fn drop(&mut self) {
1531 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
1532 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1536 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
1538 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
1540 /// Used only if an object of this type is returned as a trait impl by a method
1541 pub(crate) extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
1542 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); }
1546 pub(crate) fn get_native_ref(&self) -> &'static nativePrivateRoute {
1547 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1549 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateRoute {
1550 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1552 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1553 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
1554 assert!(self.is_owned);
1555 let ret = ObjOps::untweak_ptr(self.inner);
1556 self.inner = core::ptr::null_mut();
1560 impl Clone for PrivateRoute {
1561 fn clone(&self) -> Self {
1563 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
1564 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1570 /// Used only if an object of this type is returned as a trait impl by a method
1571 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
1572 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
1575 /// Creates a copy of the PrivateRoute
1576 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
1579 /// Checks if two PrivateRoutes contain equal inner contents.
1581 pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 {
1582 if o.inner.is_null() { return 0; }
1583 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1584 #[allow(deprecated)]
1585 let mut hasher = core::hash::SipHasher::new();
1586 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1587 core::hash::Hasher::finish(&hasher)
1589 /// Checks if two PrivateRoutes contain equal inner contents.
1590 /// This ignores pointers and is_owned flags and looks at the values in fields.
1591 /// Two objects with NULL inner values will be considered "equal" here.
1593 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
1594 if a.inner == b.inner { return true; }
1595 if a.inner.is_null() || b.inner.is_null() { return false; }
1596 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1598 /// Disassembles the `SignedRawInvoice` into its three parts:
1600 /// 2. hash of the raw invoice
1604 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
1605 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
1606 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();
1610 /// The `RawInvoice` which was signed.
1613 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
1614 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice();
1615 crate::lightning_invoice::RawInvoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawInvoice<>) as *mut _) }, is_owned: false }
1618 /// The hash of the `RawInvoice` that was signed.
1621 pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [u8; 32] {
1622 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
1626 /// InvoiceSignature for the invoice.
1629 pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
1630 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
1631 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::InvoiceSignature<>) as *mut _) }, is_owned: false }
1634 /// Recovers the public key used for signing the invoice from the recoverable signature.
1637 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
1638 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
1639 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() };
1643 /// Checks if the signature is valid for the included payee public key or if none exists if it's
1644 /// valid for the recovered signature (which should always be true?).
1647 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &SignedRawInvoice) -> bool {
1648 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
1652 /// Calculate the hash of the encoded `RawInvoice`
1655 pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1656 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
1657 crate::c_types::ThirtyTwoBytes { data: ret }
1661 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1664 pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1665 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
1666 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 };
1671 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1674 pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightning_invoice::Description {
1675 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
1676 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 };
1681 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1684 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::lightning_invoice::PayeePubKey {
1685 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
1686 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 };
1691 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1694 pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1695 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash();
1696 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 };
1701 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1704 pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightning_invoice::ExpiryTime {
1705 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
1706 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 };
1711 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1714 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
1715 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
1716 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 };
1721 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1724 pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1725 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
1726 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1731 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1734 pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
1735 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
1736 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 };
1742 pub extern "C" fn RawInvoice_private_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1743 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
1744 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 } }); };
1750 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z {
1751 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
1752 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() }) };
1758 pub extern "C" fn RawInvoice_currency(this_arg: &RawInvoice) -> crate::lightning_invoice::Currency {
1759 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
1760 crate::lightning_invoice::Currency::native_into(ret)
1763 /// Create a new `PositiveTimestamp` from a unix timestamp in the Range
1764 /// `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1765 /// `CreationError::TimestampOutOfBounds`.
1768 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1769 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
1770 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() };
1774 /// Create a new `PositiveTimestamp` from a `SystemTime` with a corresponding unix timestamp in
1775 /// the Range `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1776 /// `CreationError::TimestampOutOfBounds`.
1779 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1780 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
1781 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() };
1785 /// Returns the UNIX timestamp representing the stored time
1788 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 {
1789 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_unix_timestamp();
1793 /// Returns a reference to the internal `SystemTime` time representation
1796 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &PositiveTimestamp) -> u64 {
1797 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_time();
1798 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1801 /// Transform the `Invoice` into it's unchecked version
1804 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::lightning_invoice::SignedRawInvoice {
1805 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
1806 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(ret), is_owned: true }
1809 /// Check that the invoice is signed correctly and that key recovery works
1812 pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
1813 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
1814 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() };
1818 /// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
1820 /// use lightning_invoice::*;
1822 /// let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
1823 /// h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
1824 /// 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
1825 /// h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
1826 /// j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
1827 /// ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
1828 /// guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
1829 /// ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
1830 /// p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
1831 /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
1832 /// j5r6drg6k6zcqj0fcwg\";
1834 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
1836 /// assert!(Invoice::from_signed(signed).is_ok());
1840 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
1841 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
1842 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() };
1846 /// Returns the `Invoice`'s timestamp (should equal it's creation time)
1849 pub extern "C" fn Invoice_timestamp(this_arg: &Invoice) -> u64 {
1850 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timestamp();
1851 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1854 /// Returns the hash to which we will receive the preimage on completion of the payment
1857 pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] {
1858 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
1862 /// Get the payee's public key if one was included in the invoice
1864 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1867 pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1868 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
1869 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
1873 /// Get the payment secret if one was included in the invoice
1876 pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> *const [u8; 32] {
1877 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
1881 /// Get the invoice features if they were included in the invoice
1883 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1886 pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
1887 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
1888 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 };
1892 /// Recover the payee's public key (only to be used if none was included in the invoice)
1895 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1896 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
1897 crate::c_types::PublicKey::from_rust(&ret)
1900 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
1903 pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 {
1904 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
1908 /// Returns whether the invoice has expired.
1911 pub extern "C" fn Invoice_is_expired(this_arg: &Invoice) -> bool {
1912 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
1916 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
1917 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
1920 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 {
1921 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
1925 /// Returns a list of all routes included in the invoice
1928 pub extern "C" fn Invoice_private_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1929 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
1930 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 } }); };
1934 /// Returns a list of all routes included in the invoice as the underlying hints
1937 pub extern "C" fn Invoice_route_hints(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
1938 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints();
1939 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 } }); };
1943 /// Returns the currency for which the invoice was issued
1946 pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoice::Currency {
1947 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
1948 crate::lightning_invoice::Currency::native_into(ret)
1951 /// Returns the amount if specified in the invoice as millisatoshis.
1954 pub extern "C" fn Invoice_amount_milli_satoshis(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z {
1955 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_milli_satoshis();
1956 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() }) };
1960 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
1961 /// returns `CreationError::DescriptionTooLong` otherwise
1963 /// Please note that single characters may use more than one byte due to UTF8 encoding.
1966 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
1967 let mut ret = lightning_invoice::Description::new(description.into_string());
1968 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() };
1972 /// Returns the underlying description `String`
1975 pub extern "C" fn Description_into_inner(mut this_arg: Description) -> crate::c_types::Str {
1976 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1980 /// Construct an `ExpiryTime` from seconds. If there exists a `PositiveTimestamp` which would
1981 /// overflow on adding the `EpiryTime` to it then this function will return a
1982 /// `CreationError::ExpiryTimeOutOfBounds`.
1985 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1986 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
1987 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::ExpiryTime { 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() };
1991 /// Construct an `ExpiryTime` from a `Duration`. If there exists a `PositiveTimestamp` which
1992 /// would overflow on adding the `EpiryTime` to it then this function will return a
1993 /// `CreationError::ExpiryTimeOutOfBounds`.
1996 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1997 let mut ret = lightning_invoice::ExpiryTime::from_duration(core::time::Duration::from_secs(duration));
1998 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::ExpiryTime { 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() };
2002 /// Returns the expiry time in seconds
2005 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 {
2006 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_seconds();
2010 /// Returns a reference to the underlying `Duration` (=expiry time)
2013 pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 {
2014 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration();
2018 /// Creates a new (partial) route from a list of hops
2021 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
2022 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
2023 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() };
2027 /// Returns the underlying list of hops
2030 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: PrivateRoute) -> crate::lightning::routing::router::RouteHint {
2031 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2032 crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true }
2035 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
2039 pub enum CreationError {
2040 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
2042 /// The specified route has too many hops and can't be encoded
2044 /// The unix timestamp of the supplied date is <0 or can't be represented as `SystemTime`
2045 TimestampOutOfBounds,
2046 /// The supplied expiry time could cause an overflow if added to a `PositiveTimestamp`
2047 ExpiryTimeOutOfBounds,
2048 /// The supplied millisatoshi amount was greater than the total bitcoin supply.
2051 use lightning_invoice::CreationError as nativeCreationError;
2052 impl CreationError {
2054 pub(crate) fn to_native(&self) -> nativeCreationError {
2056 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2057 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2058 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2059 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
2060 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2064 pub(crate) fn into_native(self) -> nativeCreationError {
2066 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2067 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2068 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2069 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
2070 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2074 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
2076 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2077 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2078 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2079 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
2080 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2084 pub(crate) fn native_into(native: nativeCreationError) -> Self {
2086 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2087 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2088 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2089 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
2090 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2094 /// Creates a copy of the CreationError
2096 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
2100 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
2101 pub extern "C" fn CreationError_description_too_long() -> CreationError {
2102 CreationError::DescriptionTooLong}
2104 /// Utility method to constructs a new RouteTooLong-variant CreationError
2105 pub extern "C" fn CreationError_route_too_long() -> CreationError {
2106 CreationError::RouteTooLong}
2108 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
2109 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
2110 CreationError::TimestampOutOfBounds}
2112 /// Utility method to constructs a new ExpiryTimeOutOfBounds-variant CreationError
2113 pub extern "C" fn CreationError_expiry_time_out_of_bounds() -> CreationError {
2114 CreationError::ExpiryTimeOutOfBounds}
2116 /// Utility method to constructs a new InvalidAmount-variant CreationError
2117 pub extern "C" fn CreationError_invalid_amount() -> CreationError {
2118 CreationError::InvalidAmount}
2119 /// Checks if two CreationErrors contain equal inner contents.
2120 /// This ignores pointers and is_owned flags and looks at the values in fields.
2122 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
2123 if &a.to_native() == &b.to_native() { true } else { false }
2126 /// Get the string representation of a CreationError object
2127 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
2128 format!("{}", &o.to_native()).into()
2130 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
2131 /// requirements sections in BOLT #11
2135 pub enum SemanticError {
2136 /// The invoice is missing the mandatory payment hash
2138 /// The invoice has multiple payment hashes which isn't allowed
2139 MultiplePaymentHashes,
2140 /// No description or description hash are part of the invoice
2142 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
2143 MultipleDescriptions,
2144 /// The invoice is missing the mandatory payment secret, which all modern lightning nodes
2147 /// The invoice contains multiple payment secrets
2148 MultiplePaymentSecrets,
2149 /// The invoice's features are invalid
2151 /// The recovery id doesn't fit the signature/pub key
2153 /// The invoice's signature is invalid
2155 /// The invoice's amount was not a whole number of millisatoshis
2158 use lightning_invoice::SemanticError as nativeSemanticError;
2159 impl SemanticError {
2161 pub(crate) fn to_native(&self) -> nativeSemanticError {
2163 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2164 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2165 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2166 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2167 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2168 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2169 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2170 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2171 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2172 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2176 pub(crate) fn into_native(self) -> nativeSemanticError {
2178 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2179 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2180 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2181 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2182 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2183 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2184 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2185 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2186 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2187 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2191 pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
2193 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2194 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2195 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2196 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2197 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2198 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2199 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2200 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2201 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2202 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2206 pub(crate) fn native_into(native: nativeSemanticError) -> Self {
2208 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2209 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2210 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2211 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2212 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2213 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2214 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2215 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2216 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2217 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2221 /// Creates a copy of the SemanticError
2223 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
2227 /// Utility method to constructs a new NoPaymentHash-variant SemanticError
2228 pub extern "C" fn SemanticError_no_payment_hash() -> SemanticError {
2229 SemanticError::NoPaymentHash}
2231 /// Utility method to constructs a new MultiplePaymentHashes-variant SemanticError
2232 pub extern "C" fn SemanticError_multiple_payment_hashes() -> SemanticError {
2233 SemanticError::MultiplePaymentHashes}
2235 /// Utility method to constructs a new NoDescription-variant SemanticError
2236 pub extern "C" fn SemanticError_no_description() -> SemanticError {
2237 SemanticError::NoDescription}
2239 /// Utility method to constructs a new MultipleDescriptions-variant SemanticError
2240 pub extern "C" fn SemanticError_multiple_descriptions() -> SemanticError {
2241 SemanticError::MultipleDescriptions}
2243 /// Utility method to constructs a new NoPaymentSecret-variant SemanticError
2244 pub extern "C" fn SemanticError_no_payment_secret() -> SemanticError {
2245 SemanticError::NoPaymentSecret}
2247 /// Utility method to constructs a new MultiplePaymentSecrets-variant SemanticError
2248 pub extern "C" fn SemanticError_multiple_payment_secrets() -> SemanticError {
2249 SemanticError::MultiplePaymentSecrets}
2251 /// Utility method to constructs a new InvalidFeatures-variant SemanticError
2252 pub extern "C" fn SemanticError_invalid_features() -> SemanticError {
2253 SemanticError::InvalidFeatures}
2255 /// Utility method to constructs a new InvalidRecoveryId-variant SemanticError
2256 pub extern "C" fn SemanticError_invalid_recovery_id() -> SemanticError {
2257 SemanticError::InvalidRecoveryId}
2259 /// Utility method to constructs a new InvalidSignature-variant SemanticError
2260 pub extern "C" fn SemanticError_invalid_signature() -> SemanticError {
2261 SemanticError::InvalidSignature}
2263 /// Utility method to constructs a new ImpreciseAmount-variant SemanticError
2264 pub extern "C" fn SemanticError_imprecise_amount() -> SemanticError {
2265 SemanticError::ImpreciseAmount}
2266 /// Checks if two SemanticErrors contain equal inner contents.
2267 /// This ignores pointers and is_owned flags and looks at the values in fields.
2269 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
2270 if &a.to_native() == &b.to_native() { true } else { false }
2273 /// Get the string representation of a SemanticError object
2274 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
2275 format!("{}", &o.to_native()).into()
2277 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
2282 pub enum SignOrCreationError {
2283 /// An error occurred during signing
2285 /// An error occurred while building the transaction
2286 CreationError(crate::lightning_invoice::CreationError),
2288 use lightning_invoice::SignOrCreationError as nativeSignOrCreationError;
2289 impl SignOrCreationError {
2291 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
2293 SignOrCreationError::SignError => {
2294 nativeSignOrCreationError::SignError (
2298 SignOrCreationError::CreationError (ref a, ) => {
2299 let mut a_nonref = (*a).clone();
2300 nativeSignOrCreationError::CreationError (
2301 a_nonref.into_native(),
2307 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
2309 SignOrCreationError::SignError => {
2310 nativeSignOrCreationError::SignError (
2314 SignOrCreationError::CreationError (mut a, ) => {
2315 nativeSignOrCreationError::CreationError (
2322 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
2324 nativeSignOrCreationError::SignError (ref a, ) => {
2325 SignOrCreationError::SignError },
2326 nativeSignOrCreationError::CreationError (ref a, ) => {
2327 let mut a_nonref = (*a).clone();
2328 SignOrCreationError::CreationError (
2329 crate::lightning_invoice::CreationError::native_into(a_nonref),
2335 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
2337 nativeSignOrCreationError::SignError (mut a, ) => {
2338 SignOrCreationError::SignError },
2339 nativeSignOrCreationError::CreationError (mut a, ) => {
2340 SignOrCreationError::CreationError (
2341 crate::lightning_invoice::CreationError::native_into(a),
2347 /// Frees any resources used by the SignOrCreationError
2349 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
2350 /// Creates a copy of the SignOrCreationError
2352 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
2356 /// Utility method to constructs a new SignError-variant SignOrCreationError
2357 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
2358 SignOrCreationError::SignError
2361 /// Utility method to constructs a new CreationError-variant SignOrCreationError
2362 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
2363 SignOrCreationError::CreationError(a, )
2365 /// Checks if two SignOrCreationErrors contain equal inner contents.
2366 /// This ignores pointers and is_owned flags and looks at the values in fields.
2368 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
2369 if &a.to_native() == &b.to_native() { true } else { false }
2372 /// Get the string representation of a SignOrCreationError object
2373 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
2374 format!("{}", &o.to_native()).into()