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::*;
26 use std::str::FromStr;
28 use bitcoin::hashes::Hash;
29 use crate::c_types::*;
33 use std::str::FromStr;
35 use bitcoin::hashes::Hash;
36 use crate::c_types::*;
42 use std::str::FromStr;
44 use bitcoin::hashes::Hash;
45 use crate::c_types::*;
50 use std::str::FromStr;
52 use bitcoin::hashes::Hash;
53 use crate::c_types::*;
56 /// **Call this function on startup to ensure that all assumptions about the platform are valid.**
58 /// Unfortunately we have to make assumptions about the upper bounds of the `SystemTime` type on
59 /// your platform which we can't fully verify at compile time and which isn't part of it's contract.
60 /// To our best knowledge our assumptions hold for all platforms officially supported by rust, but
61 /// since this check is fast we recommend to do it anyway.
63 /// If this function fails this is considered a bug. Please open an issue describing your
64 /// platform and stating your current system time.
67 /// If the check fails this function panics. By calling this function on startup you ensure that
68 /// this wont happen at an arbitrary later point in time.
70 pub extern "C" fn check_platform() {
71 lightning_invoice::check_platform()
75 use lightning_invoice::Invoice as nativeInvoiceImport;
76 type nativeInvoice = nativeInvoiceImport;
78 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
80 /// There are three ways to construct an `Invoice`:
81 /// 1. using `InvoiceBuilder`
82 /// 2. using `Invoice::from_signed(SignedRawInvoice)`
83 /// 3. using `str::parse::<Invoice>(&str)`
87 /// A pointer to the opaque Rust object.
89 /// Nearly everywhere, inner must be non-null, however in places where
90 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
91 pub inner: *mut nativeInvoice,
92 /// Indicates that this is the only struct which contains the same pointer.
94 /// Rust functions which take ownership of an object provided via an argument require
95 /// this to be true and invalidate the object pointed to by inner.
99 impl Drop for Invoice {
101 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
102 let _ = unsafe { Box::from_raw(self.inner) };
106 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
108 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
110 /// Used only if an object of this type is returned as a trait impl by a method
111 extern "C" fn Invoice_free_void(this_ptr: *mut c_void) {
112 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoice); }
115 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
117 pub(crate) fn take_inner(mut self) -> *mut nativeInvoice {
118 assert!(self.is_owned);
119 let ret = self.inner;
120 self.inner = std::ptr::null_mut();
124 impl Clone for Invoice {
125 fn clone(&self) -> Self {
127 inner: if <*mut nativeInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
128 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
134 /// Used only if an object of this type is returned as a trait impl by a method
135 pub(crate) extern "C" fn Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
136 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoice)).clone() })) as *mut c_void
139 /// Creates a copy of the Invoice
140 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
144 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
145 type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
147 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
151 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
154 pub struct SignedRawInvoice {
155 /// A pointer to the opaque Rust object.
157 /// Nearly everywhere, inner must be non-null, however in places where
158 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
159 pub inner: *mut nativeSignedRawInvoice,
160 /// Indicates that this is the only struct which contains the same pointer.
162 /// Rust functions which take ownership of an object provided via an argument require
163 /// this to be true and invalidate the object pointed to by inner.
167 impl Drop for SignedRawInvoice {
169 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
170 let _ = unsafe { Box::from_raw(self.inner) };
174 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
176 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
178 /// Used only if an object of this type is returned as a trait impl by a method
179 extern "C" fn SignedRawInvoice_free_void(this_ptr: *mut c_void) {
180 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSignedRawInvoice); }
183 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
184 impl SignedRawInvoice {
185 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawInvoice {
186 assert!(self.is_owned);
187 let ret = self.inner;
188 self.inner = std::ptr::null_mut();
192 impl Clone for SignedRawInvoice {
193 fn clone(&self) -> Self {
195 inner: if <*mut nativeSignedRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
196 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
202 /// Used only if an object of this type is returned as a trait impl by a method
203 pub(crate) extern "C" fn SignedRawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
204 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawInvoice)).clone() })) as *mut c_void
207 /// Creates a copy of the SignedRawInvoice
208 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
212 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
213 type nativeRawInvoice = nativeRawInvoiceImport;
215 /// Represents an syntactically correct Invoice for a payment on the lightning network,
216 /// but without the signature information.
217 /// De- and encoding should not lead to information loss but may lead to different hashes.
219 /// For methods without docs see the corresponding methods in `Invoice`.
222 pub struct RawInvoice {
223 /// A pointer to the opaque Rust object.
225 /// Nearly everywhere, inner must be non-null, however in places where
226 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
227 pub inner: *mut nativeRawInvoice,
228 /// Indicates that this is the only struct which contains the same pointer.
230 /// Rust functions which take ownership of an object provided via an argument require
231 /// this to be true and invalidate the object pointed to by inner.
235 impl Drop for RawInvoice {
237 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
238 let _ = unsafe { Box::from_raw(self.inner) };
242 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
244 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
246 /// Used only if an object of this type is returned as a trait impl by a method
247 extern "C" fn RawInvoice_free_void(this_ptr: *mut c_void) {
248 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawInvoice); }
251 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
253 pub(crate) fn take_inner(mut self) -> *mut nativeRawInvoice {
254 assert!(self.is_owned);
255 let ret = self.inner;
256 self.inner = std::ptr::null_mut();
262 pub extern "C" fn RawInvoice_get_data(this_ptr: &RawInvoice) -> crate::lightning_invoice::RawDataPart {
263 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.data;
264 crate::lightning_invoice::RawDataPart { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
268 pub extern "C" fn RawInvoice_set_data(this_ptr: &mut RawInvoice, mut val: crate::lightning_invoice::RawDataPart) {
269 unsafe { &mut *this_ptr.inner }.data = *unsafe { Box::from_raw(val.take_inner()) };
271 impl Clone for RawInvoice {
272 fn clone(&self) -> Self {
274 inner: if <*mut nativeRawInvoice>::is_null(self.inner) { std::ptr::null_mut() } else {
275 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
281 /// Used only if an object of this type is returned as a trait impl by a method
282 pub(crate) extern "C" fn RawInvoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
283 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawInvoice)).clone() })) as *mut c_void
286 /// Creates a copy of the RawInvoice
287 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
291 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
292 type nativeRawDataPart = nativeRawDataPartImport;
294 /// Data of the `RawInvoice` that is encoded in the data part
297 pub struct RawDataPart {
298 /// A pointer to the opaque Rust object.
300 /// Nearly everywhere, inner must be non-null, however in places where
301 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
302 pub inner: *mut nativeRawDataPart,
303 /// Indicates that this is the only struct which contains the same pointer.
305 /// Rust functions which take ownership of an object provided via an argument require
306 /// this to be true and invalidate the object pointed to by inner.
310 impl Drop for RawDataPart {
312 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
313 let _ = unsafe { Box::from_raw(self.inner) };
317 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
319 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
321 /// Used only if an object of this type is returned as a trait impl by a method
322 extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
323 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRawDataPart); }
326 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
328 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
329 assert!(self.is_owned);
330 let ret = self.inner;
331 self.inner = std::ptr::null_mut();
335 /// generation time of the invoice
337 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
338 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.timestamp;
339 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
341 /// generation time of the invoice
343 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
344 unsafe { &mut *this_ptr.inner }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
346 /// tagged fields of the payment request
348 pub extern "C" fn RawDataPart_set_tagged_fields(this_ptr: &mut RawDataPart, mut val: crate::c_types::derived::CVec_RawTaggedFieldZ) {
349 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
350 unsafe { &mut *this_ptr.inner }.tagged_fields = local_val;
352 /// Constructs a new RawDataPart given each field
355 pub extern "C" fn RawDataPart_new(mut timestamp_arg: crate::lightning_invoice::PositiveTimestamp, mut tagged_fields_arg: crate::c_types::derived::CVec_RawTaggedFieldZ) -> RawDataPart {
356 let mut local_tagged_fields_arg = Vec::new(); for mut item in tagged_fields_arg.into_rust().drain(..) { local_tagged_fields_arg.push( { item.into_native() }); };
357 RawDataPart { inner: Box::into_raw(Box::new(nativeRawDataPart {
358 timestamp: *unsafe { Box::from_raw(timestamp_arg.take_inner()) },
359 tagged_fields: local_tagged_fields_arg,
360 })), is_owned: true }
362 impl Clone for RawDataPart {
363 fn clone(&self) -> Self {
365 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { std::ptr::null_mut() } else {
366 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
372 /// Used only if an object of this type is returned as a trait impl by a method
373 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
374 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
377 /// Creates a copy of the RawDataPart
378 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
382 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
383 type nativePositiveTimestamp = nativePositiveTimestampImport;
385 /// A timestamp that refers to a date after 1 January 1970 which means its representation as UNIX
386 /// timestamp is positive.
389 /// The UNIX timestamp representing the stored time has to be positive and small enough so that
390 /// a `EpiryTime` can be added to it without an overflow.
393 pub struct PositiveTimestamp {
394 /// A pointer to the opaque Rust object.
396 /// Nearly everywhere, inner must be non-null, however in places where
397 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
398 pub inner: *mut nativePositiveTimestamp,
399 /// Indicates that this is the only struct which contains the same pointer.
401 /// Rust functions which take ownership of an object provided via an argument require
402 /// this to be true and invalidate the object pointed to by inner.
406 impl Drop for PositiveTimestamp {
408 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
409 let _ = unsafe { Box::from_raw(self.inner) };
413 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
415 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
417 /// Used only if an object of this type is returned as a trait impl by a method
418 extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
419 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePositiveTimestamp); }
422 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
423 impl PositiveTimestamp {
424 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
425 assert!(self.is_owned);
426 let ret = self.inner;
427 self.inner = std::ptr::null_mut();
431 impl Clone for PositiveTimestamp {
432 fn clone(&self) -> Self {
434 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { std::ptr::null_mut() } else {
435 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
441 /// Used only if an object of this type is returned as a trait impl by a method
442 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
443 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
446 /// Creates a copy of the PositiveTimestamp
447 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
450 /// SI prefixes for the human readable part
464 use lightning_invoice::SiPrefix as nativeSiPrefix;
467 pub(crate) fn to_native(&self) -> nativeSiPrefix {
469 SiPrefix::Milli => nativeSiPrefix::Milli,
470 SiPrefix::Micro => nativeSiPrefix::Micro,
471 SiPrefix::Nano => nativeSiPrefix::Nano,
472 SiPrefix::Pico => nativeSiPrefix::Pico,
476 pub(crate) fn into_native(self) -> nativeSiPrefix {
478 SiPrefix::Milli => nativeSiPrefix::Milli,
479 SiPrefix::Micro => nativeSiPrefix::Micro,
480 SiPrefix::Nano => nativeSiPrefix::Nano,
481 SiPrefix::Pico => nativeSiPrefix::Pico,
485 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
487 nativeSiPrefix::Milli => SiPrefix::Milli,
488 nativeSiPrefix::Micro => SiPrefix::Micro,
489 nativeSiPrefix::Nano => SiPrefix::Nano,
490 nativeSiPrefix::Pico => SiPrefix::Pico,
494 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
496 nativeSiPrefix::Milli => SiPrefix::Milli,
497 nativeSiPrefix::Micro => SiPrefix::Micro,
498 nativeSiPrefix::Nano => SiPrefix::Nano,
499 nativeSiPrefix::Pico => SiPrefix::Pico,
503 /// Creates a copy of the SiPrefix
505 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
508 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
509 /// This is effectively 10^12 * the prefix multiplier
512 pub extern "C" fn SiPrefix_multiplier(this_arg: &SiPrefix) -> u64 {
513 let mut ret = this_arg.to_native().multiplier();
517 /// Enum representing the crypto currencies (or networks) supported by this library
528 /// Bitcoin simnet/signet
531 use lightning_invoice::Currency as nativeCurrency;
534 pub(crate) fn to_native(&self) -> nativeCurrency {
536 Currency::Bitcoin => nativeCurrency::Bitcoin,
537 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
538 Currency::Regtest => nativeCurrency::Regtest,
539 Currency::Simnet => nativeCurrency::Simnet,
543 pub(crate) fn into_native(self) -> nativeCurrency {
545 Currency::Bitcoin => nativeCurrency::Bitcoin,
546 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
547 Currency::Regtest => nativeCurrency::Regtest,
548 Currency::Simnet => nativeCurrency::Simnet,
552 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
554 nativeCurrency::Bitcoin => Currency::Bitcoin,
555 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
556 nativeCurrency::Regtest => Currency::Regtest,
557 nativeCurrency::Simnet => Currency::Simnet,
561 pub(crate) fn native_into(native: nativeCurrency) -> Self {
563 nativeCurrency::Bitcoin => Currency::Bitcoin,
564 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
565 nativeCurrency::Regtest => Currency::Regtest,
566 nativeCurrency::Simnet => Currency::Simnet,
570 /// Creates a copy of the Currency
572 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
575 /// Tagged field which may have an unknown tag
579 pub enum RawTaggedField {
580 /// Parsed tagged field with known tag
581 KnownSemantics(crate::lightning_invoice::TaggedField),
582 /// tagged field which was not parsed due to an unknown tag or undefined field semantics
583 UnknownSemantics(crate::c_types::derived::CVec_u5Z),
585 use lightning_invoice::RawTaggedField as nativeRawTaggedField;
586 impl RawTaggedField {
588 pub(crate) fn to_native(&self) -> nativeRawTaggedField {
590 RawTaggedField::KnownSemantics (ref a, ) => {
591 let mut a_nonref = (*a).clone();
592 nativeRawTaggedField::KnownSemantics (
593 a_nonref.into_native(),
596 RawTaggedField::UnknownSemantics (ref a, ) => {
597 let mut a_nonref = (*a).clone();
598 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { item.into() }); };
599 nativeRawTaggedField::UnknownSemantics (
606 pub(crate) fn into_native(self) -> nativeRawTaggedField {
608 RawTaggedField::KnownSemantics (mut a, ) => {
609 nativeRawTaggedField::KnownSemantics (
613 RawTaggedField::UnknownSemantics (mut a, ) => {
614 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { item.into() }); };
615 nativeRawTaggedField::UnknownSemantics (
622 pub(crate) fn from_native(native: &nativeRawTaggedField) -> Self {
624 nativeRawTaggedField::KnownSemantics (ref a, ) => {
625 let mut a_nonref = (*a).clone();
626 RawTaggedField::KnownSemantics (
627 crate::lightning_invoice::TaggedField::native_into(a_nonref),
630 nativeRawTaggedField::UnknownSemantics (ref a, ) => {
631 let mut a_nonref = (*a).clone();
632 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.drain(..) { local_a_nonref.push( { item.into() }); };
633 RawTaggedField::UnknownSemantics (
634 local_a_nonref.into(),
640 pub(crate) fn native_into(native: nativeRawTaggedField) -> Self {
642 nativeRawTaggedField::KnownSemantics (mut a, ) => {
643 RawTaggedField::KnownSemantics (
644 crate::lightning_invoice::TaggedField::native_into(a),
647 nativeRawTaggedField::UnknownSemantics (mut a, ) => {
648 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { item.into() }); };
649 RawTaggedField::UnknownSemantics (
656 /// Frees any resources used by the RawTaggedField
658 pub extern "C" fn RawTaggedField_free(this_ptr: RawTaggedField) { }
659 /// Creates a copy of the RawTaggedField
661 pub extern "C" fn RawTaggedField_clone(orig: &RawTaggedField) -> RawTaggedField {
664 /// Tagged field with known tag
666 /// For descriptions of the enum values please refer to the enclosed type's docs.
670 pub enum TaggedField {
671 PaymentHash(crate::lightning_invoice::Sha256),
672 Description(crate::lightning_invoice::Description),
673 PayeePubKey(crate::lightning_invoice::PayeePubKey),
674 DescriptionHash(crate::lightning_invoice::Sha256),
675 ExpiryTime(crate::lightning_invoice::ExpiryTime),
676 MinFinalCltvExpiry(crate::lightning_invoice::MinFinalCltvExpiry),
677 Fallback(crate::lightning_invoice::Fallback),
678 Route(crate::lightning_invoice::RouteHint),
679 PaymentSecret(crate::lightning_invoice::PaymentSecret),
680 Features(crate::lightning::ln::features::InvoiceFeatures),
682 use lightning_invoice::TaggedField as nativeTaggedField;
685 pub(crate) fn to_native(&self) -> nativeTaggedField {
687 TaggedField::PaymentHash (ref a, ) => {
688 let mut a_nonref = (*a).clone();
689 nativeTaggedField::PaymentHash (
690 *unsafe { Box::from_raw(a_nonref.take_inner()) },
693 TaggedField::Description (ref a, ) => {
694 let mut a_nonref = (*a).clone();
695 nativeTaggedField::Description (
696 *unsafe { Box::from_raw(a_nonref.take_inner()) },
699 TaggedField::PayeePubKey (ref a, ) => {
700 let mut a_nonref = (*a).clone();
701 nativeTaggedField::PayeePubKey (
702 *unsafe { Box::from_raw(a_nonref.take_inner()) },
705 TaggedField::DescriptionHash (ref a, ) => {
706 let mut a_nonref = (*a).clone();
707 nativeTaggedField::DescriptionHash (
708 *unsafe { Box::from_raw(a_nonref.take_inner()) },
711 TaggedField::ExpiryTime (ref a, ) => {
712 let mut a_nonref = (*a).clone();
713 nativeTaggedField::ExpiryTime (
714 *unsafe { Box::from_raw(a_nonref.take_inner()) },
717 TaggedField::MinFinalCltvExpiry (ref a, ) => {
718 let mut a_nonref = (*a).clone();
719 nativeTaggedField::MinFinalCltvExpiry (
720 *unsafe { Box::from_raw(a_nonref.take_inner()) },
723 TaggedField::Fallback (ref a, ) => {
724 let mut a_nonref = (*a).clone();
725 nativeTaggedField::Fallback (
726 a_nonref.into_native(),
729 TaggedField::Route (ref a, ) => {
730 let mut a_nonref = (*a).clone();
731 nativeTaggedField::Route (
732 *unsafe { Box::from_raw(a_nonref.take_inner()) },
735 TaggedField::PaymentSecret (ref a, ) => {
736 let mut a_nonref = (*a).clone();
737 nativeTaggedField::PaymentSecret (
738 *unsafe { Box::from_raw(a_nonref.take_inner()) },
741 TaggedField::Features (ref a, ) => {
742 let mut a_nonref = (*a).clone();
743 nativeTaggedField::Features (
744 *unsafe { Box::from_raw(a_nonref.take_inner()) },
750 pub(crate) fn into_native(self) -> nativeTaggedField {
752 TaggedField::PaymentHash (mut a, ) => {
753 nativeTaggedField::PaymentHash (
754 *unsafe { Box::from_raw(a.take_inner()) },
757 TaggedField::Description (mut a, ) => {
758 nativeTaggedField::Description (
759 *unsafe { Box::from_raw(a.take_inner()) },
762 TaggedField::PayeePubKey (mut a, ) => {
763 nativeTaggedField::PayeePubKey (
764 *unsafe { Box::from_raw(a.take_inner()) },
767 TaggedField::DescriptionHash (mut a, ) => {
768 nativeTaggedField::DescriptionHash (
769 *unsafe { Box::from_raw(a.take_inner()) },
772 TaggedField::ExpiryTime (mut a, ) => {
773 nativeTaggedField::ExpiryTime (
774 *unsafe { Box::from_raw(a.take_inner()) },
777 TaggedField::MinFinalCltvExpiry (mut a, ) => {
778 nativeTaggedField::MinFinalCltvExpiry (
779 *unsafe { Box::from_raw(a.take_inner()) },
782 TaggedField::Fallback (mut a, ) => {
783 nativeTaggedField::Fallback (
787 TaggedField::Route (mut a, ) => {
788 nativeTaggedField::Route (
789 *unsafe { Box::from_raw(a.take_inner()) },
792 TaggedField::PaymentSecret (mut a, ) => {
793 nativeTaggedField::PaymentSecret (
794 *unsafe { Box::from_raw(a.take_inner()) },
797 TaggedField::Features (mut a, ) => {
798 nativeTaggedField::Features (
799 *unsafe { Box::from_raw(a.take_inner()) },
805 pub(crate) fn from_native(native: &nativeTaggedField) -> Self {
807 nativeTaggedField::PaymentHash (ref a, ) => {
808 let mut a_nonref = (*a).clone();
809 TaggedField::PaymentHash (
810 crate::lightning_invoice::Sha256 { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true },
813 nativeTaggedField::Description (ref a, ) => {
814 let mut a_nonref = (*a).clone();
815 TaggedField::Description (
816 crate::lightning_invoice::Description { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true },
819 nativeTaggedField::PayeePubKey (ref a, ) => {
820 let mut a_nonref = (*a).clone();
821 TaggedField::PayeePubKey (
822 crate::lightning_invoice::PayeePubKey { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true },
825 nativeTaggedField::DescriptionHash (ref a, ) => {
826 let mut a_nonref = (*a).clone();
827 TaggedField::DescriptionHash (
828 crate::lightning_invoice::Sha256 { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true },
831 nativeTaggedField::ExpiryTime (ref a, ) => {
832 let mut a_nonref = (*a).clone();
833 TaggedField::ExpiryTime (
834 crate::lightning_invoice::ExpiryTime { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true },
837 nativeTaggedField::MinFinalCltvExpiry (ref a, ) => {
838 let mut a_nonref = (*a).clone();
839 TaggedField::MinFinalCltvExpiry (
840 crate::lightning_invoice::MinFinalCltvExpiry { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true },
843 nativeTaggedField::Fallback (ref a, ) => {
844 let mut a_nonref = (*a).clone();
845 TaggedField::Fallback (
846 crate::lightning_invoice::Fallback::native_into(a_nonref),
849 nativeTaggedField::Route (ref a, ) => {
850 let mut a_nonref = (*a).clone();
852 crate::lightning_invoice::RouteHint { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true },
855 nativeTaggedField::PaymentSecret (ref a, ) => {
856 let mut a_nonref = (*a).clone();
857 TaggedField::PaymentSecret (
858 crate::lightning_invoice::PaymentSecret { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true },
861 nativeTaggedField::Features (ref a, ) => {
862 let mut a_nonref = (*a).clone();
863 TaggedField::Features (
864 crate::lightning::ln::features::InvoiceFeatures { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true },
870 pub(crate) fn native_into(native: nativeTaggedField) -> Self {
872 nativeTaggedField::PaymentHash (mut a, ) => {
873 TaggedField::PaymentHash (
874 crate::lightning_invoice::Sha256 { inner: Box::into_raw(Box::new(a)), is_owned: true },
877 nativeTaggedField::Description (mut a, ) => {
878 TaggedField::Description (
879 crate::lightning_invoice::Description { inner: Box::into_raw(Box::new(a)), is_owned: true },
882 nativeTaggedField::PayeePubKey (mut a, ) => {
883 TaggedField::PayeePubKey (
884 crate::lightning_invoice::PayeePubKey { inner: Box::into_raw(Box::new(a)), is_owned: true },
887 nativeTaggedField::DescriptionHash (mut a, ) => {
888 TaggedField::DescriptionHash (
889 crate::lightning_invoice::Sha256 { inner: Box::into_raw(Box::new(a)), is_owned: true },
892 nativeTaggedField::ExpiryTime (mut a, ) => {
893 TaggedField::ExpiryTime (
894 crate::lightning_invoice::ExpiryTime { inner: Box::into_raw(Box::new(a)), is_owned: true },
897 nativeTaggedField::MinFinalCltvExpiry (mut a, ) => {
898 TaggedField::MinFinalCltvExpiry (
899 crate::lightning_invoice::MinFinalCltvExpiry { inner: Box::into_raw(Box::new(a)), is_owned: true },
902 nativeTaggedField::Fallback (mut a, ) => {
903 TaggedField::Fallback (
904 crate::lightning_invoice::Fallback::native_into(a),
907 nativeTaggedField::Route (mut a, ) => {
909 crate::lightning_invoice::RouteHint { inner: Box::into_raw(Box::new(a)), is_owned: true },
912 nativeTaggedField::PaymentSecret (mut a, ) => {
913 TaggedField::PaymentSecret (
914 crate::lightning_invoice::PaymentSecret { inner: Box::into_raw(Box::new(a)), is_owned: true },
917 nativeTaggedField::Features (mut a, ) => {
918 TaggedField::Features (
919 crate::lightning::ln::features::InvoiceFeatures { inner: Box::into_raw(Box::new(a)), is_owned: true },
925 /// Frees any resources used by the TaggedField
927 pub extern "C" fn TaggedField_free(this_ptr: TaggedField) { }
928 /// Creates a copy of the TaggedField
930 pub extern "C" fn TaggedField_clone(orig: &TaggedField) -> TaggedField {
934 use lightning_invoice::Sha256 as nativeSha256Import;
935 type nativeSha256 = nativeSha256Import;
941 /// A pointer to the opaque Rust object.
943 /// Nearly everywhere, inner must be non-null, however in places where
944 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
945 pub inner: *mut nativeSha256,
946 /// Indicates that this is the only struct which contains the same pointer.
948 /// Rust functions which take ownership of an object provided via an argument require
949 /// this to be true and invalidate the object pointed to by inner.
953 impl Drop for Sha256 {
955 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
956 let _ = unsafe { Box::from_raw(self.inner) };
960 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
962 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
964 /// Used only if an object of this type is returned as a trait impl by a method
965 extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
966 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeSha256); }
969 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
971 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
972 assert!(self.is_owned);
973 let ret = self.inner;
974 self.inner = std::ptr::null_mut();
978 impl Clone for Sha256 {
979 fn clone(&self) -> Self {
981 inner: if <*mut nativeSha256>::is_null(self.inner) { std::ptr::null_mut() } else {
982 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
988 /// Used only if an object of this type is returned as a trait impl by a method
989 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
990 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
993 /// Creates a copy of the Sha256
994 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
998 use lightning_invoice::Description as nativeDescriptionImport;
999 type nativeDescription = nativeDescriptionImport;
1001 /// Description string
1004 /// The description can be at most 639 __bytes__ long
1007 pub struct Description {
1008 /// A pointer to the opaque Rust object.
1010 /// Nearly everywhere, inner must be non-null, however in places where
1011 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1012 pub inner: *mut nativeDescription,
1013 /// Indicates that this is the only struct which contains the same pointer.
1015 /// Rust functions which take ownership of an object provided via an argument require
1016 /// this to be true and invalidate the object pointed to by inner.
1020 impl Drop for Description {
1021 fn drop(&mut self) {
1022 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
1023 let _ = unsafe { Box::from_raw(self.inner) };
1027 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
1029 pub extern "C" fn Description_free(this_obj: Description) { }
1031 /// Used only if an object of this type is returned as a trait impl by a method
1032 extern "C" fn Description_free_void(this_ptr: *mut c_void) {
1033 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDescription); }
1036 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1038 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
1039 assert!(self.is_owned);
1040 let ret = self.inner;
1041 self.inner = std::ptr::null_mut();
1045 impl Clone for Description {
1046 fn clone(&self) -> Self {
1048 inner: if <*mut nativeDescription>::is_null(self.inner) { std::ptr::null_mut() } else {
1049 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1055 /// Used only if an object of this type is returned as a trait impl by a method
1056 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
1057 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
1060 /// Creates a copy of the Description
1061 pub extern "C" fn Description_clone(orig: &Description) -> Description {
1065 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
1066 type nativePayeePubKey = nativePayeePubKeyImport;
1068 /// Payee public key
1071 pub struct PayeePubKey {
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 nativePayeePubKey,
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 PayeePubKey {
1085 fn drop(&mut self) {
1086 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
1087 let _ = unsafe { Box::from_raw(self.inner) };
1091 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
1093 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
1095 /// Used only if an object of this type is returned as a trait impl by a method
1096 extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
1097 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayeePubKey); }
1100 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1102 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
1103 assert!(self.is_owned);
1104 let ret = self.inner;
1105 self.inner = std::ptr::null_mut();
1109 impl Clone for PayeePubKey {
1110 fn clone(&self) -> Self {
1112 inner: if <*mut nativePayeePubKey>::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 PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
1121 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
1124 /// Creates a copy of the PayeePubKey
1125 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
1129 use lightning_invoice::PaymentSecret as nativePaymentSecretImport;
1130 type nativePaymentSecret = nativePaymentSecretImport;
1132 /// 256-bit payment secret
1135 pub struct PaymentSecret {
1136 /// A pointer to the opaque Rust object.
1138 /// Nearly everywhere, inner must be non-null, however in places where
1139 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1140 pub inner: *mut nativePaymentSecret,
1141 /// Indicates that this is the only struct which contains the same pointer.
1143 /// Rust functions which take ownership of an object provided via an argument require
1144 /// this to be true and invalidate the object pointed to by inner.
1148 impl Drop for PaymentSecret {
1149 fn drop(&mut self) {
1150 if self.is_owned && !<*mut nativePaymentSecret>::is_null(self.inner) {
1151 let _ = unsafe { Box::from_raw(self.inner) };
1155 /// Frees any resources used by the PaymentSecret, if is_owned is set and inner is non-NULL.
1157 pub extern "C" fn PaymentSecret_free(this_obj: PaymentSecret) { }
1159 /// Used only if an object of this type is returned as a trait impl by a method
1160 extern "C" fn PaymentSecret_free_void(this_ptr: *mut c_void) {
1161 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePaymentSecret); }
1164 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1165 impl PaymentSecret {
1166 pub(crate) fn take_inner(mut self) -> *mut nativePaymentSecret {
1167 assert!(self.is_owned);
1168 let ret = self.inner;
1169 self.inner = std::ptr::null_mut();
1173 impl Clone for PaymentSecret {
1174 fn clone(&self) -> Self {
1176 inner: if <*mut nativePaymentSecret>::is_null(self.inner) { std::ptr::null_mut() } else {
1177 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1183 /// Used only if an object of this type is returned as a trait impl by a method
1184 pub(crate) extern "C" fn PaymentSecret_clone_void(this_ptr: *const c_void) -> *mut c_void {
1185 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentSecret)).clone() })) as *mut c_void
1188 /// Creates a copy of the PaymentSecret
1189 pub extern "C" fn PaymentSecret_clone(orig: &PaymentSecret) -> PaymentSecret {
1193 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
1194 type nativeExpiryTime = nativeExpiryTimeImport;
1196 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
1200 /// The number of seconds this expiry time represents has to be in the range
1201 /// `0...(SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME)` to avoid overflows when adding it to a
1205 pub struct ExpiryTime {
1206 /// A pointer to the opaque Rust object.
1208 /// Nearly everywhere, inner must be non-null, however in places where
1209 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1210 pub inner: *mut nativeExpiryTime,
1211 /// Indicates that this is the only struct which contains the same pointer.
1213 /// Rust functions which take ownership of an object provided via an argument require
1214 /// this to be true and invalidate the object pointed to by inner.
1218 impl Drop for ExpiryTime {
1219 fn drop(&mut self) {
1220 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
1221 let _ = unsafe { Box::from_raw(self.inner) };
1225 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
1227 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
1229 /// Used only if an object of this type is returned as a trait impl by a method
1230 extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
1231 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeExpiryTime); }
1234 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1236 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
1237 assert!(self.is_owned);
1238 let ret = self.inner;
1239 self.inner = std::ptr::null_mut();
1243 impl Clone for ExpiryTime {
1244 fn clone(&self) -> Self {
1246 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { std::ptr::null_mut() } else {
1247 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1253 /// Used only if an object of this type is returned as a trait impl by a method
1254 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1255 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1258 /// Creates a copy of the ExpiryTime
1259 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1263 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
1264 type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
1266 /// `min_final_cltv_expiry` to use for the last HTLC in the route
1269 pub struct MinFinalCltvExpiry {
1270 /// A pointer to the opaque Rust object.
1272 /// Nearly everywhere, inner must be non-null, however in places where
1273 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1274 pub inner: *mut nativeMinFinalCltvExpiry,
1275 /// Indicates that this is the only struct which contains the same pointer.
1277 /// Rust functions which take ownership of an object provided via an argument require
1278 /// this to be true and invalidate the object pointed to by inner.
1282 impl Drop for MinFinalCltvExpiry {
1283 fn drop(&mut self) {
1284 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
1285 let _ = unsafe { Box::from_raw(self.inner) };
1289 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
1291 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
1293 /// Used only if an object of this type is returned as a trait impl by a method
1294 extern "C" fn MinFinalCltvExpiry_free_void(this_ptr: *mut c_void) {
1295 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiry); }
1298 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1299 impl MinFinalCltvExpiry {
1300 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiry {
1301 assert!(self.is_owned);
1302 let ret = self.inner;
1303 self.inner = std::ptr::null_mut();
1307 impl Clone for MinFinalCltvExpiry {
1308 fn clone(&self) -> Self {
1310 inner: if <*mut nativeMinFinalCltvExpiry>::is_null(self.inner) { std::ptr::null_mut() } else {
1311 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1317 /// Used only if an object of this type is returned as a trait impl by a method
1318 pub(crate) extern "C" fn MinFinalCltvExpiry_clone_void(this_ptr: *const c_void) -> *mut c_void {
1319 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiry)).clone() })) as *mut c_void
1322 /// Creates a copy of the MinFinalCltvExpiry
1323 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
1326 /// Fallback address in case no LN payment is possible
1332 version: crate::c_types::u5,
1333 program: crate::c_types::derived::CVec_u8Z,
1335 PubKeyHash(crate::c_types::TwentyBytes),
1336 ScriptHash(crate::c_types::TwentyBytes),
1338 use lightning_invoice::Fallback as nativeFallback;
1341 pub(crate) fn to_native(&self) -> nativeFallback {
1343 Fallback::SegWitProgram {ref version, ref program, } => {
1344 let mut version_nonref = (*version).clone();
1345 let mut program_nonref = (*program).clone();
1346 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1347 nativeFallback::SegWitProgram {
1348 version: version_nonref.into(),
1349 program: local_program_nonref,
1352 Fallback::PubKeyHash (ref a, ) => {
1353 let mut a_nonref = (*a).clone();
1354 nativeFallback::PubKeyHash (
1358 Fallback::ScriptHash (ref a, ) => {
1359 let mut a_nonref = (*a).clone();
1360 nativeFallback::ScriptHash (
1367 pub(crate) fn into_native(self) -> nativeFallback {
1369 Fallback::SegWitProgram {mut version, mut program, } => {
1370 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1371 nativeFallback::SegWitProgram {
1372 version: version.into(),
1373 program: local_program,
1376 Fallback::PubKeyHash (mut a, ) => {
1377 nativeFallback::PubKeyHash (
1381 Fallback::ScriptHash (mut a, ) => {
1382 nativeFallback::ScriptHash (
1389 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1391 nativeFallback::SegWitProgram {ref version, ref program, } => {
1392 let mut version_nonref = (*version).clone();
1393 let mut program_nonref = (*program).clone();
1394 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1395 Fallback::SegWitProgram {
1396 version: version_nonref.into(),
1397 program: local_program_nonref.into(),
1400 nativeFallback::PubKeyHash (ref a, ) => {
1401 let mut a_nonref = (*a).clone();
1402 Fallback::PubKeyHash (
1403 crate::c_types::TwentyBytes { data: a_nonref },
1406 nativeFallback::ScriptHash (ref a, ) => {
1407 let mut a_nonref = (*a).clone();
1408 Fallback::ScriptHash (
1409 crate::c_types::TwentyBytes { data: a_nonref },
1415 pub(crate) fn native_into(native: nativeFallback) -> Self {
1417 nativeFallback::SegWitProgram {mut version, mut program, } => {
1418 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1419 Fallback::SegWitProgram {
1420 version: version.into(),
1421 program: local_program.into(),
1424 nativeFallback::PubKeyHash (mut a, ) => {
1425 Fallback::PubKeyHash (
1426 crate::c_types::TwentyBytes { data: a },
1429 nativeFallback::ScriptHash (mut a, ) => {
1430 Fallback::ScriptHash (
1431 crate::c_types::TwentyBytes { data: a },
1437 /// Frees any resources used by the Fallback
1439 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1440 /// Creates a copy of the Fallback
1442 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1446 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1447 type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1449 /// Recoverable signature
1452 pub struct InvoiceSignature {
1453 /// A pointer to the opaque Rust object.
1455 /// Nearly everywhere, inner must be non-null, however in places where
1456 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1457 pub inner: *mut nativeInvoiceSignature,
1458 /// Indicates that this is the only struct which contains the same pointer.
1460 /// Rust functions which take ownership of an object provided via an argument require
1461 /// this to be true and invalidate the object pointed to by inner.
1465 impl Drop for InvoiceSignature {
1466 fn drop(&mut self) {
1467 if self.is_owned && !<*mut nativeInvoiceSignature>::is_null(self.inner) {
1468 let _ = unsafe { Box::from_raw(self.inner) };
1472 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1474 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1476 /// Used only if an object of this type is returned as a trait impl by a method
1477 extern "C" fn InvoiceSignature_free_void(this_ptr: *mut c_void) {
1478 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceSignature); }
1481 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1482 impl InvoiceSignature {
1483 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceSignature {
1484 assert!(self.is_owned);
1485 let ret = self.inner;
1486 self.inner = std::ptr::null_mut();
1490 impl Clone for InvoiceSignature {
1491 fn clone(&self) -> Self {
1493 inner: if <*mut nativeInvoiceSignature>::is_null(self.inner) { std::ptr::null_mut() } else {
1494 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1500 /// Used only if an object of this type is returned as a trait impl by a method
1501 pub(crate) extern "C" fn InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
1502 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceSignature)).clone() })) as *mut c_void
1505 /// Creates a copy of the InvoiceSignature
1506 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
1510 use lightning_invoice::RouteHint as nativeRouteHintImport;
1511 type nativeRouteHint = nativeRouteHintImport;
1513 /// Private routing information
1516 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
1520 pub struct RouteHint {
1521 /// A pointer to the opaque Rust object.
1523 /// Nearly everywhere, inner must be non-null, however in places where
1524 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1525 pub inner: *mut nativeRouteHint,
1526 /// Indicates that this is the only struct which contains the same pointer.
1528 /// Rust functions which take ownership of an object provided via an argument require
1529 /// this to be true and invalidate the object pointed to by inner.
1533 impl Drop for RouteHint {
1534 fn drop(&mut self) {
1535 if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) {
1536 let _ = unsafe { Box::from_raw(self.inner) };
1540 /// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
1542 pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
1544 /// Used only if an object of this type is returned as a trait impl by a method
1545 extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) {
1546 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHint); }
1549 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1551 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint {
1552 assert!(self.is_owned);
1553 let ret = self.inner;
1554 self.inner = std::ptr::null_mut();
1558 impl Clone for RouteHint {
1559 fn clone(&self) -> Self {
1561 inner: if <*mut nativeRouteHint>::is_null(self.inner) { std::ptr::null_mut() } else {
1562 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1568 /// Used only if an object of this type is returned as a trait impl by a method
1569 pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void {
1570 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void
1573 /// Creates a copy of the RouteHint
1574 pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
1577 /// Disassembles the `SignedRawInvoice` into its three parts:
1579 /// 2. hash of the raw invoice
1583 pub extern "C" fn SignedRawInvoice_into_parts(mut this_arg: SignedRawInvoice) -> crate::c_types::derived::C3Tuple_RawInvoice_u832InvoiceSignatureZ {
1584 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
1585 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();
1589 /// The `RawInvoice` which was signed.
1592 pub extern "C" fn SignedRawInvoice_raw_invoice(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::RawInvoice {
1593 let mut ret = unsafe { &*this_arg.inner }.raw_invoice();
1594 crate::lightning_invoice::RawInvoice { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1597 /// The hash of the `RawInvoice` that was signed.
1600 pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [u8; 32] {
1601 let mut ret = unsafe { &*this_arg.inner }.hash();
1605 /// InvoiceSignature for the invoice.
1608 pub extern "C" fn SignedRawInvoice_signature(this_arg: &SignedRawInvoice) -> crate::lightning_invoice::InvoiceSignature {
1609 let mut ret = unsafe { &*this_arg.inner }.signature();
1610 crate::lightning_invoice::InvoiceSignature { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1613 /// Recovers the public key used for signing the invoice from the recoverable signature.
1616 pub extern "C" fn SignedRawInvoice_recover_payee_pub_key(this_arg: &SignedRawInvoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
1617 let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key();
1618 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() };
1622 /// Checks if the signature is valid for the included payee public key or if none exists if it's
1623 /// valid for the recovered signature (which should always be true?).
1626 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &SignedRawInvoice) -> bool {
1627 let mut ret = unsafe { &*this_arg.inner }.check_signature();
1631 /// Calculate the hash of the encoded `RawInvoice`
1634 pub extern "C" fn RawInvoice_hash(this_arg: &RawInvoice) -> crate::c_types::ThirtyTwoBytes {
1635 let mut ret = unsafe { &*this_arg.inner }.hash();
1636 crate::c_types::ThirtyTwoBytes { data: ret }
1641 pub extern "C" fn RawInvoice_payment_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1642 let mut ret = unsafe { &*this_arg.inner }.payment_hash();
1643 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 };
1649 pub extern "C" fn RawInvoice_description(this_arg: &RawInvoice) -> crate::lightning_invoice::Description {
1650 let mut ret = unsafe { &*this_arg.inner }.description();
1651 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 };
1657 pub extern "C" fn RawInvoice_payee_pub_key(this_arg: &RawInvoice) -> crate::lightning_invoice::PayeePubKey {
1658 let mut ret = unsafe { &*this_arg.inner }.payee_pub_key();
1659 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 };
1665 pub extern "C" fn RawInvoice_description_hash(this_arg: &RawInvoice) -> crate::lightning_invoice::Sha256 {
1666 let mut ret = unsafe { &*this_arg.inner }.description_hash();
1667 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 };
1673 pub extern "C" fn RawInvoice_expiry_time(this_arg: &RawInvoice) -> crate::lightning_invoice::ExpiryTime {
1674 let mut ret = unsafe { &*this_arg.inner }.expiry_time();
1675 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 };
1681 pub extern "C" fn RawInvoice_min_final_cltv_expiry(this_arg: &RawInvoice) -> crate::lightning_invoice::MinFinalCltvExpiry {
1682 let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry();
1683 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 };
1689 pub extern "C" fn RawInvoice_payment_secret(this_arg: &RawInvoice) -> crate::lightning_invoice::PaymentSecret {
1690 let mut ret = unsafe { &*this_arg.inner }.payment_secret();
1691 let mut local_ret = crate::lightning_invoice::PaymentSecret { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1697 pub extern "C" fn RawInvoice_features(this_arg: &RawInvoice) -> crate::lightning::ln::features::InvoiceFeatures {
1698 let mut ret = unsafe { &*this_arg.inner }.features();
1699 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 };
1705 pub extern "C" fn RawInvoice_routes(this_arg: &RawInvoice) -> crate::c_types::derived::CVec_RouteHintZ {
1706 let mut ret = unsafe { &*this_arg.inner }.routes();
1707 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 } }); };
1713 pub extern "C" fn RawInvoice_amount_pico_btc(this_arg: &RawInvoice) -> crate::c_types::derived::COption_u64Z {
1714 let mut ret = unsafe { &*this_arg.inner }.amount_pico_btc();
1715 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()) } };
1721 pub extern "C" fn RawInvoice_currency(this_arg: &RawInvoice) -> crate::lightning_invoice::Currency {
1722 let mut ret = unsafe { &*this_arg.inner }.currency();
1723 crate::lightning_invoice::Currency::native_into(ret)
1726 /// Create a new `PositiveTimestamp` from a unix timestamp in the Range
1727 /// `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1728 /// `CreationError::TimestampOutOfBounds`.
1731 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1732 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
1733 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() };
1737 /// Create a new `PositiveTimestamp` from a `SystemTime` with a corresponding unix timestamp in
1738 /// the Range `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
1739 /// `CreationError::TimestampOutOfBounds`.
1742 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
1743 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
1744 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() };
1748 /// Returns the UNIX timestamp representing the stored time
1751 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 {
1752 let mut ret = unsafe { &*this_arg.inner }.as_unix_timestamp();
1756 /// Returns a reference to the internal `SystemTime` time representation
1759 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &PositiveTimestamp) -> u64 {
1760 let mut ret = unsafe { &*this_arg.inner }.as_time();
1761 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1764 /// Transform the `Invoice` into it's unchecked version
1767 pub extern "C" fn Invoice_into_signed_raw(mut this_arg: Invoice) -> crate::lightning_invoice::SignedRawInvoice {
1768 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
1769 crate::lightning_invoice::SignedRawInvoice { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1772 /// Check that the invoice is signed correctly and that key recovery works
1775 pub extern "C" fn Invoice_check_signature(this_arg: &Invoice) -> crate::c_types::derived::CResult_NoneSemanticErrorZ {
1776 let mut ret = unsafe { &*this_arg.inner }.check_signature();
1777 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::SemanticError::native_into(e) }).into() };
1781 /// Constructs an `Invoice` from a `SignedInvoice` by checking all its invariants.
1783 /// use lightning_invoice::*;
1785 /// let invoice = \"lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdp\\
1786 /// \tl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d7\\
1787 /// \t3gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ec\\
1788 /// \tky03ylcqca784w\";
1790 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
1792 /// assert!(Invoice::from_signed(signed).is_ok());
1796 pub extern "C" fn Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawInvoice) -> crate::c_types::derived::CResult_InvoiceSemanticErrorZ {
1797 let mut ret = lightning_invoice::Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
1798 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() };
1802 /// Returns the `Invoice`'s timestamp (should equal it's creation time)
1805 pub extern "C" fn Invoice_timestamp(this_arg: &Invoice) -> u64 {
1806 let mut ret = unsafe { &*this_arg.inner }.timestamp();
1807 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
1810 /// Returns the hash to which we will receive the preimage on completion of the payment
1813 pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] {
1814 let mut ret = unsafe { &*this_arg.inner }.payment_hash();
1818 /// Get the payee's public key if one was included in the invoice
1821 pub extern "C" fn Invoice_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1822 let mut ret = unsafe { &*this_arg.inner }.payee_pub_key();
1823 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
1827 /// Get the payment secret if one was included in the invoice
1830 pub extern "C" fn Invoice_payment_secret(this_arg: &Invoice) -> crate::lightning_invoice::PaymentSecret {
1831 let mut ret = unsafe { &*this_arg.inner }.payment_secret();
1832 let mut local_ret = crate::lightning_invoice::PaymentSecret { inner: unsafe { (if ret.is_none() { std::ptr::null() } else { { (ret.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1836 /// Get the invoice features if they were included in the invoice
1839 pub extern "C" fn Invoice_features(this_arg: &Invoice) -> crate::lightning::ln::features::InvoiceFeatures {
1840 let mut ret = unsafe { &*this_arg.inner }.features();
1841 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 };
1845 /// Recover the payee's public key (only to be used if none was included in the invoice)
1848 pub extern "C" fn Invoice_recover_payee_pub_key(this_arg: &Invoice) -> crate::c_types::PublicKey {
1849 let mut ret = unsafe { &*this_arg.inner }.recover_payee_pub_key();
1850 crate::c_types::PublicKey::from_rust(&ret)
1853 /// Returns the invoice's expiry time if present
1856 pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 {
1857 let mut ret = unsafe { &*this_arg.inner }.expiry_time();
1861 /// Returns the invoice's `min_cltv_expiry` time if present
1864 pub extern "C" fn Invoice_min_final_cltv_expiry(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z {
1865 let mut ret = unsafe { &*this_arg.inner }.min_final_cltv_expiry();
1866 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()) } };
1870 /// Returns a list of all routes included in the invoice
1873 pub extern "C" fn Invoice_routes(this_arg: &Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
1874 let mut ret = unsafe { &*this_arg.inner }.routes();
1875 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 } }); };
1879 /// Returns the currency for which the invoice was issued
1882 pub extern "C" fn Invoice_currency(this_arg: &Invoice) -> crate::lightning_invoice::Currency {
1883 let mut ret = unsafe { &*this_arg.inner }.currency();
1884 crate::lightning_invoice::Currency::native_into(ret)
1887 /// Returns the amount if specified in the invoice as pico <currency>.
1890 pub extern "C" fn Invoice_amount_pico_btc(this_arg: &Invoice) -> crate::c_types::derived::COption_u64Z {
1891 let mut ret = unsafe { &*this_arg.inner }.amount_pico_btc();
1892 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()) } };
1896 /// Numeric representation of the field's tag
1899 pub extern "C" fn TaggedField_tag(this_arg: &TaggedField) -> crate::c_types::u5 {
1900 let mut ret = this_arg.to_native().tag();
1904 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
1905 /// returns `CreationError::DescriptionTooLong` otherwise
1907 /// Please note that single characters may use more than one byte due to UTF8 encoding.
1910 pub extern "C" fn Description_new(mut description: crate::c_types::derived::CVec_u8Z) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
1911 let mut ret = lightning_invoice::Description::new(String::from_utf8(description.into_rust()).unwrap());
1912 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() };
1916 /// Returns the underlying description `String`
1919 pub extern "C" fn Description_into_inner(mut this_arg: Description) -> crate::c_types::derived::CVec_u8Z {
1920 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1921 ret.into_bytes().into()
1924 /// Construct an `ExpiryTime` from seconds. If there exists a `PositiveTimestamp` which would
1925 /// overflow on adding the `EpiryTime` to it then this function will return a
1926 /// `CreationError::ExpiryTimeOutOfBounds`.
1929 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1930 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
1931 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() };
1935 /// Construct an `ExpiryTime` from a `Duration`. If there exists a `PositiveTimestamp` which
1936 /// would overflow on adding the `EpiryTime` to it then this function will return a
1937 /// `CreationError::ExpiryTimeOutOfBounds`.
1940 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::c_types::derived::CResult_ExpiryTimeCreationErrorZ {
1941 let mut ret = lightning_invoice::ExpiryTime::from_duration(std::time::Duration::from_secs(duration));
1942 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() };
1946 /// Returns the expiry time in seconds
1949 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 {
1950 let mut ret = unsafe { &*this_arg.inner }.as_seconds();
1954 /// Returns a reference to the underlying `Duration` (=expiry time)
1957 pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 {
1958 let mut ret = unsafe { &*this_arg.inner }.as_duration();
1962 /// Create a new (partial) route from a list of hops
1965 pub extern "C" fn RouteHint_new(mut hops: crate::c_types::derived::CVec_RouteHintHopZ) -> crate::c_types::derived::CResult_RouteHintCreationErrorZ {
1966 let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1967 let mut ret = lightning_invoice::RouteHint::new(local_hops);
1968 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() };
1972 /// Returrn the underlying vector of hops
1975 pub extern "C" fn RouteHint_into_inner(mut this_arg: RouteHint) -> crate::c_types::derived::CVec_RouteHintHopZ {
1976 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
1977 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 } }); };
1981 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
1985 pub enum CreationError {
1986 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
1988 /// The specified route has too many hops and can't be encoded
1990 /// The unix timestamp of the supplied date is <0 or can't be represented as `SystemTime`
1991 TimestampOutOfBounds,
1992 /// The supplied expiry time could cause an overflow if added to a `PositiveTimestamp`
1993 ExpiryTimeOutOfBounds,
1995 use lightning_invoice::CreationError as nativeCreationError;
1996 impl CreationError {
1998 pub(crate) fn to_native(&self) -> nativeCreationError {
2000 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2001 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2002 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2003 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
2007 pub(crate) fn into_native(self) -> nativeCreationError {
2009 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2010 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2011 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2012 CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
2016 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
2018 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2019 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2020 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2021 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
2025 pub(crate) fn native_into(native: nativeCreationError) -> Self {
2027 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2028 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2029 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2030 nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
2034 /// Creates a copy of the CreationError
2036 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
2040 /// Get the string representation of a CreationError object
2041 pub extern "C" fn CreationError_to_str(o: &lightning_invoice::CreationError) -> Str {
2042 format!("{}", o).into()
2044 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
2045 /// requirements sections in BOLT #11
2049 pub enum SemanticError {
2050 /// The invoice is missing the mandatory payment hash
2052 /// The invoice has multiple payment hashes which isn't allowed
2053 MultiplePaymentHashes,
2054 /// No description or description hash are part of the invoice
2056 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
2057 MultipleDescriptions,
2058 /// The recovery id doesn't fit the signature/pub key
2060 /// The invoice's signature is invalid
2063 use lightning_invoice::SemanticError as nativeSemanticError;
2064 impl SemanticError {
2066 pub(crate) fn to_native(&self) -> nativeSemanticError {
2068 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2069 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2070 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2071 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2072 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2073 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2077 pub(crate) fn into_native(self) -> nativeSemanticError {
2079 SemanticError::NoPaymentHash => nativeSemanticError::NoPaymentHash,
2080 SemanticError::MultiplePaymentHashes => nativeSemanticError::MultiplePaymentHashes,
2081 SemanticError::NoDescription => nativeSemanticError::NoDescription,
2082 SemanticError::MultipleDescriptions => nativeSemanticError::MultipleDescriptions,
2083 SemanticError::InvalidRecoveryId => nativeSemanticError::InvalidRecoveryId,
2084 SemanticError::InvalidSignature => nativeSemanticError::InvalidSignature,
2088 pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
2090 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2091 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2092 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2093 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2094 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2095 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2099 pub(crate) fn native_into(native: nativeSemanticError) -> Self {
2101 nativeSemanticError::NoPaymentHash => SemanticError::NoPaymentHash,
2102 nativeSemanticError::MultiplePaymentHashes => SemanticError::MultiplePaymentHashes,
2103 nativeSemanticError::NoDescription => SemanticError::NoDescription,
2104 nativeSemanticError::MultipleDescriptions => SemanticError::MultipleDescriptions,
2105 nativeSemanticError::InvalidRecoveryId => SemanticError::InvalidRecoveryId,
2106 nativeSemanticError::InvalidSignature => SemanticError::InvalidSignature,
2110 /// Creates a copy of the SemanticError
2112 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
2116 /// Get the string representation of a SemanticError object
2117 pub extern "C" fn SemanticError_to_str(o: &lightning_invoice::SemanticError) -> Str {
2118 format!("{}", o).into()