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/lightning/bolts/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::<Bolt11Invoice>(&self)` (see [`Bolt11Invoice::from_str`])
15 //! * For constructing invoices use the [`InvoiceBuilder`]
16 //! * For serializing invoices use the [`Display`]/[`ToString`] traits
18 //! [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr
20 use alloc::str::FromStr;
21 use core::ffi::c_void;
22 use core::convert::Infallible;
23 use bitcoin::hashes::Hash;
24 use crate::c_types::*;
25 #[cfg(feature="no-std")]
26 use alloc::{vec::Vec, boxed::Box};
33 use alloc::str::FromStr;
34 use core::ffi::c_void;
35 use core::convert::Infallible;
36 use bitcoin::hashes::Hash;
37 use crate::c_types::*;
38 #[cfg(feature="no-std")]
39 use alloc::{vec::Vec, boxed::Box};
44 use alloc::str::FromStr;
45 use core::ffi::c_void;
46 use core::convert::Infallible;
47 use bitcoin::hashes::Hash;
48 use crate::c_types::*;
49 #[cfg(feature="no-std")]
50 use alloc::{vec::Vec, boxed::Box};
54 use alloc::str::FromStr;
55 use core::ffi::c_void;
56 use core::convert::Infallible;
57 use bitcoin::hashes::Hash;
58 use crate::c_types::*;
59 #[cfg(feature="no-std")]
60 use alloc::{vec::Vec, boxed::Box};
64 /// Read a SiPrefix object from a string
65 pub extern "C" fn SiPrefix_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SiPrefixBolt11ParseErrorZ {
66 match lightning_invoice::SiPrefix::from_str(s.into_str()) {
68 crate::c_types::CResultTempl::ok(
69 crate::lightning_invoice::SiPrefix::native_into(r)
73 crate::c_types::CResultTempl::err(
74 crate::lightning_invoice::Bolt11ParseError::native_into(e)
80 /// Read a Bolt11Invoice object from a string
81 pub extern "C" fn Bolt11Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_Bolt11InvoiceParseOrSemanticErrorZ {
82 match lightning_invoice::Bolt11Invoice::from_str(s.into_str()) {
84 crate::c_types::CResultTempl::ok(
85 crate::lightning_invoice::Bolt11Invoice { inner: ObjOps::heap_alloc(r), is_owned: true }
89 crate::c_types::CResultTempl::err(
90 crate::lightning_invoice::ParseOrSemanticError::native_into(e)
96 /// Read a SignedRawBolt11Invoice object from a string
97 pub extern "C" fn SignedRawBolt11Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SignedRawBolt11InvoiceBolt11ParseErrorZ {
98 match lightning_invoice::SignedRawBolt11Invoice::from_str(s.into_str()) {
100 crate::c_types::CResultTempl::ok(
101 crate::lightning_invoice::SignedRawBolt11Invoice { inner: ObjOps::heap_alloc(r), is_owned: true }
105 crate::c_types::CResultTempl::err(
106 crate::lightning_invoice::Bolt11ParseError::native_into(e)
112 /// Get the string representation of a Bolt11ParseError object
113 pub extern "C" fn Bolt11ParseError_to_str(o: &crate::lightning_invoice::Bolt11ParseError) -> Str {
114 alloc::format!("{}", &o.to_native()).into()
117 /// Get the string representation of a ParseOrSemanticError object
118 pub extern "C" fn ParseOrSemanticError_to_str(o: &crate::lightning_invoice::ParseOrSemanticError) -> Str {
119 alloc::format!("{}", &o.to_native()).into()
124 use alloc::str::FromStr;
125 use core::ffi::c_void;
126 use core::convert::Infallible;
127 use bitcoin::hashes::Hash;
128 use crate::c_types::*;
129 #[cfg(feature="no-std")]
130 use alloc::{vec::Vec, boxed::Box};
133 /// Get the string representation of a Bolt11Invoice object
134 pub extern "C" fn Bolt11Invoice_to_str(o: &crate::lightning_invoice::Bolt11Invoice) -> Str {
135 alloc::format!("{}", o.get_native_ref()).into()
138 /// Get the string representation of a SignedRawBolt11Invoice object
139 pub extern "C" fn SignedRawBolt11Invoice_to_str(o: &crate::lightning_invoice::SignedRawBolt11Invoice) -> Str {
140 alloc::format!("{}", o.get_native_ref()).into()
143 /// Get the string representation of a Currency object
144 pub extern "C" fn Currency_to_str(o: &crate::lightning_invoice::Currency) -> Str {
145 alloc::format!("{}", &o.to_native()).into()
148 /// Get the string representation of a SiPrefix object
149 pub extern "C" fn SiPrefix_to_str(o: &crate::lightning_invoice::SiPrefix) -> Str {
150 alloc::format!("{}", &o.to_native()).into()
155 use alloc::str::FromStr;
156 use core::ffi::c_void;
157 use core::convert::Infallible;
158 use bitcoin::hashes::Hash;
159 use crate::c_types::*;
160 #[cfg(feature="no-std")]
161 use alloc::{vec::Vec, boxed::Box};
166 use alloc::str::FromStr;
167 use core::ffi::c_void;
168 use core::convert::Infallible;
169 use bitcoin::hashes::Hash;
170 use crate::c_types::*;
171 #[cfg(feature="no-std")]
172 use alloc::{vec::Vec, boxed::Box};
177 use alloc::str::FromStr;
178 use core::ffi::c_void;
179 use core::convert::Infallible;
180 use bitcoin::hashes::Hash;
181 use crate::c_types::*;
182 #[cfg(feature="no-std")]
183 use alloc::{vec::Vec, boxed::Box};
186 /// Errors that indicate what is wrong with the invoice. They have some granularity for debug
187 /// reasons, but should generally result in an \"invalid BOLT11 invoice\" message for the user.
191 pub enum Bolt11ParseError {
193 crate::c_types::Bech32Error),
195 crate::c_types::Error),
197 crate::c_types::Secp256k1Error),
203 UnexpectedEndOfTaggedFields,
204 DescriptionDecodeError(
205 crate::c_types::Error),
207 IntegerOverflowError,
208 InvalidSegWitProgramLength,
209 InvalidPubKeyHashLength,
210 InvalidScriptHashLength,
213 crate::c_types::Str),
214 /// Not an error, but used internally to signal that a part of the invoice should be ignored
215 /// according to BOLT11
218 use lightning_invoice::Bolt11ParseError as Bolt11ParseErrorImport;
219 pub(crate) type nativeBolt11ParseError = Bolt11ParseErrorImport;
221 impl Bolt11ParseError {
223 pub(crate) fn to_native(&self) -> nativeBolt11ParseError {
225 Bolt11ParseError::Bech32Error (ref a, ) => {
226 let mut a_nonref = Clone::clone(a);
227 nativeBolt11ParseError::Bech32Error (
228 a_nonref.into_rust(),
231 Bolt11ParseError::ParseAmountError (ref a, ) => {
232 let mut a_nonref = Clone::clone(a);
233 nativeBolt11ParseError::ParseAmountError (
234 u8::from_str_radix(" a", 10).unwrap_err() /*a_nonref*/,
237 Bolt11ParseError::MalformedSignature (ref a, ) => {
238 let mut a_nonref = Clone::clone(a);
239 nativeBolt11ParseError::MalformedSignature (
240 a_nonref.into_rust(),
243 Bolt11ParseError::BadPrefix => nativeBolt11ParseError::BadPrefix,
244 Bolt11ParseError::UnknownCurrency => nativeBolt11ParseError::UnknownCurrency,
245 Bolt11ParseError::UnknownSiPrefix => nativeBolt11ParseError::UnknownSiPrefix,
246 Bolt11ParseError::MalformedHRP => nativeBolt11ParseError::MalformedHRP,
247 Bolt11ParseError::TooShortDataPart => nativeBolt11ParseError::TooShortDataPart,
248 Bolt11ParseError::UnexpectedEndOfTaggedFields => nativeBolt11ParseError::UnexpectedEndOfTaggedFields,
249 Bolt11ParseError::DescriptionDecodeError (ref a, ) => {
250 let mut a_nonref = Clone::clone(a);
251 nativeBolt11ParseError::DescriptionDecodeError (
252 core::str::from_utf8(&[0xff]).unwrap_err() /*a_nonref*/,
255 Bolt11ParseError::PaddingError => nativeBolt11ParseError::PaddingError,
256 Bolt11ParseError::IntegerOverflowError => nativeBolt11ParseError::IntegerOverflowError,
257 Bolt11ParseError::InvalidSegWitProgramLength => nativeBolt11ParseError::InvalidSegWitProgramLength,
258 Bolt11ParseError::InvalidPubKeyHashLength => nativeBolt11ParseError::InvalidPubKeyHashLength,
259 Bolt11ParseError::InvalidScriptHashLength => nativeBolt11ParseError::InvalidScriptHashLength,
260 Bolt11ParseError::InvalidRecoveryId => nativeBolt11ParseError::InvalidRecoveryId,
261 Bolt11ParseError::InvalidSliceLength (ref a, ) => {
262 let mut a_nonref = Clone::clone(a);
263 nativeBolt11ParseError::InvalidSliceLength (
264 a_nonref.into_string(),
267 Bolt11ParseError::Skip => nativeBolt11ParseError::Skip,
271 pub(crate) fn into_native(self) -> nativeBolt11ParseError {
273 Bolt11ParseError::Bech32Error (mut a, ) => {
274 nativeBolt11ParseError::Bech32Error (
278 Bolt11ParseError::ParseAmountError (mut a, ) => {
279 nativeBolt11ParseError::ParseAmountError (
280 u8::from_str_radix(" a", 10).unwrap_err() /*a*/,
283 Bolt11ParseError::MalformedSignature (mut a, ) => {
284 nativeBolt11ParseError::MalformedSignature (
288 Bolt11ParseError::BadPrefix => nativeBolt11ParseError::BadPrefix,
289 Bolt11ParseError::UnknownCurrency => nativeBolt11ParseError::UnknownCurrency,
290 Bolt11ParseError::UnknownSiPrefix => nativeBolt11ParseError::UnknownSiPrefix,
291 Bolt11ParseError::MalformedHRP => nativeBolt11ParseError::MalformedHRP,
292 Bolt11ParseError::TooShortDataPart => nativeBolt11ParseError::TooShortDataPart,
293 Bolt11ParseError::UnexpectedEndOfTaggedFields => nativeBolt11ParseError::UnexpectedEndOfTaggedFields,
294 Bolt11ParseError::DescriptionDecodeError (mut a, ) => {
295 nativeBolt11ParseError::DescriptionDecodeError (
296 core::str::from_utf8(&[0xff]).unwrap_err() /*a*/,
299 Bolt11ParseError::PaddingError => nativeBolt11ParseError::PaddingError,
300 Bolt11ParseError::IntegerOverflowError => nativeBolt11ParseError::IntegerOverflowError,
301 Bolt11ParseError::InvalidSegWitProgramLength => nativeBolt11ParseError::InvalidSegWitProgramLength,
302 Bolt11ParseError::InvalidPubKeyHashLength => nativeBolt11ParseError::InvalidPubKeyHashLength,
303 Bolt11ParseError::InvalidScriptHashLength => nativeBolt11ParseError::InvalidScriptHashLength,
304 Bolt11ParseError::InvalidRecoveryId => nativeBolt11ParseError::InvalidRecoveryId,
305 Bolt11ParseError::InvalidSliceLength (mut a, ) => {
306 nativeBolt11ParseError::InvalidSliceLength (
310 Bolt11ParseError::Skip => nativeBolt11ParseError::Skip,
314 pub(crate) fn from_native(native: &nativeBolt11ParseError) -> Self {
316 nativeBolt11ParseError::Bech32Error (ref a, ) => {
317 let mut a_nonref = Clone::clone(a);
318 Bolt11ParseError::Bech32Error (
319 crate::c_types::Bech32Error::from_rust(a_nonref),
322 nativeBolt11ParseError::ParseAmountError (ref a, ) => {
323 let mut a_nonref = Clone::clone(a);
324 Bolt11ParseError::ParseAmountError (
325 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
328 nativeBolt11ParseError::MalformedSignature (ref a, ) => {
329 let mut a_nonref = Clone::clone(a);
330 Bolt11ParseError::MalformedSignature (
331 crate::c_types::Secp256k1Error::from_rust(a_nonref),
334 nativeBolt11ParseError::BadPrefix => Bolt11ParseError::BadPrefix,
335 nativeBolt11ParseError::UnknownCurrency => Bolt11ParseError::UnknownCurrency,
336 nativeBolt11ParseError::UnknownSiPrefix => Bolt11ParseError::UnknownSiPrefix,
337 nativeBolt11ParseError::MalformedHRP => Bolt11ParseError::MalformedHRP,
338 nativeBolt11ParseError::TooShortDataPart => Bolt11ParseError::TooShortDataPart,
339 nativeBolt11ParseError::UnexpectedEndOfTaggedFields => Bolt11ParseError::UnexpectedEndOfTaggedFields,
340 nativeBolt11ParseError::DescriptionDecodeError (ref a, ) => {
341 let mut a_nonref = Clone::clone(a);
342 Bolt11ParseError::DescriptionDecodeError (
343 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
346 nativeBolt11ParseError::PaddingError => Bolt11ParseError::PaddingError,
347 nativeBolt11ParseError::IntegerOverflowError => Bolt11ParseError::IntegerOverflowError,
348 nativeBolt11ParseError::InvalidSegWitProgramLength => Bolt11ParseError::InvalidSegWitProgramLength,
349 nativeBolt11ParseError::InvalidPubKeyHashLength => Bolt11ParseError::InvalidPubKeyHashLength,
350 nativeBolt11ParseError::InvalidScriptHashLength => Bolt11ParseError::InvalidScriptHashLength,
351 nativeBolt11ParseError::InvalidRecoveryId => Bolt11ParseError::InvalidRecoveryId,
352 nativeBolt11ParseError::InvalidSliceLength (ref a, ) => {
353 let mut a_nonref = Clone::clone(a);
354 Bolt11ParseError::InvalidSliceLength (
358 nativeBolt11ParseError::Skip => Bolt11ParseError::Skip,
362 pub(crate) fn native_into(native: nativeBolt11ParseError) -> Self {
364 nativeBolt11ParseError::Bech32Error (mut a, ) => {
365 Bolt11ParseError::Bech32Error (
366 crate::c_types::Bech32Error::from_rust(a),
369 nativeBolt11ParseError::ParseAmountError (mut a, ) => {
370 Bolt11ParseError::ParseAmountError (
371 crate::c_types::Error { _dummy: 0 } /*a*/,
374 nativeBolt11ParseError::MalformedSignature (mut a, ) => {
375 Bolt11ParseError::MalformedSignature (
376 crate::c_types::Secp256k1Error::from_rust(a),
379 nativeBolt11ParseError::BadPrefix => Bolt11ParseError::BadPrefix,
380 nativeBolt11ParseError::UnknownCurrency => Bolt11ParseError::UnknownCurrency,
381 nativeBolt11ParseError::UnknownSiPrefix => Bolt11ParseError::UnknownSiPrefix,
382 nativeBolt11ParseError::MalformedHRP => Bolt11ParseError::MalformedHRP,
383 nativeBolt11ParseError::TooShortDataPart => Bolt11ParseError::TooShortDataPart,
384 nativeBolt11ParseError::UnexpectedEndOfTaggedFields => Bolt11ParseError::UnexpectedEndOfTaggedFields,
385 nativeBolt11ParseError::DescriptionDecodeError (mut a, ) => {
386 Bolt11ParseError::DescriptionDecodeError (
387 crate::c_types::Error { _dummy: 0 } /*a*/,
390 nativeBolt11ParseError::PaddingError => Bolt11ParseError::PaddingError,
391 nativeBolt11ParseError::IntegerOverflowError => Bolt11ParseError::IntegerOverflowError,
392 nativeBolt11ParseError::InvalidSegWitProgramLength => Bolt11ParseError::InvalidSegWitProgramLength,
393 nativeBolt11ParseError::InvalidPubKeyHashLength => Bolt11ParseError::InvalidPubKeyHashLength,
394 nativeBolt11ParseError::InvalidScriptHashLength => Bolt11ParseError::InvalidScriptHashLength,
395 nativeBolt11ParseError::InvalidRecoveryId => Bolt11ParseError::InvalidRecoveryId,
396 nativeBolt11ParseError::InvalidSliceLength (mut a, ) => {
397 Bolt11ParseError::InvalidSliceLength (
401 nativeBolt11ParseError::Skip => Bolt11ParseError::Skip,
405 /// Frees any resources used by the Bolt11ParseError
407 pub extern "C" fn Bolt11ParseError_free(this_ptr: Bolt11ParseError) { }
408 /// Creates a copy of the Bolt11ParseError
410 pub extern "C" fn Bolt11ParseError_clone(orig: &Bolt11ParseError) -> Bolt11ParseError {
414 /// Utility method to constructs a new Bech32Error-variant Bolt11ParseError
415 pub extern "C" fn Bolt11ParseError_bech32_error(a: crate::c_types::Bech32Error) -> Bolt11ParseError {
416 Bolt11ParseError::Bech32Error(a, )
419 /// Utility method to constructs a new ParseAmountError-variant Bolt11ParseError
420 pub extern "C" fn Bolt11ParseError_parse_amount_error(a: crate::c_types::Error) -> Bolt11ParseError {
421 Bolt11ParseError::ParseAmountError(a, )
424 /// Utility method to constructs a new MalformedSignature-variant Bolt11ParseError
425 pub extern "C" fn Bolt11ParseError_malformed_signature(a: crate::c_types::Secp256k1Error) -> Bolt11ParseError {
426 Bolt11ParseError::MalformedSignature(a, )
429 /// Utility method to constructs a new BadPrefix-variant Bolt11ParseError
430 pub extern "C" fn Bolt11ParseError_bad_prefix() -> Bolt11ParseError {
431 Bolt11ParseError::BadPrefix}
433 /// Utility method to constructs a new UnknownCurrency-variant Bolt11ParseError
434 pub extern "C" fn Bolt11ParseError_unknown_currency() -> Bolt11ParseError {
435 Bolt11ParseError::UnknownCurrency}
437 /// Utility method to constructs a new UnknownSiPrefix-variant Bolt11ParseError
438 pub extern "C" fn Bolt11ParseError_unknown_si_prefix() -> Bolt11ParseError {
439 Bolt11ParseError::UnknownSiPrefix}
441 /// Utility method to constructs a new MalformedHRP-variant Bolt11ParseError
442 pub extern "C" fn Bolt11ParseError_malformed_hrp() -> Bolt11ParseError {
443 Bolt11ParseError::MalformedHRP}
445 /// Utility method to constructs a new TooShortDataPart-variant Bolt11ParseError
446 pub extern "C" fn Bolt11ParseError_too_short_data_part() -> Bolt11ParseError {
447 Bolt11ParseError::TooShortDataPart}
449 /// Utility method to constructs a new UnexpectedEndOfTaggedFields-variant Bolt11ParseError
450 pub extern "C" fn Bolt11ParseError_unexpected_end_of_tagged_fields() -> Bolt11ParseError {
451 Bolt11ParseError::UnexpectedEndOfTaggedFields}
453 /// Utility method to constructs a new DescriptionDecodeError-variant Bolt11ParseError
454 pub extern "C" fn Bolt11ParseError_description_decode_error(a: crate::c_types::Error) -> Bolt11ParseError {
455 Bolt11ParseError::DescriptionDecodeError(a, )
458 /// Utility method to constructs a new PaddingError-variant Bolt11ParseError
459 pub extern "C" fn Bolt11ParseError_padding_error() -> Bolt11ParseError {
460 Bolt11ParseError::PaddingError}
462 /// Utility method to constructs a new IntegerOverflowError-variant Bolt11ParseError
463 pub extern "C" fn Bolt11ParseError_integer_overflow_error() -> Bolt11ParseError {
464 Bolt11ParseError::IntegerOverflowError}
466 /// Utility method to constructs a new InvalidSegWitProgramLength-variant Bolt11ParseError
467 pub extern "C" fn Bolt11ParseError_invalid_seg_wit_program_length() -> Bolt11ParseError {
468 Bolt11ParseError::InvalidSegWitProgramLength}
470 /// Utility method to constructs a new InvalidPubKeyHashLength-variant Bolt11ParseError
471 pub extern "C" fn Bolt11ParseError_invalid_pub_key_hash_length() -> Bolt11ParseError {
472 Bolt11ParseError::InvalidPubKeyHashLength}
474 /// Utility method to constructs a new InvalidScriptHashLength-variant Bolt11ParseError
475 pub extern "C" fn Bolt11ParseError_invalid_script_hash_length() -> Bolt11ParseError {
476 Bolt11ParseError::InvalidScriptHashLength}
478 /// Utility method to constructs a new InvalidRecoveryId-variant Bolt11ParseError
479 pub extern "C" fn Bolt11ParseError_invalid_recovery_id() -> Bolt11ParseError {
480 Bolt11ParseError::InvalidRecoveryId}
482 /// Utility method to constructs a new InvalidSliceLength-variant Bolt11ParseError
483 pub extern "C" fn Bolt11ParseError_invalid_slice_length(a: crate::c_types::Str) -> Bolt11ParseError {
484 Bolt11ParseError::InvalidSliceLength(a, )
487 /// Utility method to constructs a new Skip-variant Bolt11ParseError
488 pub extern "C" fn Bolt11ParseError_skip() -> Bolt11ParseError {
489 Bolt11ParseError::Skip}
490 /// Checks if two Bolt11ParseErrors contain equal inner contents.
491 /// This ignores pointers and is_owned flags and looks at the values in fields.
493 pub extern "C" fn Bolt11ParseError_eq(a: &Bolt11ParseError, b: &Bolt11ParseError) -> bool {
494 if &a.to_native() == &b.to_native() { true } else { false }
496 /// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
497 /// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
498 /// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
502 pub enum ParseOrSemanticError {
503 /// The invoice couldn't be decoded
505 crate::lightning_invoice::Bolt11ParseError),
506 /// The invoice could be decoded but violates the BOLT11 standard
508 crate::lightning_invoice::Bolt11SemanticError),
510 use lightning_invoice::ParseOrSemanticError as ParseOrSemanticErrorImport;
511 pub(crate) type nativeParseOrSemanticError = ParseOrSemanticErrorImport;
513 impl ParseOrSemanticError {
515 pub(crate) fn to_native(&self) -> nativeParseOrSemanticError {
517 ParseOrSemanticError::ParseError (ref a, ) => {
518 let mut a_nonref = Clone::clone(a);
519 nativeParseOrSemanticError::ParseError (
520 a_nonref.into_native(),
523 ParseOrSemanticError::SemanticError (ref a, ) => {
524 let mut a_nonref = Clone::clone(a);
525 nativeParseOrSemanticError::SemanticError (
526 a_nonref.into_native(),
532 pub(crate) fn into_native(self) -> nativeParseOrSemanticError {
534 ParseOrSemanticError::ParseError (mut a, ) => {
535 nativeParseOrSemanticError::ParseError (
539 ParseOrSemanticError::SemanticError (mut a, ) => {
540 nativeParseOrSemanticError::SemanticError (
547 pub(crate) fn from_native(native: &nativeParseOrSemanticError) -> Self {
549 nativeParseOrSemanticError::ParseError (ref a, ) => {
550 let mut a_nonref = Clone::clone(a);
551 ParseOrSemanticError::ParseError (
552 crate::lightning_invoice::Bolt11ParseError::native_into(a_nonref),
555 nativeParseOrSemanticError::SemanticError (ref a, ) => {
556 let mut a_nonref = Clone::clone(a);
557 ParseOrSemanticError::SemanticError (
558 crate::lightning_invoice::Bolt11SemanticError::native_into(a_nonref),
564 pub(crate) fn native_into(native: nativeParseOrSemanticError) -> Self {
566 nativeParseOrSemanticError::ParseError (mut a, ) => {
567 ParseOrSemanticError::ParseError (
568 crate::lightning_invoice::Bolt11ParseError::native_into(a),
571 nativeParseOrSemanticError::SemanticError (mut a, ) => {
572 ParseOrSemanticError::SemanticError (
573 crate::lightning_invoice::Bolt11SemanticError::native_into(a),
579 /// Frees any resources used by the ParseOrSemanticError
581 pub extern "C" fn ParseOrSemanticError_free(this_ptr: ParseOrSemanticError) { }
582 /// Creates a copy of the ParseOrSemanticError
584 pub extern "C" fn ParseOrSemanticError_clone(orig: &ParseOrSemanticError) -> ParseOrSemanticError {
588 /// Utility method to constructs a new ParseError-variant ParseOrSemanticError
589 pub extern "C" fn ParseOrSemanticError_parse_error(a: crate::lightning_invoice::Bolt11ParseError) -> ParseOrSemanticError {
590 ParseOrSemanticError::ParseError(a, )
593 /// Utility method to constructs a new SemanticError-variant ParseOrSemanticError
594 pub extern "C" fn ParseOrSemanticError_semantic_error(a: crate::lightning_invoice::Bolt11SemanticError) -> ParseOrSemanticError {
595 ParseOrSemanticError::SemanticError(a, )
597 /// Checks if two ParseOrSemanticErrors contain equal inner contents.
598 /// This ignores pointers and is_owned flags and looks at the values in fields.
600 pub extern "C" fn ParseOrSemanticError_eq(a: &ParseOrSemanticError, b: &ParseOrSemanticError) -> bool {
601 if &a.to_native() == &b.to_native() { true } else { false }
603 /// The maximum timestamp as [`Duration::as_secs`] since the Unix epoch allowed by [`BOLT 11`].
605 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
608 pub static MAX_TIMESTAMP: u64 = lightning_invoice::MAX_TIMESTAMP;
609 /// Default expiry time as defined by [BOLT 11].
611 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
614 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
615 /// Default minimum final CLTV expiry as defined by [BOLT 11].
617 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
618 /// provided in [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
620 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
621 /// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
624 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA;
626 use lightning_invoice::Bolt11Invoice as nativeBolt11InvoiceImport;
627 pub(crate) type nativeBolt11Invoice = nativeBolt11InvoiceImport;
629 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
631 /// There are three ways to construct a `Bolt11Invoice`:
632 /// 1. using [`InvoiceBuilder`]
633 /// 2. using [`Bolt11Invoice::from_signed`]
634 /// 3. using `str::parse::<Bolt11Invoice>(&str)` (see [`Bolt11Invoice::from_str`])
636 /// [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr
639 pub struct Bolt11Invoice {
640 /// A pointer to the opaque Rust object.
642 /// Nearly everywhere, inner must be non-null, however in places where
643 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
644 pub inner: *mut nativeBolt11Invoice,
645 /// Indicates that this is the only struct which contains the same pointer.
647 /// Rust functions which take ownership of an object provided via an argument require
648 /// this to be true and invalidate the object pointed to by inner.
652 impl Drop for Bolt11Invoice {
654 if self.is_owned && !<*mut nativeBolt11Invoice>::is_null(self.inner) {
655 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
659 /// Frees any resources used by the Bolt11Invoice, if is_owned is set and inner is non-NULL.
661 pub extern "C" fn Bolt11Invoice_free(this_obj: Bolt11Invoice) { }
663 /// Used only if an object of this type is returned as a trait impl by a method
664 pub(crate) extern "C" fn Bolt11Invoice_free_void(this_ptr: *mut c_void) {
665 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBolt11Invoice) };
669 pub(crate) fn get_native_ref(&self) -> &'static nativeBolt11Invoice {
670 unsafe { &*ObjOps::untweak_ptr(self.inner) }
672 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt11Invoice {
673 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
675 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
676 pub(crate) fn take_inner(mut self) -> *mut nativeBolt11Invoice {
677 assert!(self.is_owned);
678 let ret = ObjOps::untweak_ptr(self.inner);
679 self.inner = core::ptr::null_mut();
683 /// Checks if two Bolt11Invoices contain equal inner contents.
684 /// This ignores pointers and is_owned flags and looks at the values in fields.
685 /// Two objects with NULL inner values will be considered "equal" here.
687 pub extern "C" fn Bolt11Invoice_eq(a: &Bolt11Invoice, b: &Bolt11Invoice) -> bool {
688 if a.inner == b.inner { return true; }
689 if a.inner.is_null() || b.inner.is_null() { return false; }
690 if a.get_native_ref() == b.get_native_ref() { true } else { false }
692 impl Clone for Bolt11Invoice {
693 fn clone(&self) -> Self {
695 inner: if <*mut nativeBolt11Invoice>::is_null(self.inner) { core::ptr::null_mut() } else {
696 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
702 /// Used only if an object of this type is returned as a trait impl by a method
703 pub(crate) extern "C" fn Bolt11Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
704 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBolt11Invoice)).clone() })) as *mut c_void
707 /// Creates a copy of the Bolt11Invoice
708 pub extern "C" fn Bolt11Invoice_clone(orig: &Bolt11Invoice) -> Bolt11Invoice {
711 /// Generates a non-cryptographic 64-bit hash of the Bolt11Invoice.
713 pub extern "C" fn Bolt11Invoice_hash(o: &Bolt11Invoice) -> u64 {
714 if o.inner.is_null() { return 0; }
715 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
717 let mut hasher = core::hash::SipHasher::new();
718 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
719 core::hash::Hasher::finish(&hasher)
722 use lightning_invoice::SignedRawBolt11Invoice as nativeSignedRawBolt11InvoiceImport;
723 pub(crate) type nativeSignedRawBolt11Invoice = nativeSignedRawBolt11InvoiceImport;
725 /// Represents a signed [`RawBolt11Invoice`] with cached hash. The signature is not checked and may be
729 /// The hash has to be either from the deserialized invoice or from the serialized [`RawBolt11Invoice`].
732 pub struct SignedRawBolt11Invoice {
733 /// A pointer to the opaque Rust object.
735 /// Nearly everywhere, inner must be non-null, however in places where
736 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
737 pub inner: *mut nativeSignedRawBolt11Invoice,
738 /// Indicates that this is the only struct which contains the same pointer.
740 /// Rust functions which take ownership of an object provided via an argument require
741 /// this to be true and invalidate the object pointed to by inner.
745 impl Drop for SignedRawBolt11Invoice {
747 if self.is_owned && !<*mut nativeSignedRawBolt11Invoice>::is_null(self.inner) {
748 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
752 /// Frees any resources used by the SignedRawBolt11Invoice, if is_owned is set and inner is non-NULL.
754 pub extern "C" fn SignedRawBolt11Invoice_free(this_obj: SignedRawBolt11Invoice) { }
756 /// Used only if an object of this type is returned as a trait impl by a method
757 pub(crate) extern "C" fn SignedRawBolt11Invoice_free_void(this_ptr: *mut c_void) {
758 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSignedRawBolt11Invoice) };
761 impl SignedRawBolt11Invoice {
762 pub(crate) fn get_native_ref(&self) -> &'static nativeSignedRawBolt11Invoice {
763 unsafe { &*ObjOps::untweak_ptr(self.inner) }
765 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSignedRawBolt11Invoice {
766 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
768 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
769 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawBolt11Invoice {
770 assert!(self.is_owned);
771 let ret = ObjOps::untweak_ptr(self.inner);
772 self.inner = core::ptr::null_mut();
776 /// Checks if two SignedRawBolt11Invoices contain equal inner contents.
777 /// This ignores pointers and is_owned flags and looks at the values in fields.
778 /// Two objects with NULL inner values will be considered "equal" here.
780 pub extern "C" fn SignedRawBolt11Invoice_eq(a: &SignedRawBolt11Invoice, b: &SignedRawBolt11Invoice) -> bool {
781 if a.inner == b.inner { return true; }
782 if a.inner.is_null() || b.inner.is_null() { return false; }
783 if a.get_native_ref() == b.get_native_ref() { true } else { false }
785 impl Clone for SignedRawBolt11Invoice {
786 fn clone(&self) -> Self {
788 inner: if <*mut nativeSignedRawBolt11Invoice>::is_null(self.inner) { core::ptr::null_mut() } else {
789 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
795 /// Used only if an object of this type is returned as a trait impl by a method
796 pub(crate) extern "C" fn SignedRawBolt11Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
797 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawBolt11Invoice)).clone() })) as *mut c_void
800 /// Creates a copy of the SignedRawBolt11Invoice
801 pub extern "C" fn SignedRawBolt11Invoice_clone(orig: &SignedRawBolt11Invoice) -> SignedRawBolt11Invoice {
804 /// Generates a non-cryptographic 64-bit hash of the SignedRawBolt11Invoice.
806 pub extern "C" fn SignedRawBolt11Invoice_hash(o: &SignedRawBolt11Invoice) -> u64 {
807 if o.inner.is_null() { return 0; }
808 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
810 let mut hasher = core::hash::SipHasher::new();
811 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
812 core::hash::Hasher::finish(&hasher)
815 use lightning_invoice::RawBolt11Invoice as nativeRawBolt11InvoiceImport;
816 pub(crate) type nativeRawBolt11Invoice = nativeRawBolt11InvoiceImport;
818 /// Represents an syntactically correct [`Bolt11Invoice`] for a payment on the lightning network,
819 /// but without the signature information.
820 /// Decoding and encoding should not lead to information loss but may lead to different hashes.
822 /// For methods without docs see the corresponding methods in [`Bolt11Invoice`].
825 pub struct RawBolt11Invoice {
826 /// A pointer to the opaque Rust object.
828 /// Nearly everywhere, inner must be non-null, however in places where
829 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
830 pub inner: *mut nativeRawBolt11Invoice,
831 /// Indicates that this is the only struct which contains the same pointer.
833 /// Rust functions which take ownership of an object provided via an argument require
834 /// this to be true and invalidate the object pointed to by inner.
838 impl Drop for RawBolt11Invoice {
840 if self.is_owned && !<*mut nativeRawBolt11Invoice>::is_null(self.inner) {
841 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
845 /// Frees any resources used by the RawBolt11Invoice, if is_owned is set and inner is non-NULL.
847 pub extern "C" fn RawBolt11Invoice_free(this_obj: RawBolt11Invoice) { }
849 /// Used only if an object of this type is returned as a trait impl by a method
850 pub(crate) extern "C" fn RawBolt11Invoice_free_void(this_ptr: *mut c_void) {
851 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRawBolt11Invoice) };
854 impl RawBolt11Invoice {
855 pub(crate) fn get_native_ref(&self) -> &'static nativeRawBolt11Invoice {
856 unsafe { &*ObjOps::untweak_ptr(self.inner) }
858 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawBolt11Invoice {
859 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
861 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
862 pub(crate) fn take_inner(mut self) -> *mut nativeRawBolt11Invoice {
863 assert!(self.is_owned);
864 let ret = ObjOps::untweak_ptr(self.inner);
865 self.inner = core::ptr::null_mut();
871 pub extern "C" fn RawBolt11Invoice_get_data(this_ptr: &RawBolt11Invoice) -> crate::lightning_invoice::RawDataPart {
872 let mut inner_val = &mut this_ptr.get_native_mut_ref().data;
873 crate::lightning_invoice::RawDataPart { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::RawDataPart<>) as *mut _) }, is_owned: false }
877 pub extern "C" fn RawBolt11Invoice_set_data(this_ptr: &mut RawBolt11Invoice, mut val: crate::lightning_invoice::RawDataPart) {
878 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.data = *unsafe { Box::from_raw(val.take_inner()) };
880 /// Checks if two RawBolt11Invoices contain equal inner contents.
881 /// This ignores pointers and is_owned flags and looks at the values in fields.
882 /// Two objects with NULL inner values will be considered "equal" here.
884 pub extern "C" fn RawBolt11Invoice_eq(a: &RawBolt11Invoice, b: &RawBolt11Invoice) -> bool {
885 if a.inner == b.inner { return true; }
886 if a.inner.is_null() || b.inner.is_null() { return false; }
887 if a.get_native_ref() == b.get_native_ref() { true } else { false }
889 impl Clone for RawBolt11Invoice {
890 fn clone(&self) -> Self {
892 inner: if <*mut nativeRawBolt11Invoice>::is_null(self.inner) { core::ptr::null_mut() } else {
893 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
899 /// Used only if an object of this type is returned as a trait impl by a method
900 pub(crate) extern "C" fn RawBolt11Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
901 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawBolt11Invoice)).clone() })) as *mut c_void
904 /// Creates a copy of the RawBolt11Invoice
905 pub extern "C" fn RawBolt11Invoice_clone(orig: &RawBolt11Invoice) -> RawBolt11Invoice {
908 /// Generates a non-cryptographic 64-bit hash of the RawBolt11Invoice.
910 pub extern "C" fn RawBolt11Invoice_hash(o: &RawBolt11Invoice) -> u64 {
911 if o.inner.is_null() { return 0; }
912 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
914 let mut hasher = core::hash::SipHasher::new();
915 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
916 core::hash::Hasher::finish(&hasher)
919 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
920 pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
922 /// Data of the [`RawBolt11Invoice`] that is encoded in the data part
925 pub struct RawDataPart {
926 /// A pointer to the opaque Rust object.
928 /// Nearly everywhere, inner must be non-null, however in places where
929 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
930 pub inner: *mut nativeRawDataPart,
931 /// Indicates that this is the only struct which contains the same pointer.
933 /// Rust functions which take ownership of an object provided via an argument require
934 /// this to be true and invalidate the object pointed to by inner.
938 impl Drop for RawDataPart {
940 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
941 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
945 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
947 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
949 /// Used only if an object of this type is returned as a trait impl by a method
950 pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
951 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRawDataPart) };
955 pub(crate) fn get_native_ref(&self) -> &'static nativeRawDataPart {
956 unsafe { &*ObjOps::untweak_ptr(self.inner) }
958 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawDataPart {
959 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
961 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
962 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
963 assert!(self.is_owned);
964 let ret = ObjOps::untweak_ptr(self.inner);
965 self.inner = core::ptr::null_mut();
969 /// generation time of the invoice
971 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
972 let mut inner_val = &mut this_ptr.get_native_mut_ref().timestamp;
973 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::PositiveTimestamp<>) as *mut _) }, is_owned: false }
975 /// generation time of the invoice
977 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
978 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
980 /// Checks if two RawDataParts contain equal inner contents.
981 /// This ignores pointers and is_owned flags and looks at the values in fields.
982 /// Two objects with NULL inner values will be considered "equal" here.
984 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
985 if a.inner == b.inner { return true; }
986 if a.inner.is_null() || b.inner.is_null() { return false; }
987 if a.get_native_ref() == b.get_native_ref() { true } else { false }
989 impl Clone for RawDataPart {
990 fn clone(&self) -> Self {
992 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { core::ptr::null_mut() } else {
993 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
999 /// Used only if an object of this type is returned as a trait impl by a method
1000 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
1001 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
1004 /// Creates a copy of the RawDataPart
1005 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
1008 /// Generates a non-cryptographic 64-bit hash of the RawDataPart.
1010 pub extern "C" fn RawDataPart_hash(o: &RawDataPart) -> u64 {
1011 if o.inner.is_null() { return 0; }
1012 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1013 #[allow(deprecated)]
1014 let mut hasher = core::hash::SipHasher::new();
1015 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1016 core::hash::Hasher::finish(&hasher)
1019 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
1020 pub(crate) type nativePositiveTimestamp = nativePositiveTimestampImport;
1022 /// A timestamp that refers to a date after 1 January 1970.
1026 /// The Unix timestamp representing the stored time has to be positive and no greater than
1027 /// [`MAX_TIMESTAMP`].
1030 pub struct PositiveTimestamp {
1031 /// A pointer to the opaque Rust object.
1033 /// Nearly everywhere, inner must be non-null, however in places where
1034 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1035 pub inner: *mut nativePositiveTimestamp,
1036 /// Indicates that this is the only struct which contains the same pointer.
1038 /// Rust functions which take ownership of an object provided via an argument require
1039 /// this to be true and invalidate the object pointed to by inner.
1043 impl Drop for PositiveTimestamp {
1044 fn drop(&mut self) {
1045 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
1046 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1050 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
1052 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
1054 /// Used only if an object of this type is returned as a trait impl by a method
1055 pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
1056 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePositiveTimestamp) };
1059 impl PositiveTimestamp {
1060 pub(crate) fn get_native_ref(&self) -> &'static nativePositiveTimestamp {
1061 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1063 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePositiveTimestamp {
1064 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1066 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1067 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
1068 assert!(self.is_owned);
1069 let ret = ObjOps::untweak_ptr(self.inner);
1070 self.inner = core::ptr::null_mut();
1074 /// Checks if two PositiveTimestamps contain equal inner contents.
1075 /// This ignores pointers and is_owned flags and looks at the values in fields.
1076 /// Two objects with NULL inner values will be considered "equal" here.
1078 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
1079 if a.inner == b.inner { return true; }
1080 if a.inner.is_null() || b.inner.is_null() { return false; }
1081 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1083 impl Clone for PositiveTimestamp {
1084 fn clone(&self) -> Self {
1086 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { core::ptr::null_mut() } else {
1087 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1093 /// Used only if an object of this type is returned as a trait impl by a method
1094 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
1095 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
1098 /// Creates a copy of the PositiveTimestamp
1099 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
1102 /// Generates a non-cryptographic 64-bit hash of the PositiveTimestamp.
1104 pub extern "C" fn PositiveTimestamp_hash(o: &PositiveTimestamp) -> u64 {
1105 if o.inner.is_null() { return 0; }
1106 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1107 #[allow(deprecated)]
1108 let mut hasher = core::hash::SipHasher::new();
1109 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1110 core::hash::Hasher::finish(&hasher)
1112 /// SI prefixes for the human readable part
1126 use lightning_invoice::SiPrefix as SiPrefixImport;
1127 pub(crate) type nativeSiPrefix = SiPrefixImport;
1131 pub(crate) fn to_native(&self) -> nativeSiPrefix {
1133 SiPrefix::Milli => nativeSiPrefix::Milli,
1134 SiPrefix::Micro => nativeSiPrefix::Micro,
1135 SiPrefix::Nano => nativeSiPrefix::Nano,
1136 SiPrefix::Pico => nativeSiPrefix::Pico,
1140 pub(crate) fn into_native(self) -> nativeSiPrefix {
1142 SiPrefix::Milli => nativeSiPrefix::Milli,
1143 SiPrefix::Micro => nativeSiPrefix::Micro,
1144 SiPrefix::Nano => nativeSiPrefix::Nano,
1145 SiPrefix::Pico => nativeSiPrefix::Pico,
1149 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
1151 nativeSiPrefix::Milli => SiPrefix::Milli,
1152 nativeSiPrefix::Micro => SiPrefix::Micro,
1153 nativeSiPrefix::Nano => SiPrefix::Nano,
1154 nativeSiPrefix::Pico => SiPrefix::Pico,
1158 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
1160 nativeSiPrefix::Milli => SiPrefix::Milli,
1161 nativeSiPrefix::Micro => SiPrefix::Micro,
1162 nativeSiPrefix::Nano => SiPrefix::Nano,
1163 nativeSiPrefix::Pico => SiPrefix::Pico,
1167 /// Creates a copy of the SiPrefix
1169 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
1173 /// Utility method to constructs a new Milli-variant SiPrefix
1174 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
1177 /// Utility method to constructs a new Micro-variant SiPrefix
1178 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
1181 /// Utility method to constructs a new Nano-variant SiPrefix
1182 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
1185 /// Utility method to constructs a new Pico-variant SiPrefix
1186 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
1188 /// Checks if two SiPrefixs contain equal inner contents.
1189 /// This ignores pointers and is_owned flags and looks at the values in fields.
1191 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
1192 if &a.to_native() == &b.to_native() { true } else { false }
1194 /// Generates a non-cryptographic 64-bit hash of the SiPrefix.
1196 pub extern "C" fn SiPrefix_hash(o: &SiPrefix) -> u64 {
1197 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1198 #[allow(deprecated)]
1199 let mut hasher = core::hash::SipHasher::new();
1200 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1201 core::hash::Hasher::finish(&hasher)
1203 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
1204 /// This is effectively 10^12 * the prefix multiplier
1207 pub extern "C" fn SiPrefix_multiplier(this_arg: &crate::lightning_invoice::SiPrefix) -> u64 {
1208 let mut ret = this_arg.to_native().multiplier();
1212 /// Enum representing the crypto currencies (or networks) supported by this library
1228 use lightning_invoice::Currency as CurrencyImport;
1229 pub(crate) type nativeCurrency = CurrencyImport;
1233 pub(crate) fn to_native(&self) -> nativeCurrency {
1235 Currency::Bitcoin => nativeCurrency::Bitcoin,
1236 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1237 Currency::Regtest => nativeCurrency::Regtest,
1238 Currency::Simnet => nativeCurrency::Simnet,
1239 Currency::Signet => nativeCurrency::Signet,
1243 pub(crate) fn into_native(self) -> nativeCurrency {
1245 Currency::Bitcoin => nativeCurrency::Bitcoin,
1246 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1247 Currency::Regtest => nativeCurrency::Regtest,
1248 Currency::Simnet => nativeCurrency::Simnet,
1249 Currency::Signet => nativeCurrency::Signet,
1253 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
1255 nativeCurrency::Bitcoin => Currency::Bitcoin,
1256 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1257 nativeCurrency::Regtest => Currency::Regtest,
1258 nativeCurrency::Simnet => Currency::Simnet,
1259 nativeCurrency::Signet => Currency::Signet,
1263 pub(crate) fn native_into(native: nativeCurrency) -> Self {
1265 nativeCurrency::Bitcoin => Currency::Bitcoin,
1266 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1267 nativeCurrency::Regtest => Currency::Regtest,
1268 nativeCurrency::Simnet => Currency::Simnet,
1269 nativeCurrency::Signet => Currency::Signet,
1273 /// Creates a copy of the Currency
1275 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
1279 /// Utility method to constructs a new Bitcoin-variant Currency
1280 pub extern "C" fn Currency_bitcoin() -> Currency {
1283 /// Utility method to constructs a new BitcoinTestnet-variant Currency
1284 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
1285 Currency::BitcoinTestnet}
1287 /// Utility method to constructs a new Regtest-variant Currency
1288 pub extern "C" fn Currency_regtest() -> Currency {
1291 /// Utility method to constructs a new Simnet-variant Currency
1292 pub extern "C" fn Currency_simnet() -> Currency {
1295 /// Utility method to constructs a new Signet-variant Currency
1296 pub extern "C" fn Currency_signet() -> Currency {
1298 /// Generates a non-cryptographic 64-bit hash of the Currency.
1300 pub extern "C" fn Currency_hash(o: &Currency) -> u64 {
1301 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1302 #[allow(deprecated)]
1303 let mut hasher = core::hash::SipHasher::new();
1304 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1305 core::hash::Hasher::finish(&hasher)
1307 /// Checks if two Currencys contain equal inner contents.
1308 /// This ignores pointers and is_owned flags and looks at the values in fields.
1310 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
1311 if &a.to_native() == &b.to_native() { true } else { false }
1314 use lightning_invoice::Sha256 as nativeSha256Import;
1315 pub(crate) type nativeSha256 = nativeSha256Import;
1321 /// A pointer to the opaque Rust object.
1323 /// Nearly everywhere, inner must be non-null, however in places where
1324 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1325 pub inner: *mut nativeSha256,
1326 /// Indicates that this is the only struct which contains the same pointer.
1328 /// Rust functions which take ownership of an object provided via an argument require
1329 /// this to be true and invalidate the object pointed to by inner.
1333 impl Drop for Sha256 {
1334 fn drop(&mut self) {
1335 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
1336 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1340 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
1342 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
1344 /// Used only if an object of this type is returned as a trait impl by a method
1345 pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
1346 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSha256) };
1350 pub(crate) fn get_native_ref(&self) -> &'static nativeSha256 {
1351 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1353 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSha256 {
1354 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1356 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1357 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
1358 assert!(self.is_owned);
1359 let ret = ObjOps::untweak_ptr(self.inner);
1360 self.inner = core::ptr::null_mut();
1364 impl Clone for Sha256 {
1365 fn clone(&self) -> Self {
1367 inner: if <*mut nativeSha256>::is_null(self.inner) { core::ptr::null_mut() } else {
1368 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1374 /// Used only if an object of this type is returned as a trait impl by a method
1375 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
1376 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
1379 /// Creates a copy of the Sha256
1380 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
1383 /// Generates a non-cryptographic 64-bit hash of the Sha256.
1385 pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 {
1386 if o.inner.is_null() { return 0; }
1387 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1388 #[allow(deprecated)]
1389 let mut hasher = core::hash::SipHasher::new();
1390 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1391 core::hash::Hasher::finish(&hasher)
1393 /// Checks if two Sha256s contain equal inner contents.
1394 /// This ignores pointers and is_owned flags and looks at the values in fields.
1395 /// Two objects with NULL inner values will be considered "equal" here.
1397 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
1398 if a.inner == b.inner { return true; }
1399 if a.inner.is_null() || b.inner.is_null() { return false; }
1400 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1402 /// Constructs a new [`Sha256`] from the given bytes, which are assumed to be the output of a
1403 /// single sha256 hash.
1406 pub extern "C" fn Sha256_from_bytes(bytes: *const [u8; 32]) -> crate::lightning_invoice::Sha256 {
1407 let mut ret = lightning_invoice::Sha256::from_bytes(unsafe { &*bytes});
1408 crate::lightning_invoice::Sha256 { inner: ObjOps::heap_alloc(ret), is_owned: true }
1412 use lightning_invoice::Description as nativeDescriptionImport;
1413 pub(crate) type nativeDescription = nativeDescriptionImport;
1415 /// Description string
1418 /// The description can be at most 639 __bytes__ long
1421 pub struct Description {
1422 /// A pointer to the opaque Rust object.
1424 /// Nearly everywhere, inner must be non-null, however in places where
1425 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1426 pub inner: *mut nativeDescription,
1427 /// Indicates that this is the only struct which contains the same pointer.
1429 /// Rust functions which take ownership of an object provided via an argument require
1430 /// this to be true and invalidate the object pointed to by inner.
1434 impl Drop for Description {
1435 fn drop(&mut self) {
1436 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
1437 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1441 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
1443 pub extern "C" fn Description_free(this_obj: Description) { }
1445 /// Used only if an object of this type is returned as a trait impl by a method
1446 pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) {
1447 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDescription) };
1451 pub(crate) fn get_native_ref(&self) -> &'static nativeDescription {
1452 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1454 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDescription {
1455 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1457 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1458 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
1459 assert!(self.is_owned);
1460 let ret = ObjOps::untweak_ptr(self.inner);
1461 self.inner = core::ptr::null_mut();
1465 impl Clone for Description {
1466 fn clone(&self) -> Self {
1468 inner: if <*mut nativeDescription>::is_null(self.inner) { core::ptr::null_mut() } else {
1469 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1475 /// Used only if an object of this type is returned as a trait impl by a method
1476 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
1477 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
1480 /// Creates a copy of the Description
1481 pub extern "C" fn Description_clone(orig: &Description) -> Description {
1484 /// Generates a non-cryptographic 64-bit hash of the Description.
1486 pub extern "C" fn Description_hash(o: &Description) -> u64 {
1487 if o.inner.is_null() { return 0; }
1488 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1489 #[allow(deprecated)]
1490 let mut hasher = core::hash::SipHasher::new();
1491 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1492 core::hash::Hasher::finish(&hasher)
1494 /// Checks if two Descriptions contain equal inner contents.
1495 /// This ignores pointers and is_owned flags and looks at the values in fields.
1496 /// Two objects with NULL inner values will be considered "equal" here.
1498 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
1499 if a.inner == b.inner { return true; }
1500 if a.inner.is_null() || b.inner.is_null() { return false; }
1501 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1504 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
1505 pub(crate) type nativePayeePubKey = nativePayeePubKeyImport;
1507 /// Payee public key
1510 pub struct PayeePubKey {
1511 /// A pointer to the opaque Rust object.
1513 /// Nearly everywhere, inner must be non-null, however in places where
1514 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1515 pub inner: *mut nativePayeePubKey,
1516 /// Indicates that this is the only struct which contains the same pointer.
1518 /// Rust functions which take ownership of an object provided via an argument require
1519 /// this to be true and invalidate the object pointed to by inner.
1523 impl Drop for PayeePubKey {
1524 fn drop(&mut self) {
1525 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
1526 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1530 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
1532 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
1534 /// Used only if an object of this type is returned as a trait impl by a method
1535 pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
1536 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePayeePubKey) };
1540 pub(crate) fn get_native_ref(&self) -> &'static nativePayeePubKey {
1541 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1543 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayeePubKey {
1544 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1546 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1547 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
1548 assert!(self.is_owned);
1549 let ret = ObjOps::untweak_ptr(self.inner);
1550 self.inner = core::ptr::null_mut();
1555 pub extern "C" fn PayeePubKey_get_a(this_ptr: &PayeePubKey) -> crate::c_types::PublicKey {
1556 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1557 crate::c_types::PublicKey::from_rust(&inner_val)
1560 pub extern "C" fn PayeePubKey_set_a(this_ptr: &mut PayeePubKey, mut val: crate::c_types::PublicKey) {
1561 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
1563 /// Constructs a new PayeePubKey given each field
1566 pub extern "C" fn PayeePubKey_new(mut a_arg: crate::c_types::PublicKey) -> PayeePubKey {
1567 PayeePubKey { inner: ObjOps::heap_alloc(lightning_invoice::PayeePubKey (
1569 )), is_owned: true }
1571 impl Clone for PayeePubKey {
1572 fn clone(&self) -> Self {
1574 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { core::ptr::null_mut() } else {
1575 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1581 /// Used only if an object of this type is returned as a trait impl by a method
1582 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
1583 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
1586 /// Creates a copy of the PayeePubKey
1587 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
1590 /// Generates a non-cryptographic 64-bit hash of the PayeePubKey.
1592 pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 {
1593 if o.inner.is_null() { return 0; }
1594 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1595 #[allow(deprecated)]
1596 let mut hasher = core::hash::SipHasher::new();
1597 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1598 core::hash::Hasher::finish(&hasher)
1600 /// Checks if two PayeePubKeys contain equal inner contents.
1601 /// This ignores pointers and is_owned flags and looks at the values in fields.
1602 /// Two objects with NULL inner values will be considered "equal" here.
1604 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
1605 if a.inner == b.inner { return true; }
1606 if a.inner.is_null() || b.inner.is_null() { return false; }
1607 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1610 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
1611 pub(crate) type nativeExpiryTime = nativeExpiryTimeImport;
1613 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
1617 pub struct ExpiryTime {
1618 /// A pointer to the opaque Rust object.
1620 /// Nearly everywhere, inner must be non-null, however in places where
1621 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1622 pub inner: *mut nativeExpiryTime,
1623 /// Indicates that this is the only struct which contains the same pointer.
1625 /// Rust functions which take ownership of an object provided via an argument require
1626 /// this to be true and invalidate the object pointed to by inner.
1630 impl Drop for ExpiryTime {
1631 fn drop(&mut self) {
1632 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
1633 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1637 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
1639 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
1641 /// Used only if an object of this type is returned as a trait impl by a method
1642 pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
1643 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeExpiryTime) };
1647 pub(crate) fn get_native_ref(&self) -> &'static nativeExpiryTime {
1648 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1650 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpiryTime {
1651 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1653 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1654 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
1655 assert!(self.is_owned);
1656 let ret = ObjOps::untweak_ptr(self.inner);
1657 self.inner = core::ptr::null_mut();
1661 impl Clone for ExpiryTime {
1662 fn clone(&self) -> Self {
1664 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { core::ptr::null_mut() } else {
1665 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1671 /// Used only if an object of this type is returned as a trait impl by a method
1672 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1673 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1676 /// Creates a copy of the ExpiryTime
1677 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1680 /// Generates a non-cryptographic 64-bit hash of the ExpiryTime.
1682 pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 {
1683 if o.inner.is_null() { return 0; }
1684 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1685 #[allow(deprecated)]
1686 let mut hasher = core::hash::SipHasher::new();
1687 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1688 core::hash::Hasher::finish(&hasher)
1690 /// Checks if two ExpiryTimes contain equal inner contents.
1691 /// This ignores pointers and is_owned flags and looks at the values in fields.
1692 /// Two objects with NULL inner values will be considered "equal" here.
1694 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1695 if a.inner == b.inner { return true; }
1696 if a.inner.is_null() || b.inner.is_null() { return false; }
1697 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1700 use lightning_invoice::MinFinalCltvExpiryDelta as nativeMinFinalCltvExpiryDeltaImport;
1701 pub(crate) type nativeMinFinalCltvExpiryDelta = nativeMinFinalCltvExpiryDeltaImport;
1703 /// `min_final_cltv_expiry_delta` to use for the last HTLC in the route
1706 pub struct MinFinalCltvExpiryDelta {
1707 /// A pointer to the opaque Rust object.
1709 /// Nearly everywhere, inner must be non-null, however in places where
1710 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1711 pub inner: *mut nativeMinFinalCltvExpiryDelta,
1712 /// Indicates that this is the only struct which contains the same pointer.
1714 /// Rust functions which take ownership of an object provided via an argument require
1715 /// this to be true and invalidate the object pointed to by inner.
1719 impl Drop for MinFinalCltvExpiryDelta {
1720 fn drop(&mut self) {
1721 if self.is_owned && !<*mut nativeMinFinalCltvExpiryDelta>::is_null(self.inner) {
1722 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1726 /// Frees any resources used by the MinFinalCltvExpiryDelta, if is_owned is set and inner is non-NULL.
1728 pub extern "C" fn MinFinalCltvExpiryDelta_free(this_obj: MinFinalCltvExpiryDelta) { }
1730 /// Used only if an object of this type is returned as a trait impl by a method
1731 pub(crate) extern "C" fn MinFinalCltvExpiryDelta_free_void(this_ptr: *mut c_void) {
1732 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiryDelta) };
1735 impl MinFinalCltvExpiryDelta {
1736 pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiryDelta {
1737 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1739 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiryDelta {
1740 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1742 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1743 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiryDelta {
1744 assert!(self.is_owned);
1745 let ret = ObjOps::untweak_ptr(self.inner);
1746 self.inner = core::ptr::null_mut();
1751 pub extern "C" fn MinFinalCltvExpiryDelta_get_a(this_ptr: &MinFinalCltvExpiryDelta) -> u64 {
1752 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1756 pub extern "C" fn MinFinalCltvExpiryDelta_set_a(this_ptr: &mut MinFinalCltvExpiryDelta, mut val: u64) {
1757 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val;
1759 /// Constructs a new MinFinalCltvExpiryDelta given each field
1762 pub extern "C" fn MinFinalCltvExpiryDelta_new(mut a_arg: u64) -> MinFinalCltvExpiryDelta {
1763 MinFinalCltvExpiryDelta { inner: ObjOps::heap_alloc(lightning_invoice::MinFinalCltvExpiryDelta (
1765 )), is_owned: true }
1767 impl Clone for MinFinalCltvExpiryDelta {
1768 fn clone(&self) -> Self {
1770 inner: if <*mut nativeMinFinalCltvExpiryDelta>::is_null(self.inner) { core::ptr::null_mut() } else {
1771 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1777 /// Used only if an object of this type is returned as a trait impl by a method
1778 pub(crate) extern "C" fn MinFinalCltvExpiryDelta_clone_void(this_ptr: *const c_void) -> *mut c_void {
1779 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiryDelta)).clone() })) as *mut c_void
1782 /// Creates a copy of the MinFinalCltvExpiryDelta
1783 pub extern "C" fn MinFinalCltvExpiryDelta_clone(orig: &MinFinalCltvExpiryDelta) -> MinFinalCltvExpiryDelta {
1786 /// Generates a non-cryptographic 64-bit hash of the MinFinalCltvExpiryDelta.
1788 pub extern "C" fn MinFinalCltvExpiryDelta_hash(o: &MinFinalCltvExpiryDelta) -> u64 {
1789 if o.inner.is_null() { return 0; }
1790 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1791 #[allow(deprecated)]
1792 let mut hasher = core::hash::SipHasher::new();
1793 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1794 core::hash::Hasher::finish(&hasher)
1796 /// Checks if two MinFinalCltvExpiryDeltas contain equal inner contents.
1797 /// This ignores pointers and is_owned flags and looks at the values in fields.
1798 /// Two objects with NULL inner values will be considered "equal" here.
1800 pub extern "C" fn MinFinalCltvExpiryDelta_eq(a: &MinFinalCltvExpiryDelta, b: &MinFinalCltvExpiryDelta) -> bool {
1801 if a.inner == b.inner { return true; }
1802 if a.inner.is_null() || b.inner.is_null() { return false; }
1803 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1805 /// Fallback address in case no LN payment is possible
1811 version: crate::c_types::WitnessVersion,
1812 program: crate::c_types::derived::CVec_u8Z,
1815 crate::c_types::TwentyBytes),
1817 crate::c_types::TwentyBytes),
1819 use lightning_invoice::Fallback as FallbackImport;
1820 pub(crate) type nativeFallback = FallbackImport;
1824 pub(crate) fn to_native(&self) -> nativeFallback {
1826 Fallback::SegWitProgram {ref version, ref program, } => {
1827 let mut version_nonref = Clone::clone(version);
1828 let mut program_nonref = Clone::clone(program);
1829 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1830 nativeFallback::SegWitProgram {
1831 version: version_nonref.into(),
1832 program: local_program_nonref,
1835 Fallback::PubKeyHash (ref a, ) => {
1836 let mut a_nonref = Clone::clone(a);
1837 nativeFallback::PubKeyHash (
1838 bitcoin::hash_types::PubkeyHash::from_hash(bitcoin::hashes::Hash::from_inner(a_nonref.data)),
1841 Fallback::ScriptHash (ref a, ) => {
1842 let mut a_nonref = Clone::clone(a);
1843 nativeFallback::ScriptHash (
1844 bitcoin::hash_types::ScriptHash::from_hash(bitcoin::hashes::Hash::from_inner(a_nonref.data)),
1850 pub(crate) fn into_native(self) -> nativeFallback {
1852 Fallback::SegWitProgram {mut version, mut program, } => {
1853 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1854 nativeFallback::SegWitProgram {
1855 version: version.into(),
1856 program: local_program,
1859 Fallback::PubKeyHash (mut a, ) => {
1860 nativeFallback::PubKeyHash (
1861 bitcoin::hash_types::PubkeyHash::from_hash(bitcoin::hashes::Hash::from_inner(a.data)),
1864 Fallback::ScriptHash (mut a, ) => {
1865 nativeFallback::ScriptHash (
1866 bitcoin::hash_types::ScriptHash::from_hash(bitcoin::hashes::Hash::from_inner(a.data)),
1872 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1874 nativeFallback::SegWitProgram {ref version, ref program, } => {
1875 let mut version_nonref = Clone::clone(version);
1876 let mut program_nonref = Clone::clone(program);
1877 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1878 Fallback::SegWitProgram {
1879 version: version_nonref.into(),
1880 program: local_program_nonref.into(),
1883 nativeFallback::PubKeyHash (ref a, ) => {
1884 let mut a_nonref = Clone::clone(a);
1885 Fallback::PubKeyHash (
1886 crate::c_types::TwentyBytes { data: a_nonref.as_hash().into_inner() },
1889 nativeFallback::ScriptHash (ref a, ) => {
1890 let mut a_nonref = Clone::clone(a);
1891 Fallback::ScriptHash (
1892 crate::c_types::TwentyBytes { data: a_nonref.as_hash().into_inner() },
1898 pub(crate) fn native_into(native: nativeFallback) -> Self {
1900 nativeFallback::SegWitProgram {mut version, mut program, } => {
1901 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1902 Fallback::SegWitProgram {
1903 version: version.into(),
1904 program: local_program.into(),
1907 nativeFallback::PubKeyHash (mut a, ) => {
1908 Fallback::PubKeyHash (
1909 crate::c_types::TwentyBytes { data: a.as_hash().into_inner() },
1912 nativeFallback::ScriptHash (mut a, ) => {
1913 Fallback::ScriptHash (
1914 crate::c_types::TwentyBytes { data: a.as_hash().into_inner() },
1920 /// Frees any resources used by the Fallback
1922 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1923 /// Creates a copy of the Fallback
1925 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1929 /// Utility method to constructs a new SegWitProgram-variant Fallback
1930 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::WitnessVersion, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
1931 Fallback::SegWitProgram {
1937 /// Utility method to constructs a new PubKeyHash-variant Fallback
1938 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1939 Fallback::PubKeyHash(a, )
1942 /// Utility method to constructs a new ScriptHash-variant Fallback
1943 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1944 Fallback::ScriptHash(a, )
1946 /// Generates a non-cryptographic 64-bit hash of the Fallback.
1948 pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 {
1949 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1950 #[allow(deprecated)]
1951 let mut hasher = core::hash::SipHasher::new();
1952 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1953 core::hash::Hasher::finish(&hasher)
1955 /// Checks if two Fallbacks contain equal inner contents.
1956 /// This ignores pointers and is_owned flags and looks at the values in fields.
1958 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1959 if &a.to_native() == &b.to_native() { true } else { false }
1962 use lightning_invoice::Bolt11InvoiceSignature as nativeBolt11InvoiceSignatureImport;
1963 pub(crate) type nativeBolt11InvoiceSignature = nativeBolt11InvoiceSignatureImport;
1965 /// Recoverable signature
1968 pub struct Bolt11InvoiceSignature {
1969 /// A pointer to the opaque Rust object.
1971 /// Nearly everywhere, inner must be non-null, however in places where
1972 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1973 pub inner: *mut nativeBolt11InvoiceSignature,
1974 /// Indicates that this is the only struct which contains the same pointer.
1976 /// Rust functions which take ownership of an object provided via an argument require
1977 /// this to be true and invalidate the object pointed to by inner.
1981 impl Drop for Bolt11InvoiceSignature {
1982 fn drop(&mut self) {
1983 if self.is_owned && !<*mut nativeBolt11InvoiceSignature>::is_null(self.inner) {
1984 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1988 /// Frees any resources used by the Bolt11InvoiceSignature, if is_owned is set and inner is non-NULL.
1990 pub extern "C" fn Bolt11InvoiceSignature_free(this_obj: Bolt11InvoiceSignature) { }
1992 /// Used only if an object of this type is returned as a trait impl by a method
1993 pub(crate) extern "C" fn Bolt11InvoiceSignature_free_void(this_ptr: *mut c_void) {
1994 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBolt11InvoiceSignature) };
1997 impl Bolt11InvoiceSignature {
1998 pub(crate) fn get_native_ref(&self) -> &'static nativeBolt11InvoiceSignature {
1999 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2001 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt11InvoiceSignature {
2002 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2004 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2005 pub(crate) fn take_inner(mut self) -> *mut nativeBolt11InvoiceSignature {
2006 assert!(self.is_owned);
2007 let ret = ObjOps::untweak_ptr(self.inner);
2008 self.inner = core::ptr::null_mut();
2012 impl Clone for Bolt11InvoiceSignature {
2013 fn clone(&self) -> Self {
2015 inner: if <*mut nativeBolt11InvoiceSignature>::is_null(self.inner) { core::ptr::null_mut() } else {
2016 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2022 /// Used only if an object of this type is returned as a trait impl by a method
2023 pub(crate) extern "C" fn Bolt11InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
2024 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBolt11InvoiceSignature)).clone() })) as *mut c_void
2027 /// Creates a copy of the Bolt11InvoiceSignature
2028 pub extern "C" fn Bolt11InvoiceSignature_clone(orig: &Bolt11InvoiceSignature) -> Bolt11InvoiceSignature {
2031 /// Generates a non-cryptographic 64-bit hash of the Bolt11InvoiceSignature.
2033 pub extern "C" fn Bolt11InvoiceSignature_hash(o: &Bolt11InvoiceSignature) -> u64 {
2034 if o.inner.is_null() { return 0; }
2035 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2036 #[allow(deprecated)]
2037 let mut hasher = core::hash::SipHasher::new();
2038 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2039 core::hash::Hasher::finish(&hasher)
2041 /// Checks if two Bolt11InvoiceSignatures contain equal inner contents.
2042 /// This ignores pointers and is_owned flags and looks at the values in fields.
2043 /// Two objects with NULL inner values will be considered "equal" here.
2045 pub extern "C" fn Bolt11InvoiceSignature_eq(a: &Bolt11InvoiceSignature, b: &Bolt11InvoiceSignature) -> bool {
2046 if a.inner == b.inner { return true; }
2047 if a.inner.is_null() || b.inner.is_null() { return false; }
2048 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2051 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
2052 pub(crate) type nativePrivateRoute = nativePrivateRouteImport;
2054 /// Private routing information
2057 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
2061 pub struct PrivateRoute {
2062 /// A pointer to the opaque Rust object.
2064 /// Nearly everywhere, inner must be non-null, however in places where
2065 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2066 pub inner: *mut nativePrivateRoute,
2067 /// Indicates that this is the only struct which contains the same pointer.
2069 /// Rust functions which take ownership of an object provided via an argument require
2070 /// this to be true and invalidate the object pointed to by inner.
2074 impl Drop for PrivateRoute {
2075 fn drop(&mut self) {
2076 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
2077 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2081 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
2083 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
2085 /// Used only if an object of this type is returned as a trait impl by a method
2086 pub(crate) extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
2087 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePrivateRoute) };
2091 pub(crate) fn get_native_ref(&self) -> &'static nativePrivateRoute {
2092 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2094 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateRoute {
2095 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2097 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2098 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
2099 assert!(self.is_owned);
2100 let ret = ObjOps::untweak_ptr(self.inner);
2101 self.inner = core::ptr::null_mut();
2105 impl Clone for PrivateRoute {
2106 fn clone(&self) -> Self {
2108 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
2109 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2115 /// Used only if an object of this type is returned as a trait impl by a method
2116 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
2117 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
2120 /// Creates a copy of the PrivateRoute
2121 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
2124 /// Generates a non-cryptographic 64-bit hash of the PrivateRoute.
2126 pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 {
2127 if o.inner.is_null() { return 0; }
2128 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2129 #[allow(deprecated)]
2130 let mut hasher = core::hash::SipHasher::new();
2131 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2132 core::hash::Hasher::finish(&hasher)
2134 /// Checks if two PrivateRoutes contain equal inner contents.
2135 /// This ignores pointers and is_owned flags and looks at the values in fields.
2136 /// Two objects with NULL inner values will be considered "equal" here.
2138 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
2139 if a.inner == b.inner { return true; }
2140 if a.inner.is_null() || b.inner.is_null() { return false; }
2141 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2143 /// Disassembles the `SignedRawBolt11Invoice` into its three parts:
2145 /// 2. hash of the raw invoice
2149 pub extern "C" fn SignedRawBolt11Invoice_into_parts(mut this_arg: crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::c_types::derived::C3Tuple_RawBolt11Invoice_u832Bolt11InvoiceSignatureZ {
2150 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
2151 let (mut orig_ret_0, mut orig_ret_1, mut orig_ret_2) = ret; let mut local_ret = (crate::lightning_invoice::RawBolt11Invoice { inner: ObjOps::heap_alloc(orig_ret_0), is_owned: true }, crate::c_types::ThirtyTwoBytes { data: orig_ret_1 }, crate::lightning_invoice::Bolt11InvoiceSignature { inner: ObjOps::heap_alloc(orig_ret_2), is_owned: true }).into();
2155 /// The [`RawBolt11Invoice`] which was signed.
2158 pub extern "C" fn SignedRawBolt11Invoice_raw_invoice(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::lightning_invoice::RawBolt11Invoice {
2159 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice();
2160 crate::lightning_invoice::RawBolt11Invoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawBolt11Invoice<>) as *mut _) }, is_owned: false }
2163 /// The hash of the [`RawBolt11Invoice`] that was signed.
2166 pub extern "C" fn SignedRawBolt11Invoice_signable_hash(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> *const [u8; 32] {
2167 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2171 /// Signature for the invoice.
2174 pub extern "C" fn SignedRawBolt11Invoice_signature(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::lightning_invoice::Bolt11InvoiceSignature {
2175 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
2176 crate::lightning_invoice::Bolt11InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::Bolt11InvoiceSignature<>) as *mut _) }, is_owned: false }
2179 /// Recovers the public key used for signing the invoice from the recoverable signature.
2182 pub extern "C" fn SignedRawBolt11Invoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::c_types::derived::CResult_PayeePubKeyErrorZ {
2183 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2184 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PayeePubKey { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
2188 /// Checks if the signature is valid for the included payee public key or if none exists if it's
2189 /// valid for the recovered signature (which should always be true?).
2192 pub extern "C" fn SignedRawBolt11Invoice_check_signature(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> bool {
2193 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2197 /// Calculate the hash of the encoded `RawBolt11Invoice` which should be signed.
2200 pub extern "C" fn RawBolt11Invoice_signable_hash(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::ThirtyTwoBytes {
2201 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2202 crate::c_types::ThirtyTwoBytes { data: ret }
2206 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2209 pub extern "C" fn RawBolt11Invoice_payment_hash(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::Sha256 {
2210 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2211 let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Sha256<>) as *mut _ }, is_owned: false };
2216 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2219 pub extern "C" fn RawBolt11Invoice_description(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::Description {
2220 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
2221 let mut local_ret = crate::lightning_invoice::Description { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Description<>) as *mut _ }, is_owned: false };
2226 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2229 pub extern "C" fn RawBolt11Invoice_payee_pub_key(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::PayeePubKey {
2230 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2231 let mut local_ret = crate::lightning_invoice::PayeePubKey { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::PayeePubKey<>) as *mut _ }, is_owned: false };
2236 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2239 pub extern "C" fn RawBolt11Invoice_description_hash(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::Sha256 {
2240 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash();
2241 let mut local_ret = crate::lightning_invoice::Sha256 { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::Sha256<>) as *mut _ }, is_owned: false };
2246 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2249 pub extern "C" fn RawBolt11Invoice_expiry_time(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::ExpiryTime {
2250 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2251 let mut local_ret = crate::lightning_invoice::ExpiryTime { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::ExpiryTime<>) as *mut _ }, is_owned: false };
2256 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2259 pub extern "C" fn RawBolt11Invoice_min_final_cltv_expiry_delta(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::MinFinalCltvExpiryDelta {
2260 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry_delta();
2261 let mut local_ret = crate::lightning_invoice::MinFinalCltvExpiryDelta { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning_invoice::MinFinalCltvExpiryDelta<>) as *mut _ }, is_owned: false };
2267 pub extern "C" fn RawBolt11Invoice_payment_secret(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::derived::COption_PaymentSecretZ {
2268 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2269 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_PaymentSecretZ::None } else { crate::c_types::derived::COption_PaymentSecretZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { crate::c_types::ThirtyTwoBytes { data: (*ret.as_ref().unwrap()).clone().0 } }) };
2275 pub extern "C" fn RawBolt11Invoice_payment_metadata(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
2276 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_metadata();
2277 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { let mut local_ret_0 = Vec::new(); for mut item in (*ret.as_ref().unwrap()).clone().drain(..) { local_ret_0.push( { item }); }; local_ret_0.into() }) };
2282 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2285 pub extern "C" fn RawBolt11Invoice_features(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning::ln::features::Bolt11InvoiceFeatures {
2286 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2287 let mut local_ret = crate::lightning::ln::features::Bolt11InvoiceFeatures { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::Bolt11InvoiceFeatures<>) as *mut _ }, is_owned: false };
2293 pub extern "C" fn RawBolt11Invoice_private_routes(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2294 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2295 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning_invoice::PrivateRoute<>) as *mut _) }, is_owned: false } }); };
2301 pub extern "C" fn RawBolt11Invoice_amount_pico_btc(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::derived::COption_u64Z {
2302 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
2303 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() }) };
2309 pub extern "C" fn RawBolt11Invoice_currency(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::Currency {
2310 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2311 crate::lightning_invoice::Currency::native_into(ret)
2314 /// Creates a `PositiveTimestamp` from a Unix timestamp in the range `0..=MAX_TIMESTAMP`.
2316 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2319 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2320 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
2321 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
2325 /// Creates a `PositiveTimestamp` from a [`SystemTime`] with a corresponding Unix timestamp in
2326 /// the range `0..=MAX_TIMESTAMP`.
2328 /// Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
2330 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2333 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2334 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
2335 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
2339 /// Creates a `PositiveTimestamp` from a [`Duration`] since the Unix epoch in the range
2340 /// `0..=MAX_TIMESTAMP`.
2342 /// Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
2344 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2347 pub extern "C" fn PositiveTimestamp_from_duration_since_epoch(mut duration: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2348 let mut ret = lightning_invoice::PositiveTimestamp::from_duration_since_epoch(core::time::Duration::from_secs(duration));
2349 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PositiveTimestamp { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
2353 /// Returns the Unix timestamp representing the stored time
2356 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2357 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_unix_timestamp();
2361 /// Returns the duration of the stored time since the Unix epoch
2364 pub extern "C" fn PositiveTimestamp_as_duration_since_epoch(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2365 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration_since_epoch();
2369 /// Returns the [`SystemTime`] representing the stored time
2372 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2373 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_time();
2374 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2377 /// The hash of the [`RawBolt11Invoice`] that was signed.
2380 pub extern "C" fn Bolt11Invoice_signable_hash(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::ThirtyTwoBytes {
2381 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2382 crate::c_types::ThirtyTwoBytes { data: ret }
2385 /// Transform the `Bolt11Invoice` into its unchecked version.
2388 pub extern "C" fn Bolt11Invoice_into_signed_raw(mut this_arg: crate::lightning_invoice::Bolt11Invoice) -> crate::lightning_invoice::SignedRawBolt11Invoice {
2389 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
2390 crate::lightning_invoice::SignedRawBolt11Invoice { inner: ObjOps::heap_alloc(ret), is_owned: true }
2393 /// Check that the invoice is signed correctly and that key recovery works
2396 pub extern "C" fn Bolt11Invoice_check_signature(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::CResult_NoneBolt11SemanticErrorZ {
2397 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2398 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::Bolt11SemanticError::native_into(e) }).into() };
2402 /// Constructs a `Bolt11Invoice` from a [`SignedRawBolt11Invoice`] by checking all its invariants.
2404 /// use lightning_invoice::*;
2406 /// let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
2407 /// h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
2408 /// 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
2409 /// h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
2410 /// j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
2411 /// ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
2412 /// guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
2413 /// ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
2414 /// p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
2415 /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
2416 /// j5r6drg6k6zcqj0fcwg\";
2418 /// let signed = invoice.parse::<SignedRawBolt11Invoice>().unwrap();
2420 /// assert!(Bolt11Invoice::from_signed(signed).is_ok());
2424 pub extern "C" fn Bolt11Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::c_types::derived::CResult_Bolt11InvoiceBolt11SemanticErrorZ {
2425 let mut ret = lightning_invoice::Bolt11Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
2426 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::Bolt11Invoice { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::Bolt11SemanticError::native_into(e) }).into() };
2430 /// Returns the `Bolt11Invoice`'s timestamp (should equal its creation time)
2433 pub extern "C" fn Bolt11Invoice_timestamp(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
2434 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timestamp();
2435 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2438 /// Returns the `Bolt11Invoice`'s timestamp as a duration since the Unix epoch
2441 pub extern "C" fn Bolt11Invoice_duration_since_epoch(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
2442 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_since_epoch();
2446 /// Returns the hash to which we will receive the preimage on completion of the payment
2449 pub extern "C" fn Bolt11Invoice_payment_hash(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> *const [u8; 32] {
2450 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2454 /// Get the payee's public key if one was included in the invoice
2456 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2459 pub extern "C" fn Bolt11Invoice_payee_pub_key(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::PublicKey {
2460 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2461 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
2465 /// Get the payment secret if one was included in the invoice
2468 pub extern "C" fn Bolt11Invoice_payment_secret(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> *const [u8; 32] {
2469 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2473 /// Get the payment metadata blob if one was included in the invoice
2476 pub extern "C" fn Bolt11Invoice_payment_metadata(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
2477 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_metadata();
2478 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { let mut local_ret_0 = Vec::new(); for mut item in (*ret.as_ref().unwrap()).clone().drain(..) { local_ret_0.push( { item }); }; local_ret_0.into() }) };
2482 /// Get the invoice features if they were included in the invoice
2484 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2487 pub extern "C" fn Bolt11Invoice_features(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::lightning::ln::features::Bolt11InvoiceFeatures {
2488 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2489 let mut local_ret = crate::lightning::ln::features::Bolt11InvoiceFeatures { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::Bolt11InvoiceFeatures<>) as *mut _ }, is_owned: false };
2493 /// Recover the payee's public key (only to be used if none was included in the invoice)
2496 pub extern "C" fn Bolt11Invoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::PublicKey {
2497 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2498 crate::c_types::PublicKey::from_rust(&ret)
2501 /// Returns the Duration since the Unix epoch at which the invoice expires.
2502 /// Returning None if overflow occurred.
2505 pub extern "C" fn Bolt11Invoice_expires_at(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::COption_DurationZ {
2506 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expires_at();
2507 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_DurationZ::None } else { crate::c_types::derived::COption_DurationZ::Some( { ret.unwrap().as_secs() }) };
2511 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
2514 pub extern "C" fn Bolt11Invoice_expiry_time(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
2515 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2519 /// Returns whether the invoice has expired.
2522 pub extern "C" fn Bolt11Invoice_is_expired(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> bool {
2523 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
2527 /// Returns the Duration remaining until the invoice expires.
2530 pub extern "C" fn Bolt11Invoice_duration_until_expiry(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
2531 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_until_expiry();
2535 /// Returns the Duration remaining until the invoice expires given the current time.
2536 /// `time` is the timestamp as a duration since the Unix epoch.
2539 pub extern "C" fn Bolt11Invoice_expiration_remaining_from_epoch(this_arg: &crate::lightning_invoice::Bolt11Invoice, mut time: u64) -> u64 {
2540 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiration_remaining_from_epoch(core::time::Duration::from_secs(time));
2544 /// Returns whether the expiry time would pass at the given point in time.
2545 /// `at_time` is the timestamp as a duration since the Unix epoch.
2548 pub extern "C" fn Bolt11Invoice_would_expire(this_arg: &crate::lightning_invoice::Bolt11Invoice, mut at_time: u64) -> bool {
2549 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.would_expire(core::time::Duration::from_secs(at_time));
2553 /// Returns the invoice's `min_final_cltv_expiry_delta` time, if present, otherwise
2554 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA`].
2557 pub extern "C" fn Bolt11Invoice_min_final_cltv_expiry_delta(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
2558 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry_delta();
2562 /// Returns a list of all fallback addresses as [`Address`]es
2565 pub extern "C" fn Bolt11Invoice_fallback_addresses(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::CVec_AddressZ {
2566 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fallback_addresses();
2567 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { alloc::string::ToString::to_string(&item).into() }); };
2571 /// Returns a list of all routes included in the invoice
2574 pub extern "C" fn Bolt11Invoice_private_routes(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2575 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2576 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning_invoice::PrivateRoute { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning_invoice::PrivateRoute<>) as *mut _) }, is_owned: false } }); };
2580 /// Returns a list of all routes included in the invoice as the underlying hints
2583 pub extern "C" fn Bolt11Invoice_route_hints(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
2584 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints();
2585 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
2589 /// Returns the currency for which the invoice was issued
2592 pub extern "C" fn Bolt11Invoice_currency(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::lightning_invoice::Currency {
2593 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2594 crate::lightning_invoice::Currency::native_into(ret)
2597 /// Returns the amount if specified in the invoice as millisatoshis.
2600 pub extern "C" fn Bolt11Invoice_amount_milli_satoshis(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::COption_u64Z {
2601 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_milli_satoshis();
2602 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() }) };
2606 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
2607 /// returns [`CreationError::DescriptionTooLong`] otherwise
2609 /// Please note that single characters may use more than one byte due to UTF8 encoding.
2612 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
2613 let mut ret = lightning_invoice::Description::new(description.into_string());
2614 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::Description { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
2618 /// Returns the underlying description [`String`]
2621 pub extern "C" fn Description_into_inner(mut this_arg: crate::lightning_invoice::Description) -> crate::c_types::Str {
2622 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2626 /// Construct an `ExpiryTime` from seconds.
2629 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::lightning_invoice::ExpiryTime {
2630 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
2631 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2634 /// Construct an `ExpiryTime` from a [`Duration`], dropping the sub-second part.
2637 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::lightning_invoice::ExpiryTime {
2638 let mut ret = lightning_invoice::ExpiryTime::from_duration(core::time::Duration::from_secs(duration));
2639 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2642 /// Returns the expiry time in seconds
2645 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2646 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_seconds();
2650 /// Returns a reference to the underlying [`Duration`] (=expiry time)
2653 pub extern "C" fn ExpiryTime_as_duration(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2654 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration();
2658 /// Creates a new (partial) route from a list of hops
2661 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
2662 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
2663 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_invoice::PrivateRoute { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning_invoice::CreationError::native_into(e) }).into() };
2667 /// Returns the underlying list of hops
2670 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: crate::lightning_invoice::PrivateRoute) -> crate::lightning::routing::router::RouteHint {
2671 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2672 crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true }
2675 /// Errors that may occur when constructing a new [`RawBolt11Invoice`] or [`Bolt11Invoice`]
2679 pub enum CreationError {
2680 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new`])
2682 /// The specified route has too many hops and can't be encoded
2684 /// The Unix timestamp of the supplied date is less than zero or greater than 35-bits
2685 TimestampOutOfBounds,
2686 /// The supplied millisatoshi amount was greater than the total bitcoin supply.
2688 /// Route hints were required for this invoice and were missing. Applies to
2689 /// [phantom invoices].
2691 /// [phantom invoices]: crate::utils::create_phantom_invoice
2693 /// The provided `min_final_cltv_expiry_delta` was less than [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
2695 /// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
2696 MinFinalCltvExpiryDeltaTooShort,
2698 use lightning_invoice::CreationError as CreationErrorImport;
2699 pub(crate) type nativeCreationError = CreationErrorImport;
2701 impl CreationError {
2703 pub(crate) fn to_native(&self) -> nativeCreationError {
2705 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2706 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2707 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2708 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2709 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2710 CreationError::MinFinalCltvExpiryDeltaTooShort => nativeCreationError::MinFinalCltvExpiryDeltaTooShort,
2714 pub(crate) fn into_native(self) -> nativeCreationError {
2716 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2717 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2718 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2719 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2720 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2721 CreationError::MinFinalCltvExpiryDeltaTooShort => nativeCreationError::MinFinalCltvExpiryDeltaTooShort,
2725 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
2727 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2728 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2729 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2730 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2731 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2732 nativeCreationError::MinFinalCltvExpiryDeltaTooShort => CreationError::MinFinalCltvExpiryDeltaTooShort,
2736 pub(crate) fn native_into(native: nativeCreationError) -> Self {
2738 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2739 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2740 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2741 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2742 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2743 nativeCreationError::MinFinalCltvExpiryDeltaTooShort => CreationError::MinFinalCltvExpiryDeltaTooShort,
2747 /// Creates a copy of the CreationError
2749 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
2753 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
2754 pub extern "C" fn CreationError_description_too_long() -> CreationError {
2755 CreationError::DescriptionTooLong}
2757 /// Utility method to constructs a new RouteTooLong-variant CreationError
2758 pub extern "C" fn CreationError_route_too_long() -> CreationError {
2759 CreationError::RouteTooLong}
2761 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
2762 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
2763 CreationError::TimestampOutOfBounds}
2765 /// Utility method to constructs a new InvalidAmount-variant CreationError
2766 pub extern "C" fn CreationError_invalid_amount() -> CreationError {
2767 CreationError::InvalidAmount}
2769 /// Utility method to constructs a new MissingRouteHints-variant CreationError
2770 pub extern "C" fn CreationError_missing_route_hints() -> CreationError {
2771 CreationError::MissingRouteHints}
2773 /// Utility method to constructs a new MinFinalCltvExpiryDeltaTooShort-variant CreationError
2774 pub extern "C" fn CreationError_min_final_cltv_expiry_delta_too_short() -> CreationError {
2775 CreationError::MinFinalCltvExpiryDeltaTooShort}
2776 /// Checks if two CreationErrors contain equal inner contents.
2777 /// This ignores pointers and is_owned flags and looks at the values in fields.
2779 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
2780 if &a.to_native() == &b.to_native() { true } else { false }
2783 /// Get the string representation of a CreationError object
2784 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
2785 alloc::format!("{}", &o.to_native()).into()
2787 /// Errors that may occur when converting a [`RawBolt11Invoice`] to a [`Bolt11Invoice`]. They relate to
2788 /// the requirements sections in BOLT #11
2792 pub enum Bolt11SemanticError {
2793 /// The invoice is missing the mandatory payment hash
2795 /// The invoice has multiple payment hashes which isn't allowed
2796 MultiplePaymentHashes,
2797 /// No description or description hash are part of the invoice
2799 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
2800 MultipleDescriptions,
2801 /// The invoice is missing the mandatory payment secret, which all modern lightning nodes
2804 /// The invoice contains multiple payment secrets
2805 MultiplePaymentSecrets,
2806 /// The invoice's features are invalid
2808 /// The recovery id doesn't fit the signature/pub key
2810 /// The invoice's signature is invalid
2812 /// The invoice's amount was not a whole number of millisatoshis
2815 use lightning_invoice::Bolt11SemanticError as Bolt11SemanticErrorImport;
2816 pub(crate) type nativeBolt11SemanticError = Bolt11SemanticErrorImport;
2818 impl Bolt11SemanticError {
2820 pub(crate) fn to_native(&self) -> nativeBolt11SemanticError {
2822 Bolt11SemanticError::NoPaymentHash => nativeBolt11SemanticError::NoPaymentHash,
2823 Bolt11SemanticError::MultiplePaymentHashes => nativeBolt11SemanticError::MultiplePaymentHashes,
2824 Bolt11SemanticError::NoDescription => nativeBolt11SemanticError::NoDescription,
2825 Bolt11SemanticError::MultipleDescriptions => nativeBolt11SemanticError::MultipleDescriptions,
2826 Bolt11SemanticError::NoPaymentSecret => nativeBolt11SemanticError::NoPaymentSecret,
2827 Bolt11SemanticError::MultiplePaymentSecrets => nativeBolt11SemanticError::MultiplePaymentSecrets,
2828 Bolt11SemanticError::InvalidFeatures => nativeBolt11SemanticError::InvalidFeatures,
2829 Bolt11SemanticError::InvalidRecoveryId => nativeBolt11SemanticError::InvalidRecoveryId,
2830 Bolt11SemanticError::InvalidSignature => nativeBolt11SemanticError::InvalidSignature,
2831 Bolt11SemanticError::ImpreciseAmount => nativeBolt11SemanticError::ImpreciseAmount,
2835 pub(crate) fn into_native(self) -> nativeBolt11SemanticError {
2837 Bolt11SemanticError::NoPaymentHash => nativeBolt11SemanticError::NoPaymentHash,
2838 Bolt11SemanticError::MultiplePaymentHashes => nativeBolt11SemanticError::MultiplePaymentHashes,
2839 Bolt11SemanticError::NoDescription => nativeBolt11SemanticError::NoDescription,
2840 Bolt11SemanticError::MultipleDescriptions => nativeBolt11SemanticError::MultipleDescriptions,
2841 Bolt11SemanticError::NoPaymentSecret => nativeBolt11SemanticError::NoPaymentSecret,
2842 Bolt11SemanticError::MultiplePaymentSecrets => nativeBolt11SemanticError::MultiplePaymentSecrets,
2843 Bolt11SemanticError::InvalidFeatures => nativeBolt11SemanticError::InvalidFeatures,
2844 Bolt11SemanticError::InvalidRecoveryId => nativeBolt11SemanticError::InvalidRecoveryId,
2845 Bolt11SemanticError::InvalidSignature => nativeBolt11SemanticError::InvalidSignature,
2846 Bolt11SemanticError::ImpreciseAmount => nativeBolt11SemanticError::ImpreciseAmount,
2850 pub(crate) fn from_native(native: &nativeBolt11SemanticError) -> Self {
2852 nativeBolt11SemanticError::NoPaymentHash => Bolt11SemanticError::NoPaymentHash,
2853 nativeBolt11SemanticError::MultiplePaymentHashes => Bolt11SemanticError::MultiplePaymentHashes,
2854 nativeBolt11SemanticError::NoDescription => Bolt11SemanticError::NoDescription,
2855 nativeBolt11SemanticError::MultipleDescriptions => Bolt11SemanticError::MultipleDescriptions,
2856 nativeBolt11SemanticError::NoPaymentSecret => Bolt11SemanticError::NoPaymentSecret,
2857 nativeBolt11SemanticError::MultiplePaymentSecrets => Bolt11SemanticError::MultiplePaymentSecrets,
2858 nativeBolt11SemanticError::InvalidFeatures => Bolt11SemanticError::InvalidFeatures,
2859 nativeBolt11SemanticError::InvalidRecoveryId => Bolt11SemanticError::InvalidRecoveryId,
2860 nativeBolt11SemanticError::InvalidSignature => Bolt11SemanticError::InvalidSignature,
2861 nativeBolt11SemanticError::ImpreciseAmount => Bolt11SemanticError::ImpreciseAmount,
2865 pub(crate) fn native_into(native: nativeBolt11SemanticError) -> Self {
2867 nativeBolt11SemanticError::NoPaymentHash => Bolt11SemanticError::NoPaymentHash,
2868 nativeBolt11SemanticError::MultiplePaymentHashes => Bolt11SemanticError::MultiplePaymentHashes,
2869 nativeBolt11SemanticError::NoDescription => Bolt11SemanticError::NoDescription,
2870 nativeBolt11SemanticError::MultipleDescriptions => Bolt11SemanticError::MultipleDescriptions,
2871 nativeBolt11SemanticError::NoPaymentSecret => Bolt11SemanticError::NoPaymentSecret,
2872 nativeBolt11SemanticError::MultiplePaymentSecrets => Bolt11SemanticError::MultiplePaymentSecrets,
2873 nativeBolt11SemanticError::InvalidFeatures => Bolt11SemanticError::InvalidFeatures,
2874 nativeBolt11SemanticError::InvalidRecoveryId => Bolt11SemanticError::InvalidRecoveryId,
2875 nativeBolt11SemanticError::InvalidSignature => Bolt11SemanticError::InvalidSignature,
2876 nativeBolt11SemanticError::ImpreciseAmount => Bolt11SemanticError::ImpreciseAmount,
2880 /// Creates a copy of the Bolt11SemanticError
2882 pub extern "C" fn Bolt11SemanticError_clone(orig: &Bolt11SemanticError) -> Bolt11SemanticError {
2886 /// Utility method to constructs a new NoPaymentHash-variant Bolt11SemanticError
2887 pub extern "C" fn Bolt11SemanticError_no_payment_hash() -> Bolt11SemanticError {
2888 Bolt11SemanticError::NoPaymentHash}
2890 /// Utility method to constructs a new MultiplePaymentHashes-variant Bolt11SemanticError
2891 pub extern "C" fn Bolt11SemanticError_multiple_payment_hashes() -> Bolt11SemanticError {
2892 Bolt11SemanticError::MultiplePaymentHashes}
2894 /// Utility method to constructs a new NoDescription-variant Bolt11SemanticError
2895 pub extern "C" fn Bolt11SemanticError_no_description() -> Bolt11SemanticError {
2896 Bolt11SemanticError::NoDescription}
2898 /// Utility method to constructs a new MultipleDescriptions-variant Bolt11SemanticError
2899 pub extern "C" fn Bolt11SemanticError_multiple_descriptions() -> Bolt11SemanticError {
2900 Bolt11SemanticError::MultipleDescriptions}
2902 /// Utility method to constructs a new NoPaymentSecret-variant Bolt11SemanticError
2903 pub extern "C" fn Bolt11SemanticError_no_payment_secret() -> Bolt11SemanticError {
2904 Bolt11SemanticError::NoPaymentSecret}
2906 /// Utility method to constructs a new MultiplePaymentSecrets-variant Bolt11SemanticError
2907 pub extern "C" fn Bolt11SemanticError_multiple_payment_secrets() -> Bolt11SemanticError {
2908 Bolt11SemanticError::MultiplePaymentSecrets}
2910 /// Utility method to constructs a new InvalidFeatures-variant Bolt11SemanticError
2911 pub extern "C" fn Bolt11SemanticError_invalid_features() -> Bolt11SemanticError {
2912 Bolt11SemanticError::InvalidFeatures}
2914 /// Utility method to constructs a new InvalidRecoveryId-variant Bolt11SemanticError
2915 pub extern "C" fn Bolt11SemanticError_invalid_recovery_id() -> Bolt11SemanticError {
2916 Bolt11SemanticError::InvalidRecoveryId}
2918 /// Utility method to constructs a new InvalidSignature-variant Bolt11SemanticError
2919 pub extern "C" fn Bolt11SemanticError_invalid_signature() -> Bolt11SemanticError {
2920 Bolt11SemanticError::InvalidSignature}
2922 /// Utility method to constructs a new ImpreciseAmount-variant Bolt11SemanticError
2923 pub extern "C" fn Bolt11SemanticError_imprecise_amount() -> Bolt11SemanticError {
2924 Bolt11SemanticError::ImpreciseAmount}
2925 /// Checks if two Bolt11SemanticErrors contain equal inner contents.
2926 /// This ignores pointers and is_owned flags and looks at the values in fields.
2928 pub extern "C" fn Bolt11SemanticError_eq(a: &Bolt11SemanticError, b: &Bolt11SemanticError) -> bool {
2929 if &a.to_native() == &b.to_native() { true } else { false }
2932 /// Get the string representation of a Bolt11SemanticError object
2933 pub extern "C" fn Bolt11SemanticError_to_str(o: &crate::lightning_invoice::Bolt11SemanticError) -> Str {
2934 alloc::format!("{}", &o.to_native()).into()
2936 /// When signing using a fallible method either an user-supplied `SignError` or a [`CreationError`]
2941 pub enum SignOrCreationError {
2942 /// An error occurred during signing
2944 /// An error occurred while building the transaction
2946 crate::lightning_invoice::CreationError),
2948 use lightning_invoice::SignOrCreationError as SignOrCreationErrorImport;
2949 pub(crate) type nativeSignOrCreationError = SignOrCreationErrorImport<>;
2951 impl SignOrCreationError {
2953 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
2955 SignOrCreationError::SignError => {
2956 nativeSignOrCreationError::SignError (
2960 SignOrCreationError::CreationError (ref a, ) => {
2961 let mut a_nonref = Clone::clone(a);
2962 nativeSignOrCreationError::CreationError (
2963 a_nonref.into_native(),
2969 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
2971 SignOrCreationError::SignError => {
2972 nativeSignOrCreationError::SignError (
2976 SignOrCreationError::CreationError (mut a, ) => {
2977 nativeSignOrCreationError::CreationError (
2984 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
2986 nativeSignOrCreationError::SignError (ref a, ) => {
2987 SignOrCreationError::SignError },
2988 nativeSignOrCreationError::CreationError (ref a, ) => {
2989 let mut a_nonref = Clone::clone(a);
2990 SignOrCreationError::CreationError (
2991 crate::lightning_invoice::CreationError::native_into(a_nonref),
2997 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
2999 nativeSignOrCreationError::SignError (mut a, ) => {
3000 SignOrCreationError::SignError },
3001 nativeSignOrCreationError::CreationError (mut a, ) => {
3002 SignOrCreationError::CreationError (
3003 crate::lightning_invoice::CreationError::native_into(a),
3009 /// Frees any resources used by the SignOrCreationError
3011 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
3012 /// Creates a copy of the SignOrCreationError
3014 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
3018 /// Utility method to constructs a new SignError-variant SignOrCreationError
3019 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
3020 SignOrCreationError::SignError
3023 /// Utility method to constructs a new CreationError-variant SignOrCreationError
3024 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
3025 SignOrCreationError::CreationError(a, )
3027 /// Checks if two SignOrCreationErrors contain equal inner contents.
3028 /// This ignores pointers and is_owned flags and looks at the values in fields.
3030 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
3031 if &a.to_native() == &b.to_native() { true } else { false }
3034 /// Get the string representation of a SignOrCreationError object
3035 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
3036 alloc::format!("{}", &o.to_native()).into()