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::*;
29 use std::str::FromStr;
31 use core::convert::Infallible;
32 use bitcoin::hashes::Hash;
33 use crate::c_types::*;
37 use std::str::FromStr;
39 use core::convert::Infallible;
40 use bitcoin::hashes::Hash;
41 use crate::c_types::*;
45 /// Read a SiPrefix object from a string
46 pub extern "C" fn SiPrefix_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SiPrefixNoneZ {
47 match lightning_invoice::SiPrefix::from_str(s.into_str()) {
49 crate::c_types::CResultTempl::ok(
50 crate::lightning_invoice::SiPrefix::native_into(r)
53 Err(e) => crate::c_types::CResultTempl::err(()),
57 /// Read a Invoice object from a string
58 pub extern "C" fn Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_InvoiceNoneZ {
59 match lightning_invoice::Invoice::from_str(s.into_str()) {
61 crate::c_types::CResultTempl::ok(
62 crate::lightning_invoice::Invoice { inner: ObjOps::heap_alloc(r), is_owned: true }
65 Err(e) => crate::c_types::CResultTempl::err(()),
69 /// Read a SignedRawInvoice object from a string
70 pub extern "C" fn SignedRawInvoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SignedRawInvoiceNoneZ {
71 match lightning_invoice::SignedRawInvoice::from_str(s.into_str()) {
73 crate::c_types::CResultTempl::ok(
74 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(r), is_owned: true }
77 Err(e) => crate::c_types::CResultTempl::err(()),
83 use std::str::FromStr;
85 use core::convert::Infallible;
86 use bitcoin::hashes::Hash;
87 use crate::c_types::*;
90 /// Get the string representation of a Invoice object
91 pub extern "C" fn Invoice_to_str(o: &crate::lightning_invoice::Invoice) -> Str {
92 format!("{}", o.get_native_ref()).into()
95 /// Get the string representation of a SignedRawInvoice object
96 pub extern "C" fn SignedRawInvoice_to_str(o: &crate::lightning_invoice::SignedRawInvoice) -> Str {
97 format!("{}", o.get_native_ref()).into()
100 /// Get the string representation of a Currency object
101 pub extern "C" fn Currency_to_str(o: &crate::lightning_invoice::Currency) -> Str {
102 format!("{}", &o.to_native()).into()
105 /// Get the string representation of a SiPrefix object
106 pub extern "C" fn SiPrefix_to_str(o: &crate::lightning_invoice::SiPrefix) -> Str {
107 format!("{}", &o.to_native()).into()
112 use std::str::FromStr;
113 use std::ffi::c_void;
114 use core::convert::Infallible;
115 use bitcoin::hashes::Hash;
116 use crate::c_types::*;
119 /// Default expiry time as defined by [BOLT 11].
121 /// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md
124 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
125 /// Default minimum final CLTV expiry as defined by [BOLT 11].
127 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
128 /// provided in [`MIN_FINAL_CLTV_EXPIRY`].
130 /// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md
131 /// [`MIN_FINAL_CLTV_EXPIRY`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY
134 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY;
135 /// **Call this function on startup to ensure that all assumptions about the platform are valid.**
137 /// Unfortunately we have to make assumptions about the upper bounds of the `SystemTime` type on
138 /// your platform which we can't fully verify at compile time and which isn't part of it's contract.
139 /// To our best knowledge our assumptions hold for all platforms officially supported by rust, but
140 /// since this check is fast we recommend to do it anyway.
142 /// If this function fails this is considered a bug. Please open an issue describing your
143 /// platform and stating your current system time.
146 /// If the check fails this function panics. By calling this function on startup you ensure that
147 /// this wont happen at an arbitrary later point in time.
149 pub extern "C" fn check_platform() {
150 lightning_invoice::check_platform()
154 use lightning_invoice::Invoice as nativeInvoiceImport;
155 pub(crate) type nativeInvoice = nativeInvoiceImport;
157 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
159 /// There are three ways to construct an `Invoice`:
160 /// 1. using `InvoiceBuilder`
161 /// 2. using `Invoice::from_signed(SignedRawInvoice)`
162 /// 3. using `str::parse::<Invoice>(&str)`
166 /// A pointer to the opaque Rust object.
168 /// Nearly everywhere, inner must be non-null, however in places where
169 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
170 pub inner: *mut nativeInvoice,
171 /// Indicates that this is the only struct which contains the same pointer.
173 /// Rust functions which take ownership of an object provided via an argument require
174 /// this to be true and invalidate the object pointed to by inner.
178 impl Drop for Invoice {
180 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
181 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
185 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
187 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
189 /// Used only if an object of this type is returned as a trait impl by a method
190 pub(crate) extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
191 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
195 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoice {
196 unsafe { &*ObjOps::untweak_ptr(self.inner) }
198 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoice {
199 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
201 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
202 pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
203 assert!(self.is_owned);
204 let ret = ObjOps::untweak_ptr(self.inner);
205 self.inner = std::ptr::null_mut();
209 /// Checks if two Invoices contain equal inner contents.
210 /// This ignores pointers and is_owned flags and looks at the values in fields.
211 /// Two objects with NULL inner values will be considered "equal" here.
213 pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool {
214 if a.inner == b.inner { return true; }
215 if a.inner.is_null() || b.inner.is_null() { return false; }
216 if a.get_native_ref() == b.get_native_ref() { true } else { false }
218 impl Clone for Invoice {
219 fn clone(&self) -> Self {
221 inner: if <*mut nativeInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
222 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
228 /// Used only if an object of this type is returned as a trait impl by a method
229 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
230 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
233 /// Creates a copy of the Invoice
234 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
238 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
239 pub(crate) type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
241 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
245 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
248 pub struct SignedRawInvoice {
249 /// A pointer to the opaque Rust object.
251 /// Nearly everywhere, inner must be non-null, however in places where
252 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
253 pub inner: *mut nativeSignedRawInvoice,
254 /// Indicates that this is the only struct which contains the same pointer.
256 /// Rust functions which take ownership of an object provided via an argument require
257 /// this to be true and invalidate the object pointed to by inner.
261 impl Drop for SignedRawInvoice {
263 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
264 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
268 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
270 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
272 /// Used only if an object of this type is returned as a trait impl by a method
273 pub(crate) extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
274 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
277 impl SignedRawInvoice {
278 pub(crate) fn get_native_ref(&self) -> &'static nativeSignedRawInvoice {
279 unsafe { &*ObjOps::untweak_ptr(self.inner) }
281 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSignedRawInvoice {
282 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
284 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
285 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
286 assert!(self.is_owned);
287 let ret = ObjOps::untweak_ptr(self.inner);
288 self.inner = std::ptr::null_mut();
292 /// Checks if two SignedRawInvoices contain equal inner contents.
293 /// This ignores pointers and is_owned flags and looks at the values in fields.
294 /// Two objects with NULL inner values will be considered "equal" here.
296 pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice) -> bool {
297 if a.inner == b.inner { return true; }
298 if a.inner.is_null() || b.inner.is_null() { return false; }
299 if a.get_native_ref() == b.get_native_ref() { true } else { false }
301 impl Clone for SignedRawInvoice {
302 fn clone(&self) -> Self {
304 inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
305 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
311 /// Used only if an object of this type is returned as a trait impl by a method
312 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
313 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
316 /// Creates a copy of the SignedRawInvoice
317 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
321 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
322 pub(crate) type nativeRawInvoice = nativeRawInvoiceImport;
324 /// Represents an syntactically correct Invoice for a payment on the lightning network,
325 /// but without the signature information.
326 /// De- and encoding should not lead to information loss but may lead to different hashes.
328 /// For methods without docs see the corresponding methods in `Invoice`.
331 pub struct RawInvoice {
332 /// A pointer to the opaque Rust object.
334 /// Nearly everywhere, inner must be non-null, however in places where
335 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
336 pub inner: *mut nativeRawInvoice,
337 /// Indicates that this is the only struct which contains the same pointer.
339 /// Rust functions which take ownership of an object provided via an argument require
340 /// this to be true and invalidate the object pointed to by inner.
344 impl Drop for RawInvoice {
346 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
347 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
351 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
353 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
355 /// Used only if an object of this type is returned as a trait impl by a method
356 pub(crate) extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
357 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
361 pub(crate) fn get_native_ref(&self) -> &'static nativeRawInvoice {
362 unsafe { &*ObjOps::untweak_ptr(self.inner) }
364 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawInvoice {
365 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
367 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
368 pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
369 assert!(self.is_owned);
370 let ret = ObjOps::untweak_ptr(self.inner);
371 self.inner = std::ptr::null_mut();
377 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
378 let mut inner_val = &mut this_ptr.get_native_mut_ref().data;
379 crate::lightning_invoice::RawDataPart { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::RawDataPart<>) as *mut _) }, is_owned: false }
383 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
384 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.data = *unsafe { Box::from_raw(val.take_inner()) };
386 /// Checks if two RawInvoices contain equal inner contents.
387 /// This ignores pointers and is_owned flags and looks at the values in fields.
388 /// Two objects with NULL inner values will be considered "equal" here.
390 pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool {
391 if a.inner == b.inner { return true; }
392 if a.inner.is_null() || b.inner.is_null() { return false; }
393 if a.get_native_ref() == b.get_native_ref() { true } else { false }
395 impl Clone for RawInvoice {
396 fn clone(&self) -> Self {
398 inner: if <*mut nativeRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
399 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
405 /// Used only if an object of this type is returned as a trait impl by a method
406 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
407 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
410 /// Creates a copy of the RawInvoice
411 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
415 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
416 pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
418 /// Data of the `RawInvoice` that is encoded in the data part
421 pub struct RawDataPart {
422 /// A pointer to the opaque Rust object.
424 /// Nearly everywhere, inner must be non-null, however in places where
425 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
426 pub inner: *mut nativeRawDataPart,
427 /// Indicates that this is the only struct which contains the same pointer.
429 /// Rust functions which take ownership of an object provided via an argument require
430 /// this to be true and invalidate the object pointed to by inner.
434 impl Drop for RawDataPart {
436 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
437 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
441 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
443 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
445 /// Used only if an object of this type is returned as a trait impl by a method
446 pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
447 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
451 pub(crate) fn get_native_ref(&self) -> &'static nativeRawDataPart {
452 unsafe { &*ObjOps::untweak_ptr(self.inner) }
454 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawDataPart {
455 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
457 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
458 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
459 assert!(self.is_owned);
460 let ret = ObjOps::untweak_ptr(self.inner);
461 self.inner = std::ptr::null_mut();
465 /// generation time of the invoice
467 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
468 let mut inner_val = &mut this_ptr.get_native_mut_ref().timestamp;
469 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::PositiveTimestamp<>) as *mut _) }, is_owned: false }
471 /// generation time of the invoice
473 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
474 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
476 /// Checks if two RawDataParts contain equal inner contents.
477 /// This ignores pointers and is_owned flags and looks at the values in fields.
478 /// Two objects with NULL inner values will be considered "equal" here.
480 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
481 if a.inner == b.inner { return true; }
482 if a.inner.is_null() || b.inner.is_null() { return false; }
483 if a.get_native_ref() == b.get_native_ref() { true } else { false }
485 impl Clone for RawDataPart {
486 fn clone(&self) -> Self {
488 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { std::ptr::null_mut() } else {
489 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
495 /// Used only if an object of this type is returned as a trait impl by a method
496 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
497 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
500 /// Creates a copy of the RawDataPart
501 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
505 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
506 pub(crate) type nativePositiveTimestamp = nativePositiveTimestampImport;
508 /// A timestamp that refers to a date after 1 January 1970 which means its representation as UNIX
509 /// timestamp is positive.
512 /// The UNIX timestamp representing the stored time has to be positive and small enough so that
513 /// a `EpiryTime` can be added to it without an overflow.
516 pub struct PositiveTimestamp {
517 /// A pointer to the opaque Rust object.
519 /// Nearly everywhere, inner must be non-null, however in places where
520 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
521 pub inner: *mut nativePositiveTimestamp,
522 /// Indicates that this is the only struct which contains the same pointer.
524 /// Rust functions which take ownership of an object provided via an argument require
525 /// this to be true and invalidate the object pointed to by inner.
529 impl Drop for PositiveTimestamp {
531 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
532 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
536 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
538 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
540 /// Used only if an object of this type is returned as a trait impl by a method
541 pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
542 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
545 impl PositiveTimestamp {
546 pub(crate) fn get_native_ref(&self) -> &'static nativePositiveTimestamp {
547 unsafe { &*ObjOps::untweak_ptr(self.inner) }
549 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePositiveTimestamp {
550 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
552 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
553 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
554 assert!(self.is_owned);
555 let ret = ObjOps::untweak_ptr(self.inner);
556 self.inner = std::ptr::null_mut();
560 /// Checks if two PositiveTimestamps contain equal inner contents.
561 /// This ignores pointers and is_owned flags and looks at the values in fields.
562 /// Two objects with NULL inner values will be considered "equal" here.
564 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
565 if a.inner == b.inner { return true; }
566 if a.inner.is_null() || b.inner.is_null() { return false; }
567 if a.get_native_ref() == b.get_native_ref() { true } else { false }
569 impl Clone for PositiveTimestamp {
570 fn clone(&self) -> Self {
572 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { std::ptr::null_mut() } else {
573 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
579 /// Used only if an object of this type is returned as a trait impl by a method
580 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
581 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
584 /// Creates a copy of the PositiveTimestamp
585 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
588 /// SI prefixes for the human readable part
602 use lightning_invoice::SiPrefix as nativeSiPrefix;
605 pub(crate) fn to_native(&self) -> nativeSiPrefix {
607 SiPrefix::Milli => nativeSiPrefix::Milli,
608 SiPrefix::Micro => nativeSiPrefix::Micro,
609 SiPrefix::Nano => nativeSiPrefix::Nano,
610 SiPrefix::Pico => nativeSiPrefix::Pico,
614 pub(crate) fn into_native(self) -> nativeSiPrefix {
616 SiPrefix::Milli => nativeSiPrefix::Milli,
617 SiPrefix::Micro => nativeSiPrefix::Micro,
618 SiPrefix::Nano => nativeSiPrefix::Nano,
619 SiPrefix::Pico => nativeSiPrefix::Pico,
623 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
625 nativeSiPrefix::Milli => SiPrefix::Milli,
626 nativeSiPrefix::Micro => SiPrefix::Micro,
627 nativeSiPrefix::Nano => SiPrefix::Nano,
628 nativeSiPrefix::Pico => SiPrefix::Pico,
632 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
634 nativeSiPrefix::Milli => SiPrefix::Milli,
635 nativeSiPrefix::Micro => SiPrefix::Micro,
636 nativeSiPrefix::Nano => SiPrefix::Nano,
637 nativeSiPrefix::Pico => SiPrefix::Pico,
641 /// Creates a copy of the SiPrefix
643 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
647 /// Utility method to constructs a new Milli-variant SiPrefix
648 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
651 /// Utility method to constructs a new Micro-variant SiPrefix
652 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
655 /// Utility method to constructs a new Nano-variant SiPrefix
656 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
659 /// Utility method to constructs a new Pico-variant SiPrefix
660 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
662 /// Checks if two SiPrefixs contain equal inner contents.
663 /// This ignores pointers and is_owned flags and looks at the values in fields.
665 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
666 if &a.to_native() == &b.to_native() { true } else { false }
668 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
669 /// This is effectively 10^12 * the prefix multiplier
672 pub extern "C" fn SiPrefix_multiplier(this_arg: &SiPrefix) -> u64 {
673 let mut ret = this_arg.to_native().multiplier();
677 /// Enum representing the crypto currencies (or networks) supported by this library
693 use lightning_invoice::Currency as nativeCurrency;
696 pub(crate) fn to_native(&self) -> nativeCurrency {
698 Currency::Bitcoin => nativeCurrency::Bitcoin,
699 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
700 Currency::Regtest => nativeCurrency::Regtest,
701 Currency::Simnet => nativeCurrency::Simnet,
702 Currency::Signet => nativeCurrency::Signet,
706 pub(crate) fn into_native(self) -> nativeCurrency {
708 Currency::Bitcoin => nativeCurrency::Bitcoin,
709 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
710 Currency::Regtest => nativeCurrency::Regtest,
711 Currency::Simnet => nativeCurrency::Simnet,
712 Currency::Signet => nativeCurrency::Signet,
716 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
718 nativeCurrency::Bitcoin => Currency::Bitcoin,
719 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
720 nativeCurrency::Regtest => Currency::Regtest,
721 nativeCurrency::Simnet => Currency::Simnet,
722 nativeCurrency::Signet => Currency::Signet,
726 pub(crate) fn native_into(native: nativeCurrency) -> Self {
728 nativeCurrency::Bitcoin => Currency::Bitcoin,
729 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
730 nativeCurrency::Regtest => Currency::Regtest,
731 nativeCurrency::Simnet => Currency::Simnet,
732 nativeCurrency::Signet => Currency::Signet,
736 /// Creates a copy of the Currency
738 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
742 /// Utility method to constructs a new Bitcoin-variant Currency
743 pub extern "C" fn Currency_bitcoin() -> Currency {
746 /// Utility method to constructs a new BitcoinTestnet-variant Currency
747 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
748 Currency::BitcoinTestnet}
750 /// Utility method to constructs a new Regtest-variant Currency
751 pub extern "C" fn Currency_regtest() -> Currency {
754 /// Utility method to constructs a new Simnet-variant Currency
755 pub extern "C" fn Currency_simnet() -> Currency {
758 /// Utility method to constructs a new Signet-variant Currency
759 pub extern "C" fn Currency_signet() -> Currency {
761 /// Checks if two Currencys contain equal inner contents.
763 pub extern "C" fn Currency_hash(o: &Currency) -> u64 {
764 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
766 let mut hasher = core::hash::SipHasher::new();
767 std::hash::Hash::hash(&o.to_native(), &mut hasher);
768 std::hash::Hasher::finish(&hasher)
770 /// Checks if two Currencys contain equal inner contents.
771 /// This ignores pointers and is_owned flags and looks at the values in fields.
773 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
774 if &a.to_native() == &b.to_native() { true } else { false }
777 use lightning_invoice::Sha256 as nativeSha256Import;
778 pub(crate) type nativeSha256 = nativeSha256Import;
784 /// A pointer to the opaque Rust object.
786 /// Nearly everywhere, inner must be non-null, however in places where
787 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
788 pub inner: *mut nativeSha256,
789 /// Indicates that this is the only struct which contains the same pointer.
791 /// Rust functions which take ownership of an object provided via an argument require
792 /// this to be true and invalidate the object pointed to by inner.
796 impl Drop for Sha256 {
798 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
799 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
803 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
805 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
807 /// Used only if an object of this type is returned as a trait impl by a method
808 pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
809 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
813 pub(crate) fn get_native_ref(&self) -> &'static nativeSha256 {
814 unsafe { &*ObjOps::untweak_ptr(self.inner) }
816 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSha256 {
817 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
819 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
820 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
821 assert!(self.is_owned);
822 let ret = ObjOps::untweak_ptr(self.inner);
823 self.inner = std::ptr::null_mut();
827 impl Clone for Sha256 {
828 fn clone(&self) -> Self {
830 inner: if <*mut nativeSha256>::is_null(self.inner) { std::ptr::null_mut() } else {
831 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
837 /// Used only if an object of this type is returned as a trait impl by a method
838 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
839 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
842 /// Creates a copy of the Sha256
843 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
846 /// Checks if two Sha256s contain equal inner contents.
848 pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 {
849 if o.inner.is_null() { return 0; }
850 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
852 let mut hasher = core::hash::SipHasher::new();
853 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
854 std::hash::Hasher::finish(&hasher)
856 /// Checks if two Sha256s contain equal inner contents.
857 /// This ignores pointers and is_owned flags and looks at the values in fields.
858 /// Two objects with NULL inner values will be considered "equal" here.
860 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
861 if a.inner == b.inner { return true; }
862 if a.inner.is_null() || b.inner.is_null() { return false; }
863 if a.get_native_ref() == b.get_native_ref() { true } else { false }
866 use lightning_invoice::Description as nativeDescriptionImport;
867 pub(crate) type nativeDescription = nativeDescriptionImport;
869 /// Description string
872 /// The description can be at most 639 __bytes__ long
875 pub struct Description {
876 /// A pointer to the opaque Rust object.
878 /// Nearly everywhere, inner must be non-null, however in places where
879 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
880 pub inner: *mut nativeDescription,
881 /// Indicates that this is the only struct which contains the same pointer.
883 /// Rust functions which take ownership of an object provided via an argument require
884 /// this to be true and invalidate the object pointed to by inner.
888 impl Drop for Description {
890 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
891 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
895 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
897 pub extern "C" fn Description_free(this_obj: Description) { }
899 /// Used only if an object of this type is returned as a trait impl by a method
900 pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) {
901 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
905 pub(crate) fn get_native_ref(&self) -> &'static nativeDescription {
906 unsafe { &*ObjOps::untweak_ptr(self.inner) }
908 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDescription {
909 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
911 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
912 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
913 assert!(self.is_owned);
914 let ret = ObjOps::untweak_ptr(self.inner);
915 self.inner = std::ptr::null_mut();
919 impl Clone for Description {
920 fn clone(&self) -> Self {
922 inner: if <*mut nativeDescription>::is_null(self.inner) { std::ptr::null_mut() } else {
923 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
929 /// Used only if an object of this type is returned as a trait impl by a method
930 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
931 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
934 /// Creates a copy of the Description
935 pub extern "C" fn Description_clone(orig: &Description) -> Description {
938 /// Checks if two Descriptions contain equal inner contents.
940 pub extern "C" fn Description_hash(o: &Description) -> u64 {
941 if o.inner.is_null() { return 0; }
942 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
944 let mut hasher = core::hash::SipHasher::new();
945 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
946 std::hash::Hasher::finish(&hasher)
948 /// Checks if two Descriptions contain equal inner contents.
949 /// This ignores pointers and is_owned flags and looks at the values in fields.
950 /// Two objects with NULL inner values will be considered "equal" here.
952 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
953 if a.inner == b.inner { return true; }
954 if a.inner.is_null() || b.inner.is_null() { return false; }
955 if a.get_native_ref() == b.get_native_ref() { true } else { false }
958 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
959 pub(crate) type nativePayeePubKey = nativePayeePubKeyImport;
964 pub struct PayeePubKey {
965 /// A pointer to the opaque Rust object.
967 /// Nearly everywhere, inner must be non-null, however in places where
968 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
969 pub inner: *mut nativePayeePubKey,
970 /// Indicates that this is the only struct which contains the same pointer.
972 /// Rust functions which take ownership of an object provided via an argument require
973 /// this to be true and invalidate the object pointed to by inner.
977 impl Drop for PayeePubKey {
979 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
980 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
984 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
986 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
988 /// Used only if an object of this type is returned as a trait impl by a method
989 pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
990 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
994 pub(crate) fn get_native_ref(&self) -> &'static nativePayeePubKey {
995 unsafe { &*ObjOps::untweak_ptr(self.inner) }
997 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayeePubKey {
998 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1000 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1001 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
1002 assert!(self.is_owned);
1003 let ret = ObjOps::untweak_ptr(self.inner);
1004 self.inner = std::ptr::null_mut();
1009 pub extern "C" fn PayeePubKey_get_a(this_ptr: &PayeePubKey) -> crate::c_types::PublicKey {
1010 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1011 crate::c_types::PublicKey::from_rust(&inner_val)
1014 pub extern "C" fn PayeePubKey_set_a(this_ptr: &mut PayeePubKey, mut val: crate::c_types::PublicKey) {
1015 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
1017 /// Constructs a new PayeePubKey given each field
1020 pub extern "C" fn PayeePubKey_new(mut a_arg: crate::c_types::PublicKey) -> PayeePubKey {
1021 PayeePubKey { inner: ObjOps::heap_alloc(lightning_invoice::PayeePubKey (
1023 )), is_owned: true }
1025 impl Clone for PayeePubKey {
1026 fn clone(&self) -> Self {
1028 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { std::ptr::null_mut() } else {
1029 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1035 /// Used only if an object of this type is returned as a trait impl by a method
1036 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
1037 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
1040 /// Creates a copy of the PayeePubKey
1041 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
1044 /// Checks if two PayeePubKeys contain equal inner contents.
1046 pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 {
1047 if o.inner.is_null() { return 0; }
1048 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
1049 #[allow(deprecated)]
1050 let mut hasher = core::hash::SipHasher::new();
1051 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1052 std::hash::Hasher::finish(&hasher)
1054 /// Checks if two PayeePubKeys contain equal inner contents.
1055 /// This ignores pointers and is_owned flags and looks at the values in fields.
1056 /// Two objects with NULL inner values will be considered "equal" here.
1058 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
1059 if a.inner == b.inner { return true; }
1060 if a.inner.is_null() || b.inner.is_null() { return false; }
1061 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1064 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
1065 pub(crate) type nativeExpiryTime = nativeExpiryTimeImport;
1067 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
1071 /// The number of seconds this expiry time represents has to be in the range
1072 /// `0...(SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME)` to avoid overflows when adding it to a
1076 pub struct ExpiryTime {
1077 /// A pointer to the opaque Rust object.
1079 /// Nearly everywhere, inner must be non-null, however in places where
1080 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1081 pub inner: *mut nativeExpiryTime,
1082 /// Indicates that this is the only struct which contains the same pointer.
1084 /// Rust functions which take ownership of an object provided via an argument require
1085 /// this to be true and invalidate the object pointed to by inner.
1089 impl Drop for ExpiryTime {
1090 fn drop(&mut self) {
1091 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
1092 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1096 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
1098 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
1100 /// Used only if an object of this type is returned as a trait impl by a method
1101 pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
1102 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
1106 pub(crate) fn get_native_ref(&self) -> &'static nativeExpiryTime {
1107 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1109 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpiryTime {
1110 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1112 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1113 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
1114 assert!(self.is_owned);
1115 let ret = ObjOps::untweak_ptr(self.inner);
1116 self.inner = std::ptr::null_mut();
1120 impl Clone for ExpiryTime {
1121 fn clone(&self) -> Self {
1123 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { std::ptr::null_mut() } else {
1124 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1130 /// Used only if an object of this type is returned as a trait impl by a method
1131 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1132 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1135 /// Creates a copy of the ExpiryTime
1136 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1139 /// Checks if two ExpiryTimes contain equal inner contents.
1141 pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 {
1142 if o.inner.is_null() { return 0; }
1143 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
1144 #[allow(deprecated)]
1145 let mut hasher = core::hash::SipHasher::new();
1146 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1147 std::hash::Hasher::finish(&hasher)
1149 /// Checks if two ExpiryTimes contain equal inner contents.
1150 /// This ignores pointers and is_owned flags and looks at the values in fields.
1151 /// Two objects with NULL inner values will be considered "equal" here.
1153 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1154 if a.inner == b.inner { return true; }
1155 if a.inner.is_null() || b.inner.is_null() { return false; }
1156 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1159 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
1160 pub(crate) type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
1162 /// `min_final_cltv_expiry` to use for the last HTLC in the route
1165 pub struct MinFinalCltvExpiry {
1166 /// A pointer to the opaque Rust object.
1168 /// Nearly everywhere, inner must be non-null, however in places where
1169 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1170 pub inner: *mut nativeMinFinalCltvExpiry,
1171 /// Indicates that this is the only struct which contains the same pointer.
1173 /// Rust functions which take ownership of an object provided via an argument require
1174 /// this to be true and invalidate the object pointed to by inner.
1178 impl Drop for MinFinalCltvExpiry {
1179 fn drop(&mut self) {
1180 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
1181 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1185 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1187 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1189 /// Used only if an object of this type is returned as a trait impl by a method
1190 pub(crate) extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1191 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1194 impl MinFinalCltvExpiry {
1195 pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiry {
1196 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1198 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiry {
1199 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1201 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1202 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1203 assert!(self.is_owned);
1204 let ret = ObjOps::untweak_ptr(self.inner);
1205 self.inner = std::ptr::null_mut();
1210 pub extern "C" fn MinFinalCltvExpiry_get_a(this_ptr: &MinFinalCltvExpiry) -> u64 {
1211 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1215 pub extern "C" fn MinFinalCltvExpiry_set_a(this_ptr: &mut MinFinalCltvExpiry, mut val: u64) {
1216 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val;
1218 /// Constructs a new MinFinalCltvExpiry given each field
1221 pub extern "C" fn MinFinalCltvExpiry_new(mut a_arg: u64) -> MinFinalCltvExpiry {
1222 MinFinalCltvExpiry { inner: ObjOps::heap_alloc(lightning_invoice::MinFinalCltvExpiry (
1224 )), is_owned: true }
1226 impl Clone for MinFinalCltvExpiry {
1227 fn clone(&self) -> Self {
1229 inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { std::ptr::null_mut() } else {
1230 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1236 /// Used only if an object of this type is returned as a trait impl by a method
1237 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1238 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1241 /// Creates a copy of the MinFinalCltvExpiry
1242 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1245 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1247 pub extern "C" fn MinFinalCltvExpiry_hash(o: &MinFinalCltvExpiry) -> u64 {
1248 if o.inner.is_null() { return 0; }
1249 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
1250 #[allow(deprecated)]
1251 let mut hasher = core::hash::SipHasher::new();
1252 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1253 std::hash::Hasher::finish(&hasher)
1255 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1256 /// This ignores pointers and is_owned flags and looks at the values in fields.
1257 /// Two objects with NULL inner values will be considered "equal" here.
1259 pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool {
1260 if a.inner == b.inner { return true; }
1261 if a.inner.is_null() || b.inner.is_null() { return false; }
1262 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1264 /// Fallback address in case no LN payment is possible
1270 version: crate::c_types::u5,
1271 program: crate::c_types::derived::CVec_u8Z,
1273 PubKeyHash(crate::c_types::TwentyBytes),
1274 ScriptHash(crate::c_types::TwentyBytes),
1276 use lightning_invoice::Fallback as nativeFallback;
1279 pub(crate) fn to_native(&self) -> nativeFallback {
1281 Fallback::SegWitProgram {ref version, ref program, } => {
1282 let mut version_nonref = (*version).clone();
1283 let mut program_nonref = (*program).clone();
1284 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1285 nativeFallback::SegWitProgram {
1286 version: version_nonref.into(),
1287 program: local_program_nonref,
1290 Fallback::PubKeyHash (ref a, ) => {
1291 let mut a_nonref = (*a).clone();
1292 nativeFallback::PubKeyHash (
1296 Fallback::ScriptHash (ref a, ) => {
1297 let mut a_nonref = (*a).clone();
1298 nativeFallback::ScriptHash (
1305 pub(crate) fn into_native(self) -> nativeFallback {
1307 Fallback::SegWitProgram {mut version, mut program, } => {
1308 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1309 nativeFallback::SegWitProgram {
1310 version: version.into(),
1311 program: local_program,
1314 Fallback::PubKeyHash (mut a, ) => {
1315 nativeFallback::PubKeyHash (
1319 Fallback::ScriptHash (mut a, ) => {
1320 nativeFallback::ScriptHash (
1327 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1329 nativeFallback::SegWitProgram {ref version, ref program, } => {
1330 let mut version_nonref = (*version).clone();
1331 let mut program_nonref = (*program).clone();
1332 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1333 Fallback::SegWitProgram {
1334 version: version_nonref.into(),
1335 program: local_program_nonref.into(),
1338 nativeFallback::PubKeyHash (ref a, ) => {
1339 let mut a_nonref = (*a).clone();
1340 Fallback::PubKeyHash (
1341 crate::c_types::TwentyBytes { data: a_nonref },
1344 nativeFallback::ScriptHash (ref a, ) => {
1345 let mut a_nonref = (*a).clone();
1346 Fallback::ScriptHash (
1347 crate::c_types::TwentyBytes { data: a_nonref },
1353 pub(crate) fn native_into(native: nativeFallback) -> Self {
1355 nativeFallback::SegWitProgram {mut version, mut program, } => {
1356 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1357 Fallback::SegWitProgram {
1358 version: version.into(),
1359 program: local_program.into(),
1362 nativeFallback::PubKeyHash (mut a, ) => {
1363 Fallback::PubKeyHash (
1364 crate::c_types::TwentyBytes { data: a },
1367 nativeFallback::ScriptHash (mut a, ) => {
1368 Fallback::ScriptHash (
1369 crate::c_types::TwentyBytes { data: a },
1375 /// Frees any resources used by the Fallback
1377 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1378 /// Creates a copy of the Fallback
1380 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1384 /// Utility method to constructs a new SegWitProgram-variant Fallback
1385 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::u5, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
1386 Fallback::SegWitProgram {
1392 /// Utility method to constructs a new PubKeyHash-variant Fallback
1393 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1394 Fallback::PubKeyHash(a, )
1397 /// Utility method to constructs a new ScriptHash-variant Fallback
1398 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1399 Fallback::ScriptHash(a, )
1401 /// Checks if two Fallbacks contain equal inner contents.
1403 pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 {
1404 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
1405 #[allow(deprecated)]
1406 let mut hasher = core::hash::SipHasher::new();
1407 std::hash::Hash::hash(&o.to_native(), &mut hasher);
1408 std::hash::Hasher::finish(&hasher)
1410 /// Checks if two Fallbacks contain equal inner contents.
1411 /// This ignores pointers and is_owned flags and looks at the values in fields.
1413 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1414 if &a.to_native() == &b.to_native() { true } else { false }
1417 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1418 pub(crate) type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1420 /// Recoverable signature
1423 pub struct InvoiceSignature {
1424 /// A pointer to the opaque Rust object.
1426 /// Nearly everywhere, inner must be non-null, however in places where
1427 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1428 pub inner: *mut nativeInvoiceSignature,
1429 /// Indicates that this is the only struct which contains the same pointer.
1431 /// Rust functions which take ownership of an object provided via an argument require
1432 /// this to be true and invalidate the object pointed to by inner.
1436 impl Drop for InvoiceSignature {
1437 fn drop(&mut self) {
1438 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1439 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1443 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1445 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1447 /// Used only if an object of this type is returned as a trait impl by a method
1448 pub(crate) extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1449 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1452 impl InvoiceSignature {
1453 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceSignature {
1454 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1456 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceSignature {
1457 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1459 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1460 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1461 assert!(self.is_owned);
1462 let ret = ObjOps::untweak_ptr(self.inner);
1463 self.inner = std::ptr::null_mut();
1467 impl Clone for InvoiceSignature {
1468 fn clone(&self) -> Self {
1470 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { std::ptr::null_mut() } else {
1471 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1477 /// Used only if an object of this type is returned as a trait impl by a method
1478 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
1479 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
1482 /// Creates a copy of the InvoiceSignature
1483 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
1486 /// Checks if two InvoiceSignatures contain equal inner contents.
1487 /// This ignores pointers and is_owned flags and looks at the values in fields.
1488 /// Two objects with NULL inner values will be considered "equal" here.
1490 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
1491 if a.inner == b.inner { return true; }
1492 if a.inner.is_null() || b.inner.is_null() { return false; }
1493 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1496 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
1497 pub(crate) type nativePrivateRoute = nativePrivateRouteImport;
1499 /// Private routing information
1502 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
1506 pub struct PrivateRoute {
1507 /// A pointer to the opaque Rust object.
1509 /// Nearly everywhere, inner must be non-null, however in places where
1510 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1511 pub inner: *mut nativePrivateRoute,
1512 /// Indicates that this is the only struct which contains the same pointer.
1514 /// Rust functions which take ownership of an object provided via an argument require
1515 /// this to be true and invalidate the object pointed to by inner.
1519 impl Drop for PrivateRoute {
1520 fn drop(&mut self) {
1521 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
1522 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1526 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
1528 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
1530 /// Used only if an object of this type is returned as a trait impl by a method
1531 pub(crate) extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
1532 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); }
1536 pub(crate) fn get_native_ref(&self) -> &'static nativePrivateRoute {
1537 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1539 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateRoute {
1540 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1542 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1543 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
1544 assert!(self.is_owned);
1545 let ret = ObjOps::untweak_ptr(self.inner);
1546 self.inner = std::ptr::null_mut();
1550 impl Clone for PrivateRoute {
1551 fn clone(&self) -> Self {
1553 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { std::ptr::null_mut() } else {
1554 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1560 /// Used only if an object of this type is returned as a trait impl by a method
1561 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
1562 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
1565 /// Creates a copy of the PrivateRoute
1566 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
1569 /// Checks if two PrivateRoutes contain equal inner contents.
1571 pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 {
1572 if o.inner.is_null() { return 0; }
1573 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
1574 #[allow(deprecated)]
1575 let mut hasher = core::hash::SipHasher::new();
1576 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1577 std::hash::Hasher::finish(&hasher)
1579 /// Checks if two PrivateRoutes contain equal inner contents.
1580 /// This ignores pointers and is_owned flags and looks at the values in fields.
1581 /// Two objects with NULL inner values will be considered "equal" here.
1583 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
1584 if a.inner == b.inner { return true; }
1585 if a.inner.is_null() || b.inner.is_null() { return false; }
1586 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1588 /// Disassembles the `SignedRawInvoice` into its three parts:
1590 /// 2. hash of the raw invoice
1594 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
1595 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
1596 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();
1600 /// The `RawInvoice` which was signed.
1603 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
1604 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice();
1605 crate::lightning_invoice::RawInvoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawInvoice<>) as *mut _) }, is_owned: false }
1608 /// The hash of the `RawInvoice` that was signed.
1611 pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [u8; 32] {
1612 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
1616 /// InvoiceSignature for the invoice.
1619 pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
1620 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
1621 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::InvoiceSignature<>) as *mut _) }, is_owned: false }
1624 /// Recovers the public key used for signing the invoice from the recoverable signature.
1627 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
1628 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
1629 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() };
1633 /// Checks if the signature is valid for the included payee public key or if none exists if it's
1634 /// valid for the recovered signature (which should always be true?).
1637 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &SignedRawInvoice) -> bool {
1638 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
1642 /// Calculate the hash of the encoded `RawInvoice`
1645 pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1646 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
1647 crate::c_types::ThirtyTwoBytes { data: ret }
1651 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1654 pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1655 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
1656 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 lightning_invoice::Sha256<>) as *mut _ }, is_owned: false };
1661 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1664 pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightning_invoice::Description {
1665 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
1666 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 lightning_invoice::Description<>) as *mut _ }, is_owned: false };
1671 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1674 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::lightning_invoice::PayeePubKey {
1675 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
1676 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 lightning_invoice::PayeePubKey<>) as *mut _ }, is_owned: false };
1681 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1684 pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1685 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash();
1686 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 lightning_invoice::Sha256<>) as *mut _ }, is_owned: false };
1691 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1694 pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightning_invoice::ExpiryTime {
1695 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
1696 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 lightning_invoice::ExpiryTime<>) as *mut _ }, is_owned: false };
1701 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1704 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
1705 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
1706 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 lightning_invoice::MinFinalCltvExpiry<>) as *mut _ }, is_owned: false };
1711 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1714 pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1715 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
1716 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1721 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1724 pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
1725 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
1726 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 lightning::ln::features::InvoiceFeatures<>) as *mut _ }, is_owned: false };
1732 pub extern "C" fn RawInvoice_private_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1733 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
1734 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 } }); };
1740 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z {
1741 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
1742 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() }) };
1748 pub extern "C" fn RawInvoice_currency(this_arg: &RawInvoice) -> crate::lightning_invoice::Currency {
1749 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
1750 crate::lightning_invoice::Currency::native_into(ret)
1753 /// Create a new `PositiveTimestamp` from a unix timestamp in the Range
1754 /// `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1755 /// `CreationError::TimestampOutOfBounds`.
1758 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1759 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
1760 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() };
1764 /// Create a new `PositiveTimestamp` from a `SystemTime` with a corresponding unix timestamp in
1765 /// the Range `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1766 /// `CreationError::TimestampOutOfBounds`.
1769 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1770 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
1771 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() };
1775 /// Returns the UNIX timestamp representing the stored time
1778 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 {
1779 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_unix_timestamp();
1783 /// Returns a reference to the internal `SystemTime` time representation
1786 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &PositiveTimestamp) -> u64 {
1787 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_time();
1788 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1791 /// Transform the `Invoice` into it's unchecked version
1794 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::lightning_invoice::SignedRawInvoice {
1795 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
1796 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(ret), is_owned: true }
1799 /// Check that the invoice is signed correctly and that key recovery works
1802 pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
1803 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
1804 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() };
1808 /// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
1810 /// use lightning_invoice::*;
1812 /// let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
1813 /// h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
1814 /// 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
1815 /// h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
1816 /// j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
1817 /// ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
1818 /// guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
1819 /// ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
1820 /// p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
1821 /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
1822 /// j5r6drg6k6zcqj0fcwg\";
1824 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
1826 /// assert!(Invoice::from_signed(signed).is_ok());
1830 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
1831 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
1832 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() };
1836 /// Returns the `Invoice`'s timestamp (should equal it's creation time)
1839 pub extern "C" fn Invoice_timestamp(this_arg: &Invoice) -> u64 {
1840 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timestamp();
1841 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1844 /// Returns the hash to which we will receive the preimage on completion of the payment
1847 pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] {
1848 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
1852 /// Get the payee's public key if one was included in the invoice
1854 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1857 pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1858 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
1859 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
1863 /// Get the payment secret if one was included in the invoice
1866 pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> *const [u8; 32] {
1867 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
1871 /// Get the invoice features if they were included in the invoice
1873 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1876 pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
1877 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
1878 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 lightning::ln::features::InvoiceFeatures<>) as *mut _ }, is_owned: false };
1882 /// Recover the payee's public key (only to be used if none was included in the invoice)
1885 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1886 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
1887 crate::c_types::PublicKey::from_rust(&ret)
1890 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
1893 pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 {
1894 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
1898 /// Returns whether the invoice has expired.
1901 pub extern "C" fn Invoice_is_expired(this_arg: &Invoice) -> bool {
1902 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
1906 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
1907 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
1910 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 {
1911 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
1915 /// Returns a list of all routes included in the invoice
1918 pub extern "C" fn Invoice_private_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1919 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
1920 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 } }); };
1924 /// Returns a list of all routes included in the invoice as the underlying hints
1927 pub extern "C" fn Invoice_route_hints(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
1928 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints();
1929 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 } }); };
1933 /// Returns the currency for which the invoice was issued
1936 pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoice::Currency {
1937 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
1938 crate::lightning_invoice::Currency::native_into(ret)
1941 /// Returns the amount if specified in the invoice as millisatoshis.
1944 pub extern "C" fn Invoice_amount_milli_satoshis(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z {
1945 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_milli_satoshis();
1946 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() }) };
1950 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
1951 /// returns `CreationError::DescriptionTooLong` otherwise
1953 /// Please note that single characters may use more than one byte due to UTF8 encoding.
1956 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
1957 let mut ret = lightning_invoice::Description::new(description.into_string());
1958 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() };
1962 /// Returns the underlying description `String`
1965 pub extern "C" fn Description_into_inner(mut this_arg: Description) -> crate::c_types::Str {
1966 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1970 /// Construct an `ExpiryTime` from seconds. If there exists a `PositiveTimestamp` which would
1971 /// overflow on adding the `EpiryTime` to it then this function will return a
1972 /// `CreationError::ExpiryTimeOutOfBounds`.
1975 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1976 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
1977 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() };
1981 /// Construct an `ExpiryTime` from a `Duration`. If there exists a `PositiveTimestamp` which
1982 /// would overflow on adding the `EpiryTime` to it then this function will return a
1983 /// `CreationError::ExpiryTimeOutOfBounds`.
1986 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1987 let mut ret = lightning_invoice::ExpiryTime::from_duration(std::time::Duration::from_secs(duration));
1988 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() };
1992 /// Returns the expiry time in seconds
1995 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 {
1996 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_seconds();
2000 /// Returns a reference to the underlying `Duration` (=expiry time)
2003 pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 {
2004 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration();
2008 /// Creates a new (partial) route from a list of hops
2011 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
2012 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
2013 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() };
2017 /// Returns the underlying list of hops
2020 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: PrivateRoute) -> crate::lightning::routing::router::RouteHint {
2021 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2022 crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true }
2025 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
2029 pub enum CreationError {
2030 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
2032 /// The specified route has too many hops and can't be encoded
2034 /// The unix timestamp of the supplied date is <0 or can't be represented as `SystemTime`
2035 TimestampOutOfBounds,
2036 /// The supplied expiry time could cause an overflow if added to a `PositiveTimestamp`
2037 ExpiryTimeOutOfBounds,
2038 /// The supplied millisatoshi amount was greater than the total bitcoin supply.
2041 use lightning_invoice::CreationError as nativeCreationError;
2042 impl CreationError {
2044 pub(crate) fn to_native(&self) -> nativeCreationError {
2046 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2047 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2048 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2049 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
2050 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2054 pub(crate) fn into_native(self) -> nativeCreationError {
2056 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2057 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2058 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2059 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
2060 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2064 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
2066 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2067 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2068 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2069 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
2070 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2074 pub(crate) fn native_into(native: nativeCreationError) -> Self {
2076 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2077 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2078 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2079 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
2080 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2084 /// Creates a copy of the CreationError
2086 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
2090 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
2091 pub extern "C" fn CreationError_description_too_long() -> CreationError {
2092 CreationError::DescriptionTooLong}
2094 /// Utility method to constructs a new RouteTooLong-variant CreationError
2095 pub extern "C" fn CreationError_route_too_long() -> CreationError {
2096 CreationError::RouteTooLong}
2098 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
2099 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
2100 CreationError::TimestampOutOfBounds}
2102 /// Utility method to constructs a new ExpiryTimeOutOfBounds-variant CreationError
2103 pub extern "C" fn CreationError_expiry_time_out_of_bounds() -> CreationError {
2104 CreationError::ExpiryTimeOutOfBounds}
2106 /// Utility method to constructs a new InvalidAmount-variant CreationError
2107 pub extern "C" fn CreationError_invalid_amount() -> CreationError {
2108 CreationError::InvalidAmount}
2109 /// Checks if two CreationErrors contain equal inner contents.
2110 /// This ignores pointers and is_owned flags and looks at the values in fields.
2112 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
2113 if &a.to_native() == &b.to_native() { true } else { false }
2116 /// Get the string representation of a CreationError object
2117 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
2118 format!("{}", &o.to_native()).into()
2120 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
2121 /// requirements sections in BOLT #11
2125 pub enum SemanticError {
2126 /// The invoice is missing the mandatory payment hash
2128 /// The invoice has multiple payment hashes which isn't allowed
2129 MultiplePaymentHashes,
2130 /// No description or description hash are part of the invoice
2132 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
2133 MultipleDescriptions,
2134 /// The invoice is missing the mandatory payment secret, which all modern lightning nodes
2137 /// The invoice contains multiple payment secrets
2138 MultiplePaymentSecrets,
2139 /// The invoice's features are invalid
2141 /// The recovery id doesn't fit the signature/pub key
2143 /// The invoice's signature is invalid
2145 /// The invoice's amount was not a whole number of millisatoshis
2148 use lightning_invoice::SemanticError as nativeSemanticError;
2149 impl SemanticError {
2151 pub(crate) fn to_native(&self) -> nativeSemanticError {
2153 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2154 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2155 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2156 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2157 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2158 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2159 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2160 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2161 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2162 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2166 pub(crate) fn into_native(self) -> nativeSemanticError {
2168 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2169 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2170 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2171 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2172 SemanticError::NoPaymentSecret => nativeSemanticError::NoPaymentSecret,
2173 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2174 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2175 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2176 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2177 SemanticError::ImpreciseAmount => nativeSemanticError::ImpreciseAmount,
2181 pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
2183 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2184 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2185 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2186 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2187 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2188 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2189 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2190 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2191 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2192 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2196 pub(crate) fn native_into(native: nativeSemanticError) -> Self {
2198 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2199 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2200 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2201 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2202 nativeSemanticError::NoPaymentSecret => SemanticError::NoPaymentSecret,
2203 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2204 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2205 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2206 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2207 nativeSemanticError::ImpreciseAmount => SemanticError::ImpreciseAmount,
2211 /// Creates a copy of the SemanticError
2213 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
2217 /// Utility method to constructs a new NoPaymentHash-variant SemanticError
2218 pub extern "C" fn SemanticError_no_payment_hash() -> SemanticError {
2219 SemanticError::NoPaymentHash}
2221 /// Utility method to constructs a new MultiplePaymentHashes-variant SemanticError
2222 pub extern "C" fn SemanticError_multiple_payment_hashes() -> SemanticError {
2223 SemanticError::MultiplePaymentHashes}
2225 /// Utility method to constructs a new NoDescription-variant SemanticError
2226 pub extern "C" fn SemanticError_no_description() -> SemanticError {
2227 SemanticError::NoDescription}
2229 /// Utility method to constructs a new MultipleDescriptions-variant SemanticError
2230 pub extern "C" fn SemanticError_multiple_descriptions() -> SemanticError {
2231 SemanticError::MultipleDescriptions}
2233 /// Utility method to constructs a new NoPaymentSecret-variant SemanticError
2234 pub extern "C" fn SemanticError_no_payment_secret() -> SemanticError {
2235 SemanticError::NoPaymentSecret}
2237 /// Utility method to constructs a new MultiplePaymentSecrets-variant SemanticError
2238 pub extern "C" fn SemanticError_multiple_payment_secrets() -> SemanticError {
2239 SemanticError::MultiplePaymentSecrets}
2241 /// Utility method to constructs a new InvalidFeatures-variant SemanticError
2242 pub extern "C" fn SemanticError_invalid_features() -> SemanticError {
2243 SemanticError::InvalidFeatures}
2245 /// Utility method to constructs a new InvalidRecoveryId-variant SemanticError
2246 pub extern "C" fn SemanticError_invalid_recovery_id() -> SemanticError {
2247 SemanticError::InvalidRecoveryId}
2249 /// Utility method to constructs a new InvalidSignature-variant SemanticError
2250 pub extern "C" fn SemanticError_invalid_signature() -> SemanticError {
2251 SemanticError::InvalidSignature}
2253 /// Utility method to constructs a new ImpreciseAmount-variant SemanticError
2254 pub extern "C" fn SemanticError_imprecise_amount() -> SemanticError {
2255 SemanticError::ImpreciseAmount}
2256 /// Checks if two SemanticErrors contain equal inner contents.
2257 /// This ignores pointers and is_owned flags and looks at the values in fields.
2259 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
2260 if &a.to_native() == &b.to_native() { true } else { false }
2263 /// Get the string representation of a SemanticError object
2264 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
2265 format!("{}", &o.to_native()).into()
2267 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
2272 pub enum SignOrCreationError {
2273 /// An error occurred during signing
2275 /// An error occurred while building the transaction
2276 CreationError(crate::lightning_invoice::CreationError),
2278 use lightning_invoice::SignOrCreationError as nativeSignOrCreationError;
2279 impl SignOrCreationError {
2281 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
2283 SignOrCreationError::SignError => {
2284 nativeSignOrCreationError::SignError (
2288 SignOrCreationError::CreationError (ref a, ) => {
2289 let mut a_nonref = (*a).clone();
2290 nativeSignOrCreationError::CreationError (
2291 a_nonref.into_native(),
2297 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
2299 SignOrCreationError::SignError => {
2300 nativeSignOrCreationError::SignError (
2304 SignOrCreationError::CreationError (mut a, ) => {
2305 nativeSignOrCreationError::CreationError (
2312 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
2314 nativeSignOrCreationError::SignError (ref a, ) => {
2315 SignOrCreationError::SignError },
2316 nativeSignOrCreationError::CreationError (ref a, ) => {
2317 let mut a_nonref = (*a).clone();
2318 SignOrCreationError::CreationError (
2319 crate::lightning_invoice::CreationError::native_into(a_nonref),
2325 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
2327 nativeSignOrCreationError::SignError (mut a, ) => {
2328 SignOrCreationError::SignError },
2329 nativeSignOrCreationError::CreationError (mut a, ) => {
2330 SignOrCreationError::CreationError (
2331 crate::lightning_invoice::CreationError::native_into(a),
2337 /// Frees any resources used by the SignOrCreationError
2339 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
2340 /// Creates a copy of the SignOrCreationError
2342 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
2346 /// Utility method to constructs a new SignError-variant SignOrCreationError
2347 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
2348 SignOrCreationError::SignError
2351 /// Utility method to constructs a new CreationError-variant SignOrCreationError
2352 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
2353 SignOrCreationError::CreationError(a, )
2355 /// Checks if two SignOrCreationErrors contain equal inner contents.
2356 /// This ignores pointers and is_owned flags and looks at the values in fields.
2358 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
2359 if &a.to_native() == &b.to_native() { true } else { false }
2362 /// Get the string representation of a SignOrCreationError object
2363 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
2364 format!("{}", &o.to_native()).into()