Merge pull request #19 from TheBlueMatt/2021-04-invoice-incl
[ldk-c-bindings] / lightning-c-bindings / src / lightning_invoice / mod.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
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.
8
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:
13 //!
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
17
18 use std::str::FromStr;
19 use std::ffi::c_void;
20 use bitcoin::hashes::Hash;
21 use crate::c_types::*;
22
23 pub mod utils;
24 pub mod constants;
25 mod de {
26
27 use std::str::FromStr;
28 use std::ffi::c_void;
29 use bitcoin::hashes::Hash;
30 use crate::c_types::*;
31
32 mod hrp_sm {
33
34 use std::str::FromStr;
35 use std::ffi::c_void;
36 use bitcoin::hashes::Hash;
37 use crate::c_types::*;
38
39 }
40 #[no_mangle]
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()) {
44                 Ok(r) => {
45                         crate::c_types::CResultTempl::ok(
46                                 crate::lightning_invoice::SiPrefix::native_into(r)
47                         )
48                 },
49                 Err(e) => crate::c_types::CResultTempl::err(()),
50         }.into()
51 }
52 #[no_mangle]
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()) {
56                 Ok(r) => {
57                         crate::c_types::CResultTempl::ok(
58                                 crate::lightning_invoice::Invoice { inner: Box::into_raw(Box::new(r)), is_owned: true }
59                         )
60                 },
61                 Err(e) => crate::c_types::CResultTempl::err(()),
62         }.into()
63 }
64 #[no_mangle]
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()) {
68                 Ok(r) => {
69                         crate::c_types::CResultTempl::ok(
70                                 crate::lightning_invoice::SignedRawInvoice { inner: Box::into_raw(Box::new(r)), is_owned: true }
71                         )
72                 },
73                 Err(e) => crate::c_types::CResultTempl::err(()),
74         }.into()
75 }
76 }
77 mod ser {
78
79 use std::str::FromStr;
80 use std::ffi::c_void;
81 use bitcoin::hashes::Hash;
82 use crate::c_types::*;
83
84 #[no_mangle]
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()
88 }
89 #[no_mangle]
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()
93 }
94 #[no_mangle]
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()
98 }
99 #[no_mangle]
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()
103 }
104 }
105 mod tb {
106
107 use std::str::FromStr;
108 use std::ffi::c_void;
109 use bitcoin::hashes::Hash;
110 use crate::c_types::*;
111
112 }
113 /// **Call this function on startup to ensure that all assumptions about the platform are valid.**
114 ///
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.
119 ///
120 /// If this function fails this is considered a bug. Please open an issue describing your
121 /// platform and stating your current system time.
122 ///
123 /// # Panics
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.
126 #[no_mangle]
127 pub extern "C" fn check_platform() {
128         lightning_invoice::check_platform()
129 }
130
131
132 use lightning_invoice::Invoice as nativeInvoiceImport;
133 type nativeInvoice = nativeInvoiceImport;
134
135 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
136 ///
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)`
141 #[must_use]
142 #[repr(C)]
143 pub struct Invoice {
144         /// A pointer to the opaque Rust object.
145
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.
150
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.
153         pub is_owned: bool,
154 }
155
156 impl Drop for Invoice {
157         fn drop(&mut self) {
158                 if self.is_owned && !<*mut nativeInvoice>::is_null(self.inner) {
159                         let _ = unsafe { Box::from_raw(self.inner) };
160                 }
161         }
162 }
163 /// Frees any resources used by the Invoice, if is_owned is set and inner is non-NULL.
164 #[no_mangle]
165 pub extern "C" fn Invoice_free(this_obj: Invoice) { }
166 #[allow(unused)]
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); }
170 }
171 #[allow(unused)]
172 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
173 impl Invoice {
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();
178                 ret
179         }
180 }
181 impl Clone for Invoice {
182         fn clone(&self) -> Self {
183                 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())) },
186                         is_owned: true,
187                 }
188         }
189 }
190 #[allow(unused)]
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
194 }
195 #[no_mangle]
196 /// Creates a copy of the Invoice
197 pub extern "C" fn Invoice_clone(orig: &Invoice) -> Invoice {
198         orig.clone()
199 }
200
201 use lightning_invoice::SignedRawInvoice as nativeSignedRawInvoiceImport;
202 type nativeSignedRawInvoice = nativeSignedRawInvoiceImport;
203
204 /// Represents a signed `RawInvoice` with cached hash. The signature is not checked and may be
205 /// invalid.
206 ///
207 /// # Invariants
208 /// The hash has to be either from the deserialized invoice or from the serialized `raw_invoice`.
209 #[must_use]
210 #[repr(C)]
211 pub struct SignedRawInvoice {
212         /// A pointer to the opaque Rust object.
213
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.
218
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.
221         pub is_owned: bool,
222 }
223
224 impl Drop for SignedRawInvoice {
225         fn drop(&mut self) {
226                 if self.is_owned && !<*mut nativeSignedRawInvoice>::is_null(self.inner) {
227                         let _ = unsafe { Box::from_raw(self.inner) };
228                 }
229         }
230 }
231 /// Frees any resources used by the SignedRawInvoice, if is_owned is set and inner is non-NULL.
232 #[no_mangle]
233 pub extern "C" fn SignedRawInvoice_free(this_obj: SignedRawInvoice) { }
234 #[allow(unused)]
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); }
238 }
239 #[allow(unused)]
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();
246                 ret
247         }
248 }
249 impl Clone for SignedRawInvoice {
250         fn clone(&self) -> Self {
251                 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())) },
254                         is_owned: true,
255                 }
256         }
257 }
258 #[allow(unused)]
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
262 }
263 #[no_mangle]
264 /// Creates a copy of the SignedRawInvoice
265 pub extern "C" fn SignedRawInvoice_clone(orig: &SignedRawInvoice) -> SignedRawInvoice {
266         orig.clone()
267 }
268
269 use lightning_invoice::RawInvoice as nativeRawInvoiceImport;
270 type nativeRawInvoice = nativeRawInvoiceImport;
271
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.
275 ///
276 /// For methods without docs see the corresponding methods in `Invoice`.
277 #[must_use]
278 #[repr(C)]
279 pub struct RawInvoice {
280         /// A pointer to the opaque Rust object.
281
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.
286
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.
289         pub is_owned: bool,
290 }
291
292 impl Drop for RawInvoice {
293         fn drop(&mut self) {
294                 if self.is_owned && !<*mut nativeRawInvoice>::is_null(self.inner) {
295                         let _ = unsafe { Box::from_raw(self.inner) };
296                 }
297         }
298 }
299 /// Frees any resources used by the RawInvoice, if is_owned is set and inner is non-NULL.
300 #[no_mangle]
301 pub extern "C" fn RawInvoice_free(this_obj: RawInvoice) { }
302 #[allow(unused)]
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); }
306 }
307 #[allow(unused)]
308 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
309 impl RawInvoice {
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();
314                 ret
315         }
316 }
317 /// data part
318 #[no_mangle]
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 }
322 }
323 /// data part
324 #[no_mangle]
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()) };
327 }
328 impl Clone for RawInvoice {
329         fn clone(&self) -> Self {
330                 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())) },
333                         is_owned: true,
334                 }
335         }
336 }
337 #[allow(unused)]
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
341 }
342 #[no_mangle]
343 /// Creates a copy of the RawInvoice
344 pub extern "C" fn RawInvoice_clone(orig: &RawInvoice) -> RawInvoice {
345         orig.clone()
346 }
347
348 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
349 type nativeRawDataPart = nativeRawDataPartImport;
350
351 /// Data of the `RawInvoice` that is encoded in the data part
352 #[must_use]
353 #[repr(C)]
354 pub struct RawDataPart {
355         /// A pointer to the opaque Rust object.
356
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.
361
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.
364         pub is_owned: bool,
365 }
366
367 impl Drop for RawDataPart {
368         fn drop(&mut self) {
369                 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
370                         let _ = unsafe { Box::from_raw(self.inner) };
371                 }
372         }
373 }
374 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
375 #[no_mangle]
376 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
377 #[allow(unused)]
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); }
381 }
382 #[allow(unused)]
383 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
384 impl RawDataPart {
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();
389                 ret
390         }
391 }
392 /// generation time of the invoice
393 #[no_mangle]
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 }
397 }
398 /// generation time of the invoice
399 #[no_mangle]
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()) };
402 }
403 impl Clone for RawDataPart {
404         fn clone(&self) -> Self {
405                 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())) },
408                         is_owned: true,
409                 }
410         }
411 }
412 #[allow(unused)]
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
416 }
417 #[no_mangle]
418 /// Creates a copy of the RawDataPart
419 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
420         orig.clone()
421 }
422
423 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
424 type nativePositiveTimestamp = nativePositiveTimestampImport;
425
426 /// A timestamp that refers to a date after 1 January 1970 which means its representation as UNIX
427 /// timestamp is positive.
428 ///
429 /// # Invariants
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.
432 #[must_use]
433 #[repr(C)]
434 pub struct PositiveTimestamp {
435         /// A pointer to the opaque Rust object.
436
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.
441
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.
444         pub is_owned: bool,
445 }
446
447 impl Drop for PositiveTimestamp {
448         fn drop(&mut self) {
449                 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
450                         let _ = unsafe { Box::from_raw(self.inner) };
451                 }
452         }
453 }
454 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
455 #[no_mangle]
456 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
457 #[allow(unused)]
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); }
461 }
462 #[allow(unused)]
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();
469                 ret
470         }
471 }
472 impl Clone for PositiveTimestamp {
473         fn clone(&self) -> Self {
474                 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())) },
477                         is_owned: true,
478                 }
479         }
480 }
481 #[allow(unused)]
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
485 }
486 #[no_mangle]
487 /// Creates a copy of the PositiveTimestamp
488 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
489         orig.clone()
490 }
491 /// SI prefixes for the human readable part
492 #[must_use]
493 #[derive(Clone)]
494 #[repr(C)]
495 pub enum SiPrefix {
496         /// 10^-3
497         Milli,
498         /// 10^-6
499         Micro,
500         /// 10^-9
501         Nano,
502         /// 10^-12
503         Pico,
504 }
505 use lightning_invoice::SiPrefix as nativeSiPrefix;
506 impl SiPrefix {
507         #[allow(unused)]
508         pub(crate) fn to_native(&self) -> nativeSiPrefix {
509                 match self {
510                         SiPrefix::Milli => nativeSiPrefix::Milli,
511                         SiPrefix::Micro => nativeSiPrefix::Micro,
512                         SiPrefix::Nano => nativeSiPrefix::Nano,
513                         SiPrefix::Pico => nativeSiPrefix::Pico,
514                 }
515         }
516         #[allow(unused)]
517         pub(crate) fn into_native(self) -> nativeSiPrefix {
518                 match self {
519                         SiPrefix::Milli => nativeSiPrefix::Milli,
520                         SiPrefix::Micro => nativeSiPrefix::Micro,
521                         SiPrefix::Nano => nativeSiPrefix::Nano,
522                         SiPrefix::Pico => nativeSiPrefix::Pico,
523                 }
524         }
525         #[allow(unused)]
526         pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
527                 match native {
528                         nativeSiPrefix::Milli => SiPrefix::Milli,
529                         nativeSiPrefix::Micro => SiPrefix::Micro,
530                         nativeSiPrefix::Nano => SiPrefix::Nano,
531                         nativeSiPrefix::Pico => SiPrefix::Pico,
532                 }
533         }
534         #[allow(unused)]
535         pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
536                 match native {
537                         nativeSiPrefix::Milli => SiPrefix::Milli,
538                         nativeSiPrefix::Micro => SiPrefix::Micro,
539                         nativeSiPrefix::Nano => SiPrefix::Nano,
540                         nativeSiPrefix::Pico => SiPrefix::Pico,
541                 }
542         }
543 }
544 /// Creates a copy of the SiPrefix
545 #[no_mangle]
546 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
547         orig.clone()
548 }
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
551 #[must_use]
552 #[no_mangle]
553 pub extern "C" fn SiPrefix_multiplier(this_arg: &SiPrefix) -> u64 {
554         let mut ret = this_arg.to_native().multiplier();
555         ret
556 }
557
558 /// Enum representing the crypto currencies (or networks) supported by this library
559 #[must_use]
560 #[derive(Clone)]
561 #[repr(C)]
562 pub enum Currency {
563         /// Bitcoin mainnet
564         Bitcoin,
565         /// Bitcoin testnet
566         BitcoinTestnet,
567         /// Bitcoin regtest
568         Regtest,
569         /// Bitcoin simnet/signet
570         Simnet,
571 }
572 use lightning_invoice::Currency as nativeCurrency;
573 impl Currency {
574         #[allow(unused)]
575         pub(crate) fn to_native(&self) -> nativeCurrency {
576                 match self {
577                         Currency::Bitcoin => nativeCurrency::Bitcoin,
578                         Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
579                         Currency::Regtest => nativeCurrency::Regtest,
580                         Currency::Simnet => nativeCurrency::Simnet,
581                 }
582         }
583         #[allow(unused)]
584         pub(crate) fn into_native(self) -> nativeCurrency {
585                 match self {
586                         Currency::Bitcoin => nativeCurrency::Bitcoin,
587                         Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
588                         Currency::Regtest => nativeCurrency::Regtest,
589                         Currency::Simnet => nativeCurrency::Simnet,
590                 }
591         }
592         #[allow(unused)]
593         pub(crate) fn from_native(native: &nativeCurrency) -> Self {
594                 match native {
595                         nativeCurrency::Bitcoin => Currency::Bitcoin,
596                         nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
597                         nativeCurrency::Regtest => Currency::Regtest,
598                         nativeCurrency::Simnet => Currency::Simnet,
599                 }
600         }
601         #[allow(unused)]
602         pub(crate) fn native_into(native: nativeCurrency) -> Self {
603                 match native {
604                         nativeCurrency::Bitcoin => Currency::Bitcoin,
605                         nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
606                         nativeCurrency::Regtest => Currency::Regtest,
607                         nativeCurrency::Simnet => Currency::Simnet,
608                 }
609         }
610 }
611 /// Creates a copy of the Currency
612 #[no_mangle]
613 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
614         orig.clone()
615 }
616
617 use lightning_invoice::Sha256 as nativeSha256Import;
618 type nativeSha256 = nativeSha256Import;
619
620 /// SHA-256 hash
621 #[must_use]
622 #[repr(C)]
623 pub struct Sha256 {
624         /// A pointer to the opaque Rust object.
625
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.
630
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.
633         pub is_owned: bool,
634 }
635
636 impl Drop for Sha256 {
637         fn drop(&mut self) {
638                 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
639                         let _ = unsafe { Box::from_raw(self.inner) };
640                 }
641         }
642 }
643 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
644 #[no_mangle]
645 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
646 #[allow(unused)]
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); }
650 }
651 #[allow(unused)]
652 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
653 impl Sha256 {
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();
658                 ret
659         }
660 }
661 impl Clone for Sha256 {
662         fn clone(&self) -> Self {
663                 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())) },
666                         is_owned: true,
667                 }
668         }
669 }
670 #[allow(unused)]
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
674 }
675 #[no_mangle]
676 /// Creates a copy of the Sha256
677 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
678         orig.clone()
679 }
680
681 use lightning_invoice::Description as nativeDescriptionImport;
682 type nativeDescription = nativeDescriptionImport;
683
684 /// Description string
685 ///
686 /// # Invariants
687 /// The description can be at most 639 __bytes__ long
688 #[must_use]
689 #[repr(C)]
690 pub struct Description {
691         /// A pointer to the opaque Rust object.
692
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.
697
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.
700         pub is_owned: bool,
701 }
702
703 impl Drop for Description {
704         fn drop(&mut self) {
705                 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
706                         let _ = unsafe { Box::from_raw(self.inner) };
707                 }
708         }
709 }
710 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
711 #[no_mangle]
712 pub extern "C" fn Description_free(this_obj: Description) { }
713 #[allow(unused)]
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); }
717 }
718 #[allow(unused)]
719 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
720 impl Description {
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();
725                 ret
726         }
727 }
728 impl Clone for Description {
729         fn clone(&self) -> Self {
730                 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())) },
733                         is_owned: true,
734                 }
735         }
736 }
737 #[allow(unused)]
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
741 }
742 #[no_mangle]
743 /// Creates a copy of the Description
744 pub extern "C" fn Description_clone(orig: &Description) -> Description {
745         orig.clone()
746 }
747
748 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
749 type nativePayeePubKey = nativePayeePubKeyImport;
750
751 /// Payee public key
752 #[must_use]
753 #[repr(C)]
754 pub struct PayeePubKey {
755         /// A pointer to the opaque Rust object.
756
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.
761
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.
764         pub is_owned: bool,
765 }
766
767 impl Drop for PayeePubKey {
768         fn drop(&mut self) {
769                 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
770                         let _ = unsafe { Box::from_raw(self.inner) };
771                 }
772         }
773 }
774 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
775 #[no_mangle]
776 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
777 #[allow(unused)]
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); }
781 }
782 #[allow(unused)]
783 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
784 impl PayeePubKey {
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();
789                 ret
790         }
791 }
792 impl Clone for PayeePubKey {
793         fn clone(&self) -> Self {
794                 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())) },
797                         is_owned: true,
798                 }
799         }
800 }
801 #[allow(unused)]
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
805 }
806 #[no_mangle]
807 /// Creates a copy of the PayeePubKey
808 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
809         orig.clone()
810 }
811
812 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
813 type nativeExpiryTime = nativeExpiryTimeImport;
814
815 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
816 /// expires
817 ///
818 /// # Invariants
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
821 /// timestamp
822 #[must_use]
823 #[repr(C)]
824 pub struct ExpiryTime {
825         /// A pointer to the opaque Rust object.
826
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.
831
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.
834         pub is_owned: bool,
835 }
836
837 impl Drop for ExpiryTime {
838         fn drop(&mut self) {
839                 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
840                         let _ = unsafe { Box::from_raw(self.inner) };
841                 }
842         }
843 }
844 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
845 #[no_mangle]
846 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
847 #[allow(unused)]
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); }
851 }
852 #[allow(unused)]
853 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
854 impl ExpiryTime {
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();
859                 ret
860         }
861 }
862 impl Clone for ExpiryTime {
863         fn clone(&self) -> Self {
864                 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())) },
867                         is_owned: true,
868                 }
869         }
870 }
871 #[allow(unused)]
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
875 }
876 #[no_mangle]
877 /// Creates a copy of the ExpiryTime
878 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
879         orig.clone()
880 }
881
882 use lightning_invoice::MinFinalCltvExpiry as nativeMinFinalCltvExpiryImport;
883 type nativeMinFinalCltvExpiry = nativeMinFinalCltvExpiryImport;
884
885 /// `min_final_cltv_expiry` to use for the last HTLC in the route
886 #[must_use]
887 #[repr(C)]
888 pub struct MinFinalCltvExpiry {
889         /// A pointer to the opaque Rust object.
890
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.
895
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.
898         pub is_owned: bool,
899 }
900
901 impl Drop for MinFinalCltvExpiry {
902         fn drop(&mut self) {
903                 if self.is_owned && !<*mut nativeMinFinalCltvExpiry>::is_null(self.inner) {
904                         let _ = unsafe { Box::from_raw(self.inner) };
905                 }
906         }
907 }
908 /// Frees any resources used by the MinFinalCltvExpiry, if is_owned is set and inner is non-NULL.
909 #[no_mangle]
910 pub extern "C" fn MinFinalCltvExpiry_free(this_obj: MinFinalCltvExpiry) { }
911 #[allow(unused)]
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); }
915 }
916 #[allow(unused)]
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();
923                 ret
924         }
925 }
926 impl Clone for MinFinalCltvExpiry {
927         fn clone(&self) -> Self {
928                 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())) },
931                         is_owned: true,
932                 }
933         }
934 }
935 #[allow(unused)]
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
939 }
940 #[no_mangle]
941 /// Creates a copy of the MinFinalCltvExpiry
942 pub extern "C" fn MinFinalCltvExpiry_clone(orig: &MinFinalCltvExpiry) -> MinFinalCltvExpiry {
943         orig.clone()
944 }
945 /// Fallback address in case no LN payment is possible
946 #[must_use]
947 #[derive(Clone)]
948 #[repr(C)]
949 pub enum Fallback {
950         SegWitProgram {
951                 version: crate::c_types::u5,
952                 program: crate::c_types::derived::CVec_u8Z,
953         },
954         PubKeyHash(crate::c_types::TwentyBytes),
955         ScriptHash(crate::c_types::TwentyBytes),
956 }
957 use lightning_invoice::Fallback as nativeFallback;
958 impl Fallback {
959         #[allow(unused)]
960         pub(crate) fn to_native(&self) -> nativeFallback {
961                 match self {
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,
969                                 }
970                         },
971                         Fallback::PubKeyHash (ref a, ) => {
972                                 let mut a_nonref = (*a).clone();
973                                 nativeFallback::PubKeyHash (
974                                         a_nonref.data,
975                                 )
976                         },
977                         Fallback::ScriptHash (ref a, ) => {
978                                 let mut a_nonref = (*a).clone();
979                                 nativeFallback::ScriptHash (
980                                         a_nonref.data,
981                                 )
982                         },
983                 }
984         }
985         #[allow(unused)]
986         pub(crate) fn into_native(self) -> nativeFallback {
987                 match self {
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,
993                                 }
994                         },
995                         Fallback::PubKeyHash (mut a, ) => {
996                                 nativeFallback::PubKeyHash (
997                                         a.data,
998                                 )
999                         },
1000                         Fallback::ScriptHash (mut a, ) => {
1001                                 nativeFallback::ScriptHash (
1002                                         a.data,
1003                                 )
1004                         },
1005                 }
1006         }
1007         #[allow(unused)]
1008         pub(crate) fn from_native(native: &nativeFallback) -> Self {
1009                 match native {
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(),
1017                                 }
1018                         },
1019                         nativeFallback::PubKeyHash (ref a, ) => {
1020                                 let mut a_nonref = (*a).clone();
1021                                 Fallback::PubKeyHash (
1022                                         crate::c_types::TwentyBytes { data: a_nonref },
1023                                 )
1024                         },
1025                         nativeFallback::ScriptHash (ref a, ) => {
1026                                 let mut a_nonref = (*a).clone();
1027                                 Fallback::ScriptHash (
1028                                         crate::c_types::TwentyBytes { data: a_nonref },
1029                                 )
1030                         },
1031                 }
1032         }
1033         #[allow(unused)]
1034         pub(crate) fn native_into(native: nativeFallback) -> Self {
1035                 match native {
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(),
1041                                 }
1042                         },
1043                         nativeFallback::PubKeyHash (mut a, ) => {
1044                                 Fallback::PubKeyHash (
1045                                         crate::c_types::TwentyBytes { data: a },
1046                                 )
1047                         },
1048                         nativeFallback::ScriptHash (mut a, ) => {
1049                                 Fallback::ScriptHash (
1050                                         crate::c_types::TwentyBytes { data: a },
1051                                 )
1052                         },
1053                 }
1054         }
1055 }
1056 /// Frees any resources used by the Fallback
1057 #[no_mangle]
1058 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1059 /// Creates a copy of the Fallback
1060 #[no_mangle]
1061 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1062         orig.clone()
1063 }
1064
1065 use lightning_invoice::InvoiceSignature as nativeInvoiceSignatureImport;
1066 type nativeInvoiceSignature = nativeInvoiceSignatureImport;
1067
1068 /// Recoverable signature
1069 #[must_use]
1070 #[repr(C)]
1071 pub struct InvoiceSignature {
1072         /// A pointer to the opaque Rust object.
1073
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.
1078
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.
1081         pub is_owned: bool,
1082 }
1083
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) };
1088                 }
1089         }
1090 }
1091 /// Frees any resources used by the InvoiceSignature, if is_owned is set and inner is non-NULL.
1092 #[no_mangle]
1093 pub extern "C" fn InvoiceSignature_free(this_obj: InvoiceSignature) { }
1094 #[allow(unused)]
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); }
1098 }
1099 #[allow(unused)]
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();
1106                 ret
1107         }
1108 }
1109 impl Clone for InvoiceSignature {
1110         fn clone(&self) -> Self {
1111                 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())) },
1114                         is_owned: true,
1115                 }
1116         }
1117 }
1118 #[allow(unused)]
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
1122 }
1123 #[no_mangle]
1124 /// Creates a copy of the InvoiceSignature
1125 pub extern "C" fn InvoiceSignature_clone(orig: &InvoiceSignature) -> InvoiceSignature {
1126         orig.clone()
1127 }
1128
1129 use lightning_invoice::RouteHint as nativeRouteHintImport;
1130 type nativeRouteHint = nativeRouteHintImport;
1131
1132 /// Private routing information
1133 ///
1134 /// # Invariants
1135 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
1136 ///
1137 #[must_use]
1138 #[repr(C)]
1139 pub struct RouteHint {
1140         /// A pointer to the opaque Rust object.
1141
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.
1146
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.
1149         pub is_owned: bool,
1150 }
1151
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) };
1156                 }
1157         }
1158 }
1159 /// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
1160 #[no_mangle]
1161 pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
1162 #[allow(unused)]
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); }
1166 }
1167 #[allow(unused)]
1168 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1169 impl RouteHint {
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();
1174                 ret
1175         }
1176 }
1177 impl Clone for RouteHint {
1178         fn clone(&self) -> Self {
1179                 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())) },
1182                         is_owned: true,
1183                 }
1184         }
1185 }
1186 #[allow(unused)]
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
1190 }
1191 #[no_mangle]
1192 /// Creates a copy of the RouteHint
1193 pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
1194         orig.clone()
1195 }
1196 /// Disassembles the `SignedRawInvoice` into its three parts:
1197 ///  1. raw invoice
1198 ///  2. hash of the raw invoice
1199 ///  3. signature
1200 #[must_use]
1201 #[no_mangle]
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();
1205         local_ret
1206 }
1207
1208 /// The `RawInvoice` which was signed.
1209 #[must_use]
1210 #[no_mangle]
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 }
1214 }
1215
1216 /// The hash of the `RawInvoice` that was signed.
1217 #[must_use]
1218 #[no_mangle]
1219 pub extern "C" fn SignedRawInvoice_hash(this_arg: &SignedRawInvoice) -> *const [u8; 32] {
1220         let mut ret = unsafe { &*this_arg.inner }.hash();
1221         ret
1222 }
1223
1224 /// InvoiceSignature for the invoice.
1225 #[must_use]
1226 #[no_mangle]
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 }
1230 }
1231
1232 /// Recovers the public key used for signing the invoice from the recoverable signature.
1233 #[must_use]
1234 #[no_mangle]
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() };
1238         local_ret
1239 }
1240
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?).
1243 #[must_use]
1244 #[no_mangle]
1245 pub extern "C" fn SignedRawInvoice_check_signature(this_arg: &SignedRawInvoice) -> bool {
1246         let mut ret = unsafe { &*this_arg.inner }.check_signature();
1247         ret
1248 }
1249
1250 /// Calculate the hash of the encoded `RawInvoice`
1251 #[must_use]
1252 #[no_mangle]
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 }
1256 }
1257
1258 #[must_use]
1259 #[no_mangle]
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 };
1263         local_ret
1264 }
1265
1266 #[must_use]
1267 #[no_mangle]
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 };
1271         local_ret
1272 }
1273
1274 #[must_use]
1275 #[no_mangle]
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 };
1279         local_ret
1280 }
1281
1282 #[must_use]
1283 #[no_mangle]
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 };
1287         local_ret
1288 }
1289
1290 #[must_use]
1291 #[no_mangle]
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 };
1295         local_ret
1296 }
1297
1298 #[must_use]
1299 #[no_mangle]
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 };
1303         local_ret
1304 }
1305
1306 #[must_use]
1307 #[no_mangle]
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 } } };
1311         local_ret
1312 }
1313
1314 #[must_use]
1315 #[no_mangle]
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 };
1319         local_ret
1320 }
1321
1322 #[must_use]
1323 #[no_mangle]
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 } }); };
1327         local_ret.into()
1328 }
1329
1330 #[must_use]
1331 #[no_mangle]
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()) } };
1335         local_ret
1336 }
1337
1338 #[must_use]
1339 #[no_mangle]
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)
1343 }
1344
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`.
1348 #[must_use]
1349 #[no_mangle]
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() };
1353         local_ret
1354 }
1355
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`.
1359 #[must_use]
1360 #[no_mangle]
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() };
1364         local_ret
1365 }
1366
1367 /// Returns the UNIX timestamp representing the stored time
1368 #[must_use]
1369 #[no_mangle]
1370 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &PositiveTimestamp) -> u64 {
1371         let mut ret = unsafe { &*this_arg.inner }.as_unix_timestamp();
1372         ret
1373 }
1374
1375 /// Returns a reference to the internal `SystemTime` time representation
1376 #[must_use]
1377 #[no_mangle]
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()
1381 }
1382
1383 /// Transform the `Invoice` into it's unchecked version
1384 #[must_use]
1385 #[no_mangle]
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 }
1389 }
1390
1391 /// Check that the invoice is signed correctly and that key recovery works
1392 #[must_use]
1393 #[no_mangle]
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() };
1397         local_ret
1398 }
1399
1400 /// Constructs an `Invoice` from a `SignedInvoice` by checking all its invariants.
1401 /// ```
1402 /// use lightning_invoice::*;
1403 ///
1404 /// let invoice = \"lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdp\\
1405 /// \tl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d7\\
1406 /// \t3gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ec\\
1407 /// \tky03ylcqca784w\";
1408 ///
1409 /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
1410 ///
1411 /// assert!(Invoice::from_signed(signed).is_ok());
1412 /// ```
1413 #[must_use]
1414 #[no_mangle]
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() };
1418         local_ret
1419 }
1420
1421 /// Returns the `Invoice`'s timestamp (should equal it's creation time)
1422 #[must_use]
1423 #[no_mangle]
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()
1427 }
1428
1429 /// Returns the hash to which we will receive the preimage on completion of the payment
1430 #[must_use]
1431 #[no_mangle]
1432 pub extern "C" fn Invoice_payment_hash(this_arg: &Invoice) -> *const [u8; 32] {
1433         let mut ret = unsafe { &*this_arg.inner }.payment_hash();
1434         ret.as_inner()
1435 }
1436
1437 /// Get the payee's public key if one was included in the invoice
1438 #[must_use]
1439 #[no_mangle]
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())) } };
1443         local_ret
1444 }
1445
1446 /// Get the payment secret if one was included in the invoice
1447 #[must_use]
1448 #[no_mangle]
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 } } };
1452         local_ret
1453 }
1454
1455 /// Get the invoice features if they were included in the invoice
1456 #[must_use]
1457 #[no_mangle]
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 };
1461         local_ret
1462 }
1463
1464 /// Recover the payee's public key (only to be used if none was included in the invoice)
1465 #[must_use]
1466 #[no_mangle]
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)
1470 }
1471
1472 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
1473 #[must_use]
1474 #[no_mangle]
1475 pub extern "C" fn Invoice_expiry_time(this_arg: &Invoice) -> u64 {
1476         let mut ret = unsafe { &*this_arg.inner }.expiry_time();
1477         ret.as_secs()
1478 }
1479
1480 /// Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
1481 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
1482 #[must_use]
1483 #[no_mangle]
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();
1486         ret
1487 }
1488
1489 /// Returns a list of all routes included in the invoice
1490 #[must_use]
1491 #[no_mangle]
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 } }); };
1495         local_ret.into()
1496 }
1497
1498 /// Returns the currency for which the invoice was issued
1499 #[must_use]
1500 #[no_mangle]
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)
1504 }
1505
1506 /// Returns the amount if specified in the invoice as pico <currency>.
1507 #[must_use]
1508 #[no_mangle]
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()) } };
1512         local_ret
1513 }
1514
1515 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
1516 /// returns `CreationError::DescriptionTooLong` otherwise
1517 ///
1518 /// Please note that single characters may use more than one byte due to UTF8 encoding.
1519 #[must_use]
1520 #[no_mangle]
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() };
1524         local_ret
1525 }
1526
1527 /// Returns the underlying description `String`
1528 #[must_use]
1529 #[no_mangle]
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();
1532         ret.into()
1533 }
1534
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`.
1538 #[must_use]
1539 #[no_mangle]
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() };
1543         local_ret
1544 }
1545
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`.
1549 #[must_use]
1550 #[no_mangle]
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() };
1554         local_ret
1555 }
1556
1557 /// Returns the expiry time in seconds
1558 #[must_use]
1559 #[no_mangle]
1560 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &ExpiryTime) -> u64 {
1561         let mut ret = unsafe { &*this_arg.inner }.as_seconds();
1562         ret
1563 }
1564
1565 /// Returns a reference to the underlying `Duration` (=expiry time)
1566 #[must_use]
1567 #[no_mangle]
1568 pub extern "C" fn ExpiryTime_as_duration(this_arg: &ExpiryTime) -> u64 {
1569         let mut ret = unsafe { &*this_arg.inner }.as_duration();
1570         ret.as_secs()
1571 }
1572
1573 /// Create a new (partial) route from a list of hops
1574 #[must_use]
1575 #[no_mangle]
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() };
1580         local_ret
1581 }
1582
1583 /// Returrn the underlying vector of hops
1584 #[must_use]
1585 #[no_mangle]
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 } }); };
1589         local_ret.into()
1590 }
1591
1592 /// Errors that may occur when constructing a new `RawInvoice` or `Invoice`
1593 #[must_use]
1594 #[derive(Clone)]
1595 #[repr(C)]
1596 pub enum CreationError {
1597         /// The supplied description string was longer than 639 __bytes__ (see [`Description::new(…)`](./struct.Description.html#method.new))
1598         DescriptionTooLong,
1599         /// The specified route has too many hops and can't be encoded
1600         RouteTooLong,
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,
1605 }
1606 use lightning_invoice::CreationError as nativeCreationError;
1607 impl CreationError {
1608         #[allow(unused)]
1609         pub(crate) fn to_native(&self) -> nativeCreationError {
1610                 match self {
1611                         CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
1612                         CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
1613                         CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
1614                         CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
1615                 }
1616         }
1617         #[allow(unused)]
1618         pub(crate) fn into_native(self) -> nativeCreationError {
1619                 match self {
1620                         CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
1621                         CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
1622                         CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
1623                         CreationError::ExpiryTimeOutOfBounds => nativeCreationError::ExpiryTimeOutOfBounds,
1624                 }
1625         }
1626         #[allow(unused)]
1627         pub(crate) fn from_native(native: &nativeCreationError) -> Self {
1628                 match native {
1629                         nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
1630                         nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
1631                         nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
1632                         nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
1633                 }
1634         }
1635         #[allow(unused)]
1636         pub(crate) fn native_into(native: nativeCreationError) -> Self {
1637                 match native {
1638                         nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
1639                         nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
1640                         nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
1641                         nativeCreationError::ExpiryTimeOutOfBounds => CreationError::ExpiryTimeOutOfBounds,
1642                 }
1643         }
1644 }
1645 /// Creates a copy of the CreationError
1646 #[no_mangle]
1647 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
1648         orig.clone()
1649 }
1650 #[no_mangle]
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()
1654 }
1655 /// Errors that may occur when converting a `RawInvoice` to an `Invoice`. They relate to the
1656 /// requirements sections in BOLT #11
1657 #[must_use]
1658 #[derive(Clone)]
1659 #[repr(C)]
1660 pub enum SemanticError {
1661         /// The invoice is missing the mandatory payment hash
1662         NoPaymentHash,
1663         /// The invoice has multiple payment hashes which isn't allowed
1664         MultiplePaymentHashes,
1665         /// No description or description hash are part of the invoice
1666         NoDescription,
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
1670         InvalidRecoveryId,
1671         /// The invoice's signature is invalid
1672         InvalidSignature,
1673 }
1674 use lightning_invoice::SemanticError as nativeSemanticError;
1675 impl SemanticError {
1676         #[allow(unused)]
1677         pub(crate) fn to_native(&self) -> nativeSemanticError {
1678                 match self {
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,
1685                 }
1686         }
1687         #[allow(unused)]
1688         pub(crate) fn into_native(self) -> nativeSemanticError {
1689                 match self {
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,
1696                 }
1697         }
1698         #[allow(unused)]
1699         pub(crate) fn from_native(native: &nativeSemanticError) -> Self {
1700                 match native {
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,
1707                 }
1708         }
1709         #[allow(unused)]
1710         pub(crate) fn native_into(native: nativeSemanticError) -> Self {
1711                 match native {
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,
1718                 }
1719         }
1720 }
1721 /// Creates a copy of the SemanticError
1722 #[no_mangle]
1723 pub extern "C" fn SemanticError_clone(orig: &SemanticError) -> SemanticError {
1724         orig.clone()
1725 }
1726 #[no_mangle]
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()
1730 }
1731 /// When signing using a fallible method either an user-supplied `SignError` or a `CreationError`
1732 /// may occur.
1733 #[must_use]
1734 #[derive(Clone)]
1735 #[repr(C)]
1736 pub enum SignOrCreationError {
1737         /// An error occurred during signing
1738         SignError,
1739         /// An error occurred while building the transaction
1740         CreationError(crate::lightning_invoice::CreationError),
1741 }
1742 use lightning_invoice::SignOrCreationError as nativeSignOrCreationError;
1743 impl SignOrCreationError {
1744         #[allow(unused)]
1745         pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
1746                 match self {
1747                         SignOrCreationError::SignError => {
1748                                 nativeSignOrCreationError::SignError (
1749                                         () /*a_nonref*/,
1750                                 )
1751                         },
1752                         SignOrCreationError::CreationError (ref a, ) => {
1753                                 let mut a_nonref = (*a).clone();
1754                                 nativeSignOrCreationError::CreationError (
1755                                         a_nonref.into_native(),
1756                                 )
1757                         },
1758                 }
1759         }
1760         #[allow(unused)]
1761         pub(crate) fn into_native(self) -> nativeSignOrCreationError {
1762                 match self {
1763                         SignOrCreationError::SignError => {
1764                                 nativeSignOrCreationError::SignError (
1765                                         () /*a*/,
1766                                 )
1767                         },
1768                         SignOrCreationError::CreationError (mut a, ) => {
1769                                 nativeSignOrCreationError::CreationError (
1770                                         a.into_native(),
1771                                 )
1772                         },
1773                 }
1774         }
1775         #[allow(unused)]
1776         pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
1777                 match native {
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),
1784                                 )
1785                         },
1786                 }
1787         }
1788         #[allow(unused)]
1789         pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
1790                 match native {
1791                         nativeSignOrCreationError::SignError (mut a, ) => {
1792                                 SignOrCreationError::SignError                  },
1793                         nativeSignOrCreationError::CreationError (mut a, ) => {
1794                                 SignOrCreationError::CreationError (
1795                                         crate::lightning_invoice::CreationError::native_into(a),
1796                                 )
1797                         },
1798                 }
1799         }
1800 }
1801 /// Frees any resources used by the SignOrCreationError
1802 #[no_mangle]
1803 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
1804 /// Creates a copy of the SignOrCreationError
1805 #[no_mangle]
1806 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
1807         orig.clone()
1808 }
1809 #[no_mangle]
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()
1813 }