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 std::str::FromStr;
20 use core::convert::Infallible;
21 use bitcoin::hashes::Hash;
22 use crate::c_types::*;
28 use std::str::FromStr;
30 use core::convert::Infallible;
31 use bitcoin::hashes::Hash;
32 use crate::c_types::*;
36 use std::str::FromStr;
38 use core::convert::Infallible;
39 use bitcoin::hashes::Hash;
40 use crate::c_types::*;
44 /// Read a SiPrefix object from a string
45 pub extern "C" fn SiPrefix_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SiPrefixNoneZ {
46 match lightning_invoice::SiPrefix::from_str(s.into_str()) {
48 crate::c_types::CResultTempl::ok(
49 crate::lightning_invoice::SiPrefix::native_into(r)
52 Err(e) => crate::c_types::CResultTempl::err(()),
56 /// Read a Invoice object from a string
57 pub extern "C" fn Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_InvoiceNoneZ {
58 match lightning_invoice::Invoice::from_str(s.into_str()) {
60 crate::c_types::CResultTempl::ok(
61 crate::lightning_invoice::Invoice { inner: ObjOps::heap_alloc(r), is_owned: true }
64 Err(e) => crate::c_types::CResultTempl::err(()),
68 /// Read a SignedRawInvoice object from a string
69 pub extern "C" fn SignedRawInvoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SignedRawInvoiceNoneZ {
70 match lightning_invoice::SignedRawInvoice::from_str(s.into_str()) {
72 crate::c_types::CResultTempl::ok(
73 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(r), is_owned: true }
76 Err(e) => crate::c_types::CResultTempl::err(()),
82 use std::str::FromStr;
84 use core::convert::Infallible;
85 use bitcoin::hashes::Hash;
86 use crate::c_types::*;
89 /// Get the string representation of a Invoice object
90 pub extern "C" fn Invoice_to_str(o: &crate::lightning_invoice::Invoice) -> Str {
91 format!("{}", o.get_native_ref()).into()
94 /// Get the string representation of a SignedRawInvoice object
95 pub extern "C" fn SignedRawInvoice_to_str(o: &crate::lightning_invoice::SignedRawInvoice) -> Str {
96 format!("{}", o.get_native_ref()).into()
99 /// Get the string representation of a Currency object
100 pub extern "C" fn Currency_to_str(o: &crate::lightning_invoice::Currency) -> Str {
101 format!("{}", &o.to_native()).into()
104 /// Get the string representation of a SiPrefix object
105 pub extern "C" fn SiPrefix_to_str(o: &crate::lightning_invoice::SiPrefix) -> Str {
106 format!("{}", &o.to_native()).into()
111 use std::str::FromStr;
112 use std::ffi::c_void;
113 use core::convert::Infallible;
114 use bitcoin::hashes::Hash;
115 use crate::c_types::*;
118 /// Default expiry time as defined by [BOLT 11].
120 /// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md
123 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
124 /// Default minimum final CLTV expiry as defined by [BOLT 11].
126 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
127 /// provided in [`MIN_FINAL_CLTV_EXPIRY`].
129 /// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md
130 /// [`MIN_FINAL_CLTV_EXPIRY`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY
133 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY;
134 /// **Call this function on startup to ensure that all assumptions about the platform are valid.**
136 /// Unfortunately we have to make assumptions about the upper bounds of the `SystemTime` type on
137 /// your platform which we can't fully verify at compile time and which isn't part of it's contract.
138 /// To our best knowledge our assumptions hold for all platforms officially supported by rust, but
139 /// since this check is fast we recommend to do it anyway.
141 /// If this function fails this is considered a bug. Please open an issue describing your
142 /// platform and stating your current system time.
145 /// If the check fails this function panics. By calling this function on startup you ensure that
146 /// this wont happen at an arbitrary later point in time.
148 pub extern "C" fn check_platform() {
149 lightning_invoice::check_platform()
153 use lightning_invoice::Invoice as nativeInvoiceImport;
154 type nativeInvoice = nativeInvoiceImport;
156 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
158 /// There are three ways to construct an `Invoice`:
159 /// 1. using `InvoiceBuilder`
160 /// 2. using `Invoice::from_signed(SignedRawInvoice)`
161 /// 3. using `str::parse::<Invoice>(&str)`
165 /// A pointer to the opaque Rust object.
167 /// Nearly everywhere, inner must be non-null, however in places where
168 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
169 pub inner: *mut nativeInvoice,
170 /// Indicates that this is the only struct which contains the same pointer.
172 /// Rust functions which take ownership of an object provided via an argument require
173 /// this to be true and invalidate the object pointed to by inner.
177 impl Drop for Invoice {
179 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
180 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
184 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
186 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
188 /// Used only if an object of this type is returned as a trait impl by a method
189 extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
190 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
194 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoice {
195 unsafe { &*ObjOps::untweak_ptr(self.inner) }
197 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoice {
198 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
200 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
201 pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
202 assert!(self.is_owned);
203 let ret = ObjOps::untweak_ptr(self.inner);
204 self.inner = std::ptr::null_mut();
208 /// Checks if two Invoices contain equal inner contents.
209 /// This ignores pointers and is_owned flags and looks at the values in fields.
210 /// Two objects with NULL inner values will be considered "equal" here.
212 pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool {
213 if a.inner == b.inner { return true; }
214 if a.inner.is_null() || b.inner.is_null() { return false; }
215 if a.get_native_ref() == b.get_native_ref() { true } else { false }
217 impl Clone for Invoice {
218 fn clone(&self) -> Self {
220 inner: if <*mut nativeInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
221 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
227 /// Used only if an object of this type is returned as a trait impl by a method
228 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
229 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
232 /// Creates a copy of the Invoice
233 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
237 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
238 type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
240 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
244 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
247 pub struct SignedRawInvoice {
248 /// A pointer to the opaque Rust object.
250 /// Nearly everywhere, inner must be non-null, however in places where
251 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
252 pub inner: *mut nativeSignedRawInvoice,
253 /// Indicates that this is the only struct which contains the same pointer.
255 /// Rust functions which take ownership of an object provided via an argument require
256 /// this to be true and invalidate the object pointed to by inner.
260 impl Drop for SignedRawInvoice {
262 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
263 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
267 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
269 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
271 /// Used only if an object of this type is returned as a trait impl by a method
272 extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
273 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
276 impl SignedRawInvoice {
277 pub(crate) fn get_native_ref(&self) -> &'static nativeSignedRawInvoice {
278 unsafe { &*ObjOps::untweak_ptr(self.inner) }
280 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSignedRawInvoice {
281 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
283 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
284 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
285 assert!(self.is_owned);
286 let ret = ObjOps::untweak_ptr(self.inner);
287 self.inner = std::ptr::null_mut();
291 /// Checks if two SignedRawInvoices contain equal inner contents.
292 /// This ignores pointers and is_owned flags and looks at the values in fields.
293 /// Two objects with NULL inner values will be considered "equal" here.
295 pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice) -> bool {
296 if a.inner == b.inner { return true; }
297 if a.inner.is_null() || b.inner.is_null() { return false; }
298 if a.get_native_ref() == b.get_native_ref() { true } else { false }
300 impl Clone for SignedRawInvoice {
301 fn clone(&self) -> Self {
303 inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
304 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
310 /// Used only if an object of this type is returned as a trait impl by a method
311 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
312 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
315 /// Creates a copy of the SignedRawInvoice
316 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
320 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
321 type nativeRawInvoice = nativeRawInvoiceImport;
323 /// Represents an syntactically correct Invoice for a payment on the lightning network,
324 /// but without the signature information.
325 /// De- and encoding should not lead to information loss but may lead to different hashes.
327 /// For methods without docs see the corresponding methods in `Invoice`.
330 pub struct RawInvoice {
331 /// A pointer to the opaque Rust object.
333 /// Nearly everywhere, inner must be non-null, however in places where
334 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
335 pub inner: *mut nativeRawInvoice,
336 /// Indicates that this is the only struct which contains the same pointer.
338 /// Rust functions which take ownership of an object provided via an argument require
339 /// this to be true and invalidate the object pointed to by inner.
343 impl Drop for RawInvoice {
345 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
346 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
350 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
352 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
354 /// Used only if an object of this type is returned as a trait impl by a method
355 extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
356 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
360 pub(crate) fn get_native_ref(&self) -> &'static nativeRawInvoice {
361 unsafe { &*ObjOps::untweak_ptr(self.inner) }
363 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawInvoice {
364 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
366 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
367 pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
368 assert!(self.is_owned);
369 let ret = ObjOps::untweak_ptr(self.inner);
370 self.inner = std::ptr::null_mut();
376 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
377 let mut inner_val = &mut this_ptr.get_native_mut_ref().data;
378 crate::lightning_invoice::RawDataPart { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
382 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
383 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.data = *unsafe { Box::from_raw(val.take_inner()) };
385 /// Checks if two RawInvoices contain equal inner contents.
386 /// This ignores pointers and is_owned flags and looks at the values in fields.
387 /// Two objects with NULL inner values will be considered "equal" here.
389 pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool {
390 if a.inner == b.inner { return true; }
391 if a.inner.is_null() || b.inner.is_null() { return false; }
392 if a.get_native_ref() == b.get_native_ref() { true } else { false }
394 impl Clone for RawInvoice {
395 fn clone(&self) -> Self {
397 inner: if <*mut nativeRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
398 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
404 /// Used only if an object of this type is returned as a trait impl by a method
405 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
406 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
409 /// Creates a copy of the RawInvoice
410 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
414 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
415 type nativeRawDataPart = nativeRawDataPartImport;
417 /// Data of the `RawInvoice` that is encoded in the data part
420 pub struct RawDataPart {
421 /// A pointer to the opaque Rust object.
423 /// Nearly everywhere, inner must be non-null, however in places where
424 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
425 pub inner: *mut nativeRawDataPart,
426 /// Indicates that this is the only struct which contains the same pointer.
428 /// Rust functions which take ownership of an object provided via an argument require
429 /// this to be true and invalidate the object pointed to by inner.
433 impl Drop for RawDataPart {
435 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
436 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
440 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
442 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
444 /// Used only if an object of this type is returned as a trait impl by a method
445 extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
446 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
450 pub(crate) fn get_native_ref(&self) -> &'static nativeRawDataPart {
451 unsafe { &*ObjOps::untweak_ptr(self.inner) }
453 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawDataPart {
454 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
456 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
457 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
458 assert!(self.is_owned);
459 let ret = ObjOps::untweak_ptr(self.inner);
460 self.inner = std::ptr::null_mut();
464 /// generation time of the invoice
466 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
467 let mut inner_val = &mut this_ptr.get_native_mut_ref().timestamp;
468 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
470 /// generation time of the invoice
472 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
473 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
475 /// Checks if two RawDataParts contain equal inner contents.
476 /// This ignores pointers and is_owned flags and looks at the values in fields.
477 /// Two objects with NULL inner values will be considered "equal" here.
479 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
480 if a.inner == b.inner { return true; }
481 if a.inner.is_null() || b.inner.is_null() { return false; }
482 if a.get_native_ref() == b.get_native_ref() { true } else { false }
484 impl Clone for RawDataPart {
485 fn clone(&self) -> Self {
487 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { std::ptr::null_mut() } else {
488 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
494 /// Used only if an object of this type is returned as a trait impl by a method
495 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
496 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
499 /// Creates a copy of the RawDataPart
500 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
504 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
505 type nativePositiveTimestamp = nativePositiveTimestampImport;
507 /// A timestamp that refers to a date after 1 January 1970 which means its representation as UNIX
508 /// timestamp is positive.
511 /// The UNIX timestamp representing the stored time has to be positive and small enough so that
512 /// a `EpiryTime` can be added to it without an overflow.
515 pub struct PositiveTimestamp {
516 /// A pointer to the opaque Rust object.
518 /// Nearly everywhere, inner must be non-null, however in places where
519 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
520 pub inner: *mut nativePositiveTimestamp,
521 /// Indicates that this is the only struct which contains the same pointer.
523 /// Rust functions which take ownership of an object provided via an argument require
524 /// this to be true and invalidate the object pointed to by inner.
528 impl Drop for PositiveTimestamp {
530 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
531 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
535 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
537 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
539 /// Used only if an object of this type is returned as a trait impl by a method
540 extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
541 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
544 impl PositiveTimestamp {
545 pub(crate) fn get_native_ref(&self) -> &'static nativePositiveTimestamp {
546 unsafe { &*ObjOps::untweak_ptr(self.inner) }
548 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePositiveTimestamp {
549 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
551 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
552 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
553 assert!(self.is_owned);
554 let ret = ObjOps::untweak_ptr(self.inner);
555 self.inner = std::ptr::null_mut();
559 /// Checks if two PositiveTimestamps contain equal inner contents.
560 /// This ignores pointers and is_owned flags and looks at the values in fields.
561 /// Two objects with NULL inner values will be considered "equal" here.
563 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
564 if a.inner == b.inner { return true; }
565 if a.inner.is_null() || b.inner.is_null() { return false; }
566 if a.get_native_ref() == b.get_native_ref() { true } else { false }
568 impl Clone for PositiveTimestamp {
569 fn clone(&self) -> Self {
571 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { std::ptr::null_mut() } else {
572 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
578 /// Used only if an object of this type is returned as a trait impl by a method
579 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
580 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
583 /// Creates a copy of the PositiveTimestamp
584 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
587 /// SI prefixes for the human readable part
601 use lightning_invoice::SiPrefix as nativeSiPrefix;
604 pub(crate) fn to_native(&self) -> nativeSiPrefix {
606 SiPrefix::Milli => nativeSiPrefix::Milli,
607 SiPrefix::Micro => nativeSiPrefix::Micro,
608 SiPrefix::Nano => nativeSiPrefix::Nano,
609 SiPrefix::Pico => nativeSiPrefix::Pico,
613 pub(crate) fn into_native(self) -> nativeSiPrefix {
615 SiPrefix::Milli => nativeSiPrefix::Milli,
616 SiPrefix::Micro => nativeSiPrefix::Micro,
617 SiPrefix::Nano => nativeSiPrefix::Nano,
618 SiPrefix::Pico => nativeSiPrefix::Pico,
622 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
624 nativeSiPrefix::Milli => SiPrefix::Milli,
625 nativeSiPrefix::Micro => SiPrefix::Micro,
626 nativeSiPrefix::Nano => SiPrefix::Nano,
627 nativeSiPrefix::Pico => SiPrefix::Pico,
631 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
633 nativeSiPrefix::Milli => SiPrefix::Milli,
634 nativeSiPrefix::Micro => SiPrefix::Micro,
635 nativeSiPrefix::Nano => SiPrefix::Nano,
636 nativeSiPrefix::Pico => SiPrefix::Pico,
640 /// Creates a copy of the SiPrefix
642 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
646 /// Utility method to constructs a new Milli-variant SiPrefix
647 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
650 /// Utility method to constructs a new Micro-variant SiPrefix
651 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
654 /// Utility method to constructs a new Nano-variant SiPrefix
655 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
658 /// Utility method to constructs a new Pico-variant SiPrefix
659 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
661 /// Checks if two SiPrefixs contain equal inner contents.
662 /// This ignores pointers and is_owned flags and looks at the values in fields.
664 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
665 if &a.to_native() == &b.to_native() { true } else { false }
667 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
668 /// This is effectively 10^12 * the prefix multiplier
671 pub extern "C" fn SiPrefix_multiplier(this_arg: &SiPrefix) -> u64 {
672 let mut ret = this_arg.to_native().multiplier();
676 /// Enum representing the crypto currencies (or networks) supported by this library
692 use lightning_invoice::Currency as nativeCurrency;
695 pub(crate) fn to_native(&self) -> nativeCurrency {
697 Currency::Bitcoin => nativeCurrency::Bitcoin,
698 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
699 Currency::Regtest => nativeCurrency::Regtest,
700 Currency::Simnet => nativeCurrency::Simnet,
701 Currency::Signet => nativeCurrency::Signet,
705 pub(crate) fn into_native(self) -> nativeCurrency {
707 Currency::Bitcoin => nativeCurrency::Bitcoin,
708 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
709 Currency::Regtest => nativeCurrency::Regtest,
710 Currency::Simnet => nativeCurrency::Simnet,
711 Currency::Signet => nativeCurrency::Signet,
715 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
717 nativeCurrency::Bitcoin => Currency::Bitcoin,
718 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
719 nativeCurrency::Regtest => Currency::Regtest,
720 nativeCurrency::Simnet => Currency::Simnet,
721 nativeCurrency::Signet => Currency::Signet,
725 pub(crate) fn native_into(native: nativeCurrency) -> Self {
727 nativeCurrency::Bitcoin => Currency::Bitcoin,
728 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
729 nativeCurrency::Regtest => Currency::Regtest,
730 nativeCurrency::Simnet => Currency::Simnet,
731 nativeCurrency::Signet => Currency::Signet,
735 /// Creates a copy of the Currency
737 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
741 /// Utility method to constructs a new Bitcoin-variant Currency
742 pub extern "C" fn Currency_bitcoin() -> Currency {
745 /// Utility method to constructs a new BitcoinTestnet-variant Currency
746 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
747 Currency::BitcoinTestnet}
749 /// Utility method to constructs a new Regtest-variant Currency
750 pub extern "C" fn Currency_regtest() -> Currency {
753 /// Utility method to constructs a new Simnet-variant Currency
754 pub extern "C" fn Currency_simnet() -> Currency {
757 /// Utility method to constructs a new Signet-variant Currency
758 pub extern "C" fn Currency_signet() -> Currency {
760 /// Checks if two Currencys contain equal inner contents.
762 pub extern "C" fn Currency_hash(o: &Currency) -> u64 {
763 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
765 let mut hasher = core::hash::SipHasher::new();
766 std::hash::Hash::hash(&o.to_native(), &mut hasher);
767 std::hash::Hasher::finish(&hasher)
769 /// Checks if two Currencys contain equal inner contents.
770 /// This ignores pointers and is_owned flags and looks at the values in fields.
772 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
773 if &a.to_native() == &b.to_native() { true } else { false }
776 use lightning_invoice::Sha256 as nativeSha256Import;
777 type nativeSha256 = nativeSha256Import;
783 /// A pointer to the opaque Rust object.
785 /// Nearly everywhere, inner must be non-null, however in places where
786 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
787 pub inner: *mut nativeSha256,
788 /// Indicates that this is the only struct which contains the same pointer.
790 /// Rust functions which take ownership of an object provided via an argument require
791 /// this to be true and invalidate the object pointed to by inner.
795 impl Drop for Sha256 {
797 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
798 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
802 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
804 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
806 /// Used only if an object of this type is returned as a trait impl by a method
807 extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
808 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
812 pub(crate) fn get_native_ref(&self) -> &'static nativeSha256 {
813 unsafe { &*ObjOps::untweak_ptr(self.inner) }
815 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSha256 {
816 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
818 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
819 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
820 assert!(self.is_owned);
821 let ret = ObjOps::untweak_ptr(self.inner);
822 self.inner = std::ptr::null_mut();
826 impl Clone for Sha256 {
827 fn clone(&self) -> Self {
829 inner: if <*mut nativeSha256>::is_null(self.inner) { std::ptr::null_mut() } else {
830 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
836 /// Used only if an object of this type is returned as a trait impl by a method
837 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
838 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
841 /// Creates a copy of the Sha256
842 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
845 /// Checks if two Sha256s contain equal inner contents.
847 pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 {
848 if o.inner.is_null() { return 0; }
849 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
851 let mut hasher = core::hash::SipHasher::new();
852 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
853 std::hash::Hasher::finish(&hasher)
855 /// Checks if two Sha256s contain equal inner contents.
856 /// This ignores pointers and is_owned flags and looks at the values in fields.
857 /// Two objects with NULL inner values will be considered "equal" here.
859 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
860 if a.inner == b.inner { return true; }
861 if a.inner.is_null() || b.inner.is_null() { return false; }
862 if a.get_native_ref() == b.get_native_ref() { true } else { false }
865 use lightning_invoice::Description as nativeDescriptionImport;
866 type nativeDescription = nativeDescriptionImport;
868 /// Description string
871 /// The description can be at most 639 __bytes__ long
874 pub struct Description {
875 /// A pointer to the opaque Rust object.
877 /// Nearly everywhere, inner must be non-null, however in places where
878 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
879 pub inner: *mut nativeDescription,
880 /// Indicates that this is the only struct which contains the same pointer.
882 /// Rust functions which take ownership of an object provided via an argument require
883 /// this to be true and invalidate the object pointed to by inner.
887 impl Drop for Description {
889 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
890 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
894 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
896 pub extern "C" fn Description_free(this_obj: Description) { }
898 /// Used only if an object of this type is returned as a trait impl by a method
899 extern "C" fn Description_free_void(this_ptr: *mut c_void) {
900 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
904 pub(crate) fn get_native_ref(&self) -> &'static nativeDescription {
905 unsafe { &*ObjOps::untweak_ptr(self.inner) }
907 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDescription {
908 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
910 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
911 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
912 assert!(self.is_owned);
913 let ret = ObjOps::untweak_ptr(self.inner);
914 self.inner = std::ptr::null_mut();
918 impl Clone for Description {
919 fn clone(&self) -> Self {
921 inner: if <*mut nativeDescription>::is_null(self.inner) { std::ptr::null_mut() } else {
922 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
928 /// Used only if an object of this type is returned as a trait impl by a method
929 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
930 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
933 /// Creates a copy of the Description
934 pub extern "C" fn Description_clone(orig: &Description) -> Description {
937 /// Checks if two Descriptions contain equal inner contents.
939 pub extern "C" fn Description_hash(o: &Description) -> u64 {
940 if o.inner.is_null() { return 0; }
941 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
943 let mut hasher = core::hash::SipHasher::new();
944 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
945 std::hash::Hasher::finish(&hasher)
947 /// Checks if two Descriptions contain equal inner contents.
948 /// This ignores pointers and is_owned flags and looks at the values in fields.
949 /// Two objects with NULL inner values will be considered "equal" here.
951 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
952 if a.inner == b.inner { return true; }
953 if a.inner.is_null() || b.inner.is_null() { return false; }
954 if a.get_native_ref() == b.get_native_ref() { true } else { false }
957 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
958 type nativePayeePubKey = nativePayeePubKeyImport;
963 pub struct PayeePubKey {
964 /// A pointer to the opaque Rust object.
966 /// Nearly everywhere, inner must be non-null, however in places where
967 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
968 pub inner: *mut nativePayeePubKey,
969 /// Indicates that this is the only struct which contains the same pointer.
971 /// Rust functions which take ownership of an object provided via an argument require
972 /// this to be true and invalidate the object pointed to by inner.
976 impl Drop for PayeePubKey {
978 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
979 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
983 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
985 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
987 /// Used only if an object of this type is returned as a trait impl by a method
988 extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
989 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
993 pub(crate) fn get_native_ref(&self) -> &'static nativePayeePubKey {
994 unsafe { &*ObjOps::untweak_ptr(self.inner) }
996 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayeePubKey {
997 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
999 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1000 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
1001 assert!(self.is_owned);
1002 let ret = ObjOps::untweak_ptr(self.inner);
1003 self.inner = std::ptr::null_mut();
1007 impl Clone for PayeePubKey {
1008 fn clone(&self) -> Self {
1010 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { std::ptr::null_mut() } else {
1011 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1017 /// Used only if an object of this type is returned as a trait impl by a method
1018 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
1019 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
1022 /// Creates a copy of the PayeePubKey
1023 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
1026 /// Checks if two PayeePubKeys contain equal inner contents.
1028 pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 {
1029 if o.inner.is_null() { return 0; }
1030 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
1031 #[allow(deprecated)]
1032 let mut hasher = core::hash::SipHasher::new();
1033 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1034 std::hash::Hasher::finish(&hasher)
1036 /// Checks if two PayeePubKeys contain equal inner contents.
1037 /// This ignores pointers and is_owned flags and looks at the values in fields.
1038 /// Two objects with NULL inner values will be considered "equal" here.
1040 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
1041 if a.inner == b.inner { return true; }
1042 if a.inner.is_null() || b.inner.is_null() { return false; }
1043 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1046 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
1047 type nativeExpiryTime = nativeExpiryTimeImport;
1049 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
1053 /// The number of seconds this expiry time represents has to be in the range
1054 /// `0...(SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME)` to avoid overflows when adding it to a
1058 pub struct ExpiryTime {
1059 /// A pointer to the opaque Rust object.
1061 /// Nearly everywhere, inner must be non-null, however in places where
1062 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1063 pub inner: *mut nativeExpiryTime,
1064 /// Indicates that this is the only struct which contains the same pointer.
1066 /// Rust functions which take ownership of an object provided via an argument require
1067 /// this to be true and invalidate the object pointed to by inner.
1071 impl Drop for ExpiryTime {
1072 fn drop(&mut self) {
1073 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
1074 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1078 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
1080 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
1082 /// Used only if an object of this type is returned as a trait impl by a method
1083 extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
1084 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
1088 pub(crate) fn get_native_ref(&self) -> &'static nativeExpiryTime {
1089 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1091 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpiryTime {
1092 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1094 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1095 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
1096 assert!(self.is_owned);
1097 let ret = ObjOps::untweak_ptr(self.inner);
1098 self.inner = std::ptr::null_mut();
1102 impl Clone for ExpiryTime {
1103 fn clone(&self) -> Self {
1105 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { std::ptr::null_mut() } else {
1106 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1112 /// Used only if an object of this type is returned as a trait impl by a method
1113 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1114 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1117 /// Creates a copy of the ExpiryTime
1118 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1121 /// Checks if two ExpiryTimes contain equal inner contents.
1123 pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 {
1124 if o.inner.is_null() { return 0; }
1125 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
1126 #[allow(deprecated)]
1127 let mut hasher = core::hash::SipHasher::new();
1128 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1129 std::hash::Hasher::finish(&hasher)
1131 /// Checks if two ExpiryTimes contain equal inner contents.
1132 /// This ignores pointers and is_owned flags and looks at the values in fields.
1133 /// Two objects with NULL inner values will be considered "equal" here.
1135 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1136 if a.inner == b.inner { return true; }
1137 if a.inner.is_null() || b.inner.is_null() { return false; }
1138 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1141 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
1142 type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
1144 /// `min_final_cltv_expiry` to use for the last HTLC in the route
1147 pub struct MinFinalCltvExpiry {
1148 /// A pointer to the opaque Rust object.
1150 /// Nearly everywhere, inner must be non-null, however in places where
1151 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1152 pub inner: *mut nativeMinFinalCltvExpiry,
1153 /// Indicates that this is the only struct which contains the same pointer.
1155 /// Rust functions which take ownership of an object provided via an argument require
1156 /// this to be true and invalidate the object pointed to by inner.
1160 impl Drop for MinFinalCltvExpiry {
1161 fn drop(&mut self) {
1162 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
1163 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1167 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1169 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1171 /// Used only if an object of this type is returned as a trait impl by a method
1172 extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1173 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1176 impl MinFinalCltvExpiry {
1177 pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiry {
1178 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1180 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiry {
1181 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1183 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1184 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1185 assert!(self.is_owned);
1186 let ret = ObjOps::untweak_ptr(self.inner);
1187 self.inner = std::ptr::null_mut();
1191 impl Clone for MinFinalCltvExpiry {
1192 fn clone(&self) -> Self {
1194 inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { std::ptr::null_mut() } else {
1195 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1201 /// Used only if an object of this type is returned as a trait impl by a method
1202 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1203 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1206 /// Creates a copy of the MinFinalCltvExpiry
1207 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1210 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1212 pub extern "C" fn MinFinalCltvExpiry_hash(o: &MinFinalCltvExpiry) -> u64 {
1213 if o.inner.is_null() { return 0; }
1214 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
1215 #[allow(deprecated)]
1216 let mut hasher = core::hash::SipHasher::new();
1217 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1218 std::hash::Hasher::finish(&hasher)
1220 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1221 /// This ignores pointers and is_owned flags and looks at the values in fields.
1222 /// Two objects with NULL inner values will be considered "equal" here.
1224 pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool {
1225 if a.inner == b.inner { return true; }
1226 if a.inner.is_null() || b.inner.is_null() { return false; }
1227 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1229 /// Fallback address in case no LN payment is possible
1235 version: crate::c_types::u5,
1236 program: crate::c_types::derived::CVec_u8Z,
1238 PubKeyHash(crate::c_types::TwentyBytes),
1239 ScriptHash(crate::c_types::TwentyBytes),
1241 use lightning_invoice::Fallback as nativeFallback;
1244 pub(crate) fn to_native(&self) -> nativeFallback {
1246 Fallback::SegWitProgram {ref version, ref program, } => {
1247 let mut version_nonref = (*version).clone();
1248 let mut program_nonref = (*program).clone();
1249 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1250 nativeFallback::SegWitProgram {
1251 version: version_nonref.into(),
1252 program: local_program_nonref,
1255 Fallback::PubKeyHash (ref a, ) => {
1256 let mut a_nonref = (*a).clone();
1257 nativeFallback::PubKeyHash (
1261 Fallback::ScriptHash (ref a, ) => {
1262 let mut a_nonref = (*a).clone();
1263 nativeFallback::ScriptHash (
1270 pub(crate) fn into_native(self) -> nativeFallback {
1272 Fallback::SegWitProgram {mut version, mut program, } => {
1273 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1274 nativeFallback::SegWitProgram {
1275 version: version.into(),
1276 program: local_program,
1279 Fallback::PubKeyHash (mut a, ) => {
1280 nativeFallback::PubKeyHash (
1284 Fallback::ScriptHash (mut a, ) => {
1285 nativeFallback::ScriptHash (
1292 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1294 nativeFallback::SegWitProgram {ref version, ref program, } => {
1295 let mut version_nonref = (*version).clone();
1296 let mut program_nonref = (*program).clone();
1297 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1298 Fallback::SegWitProgram {
1299 version: version_nonref.into(),
1300 program: local_program_nonref.into(),
1303 nativeFallback::PubKeyHash (ref a, ) => {
1304 let mut a_nonref = (*a).clone();
1305 Fallback::PubKeyHash (
1306 crate::c_types::TwentyBytes { data: a_nonref },
1309 nativeFallback::ScriptHash (ref a, ) => {
1310 let mut a_nonref = (*a).clone();
1311 Fallback::ScriptHash (
1312 crate::c_types::TwentyBytes { data: a_nonref },
1318 pub(crate) fn native_into(native: nativeFallback) -> Self {
1320 nativeFallback::SegWitProgram {mut version, mut program, } => {
1321 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1322 Fallback::SegWitProgram {
1323 version: version.into(),
1324 program: local_program.into(),
1327 nativeFallback::PubKeyHash (mut a, ) => {
1328 Fallback::PubKeyHash (
1329 crate::c_types::TwentyBytes { data: a },
1332 nativeFallback::ScriptHash (mut a, ) => {
1333 Fallback::ScriptHash (
1334 crate::c_types::TwentyBytes { data: a },
1340 /// Frees any resources used by the Fallback
1342 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1343 /// Creates a copy of the Fallback
1345 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1349 /// Utility method to constructs a new SegWitProgram-variant Fallback
1350 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::u5, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
1351 Fallback::SegWitProgram {
1357 /// Utility method to constructs a new PubKeyHash-variant Fallback
1358 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1359 Fallback::PubKeyHash(a, )
1362 /// Utility method to constructs a new ScriptHash-variant Fallback
1363 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1364 Fallback::ScriptHash(a, )
1366 /// Checks if two Fallbacks contain equal inner contents.
1368 pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 {
1369 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
1370 #[allow(deprecated)]
1371 let mut hasher = core::hash::SipHasher::new();
1372 std::hash::Hash::hash(&o.to_native(), &mut hasher);
1373 std::hash::Hasher::finish(&hasher)
1375 /// Checks if two Fallbacks contain equal inner contents.
1376 /// This ignores pointers and is_owned flags and looks at the values in fields.
1378 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1379 if &a.to_native() == &b.to_native() { true } else { false }
1382 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1383 type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1385 /// Recoverable signature
1388 pub struct InvoiceSignature {
1389 /// A pointer to the opaque Rust object.
1391 /// Nearly everywhere, inner must be non-null, however in places where
1392 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1393 pub inner: *mut nativeInvoiceSignature,
1394 /// Indicates that this is the only struct which contains the same pointer.
1396 /// Rust functions which take ownership of an object provided via an argument require
1397 /// this to be true and invalidate the object pointed to by inner.
1401 impl Drop for InvoiceSignature {
1402 fn drop(&mut self) {
1403 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1404 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1408 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1410 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1412 /// Used only if an object of this type is returned as a trait impl by a method
1413 extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1414 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1417 impl InvoiceSignature {
1418 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceSignature {
1419 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1421 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceSignature {
1422 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1424 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1425 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1426 assert!(self.is_owned);
1427 let ret = ObjOps::untweak_ptr(self.inner);
1428 self.inner = std::ptr::null_mut();
1432 impl Clone for InvoiceSignature {
1433 fn clone(&self) -> Self {
1435 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { std::ptr::null_mut() } else {
1436 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1442 /// Used only if an object of this type is returned as a trait impl by a method
1443 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
1444 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
1447 /// Creates a copy of the InvoiceSignature
1448 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
1451 /// Checks if two InvoiceSignatures contain equal inner contents.
1452 /// This ignores pointers and is_owned flags and looks at the values in fields.
1453 /// Two objects with NULL inner values will be considered "equal" here.
1455 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
1456 if a.inner == b.inner { return true; }
1457 if a.inner.is_null() || b.inner.is_null() { return false; }
1458 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1461 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
1462 type nativePrivateRoute = nativePrivateRouteImport;
1464 /// Private routing information
1467 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
1471 pub struct PrivateRoute {
1472 /// A pointer to the opaque Rust object.
1474 /// Nearly everywhere, inner must be non-null, however in places where
1475 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1476 pub inner: *mut nativePrivateRoute,
1477 /// Indicates that this is the only struct which contains the same pointer.
1479 /// Rust functions which take ownership of an object provided via an argument require
1480 /// this to be true and invalidate the object pointed to by inner.
1484 impl Drop for PrivateRoute {
1485 fn drop(&mut self) {
1486 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
1487 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1491 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
1493 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
1495 /// Used only if an object of this type is returned as a trait impl by a method
1496 extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
1497 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); }
1501 pub(crate) fn get_native_ref(&self) -> &'static nativePrivateRoute {
1502 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1504 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateRoute {
1505 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1507 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1508 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
1509 assert!(self.is_owned);
1510 let ret = ObjOps::untweak_ptr(self.inner);
1511 self.inner = std::ptr::null_mut();
1515 impl Clone for PrivateRoute {
1516 fn clone(&self) -> Self {
1518 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { std::ptr::null_mut() } else {
1519 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1525 /// Used only if an object of this type is returned as a trait impl by a method
1526 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
1527 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
1530 /// Creates a copy of the PrivateRoute
1531 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
1534 /// Checks if two PrivateRoutes contain equal inner contents.
1536 pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 {
1537 if o.inner.is_null() { return 0; }
1538 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
1539 #[allow(deprecated)]
1540 let mut hasher = core::hash::SipHasher::new();
1541 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1542 std::hash::Hasher::finish(&hasher)
1544 /// Checks if two PrivateRoutes contain equal inner contents.
1545 /// This ignores pointers and is_owned flags and looks at the values in fields.
1546 /// Two objects with NULL inner values will be considered "equal" here.
1548 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
1549 if a.inner == b.inner { return true; }
1550 if a.inner.is_null() || b.inner.is_null() { return false; }
1551 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1553 /// Disassembles the `SignedRawInvoice` into its three parts:
1555 /// 2. hash of the raw invoice
1559 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
1560 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
1561 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();
1565 /// The `RawInvoice` which was signed.
1568 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
1569 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice();
1570 crate::lightning_invoice::RawInvoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false }
1573 /// The hash of the `RawInvoice` that was signed.
1576 pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [u8; 32] {
1577 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
1581 /// InvoiceSignature for the invoice.
1584 pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
1585 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
1586 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false }
1589 /// Recovers the public key used for signing the invoice from the recoverable signature.
1592 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
1593 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
1594 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() };
1598 /// Checks if the signature is valid for the included payee public key or if none exists if it's
1599 /// valid for the recovered signature (which should always be true?).
1602 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &SignedRawInvoice) -> bool {
1603 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
1607 /// Calculate the hash of the encoded `RawInvoice`
1610 pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1611 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
1612 crate::c_types::ThirtyTwoBytes { data: ret }
1616 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1619 pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1620 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
1621 let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1626 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1629 pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightning_invoice::Description {
1630 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
1631 let mut local_ret = crate::lightning_invoice::Description { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1636 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1639 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::lightning_invoice::PayeePubKey {
1640 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
1641 let mut local_ret = crate::lightning_invoice::PayeePubKey { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1646 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1649 pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1650 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash();
1651 let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1656 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1659 pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightning_invoice::ExpiryTime {
1660 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
1661 let mut local_ret = crate::lightning_invoice::ExpiryTime { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
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_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
1670 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
1671 let mut local_ret = crate::lightning_invoice::MinFinalCltvExpiry { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) 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_payment_secret(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1680 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
1681 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
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_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
1690 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
1691 let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1697 pub extern "C" fn RawInvoice_private_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1698 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
1699 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 _) as *mut _) }, is_owned: false } }); };
1705 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z {
1706 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
1707 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() }) };
1713 pub extern "C" fn RawInvoice_currency(this_arg: &RawInvoice) -> crate::lightning_invoice::Currency {
1714 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
1715 crate::lightning_invoice::Currency::native_into(ret)
1718 /// Create a new `PositiveTimestamp` from a unix timestamp in the Range
1719 /// `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1720 /// `CreationError::TimestampOutOfBounds`.
1723 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1724 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
1725 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() };
1729 /// Create a new `PositiveTimestamp` from a `SystemTime` with a corresponding unix timestamp in
1730 /// the Range `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1731 /// `CreationError::TimestampOutOfBounds`.
1734 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1735 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
1736 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() };
1740 /// Returns the UNIX timestamp representing the stored time
1743 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 {
1744 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_unix_timestamp();
1748 /// Returns a reference to the internal `SystemTime` time representation
1751 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &PositiveTimestamp) -> u64 {
1752 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_time();
1753 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1756 /// Transform the `Invoice` into it's unchecked version
1759 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::lightning_invoice::SignedRawInvoice {
1760 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
1761 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(ret), is_owned: true }
1764 /// Check that the invoice is signed correctly and that key recovery works
1767 pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
1768 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
1769 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() };
1773 /// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
1775 /// use lightning_invoice::*;
1777 /// let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
1778 /// h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
1779 /// 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
1780 /// h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
1781 /// j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
1782 /// ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
1783 /// guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
1784 /// ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
1785 /// p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
1786 /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
1787 /// j5r6drg6k6zcqj0fcwg\";
1789 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
1791 /// assert!(Invoice::from_signed(signed).is_ok());
1795 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
1796 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
1797 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() };
1801 /// Returns the `Invoice`'s timestamp (should equal it's creation time)
1804 pub extern "C" fn Invoice_timestamp(this_arg: &Invoice) -> u64 {
1805 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timestamp();
1806 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1809 /// Returns the hash to which we will receive the preimage on completion of the payment
1812 pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] {
1813 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
1817 /// Get the payee's public key if one was included in the invoice
1819 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1822 pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1823 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
1824 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
1828 /// Get the payment secret if one was included in the invoice
1831 pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> crate::c_types::ThirtyTwoBytes {
1832 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
1833 crate::c_types::ThirtyTwoBytes { data: ret.0 }
1836 /// Get the invoice features if they were included in the invoice
1838 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1841 pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
1842 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
1843 let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1847 /// Recover the payee's public key (only to be used if none was included in the invoice)
1850 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1851 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
1852 crate::c_types::PublicKey::from_rust(&ret)
1855 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
1858 pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 {
1859 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
1863 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
1864 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
1867 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 {
1868 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
1872 /// Returns a list of all routes included in the invoice
1875 pub extern "C" fn Invoice_private_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1876 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
1877 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 _) as *mut _) }, is_owned: false } }); };
1881 /// Returns a list of all routes included in the invoice as the underlying hints
1884 pub extern "C" fn Invoice_route_hints(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
1885 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints();
1886 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::router::RouteHint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const _) as *mut _) }, is_owned: false } }); };
1890 /// Returns the currency for which the invoice was issued
1893 pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoice::Currency {
1894 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
1895 crate::lightning_invoice::Currency::native_into(ret)
1898 /// Returns the amount if specified in the invoice as pico <currency>.
1901 pub extern "C" fn Invoice_amount_pico_btc(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z {
1902 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
1903 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() }) };
1907 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
1908 /// returns `CreationError::DescriptionTooLong` otherwise
1910 /// Please note that single characters may use more than one byte due to UTF8 encoding.
1913 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
1914 let mut ret = lightning_invoice::Description::new(description.into_string());
1915 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() };
1919 /// Returns the underlying description `String`
1922 pub extern "C" fn Description_into_inner(mut this_arg: Description) -> crate::c_types::Str {
1923 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1927 /// Construct an `ExpiryTime` from seconds. If there exists a `PositiveTimestamp` which would
1928 /// overflow on adding the `EpiryTime` to it then this function will return a
1929 /// `CreationError::ExpiryTimeOutOfBounds`.
1932 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1933 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
1934 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
1938 /// Construct an `ExpiryTime` from a `Duration`. If there exists a `PositiveTimestamp` which
1939 /// would overflow on adding the `EpiryTime` to it then this function will return a
1940 /// `CreationError::ExpiryTimeOutOfBounds`.
1943 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1944 let mut ret = lightning_invoice::ExpiryTime::from_duration(std::time::Duration::from_secs(duration));
1945 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
1949 /// Returns the expiry time in seconds
1952 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 {
1953 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_seconds();
1957 /// Returns a reference to the underlying `Duration` (=expiry time)
1960 pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 {
1961 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration();
1965 /// Creates a new (partial) route from a list of hops
1968 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
1969 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
1970 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() };
1974 /// Returns the underlying list of hops
1977 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: PrivateRoute) -> crate::lightning::routing::router::RouteHint {
1978 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1979 crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true }
1982 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
1986 pub enum CreationError {
1987 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
1989 /// The specified route has too many hops and can't be encoded
1991 /// The unix timestamp of the supplied date is <0 or can't be represented as `SystemTime`
1992 TimestampOutOfBounds,
1993 /// The supplied expiry time could cause an overflow if added to a `PositiveTimestamp`
1994 ExpiryTimeOutOfBounds,
1996 use lightning_invoice::CreationError as nativeCreationError;
1997 impl CreationError {
1999 pub(crate) fn to_native(&self) -> nativeCreationError {
2001 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2002 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2003 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2004 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
2008 pub(crate) fn into_native(self) -> nativeCreationError {
2010 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2011 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2012 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2013 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
2017 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
2019 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2020 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2021 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2022 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
2026 pub(crate) fn native_into(native: nativeCreationError) -> Self {
2028 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2029 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2030 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2031 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
2035 /// Creates a copy of the CreationError
2037 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
2041 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
2042 pub extern "C" fn CreationError_description_too_long() -> CreationError {
2043 CreationError::DescriptionTooLong}
2045 /// Utility method to constructs a new RouteTooLong-variant CreationError
2046 pub extern "C" fn CreationError_route_too_long() -> CreationError {
2047 CreationError::RouteTooLong}
2049 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
2050 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
2051 CreationError::TimestampOutOfBounds}
2053 /// Utility method to constructs a new ExpiryTimeOutOfBounds-variant CreationError
2054 pub extern "C" fn CreationError_expiry_time_out_of_bounds() -> CreationError {
2055 CreationError::ExpiryTimeOutOfBounds}
2056 /// Checks if two CreationErrors contain equal inner contents.
2057 /// This ignores pointers and is_owned flags and looks at the values in fields.
2059 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
2060 if &a.to_native() == &b.to_native() { true } else { false }
2063 /// Get the string representation of a CreationError object
2064 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
2065 format!("{}", &o.to_native()).into()
2067 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
2068 /// requirements sections in BOLT #11
2072 pub enum SemanticError {
2073 /// The invoice is missing the mandatory payment hash
2075 /// The invoice has multiple payment hashes which isn't allowed
2076 MultiplePaymentHashes,
2077 /// No description or description hash are part of the invoice
2079 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
2080 MultipleDescriptions,
2081 /// The invoice is missing the mandatory payment secret, which all modern lightning nodes
2084 /// The invoice contains multiple payment secrets
2085 MultiplePaymentSecrets,
2086 /// The invoice's features are invalid
2088 /// The recovery id doesn't fit the signature/pub key
2090 /// The invoice's signature is invalid
2092 /// The invoice's amount was not a whole number of millisatoshis
2095 use lightning_invoice::SemanticError as nativeSemanticError;
2096 impl SemanticError {
2098 pub(crate) fn to_native(&self) -> nativeSemanticError {
2100 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2101 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2102 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2103 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2104 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2105 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2106 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2107 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2108 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2109 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2113 pub(crate) fn into_native(self) -> nativeSemanticError {
2115 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2116 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2117 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2118 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2119 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2120 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2121 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2122 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2123 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2124 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2128 pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
2130 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2131 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2132 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2133 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2134 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2135 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2136 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2137 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2138 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2139 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2143 pub(crate) fn native_into(native: nativeSemanticError) -> Self {
2145 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2146 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2147 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2148 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2149 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2150 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2151 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2152 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2153 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2154 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2158 /// Creates a copy of the SemanticError
2160 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
2164 /// Utility method to constructs a new NoPaymentHash-variant SemanticError
2165 pub extern "C" fn SemanticError_no_payment_hash() -> SemanticError {
2166 SemanticError::NoPaymentHash}
2168 /// Utility method to constructs a new MultiplePaymentHashes-variant SemanticError
2169 pub extern "C" fn SemanticError_multiple_payment_hashes() -> SemanticError {
2170 SemanticError::MultiplePaymentHashes}
2172 /// Utility method to constructs a new NoDescription-variant SemanticError
2173 pub extern "C" fn SemanticError_no_description() -> SemanticError {
2174 SemanticError::NoDescription}
2176 /// Utility method to constructs a new MultipleDescriptions-variant SemanticError
2177 pub extern "C" fn SemanticError_multiple_descriptions() -> SemanticError {
2178 SemanticError::MultipleDescriptions}
2180 /// Utility method to constructs a new NoPaymentSecret-variant SemanticError
2181 pub extern "C" fn SemanticError_no_payment_secret() -> SemanticError {
2182 SemanticError::NoPaymentSecret}
2184 /// Utility method to constructs a new MultiplePaymentSecrets-variant SemanticError
2185 pub extern "C" fn SemanticError_multiple_payment_secrets() -> SemanticError {
2186 SemanticError::MultiplePaymentSecrets}
2188 /// Utility method to constructs a new InvalidFeatures-variant SemanticError
2189 pub extern "C" fn SemanticError_invalid_features() -> SemanticError {
2190 SemanticError::InvalidFeatures}
2192 /// Utility method to constructs a new InvalidRecoveryId-variant SemanticError
2193 pub extern "C" fn SemanticError_invalid_recovery_id() -> SemanticError {
2194 SemanticError::InvalidRecoveryId}
2196 /// Utility method to constructs a new InvalidSignature-variant SemanticError
2197 pub extern "C" fn SemanticError_invalid_signature() -> SemanticError {
2198 SemanticError::InvalidSignature}
2200 /// Utility method to constructs a new ImpreciseAmount-variant SemanticError
2201 pub extern "C" fn SemanticError_imprecise_amount() -> SemanticError {
2202 SemanticError::ImpreciseAmount}
2203 /// Checks if two SemanticErrors contain equal inner contents.
2204 /// This ignores pointers and is_owned flags and looks at the values in fields.
2206 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
2207 if &a.to_native() == &b.to_native() { true } else { false }
2210 /// Get the string representation of a SemanticError object
2211 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
2212 format!("{}", &o.to_native()).into()
2214 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
2219 pub enum SignOrCreationError {
2220 /// An error occurred during signing
2222 /// An error occurred while building the transaction
2223 CreationError(crate::lightning_invoice::CreationError),
2225 use lightning_invoice::SignOrCreationError as nativeSignOrCreationError;
2226 impl SignOrCreationError {
2228 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
2230 SignOrCreationError::SignError => {
2231 nativeSignOrCreationError::SignError (
2235 SignOrCreationError::CreationError (ref a, ) => {
2236 let mut a_nonref = (*a).clone();
2237 nativeSignOrCreationError::CreationError (
2238 a_nonref.into_native(),
2244 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
2246 SignOrCreationError::SignError => {
2247 nativeSignOrCreationError::SignError (
2251 SignOrCreationError::CreationError (mut a, ) => {
2252 nativeSignOrCreationError::CreationError (
2259 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
2261 nativeSignOrCreationError::SignError (ref a, ) => {
2262 SignOrCreationError::SignError },
2263 nativeSignOrCreationError::CreationError (ref a, ) => {
2264 let mut a_nonref = (*a).clone();
2265 SignOrCreationError::CreationError (
2266 crate::lightning_invoice::CreationError::native_into(a_nonref),
2272 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
2274 nativeSignOrCreationError::SignError (mut a, ) => {
2275 SignOrCreationError::SignError },
2276 nativeSignOrCreationError::CreationError (mut a, ) => {
2277 SignOrCreationError::CreationError (
2278 crate::lightning_invoice::CreationError::native_into(a),
2284 /// Frees any resources used by the SignOrCreationError
2286 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
2287 /// Creates a copy of the SignOrCreationError
2289 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
2293 /// Utility method to constructs a new SignError-variant SignOrCreationError
2294 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
2295 SignOrCreationError::SignError
2298 /// Utility method to constructs a new CreationError-variant SignOrCreationError
2299 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
2300 SignOrCreationError::CreationError(a, )
2302 /// Checks if two SignOrCreationErrors contain equal inner contents.
2303 /// This ignores pointers and is_owned flags and looks at the values in fields.
2305 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
2306 if &a.to_native() == &b.to_native() { true } else { false }
2309 /// Get the string representation of a SignOrCreationError object
2310 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
2311 format!("{}", &o.to_native()).into()