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 bitcoin::hashes::Hash;
21 use crate::c_types::*;
27 use std::str::FromStr;
29 use bitcoin::hashes::Hash;
30 use crate::c_types::*;
34 use std::str::FromStr;
36 use bitcoin::hashes::Hash;
37 use crate::c_types::*;
41 /// Read a SiPrefix object from a string
42 pub extern "C" fn SiPrefix_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SiPrefixNoneZ {
43 match lightning_invoice::SiPrefix::from_str(s.into_str()) {
45 crate::c_types::CResultTempl::ok(
46 crate::lightning_invoice::SiPrefix::native_into(r)
49 Err(e) => crate::c_types::CResultTempl::err(()),
53 /// Read a Invoice object from a string
54 pub extern "C" fn Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_InvoiceNoneZ {
55 match lightning_invoice::Invoice::from_str(s.into_str()) {
57 crate::c_types::CResultTempl::ok(
58 crate::lightning_invoice::Invoice { inner: ObjOps::heap_alloc(r), is_owned: true }
61 Err(e) => crate::c_types::CResultTempl::err(()),
65 /// Read a SignedRawInvoice object from a string
66 pub extern "C" fn SignedRawInvoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SignedRawInvoiceNoneZ {
67 match lightning_invoice::SignedRawInvoice::from_str(s.into_str()) {
69 crate::c_types::CResultTempl::ok(
70 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(r), is_owned: true }
73 Err(e) => crate::c_types::CResultTempl::err(()),
79 use std::str::FromStr;
81 use bitcoin::hashes::Hash;
82 use crate::c_types::*;
85 /// Get the string representation of a Invoice object
86 pub extern "C" fn Invoice_to_str(o: &crate::lightning_invoice::Invoice) -> Str {
87 format!("{}", o.get_native_ref()).into()
90 /// Get the string representation of a SignedRawInvoice object
91 pub extern "C" fn SignedRawInvoice_to_str(o: &crate::lightning_invoice::SignedRawInvoice) -> Str {
92 format!("{}", o.get_native_ref()).into()
95 /// Get the string representation of a Currency object
96 pub extern "C" fn Currency_to_str(o: &crate::lightning_invoice::Currency) -> Str {
97 format!("{}", &o.to_native()).into()
100 /// Get the string representation of a SiPrefix object
101 pub extern "C" fn SiPrefix_to_str(o: &crate::lightning_invoice::SiPrefix) -> Str {
102 format!("{}", &o.to_native()).into()
107 use std::str::FromStr;
108 use std::ffi::c_void;
109 use bitcoin::hashes::Hash;
110 use crate::c_types::*;
113 /// Default expiry time as defined by [BOLT 11].
115 /// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md
118 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
119 /// Default minimum final CLTV expiry as defined by [BOLT 11].
121 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
122 /// provided in [`MIN_FINAL_CLTV_EXPIRY`].
124 /// [BOLT 11]: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md
125 /// [`MIN_FINAL_CLTV_EXPIRY`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY
128 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY;
129 /// **Call this function on startup to ensure that all assumptions about the platform are valid.**
131 /// Unfortunately we have to make assumptions about the upper bounds of the `SystemTime` type on
132 /// your platform which we can't fully verify at compile time and which isn't part of it's contract.
133 /// To our best knowledge our assumptions hold for all platforms officially supported by rust, but
134 /// since this check is fast we recommend to do it anyway.
136 /// If this function fails this is considered a bug. Please open an issue describing your
137 /// platform and stating your current system time.
140 /// If the check fails this function panics. By calling this function on startup you ensure that
141 /// this wont happen at an arbitrary later point in time.
143 pub extern "C" fn check_platform() {
144 lightning_invoice::check_platform()
148 use lightning_invoice::Invoice as nativeInvoiceImport;
149 type nativeInvoice = nativeInvoiceImport;
151 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
153 /// There are three ways to construct an `Invoice`:
154 /// 1. using `InvoiceBuilder`
155 /// 2. using `Invoice::from_signed(SignedRawInvoice)`
156 /// 3. using `str::parse::<Invoice>(&str)`
160 /// A pointer to the opaque Rust object.
162 /// Nearly everywhere, inner must be non-null, however in places where
163 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
164 pub inner: *mut nativeInvoice,
165 /// Indicates that this is the only struct which contains the same pointer.
167 /// Rust functions which take ownership of an object provided via an argument require
168 /// this to be true and invalidate the object pointed to by inner.
172 impl Drop for Invoice {
174 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
175 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
179 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
181 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
183 /// Used only if an object of this type is returned as a trait impl by a method
184 extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
185 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
189 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoice {
190 unsafe { &*ObjOps::untweak_ptr(self.inner) }
192 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoice {
193 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
195 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
196 pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
197 assert!(self.is_owned);
198 let ret = ObjOps::untweak_ptr(self.inner);
199 self.inner = std::ptr::null_mut();
203 /// Checks if two Invoices contain equal inner contents.
204 /// This ignores pointers and is_owned flags and looks at the values in fields.
205 /// Two objects with NULL inner values will be considered "equal" here.
207 pub extern "C" fn Invoice_eq(a: &Invoice, b: &Invoice) -> bool {
208 if a.inner == b.inner { return true; }
209 if a.inner.is_null() || b.inner.is_null() { return false; }
210 if a.get_native_ref() == b.get_native_ref() { true } else { false }
212 impl Clone for Invoice {
213 fn clone(&self) -> Self {
215 inner: if <*mut nativeInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
216 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
222 /// Used only if an object of this type is returned as a trait impl by a method
223 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
224 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
227 /// Creates a copy of the Invoice
228 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
232 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
233 type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
235 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
239 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
242 pub struct SignedRawInvoice {
243 /// A pointer to the opaque Rust object.
245 /// Nearly everywhere, inner must be non-null, however in places where
246 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
247 pub inner: *mut nativeSignedRawInvoice,
248 /// Indicates that this is the only struct which contains the same pointer.
250 /// Rust functions which take ownership of an object provided via an argument require
251 /// this to be true and invalidate the object pointed to by inner.
255 impl Drop for SignedRawInvoice {
257 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
258 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
262 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
264 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
266 /// Used only if an object of this type is returned as a trait impl by a method
267 extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
268 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
271 impl SignedRawInvoice {
272 pub(crate) fn get_native_ref(&self) -> &'static nativeSignedRawInvoice {
273 unsafe { &*ObjOps::untweak_ptr(self.inner) }
275 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSignedRawInvoice {
276 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
278 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
279 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
280 assert!(self.is_owned);
281 let ret = ObjOps::untweak_ptr(self.inner);
282 self.inner = std::ptr::null_mut();
286 /// Checks if two SignedRawInvoices contain equal inner contents.
287 /// This ignores pointers and is_owned flags and looks at the values in fields.
288 /// Two objects with NULL inner values will be considered "equal" here.
290 pub extern "C" fn SignedRawInvoice_eq(a: &SignedRawInvoice, b: &SignedRawInvoice) -> bool {
291 if a.inner == b.inner { return true; }
292 if a.inner.is_null() || b.inner.is_null() { return false; }
293 if a.get_native_ref() == b.get_native_ref() { true } else { false }
295 impl Clone for SignedRawInvoice {
296 fn clone(&self) -> Self {
298 inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
299 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
305 /// Used only if an object of this type is returned as a trait impl by a method
306 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
307 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
310 /// Creates a copy of the SignedRawInvoice
311 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
315 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
316 type nativeRawInvoice = nativeRawInvoiceImport;
318 /// Represents an syntactically correct Invoice for a payment on the lightning network,
319 /// but without the signature information.
320 /// De- and encoding should not lead to information loss but may lead to different hashes.
322 /// For methods without docs see the corresponding methods in `Invoice`.
325 pub struct RawInvoice {
326 /// A pointer to the opaque Rust object.
328 /// Nearly everywhere, inner must be non-null, however in places where
329 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
330 pub inner: *mut nativeRawInvoice,
331 /// Indicates that this is the only struct which contains the same pointer.
333 /// Rust functions which take ownership of an object provided via an argument require
334 /// this to be true and invalidate the object pointed to by inner.
338 impl Drop for RawInvoice {
340 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
341 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
345 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
347 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
349 /// Used only if an object of this type is returned as a trait impl by a method
350 extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
351 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
355 pub(crate) fn get_native_ref(&self) -> &'static nativeRawInvoice {
356 unsafe { &*ObjOps::untweak_ptr(self.inner) }
358 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawInvoice {
359 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
361 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
362 pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
363 assert!(self.is_owned);
364 let ret = ObjOps::untweak_ptr(self.inner);
365 self.inner = std::ptr::null_mut();
371 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
372 let mut inner_val = &mut this_ptr.get_native_mut_ref().data;
373 crate::lightning_invoice::RawDataPart { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
377 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
378 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.data = *unsafe { Box::from_raw(val.take_inner()) };
380 /// Checks if two RawInvoices contain equal inner contents.
381 /// This ignores pointers and is_owned flags and looks at the values in fields.
382 /// Two objects with NULL inner values will be considered "equal" here.
384 pub extern "C" fn RawInvoice_eq(a: &RawInvoice, b: &RawInvoice) -> bool {
385 if a.inner == b.inner { return true; }
386 if a.inner.is_null() || b.inner.is_null() { return false; }
387 if a.get_native_ref() == b.get_native_ref() { true } else { false }
389 impl Clone for RawInvoice {
390 fn clone(&self) -> Self {
392 inner: if <*mut nativeRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
393 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
399 /// Used only if an object of this type is returned as a trait impl by a method
400 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
401 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
404 /// Creates a copy of the RawInvoice
405 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
409 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
410 type nativeRawDataPart = nativeRawDataPartImport;
412 /// Data of the `RawInvoice` that is encoded in the data part
415 pub struct RawDataPart {
416 /// A pointer to the opaque Rust object.
418 /// Nearly everywhere, inner must be non-null, however in places where
419 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
420 pub inner: *mut nativeRawDataPart,
421 /// Indicates that this is the only struct which contains the same pointer.
423 /// Rust functions which take ownership of an object provided via an argument require
424 /// this to be true and invalidate the object pointed to by inner.
428 impl Drop for RawDataPart {
430 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
431 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
435 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
437 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
439 /// Used only if an object of this type is returned as a trait impl by a method
440 extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
441 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
445 pub(crate) fn get_native_ref(&self) -> &'static nativeRawDataPart {
446 unsafe { &*ObjOps::untweak_ptr(self.inner) }
448 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawDataPart {
449 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
451 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
452 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
453 assert!(self.is_owned);
454 let ret = ObjOps::untweak_ptr(self.inner);
455 self.inner = std::ptr::null_mut();
459 /// generation time of the invoice
461 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
462 let mut inner_val = &mut this_ptr.get_native_mut_ref().timestamp;
463 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
465 /// generation time of the invoice
467 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
468 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
470 /// Checks if two RawDataParts contain equal inner contents.
471 /// This ignores pointers and is_owned flags and looks at the values in fields.
472 /// Two objects with NULL inner values will be considered "equal" here.
474 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
475 if a.inner == b.inner { return true; }
476 if a.inner.is_null() || b.inner.is_null() { return false; }
477 if a.get_native_ref() == b.get_native_ref() { true } else { false }
479 impl Clone for RawDataPart {
480 fn clone(&self) -> Self {
482 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { std::ptr::null_mut() } else {
483 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
489 /// Used only if an object of this type is returned as a trait impl by a method
490 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
491 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
494 /// Creates a copy of the RawDataPart
495 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
499 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
500 type nativePositiveTimestamp = nativePositiveTimestampImport;
502 /// A timestamp that refers to a date after 1 January 1970 which means its representation as UNIX
503 /// timestamp is positive.
506 /// The UNIX timestamp representing the stored time has to be positive and small enough so that
507 /// a `EpiryTime` can be added to it without an overflow.
510 pub struct PositiveTimestamp {
511 /// A pointer to the opaque Rust object.
513 /// Nearly everywhere, inner must be non-null, however in places where
514 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
515 pub inner: *mut nativePositiveTimestamp,
516 /// Indicates that this is the only struct which contains the same pointer.
518 /// Rust functions which take ownership of an object provided via an argument require
519 /// this to be true and invalidate the object pointed to by inner.
523 impl Drop for PositiveTimestamp {
525 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
526 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
530 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
532 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
534 /// Used only if an object of this type is returned as a trait impl by a method
535 extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
536 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
539 impl PositiveTimestamp {
540 pub(crate) fn get_native_ref(&self) -> &'static nativePositiveTimestamp {
541 unsafe { &*ObjOps::untweak_ptr(self.inner) }
543 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePositiveTimestamp {
544 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
546 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
547 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
548 assert!(self.is_owned);
549 let ret = ObjOps::untweak_ptr(self.inner);
550 self.inner = std::ptr::null_mut();
554 /// Checks if two PositiveTimestamps contain equal inner contents.
555 /// This ignores pointers and is_owned flags and looks at the values in fields.
556 /// Two objects with NULL inner values will be considered "equal" here.
558 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
559 if a.inner == b.inner { return true; }
560 if a.inner.is_null() || b.inner.is_null() { return false; }
561 if a.get_native_ref() == b.get_native_ref() { true } else { false }
563 impl Clone for PositiveTimestamp {
564 fn clone(&self) -> Self {
566 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { std::ptr::null_mut() } else {
567 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
573 /// Used only if an object of this type is returned as a trait impl by a method
574 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
575 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
578 /// Creates a copy of the PositiveTimestamp
579 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
582 /// SI prefixes for the human readable part
596 use lightning_invoice::SiPrefix as nativeSiPrefix;
599 pub(crate) fn to_native(&self) -> nativeSiPrefix {
601 SiPrefix::Milli => nativeSiPrefix::Milli,
602 SiPrefix::Micro => nativeSiPrefix::Micro,
603 SiPrefix::Nano => nativeSiPrefix::Nano,
604 SiPrefix::Pico => nativeSiPrefix::Pico,
608 pub(crate) fn into_native(self) -> nativeSiPrefix {
610 SiPrefix::Milli => nativeSiPrefix::Milli,
611 SiPrefix::Micro => nativeSiPrefix::Micro,
612 SiPrefix::Nano => nativeSiPrefix::Nano,
613 SiPrefix::Pico => nativeSiPrefix::Pico,
617 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
619 nativeSiPrefix::Milli => SiPrefix::Milli,
620 nativeSiPrefix::Micro => SiPrefix::Micro,
621 nativeSiPrefix::Nano => SiPrefix::Nano,
622 nativeSiPrefix::Pico => SiPrefix::Pico,
626 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
628 nativeSiPrefix::Milli => SiPrefix::Milli,
629 nativeSiPrefix::Micro => SiPrefix::Micro,
630 nativeSiPrefix::Nano => SiPrefix::Nano,
631 nativeSiPrefix::Pico => SiPrefix::Pico,
635 /// Creates a copy of the SiPrefix
637 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
641 /// Utility method to constructs a new Milli-variant SiPrefix
642 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
645 /// Utility method to constructs a new Micro-variant SiPrefix
646 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
649 /// Utility method to constructs a new Nano-variant SiPrefix
650 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
653 /// Utility method to constructs a new Pico-variant SiPrefix
654 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
656 /// Checks if two SiPrefixs contain equal inner contents.
657 /// This ignores pointers and is_owned flags and looks at the values in fields.
659 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
660 if &a.to_native() == &b.to_native() { true } else { false }
662 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
663 /// This is effectively 10^12 * the prefix multiplier
666 pub extern "C" fn SiPrefix_multiplier(this_arg: &SiPrefix) -> u64 {
667 let mut ret = this_arg.to_native().multiplier();
671 /// Enum representing the crypto currencies (or networks) supported by this library
687 use lightning_invoice::Currency as nativeCurrency;
690 pub(crate) fn to_native(&self) -> nativeCurrency {
692 Currency::Bitcoin => nativeCurrency::Bitcoin,
693 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
694 Currency::Regtest => nativeCurrency::Regtest,
695 Currency::Simnet => nativeCurrency::Simnet,
696 Currency::Signet => nativeCurrency::Signet,
700 pub(crate) fn into_native(self) -> nativeCurrency {
702 Currency::Bitcoin => nativeCurrency::Bitcoin,
703 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
704 Currency::Regtest => nativeCurrency::Regtest,
705 Currency::Simnet => nativeCurrency::Simnet,
706 Currency::Signet => nativeCurrency::Signet,
710 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
712 nativeCurrency::Bitcoin => Currency::Bitcoin,
713 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
714 nativeCurrency::Regtest => Currency::Regtest,
715 nativeCurrency::Simnet => Currency::Simnet,
716 nativeCurrency::Signet => Currency::Signet,
720 pub(crate) fn native_into(native: nativeCurrency) -> Self {
722 nativeCurrency::Bitcoin => Currency::Bitcoin,
723 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
724 nativeCurrency::Regtest => Currency::Regtest,
725 nativeCurrency::Simnet => Currency::Simnet,
726 nativeCurrency::Signet => Currency::Signet,
730 /// Creates a copy of the Currency
732 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
736 /// Utility method to constructs a new Bitcoin-variant Currency
737 pub extern "C" fn Currency_bitcoin() -> Currency {
740 /// Utility method to constructs a new BitcoinTestnet-variant Currency
741 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
742 Currency::BitcoinTestnet}
744 /// Utility method to constructs a new Regtest-variant Currency
745 pub extern "C" fn Currency_regtest() -> Currency {
748 /// Utility method to constructs a new Simnet-variant Currency
749 pub extern "C" fn Currency_simnet() -> Currency {
752 /// Utility method to constructs a new Signet-variant Currency
753 pub extern "C" fn Currency_signet() -> Currency {
755 /// Checks if two Currencys contain equal inner contents.
756 /// This ignores pointers and is_owned flags and looks at the values in fields.
758 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
759 if &a.to_native() == &b.to_native() { true } else { false }
762 use lightning_invoice::Sha256 as nativeSha256Import;
763 type nativeSha256 = nativeSha256Import;
769 /// A pointer to the opaque Rust object.
771 /// Nearly everywhere, inner must be non-null, however in places where
772 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
773 pub inner: *mut nativeSha256,
774 /// Indicates that this is the only struct which contains the same pointer.
776 /// Rust functions which take ownership of an object provided via an argument require
777 /// this to be true and invalidate the object pointed to by inner.
781 impl Drop for Sha256 {
783 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
784 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
788 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
790 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
792 /// Used only if an object of this type is returned as a trait impl by a method
793 extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
794 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
798 pub(crate) fn get_native_ref(&self) -> &'static nativeSha256 {
799 unsafe { &*ObjOps::untweak_ptr(self.inner) }
801 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSha256 {
802 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
804 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
805 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
806 assert!(self.is_owned);
807 let ret = ObjOps::untweak_ptr(self.inner);
808 self.inner = std::ptr::null_mut();
812 /// Checks if two Sha256s contain equal inner contents.
813 /// This ignores pointers and is_owned flags and looks at the values in fields.
814 /// Two objects with NULL inner values will be considered "equal" here.
816 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
817 if a.inner == b.inner { return true; }
818 if a.inner.is_null() || b.inner.is_null() { return false; }
819 if a.get_native_ref() == b.get_native_ref() { true } else { false }
821 impl Clone for Sha256 {
822 fn clone(&self) -> Self {
824 inner: if <*mut nativeSha256>::is_null(self.inner) { std::ptr::null_mut() } else {
825 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
831 /// Used only if an object of this type is returned as a trait impl by a method
832 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
833 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
836 /// Creates a copy of the Sha256
837 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
841 use lightning_invoice::Description as nativeDescriptionImport;
842 type nativeDescription = nativeDescriptionImport;
844 /// Description string
847 /// The description can be at most 639 __bytes__ long
850 pub struct Description {
851 /// A pointer to the opaque Rust object.
853 /// Nearly everywhere, inner must be non-null, however in places where
854 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
855 pub inner: *mut nativeDescription,
856 /// Indicates that this is the only struct which contains the same pointer.
858 /// Rust functions which take ownership of an object provided via an argument require
859 /// this to be true and invalidate the object pointed to by inner.
863 impl Drop for Description {
865 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
866 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
870 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
872 pub extern "C" fn Description_free(this_obj: Description) { }
874 /// Used only if an object of this type is returned as a trait impl by a method
875 extern "C" fn Description_free_void(this_ptr: *mut c_void) {
876 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
880 pub(crate) fn get_native_ref(&self) -> &'static nativeDescription {
881 unsafe { &*ObjOps::untweak_ptr(self.inner) }
883 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDescription {
884 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
886 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
887 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
888 assert!(self.is_owned);
889 let ret = ObjOps::untweak_ptr(self.inner);
890 self.inner = std::ptr::null_mut();
894 /// Checks if two Descriptions contain equal inner contents.
895 /// This ignores pointers and is_owned flags and looks at the values in fields.
896 /// Two objects with NULL inner values will be considered "equal" here.
898 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
899 if a.inner == b.inner { return true; }
900 if a.inner.is_null() || b.inner.is_null() { return false; }
901 if a.get_native_ref() == b.get_native_ref() { true } else { false }
903 impl Clone for Description {
904 fn clone(&self) -> Self {
906 inner: if <*mut nativeDescription>::is_null(self.inner) { std::ptr::null_mut() } else {
907 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
913 /// Used only if an object of this type is returned as a trait impl by a method
914 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
915 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
918 /// Creates a copy of the Description
919 pub extern "C" fn Description_clone(orig: &Description) -> Description {
923 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
924 type nativePayeePubKey = nativePayeePubKeyImport;
929 pub struct PayeePubKey {
930 /// A pointer to the opaque Rust object.
932 /// Nearly everywhere, inner must be non-null, however in places where
933 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
934 pub inner: *mut nativePayeePubKey,
935 /// Indicates that this is the only struct which contains the same pointer.
937 /// Rust functions which take ownership of an object provided via an argument require
938 /// this to be true and invalidate the object pointed to by inner.
942 impl Drop for PayeePubKey {
944 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
945 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
949 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
951 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
953 /// Used only if an object of this type is returned as a trait impl by a method
954 extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
955 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
959 pub(crate) fn get_native_ref(&self) -> &'static nativePayeePubKey {
960 unsafe { &*ObjOps::untweak_ptr(self.inner) }
962 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayeePubKey {
963 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
965 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
966 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
967 assert!(self.is_owned);
968 let ret = ObjOps::untweak_ptr(self.inner);
969 self.inner = std::ptr::null_mut();
973 /// Checks if two PayeePubKeys contain equal inner contents.
974 /// This ignores pointers and is_owned flags and looks at the values in fields.
975 /// Two objects with NULL inner values will be considered "equal" here.
977 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
978 if a.inner == b.inner { return true; }
979 if a.inner.is_null() || b.inner.is_null() { return false; }
980 if a.get_native_ref() == b.get_native_ref() { true } else { false }
982 impl Clone for PayeePubKey {
983 fn clone(&self) -> Self {
985 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { std::ptr::null_mut() } else {
986 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
992 /// Used only if an object of this type is returned as a trait impl by a method
993 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
994 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
997 /// Creates a copy of the PayeePubKey
998 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
1002 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
1003 type nativeExpiryTime = nativeExpiryTimeImport;
1005 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
1009 /// The number of seconds this expiry time represents has to be in the range
1010 /// `0...(SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME)` to avoid overflows when adding it to a
1014 pub struct ExpiryTime {
1015 /// A pointer to the opaque Rust object.
1017 /// Nearly everywhere, inner must be non-null, however in places where
1018 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1019 pub inner: *mut nativeExpiryTime,
1020 /// Indicates that this is the only struct which contains the same pointer.
1022 /// Rust functions which take ownership of an object provided via an argument require
1023 /// this to be true and invalidate the object pointed to by inner.
1027 impl Drop for ExpiryTime {
1028 fn drop(&mut self) {
1029 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
1030 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1034 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
1036 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
1038 /// Used only if an object of this type is returned as a trait impl by a method
1039 extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
1040 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
1044 pub(crate) fn get_native_ref(&self) -> &'static nativeExpiryTime {
1045 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1047 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpiryTime {
1048 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1050 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1051 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
1052 assert!(self.is_owned);
1053 let ret = ObjOps::untweak_ptr(self.inner);
1054 self.inner = std::ptr::null_mut();
1058 /// Checks if two ExpiryTimes contain equal inner contents.
1059 /// This ignores pointers and is_owned flags and looks at the values in fields.
1060 /// Two objects with NULL inner values will be considered "equal" here.
1062 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1063 if a.inner == b.inner { return true; }
1064 if a.inner.is_null() || b.inner.is_null() { return false; }
1065 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1067 impl Clone for ExpiryTime {
1068 fn clone(&self) -> Self {
1070 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { std::ptr::null_mut() } else {
1071 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1077 /// Used only if an object of this type is returned as a trait impl by a method
1078 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1079 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1082 /// Creates a copy of the ExpiryTime
1083 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1087 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
1088 type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
1090 /// `min_final_cltv_expiry` to use for the last HTLC in the route
1093 pub struct MinFinalCltvExpiry {
1094 /// A pointer to the opaque Rust object.
1096 /// Nearly everywhere, inner must be non-null, however in places where
1097 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1098 pub inner: *mut nativeMinFinalCltvExpiry,
1099 /// Indicates that this is the only struct which contains the same pointer.
1101 /// Rust functions which take ownership of an object provided via an argument require
1102 /// this to be true and invalidate the object pointed to by inner.
1106 impl Drop for MinFinalCltvExpiry {
1107 fn drop(&mut self) {
1108 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
1109 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1113 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1115 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1117 /// Used only if an object of this type is returned as a trait impl by a method
1118 extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1119 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1122 impl MinFinalCltvExpiry {
1123 pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiry {
1124 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1126 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiry {
1127 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1129 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1130 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1131 assert!(self.is_owned);
1132 let ret = ObjOps::untweak_ptr(self.inner);
1133 self.inner = std::ptr::null_mut();
1137 /// Checks if two MinFinalCltvExpirys contain equal inner contents.
1138 /// This ignores pointers and is_owned flags and looks at the values in fields.
1139 /// Two objects with NULL inner values will be considered "equal" here.
1141 pub extern "C" fn MinFinalCltvExpiry_eq(a: &MinFinalCltvExpiry, b: &MinFinalCltvExpiry) -> bool {
1142 if a.inner == b.inner { return true; }
1143 if a.inner.is_null() || b.inner.is_null() { return false; }
1144 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1146 impl Clone for MinFinalCltvExpiry {
1147 fn clone(&self) -> Self {
1149 inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { std::ptr::null_mut() } else {
1150 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1156 /// Used only if an object of this type is returned as a trait impl by a method
1157 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1158 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1161 /// Creates a copy of the MinFinalCltvExpiry
1162 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1165 /// Fallback address in case no LN payment is possible
1171 version: crate::c_types::u5,
1172 program: crate::c_types::derived::CVec_u8Z,
1174 PubKeyHash(crate::c_types::TwentyBytes),
1175 ScriptHash(crate::c_types::TwentyBytes),
1177 use lightning_invoice::Fallback as nativeFallback;
1180 pub(crate) fn to_native(&self) -> nativeFallback {
1182 Fallback::SegWitProgram {ref version, ref program, } => {
1183 let mut version_nonref = (*version).clone();
1184 let mut program_nonref = (*program).clone();
1185 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1186 nativeFallback::SegWitProgram {
1187 version: version_nonref.into(),
1188 program: local_program_nonref,
1191 Fallback::PubKeyHash (ref a, ) => {
1192 let mut a_nonref = (*a).clone();
1193 nativeFallback::PubKeyHash (
1197 Fallback::ScriptHash (ref a, ) => {
1198 let mut a_nonref = (*a).clone();
1199 nativeFallback::ScriptHash (
1206 pub(crate) fn into_native(self) -> nativeFallback {
1208 Fallback::SegWitProgram {mut version, mut program, } => {
1209 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1210 nativeFallback::SegWitProgram {
1211 version: version.into(),
1212 program: local_program,
1215 Fallback::PubKeyHash (mut a, ) => {
1216 nativeFallback::PubKeyHash (
1220 Fallback::ScriptHash (mut a, ) => {
1221 nativeFallback::ScriptHash (
1228 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1230 nativeFallback::SegWitProgram {ref version, ref program, } => {
1231 let mut version_nonref = (*version).clone();
1232 let mut program_nonref = (*program).clone();
1233 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1234 Fallback::SegWitProgram {
1235 version: version_nonref.into(),
1236 program: local_program_nonref.into(),
1239 nativeFallback::PubKeyHash (ref a, ) => {
1240 let mut a_nonref = (*a).clone();
1241 Fallback::PubKeyHash (
1242 crate::c_types::TwentyBytes { data: a_nonref },
1245 nativeFallback::ScriptHash (ref a, ) => {
1246 let mut a_nonref = (*a).clone();
1247 Fallback::ScriptHash (
1248 crate::c_types::TwentyBytes { data: a_nonref },
1254 pub(crate) fn native_into(native: nativeFallback) -> Self {
1256 nativeFallback::SegWitProgram {mut version, mut program, } => {
1257 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1258 Fallback::SegWitProgram {
1259 version: version.into(),
1260 program: local_program.into(),
1263 nativeFallback::PubKeyHash (mut a, ) => {
1264 Fallback::PubKeyHash (
1265 crate::c_types::TwentyBytes { data: a },
1268 nativeFallback::ScriptHash (mut a, ) => {
1269 Fallback::ScriptHash (
1270 crate::c_types::TwentyBytes { data: a },
1276 /// Frees any resources used by the Fallback
1278 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1279 /// Creates a copy of the Fallback
1281 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1285 /// Utility method to constructs a new SegWitProgram-variant Fallback
1286 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::u5, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
1287 Fallback::SegWitProgram {
1293 /// Utility method to constructs a new PubKeyHash-variant Fallback
1294 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1295 Fallback::PubKeyHash(a, )
1298 /// Utility method to constructs a new ScriptHash-variant Fallback
1299 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1300 Fallback::ScriptHash(a, )
1302 /// Checks if two Fallbacks contain equal inner contents.
1303 /// This ignores pointers and is_owned flags and looks at the values in fields.
1305 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1306 if &a.to_native() == &b.to_native() { true } else { false }
1309 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1310 type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1312 /// Recoverable signature
1315 pub struct InvoiceSignature {
1316 /// A pointer to the opaque Rust object.
1318 /// Nearly everywhere, inner must be non-null, however in places where
1319 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1320 pub inner: *mut nativeInvoiceSignature,
1321 /// Indicates that this is the only struct which contains the same pointer.
1323 /// Rust functions which take ownership of an object provided via an argument require
1324 /// this to be true and invalidate the object pointed to by inner.
1328 impl Drop for InvoiceSignature {
1329 fn drop(&mut self) {
1330 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1331 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1335 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1337 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1339 /// Used only if an object of this type is returned as a trait impl by a method
1340 extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1341 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1344 impl InvoiceSignature {
1345 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceSignature {
1346 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1348 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceSignature {
1349 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1351 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1352 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1353 assert!(self.is_owned);
1354 let ret = ObjOps::untweak_ptr(self.inner);
1355 self.inner = std::ptr::null_mut();
1359 /// Checks if two InvoiceSignatures contain equal inner contents.
1360 /// This ignores pointers and is_owned flags and looks at the values in fields.
1361 /// Two objects with NULL inner values will be considered "equal" here.
1363 pub extern "C" fn InvoiceSignature_eq(a: &InvoiceSignature, b: &InvoiceSignature) -> bool {
1364 if a.inner == b.inner { return true; }
1365 if a.inner.is_null() || b.inner.is_null() { return false; }
1366 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1368 impl Clone for InvoiceSignature {
1369 fn clone(&self) -> Self {
1371 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { std::ptr::null_mut() } else {
1372 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1378 /// Used only if an object of this type is returned as a trait impl by a method
1379 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
1380 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
1383 /// Creates a copy of the InvoiceSignature
1384 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
1388 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
1389 type nativePrivateRoute = nativePrivateRouteImport;
1391 /// Private routing information
1394 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
1398 pub struct PrivateRoute {
1399 /// A pointer to the opaque Rust object.
1401 /// Nearly everywhere, inner must be non-null, however in places where
1402 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1403 pub inner: *mut nativePrivateRoute,
1404 /// Indicates that this is the only struct which contains the same pointer.
1406 /// Rust functions which take ownership of an object provided via an argument require
1407 /// this to be true and invalidate the object pointed to by inner.
1411 impl Drop for PrivateRoute {
1412 fn drop(&mut self) {
1413 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
1414 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1418 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
1420 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
1422 /// Used only if an object of this type is returned as a trait impl by a method
1423 extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
1424 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePrivateRoute); }
1428 pub(crate) fn get_native_ref(&self) -> &'static nativePrivateRoute {
1429 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1431 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateRoute {
1432 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1434 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1435 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
1436 assert!(self.is_owned);
1437 let ret = ObjOps::untweak_ptr(self.inner);
1438 self.inner = std::ptr::null_mut();
1442 /// Checks if two PrivateRoutes contain equal inner contents.
1443 /// This ignores pointers and is_owned flags and looks at the values in fields.
1444 /// Two objects with NULL inner values will be considered "equal" here.
1446 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
1447 if a.inner == b.inner { return true; }
1448 if a.inner.is_null() || b.inner.is_null() { return false; }
1449 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1451 impl Clone for PrivateRoute {
1452 fn clone(&self) -> Self {
1454 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { std::ptr::null_mut() } else {
1455 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1461 /// Used only if an object of this type is returned as a trait impl by a method
1462 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
1463 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
1466 /// Creates a copy of the PrivateRoute
1467 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
1470 /// Disassembles the `SignedRawInvoice` into its three parts:
1472 /// 2. hash of the raw invoice
1476 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
1477 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
1478 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();
1482 /// The `RawInvoice` which was signed.
1485 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
1486 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice();
1487 crate::lightning_invoice::RawInvoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false }
1490 /// The hash of the `RawInvoice` that was signed.
1493 pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [u8; 32] {
1494 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
1498 /// InvoiceSignature for the invoice.
1501 pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
1502 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
1503 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false }
1506 /// Recovers the public key used for signing the invoice from the recoverable signature.
1509 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
1510 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
1511 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() };
1515 /// Checks if the signature is valid for the included payee public key or if none exists if it's
1516 /// valid for the recovered signature (which should always be true?).
1519 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &SignedRawInvoice) -> bool {
1520 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
1524 /// Calculate the hash of the encoded `RawInvoice`
1527 pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1528 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.hash();
1529 crate::c_types::ThirtyTwoBytes { data: ret }
1533 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1536 pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1537 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
1538 let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1543 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1546 pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightning_invoice::Description {
1547 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
1548 let mut local_ret = crate::lightning_invoice::Description { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1553 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1556 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::lightning_invoice::PayeePubKey {
1557 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
1558 let mut local_ret = crate::lightning_invoice::PayeePubKey { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1563 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1566 pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1567 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash();
1568 let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1573 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1576 pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightning_invoice::ExpiryTime {
1577 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
1578 let mut local_ret = crate::lightning_invoice::ExpiryTime { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1583 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1586 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
1587 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
1588 let mut local_ret = crate::lightning_invoice::MinFinalCltvExpiry { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1593 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1596 pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1597 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
1598 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1603 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1606 pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
1607 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
1608 let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1614 pub extern "C" fn RawInvoice_private_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1615 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
1616 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const _) as *mut _) }, is_owned: false } }); };
1622 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z {
1623 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
1624 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()) } };
1630 pub extern "C" fn RawInvoice_currency(this_arg: &RawInvoice) -> crate::lightning_invoice::Currency {
1631 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
1632 crate::lightning_invoice::Currency::native_into(ret)
1635 /// Create a new `PositiveTimestamp` from a unix timestamp in the Range
1636 /// `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1637 /// `CreationError::TimestampOutOfBounds`.
1640 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1641 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
1642 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() };
1646 /// Create a new `PositiveTimestamp` from a `SystemTime` with a corresponding unix timestamp in
1647 /// the Range `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1648 /// `CreationError::TimestampOutOfBounds`.
1651 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1652 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
1653 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() };
1657 /// Returns the UNIX timestamp representing the stored time
1660 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 {
1661 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_unix_timestamp();
1665 /// Returns a reference to the internal `SystemTime` time representation
1668 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &PositiveTimestamp) -> u64 {
1669 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_time();
1670 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1673 /// Transform the `Invoice` into it's unchecked version
1676 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::lightning_invoice::SignedRawInvoice {
1677 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
1678 crate::lightning_invoice::SignedRawInvoice { inner: ObjOps::heap_alloc(ret), is_owned: true }
1681 /// Check that the invoice is signed correctly and that key recovery works
1684 pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
1685 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
1686 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() };
1690 /// Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
1692 /// use lightning_invoice::*;
1694 /// let invoice = \"lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdp\\
1695 /// \tl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d7\\
1696 /// \t3gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ec\\
1697 /// \tky03ylcqca784w\";
1699 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
1701 /// assert!(Invoice::from_signed(signed).is_ok());
1705 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
1706 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
1707 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() };
1711 /// Returns the `Invoice`'s timestamp (should equal it's creation time)
1714 pub extern "C" fn Invoice_timestamp(this_arg: &Invoice) -> u64 {
1715 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timestamp();
1716 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1719 /// Returns the hash to which we will receive the preimage on completion of the payment
1722 pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] {
1723 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
1727 /// Get the payee's public key if one was included in the invoice
1729 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1732 pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1733 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
1734 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
1738 /// Get the payment secret if one was included in the invoice
1740 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1743 pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> crate::c_types::ThirtyTwoBytes {
1744 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
1745 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1749 /// Get the invoice features if they were included in the invoice
1751 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1754 pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
1755 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
1756 let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1760 /// Recover the payee's public key (only to be used if none was included in the invoice)
1763 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1764 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
1765 crate::c_types::PublicKey::from_rust(&ret)
1768 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
1771 pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 {
1772 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
1776 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
1777 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
1780 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 {
1781 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry();
1785 /// Returns a list of all routes included in the invoice
1788 pub extern "C" fn Invoice_private_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
1789 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
1790 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const _) as *mut _) }, is_owned: false } }); };
1794 /// Returns a list of all routes included in the invoice as the underlying hints
1797 pub extern "C" fn Invoice_route_hints(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
1798 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints();
1799 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::router::RouteHint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const _) as *mut _) }, is_owned: false } }); };
1803 /// Returns the currency for which the invoice was issued
1806 pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoice::Currency {
1807 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
1808 crate::lightning_invoice::Currency::native_into(ret)
1811 /// Returns the amount if specified in the invoice as pico <currency>.
1814 pub extern "C" fn Invoice_amount_pico_btc(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z {
1815 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
1816 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()) } };
1820 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
1821 /// returns `CreationError::DescriptionTooLong` otherwise
1823 /// Please note that single characters may use more than one byte due to UTF8 encoding.
1826 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
1827 let mut ret = lightning_invoice::Description::new(description.into_string());
1828 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() };
1832 /// Returns the underlying description `String`
1835 pub extern "C" fn Description_into_inner(mut this_arg: Description) -> crate::c_types::Str {
1836 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1840 /// Construct an `ExpiryTime` from seconds. If there exists a `PositiveTimestamp` which would
1841 /// overflow on adding the `EpiryTime` to it then this function will return a
1842 /// `CreationError::ExpiryTimeOutOfBounds`.
1845 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1846 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
1847 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() };
1851 /// Construct an `ExpiryTime` from a `Duration`. If there exists a `PositiveTimestamp` which
1852 /// would overflow on adding the `EpiryTime` to it then this function will return a
1853 /// `CreationError::ExpiryTimeOutOfBounds`.
1856 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1857 let mut ret = lightning_invoice::ExpiryTime::from_duration(std::time::Duration::from_secs(duration));
1858 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() };
1862 /// Returns the expiry time in seconds
1865 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 {
1866 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_seconds();
1870 /// Returns a reference to the underlying `Duration` (=expiry time)
1873 pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 {
1874 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration();
1878 /// Creates a new (partial) route from a list of hops
1881 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
1882 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
1883 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() };
1887 /// Returns the underlying list of hops
1890 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: PrivateRoute) -> crate::lightning::routing::router::RouteHint {
1891 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1892 crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true }
1895 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
1899 pub enum CreationError {
1900 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
1902 /// The specified route has too many hops and can't be encoded
1904 /// The unix timestamp of the supplied date is <0 or can't be represented as `SystemTime`
1905 TimestampOutOfBounds,
1906 /// The supplied expiry time could cause an overflow if added to a `PositiveTimestamp`
1907 ExpiryTimeOutOfBounds,
1909 use lightning_invoice::CreationError as nativeCreationError;
1910 impl CreationError {
1912 pub(crate) fn to_native(&self) -> nativeCreationError {
1914 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
1915 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
1916 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
1917 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
1921 pub(crate) fn into_native(self) -> nativeCreationError {
1923 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
1924 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
1925 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
1926 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
1930 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
1932 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
1933 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
1934 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
1935 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
1939 pub(crate) fn native_into(native: nativeCreationError) -> Self {
1941 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
1942 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
1943 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
1944 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
1948 /// Creates a copy of the CreationError
1950 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
1954 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
1955 pub extern "C" fn CreationError_description_too_long() -> CreationError {
1956 CreationError::DescriptionTooLong}
1958 /// Utility method to constructs a new RouteTooLong-variant CreationError
1959 pub extern "C" fn CreationError_route_too_long() -> CreationError {
1960 CreationError::RouteTooLong}
1962 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
1963 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
1964 CreationError::TimestampOutOfBounds}
1966 /// Utility method to constructs a new ExpiryTimeOutOfBounds-variant CreationError
1967 pub extern "C" fn CreationError_expiry_time_out_of_bounds() -> CreationError {
1968 CreationError::ExpiryTimeOutOfBounds}
1969 /// Checks if two CreationErrors contain equal inner contents.
1970 /// This ignores pointers and is_owned flags and looks at the values in fields.
1972 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
1973 if &a.to_native() == &b.to_native() { true } else { false }
1976 /// Get the string representation of a CreationError object
1977 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
1978 format!("{}", &o.to_native()).into()
1980 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
1981 /// requirements sections in BOLT #11
1985 pub enum SemanticError {
1986 /// The invoice is missing the mandatory payment hash
1988 /// The invoice has multiple payment hashes which isn't allowed
1989 MultiplePaymentHashes,
1990 /// No description or description hash are part of the invoice
1992 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
1993 MultipleDescriptions,
1994 /// The invoice contains multiple payment secrets
1995 MultiplePaymentSecrets,
1996 /// The invoice's features are invalid
1998 /// The recovery id doesn't fit the signature/pub key
2000 /// The invoice's signature is invalid
2003 use lightning_invoice::SemanticError as nativeSemanticError;
2004 impl SemanticError {
2006 pub(crate) fn to_native(&self) -> nativeSemanticError {
2008 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2009 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2010 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2011 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2012 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2013 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2014 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2015 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2019 pub(crate) fn into_native(self) -> nativeSemanticError {
2021 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2022 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2023 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2024 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2025 SemanticError::MultiplePaymentSecrets => nativeSemanticError::MultiplePaymentSecrets,
2026 SemanticError::InvalidFeatures => nativeSemanticError::InvalidFeatures,
2027 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2028 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2032 pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
2034 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2035 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2036 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2037 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2038 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2039 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2040 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2041 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2045 pub(crate) fn native_into(native: nativeSemanticError) -> Self {
2047 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2048 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2049 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2050 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2051 nativeSemanticError::MultiplePaymentSecrets => SemanticError::MultiplePaymentSecrets,
2052 nativeSemanticError::InvalidFeatures => SemanticError::InvalidFeatures,
2053 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2054 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2058 /// Creates a copy of the SemanticError
2060 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
2064 /// Utility method to constructs a new NoPaymentHash-variant SemanticError
2065 pub extern "C" fn SemanticError_no_payment_hash() -> SemanticError {
2066 SemanticError::NoPaymentHash}
2068 /// Utility method to constructs a new MultiplePaymentHashes-variant SemanticError
2069 pub extern "C" fn SemanticError_multiple_payment_hashes() -> SemanticError {
2070 SemanticError::MultiplePaymentHashes}
2072 /// Utility method to constructs a new NoDescription-variant SemanticError
2073 pub extern "C" fn SemanticError_no_description() -> SemanticError {
2074 SemanticError::NoDescription}
2076 /// Utility method to constructs a new MultipleDescriptions-variant SemanticError
2077 pub extern "C" fn SemanticError_multiple_descriptions() -> SemanticError {
2078 SemanticError::MultipleDescriptions}
2080 /// Utility method to constructs a new MultiplePaymentSecrets-variant SemanticError
2081 pub extern "C" fn SemanticError_multiple_payment_secrets() -> SemanticError {
2082 SemanticError::MultiplePaymentSecrets}
2084 /// Utility method to constructs a new InvalidFeatures-variant SemanticError
2085 pub extern "C" fn SemanticError_invalid_features() -> SemanticError {
2086 SemanticError::InvalidFeatures}
2088 /// Utility method to constructs a new InvalidRecoveryId-variant SemanticError
2089 pub extern "C" fn SemanticError_invalid_recovery_id() -> SemanticError {
2090 SemanticError::InvalidRecoveryId}
2092 /// Utility method to constructs a new InvalidSignature-variant SemanticError
2093 pub extern "C" fn SemanticError_invalid_signature() -> SemanticError {
2094 SemanticError::InvalidSignature}
2095 /// Checks if two SemanticErrors contain equal inner contents.
2096 /// This ignores pointers and is_owned flags and looks at the values in fields.
2098 pub extern "C" fn SemanticError_eq(a: &SemanticError, b: &SemanticError) -> bool {
2099 if &a.to_native() == &b.to_native() { true } else { false }
2102 /// Get the string representation of a SemanticError object
2103 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
2104 format!("{}", &o.to_native()).into()
2106 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
2111 pub enum SignOrCreationError {
2112 /// An error occurred during signing
2114 /// An error occurred while building the transaction
2115 CreationError(crate::lightning_invoice::CreationError),
2117 use lightning_invoice::SignOrCreationError as nativeSignOrCreationError;
2118 impl SignOrCreationError {
2120 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
2122 SignOrCreationError::SignError => {
2123 nativeSignOrCreationError::SignError (
2127 SignOrCreationError::CreationError (ref a, ) => {
2128 let mut a_nonref = (*a).clone();
2129 nativeSignOrCreationError::CreationError (
2130 a_nonref.into_native(),
2136 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
2138 SignOrCreationError::SignError => {
2139 nativeSignOrCreationError::SignError (
2143 SignOrCreationError::CreationError (mut a, ) => {
2144 nativeSignOrCreationError::CreationError (
2151 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
2153 nativeSignOrCreationError::SignError (ref a, ) => {
2154 SignOrCreationError::SignError },
2155 nativeSignOrCreationError::CreationError (ref a, ) => {
2156 let mut a_nonref = (*a).clone();
2157 SignOrCreationError::CreationError (
2158 crate::lightning_invoice::CreationError::native_into(a_nonref),
2164 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
2166 nativeSignOrCreationError::SignError (mut a, ) => {
2167 SignOrCreationError::SignError },
2168 nativeSignOrCreationError::CreationError (mut a, ) => {
2169 SignOrCreationError::CreationError (
2170 crate::lightning_invoice::CreationError::native_into(a),
2176 /// Frees any resources used by the SignOrCreationError
2178 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
2179 /// Creates a copy of the SignOrCreationError
2181 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
2185 /// Utility method to constructs a new SignError-variant SignOrCreationError
2186 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
2187 SignOrCreationError::SignError
2190 /// Utility method to constructs a new CreationError-variant SignOrCreationError
2191 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
2192 SignOrCreationError::CreationError(a, )
2194 /// Checks if two SignOrCreationErrors contain equal inner contents.
2195 /// This ignores pointers and is_owned flags and looks at the values in fields.
2197 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
2198 if &a.to_native() == &b.to_native() { true } else { false }
2201 /// Get the string representation of a SignOrCreationError object
2202 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
2203 format!("{}", &o.to_native()).into()