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: Box::into_raw(Box::new(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: Box::into_raw(Box::new(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!("{}", unsafe { &*o.inner }).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!("{}", unsafe { &*o.inner }).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 /// **Call this function on startup to ensure that all assumptions about the platform are valid.**
115 /// Unfortunately we have to make assumptions about the upper bounds of the `SystemTime` type on
116 /// your platform which we can't fully verify at compile time and which isn't part of it's contract.
117 /// To our best knowledge our assumptions hold for all platforms officially supported by rust, but
118 /// since this check is fast we recommend to do it anyway.
120 /// If this function fails this is considered a bug. Please open an issue describing your
121 /// platform and stating your current system time.
124 /// If the check fails this function panics. By calling this function on startup you ensure that
125 /// this wont happen at an arbitrary later point in time.
127 pub extern "C" fn check_platform() {
128 lightning_invoice::check_platform()
132 use lightning_invoice::Invoice as nativeInvoiceImport;
133 type nativeInvoice = nativeInvoiceImport;
135 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
137 /// There are three ways to construct an `Invoice`:
138 /// 1. using `InvoiceBuilder`
139 /// 2. using `Invoice::from_signed(SignedRawInvoice)`
140 /// 3. using `str::parse::<Invoice>(&str)`
144 /// A pointer to the opaque Rust object.
146 /// Nearly everywhere, inner must be non-null, however in places where
147 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
148 pub inner: *mut nativeInvoice,
149 /// Indicates that this is the only struct which contains the same pointer.
151 /// Rust functions which take ownership of an object provided via an argument require
152 /// this to be true and invalidate the object pointed to by inner.
156 impl Drop for Invoice {
158 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
159 let _ = unsafe { Box::from_raw(self.inner) };
163 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
165 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
167 /// Used only if an object of this type is returned as a trait impl by a method
168 extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
169 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
172 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
174 pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
175 assert!(self.is_owned);
176 let ret = self.inner;
177 self.inner = std::ptr::null_mut();
181 impl Clone for Invoice {
182 fn clone(&self) -> Self {
184 inner: if <*mut nativeInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
185 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
191 /// Used only if an object of this type is returned as a trait impl by a method
192 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
193 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
196 /// Creates a copy of the Invoice
197 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
201 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
202 type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
204 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
208 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
211 pub struct SignedRawInvoice {
212 /// A pointer to the opaque Rust object.
214 /// Nearly everywhere, inner must be non-null, however in places where
215 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
216 pub inner: *mut nativeSignedRawInvoice,
217 /// Indicates that this is the only struct which contains the same pointer.
219 /// Rust functions which take ownership of an object provided via an argument require
220 /// this to be true and invalidate the object pointed to by inner.
224 impl Drop for SignedRawInvoice {
226 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
227 let _ = unsafe { Box::from_raw(self.inner) };
231 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
233 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
235 /// Used only if an object of this type is returned as a trait impl by a method
236 extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
237 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
240 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
241 impl SignedRawInvoice {
242 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
243 assert!(self.is_owned);
244 let ret = self.inner;
245 self.inner = std::ptr::null_mut();
249 impl Clone for SignedRawInvoice {
250 fn clone(&self) -> Self {
252 inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
253 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
259 /// Used only if an object of this type is returned as a trait impl by a method
260 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
261 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
264 /// Creates a copy of the SignedRawInvoice
265 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
269 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
270 type nativeRawInvoice = nativeRawInvoiceImport;
272 /// Represents an syntactically correct Invoice for a payment on the lightning network,
273 /// but without the signature information.
274 /// De- and encoding should not lead to information loss but may lead to different hashes.
276 /// For methods without docs see the corresponding methods in `Invoice`.
279 pub struct RawInvoice {
280 /// A pointer to the opaque Rust object.
282 /// Nearly everywhere, inner must be non-null, however in places where
283 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
284 pub inner: *mut nativeRawInvoice,
285 /// Indicates that this is the only struct which contains the same pointer.
287 /// Rust functions which take ownership of an object provided via an argument require
288 /// this to be true and invalidate the object pointed to by inner.
292 impl Drop for RawInvoice {
294 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
295 let _ = unsafe { Box::from_raw(self.inner) };
299 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
301 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
303 /// Used only if an object of this type is returned as a trait impl by a method
304 extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
305 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
308 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
310 pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
311 assert!(self.is_owned);
312 let ret = self.inner;
313 self.inner = std::ptr::null_mut();
319 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
320 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.data;
321 crate::lightning_invoice::RawDataPart { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
325 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
326 unsafe { &mut *this_ptr.inner }.data = *unsafe { Box::from_raw(val.take_inner()) };
328 impl Clone for RawInvoice {
329 fn clone(&self) -> Self {
331 inner: if <*mut nativeRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
332 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
338 /// Used only if an object of this type is returned as a trait impl by a method
339 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
340 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
343 /// Creates a copy of the RawInvoice
344 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
348 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
349 type nativeRawDataPart = nativeRawDataPartImport;
351 /// Data of the `RawInvoice` that is encoded in the data part
354 pub struct RawDataPart {
355 /// A pointer to the opaque Rust object.
357 /// Nearly everywhere, inner must be non-null, however in places where
358 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
359 pub inner: *mut nativeRawDataPart,
360 /// Indicates that this is the only struct which contains the same pointer.
362 /// Rust functions which take ownership of an object provided via an argument require
363 /// this to be true and invalidate the object pointed to by inner.
367 impl Drop for RawDataPart {
369 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
370 let _ = unsafe { Box::from_raw(self.inner) };
374 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
376 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
378 /// Used only if an object of this type is returned as a trait impl by a method
379 extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
380 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
383 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
385 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
386 assert!(self.is_owned);
387 let ret = self.inner;
388 self.inner = std::ptr::null_mut();
392 /// generation time of the invoice
394 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
395 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.timestamp;
396 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
398 /// generation time of the invoice
400 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
401 unsafe { &mut *this_ptr.inner }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
403 impl Clone for RawDataPart {
404 fn clone(&self) -> Self {
406 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { std::ptr::null_mut() } else {
407 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
413 /// Used only if an object of this type is returned as a trait impl by a method
414 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
415 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
418 /// Creates a copy of the RawDataPart
419 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
423 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
424 type nativePositiveTimestamp = nativePositiveTimestampImport;
426 /// A timestamp that refers to a date after 1 January 1970 which means its representation as UNIX
427 /// timestamp is positive.
430 /// The UNIX timestamp representing the stored time has to be positive and small enough so that
431 /// a `EpiryTime` can be added to it without an overflow.
434 pub struct PositiveTimestamp {
435 /// A pointer to the opaque Rust object.
437 /// Nearly everywhere, inner must be non-null, however in places where
438 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
439 pub inner: *mut nativePositiveTimestamp,
440 /// Indicates that this is the only struct which contains the same pointer.
442 /// Rust functions which take ownership of an object provided via an argument require
443 /// this to be true and invalidate the object pointed to by inner.
447 impl Drop for PositiveTimestamp {
449 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
450 let _ = unsafe { Box::from_raw(self.inner) };
454 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
456 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
458 /// Used only if an object of this type is returned as a trait impl by a method
459 extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
460 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
463 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
464 impl PositiveTimestamp {
465 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
466 assert!(self.is_owned);
467 let ret = self.inner;
468 self.inner = std::ptr::null_mut();
472 impl Clone for PositiveTimestamp {
473 fn clone(&self) -> Self {
475 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { std::ptr::null_mut() } else {
476 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
482 /// Used only if an object of this type is returned as a trait impl by a method
483 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
484 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
487 /// Creates a copy of the PositiveTimestamp
488 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
491 /// SI prefixes for the human readable part
505 use lightning_invoice::SiPrefix as nativeSiPrefix;
508 pub(crate) fn to_native(&self) -> nativeSiPrefix {
510 SiPrefix::Milli => nativeSiPrefix::Milli,
511 SiPrefix::Micro => nativeSiPrefix::Micro,
512 SiPrefix::Nano => nativeSiPrefix::Nano,
513 SiPrefix::Pico => nativeSiPrefix::Pico,
517 pub(crate) fn into_native(self) -> nativeSiPrefix {
519 SiPrefix::Milli => nativeSiPrefix::Milli,
520 SiPrefix::Micro => nativeSiPrefix::Micro,
521 SiPrefix::Nano => nativeSiPrefix::Nano,
522 SiPrefix::Pico => nativeSiPrefix::Pico,
526 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
528 nativeSiPrefix::Milli => SiPrefix::Milli,
529 nativeSiPrefix::Micro => SiPrefix::Micro,
530 nativeSiPrefix::Nano => SiPrefix::Nano,
531 nativeSiPrefix::Pico => SiPrefix::Pico,
535 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
537 nativeSiPrefix::Milli => SiPrefix::Milli,
538 nativeSiPrefix::Micro => SiPrefix::Micro,
539 nativeSiPrefix::Nano => SiPrefix::Nano,
540 nativeSiPrefix::Pico => SiPrefix::Pico,
544 /// Creates a copy of the SiPrefix
546 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
549 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
550 /// This is effectively 10^12 * the prefix multiplier
553 pub extern "C" fn SiPrefix_multiplier(this_arg: &SiPrefix) -> u64 {
554 let mut ret = this_arg.to_native().multiplier();
558 /// Enum representing the crypto currencies (or networks) supported by this library
569 /// Bitcoin simnet/signet
572 use lightning_invoice::Currency as nativeCurrency;
575 pub(crate) fn to_native(&self) -> nativeCurrency {
577 Currency::Bitcoin => nativeCurrency::Bitcoin,
578 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
579 Currency::Regtest => nativeCurrency::Regtest,
580 Currency::Simnet => nativeCurrency::Simnet,
584 pub(crate) fn into_native(self) -> nativeCurrency {
586 Currency::Bitcoin => nativeCurrency::Bitcoin,
587 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
588 Currency::Regtest => nativeCurrency::Regtest,
589 Currency::Simnet => nativeCurrency::Simnet,
593 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
595 nativeCurrency::Bitcoin => Currency::Bitcoin,
596 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
597 nativeCurrency::Regtest => Currency::Regtest,
598 nativeCurrency::Simnet => Currency::Simnet,
602 pub(crate) fn native_into(native: nativeCurrency) -> Self {
604 nativeCurrency::Bitcoin => Currency::Bitcoin,
605 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
606 nativeCurrency::Regtest => Currency::Regtest,
607 nativeCurrency::Simnet => Currency::Simnet,
611 /// Creates a copy of the Currency
613 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
617 use lightning_invoice::Sha256 as nativeSha256Import;
618 type nativeSha256 = nativeSha256Import;
624 /// A pointer to the opaque Rust object.
626 /// Nearly everywhere, inner must be non-null, however in places where
627 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
628 pub inner: *mut nativeSha256,
629 /// Indicates that this is the only struct which contains the same pointer.
631 /// Rust functions which take ownership of an object provided via an argument require
632 /// this to be true and invalidate the object pointed to by inner.
636 impl Drop for Sha256 {
638 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
639 let _ = unsafe { Box::from_raw(self.inner) };
643 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
645 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
647 /// Used only if an object of this type is returned as a trait impl by a method
648 extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
649 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
652 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
654 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
655 assert!(self.is_owned);
656 let ret = self.inner;
657 self.inner = std::ptr::null_mut();
661 impl Clone for Sha256 {
662 fn clone(&self) -> Self {
664 inner: if <*mut nativeSha256>::is_null(self.inner) { std::ptr::null_mut() } else {
665 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
671 /// Used only if an object of this type is returned as a trait impl by a method
672 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
673 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
676 /// Creates a copy of the Sha256
677 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
681 use lightning_invoice::Description as nativeDescriptionImport;
682 type nativeDescription = nativeDescriptionImport;
684 /// Description string
687 /// The description can be at most 639 __bytes__ long
690 pub struct Description {
691 /// A pointer to the opaque Rust object.
693 /// Nearly everywhere, inner must be non-null, however in places where
694 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
695 pub inner: *mut nativeDescription,
696 /// Indicates that this is the only struct which contains the same pointer.
698 /// Rust functions which take ownership of an object provided via an argument require
699 /// this to be true and invalidate the object pointed to by inner.
703 impl Drop for Description {
705 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
706 let _ = unsafe { Box::from_raw(self.inner) };
710 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
712 pub extern "C" fn Description_free(this_obj: Description) { }
714 /// Used only if an object of this type is returned as a trait impl by a method
715 extern "C" fn Description_free_void(this_ptr: *mut c_void) {
716 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
719 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
721 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
722 assert!(self.is_owned);
723 let ret = self.inner;
724 self.inner = std::ptr::null_mut();
728 impl Clone for Description {
729 fn clone(&self) -> Self {
731 inner: if <*mut nativeDescription>::is_null(self.inner) { std::ptr::null_mut() } else {
732 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
738 /// Used only if an object of this type is returned as a trait impl by a method
739 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
740 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
743 /// Creates a copy of the Description
744 pub extern "C" fn Description_clone(orig: &Description) -> Description {
748 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
749 type nativePayeePubKey = nativePayeePubKeyImport;
754 pub struct PayeePubKey {
755 /// A pointer to the opaque Rust object.
757 /// Nearly everywhere, inner must be non-null, however in places where
758 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
759 pub inner: *mut nativePayeePubKey,
760 /// Indicates that this is the only struct which contains the same pointer.
762 /// Rust functions which take ownership of an object provided via an argument require
763 /// this to be true and invalidate the object pointed to by inner.
767 impl Drop for PayeePubKey {
769 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
770 let _ = unsafe { Box::from_raw(self.inner) };
774 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
776 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
778 /// Used only if an object of this type is returned as a trait impl by a method
779 extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
780 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
783 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
785 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
786 assert!(self.is_owned);
787 let ret = self.inner;
788 self.inner = std::ptr::null_mut();
792 impl Clone for PayeePubKey {
793 fn clone(&self) -> Self {
795 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { std::ptr::null_mut() } else {
796 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
802 /// Used only if an object of this type is returned as a trait impl by a method
803 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
804 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
807 /// Creates a copy of the PayeePubKey
808 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
812 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
813 type nativeExpiryTime = nativeExpiryTimeImport;
815 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
819 /// The number of seconds this expiry time represents has to be in the range
820 /// `0...(SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME)` to avoid overflows when adding it to a
824 pub struct ExpiryTime {
825 /// A pointer to the opaque Rust object.
827 /// Nearly everywhere, inner must be non-null, however in places where
828 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
829 pub inner: *mut nativeExpiryTime,
830 /// Indicates that this is the only struct which contains the same pointer.
832 /// Rust functions which take ownership of an object provided via an argument require
833 /// this to be true and invalidate the object pointed to by inner.
837 impl Drop for ExpiryTime {
839 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
840 let _ = unsafe { Box::from_raw(self.inner) };
844 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
846 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
848 /// Used only if an object of this type is returned as a trait impl by a method
849 extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
850 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
853 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
855 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
856 assert!(self.is_owned);
857 let ret = self.inner;
858 self.inner = std::ptr::null_mut();
862 impl Clone for ExpiryTime {
863 fn clone(&self) -> Self {
865 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { std::ptr::null_mut() } else {
866 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
872 /// Used only if an object of this type is returned as a trait impl by a method
873 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
874 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
877 /// Creates a copy of the ExpiryTime
878 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
882 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
883 type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
885 /// `min_final_cltv_expiry` to use for the last HTLC in the route
888 pub struct MinFinalCltvExpiry {
889 /// A pointer to the opaque Rust object.
891 /// Nearly everywhere, inner must be non-null, however in places where
892 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
893 pub inner: *mut nativeMinFinalCltvExpiry,
894 /// Indicates that this is the only struct which contains the same pointer.
896 /// Rust functions which take ownership of an object provided via an argument require
897 /// this to be true and invalidate the object pointed to by inner.
901 impl Drop for MinFinalCltvExpiry {
903 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
904 let _ = unsafe { Box::from_raw(self.inner) };
908 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
910 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
912 /// Used only if an object of this type is returned as a trait impl by a method
913 extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
914 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
917 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
918 impl MinFinalCltvExpiry {
919 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
920 assert!(self.is_owned);
921 let ret = self.inner;
922 self.inner = std::ptr::null_mut();
926 impl Clone for MinFinalCltvExpiry {
927 fn clone(&self) -> Self {
929 inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { std::ptr::null_mut() } else {
930 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
936 /// Used only if an object of this type is returned as a trait impl by a method
937 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
938 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
941 /// Creates a copy of the MinFinalCltvExpiry
942 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
945 /// Fallback address in case no LN payment is possible
951 version: crate::c_types::u5,
952 program: crate::c_types::derived::CVec_u8Z,
954 PubKeyHash(crate::c_types::TwentyBytes),
955 ScriptHash(crate::c_types::TwentyBytes),
957 use lightning_invoice::Fallback as nativeFallback;
960 pub(crate) fn to_native(&self) -> nativeFallback {
962 Fallback::SegWitProgram {ref version, ref program, } => {
963 let mut version_nonref = (*version).clone();
964 let mut program_nonref = (*program).clone();
965 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
966 nativeFallback::SegWitProgram {
967 version: version_nonref.into(),
968 program: local_program_nonref,
971 Fallback::PubKeyHash (ref a, ) => {
972 let mut a_nonref = (*a).clone();
973 nativeFallback::PubKeyHash (
977 Fallback::ScriptHash (ref a, ) => {
978 let mut a_nonref = (*a).clone();
979 nativeFallback::ScriptHash (
986 pub(crate) fn into_native(self) -> nativeFallback {
988 Fallback::SegWitProgram {mut version, mut program, } => {
989 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
990 nativeFallback::SegWitProgram {
991 version: version.into(),
992 program: local_program,
995 Fallback::PubKeyHash (mut a, ) => {
996 nativeFallback::PubKeyHash (
1000 Fallback::ScriptHash (mut a, ) => {
1001 nativeFallback::ScriptHash (
1008 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1010 nativeFallback::SegWitProgram {ref version, ref program, } => {
1011 let mut version_nonref = (*version).clone();
1012 let mut program_nonref = (*program).clone();
1013 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1014 Fallback::SegWitProgram {
1015 version: version_nonref.into(),
1016 program: local_program_nonref.into(),
1019 nativeFallback::PubKeyHash (ref a, ) => {
1020 let mut a_nonref = (*a).clone();
1021 Fallback::PubKeyHash (
1022 crate::c_types::TwentyBytes { data: a_nonref },
1025 nativeFallback::ScriptHash (ref a, ) => {
1026 let mut a_nonref = (*a).clone();
1027 Fallback::ScriptHash (
1028 crate::c_types::TwentyBytes { data: a_nonref },
1034 pub(crate) fn native_into(native: nativeFallback) -> Self {
1036 nativeFallback::SegWitProgram {mut version, mut program, } => {
1037 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1038 Fallback::SegWitProgram {
1039 version: version.into(),
1040 program: local_program.into(),
1043 nativeFallback::PubKeyHash (mut a, ) => {
1044 Fallback::PubKeyHash (
1045 crate::c_types::TwentyBytes { data: a },
1048 nativeFallback::ScriptHash (mut a, ) => {
1049 Fallback::ScriptHash (
1050 crate::c_types::TwentyBytes { data: a },
1056 /// Frees any resources used by the Fallback
1058 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1059 /// Creates a copy of the Fallback
1061 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1065 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1066 type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1068 /// Recoverable signature
1071 pub struct InvoiceSignature {
1072 /// A pointer to the opaque Rust object.
1074 /// Nearly everywhere, inner must be non-null, however in places where
1075 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1076 pub inner: *mut nativeInvoiceSignature,
1077 /// Indicates that this is the only struct which contains the same pointer.
1079 /// Rust functions which take ownership of an object provided via an argument require
1080 /// this to be true and invalidate the object pointed to by inner.
1084 impl Drop for InvoiceSignature {
1085 fn drop(&mut self) {
1086 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1087 let _ = unsafe { Box::from_raw(self.inner) };
1091 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1093 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1095 /// Used only if an object of this type is returned as a trait impl by a method
1096 extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1097 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1100 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1101 impl InvoiceSignature {
1102 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1103 assert!(self.is_owned);
1104 let ret = self.inner;
1105 self.inner = std::ptr::null_mut();
1109 impl Clone for InvoiceSignature {
1110 fn clone(&self) -> Self {
1112 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { std::ptr::null_mut() } else {
1113 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1119 /// Used only if an object of this type is returned as a trait impl by a method
1120 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
1121 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
1124 /// Creates a copy of the InvoiceSignature
1125 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
1129 use lightning_invoice::RouteHint as nativeRouteHintImport;
1130 type nativeRouteHint = nativeRouteHintImport;
1132 /// Private routing information
1135 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
1139 pub struct RouteHint {
1140 /// A pointer to the opaque Rust object.
1142 /// Nearly everywhere, inner must be non-null, however in places where
1143 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1144 pub inner: *mut nativeRouteHint,
1145 /// Indicates that this is the only struct which contains the same pointer.
1147 /// Rust functions which take ownership of an object provided via an argument require
1148 /// this to be true and invalidate the object pointed to by inner.
1152 impl Drop for RouteHint {
1153 fn drop(&mut self) {
1154 if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) {
1155 let _ = unsafe { Box::from_raw(self.inner) };
1159 /// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
1161 pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
1163 /// Used only if an object of this type is returned as a trait impl by a method
1164 extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) {
1165 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHint); }
1168 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1170 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint {
1171 assert!(self.is_owned);
1172 let ret = self.inner;
1173 self.inner = std::ptr::null_mut();
1177 impl Clone for RouteHint {
1178 fn clone(&self) -> Self {
1180 inner: if <*mut nativeRouteHint>::is_null(self.inner) { std::ptr::null_mut() } else {
1181 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1187 /// Used only if an object of this type is returned as a trait impl by a method
1188 pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void {
1189 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void
1192 /// Creates a copy of the RouteHint
1193 pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
1196 /// Disassembles the `SignedRawInvoice` into its three parts:
1198 /// 2. hash of the raw invoice
1202 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
1203 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
1204 let (mut orig_ret_0, mut orig_ret_1, mut orig_ret_2) = ret; let mut local_ret = (crate::lightning_invoice::RawInvoice { inner: Box::into_raw(Box::new(orig_ret_0)), is_owned: true }, crate::c_types::ThirtyTwoBytes { data: orig_ret_1 }, crate::lightning_invoice::InvoiceSignature { inner: Box::into_raw(Box::new(orig_ret_2)), is_owned: true }).into();
1208 /// The `RawInvoice` which was signed.
1211 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
1212 let mut ret = unsafe { &*this_arg.inner }.raw_invoice();
1213 crate::lightning_invoice::RawInvoice { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1216 /// The hash of the `RawInvoice` that was signed.
1219 pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [u8; 32] {
1220 let mut ret = unsafe { &*this_arg.inner }.hash();
1224 /// InvoiceSignature for the invoice.
1227 pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
1228 let mut ret = unsafe { &*this_arg.inner }.signature();
1229 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1232 /// Recovers the public key used for signing the invoice from the recoverable signature.
1235 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
1236 let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key();
1237 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PayeePubKey { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
1241 /// Checks if the signature is valid for the included payee public key or if none exists if it's
1242 /// valid for the recovered signature (which should always be true?).
1245 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &SignedRawInvoice) -> bool {
1246 let mut ret = unsafe { &*this_arg.inner }.check_signature();
1250 /// Calculate the hash of the encoded `RawInvoice`
1253 pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1254 let mut ret = unsafe { &*this_arg.inner }.hash();
1255 crate::c_types::ThirtyTwoBytes { data: ret }
1260 pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1261 let mut ret = unsafe { &*this_arg.inner }.payment_hash();
1262 let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1268 pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightning_invoice::Description {
1269 let mut ret = unsafe { &*this_arg.inner }.description();
1270 let mut local_ret = crate::lightning_invoice::Description { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1276 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::lightning_invoice::PayeePubKey {
1277 let mut ret = unsafe { &*this_arg.inner }.payee_pub_key();
1278 let mut local_ret = crate::lightning_invoice::PayeePubKey { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1284 pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1285 let mut ret = unsafe { &*this_arg.inner }.description_hash();
1286 let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1292 pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightning_invoice::ExpiryTime {
1293 let mut ret = unsafe { &*this_arg.inner }.expiry_time();
1294 let mut local_ret = crate::lightning_invoice::ExpiryTime { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1300 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
1301 let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry();
1302 let mut local_ret = crate::lightning_invoice::MinFinalCltvExpiry { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1308 pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1309 let mut ret = unsafe { &*this_arg.inner }.payment_secret();
1310 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1316 pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
1317 let mut ret = unsafe { &*this_arg.inner }.features();
1318 let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1324 pub extern "C" fn RawInvoice_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_RouteHintZ {
1325 let mut ret = unsafe { &*this_arg.inner }.routes();
1326 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::RouteHint { inner: unsafe { ( (&(**item) as *const _) as *mut _) }, is_owned: false } }); };
1332 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z {
1333 let mut ret = unsafe { &*this_arg.inner }.amount_pico_btc();
1334 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()) } };
1340 pub extern "C" fn RawInvoice_currency(this_arg: &RawInvoice) -> crate::lightning_invoice::Currency {
1341 let mut ret = unsafe { &*this_arg.inner }.currency();
1342 crate::lightning_invoice::Currency::native_into(ret)
1345 /// Create a new `PositiveTimestamp` from a unix timestamp in the Range
1346 /// `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1347 /// `CreationError::TimestampOutOfBounds`.
1350 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1351 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
1352 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
1356 /// Create a new `PositiveTimestamp` from a `SystemTime` with a corresponding unix timestamp in
1357 /// the Range `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1358 /// `CreationError::TimestampOutOfBounds`.
1361 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1362 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
1363 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
1367 /// Returns the UNIX timestamp representing the stored time
1370 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 {
1371 let mut ret = unsafe { &*this_arg.inner }.as_unix_timestamp();
1375 /// Returns a reference to the internal `SystemTime` time representation
1378 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &PositiveTimestamp) -> u64 {
1379 let mut ret = unsafe { &*this_arg.inner }.as_time();
1380 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1383 /// Transform the `Invoice` into it's unchecked version
1386 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::lightning_invoice::SignedRawInvoice {
1387 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
1388 crate::lightning_invoice::SignedRawInvoice { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1391 /// Check that the invoice is signed correctly and that key recovery works
1394 pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
1395 let mut ret = unsafe { &*this_arg.inner }.check_signature();
1396 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() };
1400 /// Constructs an `Invoice` from a `SignedInvoice` by checking all its invariants.
1402 /// use lightning_invoice::*;
1404 /// let invoice = \"lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdp\\
1405 /// \tl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d7\\
1406 /// \t3gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ec\\
1407 /// \tky03ylcqca784w\";
1409 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
1411 /// assert!(Invoice::from_signed(signed).is_ok());
1415 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
1416 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
1417 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::Invoice { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::SemanticError::native_into(e) }).into() };
1421 /// Returns the `Invoice`'s timestamp (should equal it's creation time)
1424 pub extern "C" fn Invoice_timestamp(this_arg: &Invoice) -> u64 {
1425 let mut ret = unsafe { &*this_arg.inner }.timestamp();
1426 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1429 /// Returns the hash to which we will receive the preimage on completion of the payment
1432 pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] {
1433 let mut ret = unsafe { &*this_arg.inner }.payment_hash();
1437 /// Get the payee's public key if one was included in the invoice
1440 pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1441 let mut ret = unsafe { &*this_arg.inner }.payee_pub_key();
1442 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
1446 /// Get the payment secret if one was included in the invoice
1449 pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> crate::c_types::ThirtyTwoBytes {
1450 let mut ret = unsafe { &*this_arg.inner }.payment_secret();
1451 let mut local_ret = if ret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (ret.unwrap()).0 } } };
1455 /// Get the invoice features if they were included in the invoice
1458 pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
1459 let mut ret = unsafe { &*this_arg.inner }.features();
1460 let mut local_ret = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1464 /// Recover the payee's public key (only to be used if none was included in the invoice)
1467 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1468 let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key();
1469 crate::c_types::PublicKey::from_rust(&ret)
1472 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
1475 pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 {
1476 let mut ret = unsafe { &*this_arg.inner }.expiry_time();
1480 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
1481 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
1484 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> u64 {
1485 let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry();
1489 /// Returns a list of all routes included in the invoice
1492 pub extern "C" fn Invoice_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
1493 let mut ret = unsafe { &*this_arg.inner }.routes();
1494 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::RouteHint { inner: unsafe { ( (&(**item) as *const _) as *mut _) }, is_owned: false } }); };
1498 /// Returns the currency for which the invoice was issued
1501 pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoice::Currency {
1502 let mut ret = unsafe { &*this_arg.inner }.currency();
1503 crate::lightning_invoice::Currency::native_into(ret)
1506 /// Returns the amount if specified in the invoice as pico <currency>.
1509 pub extern "C" fn Invoice_amount_pico_btc(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z {
1510 let mut ret = unsafe { &*this_arg.inner }.amount_pico_btc();
1511 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()) } };
1515 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
1516 /// returns `CreationError::DescriptionTooLong` otherwise
1518 /// Please note that single characters may use more than one byte due to UTF8 encoding.
1521 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
1522 let mut ret = lightning_invoice::Description::new(description.into_string());
1523 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::Description { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
1527 /// Returns the underlying description `String`
1530 pub extern "C" fn Description_into_inner(mut this_arg: Description) -> crate::c_types::Str {
1531 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1535 /// Construct an `ExpiryTime` from seconds. If there exists a `PositiveTimestamp` which would
1536 /// overflow on adding the `EpiryTime` to it then this function will return a
1537 /// `CreationError::ExpiryTimeOutOfBounds`.
1540 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1541 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
1542 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::ExpiryTime { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
1546 /// Construct an `ExpiryTime` from a `Duration`. If there exists a `PositiveTimestamp` which
1547 /// would overflow on adding the `EpiryTime` to it then this function will return a
1548 /// `CreationError::ExpiryTimeOutOfBounds`.
1551 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1552 let mut ret = lightning_invoice::ExpiryTime::from_duration(std::time::Duration::from_secs(duration));
1553 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::ExpiryTime { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
1557 /// Returns the expiry time in seconds
1560 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 {
1561 let mut ret = unsafe { &*this_arg.inner }.as_seconds();
1565 /// Returns a reference to the underlying `Duration` (=expiry time)
1568 pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 {
1569 let mut ret = unsafe { &*this_arg.inner }.as_duration();
1573 /// Create a new (partial) route from a list of hops
1576 pub extern "C" fn RouteHint_new(mut hops: crate::c_types::derived::CVec_RouteHintHopZ) -> crate::c_types::derived::CResult_RouteHintCreationErrorZ {
1577 let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1578 let mut ret = lightning_invoice::RouteHint::new(local_hops);
1579 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::RouteHint { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
1583 /// Returrn the underlying vector of hops
1586 pub extern "C" fn RouteHint_into_inner(mut this_arg: RouteHint) -> crate::c_types::derived::CVec_RouteHintHopZ {
1587 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1588 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::router::RouteHintHop { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
1592 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
1596 pub enum CreationError {
1597 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
1599 /// The specified route has too many hops and can't be encoded
1601 /// The unix timestamp of the supplied date is <0 or can't be represented as `SystemTime`
1602 TimestampOutOfBounds,
1603 /// The supplied expiry time could cause an overflow if added to a `PositiveTimestamp`
1604 ExpiryTimeOutOfBounds,
1606 use lightning_invoice::CreationError as nativeCreationError;
1607 impl CreationError {
1609 pub(crate) fn to_native(&self) -> nativeCreationError {
1611 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
1612 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
1613 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
1614 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
1618 pub(crate) fn into_native(self) -> nativeCreationError {
1620 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
1621 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
1622 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
1623 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
1627 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
1629 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
1630 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
1631 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
1632 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
1636 pub(crate) fn native_into(native: nativeCreationError) -> Self {
1638 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
1639 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
1640 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
1641 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
1645 /// Creates a copy of the CreationError
1647 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
1651 /// Get the string representation of a CreationError object
1652 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
1653 format!("{}", &o.to_native()).into()
1655 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
1656 /// requirements sections in BOLT #11
1660 pub enum SemanticError {
1661 /// The invoice is missing the mandatory payment hash
1663 /// The invoice has multiple payment hashes which isn't allowed
1664 MultiplePaymentHashes,
1665 /// No description or description hash are part of the invoice
1667 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
1668 MultipleDescriptions,
1669 /// The recovery id doesn't fit the signature/pub key
1671 /// The invoice's signature is invalid
1674 use lightning_invoice::SemanticError as nativeSemanticError;
1675 impl SemanticError {
1677 pub(crate) fn to_native(&self) -> nativeSemanticError {
1679 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
1680 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
1681 SemanticError::NoDescription => nativeSemanticError::NoDescription,
1682 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
1683 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
1684 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
1688 pub(crate) fn into_native(self) -> nativeSemanticError {
1690 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
1691 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
1692 SemanticError::NoDescription => nativeSemanticError::NoDescription,
1693 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
1694 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
1695 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
1699 pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
1701 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
1702 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
1703 nativeSemanticError::NoDescription => SemanticError::NoDescription,
1704 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
1705 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
1706 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
1710 pub(crate) fn native_into(native: nativeSemanticError) -> Self {
1712 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
1713 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
1714 nativeSemanticError::NoDescription => SemanticError::NoDescription,
1715 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
1716 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
1717 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
1721 /// Creates a copy of the SemanticError
1723 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
1727 /// Get the string representation of a SemanticError object
1728 pub extern "C" fn SemanticError_to_str(o: &crate::lightning_invoice::SemanticError) -> Str {
1729 format!("{}", &o.to_native()).into()
1731 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
1736 pub enum SignOrCreationError {
1737 /// An error occurred during signing
1739 /// An error occurred while building the transaction
1740 CreationError(crate::lightning_invoice::CreationError),
1742 use lightning_invoice::SignOrCreationError as nativeSignOrCreationError;
1743 impl SignOrCreationError {
1745 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
1747 SignOrCreationError::SignError => {
1748 nativeSignOrCreationError::SignError (
1752 SignOrCreationError::CreationError (ref a, ) => {
1753 let mut a_nonref = (*a).clone();
1754 nativeSignOrCreationError::CreationError (
1755 a_nonref.into_native(),
1761 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
1763 SignOrCreationError::SignError => {
1764 nativeSignOrCreationError::SignError (
1768 SignOrCreationError::CreationError (mut a, ) => {
1769 nativeSignOrCreationError::CreationError (
1776 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
1778 nativeSignOrCreationError::SignError (ref a, ) => {
1779 SignOrCreationError::SignError },
1780 nativeSignOrCreationError::CreationError (ref a, ) => {
1781 let mut a_nonref = (*a).clone();
1782 SignOrCreationError::CreationError (
1783 crate::lightning_invoice::CreationError::native_into(a_nonref),
1789 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
1791 nativeSignOrCreationError::SignError (mut a, ) => {
1792 SignOrCreationError::SignError },
1793 nativeSignOrCreationError::CreationError (mut a, ) => {
1794 SignOrCreationError::CreationError (
1795 crate::lightning_invoice::CreationError::native_into(a),
1801 /// Frees any resources used by the SignOrCreationError
1803 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
1804 /// Creates a copy of the SignOrCreationError
1806 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
1810 /// Get the string representation of a SignOrCreationError object
1811 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
1812 format!("{}", &o.to_native()).into()