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 alloc::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 alloc::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 alloc::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 alloc::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};
131 use alloc::str::FromStr;
132 use core::ffi::c_void;
133 use core::convert::Infallible;
134 use bitcoin::hashes::Hash;
135 use crate::c_types::*;
136 #[cfg(feature="no-std")]
137 use alloc::{vec::Vec, boxed::Box};
142 use alloc::str::FromStr;
143 use core::ffi::c_void;
144 use core::convert::Infallible;
145 use bitcoin::hashes::Hash;
146 use crate::c_types::*;
147 #[cfg(feature="no-std")]
148 use alloc::{vec::Vec, boxed::Box};
151 /// The maximum timestamp as [`Duration::as_secs`] since the Unix epoch allowed by [`BOLT 11`].
153 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
156 pub static MAX_TIMESTAMP: u64 = lightning_invoice::MAX_TIMESTAMP;
157 /// Default expiry time as defined by [BOLT 11].
159 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
162 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
163 /// Default minimum final CLTV expiry as defined by [BOLT 11].
165 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
166 /// provided in [`MIN_FINAL_CLTV_EXPIRY`].
168 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
169 /// [`MIN_FINAL_CLTV_EXPIRY`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY
172 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY;
174 use lightning_invoice::Invoice as nativeInvoiceImport;
175 pub(crate) type nativeInvoice = nativeInvoiceImport;
177 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
179 /// There are three ways to construct an `Invoice`:
180 /// 1. using `InvoiceBuilder`
181 /// 2. using `Invoice::from_signed(SignedRawInvoice)`
182 /// 3. using `str::parse::<Invoice>(&str)`
186 /// A pointer to the opaque Rust object.
188 /// Nearly everywhere, inner must be non-null, however in places where
189 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
190 pub inner: *mut nativeInvoice,
191 /// Indicates that this is the only struct which contains the same pointer.
193 /// Rust functions which take ownership of an object provided via an argument require
194 /// this to be true and invalidate the object pointed to by inner.
198 impl Drop for Invoice {
200 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
201 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
205 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
207 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
209 /// Used only if an object of this type is returned as a trait impl by a method
210 pub(crate) extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
211 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
215 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoice {
216 unsafe { &*ObjOps::untweak_ptr(self.inner) }
218 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoice {
219 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
221 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
222 pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
223 assert!(self.is_owned);
224 let ret = ObjOps::untweak_ptr(self.inner);
225 self.inner = core::ptr::null_mut();
229 /// Checks if two Invoices contain equal inner contents.
230 /// This ignores pointers and is_owned flags and looks at the values in fields.
231 /// Two objects with NULL inner values will be considered "equal" here.
233 pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool {
234 if a.inner == b.inner { return true; }
235 if a.inner.is_null() || b.inner.is_null() { return false; }
236 if a.get_native_ref() == b.get_native_ref() { true } else { false }
238 impl Clone for Invoice {
239 fn clone(&self) -> Self {
241 inner: if <*mut nativeInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
242 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
248 /// Used only if an object of this type is returned as a trait impl by a method
249 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
250 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
253 /// Creates a copy of the Invoice
254 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
258 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
259 pub(crate) type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
261 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
265 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
268 pub struct SignedRawInvoice {
269 /// A pointer to the opaque Rust object.
271 /// Nearly everywhere, inner must be non-null, however in places where
272 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
273 pub inner: *mut nativeSignedRawInvoice,
274 /// Indicates that this is the only struct which contains the same pointer.
276 /// Rust functions which take ownership of an object provided via an argument require
277 /// this to be true and invalidate the object pointed to by inner.
281 impl Drop for SignedRawInvoice {
283 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
284 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
288 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
290 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
292 /// Used only if an object of this type is returned as a trait impl by a method
293 pub(crate) extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
294 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
297 impl SignedRawInvoice {
298 pub(crate) fn get_native_ref(&self) -> &'static nativeSignedRawInvoice {
299 unsafe { &*ObjOps::untweak_ptr(self.inner) }
301 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSignedRawInvoice {
302 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
304 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
305 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
306 assert!(self.is_owned);
307 let ret = ObjOps::untweak_ptr(self.inner);
308 self.inner = core::ptr::null_mut();
312 /// Checks if two SignedRawInvoices contain equal inner contents.
313 /// This ignores pointers and is_owned flags and looks at the values in fields.
314 /// Two objects with NULL inner values will be considered "equal" here.
316 pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice) -> bool {
317 if a.inner == b.inner { return true; }
318 if a.inner.is_null() || b.inner.is_null() { return false; }
319 if a.get_native_ref() == b.get_native_ref() { true } else { false }
321 impl Clone for SignedRawInvoice {
322 fn clone(&self) -> Self {
324 inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
325 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
331 /// Used only if an object of this type is returned as a trait impl by a method
332 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
333 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
336 /// Creates a copy of the SignedRawInvoice
337 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
341 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
342 pub(crate) type nativeRawInvoice = nativeRawInvoiceImport;
344 /// Represents an syntactically correct Invoice for a payment on the lightning network,
345 /// but without the signature information.
346 /// De- and encoding should not lead to information loss but may lead to different hashes.
348 /// For methods without docs see the corresponding methods in `Invoice`.
351 pub struct RawInvoice {
352 /// A pointer to the opaque Rust object.
354 /// Nearly everywhere, inner must be non-null, however in places where
355 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
356 pub inner: *mut nativeRawInvoice,
357 /// Indicates that this is the only struct which contains the same pointer.
359 /// Rust functions which take ownership of an object provided via an argument require
360 /// this to be true and invalidate the object pointed to by inner.
364 impl Drop for RawInvoice {
366 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
367 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
371 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
373 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
375 /// Used only if an object of this type is returned as a trait impl by a method
376 pub(crate) extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
377 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
381 pub(crate) fn get_native_ref(&self) -> &'static nativeRawInvoice {
382 unsafe { &*ObjOps::untweak_ptr(self.inner) }
384 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawInvoice {
385 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
387 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
388 pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
389 assert!(self.is_owned);
390 let ret = ObjOps::untweak_ptr(self.inner);
391 self.inner = core::ptr::null_mut();
397 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
398 let mut inner_val = &mut this_ptr.get_native_mut_ref().data;
399 crate::lightning_invoice::RawDataPart { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::RawDataPart<>) as *mut _) }, is_owned: false }
403 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
404 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.data = *unsafe { Box::from_raw(val.take_inner()) };
406 /// Checks if two RawInvoices contain equal inner contents.
407 /// This ignores pointers and is_owned flags and looks at the values in fields.
408 /// Two objects with NULL inner values will be considered "equal" here.
410 pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool {
411 if a.inner == b.inner { return true; }
412 if a.inner.is_null() || b.inner.is_null() { return false; }
413 if a.get_native_ref() == b.get_native_ref() { true } else { false }
415 impl Clone for RawInvoice {
416 fn clone(&self) -> Self {
418 inner: if <*mut nativeRawInvoice>::is_null(self.inner) { core::ptr::null_mut() } else {
419 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
425 /// Used only if an object of this type is returned as a trait impl by a method
426 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
427 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
430 /// Creates a copy of the RawInvoice
431 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
435 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
436 pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
438 /// Data of the `RawInvoice` that is encoded in the data part
441 pub struct RawDataPart {
442 /// A pointer to the opaque Rust object.
444 /// Nearly everywhere, inner must be non-null, however in places where
445 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
446 pub inner: *mut nativeRawDataPart,
447 /// Indicates that this is the only struct which contains the same pointer.
449 /// Rust functions which take ownership of an object provided via an argument require
450 /// this to be true and invalidate the object pointed to by inner.
454 impl Drop for RawDataPart {
456 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
457 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
461 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
463 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
465 /// Used only if an object of this type is returned as a trait impl by a method
466 pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
467 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
471 pub(crate) fn get_native_ref(&self) -> &'static nativeRawDataPart {
472 unsafe { &*ObjOps::untweak_ptr(self.inner) }
474 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawDataPart {
475 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
477 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
478 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
479 assert!(self.is_owned);
480 let ret = ObjOps::untweak_ptr(self.inner);
481 self.inner = core::ptr::null_mut();
485 /// generation time of the invoice
487 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
488 let mut inner_val = &mut this_ptr.get_native_mut_ref().timestamp;
489 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::PositiveTimestamp<>) as *mut _) }, is_owned: false }
491 /// generation time of the invoice
493 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
494 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
496 /// Checks if two RawDataParts contain equal inner contents.
497 /// This ignores pointers and is_owned flags and looks at the values in fields.
498 /// Two objects with NULL inner values will be considered "equal" here.
500 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
501 if a.inner == b.inner { return true; }
502 if a.inner.is_null() || b.inner.is_null() { return false; }
503 if a.get_native_ref() == b.get_native_ref() { true } else { false }
505 impl Clone for RawDataPart {
506 fn clone(&self) -> Self {
508 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { core::ptr::null_mut() } else {
509 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
515 /// Used only if an object of this type is returned as a trait impl by a method
516 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
517 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
520 /// Creates a copy of the RawDataPart
521 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
525 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
526 pub(crate) type nativePositiveTimestamp = nativePositiveTimestampImport;
528 /// A timestamp that refers to a date after 1 January 1970.
532 /// The Unix timestamp representing the stored time has to be positive and no greater than
533 /// [`MAX_TIMESTAMP`].
536 pub struct PositiveTimestamp {
537 /// A pointer to the opaque Rust object.
539 /// Nearly everywhere, inner must be non-null, however in places where
540 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
541 pub inner: *mut nativePositiveTimestamp,
542 /// Indicates that this is the only struct which contains the same pointer.
544 /// Rust functions which take ownership of an object provided via an argument require
545 /// this to be true and invalidate the object pointed to by inner.
549 impl Drop for PositiveTimestamp {
551 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
552 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
556 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
558 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
560 /// Used only if an object of this type is returned as a trait impl by a method
561 pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
562 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
565 impl PositiveTimestamp {
566 pub(crate) fn get_native_ref(&self) -> &'static nativePositiveTimestamp {
567 unsafe { &*ObjOps::untweak_ptr(self.inner) }
569 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePositiveTimestamp {
570 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
572 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
573 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
574 assert!(self.is_owned);
575 let ret = ObjOps::untweak_ptr(self.inner);
576 self.inner = core::ptr::null_mut();
580 /// Checks if two PositiveTimestamps contain equal inner contents.
581 /// This ignores pointers and is_owned flags and looks at the values in fields.
582 /// Two objects with NULL inner values will be considered "equal" here.
584 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
585 if a.inner == b.inner { return true; }
586 if a.inner.is_null() || b.inner.is_null() { return false; }
587 if a.get_native_ref() == b.get_native_ref() { true } else { false }
589 impl Clone for PositiveTimestamp {
590 fn clone(&self) -> Self {
592 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { core::ptr::null_mut() } else {
593 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
599 /// Used only if an object of this type is returned as a trait impl by a method
600 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
601 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
604 /// Creates a copy of the PositiveTimestamp
605 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
608 /// SI prefixes for the human readable part
622 use lightning_invoice::SiPrefix as nativeSiPrefix;
625 pub(crate) fn to_native(&self) -> nativeSiPrefix {
627 SiPrefix::Milli => nativeSiPrefix::Milli,
628 SiPrefix::Micro => nativeSiPrefix::Micro,
629 SiPrefix::Nano => nativeSiPrefix::Nano,
630 SiPrefix::Pico => nativeSiPrefix::Pico,
634 pub(crate) fn into_native(self) -> nativeSiPrefix {
636 SiPrefix::Milli => nativeSiPrefix::Milli,
637 SiPrefix::Micro => nativeSiPrefix::Micro,
638 SiPrefix::Nano => nativeSiPrefix::Nano,
639 SiPrefix::Pico => nativeSiPrefix::Pico,
643 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
645 nativeSiPrefix::Milli => SiPrefix::Milli,
646 nativeSiPrefix::Micro => SiPrefix::Micro,
647 nativeSiPrefix::Nano => SiPrefix::Nano,
648 nativeSiPrefix::Pico => SiPrefix::Pico,
652 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
654 nativeSiPrefix::Milli => SiPrefix::Milli,
655 nativeSiPrefix::Micro => SiPrefix::Micro,
656 nativeSiPrefix::Nano => SiPrefix::Nano,
657 nativeSiPrefix::Pico => SiPrefix::Pico,
661 /// Creates a copy of the SiPrefix
663 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
667 /// Utility method to constructs a new Milli-variant SiPrefix
668 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
671 /// Utility method to constructs a new Micro-variant SiPrefix
672 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
675 /// Utility method to constructs a new Nano-variant SiPrefix
676 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
679 /// Utility method to constructs a new Pico-variant SiPrefix
680 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
682 /// Checks if two SiPrefixs contain equal inner contents.
683 /// This ignores pointers and is_owned flags and looks at the values in fields.
685 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
686 if &a.to_native() == &b.to_native() { true } else { false }
688 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
689 /// This is effectively 10^12 * the prefix multiplier
692 pub extern "C" fn SiPrefix_multiplier(this_arg: &SiPrefix) -> u64 {
693 let mut ret = this_arg.to_native().multiplier();
697 /// Enum representing the crypto currencies (or networks) supported by this library
713 use lightning_invoice::Currency as nativeCurrency;
716 pub(crate) fn to_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 into_native(self) -> nativeCurrency {
728 Currency::Bitcoin => nativeCurrency::Bitcoin,
729 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
730 Currency::Regtest => nativeCurrency::Regtest,
731 Currency::Simnet => nativeCurrency::Simnet,
732 Currency::Signet => nativeCurrency::Signet,
736 pub(crate) fn from_native(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 pub(crate) fn native_into(native: nativeCurrency) -> Self {
748 nativeCurrency::Bitcoin => Currency::Bitcoin,
749 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
750 nativeCurrency::Regtest => Currency::Regtest,
751 nativeCurrency::Simnet => Currency::Simnet,
752 nativeCurrency::Signet => Currency::Signet,
756 /// Creates a copy of the Currency
758 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
762 /// Utility method to constructs a new Bitcoin-variant Currency
763 pub extern "C" fn Currency_bitcoin() -> Currency {
766 /// Utility method to constructs a new BitcoinTestnet-variant Currency
767 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
768 Currency::BitcoinTestnet}
770 /// Utility method to constructs a new Regtest-variant Currency
771 pub extern "C" fn Currency_regtest() -> Currency {
774 /// Utility method to constructs a new Simnet-variant Currency
775 pub extern "C" fn Currency_simnet() -> Currency {
778 /// Utility method to constructs a new Signet-variant Currency
779 pub extern "C" fn Currency_signet() -> Currency {
781 /// Checks if two Currencys contain equal inner contents.
783 pub extern "C" fn Currency_hash(o: &Currency) -> u64 {
784 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
786 let mut hasher = core::hash::SipHasher::new();
787 core::hash::Hash::hash(&o.to_native(), &mut hasher);
788 core::hash::Hasher::finish(&hasher)
790 /// Checks if two Currencys contain equal inner contents.
791 /// This ignores pointers and is_owned flags and looks at the values in fields.
793 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
794 if &a.to_native() == &b.to_native() { true } else { false }
797 use lightning_invoice::Sha256 as nativeSha256Import;
798 pub(crate) type nativeSha256 = nativeSha256Import;
804 /// A pointer to the opaque Rust object.
806 /// Nearly everywhere, inner must be non-null, however in places where
807 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
808 pub inner: *mut nativeSha256,
809 /// Indicates that this is the only struct which contains the same pointer.
811 /// Rust functions which take ownership of an object provided via an argument require
812 /// this to be true and invalidate the object pointed to by inner.
816 impl Drop for Sha256 {
818 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
819 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
823 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
825 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
827 /// Used only if an object of this type is returned as a trait impl by a method
828 pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
829 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
833 pub(crate) fn get_native_ref(&self) -> &'static nativeSha256 {
834 unsafe { &*ObjOps::untweak_ptr(self.inner) }
836 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSha256 {
837 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
839 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
840 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
841 assert!(self.is_owned);
842 let ret = ObjOps::untweak_ptr(self.inner);
843 self.inner = core::ptr::null_mut();
847 impl Clone for Sha256 {
848 fn clone(&self) -> Self {
850 inner: if <*mut nativeSha256>::is_null(self.inner) { core::ptr::null_mut() } else {
851 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
857 /// Used only if an object of this type is returned as a trait impl by a method
858 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
859 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
862 /// Creates a copy of the Sha256
863 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
866 /// Checks if two Sha256s contain equal inner contents.
868 pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 {
869 if o.inner.is_null() { return 0; }
870 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
872 let mut hasher = core::hash::SipHasher::new();
873 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
874 core::hash::Hasher::finish(&hasher)
876 /// Checks if two Sha256s contain equal inner contents.
877 /// This ignores pointers and is_owned flags and looks at the values in fields.
878 /// Two objects with NULL inner values will be considered "equal" here.
880 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
881 if a.inner == b.inner { return true; }
882 if a.inner.is_null() || b.inner.is_null() { return false; }
883 if a.get_native_ref() == b.get_native_ref() { true } else { false }
886 use lightning_invoice::Description as nativeDescriptionImport;
887 pub(crate) type nativeDescription = nativeDescriptionImport;
889 /// Description string
892 /// The description can be at most 639 __bytes__ long
895 pub struct Description {
896 /// A pointer to the opaque Rust object.
898 /// Nearly everywhere, inner must be non-null, however in places where
899 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
900 pub inner: *mut nativeDescription,
901 /// Indicates that this is the only struct which contains the same pointer.
903 /// Rust functions which take ownership of an object provided via an argument require
904 /// this to be true and invalidate the object pointed to by inner.
908 impl Drop for Description {
910 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
911 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
915 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
917 pub extern "C" fn Description_free(this_obj: Description) { }
919 /// Used only if an object of this type is returned as a trait impl by a method
920 pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) {
921 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
925 pub(crate) fn get_native_ref(&self) -> &'static nativeDescription {
926 unsafe { &*ObjOps::untweak_ptr(self.inner) }
928 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDescription {
929 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
931 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
932 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
933 assert!(self.is_owned);
934 let ret = ObjOps::untweak_ptr(self.inner);
935 self.inner = core::ptr::null_mut();
939 impl Clone for Description {
940 fn clone(&self) -> Self {
942 inner: if <*mut nativeDescription>::is_null(self.inner) { core::ptr::null_mut() } else {
943 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
949 /// Used only if an object of this type is returned as a trait impl by a method
950 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
951 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
954 /// Creates a copy of the Description
955 pub extern "C" fn Description_clone(orig: &Description) -> Description {
958 /// Checks if two Descriptions contain equal inner contents.
960 pub extern "C" fn Description_hash(o: &Description) -> u64 {
961 if o.inner.is_null() { return 0; }
962 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
964 let mut hasher = core::hash::SipHasher::new();
965 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
966 core::hash::Hasher::finish(&hasher)
968 /// Checks if two Descriptions contain equal inner contents.
969 /// This ignores pointers and is_owned flags and looks at the values in fields.
970 /// Two objects with NULL inner values will be considered "equal" here.
972 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
973 if a.inner == b.inner { return true; }
974 if a.inner.is_null() || b.inner.is_null() { return false; }
975 if a.get_native_ref() == b.get_native_ref() { true } else { false }
978 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
979 pub(crate) type nativePayeePubKey = nativePayeePubKeyImport;
984 pub struct PayeePubKey {
985 /// A pointer to the opaque Rust object.
987 /// Nearly everywhere, inner must be non-null, however in places where
988 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
989 pub inner: *mut nativePayeePubKey,
990 /// Indicates that this is the only struct which contains the same pointer.
992 /// Rust functions which take ownership of an object provided via an argument require
993 /// this to be true and invalidate the object pointed to by inner.
997 impl Drop for PayeePubKey {
999 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
1000 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1004 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
1006 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
1008 /// Used only if an object of this type is returned as a trait impl by a method
1009 pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
1010 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
1014 pub(crate) fn get_native_ref(&self) -> &'static nativePayeePubKey {
1015 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1017 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayeePubKey {
1018 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1020 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1021 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
1022 assert!(self.is_owned);
1023 let ret = ObjOps::untweak_ptr(self.inner);
1024 self.inner = core::ptr::null_mut();
1029 pub extern "C" fn PayeePubKey_get_a(this_ptr: &PayeePubKey) -> crate::c_types::PublicKey {
1030 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1031 crate::c_types::PublicKey::from_rust(&inner_val)
1034 pub extern "C" fn PayeePubKey_set_a(this_ptr: &mut PayeePubKey, mut val: crate::c_types::PublicKey) {
1035 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
1037 /// Constructs a new PayeePubKey given each field
1040 pub extern "C" fn PayeePubKey_new(mut a_arg: crate::c_types::PublicKey) -> PayeePubKey {
1041 PayeePubKey { inner: ObjOps::heap_alloc(lightning_invoice::PayeePubKey (
1043 )), is_owned: true }
1045 impl Clone for PayeePubKey {
1046 fn clone(&self) -> Self {
1048 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { core::ptr::null_mut() } else {
1049 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1055 /// Used only if an object of this type is returned as a trait impl by a method
1056 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
1057 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
1060 /// Creates a copy of the PayeePubKey
1061 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
1064 /// Checks if two PayeePubKeys contain equal inner contents.
1066 pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 {
1067 if o.inner.is_null() { return 0; }
1068 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1069 #[allow(deprecated)]
1070 let mut hasher = core::hash::SipHasher::new();
1071 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1072 core::hash::Hasher::finish(&hasher)
1074 /// Checks if two PayeePubKeys contain equal inner contents.
1075 /// This ignores pointers and is_owned flags and looks at the values in fields.
1076 /// Two objects with NULL inner values will be considered "equal" here.
1078 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
1079 if a.inner == b.inner { return true; }
1080 if a.inner.is_null() || b.inner.is_null() { return false; }
1081 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1084 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
1085 pub(crate) type nativeExpiryTime = nativeExpiryTimeImport;
1087 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
1091 pub struct ExpiryTime {
1092 /// A pointer to the opaque Rust object.
1094 /// Nearly everywhere, inner must be non-null, however in places where
1095 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1096 pub inner: *mut nativeExpiryTime,
1097 /// Indicates that this is the only struct which contains the same pointer.
1099 /// Rust functions which take ownership of an object provided via an argument require
1100 /// this to be true and invalidate the object pointed to by inner.
1104 impl Drop for ExpiryTime {
1105 fn drop(&mut self) {
1106 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
1107 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1111 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
1113 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
1115 /// Used only if an object of this type is returned as a trait impl by a method
1116 pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
1117 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
1121 pub(crate) fn get_native_ref(&self) -> &'static nativeExpiryTime {
1122 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1124 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpiryTime {
1125 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1127 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1128 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
1129 assert!(self.is_owned);
1130 let ret = ObjOps::untweak_ptr(self.inner);
1131 self.inner = core::ptr::null_mut();
1135 impl Clone for ExpiryTime {
1136 fn clone(&self) -> Self {
1138 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { core::ptr::null_mut() } else {
1139 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1145 /// Used only if an object of this type is returned as a trait impl by a method
1146 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1147 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1150 /// Creates a copy of the ExpiryTime
1151 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1154 /// Checks if two ExpiryTimes contain equal inner contents.
1156 pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 {
1157 if o.inner.is_null() { return 0; }
1158 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1159 #[allow(deprecated)]
1160 let mut hasher = core::hash::SipHasher::new();
1161 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1162 core::hash::Hasher::finish(&hasher)
1164 /// Checks if two ExpiryTimes contain equal inner contents.
1165 /// This ignores pointers and is_owned flags and looks at the values in fields.
1166 /// Two objects with NULL inner values will be considered "equal" here.
1168 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1169 if a.inner == b.inner { return true; }
1170 if a.inner.is_null() || b.inner.is_null() { return false; }
1171 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1174 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
1175 pub(crate) type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
1177 /// `min_final_cltv_expiry` to use for the last HTLC in the route
1180 pub struct MinFinalCltvExpiry {
1181 /// A pointer to the opaque Rust object.
1183 /// Nearly everywhere, inner must be non-null, however in places where
1184 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1185 pub inner: *mut nativeMinFinalCltvExpiry,
1186 /// Indicates that this is the only struct which contains the same pointer.
1188 /// Rust functions which take ownership of an object provided via an argument require
1189 /// this to be true and invalidate the object pointed to by inner.
1193 impl Drop for MinFinalCltvExpiry {
1194 fn drop(&mut self) {
1195 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
1196 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1200 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1202 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1204 /// Used only if an object of this type is returned as a trait impl by a method
1205 pub(crate) extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1206 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1209 impl MinFinalCltvExpiry {
1210 pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiry {
1211 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1213 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiry {
1214 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1216 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1217 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1218 assert!(self.is_owned);
1219 let ret = ObjOps::untweak_ptr(self.inner);
1220 self.inner = core::ptr::null_mut();
1225 pub extern "C" fn MinFinalCltvExpiry_get_a(this_ptr: &MinFinalCltvExpiry) -> u64 {
1226 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1230 pub extern "C" fn MinFinalCltvExpiry_set_a(this_ptr: &mut MinFinalCltvExpiry, mut val: u64) {
1231 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val;
1233 /// Constructs a new MinFinalCltvExpiry given each field
1236 pub extern "C" fn MinFinalCltvExpiry_new(mut a_arg: u64) -> MinFinalCltvExpiry {
1237 MinFinalCltvExpiry { inner: ObjOps::heap_alloc(lightning_invoice::MinFinalCltvExpiry (
1239 )), is_owned: true }
1241 impl Clone for MinFinalCltvExpiry {
1242 fn clone(&self) -> Self {
1244 inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { core::ptr::null_mut() } else {
1245 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1251 /// Used only if an object of this type is returned as a trait impl by a method
1252 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1253 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1256 /// Creates a copy of the MinFinalCltvExpiry
1257 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1260 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1262 pub extern "C" fn MinFinalCltvExpiry_hash(o: &MinFinalCltvExpiry) -> u64 {
1263 if o.inner.is_null() { return 0; }
1264 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1265 #[allow(deprecated)]
1266 let mut hasher = core::hash::SipHasher::new();
1267 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1268 core::hash::Hasher::finish(&hasher)
1270 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1271 /// This ignores pointers and is_owned flags and looks at the values in fields.
1272 /// Two objects with NULL inner values will be considered "equal" here.
1274 pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool {
1275 if a.inner == b.inner { return true; }
1276 if a.inner.is_null() || b.inner.is_null() { return false; }
1277 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1279 /// Fallback address in case no LN payment is possible
1285 version: crate::c_types::u5,
1286 program: crate::c_types::derived::CVec_u8Z,
1288 PubKeyHash(crate::c_types::TwentyBytes),
1289 ScriptHash(crate::c_types::TwentyBytes),
1291 use lightning_invoice::Fallback as nativeFallback;
1294 pub(crate) fn to_native(&self) -> nativeFallback {
1296 Fallback::SegWitProgram {ref version, ref program, } => {
1297 let mut version_nonref = (*version).clone();
1298 let mut program_nonref = (*program).clone();
1299 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1300 nativeFallback::SegWitProgram {
1301 version: version_nonref.into(),
1302 program: local_program_nonref,
1305 Fallback::PubKeyHash (ref a, ) => {
1306 let mut a_nonref = (*a).clone();
1307 nativeFallback::PubKeyHash (
1311 Fallback::ScriptHash (ref a, ) => {
1312 let mut a_nonref = (*a).clone();
1313 nativeFallback::ScriptHash (
1320 pub(crate) fn into_native(self) -> nativeFallback {
1322 Fallback::SegWitProgram {mut version, mut program, } => {
1323 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1324 nativeFallback::SegWitProgram {
1325 version: version.into(),
1326 program: local_program,
1329 Fallback::PubKeyHash (mut a, ) => {
1330 nativeFallback::PubKeyHash (
1334 Fallback::ScriptHash (mut a, ) => {
1335 nativeFallback::ScriptHash (
1342 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1344 nativeFallback::SegWitProgram {ref version, ref program, } => {
1345 let mut version_nonref = (*version).clone();
1346 let mut program_nonref = (*program).clone();
1347 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1348 Fallback::SegWitProgram {
1349 version: version_nonref.into(),
1350 program: local_program_nonref.into(),
1353 nativeFallback::PubKeyHash (ref a, ) => {
1354 let mut a_nonref = (*a).clone();
1355 Fallback::PubKeyHash (
1356 crate::c_types::TwentyBytes { data: a_nonref },
1359 nativeFallback::ScriptHash (ref a, ) => {
1360 let mut a_nonref = (*a).clone();
1361 Fallback::ScriptHash (
1362 crate::c_types::TwentyBytes { data: a_nonref },
1368 pub(crate) fn native_into(native: nativeFallback) -> Self {
1370 nativeFallback::SegWitProgram {mut version, mut program, } => {
1371 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1372 Fallback::SegWitProgram {
1373 version: version.into(),
1374 program: local_program.into(),
1377 nativeFallback::PubKeyHash (mut a, ) => {
1378 Fallback::PubKeyHash (
1379 crate::c_types::TwentyBytes { data: a },
1382 nativeFallback::ScriptHash (mut a, ) => {
1383 Fallback::ScriptHash (
1384 crate::c_types::TwentyBytes { data: a },
1390 /// Frees any resources used by the Fallback
1392 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1393 /// Creates a copy of the Fallback
1395 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1399 /// Utility method to constructs a new SegWitProgram-variant Fallback
1400 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::u5, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
1401 Fallback::SegWitProgram {
1407 /// Utility method to constructs a new PubKeyHash-variant Fallback
1408 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1409 Fallback::PubKeyHash(a, )
1412 /// Utility method to constructs a new ScriptHash-variant Fallback
1413 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1414 Fallback::ScriptHash(a, )
1416 /// Checks if two Fallbacks contain equal inner contents.
1418 pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 {
1419 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1420 #[allow(deprecated)]
1421 let mut hasher = core::hash::SipHasher::new();
1422 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1423 core::hash::Hasher::finish(&hasher)
1425 /// Checks if two Fallbacks contain equal inner contents.
1426 /// This ignores pointers and is_owned flags and looks at the values in fields.
1428 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1429 if &a.to_native() == &b.to_native() { true } else { false }
1432 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1433 pub(crate) type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1435 /// Recoverable signature
1438 pub struct InvoiceSignature {
1439 /// A pointer to the opaque Rust object.
1441 /// Nearly everywhere, inner must be non-null, however in places where
1442 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1443 pub inner: *mut nativeInvoiceSignature,
1444 /// Indicates that this is the only struct which contains the same pointer.
1446 /// Rust functions which take ownership of an object provided via an argument require
1447 /// this to be true and invalidate the object pointed to by inner.
1451 impl Drop for InvoiceSignature {
1452 fn drop(&mut self) {
1453 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1454 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1458 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1460 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1462 /// Used only if an object of this type is returned as a trait impl by a method
1463 pub(crate) extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1464 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1467 impl InvoiceSignature {
1468 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceSignature {
1469 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1471 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceSignature {
1472 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1474 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1475 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1476 assert!(self.is_owned);
1477 let ret = ObjOps::untweak_ptr(self.inner);
1478 self.inner = core::ptr::null_mut();
1482 impl Clone for InvoiceSignature {
1483 fn clone(&self) -> Self {
1485 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { core::ptr::null_mut() } else {
1486 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1492 /// Used only if an object of this type is returned as a trait impl by a method
1493 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
1494 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
1497 /// Creates a copy of the InvoiceSignature
1498 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
1501 /// Checks if two InvoiceSignatures contain equal inner contents.
1502 /// This ignores pointers and is_owned flags and looks at the values in fields.
1503 /// Two objects with NULL inner values will be considered "equal" here.
1505 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
1506 if a.inner == b.inner { return true; }
1507 if a.inner.is_null() || b.inner.is_null() { return false; }
1508 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1511 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
1512 pub(crate) type nativePrivateRoute = nativePrivateRouteImport;
1514 /// Private routing information
1517 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
1521 pub struct PrivateRoute {
1522 /// A pointer to the opaque Rust object.
1524 /// Nearly everywhere, inner must be non-null, however in places where
1525 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1526 pub inner: *mut nativePrivateRoute,
1527 /// Indicates that this is the only struct which contains the same pointer.
1529 /// Rust functions which take ownership of an object provided via an argument require
1530 /// this to be true and invalidate the object pointed to by inner.
1534 impl Drop for PrivateRoute {
1535 fn drop(&mut self) {
1536 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
1537 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1541 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
1543 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
1545 /// Used only if an object of this type is returned as a trait impl by a method
1546 pub(crate) extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
1547 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); }
1551 pub(crate) fn get_native_ref(&self) -> &'static nativePrivateRoute {
1552 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1554 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateRoute {
1555 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1557 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1558 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
1559 assert!(self.is_owned);
1560 let ret = ObjOps::untweak_ptr(self.inner);
1561 self.inner = core::ptr::null_mut();
1565 impl Clone for PrivateRoute {
1566 fn clone(&self) -> Self {
1568 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
1569 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1575 /// Used only if an object of this type is returned as a trait impl by a method
1576 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
1577 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
1580 /// Creates a copy of the PrivateRoute
1581 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
1584 /// Checks if two PrivateRoutes contain equal inner contents.
1586 pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 {
1587 if o.inner.is_null() { return 0; }
1588 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1589 #[allow(deprecated)]
1590 let mut hasher = core::hash::SipHasher::new();
1591 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1592 core::hash::Hasher::finish(&hasher)
1594 /// Checks if two PrivateRoutes contain equal inner contents.
1595 /// This ignores pointers and is_owned flags and looks at the values in fields.
1596 /// Two objects with NULL inner values will be considered "equal" here.
1598 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
1599 if a.inner == b.inner { return true; }
1600 if a.inner.is_null() || b.inner.is_null() { return false; }
1601 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1603 /// Disassembles the `SignedRawInvoice` into its three parts:
1605 /// 2. hash of the raw invoice
1609 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
1610 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
1611 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();
1615 /// The `RawInvoice` which was signed.
1618 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
1619 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice();
1620 crate::lightning_invoice::RawInvoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawInvoice<>) as *mut _) }, is_owned: false }
1623 /// The hash of the `RawInvoice` that was signed.
1626 pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [u8; 32] {
1627 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
1631 /// InvoiceSignature for the invoice.
1634 pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
1635 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
1636 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::InvoiceSignature<>) as *mut _) }, is_owned: false }
1639 /// Recovers the public key used for signing the invoice from the recoverable signature.
1642 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
1643 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
1644 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() };
1648 /// Checks if the signature is valid for the included payee public key or if none exists if it's
1649 /// valid for the recovered signature (which should always be true?).
1652 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &SignedRawInvoice) -> bool {
1653 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
1657 /// Calculate the hash of the encoded `RawInvoice`
1660 pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1661 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
1662 crate::c_types::ThirtyTwoBytes { data: ret }
1666 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1669 pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1670 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
1671 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 };
1676 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1679 pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightning_invoice::Description {
1680 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
1681 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 };
1686 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1689 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::lightning_invoice::PayeePubKey {
1690 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
1691 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 };
1696 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1699 pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1700 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash();
1701 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 };
1706 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1709 pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightning_invoice::ExpiryTime {
1710 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
1711 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 };
1716 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1719 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
1720 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
1721 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 };
1726 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1729 pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1730 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
1731 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1736 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1739 pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
1740 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
1741 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 };
1747 pub extern "C" fn RawInvoice_private_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1748 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
1749 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 } }); };
1755 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z {
1756 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
1757 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() }) };
1763 pub extern "C" fn RawInvoice_currency(this_arg: &RawInvoice) -> crate::lightning_invoice::Currency {
1764 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
1765 crate::lightning_invoice::Currency::native_into(ret)
1768 /// Creates a `PositiveTimestamp` from a Unix timestamp in the range `0..=MAX_TIMESTAMP`.
1770 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
1773 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1774 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
1775 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() };
1779 /// Creates a `PositiveTimestamp` from a [`SystemTime`] with a corresponding Unix timestamp in
1780 /// the range `0..=MAX_TIMESTAMP`.
1782 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
1785 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1786 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
1787 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() };
1791 /// Creates a `PositiveTimestamp` from a [`Duration`] since the Unix epoch in the range
1792 /// `0..=MAX_TIMESTAMP`.
1794 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
1797 pub extern "C" fn PositiveTimestamp_from_duration_since_epoch(mut duration: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1798 let mut ret = lightning_invoice::PositiveTimestamp::from_duration_since_epoch(core::time::Duration::from_secs(duration));
1799 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() };
1803 /// Returns the Unix timestamp representing the stored time
1806 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 {
1807 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_unix_timestamp();
1811 /// Returns the duration of the stored time since the Unix epoch
1814 pub extern "C" fn PositiveTimestamp_as_duration_since_epoch(this_arg: &PositiveTimestamp) -> u64 {
1815 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration_since_epoch();
1819 /// Returns the [`SystemTime`] representing the stored time
1822 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &PositiveTimestamp) -> u64 {
1823 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_time();
1824 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1827 /// Transform the `Invoice` into it's unchecked version
1830 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::lightning_invoice::SignedRawInvoice {
1831 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
1832 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(ret), is_owned: true }
1835 /// Check that the invoice is signed correctly and that key recovery works
1838 pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
1839 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
1840 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() };
1844 /// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
1846 /// use lightning_invoice::*;
1848 /// let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
1849 /// h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
1850 /// 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
1851 /// h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
1852 /// j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
1853 /// ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
1854 /// guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
1855 /// ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
1856 /// p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
1857 /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
1858 /// j5r6drg6k6zcqj0fcwg\";
1860 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
1862 /// assert!(Invoice::from_signed(signed).is_ok());
1866 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
1867 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
1868 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() };
1872 /// Returns the `Invoice`'s timestamp (should equal its creation time)
1875 pub extern "C" fn Invoice_timestamp(this_arg: &Invoice) -> u64 {
1876 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timestamp();
1877 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1880 /// Returns the `Invoice`'s timestamp as a duration since the Unix epoch
1883 pub extern "C" fn Invoice_duration_since_epoch(this_arg: &Invoice) -> u64 {
1884 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_since_epoch();
1888 /// Returns the hash to which we will receive the preimage on completion of the payment
1891 pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] {
1892 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
1896 /// Get the payee's public key if one was included in the invoice
1898 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1901 pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1902 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
1903 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
1907 /// Get the payment secret if one was included in the invoice
1910 pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> *const [u8; 32] {
1911 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
1915 /// Get the invoice features if they were included in the invoice
1917 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1920 pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
1921 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
1922 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 };
1926 /// Recover the payee's public key (only to be used if none was included in the invoice)
1929 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1930 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
1931 crate::c_types::PublicKey::from_rust(&ret)
1934 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
1937 pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 {
1938 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
1942 /// Returns whether the invoice has expired.
1945 pub extern "C" fn Invoice_is_expired(this_arg: &Invoice) -> bool {
1946 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
1950 /// Returns whether the expiry time would pass at the given point in time.
1951 /// `at_time` is the timestamp as a duration since the Unix epoch.
1954 pub extern "C" fn Invoice_would_expire(this_arg: &Invoice, mut at_time: u64) -> bool {
1955 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.would_expire(core::time::Duration::from_secs(at_time));
1959 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
1960 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
1963 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 {
1964 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
1968 /// Returns a list of all routes included in the invoice
1971 pub extern "C" fn Invoice_private_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1972 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
1973 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 } }); };
1977 /// Returns a list of all routes included in the invoice as the underlying hints
1980 pub extern "C" fn Invoice_route_hints(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
1981 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints();
1982 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 } }); };
1986 /// Returns the currency for which the invoice was issued
1989 pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoice::Currency {
1990 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
1991 crate::lightning_invoice::Currency::native_into(ret)
1994 /// Returns the amount if specified in the invoice as millisatoshis.
1997 pub extern "C" fn Invoice_amount_milli_satoshis(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z {
1998 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_milli_satoshis();
1999 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() }) };
2003 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
2004 /// returns `CreationError::DescriptionTooLong` otherwise
2006 /// Please note that single characters may use more than one byte due to UTF8 encoding.
2009 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
2010 let mut ret = lightning_invoice::Description::new(description.into_string());
2011 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() };
2015 /// Returns the underlying description `String`
2018 pub extern "C" fn Description_into_inner(mut this_arg: Description) -> crate::c_types::Str {
2019 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2023 /// Construct an `ExpiryTime` from seconds.
2026 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::lightning_invoice::ExpiryTime {
2027 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
2028 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2031 /// Construct an `ExpiryTime` from a `Duration`.
2034 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::lightning_invoice::ExpiryTime {
2035 let mut ret = lightning_invoice::ExpiryTime::from_duration(core::time::Duration::from_secs(duration));
2036 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2039 /// Returns the expiry time in seconds
2042 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 {
2043 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_seconds();
2047 /// Returns a reference to the underlying `Duration` (=expiry time)
2050 pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 {
2051 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration();
2055 /// Creates a new (partial) route from a list of hops
2058 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
2059 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
2060 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() };
2064 /// Returns the underlying list of hops
2067 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: PrivateRoute) -> crate::lightning::routing::router::RouteHint {
2068 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2069 crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true }
2072 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
2076 pub enum CreationError {
2077 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
2079 /// The specified route has too many hops and can't be encoded
2081 /// The Unix timestamp of the supplied date is less than zero or greater than 35-bits
2082 TimestampOutOfBounds,
2083 /// The supplied millisatoshi amount was greater than the total bitcoin supply.
2085 /// Route hints were required for this invoice and were missing. Applies to
2086 /// [phantom invoices].
2088 /// [phantom invoices]: crate::utils::create_phantom_invoice
2091 use lightning_invoice::CreationError as nativeCreationError;
2092 impl CreationError {
2094 pub(crate) fn to_native(&self) -> nativeCreationError {
2096 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2097 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2098 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2099 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2100 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2104 pub(crate) fn into_native(self) -> nativeCreationError {
2106 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2107 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2108 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2109 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2110 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2114 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
2116 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2117 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2118 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2119 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2120 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2124 pub(crate) fn native_into(native: nativeCreationError) -> Self {
2126 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2127 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2128 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2129 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2130 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2134 /// Creates a copy of the CreationError
2136 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
2140 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
2141 pub extern "C" fn CreationError_description_too_long() -> CreationError {
2142 CreationError::DescriptionTooLong}
2144 /// Utility method to constructs a new RouteTooLong-variant CreationError
2145 pub extern "C" fn CreationError_route_too_long() -> CreationError {
2146 CreationError::RouteTooLong}
2148 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
2149 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
2150 CreationError::TimestampOutOfBounds}
2152 /// Utility method to constructs a new InvalidAmount-variant CreationError
2153 pub extern "C" fn CreationError_invalid_amount() -> CreationError {
2154 CreationError::InvalidAmount}
2156 /// Utility method to constructs a new MissingRouteHints-variant CreationError
2157 pub extern "C" fn CreationError_missing_route_hints() -> CreationError {
2158 CreationError::MissingRouteHints}
2159 /// Checks if two CreationErrors contain equal inner contents.
2160 /// This ignores pointers and is_owned flags and looks at the values in fields.
2162 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
2163 if &a.to_native() == &b.to_native() { true } else { false }
2166 /// Get the string representation of a CreationError object
2167 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
2168 alloc::format!("{}", &o.to_native()).into()
2170 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
2171 /// requirements sections in BOLT #11
2175 pub enum SemanticError {
2176 /// The invoice is missing the mandatory payment hash
2178 /// The invoice has multiple payment hashes which isn't allowed
2179 MultiplePaymentHashes,
2180 /// No description or description hash are part of the invoice
2182 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
2183 MultipleDescriptions,
2184 /// The invoice is missing the mandatory payment secret, which all modern lightning nodes
2187 /// The invoice contains multiple payment secrets
2188 MultiplePaymentSecrets,
2189 /// The invoice's features are invalid
2191 /// The recovery id doesn't fit the signature/pub key
2193 /// The invoice's signature is invalid
2195 /// The invoice's amount was not a whole number of millisatoshis
2198 use lightning_invoice::SemanticError as nativeSemanticError;
2199 impl SemanticError {
2201 pub(crate) fn to_native(&self) -> nativeSemanticError {
2203 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2204 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2205 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2206 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2207 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2208 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2209 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2210 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2211 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2212 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2216 pub(crate) fn into_native(self) -> nativeSemanticError {
2218 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2219 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2220 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2221 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2222 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2223 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2224 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2225 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2226 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2227 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2231 pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
2233 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2234 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2235 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2236 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2237 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2238 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2239 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2240 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2241 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2242 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2246 pub(crate) fn native_into(native: nativeSemanticError) -> Self {
2248 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2249 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2250 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2251 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2252 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2253 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2254 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2255 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2256 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2257 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2261 /// Creates a copy of the SemanticError
2263 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
2267 /// Utility method to constructs a new NoPaymentHash-variant SemanticError
2268 pub extern "C" fn SemanticError_no_payment_hash() -> SemanticError {
2269 SemanticError::NoPaymentHash}
2271 /// Utility method to constructs a new MultiplePaymentHashes-variant SemanticError
2272 pub extern "C" fn SemanticError_multiple_payment_hashes() -> SemanticError {
2273 SemanticError::MultiplePaymentHashes}
2275 /// Utility method to constructs a new NoDescription-variant SemanticError
2276 pub extern "C" fn SemanticError_no_description() -> SemanticError {
2277 SemanticError::NoDescription}
2279 /// Utility method to constructs a new MultipleDescriptions-variant SemanticError
2280 pub extern "C" fn SemanticError_multiple_descriptions() -> SemanticError {
2281 SemanticError::MultipleDescriptions}
2283 /// Utility method to constructs a new NoPaymentSecret-variant SemanticError
2284 pub extern "C" fn SemanticError_no_payment_secret() -> SemanticError {
2285 SemanticError::NoPaymentSecret}
2287 /// Utility method to constructs a new MultiplePaymentSecrets-variant SemanticError
2288 pub extern "C" fn SemanticError_multiple_payment_secrets() -> SemanticError {
2289 SemanticError::MultiplePaymentSecrets}
2291 /// Utility method to constructs a new InvalidFeatures-variant SemanticError
2292 pub extern "C" fn SemanticError_invalid_features() -> SemanticError {
2293 SemanticError::InvalidFeatures}
2295 /// Utility method to constructs a new InvalidRecoveryId-variant SemanticError
2296 pub extern "C" fn SemanticError_invalid_recovery_id() -> SemanticError {
2297 SemanticError::InvalidRecoveryId}
2299 /// Utility method to constructs a new InvalidSignature-variant SemanticError
2300 pub extern "C" fn SemanticError_invalid_signature() -> SemanticError {
2301 SemanticError::InvalidSignature}
2303 /// Utility method to constructs a new ImpreciseAmount-variant SemanticError
2304 pub extern "C" fn SemanticError_imprecise_amount() -> SemanticError {
2305 SemanticError::ImpreciseAmount}
2306 /// Checks if two SemanticErrors contain equal inner contents.
2307 /// This ignores pointers and is_owned flags and looks at the values in fields.
2309 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
2310 if &a.to_native() == &b.to_native() { true } else { false }
2313 /// Get the string representation of a SemanticError object
2314 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
2315 alloc::format!("{}", &o.to_native()).into()
2317 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
2322 pub enum SignOrCreationError {
2323 /// An error occurred during signing
2325 /// An error occurred while building the transaction
2326 CreationError(crate::lightning_invoice::CreationError),
2328 use lightning_invoice::SignOrCreationError as nativeSignOrCreationError;
2329 impl SignOrCreationError {
2331 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
2333 SignOrCreationError::SignError => {
2334 nativeSignOrCreationError::SignError (
2338 SignOrCreationError::CreationError (ref a, ) => {
2339 let mut a_nonref = (*a).clone();
2340 nativeSignOrCreationError::CreationError (
2341 a_nonref.into_native(),
2347 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
2349 SignOrCreationError::SignError => {
2350 nativeSignOrCreationError::SignError (
2354 SignOrCreationError::CreationError (mut a, ) => {
2355 nativeSignOrCreationError::CreationError (
2362 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
2364 nativeSignOrCreationError::SignError (ref a, ) => {
2365 SignOrCreationError::SignError },
2366 nativeSignOrCreationError::CreationError (ref a, ) => {
2367 let mut a_nonref = (*a).clone();
2368 SignOrCreationError::CreationError (
2369 crate::lightning_invoice::CreationError::native_into(a_nonref),
2375 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
2377 nativeSignOrCreationError::SignError (mut a, ) => {
2378 SignOrCreationError::SignError },
2379 nativeSignOrCreationError::CreationError (mut a, ) => {
2380 SignOrCreationError::CreationError (
2381 crate::lightning_invoice::CreationError::native_into(a),
2387 /// Frees any resources used by the SignOrCreationError
2389 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
2390 /// Creates a copy of the SignOrCreationError
2392 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
2396 /// Utility method to constructs a new SignError-variant SignOrCreationError
2397 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
2398 SignOrCreationError::SignError
2401 /// Utility method to constructs a new CreationError-variant SignOrCreationError
2402 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
2403 SignOrCreationError::CreationError(a, )
2405 /// Checks if two SignOrCreationErrors contain equal inner contents.
2406 /// This ignores pointers and is_owned flags and looks at the values in fields.
2408 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
2409 if &a.to_native() == &b.to_native() { true } else { false }
2412 /// Get the string representation of a SignOrCreationError object
2413 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
2414 alloc::format!("{}", &o.to_native()).into()